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 pologi 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 lpfc_rport_data *rdata;
1595 struct fc_rport *rport;
1596 struct serv_parm *sp;
1597 uint8_t name[sizeof(struct lpfc_name)];
1598 uint32_t rc, keepDID = 0, keep_nlp_flag = 0;
1599 uint32_t keep_new_nlp_flag = 0;
1600 uint16_t keep_nlp_state;
1601 u32 keep_nlp_fc4_type = 0;
1602 struct lpfc_nvme_rport *keep_nrport = NULL;
1605 unsigned long *active_rrqs_xri_bitmap = NULL;
1607 /* Fabric nodes can have the same WWPN so we don't bother searching
1608 * by WWPN. Just return the ndlp that was given to us.
1610 if (ndlp->nlp_type & NLP_FABRIC)
1613 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
1614 memset(name, 0, sizeof(struct lpfc_name));
1616 /* Now we find out if the NPort we are logging into, matches the WWPN
1617 * we have for that ndlp. If not, we have some work to do.
1619 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
1621 /* return immediately if the WWPN matches ndlp */
1622 if (new_ndlp == ndlp)
1625 if (phba->sli_rev == LPFC_SLI_REV4) {
1626 active_rrqs_xri_bitmap = mempool_alloc(phba->active_rrq_pool,
1628 if (active_rrqs_xri_bitmap)
1629 memset(active_rrqs_xri_bitmap, 0,
1630 phba->cfg_rrq_xri_bitmap_sz);
1633 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_NODE,
1634 "3178 PLOGI confirm: ndlp x%x x%x x%x: "
1635 "new_ndlp x%x x%x x%x\n",
1636 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_fc4_type,
1637 (new_ndlp ? new_ndlp->nlp_DID : 0),
1638 (new_ndlp ? new_ndlp->nlp_flag : 0),
1639 (new_ndlp ? new_ndlp->nlp_fc4_type : 0));
1642 rc = memcmp(&ndlp->nlp_portname, name,
1643 sizeof(struct lpfc_name));
1645 if (active_rrqs_xri_bitmap)
1646 mempool_free(active_rrqs_xri_bitmap,
1647 phba->active_rrq_pool);
1650 new_ndlp = lpfc_nlp_init(vport, ndlp->nlp_DID);
1652 if (active_rrqs_xri_bitmap)
1653 mempool_free(active_rrqs_xri_bitmap,
1654 phba->active_rrq_pool);
1658 keepDID = new_ndlp->nlp_DID;
1659 if (phba->sli_rev == LPFC_SLI_REV4 &&
1660 active_rrqs_xri_bitmap)
1661 memcpy(active_rrqs_xri_bitmap,
1662 new_ndlp->active_rrqs_xri_bitmap,
1663 phba->cfg_rrq_xri_bitmap_sz);
1666 /* At this point in this routine, we know new_ndlp will be
1667 * returned. however, any previous GID_FTs that were done
1668 * would have updated nlp_fc4_type in ndlp, so we must ensure
1669 * new_ndlp has the right value.
1671 if (vport->fc_flag & FC_FABRIC) {
1672 keep_nlp_fc4_type = new_ndlp->nlp_fc4_type;
1673 new_ndlp->nlp_fc4_type = ndlp->nlp_fc4_type;
1676 lpfc_unreg_rpi(vport, new_ndlp);
1677 new_ndlp->nlp_DID = ndlp->nlp_DID;
1678 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
1679 if (phba->sli_rev == LPFC_SLI_REV4)
1680 memcpy(new_ndlp->active_rrqs_xri_bitmap,
1681 ndlp->active_rrqs_xri_bitmap,
1682 phba->cfg_rrq_xri_bitmap_sz);
1684 spin_lock_irq(shost->host_lock);
1685 keep_new_nlp_flag = new_ndlp->nlp_flag;
1686 keep_nlp_flag = ndlp->nlp_flag;
1687 new_ndlp->nlp_flag = ndlp->nlp_flag;
1689 /* if new_ndlp had NLP_UNREG_INP set, keep it */
1690 if (keep_new_nlp_flag & NLP_UNREG_INP)
1691 new_ndlp->nlp_flag |= NLP_UNREG_INP;
1693 new_ndlp->nlp_flag &= ~NLP_UNREG_INP;
1695 /* if new_ndlp had NLP_RPI_REGISTERED set, keep it */
1696 if (keep_new_nlp_flag & NLP_RPI_REGISTERED)
1697 new_ndlp->nlp_flag |= NLP_RPI_REGISTERED;
1699 new_ndlp->nlp_flag &= ~NLP_RPI_REGISTERED;
1701 ndlp->nlp_flag = keep_new_nlp_flag;
1703 /* if ndlp had NLP_UNREG_INP set, keep it */
1704 if (keep_nlp_flag & NLP_UNREG_INP)
1705 ndlp->nlp_flag |= NLP_UNREG_INP;
1707 ndlp->nlp_flag &= ~NLP_UNREG_INP;
1709 /* if ndlp had NLP_RPI_REGISTERED set, keep it */
1710 if (keep_nlp_flag & NLP_RPI_REGISTERED)
1711 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
1713 ndlp->nlp_flag &= ~NLP_RPI_REGISTERED;
1715 spin_unlock_irq(shost->host_lock);
1717 /* Set nlp_states accordingly */
1718 keep_nlp_state = new_ndlp->nlp_state;
1719 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
1721 /* interchange the nvme remoteport structs */
1722 keep_nrport = new_ndlp->nrport;
1723 new_ndlp->nrport = ndlp->nrport;
1725 /* Move this back to NPR state */
1726 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
1727 /* The new_ndlp is replacing ndlp totally, so we need
1728 * to put ndlp on UNUSED list and try to free it.
1730 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1731 "3179 PLOGI confirm NEW: %x %x\n",
1732 new_ndlp->nlp_DID, keepDID);
1734 /* Fix up the rport accordingly */
1735 rport = ndlp->rport;
1737 rdata = rport->dd_data;
1738 if (rdata->pnode == ndlp) {
1739 /* break the link before dropping the ref */
1742 rdata->pnode = lpfc_nlp_get(new_ndlp);
1743 new_ndlp->rport = rport;
1745 new_ndlp->nlp_type = ndlp->nlp_type;
1748 /* Fix up the nvme rport */
1750 ndlp->nrport = NULL;
1754 /* Two ndlps cannot have the same did on the nodelist.
1755 * Note: for this case, ndlp has a NULL WWPN so setting
1756 * the nlp_fc4_type isn't required.
1758 ndlp->nlp_DID = keepDID;
1759 lpfc_nlp_set_state(vport, ndlp, keep_nlp_state);
1760 if (phba->sli_rev == LPFC_SLI_REV4 &&
1761 active_rrqs_xri_bitmap)
1762 memcpy(ndlp->active_rrqs_xri_bitmap,
1763 active_rrqs_xri_bitmap,
1764 phba->cfg_rrq_xri_bitmap_sz);
1767 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1768 "3180 PLOGI confirm SWAP: %x %x\n",
1769 new_ndlp->nlp_DID, keepDID);
1771 lpfc_unreg_rpi(vport, ndlp);
1773 /* Two ndlps cannot have the same did and the fc4
1774 * type must be transferred because the ndlp is in
1777 ndlp->nlp_DID = keepDID;
1778 ndlp->nlp_fc4_type = keep_nlp_fc4_type;
1780 if (phba->sli_rev == LPFC_SLI_REV4 &&
1781 active_rrqs_xri_bitmap)
1782 memcpy(ndlp->active_rrqs_xri_bitmap,
1783 active_rrqs_xri_bitmap,
1784 phba->cfg_rrq_xri_bitmap_sz);
1786 /* Since we are switching over to the new_ndlp,
1787 * reset the old ndlp state
1789 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
1790 (ndlp->nlp_state == NLP_STE_MAPPED_NODE))
1791 keep_nlp_state = NLP_STE_NPR_NODE;
1792 lpfc_nlp_set_state(vport, ndlp, keep_nlp_state);
1794 /* Previous ndlp no longer active with nvme host transport.
1795 * Remove reference from earlier registration unless the
1796 * nvme host took care of it.
1800 ndlp->nrport = keep_nrport;
1802 /* Fix up the rport accordingly */
1803 rport = ndlp->rport;
1805 rdata = rport->dd_data;
1806 put_node = rdata->pnode != NULL;
1807 put_rport = ndlp->rport != NULL;
1808 rdata->pnode = NULL;
1813 put_device(&rport->dev);
1818 * If ndlp is not associated with any rport we can drop it here else
1819 * let dev_loss_tmo_callbk trigger DEVICE_RM event
1821 if (!ndlp->rport && (ndlp->nlp_state == NLP_STE_NPR_NODE))
1822 lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM);
1824 if (phba->sli_rev == LPFC_SLI_REV4 &&
1825 active_rrqs_xri_bitmap)
1826 mempool_free(active_rrqs_xri_bitmap,
1827 phba->active_rrq_pool);
1829 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_NODE,
1830 "3173 PLOGI confirm exit: new_ndlp x%x x%x x%x\n",
1831 new_ndlp->nlp_DID, new_ndlp->nlp_flag,
1832 new_ndlp->nlp_fc4_type);
1838 * lpfc_end_rscn - Check and handle more rscn for a vport
1839 * @vport: pointer to a host virtual N_Port data structure.
1841 * This routine checks whether more Registration State Change
1842 * Notifications (RSCNs) came in while the discovery state machine was in
1843 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1844 * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1845 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1846 * handling the RSCNs.
1849 lpfc_end_rscn(struct lpfc_vport *vport)
1851 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1853 if (vport->fc_flag & FC_RSCN_MODE) {
1855 * Check to see if more RSCNs came in while we were
1856 * processing this one.
1858 if (vport->fc_rscn_id_cnt ||
1859 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
1860 lpfc_els_handle_rscn(vport);
1862 spin_lock_irq(shost->host_lock);
1863 vport->fc_flag &= ~FC_RSCN_MODE;
1864 spin_unlock_irq(shost->host_lock);
1870 * lpfc_cmpl_els_rrq - Completion handled for els RRQs.
1871 * @phba: pointer to lpfc hba data structure.
1872 * @cmdiocb: pointer to lpfc command iocb data structure.
1873 * @rspiocb: pointer to lpfc response iocb data structure.
1875 * This routine will call the clear rrq function to free the rrq and
1876 * clear the xri's bit in the ndlp's xri_bitmap. If the ndlp does not
1877 * exist then the clear_rrq is still called because the rrq needs to
1882 lpfc_cmpl_els_rrq(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1883 struct lpfc_iocbq *rspiocb)
1885 struct lpfc_vport *vport = cmdiocb->vport;
1887 struct lpfc_nodelist *ndlp;
1888 struct lpfc_node_rrq *rrq;
1890 /* we pass cmdiocb to state machine which needs rspiocb as well */
1891 rrq = cmdiocb->context_un.rrq;
1892 cmdiocb->context_un.rsp_iocb = rspiocb;
1894 irsp = &rspiocb->iocb;
1895 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1896 "RRQ cmpl: status:x%x/x%x did:x%x",
1897 irsp->ulpStatus, irsp->un.ulpWord[4],
1898 irsp->un.elsreq64.remoteID);
1900 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
1901 if (!ndlp || ndlp != rrq->ndlp) {
1902 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1903 "2882 RRQ completes to NPort x%x "
1904 "with no ndlp. Data: x%x x%x x%x\n",
1905 irsp->un.elsreq64.remoteID,
1906 irsp->ulpStatus, irsp->un.ulpWord[4],
1911 /* rrq completes to NPort <nlp_DID> */
1912 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1913 "2880 RRQ completes to NPort x%x "
1914 "Data: x%x x%x x%x x%x x%x\n",
1915 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1916 irsp->ulpTimeout, rrq->xritag, rrq->rxid);
1918 if (irsp->ulpStatus) {
1919 /* Check for retry */
1920 /* RRQ failed Don't print the vport to vport rjts */
1921 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1922 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1923 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1924 (phba)->pport->cfg_log_verbose & LOG_ELS)
1925 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1926 "2881 RRQ failure DID:%06X Status:"
1928 ndlp->nlp_DID, irsp->ulpStatus,
1929 irsp->un.ulpWord[4]);
1933 lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
1935 lpfc_els_free_iocb(phba, cmdiocb);
1940 * lpfc_cmpl_els_plogi - Completion callback function for plogi
1941 * @phba: pointer to lpfc hba data structure.
1942 * @cmdiocb: pointer to lpfc command iocb data structure.
1943 * @rspiocb: pointer to lpfc response iocb data structure.
1945 * This routine is the completion callback function for issuing the Port
1946 * Login (PLOGI) command. For PLOGI completion, there must be an active
1947 * ndlp on the vport node list that matches the remote node ID from the
1948 * PLOGI response IOCB. If such ndlp does not exist, the PLOGI is simply
1949 * ignored and command IOCB released. The PLOGI response IOCB status is
1950 * checked for error conditons. If there is error status reported, PLOGI
1951 * retry shall be attempted by invoking the lpfc_els_retry() routine.
1952 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1953 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1954 * (DSM) is set for this PLOGI completion. Finally, it checks whether
1955 * there are additional N_Port nodes with the vport that need to perform
1956 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
1960 lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1961 struct lpfc_iocbq *rspiocb)
1963 struct lpfc_vport *vport = cmdiocb->vport;
1964 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1966 struct lpfc_nodelist *ndlp, *free_ndlp;
1967 struct lpfc_dmabuf *prsp;
1970 /* we pass cmdiocb to state machine which needs rspiocb as well */
1971 cmdiocb->context_un.rsp_iocb = rspiocb;
1973 irsp = &rspiocb->iocb;
1974 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1975 "PLOGI cmpl: status:x%x/x%x did:x%x",
1976 irsp->ulpStatus, irsp->un.ulpWord[4],
1977 irsp->un.elsreq64.remoteID);
1979 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
1981 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1982 "0136 PLOGI completes to NPort x%x "
1983 "with no ndlp. Data: x%x x%x x%x\n",
1984 irsp->un.elsreq64.remoteID,
1985 irsp->ulpStatus, irsp->un.ulpWord[4],
1990 /* Since ndlp can be freed in the disc state machine, note if this node
1991 * is being used during discovery.
1993 spin_lock_irq(shost->host_lock);
1994 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
1995 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1996 spin_unlock_irq(shost->host_lock);
1998 /* PLOGI completes to NPort <nlp_DID> */
1999 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2000 "0102 PLOGI completes to NPort x%06x "
2001 "Data: x%x x%x x%x x%x x%x\n",
2002 ndlp->nlp_DID, ndlp->nlp_fc4_type,
2003 irsp->ulpStatus, irsp->un.ulpWord[4],
2004 disc, vport->num_disc_nodes);
2006 /* Check to see if link went down during discovery */
2007 if (lpfc_els_chk_latt(vport)) {
2008 spin_lock_irq(shost->host_lock);
2009 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2010 spin_unlock_irq(shost->host_lock);
2014 if (irsp->ulpStatus) {
2015 /* Check for retry */
2016 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2017 /* ELS command is being retried */
2019 spin_lock_irq(shost->host_lock);
2020 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2021 spin_unlock_irq(shost->host_lock);
2025 /* PLOGI failed Don't print the vport to vport rjts */
2026 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
2027 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
2028 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
2029 (phba)->pport->cfg_log_verbose & LOG_ELS)
2030 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
2031 "2753 PLOGI failure DID:%06X Status:x%x/x%x\n",
2032 ndlp->nlp_DID, irsp->ulpStatus,
2033 irsp->un.ulpWord[4]);
2034 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2035 if (!lpfc_error_lost_link(irsp))
2036 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2037 NLP_EVT_CMPL_PLOGI);
2039 /* Good status, call state machine */
2040 prsp = list_entry(((struct lpfc_dmabuf *)
2041 cmdiocb->context2)->list.next,
2042 struct lpfc_dmabuf, list);
2043 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
2044 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2045 NLP_EVT_CMPL_PLOGI);
2048 if (disc && vport->num_disc_nodes) {
2049 /* Check to see if there are more PLOGIs to be sent */
2050 lpfc_more_plogi(vport);
2052 if (vport->num_disc_nodes == 0) {
2053 spin_lock_irq(shost->host_lock);
2054 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2055 spin_unlock_irq(shost->host_lock);
2057 lpfc_can_disctmo(vport);
2058 lpfc_end_rscn(vport);
2063 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
2064 "PLOGI Cmpl PUT: did:x%x refcnt %d",
2065 ndlp->nlp_DID, kref_read(&ndlp->kref), 0);
2067 /* Release the reference on the original I/O request. */
2068 free_ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
2070 lpfc_els_free_iocb(phba, cmdiocb);
2071 lpfc_nlp_put(free_ndlp);
2076 * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
2077 * @vport: pointer to a host virtual N_Port data structure.
2078 * @did: destination port identifier.
2079 * @retry: number of retries to the command IOCB.
2081 * This routine issues a Port Login (PLOGI) command to a remote N_Port
2082 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
2083 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
2084 * This routine constructs the proper feilds of the PLOGI IOCB and invokes
2085 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
2087 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2088 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2089 * will be stored into the context1 field of the IOCB for the completion
2090 * callback function to the PLOGI ELS command.
2093 * 0 - Successfully issued a plogi for @vport
2094 * 1 - failed to issue a plogi for @vport
2097 lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
2099 struct lpfc_hba *phba = vport->phba;
2100 struct Scsi_Host *shost;
2101 struct serv_parm *sp;
2102 struct lpfc_nodelist *ndlp;
2103 struct lpfc_iocbq *elsiocb;
2108 ndlp = lpfc_findnode_did(vport, did);
2111 /* Defer the processing of the issue PLOGI until after the
2112 * outstanding UNREG_RPI mbox command completes, unless we
2113 * are going offline. This logic does not apply for Fabric DIDs
2115 if ((ndlp->nlp_flag & NLP_UNREG_INP) &&
2116 ((ndlp->nlp_DID & Fabric_DID_MASK) != Fabric_DID_MASK) &&
2117 !(vport->fc_flag & FC_OFFLINE_MODE)) {
2118 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2119 "4110 Issue PLOGI x%x deferred "
2120 "on NPort x%x rpi x%x Data: x%px\n",
2121 ndlp->nlp_defer_did, ndlp->nlp_DID,
2122 ndlp->nlp_rpi, ndlp);
2124 /* We can only defer 1st PLOGI */
2125 if (ndlp->nlp_defer_did == NLP_EVT_NOTHING_PENDING)
2126 ndlp->nlp_defer_did = did;
2131 /* If ndlp is not NULL, we will bump the reference count on it */
2132 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
2133 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
2138 shost = lpfc_shost_from_vport(vport);
2139 spin_lock_irq(shost->host_lock);
2140 ndlp->nlp_flag &= ~NLP_FCP_PRLI_RJT;
2141 spin_unlock_irq(shost->host_lock);
2143 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2145 /* For PLOGI request, remainder of payload is service parameters */
2146 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
2147 pcmd += sizeof(uint32_t);
2148 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
2149 sp = (struct serv_parm *) pcmd;
2152 * If we are a N-port connected to a Fabric, fix-up paramm's so logins
2153 * to device on remote loops work.
2155 if ((vport->fc_flag & FC_FABRIC) && !(vport->fc_flag & FC_PUBLIC_LOOP))
2156 sp->cmn.altBbCredit = 1;
2158 if (sp->cmn.fcphLow < FC_PH_4_3)
2159 sp->cmn.fcphLow = FC_PH_4_3;
2161 if (sp->cmn.fcphHigh < FC_PH3)
2162 sp->cmn.fcphHigh = FC_PH3;
2164 sp->cmn.valid_vendor_ver_level = 0;
2165 memset(sp->un.vendorVersion, 0, sizeof(sp->un.vendorVersion));
2166 sp->cmn.bbRcvSizeMsb &= 0xF;
2168 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2169 "Issue PLOGI: did:x%x",
2172 /* If our firmware supports this feature, convey that
2173 * information to the target using the vendor specific field.
2175 if (phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) {
2176 sp->cmn.valid_vendor_ver_level = 1;
2177 sp->un.vv.vid = cpu_to_be32(LPFC_VV_EMLX_ID);
2178 sp->un.vv.flags = cpu_to_be32(LPFC_VV_SUPPRESS_RSP);
2181 phba->fc_stat.elsXmitPLOGI++;
2182 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
2184 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2185 "Issue PLOGI: did:x%x refcnt %d",
2186 did, kref_read(&ndlp->kref), 0);
2187 elsiocb->context1 = lpfc_nlp_get(ndlp);
2188 if (!elsiocb->context1)
2191 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
2199 lpfc_els_free_iocb(phba, elsiocb);
2204 * lpfc_cmpl_els_prli - Completion callback function for prli
2205 * @phba: pointer to lpfc hba data structure.
2206 * @cmdiocb: pointer to lpfc command iocb data structure.
2207 * @rspiocb: pointer to lpfc response iocb data structure.
2209 * This routine is the completion callback function for a Process Login
2210 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
2211 * status. If there is error status reported, PRLI retry shall be attempted
2212 * by invoking the lpfc_els_retry() routine. Otherwise, the state
2213 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
2214 * ndlp to mark the PRLI completion.
2217 lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2218 struct lpfc_iocbq *rspiocb)
2220 struct lpfc_vport *vport = cmdiocb->vport;
2221 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2223 struct lpfc_nodelist *ndlp;
2227 /* we pass cmdiocb to state machine which needs rspiocb as well */
2228 cmdiocb->context_un.rsp_iocb = rspiocb;
2230 irsp = &(rspiocb->iocb);
2231 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2232 spin_lock_irq(shost->host_lock);
2233 ndlp->nlp_flag &= ~NLP_PRLI_SND;
2235 /* Driver supports multiple FC4 types. Counters matter. */
2236 vport->fc_prli_sent--;
2237 ndlp->fc4_prli_sent--;
2238 spin_unlock_irq(shost->host_lock);
2240 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2241 "PRLI cmpl: status:x%x/x%x did:x%x",
2242 irsp->ulpStatus, irsp->un.ulpWord[4],
2245 /* PRLI completes to NPort <nlp_DID> */
2246 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2247 "0103 PRLI completes to NPort x%06x "
2248 "Data: x%x x%x x%x x%x\n",
2249 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2250 vport->num_disc_nodes, ndlp->fc4_prli_sent);
2252 /* Check to see if link went down during discovery */
2253 if (lpfc_els_chk_latt(vport))
2256 if (irsp->ulpStatus) {
2257 /* Check for retry */
2258 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2259 /* ELS command is being retried */
2263 /* If we don't send GFT_ID to Fabric, a PRLI error
2264 * could be expected.
2266 if ((vport->fc_flag & FC_FABRIC) ||
2267 (vport->cfg_enable_fc4_type != LPFC_ENABLE_BOTH)) {
2269 loglevel = LOG_TRACE_EVENT;
2276 lpfc_printf_vlog(vport, mode, loglevel,
2277 "2754 PRLI failure DID:%06X Status:x%x/x%x, "
2279 ndlp->nlp_DID, irsp->ulpStatus,
2280 irsp->un.ulpWord[4], ndlp->fc4_prli_sent);
2282 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2283 if (lpfc_error_lost_link(irsp))
2286 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2289 /* Good status, call state machine. However, if another
2290 * PRLI is outstanding, don't call the state machine
2291 * because final disposition to Mapped or Unmapped is
2294 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2299 lpfc_els_free_iocb(phba, cmdiocb);
2305 * lpfc_issue_els_prli - Issue a prli iocb command for a vport
2306 * @vport: pointer to a host virtual N_Port data structure.
2307 * @ndlp: pointer to a node-list data structure.
2308 * @retry: number of retries to the command IOCB.
2310 * This routine issues a Process Login (PRLI) ELS command for the
2311 * @vport. The PRLI service parameters are set up in the payload of the
2312 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
2313 * is put to the IOCB completion callback func field before invoking the
2314 * routine lpfc_sli_issue_iocb() to send out PRLI command.
2316 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2317 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2318 * will be stored into the context1 field of the IOCB for the completion
2319 * callback function to the PRLI ELS command.
2322 * 0 - successfully issued prli iocb command for @vport
2323 * 1 - failed to issue prli iocb command for @vport
2326 lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2330 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2331 struct lpfc_hba *phba = vport->phba;
2333 struct lpfc_nvme_prli *npr_nvme;
2334 struct lpfc_iocbq *elsiocb;
2337 u32 local_nlp_type, elscmd;
2340 * If we are in RSCN mode, the FC4 types supported from a
2341 * previous GFT_ID command may not be accurate. So, if we
2342 * are a NVME Initiator, always look for the possibility of
2343 * the remote NPort beng a NVME Target.
2345 if (phba->sli_rev == LPFC_SLI_REV4 &&
2346 vport->fc_flag & FC_RSCN_MODE &&
2347 vport->nvmei_support)
2348 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
2349 local_nlp_type = ndlp->nlp_fc4_type;
2351 /* This routine will issue 1 or 2 PRLIs, so zero all the ndlp
2352 * fields here before any of them can complete.
2354 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
2355 ndlp->nlp_type &= ~(NLP_NVME_TARGET | NLP_NVME_INITIATOR);
2356 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
2357 ndlp->nlp_flag &= ~(NLP_FIRSTBURST | NLP_NPR_2B_DISC);
2358 ndlp->nvme_fb_size = 0;
2361 if (local_nlp_type & NLP_FC4_FCP) {
2362 /* Payload is 4 + 16 = 20 x14 bytes. */
2363 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
2364 elscmd = ELS_CMD_PRLI;
2365 } else if (local_nlp_type & NLP_FC4_NVME) {
2366 /* Payload is 4 + 20 = 24 x18 bytes. */
2367 cmdsize = (sizeof(uint32_t) + sizeof(struct lpfc_nvme_prli));
2368 elscmd = ELS_CMD_NVMEPRLI;
2370 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2371 "3083 Unknown FC_TYPE x%x ndlp x%06x\n",
2372 ndlp->nlp_fc4_type, ndlp->nlp_DID);
2376 /* SLI3 ports don't support NVME. If this rport is a strict NVME
2377 * FC4 type, implicitly LOGO.
2379 if (phba->sli_rev == LPFC_SLI_REV3 &&
2380 ndlp->nlp_fc4_type == NLP_FC4_NVME) {
2381 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2382 "3088 Rport fc4 type 0x%x not supported by SLI3 adapter\n",
2384 lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM);
2388 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2389 ndlp->nlp_DID, elscmd);
2393 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2395 /* For PRLI request, remainder of payload is service parameters */
2396 memset(pcmd, 0, cmdsize);
2398 if (local_nlp_type & NLP_FC4_FCP) {
2399 /* Remainder of payload is FCP PRLI parameter page.
2400 * Note: this data structure is defined as
2401 * BE/LE in the structure definition so no
2402 * byte swap call is made.
2404 *((uint32_t *)(pcmd)) = ELS_CMD_PRLI;
2405 pcmd += sizeof(uint32_t);
2409 * If our firmware version is 3.20 or later,
2410 * set the following bits for FC-TAPE support.
2412 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
2413 npr->ConfmComplAllowed = 1;
2415 npr->TaskRetryIdReq = 1;
2417 npr->estabImagePair = 1;
2418 npr->readXferRdyDis = 1;
2419 if (vport->cfg_first_burst_size)
2420 npr->writeXferRdyDis = 1;
2422 /* For FCP support */
2423 npr->prliType = PRLI_FCP_TYPE;
2424 npr->initiatorFunc = 1;
2425 elsiocb->iocb_flag |= LPFC_PRLI_FCP_REQ;
2427 /* Remove FCP type - processed. */
2428 local_nlp_type &= ~NLP_FC4_FCP;
2429 } else if (local_nlp_type & NLP_FC4_NVME) {
2430 /* Remainder of payload is NVME PRLI parameter page.
2431 * This data structure is the newer definition that
2432 * uses bf macros so a byte swap is required.
2434 *((uint32_t *)(pcmd)) = ELS_CMD_NVMEPRLI;
2435 pcmd += sizeof(uint32_t);
2436 npr_nvme = (struct lpfc_nvme_prli *)pcmd;
2437 bf_set(prli_type_code, npr_nvme, PRLI_NVME_TYPE);
2438 bf_set(prli_estabImagePair, npr_nvme, 0); /* Should be 0 */
2440 bf_set(prli_nsler, npr_nvme, 1);
2441 bf_set(prli_conf, npr_nvme, 1);
2444 /* Only initiators request first burst. */
2445 if ((phba->cfg_nvme_enable_fb) &&
2446 !phba->nvmet_support)
2447 bf_set(prli_fba, npr_nvme, 1);
2449 if (phba->nvmet_support) {
2450 bf_set(prli_tgt, npr_nvme, 1);
2451 bf_set(prli_disc, npr_nvme, 1);
2453 bf_set(prli_init, npr_nvme, 1);
2454 bf_set(prli_conf, npr_nvme, 1);
2457 npr_nvme->word1 = cpu_to_be32(npr_nvme->word1);
2458 npr_nvme->word4 = cpu_to_be32(npr_nvme->word4);
2459 elsiocb->iocb_flag |= LPFC_PRLI_NVME_REQ;
2461 /* Remove NVME type - processed. */
2462 local_nlp_type &= ~NLP_FC4_NVME;
2465 phba->fc_stat.elsXmitPRLI++;
2466 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
2467 spin_lock_irq(shost->host_lock);
2468 ndlp->nlp_flag |= NLP_PRLI_SND;
2470 /* The vport counters are used for lpfc_scan_finished, but
2471 * the ndlp is used to track outstanding PRLIs for different
2474 vport->fc_prli_sent++;
2475 ndlp->fc4_prli_sent++;
2476 spin_unlock_irq(shost->host_lock);
2478 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2479 "Issue PRLI: did:x%x refcnt %d",
2480 ndlp->nlp_DID, kref_read(&ndlp->kref), 0);
2481 elsiocb->context1 = lpfc_nlp_get(ndlp);
2482 if (!elsiocb->context1)
2485 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
2486 if (rc == IOCB_ERROR)
2490 /* The driver supports 2 FC4 types. Make sure
2491 * a PRLI is issued for all types before exiting.
2493 if (phba->sli_rev == LPFC_SLI_REV4 &&
2494 local_nlp_type & (NLP_FC4_FCP | NLP_FC4_NVME))
2495 goto send_next_prli;
2502 spin_lock_irq(shost->host_lock);
2503 ndlp->nlp_flag &= ~NLP_PRLI_SND;
2504 spin_unlock_irq(shost->host_lock);
2505 lpfc_els_free_iocb(phba, elsiocb);
2510 * lpfc_rscn_disc - Perform rscn discovery for a vport
2511 * @vport: pointer to a host virtual N_Port data structure.
2513 * This routine performs Registration State Change Notification (RSCN)
2514 * discovery for a @vport. If the @vport's node port recovery count is not
2515 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
2516 * the nodes that need recovery. If none of the PLOGI were needed through
2517 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
2518 * invoked to check and handle possible more RSCN came in during the period
2519 * of processing the current ones.
2522 lpfc_rscn_disc(struct lpfc_vport *vport)
2524 lpfc_can_disctmo(vport);
2526 /* RSCN discovery */
2527 /* go thru NPR nodes and issue ELS PLOGIs */
2528 if (vport->fc_npr_cnt)
2529 if (lpfc_els_disc_plogi(vport))
2532 lpfc_end_rscn(vport);
2536 * lpfc_adisc_done - Complete the adisc phase of discovery
2537 * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
2539 * This function is called when the final ADISC is completed during discovery.
2540 * This function handles clearing link attention or issuing reg_vpi depending
2541 * on whether npiv is enabled. This function also kicks off the PLOGI phase of
2543 * This function is called with no locks held.
2546 lpfc_adisc_done(struct lpfc_vport *vport)
2548 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2549 struct lpfc_hba *phba = vport->phba;
2552 * For NPIV, cmpl_reg_vpi will set port_state to READY,
2553 * and continue discovery.
2555 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2556 !(vport->fc_flag & FC_RSCN_MODE) &&
2557 (phba->sli_rev < LPFC_SLI_REV4)) {
2558 /* The ADISCs are complete. Doesn't matter if they
2559 * succeeded or failed because the ADISC completion
2560 * routine guarantees to call the state machine and
2561 * the RPI is either unregistered (failed ADISC response)
2562 * or the RPI is still valid and the node is marked
2563 * mapped for a target. The exchanges should be in the
2564 * correct state. This code is specific to SLI3.
2566 lpfc_issue_clear_la(phba, vport);
2567 lpfc_issue_reg_vpi(phba, vport);
2571 * For SLI2, we need to set port_state to READY
2572 * and continue discovery.
2574 if (vport->port_state < LPFC_VPORT_READY) {
2575 /* If we get here, there is nothing to ADISC */
2576 lpfc_issue_clear_la(phba, vport);
2577 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
2578 vport->num_disc_nodes = 0;
2579 /* go thru NPR list, issue ELS PLOGIs */
2580 if (vport->fc_npr_cnt)
2581 lpfc_els_disc_plogi(vport);
2582 if (!vport->num_disc_nodes) {
2583 spin_lock_irq(shost->host_lock);
2584 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2585 spin_unlock_irq(shost->host_lock);
2586 lpfc_can_disctmo(vport);
2587 lpfc_end_rscn(vport);
2590 vport->port_state = LPFC_VPORT_READY;
2592 lpfc_rscn_disc(vport);
2596 * lpfc_more_adisc - Issue more adisc as needed
2597 * @vport: pointer to a host virtual N_Port data structure.
2599 * This routine determines whether there are more ndlps on a @vport
2600 * node list need to have Address Discover (ADISC) issued. If so, it will
2601 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
2602 * remaining nodes which need to have ADISC sent.
2605 lpfc_more_adisc(struct lpfc_vport *vport)
2607 if (vport->num_disc_nodes)
2608 vport->num_disc_nodes--;
2609 /* Continue discovery with <num_disc_nodes> ADISCs to go */
2610 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2611 "0210 Continue discovery with %d ADISCs to go "
2612 "Data: x%x x%x x%x\n",
2613 vport->num_disc_nodes, vport->fc_adisc_cnt,
2614 vport->fc_flag, vport->port_state);
2615 /* Check to see if there are more ADISCs to be sent */
2616 if (vport->fc_flag & FC_NLP_MORE) {
2617 lpfc_set_disctmo(vport);
2618 /* go thru NPR nodes and issue any remaining ELS ADISCs */
2619 lpfc_els_disc_adisc(vport);
2621 if (!vport->num_disc_nodes)
2622 lpfc_adisc_done(vport);
2627 * lpfc_cmpl_els_adisc - Completion callback function for adisc
2628 * @phba: pointer to lpfc hba data structure.
2629 * @cmdiocb: pointer to lpfc command iocb data structure.
2630 * @rspiocb: pointer to lpfc response iocb data structure.
2632 * This routine is the completion function for issuing the Address Discover
2633 * (ADISC) command. It first checks to see whether link went down during
2634 * the discovery process. If so, the node will be marked as node port
2635 * recovery for issuing discover IOCB by the link attention handler and
2636 * exit. Otherwise, the response status is checked. If error was reported
2637 * in the response status, the ADISC command shall be retried by invoking
2638 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
2639 * the response status, the state machine is invoked to set transition
2640 * with respect to NLP_EVT_CMPL_ADISC event.
2643 lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2644 struct lpfc_iocbq *rspiocb)
2646 struct lpfc_vport *vport = cmdiocb->vport;
2647 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2649 struct lpfc_nodelist *ndlp;
2652 /* we pass cmdiocb to state machine which needs rspiocb as well */
2653 cmdiocb->context_un.rsp_iocb = rspiocb;
2655 irsp = &(rspiocb->iocb);
2656 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2658 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2659 "ADISC cmpl: status:x%x/x%x did:x%x",
2660 irsp->ulpStatus, irsp->un.ulpWord[4],
2663 /* Since ndlp can be freed in the disc state machine, note if this node
2664 * is being used during discovery.
2666 spin_lock_irq(shost->host_lock);
2667 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
2668 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
2669 spin_unlock_irq(shost->host_lock);
2670 /* ADISC completes to NPort <nlp_DID> */
2671 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2672 "0104 ADISC completes to NPort x%x "
2673 "Data: x%x x%x x%x x%x x%x\n",
2674 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2675 irsp->ulpTimeout, disc, vport->num_disc_nodes);
2676 /* Check to see if link went down during discovery */
2677 if (lpfc_els_chk_latt(vport)) {
2678 spin_lock_irq(shost->host_lock);
2679 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2680 spin_unlock_irq(shost->host_lock);
2684 if (irsp->ulpStatus) {
2685 /* Check for retry */
2686 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2687 /* ELS command is being retried */
2689 spin_lock_irq(shost->host_lock);
2690 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2691 spin_unlock_irq(shost->host_lock);
2692 lpfc_set_disctmo(vport);
2697 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
2698 "2755 ADISC failure DID:%06X Status:x%x/x%x\n",
2699 ndlp->nlp_DID, irsp->ulpStatus,
2700 irsp->un.ulpWord[4]);
2701 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2702 if (!lpfc_error_lost_link(irsp))
2703 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2704 NLP_EVT_CMPL_ADISC);
2706 /* Good status, call state machine */
2707 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2708 NLP_EVT_CMPL_ADISC);
2710 /* Check to see if there are more ADISCs to be sent */
2711 if (disc && vport->num_disc_nodes)
2712 lpfc_more_adisc(vport);
2714 lpfc_els_free_iocb(phba, cmdiocb);
2720 * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
2721 * @vport: pointer to a virtual N_Port data structure.
2722 * @ndlp: pointer to a node-list data structure.
2723 * @retry: number of retries to the command IOCB.
2725 * This routine issues an Address Discover (ADISC) for an @ndlp on a
2726 * @vport. It prepares the payload of the ADISC ELS command, updates the
2727 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
2728 * to issue the ADISC ELS command.
2730 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2731 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2732 * will be stored into the context1 field of the IOCB for the completion
2733 * callback function to the ADISC ELS command.
2736 * 0 - successfully issued adisc
2737 * 1 - failed to issue adisc
2740 lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2744 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2745 struct lpfc_hba *phba = vport->phba;
2747 struct lpfc_iocbq *elsiocb;
2751 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
2752 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2753 ndlp->nlp_DID, ELS_CMD_ADISC);
2757 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2759 /* For ADISC request, remainder of payload is service parameters */
2760 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
2761 pcmd += sizeof(uint32_t);
2763 /* Fill in ADISC payload */
2764 ap = (ADISC *) pcmd;
2765 ap->hardAL_PA = phba->fc_pref_ALPA;
2766 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2767 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
2768 ap->DID = be32_to_cpu(vport->fc_myDID);
2770 phba->fc_stat.elsXmitADISC++;
2771 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
2772 spin_lock_irq(shost->host_lock);
2773 ndlp->nlp_flag |= NLP_ADISC_SND;
2774 spin_unlock_irq(shost->host_lock);
2775 elsiocb->context1 = lpfc_nlp_get(ndlp);
2776 if (!elsiocb->context1)
2779 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2780 "Issue ADISC: did:x%x refcnt %d",
2781 ndlp->nlp_DID, kref_read(&ndlp->kref), 0);
2782 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
2783 if (rc == IOCB_ERROR)
2790 spin_lock_irq(shost->host_lock);
2791 ndlp->nlp_flag &= ~NLP_ADISC_SND;
2792 spin_unlock_irq(shost->host_lock);
2793 lpfc_els_free_iocb(phba, elsiocb);
2798 * lpfc_cmpl_els_logo - Completion callback function for logo
2799 * @phba: pointer to lpfc hba data structure.
2800 * @cmdiocb: pointer to lpfc command iocb data structure.
2801 * @rspiocb: pointer to lpfc response iocb data structure.
2803 * This routine is the completion function for issuing the ELS Logout (LOGO)
2804 * command. If no error status was reported from the LOGO response, the
2805 * state machine of the associated ndlp shall be invoked for transition with
2806 * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
2807 * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
2810 lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2811 struct lpfc_iocbq *rspiocb)
2813 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2814 struct lpfc_vport *vport = ndlp->vport;
2815 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2817 struct lpfcMboxq *mbox;
2818 unsigned long flags;
2819 uint32_t skip_recovery = 0;
2821 /* we pass cmdiocb to state machine which needs rspiocb as well */
2822 cmdiocb->context_un.rsp_iocb = rspiocb;
2824 irsp = &(rspiocb->iocb);
2825 spin_lock_irq(shost->host_lock);
2826 ndlp->nlp_flag &= ~NLP_LOGO_SND;
2827 spin_unlock_irq(shost->host_lock);
2829 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2830 "LOGO cmpl: status:x%x/x%x did:x%x",
2831 irsp->ulpStatus, irsp->un.ulpWord[4],
2834 /* LOGO completes to NPort <nlp_DID> */
2835 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2836 "0105 LOGO completes to NPort x%x "
2837 "Data: x%x x%x x%x x%x\n",
2838 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2839 irsp->ulpTimeout, vport->num_disc_nodes);
2841 if (lpfc_els_chk_latt(vport)) {
2846 /* Check to see if link went down during discovery */
2847 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
2848 /* NLP_EVT_DEVICE_RM should unregister the RPI
2849 * which should abort all outstanding IOs.
2851 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2857 /* The LOGO will not be retried on failure. A LOGO was
2858 * issued to the remote rport and a ACC or RJT or no Answer are
2859 * all acceptable. Note the failure and move forward with
2860 * discovery. The PLOGI will retry.
2862 if (irsp->ulpStatus) {
2864 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
2865 "2756 LOGO failure, No Retry DID:%06X Status:x%x/x%x\n",
2866 ndlp->nlp_DID, irsp->ulpStatus,
2867 irsp->un.ulpWord[4]);
2868 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2869 if (lpfc_error_lost_link(irsp)) {
2875 /* Call state machine. This will unregister the rpi if needed. */
2876 lpfc_disc_state_machine(vport, ndlp, cmdiocb, NLP_EVT_CMPL_LOGO);
2879 /* Driver is done with the IO. */
2880 lpfc_els_free_iocb(phba, cmdiocb);
2883 /* If we are in pt2pt mode, we could rcv new S_ID on PLOGI */
2884 if ((vport->fc_flag & FC_PT2PT) &&
2885 !(vport->fc_flag & FC_PT2PT_PLOGI)) {
2886 phba->pport->fc_myDID = 0;
2888 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
2889 (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
2890 if (phba->nvmet_support)
2891 lpfc_nvmet_update_targetport(phba);
2893 lpfc_nvme_update_localport(phba->pport);
2896 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2898 lpfc_config_link(phba, mbox);
2899 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
2900 mbox->vport = vport;
2901 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) ==
2903 mempool_free(mbox, phba->mbox_mem_pool);
2910 * If the node is a target, the handling attempts to recover the port.
2911 * For any other port type, the rpi is unregistered as an implicit
2914 if (ndlp->nlp_type & (NLP_FCP_TARGET | NLP_NVME_TARGET) &&
2915 skip_recovery == 0) {
2916 lpfc_cancel_retry_delay_tmo(vport, ndlp);
2917 spin_lock_irqsave(shost->host_lock, flags);
2918 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2919 spin_unlock_irqrestore(shost->host_lock, flags);
2921 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2922 "3187 LOGO completes to NPort x%x: Start "
2923 "Recovery Data: x%x x%x x%x x%x\n",
2924 ndlp->nlp_DID, irsp->ulpStatus,
2925 irsp->un.ulpWord[4], irsp->ulpTimeout,
2926 vport->num_disc_nodes);
2927 lpfc_disc_start(vport);
2933 * lpfc_issue_els_logo - Issue a logo to an node on a vport
2934 * @vport: pointer to a virtual N_Port data structure.
2935 * @ndlp: pointer to a node-list data structure.
2936 * @retry: number of retries to the command IOCB.
2938 * This routine constructs and issues an ELS Logout (LOGO) iocb command
2939 * to a remote node, referred by an @ndlp on a @vport. It constructs the
2940 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
2941 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
2943 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2944 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2945 * will be stored into the context1 field of the IOCB for the completion
2946 * callback function to the LOGO ELS command.
2948 * Callers of this routine are expected to unregister the RPI first
2951 * 0 - successfully issued logo
2952 * 1 - failed to issue logo
2955 lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2958 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2959 struct lpfc_hba *phba = vport->phba;
2960 struct lpfc_iocbq *elsiocb;
2965 spin_lock_irq(shost->host_lock);
2966 if (ndlp->nlp_flag & NLP_LOGO_SND) {
2967 spin_unlock_irq(shost->host_lock);
2970 spin_unlock_irq(shost->host_lock);
2972 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
2973 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2974 ndlp->nlp_DID, ELS_CMD_LOGO);
2978 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2979 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
2980 pcmd += sizeof(uint32_t);
2982 /* Fill in LOGO payload */
2983 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
2984 pcmd += sizeof(uint32_t);
2985 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
2987 phba->fc_stat.elsXmitLOGO++;
2988 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
2989 spin_lock_irq(shost->host_lock);
2990 ndlp->nlp_flag |= NLP_LOGO_SND;
2991 ndlp->nlp_flag &= ~NLP_ISSUE_LOGO;
2992 spin_unlock_irq(shost->host_lock);
2993 elsiocb->context1 = lpfc_nlp_get(ndlp);
2994 if (!elsiocb->context1)
2997 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2998 "Issue LOGO: did:x%x refcnt %d",
2999 ndlp->nlp_DID, kref_read(&ndlp->kref), 0);
3000 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
3001 if (rc == IOCB_ERROR)
3004 spin_lock_irq(shost->host_lock);
3005 ndlp->nlp_prev_state = ndlp->nlp_state;
3006 spin_unlock_irq(shost->host_lock);
3007 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
3013 spin_lock_irq(shost->host_lock);
3014 ndlp->nlp_flag &= ~NLP_LOGO_SND;
3015 spin_unlock_irq(shost->host_lock);
3016 lpfc_els_free_iocb(phba, elsiocb);
3021 * lpfc_cmpl_els_cmd - Completion callback function for generic els command
3022 * @phba: pointer to lpfc hba data structure.
3023 * @cmdiocb: pointer to lpfc command iocb data structure.
3024 * @rspiocb: pointer to lpfc response iocb data structure.
3026 * This routine is a generic completion callback function for ELS commands.
3027 * Specifically, it is the callback function which does not need to perform
3028 * any command specific operations. It is currently used by the ELS command
3029 * issuing routines for RSCN, lpfc_issue_els_rscn, and the ELS Fibre Channel
3030 * Address Resolution Protocol Response (FARPR) routine, lpfc_issue_els_farpr().
3031 * Other than certain debug loggings, this callback function simply invokes the
3032 * lpfc_els_chk_latt() routine to check whether link went down during the
3033 * discovery process.
3036 lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3037 struct lpfc_iocbq *rspiocb)
3039 struct lpfc_vport *vport = cmdiocb->vport;
3040 struct lpfc_nodelist *free_ndlp;
3043 irsp = &rspiocb->iocb;
3045 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3046 "ELS cmd cmpl: status:x%x/x%x did:x%x",
3047 irsp->ulpStatus, irsp->un.ulpWord[4],
3048 irsp->un.elsreq64.remoteID);
3050 /* ELS cmd tag <ulpIoTag> completes */
3051 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3052 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
3053 irsp->ulpIoTag, irsp->ulpStatus,
3054 irsp->un.ulpWord[4], irsp->ulpTimeout);
3056 /* Check to see if link went down during discovery */
3057 lpfc_els_chk_latt(vport);
3059 free_ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
3061 lpfc_els_free_iocb(phba, cmdiocb);
3062 lpfc_nlp_put(free_ndlp);
3066 * lpfc_cmpl_els_disc_cmd - Completion callback function for Discovery ELS cmd
3067 * @phba: pointer to lpfc hba data structure.
3068 * @cmdiocb: pointer to lpfc command iocb data structure.
3069 * @rspiocb: pointer to lpfc response iocb data structure.
3071 * This routine is a generic completion callback function for Discovery ELS cmd.
3072 * Currently used by the ELS command issuing routines for the ELS State Change
3073 * Request (SCR), lpfc_issue_els_scr() and the ELS RDF, lpfc_issue_els_rdf().
3074 * These commands will be retried once only for ELS timeout errors.
3077 lpfc_cmpl_els_disc_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3078 struct lpfc_iocbq *rspiocb)
3080 struct lpfc_vport *vport = cmdiocb->vport;
3082 struct lpfc_els_rdf_rsp *prdf;
3083 struct lpfc_dmabuf *pcmd, *prsp;
3086 struct lpfc_nodelist *ndlp = cmdiocb->context1;
3088 irsp = &rspiocb->iocb;
3090 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3091 "ELS cmd cmpl: status:x%x/x%x did:x%x",
3092 irsp->ulpStatus, irsp->un.ulpWord[4],
3093 irsp->un.elsreq64.remoteID);
3094 /* ELS cmd tag <ulpIoTag> completes */
3095 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3096 "0217 ELS cmd tag x%x completes Data: x%x x%x x%x "
3098 irsp->ulpIoTag, irsp->ulpStatus,
3099 irsp->un.ulpWord[4], irsp->ulpTimeout,
3102 pcmd = (struct lpfc_dmabuf *)cmdiocb->context2;
3106 pdata = (u32 *)pcmd->virt;
3111 /* Only 1 retry for ELS Timeout only */
3112 if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT &&
3113 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
3114 IOERR_SEQUENCE_TIMEOUT)) {
3116 if (cmdiocb->retry <= 1) {
3119 lpfc_issue_els_scr(vport, cmdiocb->retry);
3122 cmdiocb->context1 = NULL; /* save ndlp refcnt */
3123 lpfc_issue_els_rdf(vport, cmdiocb->retry);
3128 phba->fc_stat.elsRetryExceeded++;
3130 if (irsp->ulpStatus) {
3131 /* ELS discovery cmd completes with error */
3132 lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS,
3133 "4203 ELS cmd x%x error: x%x x%X\n", cmd,
3134 irsp->ulpStatus, irsp->un.ulpWord[4]);
3138 /* The RDF response doesn't have any impact on the running driver
3139 * but the notification descriptors are dumped here for support.
3141 if (cmd == ELS_CMD_RDF) {
3144 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
3148 prdf = (struct lpfc_els_rdf_rsp *)prsp->virt;
3152 for (i = 0; i < ELS_RDF_REG_TAG_CNT &&
3153 i < be32_to_cpu(prdf->reg_d1.reg_desc.count); i++)
3154 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3155 "4677 Fabric RDF Notification Grant Data: "
3158 prdf->reg_d1.desc_tags[i]));
3162 /* Check to see if link went down during discovery */
3163 lpfc_els_chk_latt(vport);
3164 lpfc_els_free_iocb(phba, cmdiocb);
3170 * lpfc_issue_els_scr - Issue a scr to an node on a vport
3171 * @vport: pointer to a host virtual N_Port data structure.
3172 * @retry: retry counter for the command IOCB.
3174 * This routine issues a State Change Request (SCR) to a fabric node
3175 * on a @vport. The remote node is Fabric Controller (0xfffffd). It
3176 * first search the @vport node list to find the matching ndlp. If no such
3177 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
3178 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
3179 * routine is invoked to send the SCR IOCB.
3181 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3182 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3183 * will be stored into the context1 field of the IOCB for the completion
3184 * callback function to the SCR ELS command.
3187 * 0 - Successfully issued scr command
3188 * 1 - Failed to issue scr command
3191 lpfc_issue_els_scr(struct lpfc_vport *vport, uint8_t retry)
3194 struct lpfc_hba *phba = vport->phba;
3195 struct lpfc_iocbq *elsiocb;
3198 struct lpfc_nodelist *ndlp;
3200 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
3202 ndlp = lpfc_findnode_did(vport, Fabric_Cntl_DID);
3204 ndlp = lpfc_nlp_init(vport, Fabric_Cntl_DID);
3207 lpfc_enqueue_node(vport, ndlp);
3210 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
3211 ndlp->nlp_DID, ELS_CMD_SCR);
3216 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3218 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
3219 pcmd += sizeof(uint32_t);
3221 /* For SCR, remainder of payload is SCR parameter page */
3222 memset(pcmd, 0, sizeof(SCR));
3223 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
3225 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3226 "Issue SCR: did:x%x",
3227 ndlp->nlp_DID, 0, 0);
3229 phba->fc_stat.elsXmitSCR++;
3230 elsiocb->iocb_cmpl = lpfc_cmpl_els_disc_cmd;
3231 elsiocb->context1 = lpfc_nlp_get(ndlp);
3232 if (!elsiocb->context1)
3235 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3236 "Issue SCR: did:x%x refcnt %d",
3237 ndlp->nlp_DID, kref_read(&ndlp->kref), 0);
3239 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
3240 if (rc == IOCB_ERROR)
3243 /* Keep the ndlp just in case RDF is being sent */
3249 lpfc_els_free_iocb(phba, elsiocb);
3254 * lpfc_issue_els_rscn - Issue an RSCN to the Fabric Controller (Fabric)
3255 * or the other nport (pt2pt).
3256 * @vport: pointer to a host virtual N_Port data structure.
3257 * @retry: number of retries to the command IOCB.
3259 * This routine issues a RSCN to the Fabric Controller (DID 0xFFFFFD)
3260 * when connected to a fabric, or to the remote port when connected
3261 * in point-to-point mode. When sent to the Fabric Controller, it will
3262 * replay the RSCN to registered recipients.
3264 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3265 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3266 * will be stored into the context1 field of the IOCB for the completion
3267 * callback function to the RSCN ELS command.
3270 * 0 - Successfully issued RSCN command
3271 * 1 - Failed to issue RSCN command
3274 lpfc_issue_els_rscn(struct lpfc_vport *vport, uint8_t retry)
3277 struct lpfc_hba *phba = vport->phba;
3278 struct lpfc_iocbq *elsiocb;
3279 struct lpfc_nodelist *ndlp;
3281 struct fc_els_rscn rscn;
3282 struct fc_els_rscn_page portid;
3285 uint16_t cmdsize = sizeof(*event);
3287 /* Not supported for private loop */
3288 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP &&
3289 !(vport->fc_flag & FC_PUBLIC_LOOP))
3292 if (vport->fc_flag & FC_PT2PT) {
3293 /* find any mapped nport - that would be the other nport */
3294 ndlp = lpfc_findnode_mapped(vport);
3298 nportid = FC_FID_FCTRL;
3299 /* find the fabric controller node */
3300 ndlp = lpfc_findnode_did(vport, nportid);
3302 /* if one didn't exist, make one */
3303 ndlp = lpfc_nlp_init(vport, nportid);
3306 lpfc_enqueue_node(vport, ndlp);
3310 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
3311 ndlp->nlp_DID, ELS_CMD_RSCN_XMT);
3316 event = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
3318 event->rscn.rscn_cmd = ELS_RSCN;
3319 event->rscn.rscn_page_len = sizeof(struct fc_els_rscn_page);
3320 event->rscn.rscn_plen = cpu_to_be16(cmdsize);
3322 nportid = vport->fc_myDID;
3323 /* appears that page flags must be 0 for fabric to broadcast RSCN */
3324 event->portid.rscn_page_flags = 0;
3325 event->portid.rscn_fid[0] = (nportid & 0x00FF0000) >> 16;
3326 event->portid.rscn_fid[1] = (nportid & 0x0000FF00) >> 8;
3327 event->portid.rscn_fid[2] = nportid & 0x000000FF;
3329 phba->fc_stat.elsXmitRSCN++;
3330 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
3331 elsiocb->context1 = lpfc_nlp_get(ndlp);
3332 if (!elsiocb->context1)
3335 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3336 "Issue RSCN: did:x%x",
3337 ndlp->nlp_DID, 0, 0);
3339 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
3340 if (rc == IOCB_ERROR)
3343 /* This will cause the callback-function lpfc_cmpl_els_cmd to
3344 * trigger the release of node.
3346 if (!(vport->fc_flag & FC_PT2PT))
3352 lpfc_els_free_iocb(phba, elsiocb);
3357 * lpfc_issue_els_farpr - Issue a farp to an node on a vport
3358 * @vport: pointer to a host virtual N_Port data structure.
3359 * @nportid: N_Port identifier to the remote node.
3360 * @retry: number of retries to the command IOCB.
3362 * This routine issues a Fibre Channel Address Resolution Response
3363 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
3364 * is passed into the function. It first search the @vport node list to find
3365 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
3366 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
3367 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
3369 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3370 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3371 * will be stored into the context1 field of the IOCB for the completion
3372 * callback function to the PARPR ELS command.
3375 * 0 - Successfully issued farpr command
3376 * 1 - Failed to issue farpr command
3379 lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
3382 struct lpfc_hba *phba = vport->phba;
3383 struct lpfc_iocbq *elsiocb;
3388 struct lpfc_nodelist *ondlp;
3389 struct lpfc_nodelist *ndlp;
3391 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
3393 ndlp = lpfc_findnode_did(vport, nportid);
3395 ndlp = lpfc_nlp_init(vport, nportid);
3398 lpfc_enqueue_node(vport, ndlp);
3401 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
3402 ndlp->nlp_DID, ELS_CMD_RNID);
3406 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3408 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
3409 pcmd += sizeof(uint32_t);
3411 /* Fill in FARPR payload */
3412 fp = (FARP *) (pcmd);
3413 memset(fp, 0, sizeof(FARP));
3414 lp = (uint32_t *) pcmd;
3415 *lp++ = be32_to_cpu(nportid);
3416 *lp++ = be32_to_cpu(vport->fc_myDID);
3418 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
3420 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
3421 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
3422 ondlp = lpfc_findnode_did(vport, nportid);
3424 memcpy(&fp->OportName, &ondlp->nlp_portname,
3425 sizeof(struct lpfc_name));
3426 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
3427 sizeof(struct lpfc_name));
3430 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3431 "Issue FARPR: did:x%x",
3432 ndlp->nlp_DID, 0, 0);
3434 phba->fc_stat.elsXmitFARPR++;
3435 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
3436 elsiocb->context1 = lpfc_nlp_get(ndlp);
3437 if (!elsiocb->context1) {
3438 lpfc_els_free_iocb(phba, elsiocb);
3442 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
3443 if (rc == IOCB_ERROR) {
3444 /* The additional lpfc_nlp_put will cause the following
3445 * lpfc_els_free_iocb routine to trigger the release of
3449 lpfc_els_free_iocb(phba, elsiocb);
3452 /* This will cause the callback-function lpfc_cmpl_els_cmd to
3453 * trigger the release of the node.
3455 /* Don't release reference count as RDF is likely outstanding */
3460 * lpfc_issue_els_rdf - Register for diagnostic functions from the fabric.
3461 * @vport: pointer to a host virtual N_Port data structure.
3462 * @retry: retry counter for the command IOCB.
3464 * This routine issues an ELS RDF to the Fabric Controller to register
3465 * for diagnostic functions.
3467 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3468 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3469 * will be stored into the context1 field of the IOCB for the completion
3470 * callback function to the RDF ELS command.
3473 * 0 - Successfully issued rdf command
3474 * 1 - Failed to issue rdf command
3477 lpfc_issue_els_rdf(struct lpfc_vport *vport, uint8_t retry)
3479 struct lpfc_hba *phba = vport->phba;
3480 struct lpfc_iocbq *elsiocb;
3481 struct lpfc_els_rdf_req *prdf;
3482 struct lpfc_nodelist *ndlp;
3486 cmdsize = sizeof(*prdf);
3488 ndlp = lpfc_findnode_did(vport, Fabric_Cntl_DID);
3490 ndlp = lpfc_nlp_init(vport, Fabric_Cntl_DID);
3493 lpfc_enqueue_node(vport, ndlp);
3496 /* RDF ELS is not required on an NPIV VN_Port. */
3497 if (vport->port_type == LPFC_NPIV_PORT) {
3502 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
3503 ndlp->nlp_DID, ELS_CMD_RDF);
3507 /* Configure the payload for the supported FPIN events. */
3508 prdf = (struct lpfc_els_rdf_req *)
3509 (((struct lpfc_dmabuf *)elsiocb->context2)->virt);
3510 memset(prdf, 0, cmdsize);
3511 prdf->rdf.fpin_cmd = ELS_RDF;
3512 prdf->rdf.desc_len = cpu_to_be32(sizeof(struct lpfc_els_rdf_req) -
3513 sizeof(struct fc_els_rdf));
3514 prdf->reg_d1.reg_desc.desc_tag = cpu_to_be32(ELS_DTAG_FPIN_REGISTER);
3515 prdf->reg_d1.reg_desc.desc_len = cpu_to_be32(
3516 FC_TLV_DESC_LENGTH_FROM_SZ(prdf->reg_d1));
3517 prdf->reg_d1.reg_desc.count = cpu_to_be32(ELS_RDF_REG_TAG_CNT);
3518 prdf->reg_d1.desc_tags[0] = cpu_to_be32(ELS_DTAG_LNK_INTEGRITY);
3519 prdf->reg_d1.desc_tags[1] = cpu_to_be32(ELS_DTAG_DELIVERY);
3520 prdf->reg_d1.desc_tags[2] = cpu_to_be32(ELS_DTAG_PEER_CONGEST);
3521 prdf->reg_d1.desc_tags[3] = cpu_to_be32(ELS_DTAG_CONGESTION);
3523 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3524 "6444 Xmit RDF to remote NPORT x%x\n",
3527 elsiocb->iocb_cmpl = lpfc_cmpl_els_disc_cmd;
3528 elsiocb->context1 = lpfc_nlp_get(ndlp);
3529 if (!elsiocb->context1)
3532 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3533 "Issue RDF: did:x%x refcnt %d",
3534 ndlp->nlp_DID, kref_read(&ndlp->kref), 0);
3536 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
3537 if (rc == IOCB_ERROR)
3544 lpfc_els_free_iocb(phba, elsiocb);
3549 * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
3550 * @vport: pointer to a host virtual N_Port data structure.
3551 * @nlp: pointer to a node-list data structure.
3553 * This routine cancels the timer with a delayed IOCB-command retry for
3554 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
3555 * removes the ELS retry event if it presents. In addition, if the
3556 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
3557 * commands are sent for the @vport's nodes that require issuing discovery
3561 lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
3563 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3564 struct lpfc_work_evt *evtp;
3566 if (!(nlp->nlp_flag & NLP_DELAY_TMO))
3568 spin_lock_irq(shost->host_lock);
3569 nlp->nlp_flag &= ~NLP_DELAY_TMO;
3570 spin_unlock_irq(shost->host_lock);
3571 del_timer_sync(&nlp->nlp_delayfunc);
3572 nlp->nlp_last_elscmd = 0;
3573 if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
3574 list_del_init(&nlp->els_retry_evt.evt_listp);
3575 /* Decrement nlp reference count held for the delayed retry */
3576 evtp = &nlp->els_retry_evt;
3577 lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
3579 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
3580 spin_lock_irq(shost->host_lock);
3581 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
3582 spin_unlock_irq(shost->host_lock);
3583 if (vport->num_disc_nodes) {
3584 if (vport->port_state < LPFC_VPORT_READY) {
3585 /* Check if there are more ADISCs to be sent */
3586 lpfc_more_adisc(vport);
3588 /* Check if there are more PLOGIs to be sent */
3589 lpfc_more_plogi(vport);
3590 if (vport->num_disc_nodes == 0) {
3591 spin_lock_irq(shost->host_lock);
3592 vport->fc_flag &= ~FC_NDISC_ACTIVE;
3593 spin_unlock_irq(shost->host_lock);
3594 lpfc_can_disctmo(vport);
3595 lpfc_end_rscn(vport);
3604 * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
3605 * @t: pointer to the timer function associated data (ndlp).
3607 * This routine is invoked by the ndlp delayed-function timer to check
3608 * whether there is any pending ELS retry event(s) with the node. If not, it
3609 * simply returns. Otherwise, if there is at least one ELS delayed event, it
3610 * adds the delayed events to the HBA work list and invokes the
3611 * lpfc_worker_wake_up() routine to wake up worker thread to process the
3612 * event. Note that lpfc_nlp_get() is called before posting the event to
3613 * the work list to hold reference count of ndlp so that it guarantees the
3614 * reference to ndlp will still be available when the worker thread gets
3615 * to the event associated with the ndlp.
3618 lpfc_els_retry_delay(struct timer_list *t)
3620 struct lpfc_nodelist *ndlp = from_timer(ndlp, t, nlp_delayfunc);
3621 struct lpfc_vport *vport = ndlp->vport;
3622 struct lpfc_hba *phba = vport->phba;
3623 unsigned long flags;
3624 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
3626 spin_lock_irqsave(&phba->hbalock, flags);
3627 if (!list_empty(&evtp->evt_listp)) {
3628 spin_unlock_irqrestore(&phba->hbalock, flags);
3632 /* We need to hold the node by incrementing the reference
3633 * count until the queued work is done
3635 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
3636 if (evtp->evt_arg1) {
3637 evtp->evt = LPFC_EVT_ELS_RETRY;
3638 list_add_tail(&evtp->evt_listp, &phba->work_list);
3639 lpfc_worker_wake_up(phba);
3641 spin_unlock_irqrestore(&phba->hbalock, flags);
3646 * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
3647 * @ndlp: pointer to a node-list data structure.
3649 * This routine is the worker-thread handler for processing the @ndlp delayed
3650 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
3651 * the last ELS command from the associated ndlp and invokes the proper ELS
3652 * function according to the delayed ELS command to retry the command.
3655 lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
3657 struct lpfc_vport *vport = ndlp->vport;
3658 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3659 uint32_t cmd, retry;
3661 spin_lock_irq(shost->host_lock);
3662 cmd = ndlp->nlp_last_elscmd;
3663 ndlp->nlp_last_elscmd = 0;
3665 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
3666 spin_unlock_irq(shost->host_lock);
3670 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
3671 spin_unlock_irq(shost->host_lock);
3673 * If a discovery event readded nlp_delayfunc after timer
3674 * firing and before processing the timer, cancel the
3677 del_timer_sync(&ndlp->nlp_delayfunc);
3678 retry = ndlp->nlp_retry;
3679 ndlp->nlp_retry = 0;
3683 lpfc_issue_els_flogi(vport, ndlp, retry);
3686 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
3687 ndlp->nlp_prev_state = ndlp->nlp_state;
3688 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
3692 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
3693 ndlp->nlp_prev_state = ndlp->nlp_state;
3694 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
3698 case ELS_CMD_NVMEPRLI:
3699 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
3700 ndlp->nlp_prev_state = ndlp->nlp_state;
3701 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
3705 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
3706 ndlp->nlp_prev_state = ndlp->nlp_state;
3707 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
3711 if (!(vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI))
3712 lpfc_issue_els_fdisc(vport, ndlp, retry);
3719 * lpfc_link_reset - Issue link reset
3720 * @vport: pointer to a virtual N_Port data structure.
3722 * This routine performs link reset by sending INIT_LINK mailbox command.
3723 * For SLI-3 adapter, link attention interrupt is enabled before issuing
3724 * INIT_LINK mailbox command.
3727 * 0 - Link reset initiated successfully
3728 * 1 - Failed to initiate link reset
3731 lpfc_link_reset(struct lpfc_vport *vport)
3733 struct lpfc_hba *phba = vport->phba;
3738 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3739 "2851 Attempt link reset\n");
3740 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3742 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
3743 "2852 Failed to allocate mbox memory");
3747 /* Enable Link attention interrupts */
3748 if (phba->sli_rev <= LPFC_SLI_REV3) {
3749 spin_lock_irq(&phba->hbalock);
3750 phba->sli.sli_flag |= LPFC_PROCESS_LA;
3751 control = readl(phba->HCregaddr);
3752 control |= HC_LAINT_ENA;
3753 writel(control, phba->HCregaddr);
3754 readl(phba->HCregaddr); /* flush */
3755 spin_unlock_irq(&phba->hbalock);
3758 lpfc_init_link(phba, mbox, phba->cfg_topology,
3759 phba->cfg_link_speed);
3760 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
3761 mbox->vport = vport;
3762 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
3763 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
3764 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
3765 "2853 Failed to issue INIT_LINK "
3766 "mbox command, rc:x%x\n", rc);
3767 mempool_free(mbox, phba->mbox_mem_pool);
3775 * lpfc_els_retry - Make retry decision on an els command iocb
3776 * @phba: pointer to lpfc hba data structure.
3777 * @cmdiocb: pointer to lpfc command iocb data structure.
3778 * @rspiocb: pointer to lpfc response iocb data structure.
3780 * This routine makes a retry decision on an ELS command IOCB, which has
3781 * failed. The following ELS IOCBs use this function for retrying the command
3782 * when previously issued command responsed with error status: FLOGI, PLOGI,
3783 * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
3784 * returned error status, it makes the decision whether a retry shall be
3785 * issued for the command, and whether a retry shall be made immediately or
3786 * delayed. In the former case, the corresponding ELS command issuing-function
3787 * is called to retry the command. In the later case, the ELS command shall
3788 * be posted to the ndlp delayed event and delayed function timer set to the
3789 * ndlp for the delayed command issusing.
3792 * 0 - No retry of els command is made
3793 * 1 - Immediate or delayed retry of els command is made
3796 lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3797 struct lpfc_iocbq *rspiocb)
3799 struct lpfc_vport *vport = cmdiocb->vport;
3800 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3801 IOCB_t *irsp = &rspiocb->iocb;
3802 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3803 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3806 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
3810 int link_reset = 0, rc;
3813 /* Note: context2 may be 0 for internal driver abort
3814 * of delays ELS command.
3817 if (pcmd && pcmd->virt) {
3818 elscmd = (uint32_t *) (pcmd->virt);
3823 did = ndlp->nlp_DID;
3825 /* We should only hit this case for retrying PLOGI */
3826 did = irsp->un.elsreq64.remoteID;
3827 ndlp = lpfc_findnode_did(vport, did);
3828 if (!ndlp && (cmd != ELS_CMD_PLOGI))
3832 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3833 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
3834 *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
3836 switch (irsp->ulpStatus) {
3837 case IOSTAT_FCP_RSP_ERROR:
3839 case IOSTAT_REMOTE_STOP:
3840 if (phba->sli_rev == LPFC_SLI_REV4) {
3841 /* This IO was aborted by the target, we don't
3842 * know the rxid and because we did not send the
3843 * ABTS we cannot generate and RRQ.
3845 lpfc_set_rrq_active(phba, ndlp,
3846 cmdiocb->sli4_lxritag, 0, 0);
3849 case IOSTAT_LOCAL_REJECT:
3850 switch ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK)) {
3851 case IOERR_LOOP_OPEN_FAILURE:
3852 if (cmd == ELS_CMD_FLOGI) {
3853 if (PCI_DEVICE_ID_HORNET ==
3854 phba->pcidev->device) {
3855 phba->fc_topology = LPFC_TOPOLOGY_LOOP;
3856 phba->pport->fc_myDID = 0;
3857 phba->alpa_map[0] = 0;
3858 phba->alpa_map[1] = 0;
3861 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
3866 case IOERR_ILLEGAL_COMMAND:
3867 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3868 "0124 Retry illegal cmd x%x "
3869 "retry:x%x delay:x%x\n",
3870 cmd, cmdiocb->retry, delay);
3872 /* All command's retry policy */
3874 if (cmdiocb->retry > 2)
3878 case IOERR_NO_RESOURCES:
3879 logerr = 1; /* HBA out of resources */
3881 if (cmdiocb->retry > 100)
3886 case IOERR_ILLEGAL_FRAME:
3891 case IOERR_INVALID_RPI:
3892 if (cmd == ELS_CMD_PLOGI &&
3893 did == NameServer_DID) {
3894 /* Continue forever if plogi to */
3895 /* the nameserver fails */
3902 case IOERR_SEQUENCE_TIMEOUT:
3903 if (cmd == ELS_CMD_PLOGI &&
3904 did == NameServer_DID &&
3905 (cmdiocb->retry + 1) == maxretry) {
3906 /* Reset the Link */
3916 case IOSTAT_NPORT_RJT:
3917 case IOSTAT_FABRIC_RJT:
3918 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
3924 case IOSTAT_NPORT_BSY:
3925 case IOSTAT_FABRIC_BSY:
3926 logerr = 1; /* Fabric / Remote NPort out of resources */
3931 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
3932 /* Added for Vendor specifc support
3933 * Just keep retrying for these Rsn / Exp codes
3935 switch (stat.un.b.lsRjtRsnCode) {
3936 case LSRJT_UNABLE_TPC:
3937 /* The driver has a VALID PLOGI but the rport has
3938 * rejected the PRLI - can't do it now. Delay
3939 * for 1 second and try again.
3941 * However, if explanation is REQ_UNSUPPORTED there's
3942 * no point to retry PRLI.
3944 if ((cmd == ELS_CMD_PRLI || cmd == ELS_CMD_NVMEPRLI) &&
3945 stat.un.b.lsRjtRsnCodeExp !=
3946 LSEXP_REQ_UNSUPPORTED) {
3948 maxretry = lpfc_max_els_tries + 1;
3953 /* Legacy bug fix code for targets with PLOGI delays. */
3954 if (stat.un.b.lsRjtRsnCodeExp ==
3955 LSEXP_CMD_IN_PROGRESS) {
3956 if (cmd == ELS_CMD_PLOGI) {
3963 if (stat.un.b.lsRjtRsnCodeExp ==
3964 LSEXP_CANT_GIVE_DATA) {
3965 if (cmd == ELS_CMD_PLOGI) {
3972 if (cmd == ELS_CMD_PLOGI) {
3974 maxretry = lpfc_max_els_tries + 1;
3978 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
3979 (cmd == ELS_CMD_FDISC) &&
3980 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
3981 lpfc_printf_vlog(vport, KERN_ERR,
3983 "0125 FDISC Failed (x%x). "
3984 "Fabric out of resources\n",
3985 stat.un.lsRjtError);
3986 lpfc_vport_set_state(vport,
3987 FC_VPORT_NO_FABRIC_RSCS);
3991 case LSRJT_LOGICAL_BSY:
3992 if ((cmd == ELS_CMD_PLOGI) ||
3993 (cmd == ELS_CMD_PRLI) ||
3994 (cmd == ELS_CMD_NVMEPRLI)) {
3997 } else if (cmd == ELS_CMD_FDISC) {
3998 /* FDISC retry policy */
4000 if (cmdiocb->retry >= 32)
4006 case LSRJT_LOGICAL_ERR:
4007 /* There are some cases where switches return this
4008 * error when they are not ready and should be returning
4009 * Logical Busy. We should delay every time.
4011 if (cmd == ELS_CMD_FDISC &&
4012 stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
4016 } else if (cmd == ELS_CMD_FLOGI &&
4017 stat.un.b.lsRjtRsnCodeExp ==
4018 LSEXP_NOTHING_MORE) {
4019 vport->fc_sparam.cmn.bbRcvSizeMsb &= 0xf;
4021 lpfc_printf_vlog(vport, KERN_ERR,
4023 "0820 FLOGI Failed (x%x). "
4024 "BBCredit Not Supported\n",
4025 stat.un.lsRjtError);
4029 case LSRJT_PROTOCOL_ERR:
4030 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
4031 (cmd == ELS_CMD_FDISC) &&
4032 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
4033 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
4035 lpfc_printf_vlog(vport, KERN_ERR,
4037 "0122 FDISC Failed (x%x). "
4038 "Fabric Detected Bad WWN\n",
4039 stat.un.lsRjtError);
4040 lpfc_vport_set_state(vport,
4041 FC_VPORT_FABRIC_REJ_WWN);
4044 case LSRJT_VENDOR_UNIQUE:
4045 if ((stat.un.b.vendorUnique == 0x45) &&
4046 (cmd == ELS_CMD_FLOGI)) {
4050 case LSRJT_CMD_UNSUPPORTED:
4051 /* lpfc nvmet returns this type of LS_RJT when it
4052 * receives an FCP PRLI because lpfc nvmet only
4053 * support NVME. ELS request is terminated for FCP4
4056 if (stat.un.b.lsRjtRsnCodeExp ==
4057 LSEXP_REQ_UNSUPPORTED && cmd == ELS_CMD_PRLI) {
4058 spin_lock_irq(shost->host_lock);
4059 ndlp->nlp_flag |= NLP_FCP_PRLI_RJT;
4060 spin_unlock_irq(shost->host_lock);
4068 case IOSTAT_INTERMED_RSP:
4077 rc = lpfc_link_reset(vport);
4079 /* Do not give up. Retry PLOGI one more time and attempt
4080 * link reset if PLOGI fails again.
4089 if (did == FDMI_DID)
4092 if ((cmd == ELS_CMD_FLOGI) &&
4093 (phba->fc_topology != LPFC_TOPOLOGY_LOOP) &&
4094 !lpfc_error_lost_link(irsp)) {
4095 /* FLOGI retry policy */
4097 /* retry FLOGI forever */
4098 if (phba->link_flag != LS_LOOPBACK_MODE)
4103 if (cmdiocb->retry >= 100)
4105 else if (cmdiocb->retry >= 32)
4107 } else if ((cmd == ELS_CMD_FDISC) && !lpfc_error_lost_link(irsp)) {
4108 /* retry FDISCs every second up to devloss */
4110 maxretry = vport->cfg_devloss_tmo;
4115 if (maxretry && (cmdiocb->retry >= maxretry)) {
4116 phba->fc_stat.elsRetryExceeded++;
4120 if ((vport->load_flag & FC_UNLOADING) != 0)
4125 if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) {
4126 /* Stop retrying PLOGI and FDISC if in FCF discovery */
4127 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
4128 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4129 "2849 Stop retry ELS command "
4130 "x%x to remote NPORT x%x, "
4131 "Data: x%x x%x\n", cmd, did,
4132 cmdiocb->retry, delay);
4137 /* Retry ELS command <elsCmd> to remote NPORT <did> */
4138 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4139 "0107 Retry ELS command x%x to remote "
4140 "NPORT x%x Data: x%x x%x\n",
4141 cmd, did, cmdiocb->retry, delay);
4143 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
4144 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
4145 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
4146 IOERR_NO_RESOURCES))) {
4147 /* Don't reset timer for no resources */
4149 /* If discovery / RSCN timer is running, reset it */
4150 if (timer_pending(&vport->fc_disctmo) ||
4151 (vport->fc_flag & FC_RSCN_MODE))
4152 lpfc_set_disctmo(vport);
4155 phba->fc_stat.elsXmitRetry++;
4156 if (ndlp && delay) {
4157 phba->fc_stat.elsDelayRetry++;
4158 ndlp->nlp_retry = cmdiocb->retry;
4160 /* delay is specified in milliseconds */
4161 mod_timer(&ndlp->nlp_delayfunc,
4162 jiffies + msecs_to_jiffies(delay));
4163 spin_lock_irq(shost->host_lock);
4164 ndlp->nlp_flag |= NLP_DELAY_TMO;
4165 spin_unlock_irq(shost->host_lock);
4167 ndlp->nlp_prev_state = ndlp->nlp_state;
4168 if ((cmd == ELS_CMD_PRLI) ||
4169 (cmd == ELS_CMD_NVMEPRLI))
4170 lpfc_nlp_set_state(vport, ndlp,
4171 NLP_STE_PRLI_ISSUE);
4173 lpfc_nlp_set_state(vport, ndlp,
4175 ndlp->nlp_last_elscmd = cmd;
4181 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
4184 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
4188 ndlp->nlp_prev_state = ndlp->nlp_state;
4189 lpfc_nlp_set_state(vport, ndlp,
4190 NLP_STE_PLOGI_ISSUE);
4192 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
4195 ndlp->nlp_prev_state = ndlp->nlp_state;
4196 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
4197 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
4200 case ELS_CMD_NVMEPRLI:
4201 ndlp->nlp_prev_state = ndlp->nlp_state;
4202 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
4203 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
4206 ndlp->nlp_prev_state = ndlp->nlp_state;
4207 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
4208 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
4212 /* No retry ELS command <elsCmd> to remote NPORT <did> */
4214 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
4215 "0137 No retry ELS command x%x to remote "
4216 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
4217 cmd, did, irsp->ulpStatus,
4218 irsp->un.ulpWord[4]);
4221 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4222 "0108 No retry ELS command x%x to remote "
4223 "NPORT x%x Retried:%d Error:x%x/%x\n",
4224 cmd, did, cmdiocb->retry, irsp->ulpStatus,
4225 irsp->un.ulpWord[4]);
4231 * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
4232 * @phba: pointer to lpfc hba data structure.
4233 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
4235 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
4236 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
4237 * checks to see whether there is a lpfc DMA buffer associated with the
4238 * response of the command IOCB. If so, it will be released before releasing
4239 * the lpfc DMA buffer associated with the IOCB itself.
4242 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
4245 lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
4247 struct lpfc_dmabuf *buf_ptr;
4249 /* Free the response before processing the command. */
4250 if (!list_empty(&buf_ptr1->list)) {
4251 list_remove_head(&buf_ptr1->list, buf_ptr,
4254 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
4257 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
4263 * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
4264 * @phba: pointer to lpfc hba data structure.
4265 * @buf_ptr: pointer to the lpfc dma buffer data structure.
4267 * This routine releases the lpfc Direct Memory Access (DMA) buffer
4268 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
4272 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
4275 lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
4277 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
4283 * lpfc_els_free_iocb - Free a command iocb and its associated resources
4284 * @phba: pointer to lpfc hba data structure.
4285 * @elsiocb: pointer to lpfc els command iocb data structure.
4287 * This routine frees a command IOCB and its associated resources. The
4288 * command IOCB data structure contains the reference to various associated
4289 * resources, these fields must be set to NULL if the associated reference
4291 * context1 - reference to ndlp
4292 * context2 - reference to cmd
4293 * context2->next - reference to rsp
4294 * context3 - reference to bpl
4296 * It first properly decrements the reference count held on ndlp for the
4297 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
4298 * set, it invokes the lpfc_els_free_data() routine to release the Direct
4299 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
4300 * adds the DMA buffer the @phba data structure for the delayed release.
4301 * If reference to the Buffer Pointer List (BPL) is present, the
4302 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
4303 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
4304 * invoked to release the IOCB data structure back to @phba IOCBQ list.
4307 * 0 - Success (currently, always return 0)
4310 lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
4312 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
4314 /* The I/O job is complete. Clear the context1 data. */
4315 elsiocb->context1 = NULL;
4317 /* context2 = cmd, context2->next = rsp, context3 = bpl */
4318 if (elsiocb->context2) {
4319 if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
4320 /* Firmware could still be in progress of DMAing
4321 * payload, so don't free data buffer till after
4324 elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
4325 buf_ptr = elsiocb->context2;
4326 elsiocb->context2 = NULL;
4329 spin_lock_irq(&phba->hbalock);
4330 if (!list_empty(&buf_ptr->list)) {
4331 list_remove_head(&buf_ptr->list,
4332 buf_ptr1, struct lpfc_dmabuf,
4334 INIT_LIST_HEAD(&buf_ptr1->list);
4335 list_add_tail(&buf_ptr1->list,
4339 INIT_LIST_HEAD(&buf_ptr->list);
4340 list_add_tail(&buf_ptr->list, &phba->elsbuf);
4342 spin_unlock_irq(&phba->hbalock);
4345 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
4346 lpfc_els_free_data(phba, buf_ptr1);
4347 elsiocb->context2 = NULL;
4351 if (elsiocb->context3) {
4352 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
4353 lpfc_els_free_bpl(phba, buf_ptr);
4354 elsiocb->context3 = NULL;
4356 lpfc_sli_release_iocbq(phba, elsiocb);
4361 * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
4362 * @phba: pointer to lpfc hba data structure.
4363 * @cmdiocb: pointer to lpfc command iocb data structure.
4364 * @rspiocb: pointer to lpfc response iocb data structure.
4366 * This routine is the completion callback function to the Logout (LOGO)
4367 * Accept (ACC) Response ELS command. This routine is invoked to indicate
4368 * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
4369 * release the ndlp if it has the last reference remaining (reference count
4370 * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
4371 * field to NULL to inform the following lpfc_els_free_iocb() routine no
4372 * ndlp reference count needs to be decremented. Otherwise, the ndlp
4373 * reference use-count shall be decremented by the lpfc_els_free_iocb()
4374 * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
4375 * IOCB data structure.
4378 lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
4379 struct lpfc_iocbq *rspiocb)
4381 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
4382 struct lpfc_vport *vport = cmdiocb->vport;
4385 irsp = &rspiocb->iocb;
4386 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4387 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
4388 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
4389 /* ACC to LOGO completes to NPort <nlp_DID> */
4390 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4391 "0109 ACC to LOGO completes to NPort x%x "
4392 "Data: x%x x%x x%x\n",
4393 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4396 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
4397 /* NPort Recovery mode or node is just allocated */
4398 if (!lpfc_nlp_not_used(ndlp)) {
4399 /* If the ndlp is being used by another discovery
4400 * thread, just unregister the RPI.
4402 lpfc_unreg_rpi(vport, ndlp);
4404 /* Indicate the node has already released, should
4405 * not reference to it from within lpfc_els_free_iocb.
4407 cmdiocb->context1 = NULL;
4412 * The driver received a LOGO from the rport and has ACK'd it.
4413 * At this point, the driver is done so release the IOCB
4415 lpfc_els_free_iocb(phba, cmdiocb);
4420 * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
4421 * @phba: pointer to lpfc hba data structure.
4422 * @pmb: pointer to the driver internal queue element for mailbox command.
4424 * This routine is the completion callback function for unregister default
4425 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
4426 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
4427 * decrements the ndlp reference count held for this completion callback
4428 * function. After that, it invokes the lpfc_nlp_not_used() to check
4429 * whether there is only one reference left on the ndlp. If so, it will
4430 * perform one more decrement and trigger the release of the ndlp.
4433 lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4435 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
4436 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
4438 pmb->ctx_buf = NULL;
4439 pmb->ctx_ndlp = NULL;
4441 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4443 mempool_free(pmb, phba->mbox_mem_pool);
4445 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
4446 "0006 rpi%x DID:%x flg:%x %d x%px\n",
4447 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
4448 kref_read(&ndlp->kref),
4451 /* This is the end of the default RPI cleanup logic for
4452 * this ndlp. If no other discovery threads are using
4453 * this ndlp, free all resources associated with it.
4455 lpfc_nlp_not_used(ndlp);
4462 * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
4463 * @phba: pointer to lpfc hba data structure.
4464 * @cmdiocb: pointer to lpfc command iocb data structure.
4465 * @rspiocb: pointer to lpfc response iocb data structure.
4467 * This routine is the completion callback function for ELS Response IOCB
4468 * command. In normal case, this callback function just properly sets the
4469 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
4470 * field in the command IOCB is not NULL, the referred mailbox command will
4471 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
4472 * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
4473 * link down event occurred during the discovery, the lpfc_nlp_not_used()
4474 * routine shall be invoked trying to release the ndlp if no other threads
4475 * are currently referring it.
4478 lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
4479 struct lpfc_iocbq *rspiocb)
4481 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
4482 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
4483 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
4486 LPFC_MBOXQ_t *mbox = NULL;
4487 struct lpfc_dmabuf *mp = NULL;
4488 uint32_t ls_rjt = 0;
4490 irsp = &rspiocb->iocb;
4493 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
4494 "3177 ELS response failed\n");
4497 if (cmdiocb->context_un.mbox)
4498 mbox = cmdiocb->context_un.mbox;
4500 /* First determine if this is a LS_RJT cmpl. Note, this callback
4501 * function can have cmdiocb->contest1 (ndlp) field set to NULL.
4503 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
4504 if (ndlp && (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) {
4505 /* A LS_RJT associated with Default RPI cleanup has its own
4506 * separate code path.
4508 if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
4512 /* Check to see if link went down during discovery */
4513 if (!ndlp || lpfc_els_chk_latt(vport)) {
4515 mp = (struct lpfc_dmabuf *)mbox->ctx_buf;
4517 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4520 mempool_free(mbox, phba->mbox_mem_pool);
4522 if (ndlp && (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
4523 if (lpfc_nlp_not_used(ndlp)) {
4525 /* Indicate the node has already released,
4526 * should not reference to it from within
4527 * the routine lpfc_els_free_iocb.
4529 cmdiocb->context1 = NULL;
4534 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4535 "ELS rsp cmpl: status:x%x/x%x did:x%x",
4536 irsp->ulpStatus, irsp->un.ulpWord[4],
4537 cmdiocb->iocb.un.elsreq64.remoteID);
4538 /* ELS response tag <ulpIoTag> completes */
4539 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4540 "0110 ELS response tag x%x completes "
4541 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
4542 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
4543 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
4544 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4547 if ((rspiocb->iocb.ulpStatus == 0) &&
4548 (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
4549 if (!lpfc_unreg_rpi(vport, ndlp) &&
4550 (!(vport->fc_flag & FC_PT2PT))) {
4551 if (ndlp->nlp_state == NLP_STE_REG_LOGIN_ISSUE) {
4552 lpfc_printf_vlog(vport, KERN_INFO,
4556 "Data: x%x x%x x%x\n",
4563 lpfc_mbuf_free(phba, mp->virt,
4567 mempool_free(mbox, phba->mbox_mem_pool);
4572 /* Increment reference count to ndlp to hold the
4573 * reference to ndlp for the callback function.
4575 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
4576 if (!mbox->ctx_ndlp)
4579 mbox->vport = vport;
4580 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
4581 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
4582 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
4585 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
4586 ndlp->nlp_prev_state = ndlp->nlp_state;
4587 lpfc_nlp_set_state(vport, ndlp,
4588 NLP_STE_REG_LOGIN_ISSUE);
4591 ndlp->nlp_flag |= NLP_REG_LOGIN_SEND;
4592 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
4593 != MBX_NOT_FINISHED)
4596 /* Decrement the ndlp reference count we
4597 * set for this failed mailbox command.
4600 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
4602 /* ELS rsp: Cannot issue reg_login for <NPortid> */
4603 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
4604 "0138 ELS rsp: Cannot issue reg_login for x%x "
4605 "Data: x%x x%x x%x\n",
4606 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4609 if (lpfc_nlp_not_used(ndlp)) {
4611 /* Indicate node has already been released,
4612 * should not reference to it from within
4613 * the routine lpfc_els_free_iocb.
4615 cmdiocb->context1 = NULL;
4618 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
4619 if (!lpfc_error_lost_link(irsp) &&
4620 ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
4621 if (lpfc_nlp_not_used(ndlp)) {
4623 /* Indicate node has already been
4624 * released, should not reference
4625 * to it from within the routine
4626 * lpfc_els_free_iocb.
4628 cmdiocb->context1 = NULL;
4632 mp = (struct lpfc_dmabuf *)mbox->ctx_buf;
4634 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4637 mempool_free(mbox, phba->mbox_mem_pool);
4640 if (ndlp && shost) {
4641 spin_lock_irq(shost->host_lock);
4643 ndlp->nlp_flag &= ~NLP_ACC_REGLOGIN;
4644 ndlp->nlp_flag &= ~NLP_RM_DFLT_RPI;
4645 spin_unlock_irq(shost->host_lock);
4647 /* If the node is not being used by another discovery thread,
4648 * and we are sending a reject, we are done with it.
4649 * Release driver reference count here and free associated
4653 if (lpfc_nlp_not_used(ndlp))
4654 /* Indicate node has already been released,
4655 * should not reference to it from within
4656 * the routine lpfc_els_free_iocb.
4658 cmdiocb->context1 = NULL;
4662 /* Release the originating I/O reference. */
4663 lpfc_els_free_iocb(phba, cmdiocb);
4669 * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
4670 * @vport: pointer to a host virtual N_Port data structure.
4671 * @flag: the els command code to be accepted.
4672 * @oldiocb: pointer to the original lpfc command iocb data structure.
4673 * @ndlp: pointer to a node-list data structure.
4674 * @mbox: pointer to the driver internal queue element for mailbox command.
4676 * This routine prepares and issues an Accept (ACC) response IOCB
4677 * command. It uses the @flag to properly set up the IOCB field for the
4678 * specific ACC response command to be issued and invokes the
4679 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
4680 * @mbox pointer is passed in, it will be put into the context_un.mbox
4681 * field of the IOCB for the completion callback function to issue the
4682 * mailbox command to the HBA later when callback is invoked.
4684 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4685 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4686 * will be stored into the context1 field of the IOCB for the completion
4687 * callback function to the corresponding response ELS IOCB command.
4690 * 0 - Successfully issued acc response
4691 * 1 - Failed to issue acc response
4694 lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
4695 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
4698 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4699 struct lpfc_hba *phba = vport->phba;
4702 struct lpfc_iocbq *elsiocb;
4704 struct serv_parm *sp;
4707 ELS_PKT *els_pkt_ptr;
4709 oldcmd = &oldiocb->iocb;
4713 cmdsize = sizeof(uint32_t);
4714 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
4715 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
4717 spin_lock_irq(shost->host_lock);
4718 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
4719 spin_unlock_irq(shost->host_lock);
4723 icmd = &elsiocb->iocb;
4724 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4725 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4726 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4727 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4728 pcmd += sizeof(uint32_t);
4730 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4731 "Issue ACC: did:x%x flg:x%x",
4732 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4736 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
4737 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
4738 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
4742 icmd = &elsiocb->iocb;
4743 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4744 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4745 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4748 elsiocb->context_un.mbox = mbox;
4750 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4751 pcmd += sizeof(uint32_t);
4752 sp = (struct serv_parm *)pcmd;
4754 if (flag == ELS_CMD_FLOGI) {
4755 /* Copy the received service parameters back */
4756 memcpy(sp, &phba->fc_fabparam,
4757 sizeof(struct serv_parm));
4759 /* Clear the F_Port bit */
4762 /* Mark all class service parameters as invalid */
4763 sp->cls1.classValid = 0;
4764 sp->cls2.classValid = 0;
4765 sp->cls3.classValid = 0;
4766 sp->cls4.classValid = 0;
4768 /* Copy our worldwide names */
4769 memcpy(&sp->portName, &vport->fc_sparam.portName,
4770 sizeof(struct lpfc_name));
4771 memcpy(&sp->nodeName, &vport->fc_sparam.nodeName,
4772 sizeof(struct lpfc_name));
4774 memcpy(pcmd, &vport->fc_sparam,
4775 sizeof(struct serv_parm));
4777 sp->cmn.valid_vendor_ver_level = 0;
4778 memset(sp->un.vendorVersion, 0,
4779 sizeof(sp->un.vendorVersion));
4780 sp->cmn.bbRcvSizeMsb &= 0xF;
4782 /* If our firmware supports this feature, convey that
4783 * info to the target using the vendor specific field.
4785 if (phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) {
4786 sp->cmn.valid_vendor_ver_level = 1;
4787 sp->un.vv.vid = cpu_to_be32(LPFC_VV_EMLX_ID);
4789 cpu_to_be32(LPFC_VV_SUPPRESS_RSP);
4793 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4794 "Issue ACC FLOGI/PLOGI: did:x%x flg:x%x",
4795 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4798 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
4799 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
4800 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
4804 icmd = &elsiocb->iocb;
4805 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4806 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4807 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4809 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
4810 sizeof(uint32_t) + sizeof(PRLO));
4811 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
4812 els_pkt_ptr = (ELS_PKT *) pcmd;
4813 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
4815 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4816 "Issue ACC PRLO: did:x%x flg:x%x",
4817 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4822 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
4823 spin_lock_irq(shost->host_lock);
4824 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED ||
4825 ndlp->nlp_flag & NLP_REG_LOGIN_SEND))
4826 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
4827 spin_unlock_irq(shost->host_lock);
4828 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
4830 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4833 phba->fc_stat.elsXmitACC++;
4834 elsiocb->context1 = lpfc_nlp_get(ndlp);
4835 if (!elsiocb->context1)
4838 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4839 if (rc == IOCB_ERROR)
4842 /* Xmit ELS ACC response tag <ulpIoTag> */
4843 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4844 "0128 Xmit ELS ACC response Status: x%x, IoTag: x%x, "
4845 "XRI: x%x, DID: x%x, nlp_flag: x%x nlp_state: x%x "
4846 "RPI: x%x, fc_flag x%x\n",
4847 rc, elsiocb->iotag, elsiocb->sli4_xritag,
4848 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4849 ndlp->nlp_rpi, vport->fc_flag);
4855 lpfc_els_free_iocb(phba, elsiocb);
4860 * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command
4861 * @vport: pointer to a virtual N_Port data structure.
4862 * @rejectError: reject response to issue
4863 * @oldiocb: pointer to the original lpfc command iocb data structure.
4864 * @ndlp: pointer to a node-list data structure.
4865 * @mbox: pointer to the driver internal queue element for mailbox command.
4867 * This routine prepares and issue an Reject (RJT) response IOCB
4868 * command. If a @mbox pointer is passed in, it will be put into the
4869 * context_un.mbox field of the IOCB for the completion callback function
4870 * to issue to the HBA later.
4872 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4873 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4874 * will be stored into the context1 field of the IOCB for the completion
4875 * callback function to the reject response ELS IOCB command.
4878 * 0 - Successfully issued reject response
4879 * 1 - Failed to issue reject response
4882 lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
4883 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
4887 struct lpfc_hba *phba = vport->phba;
4890 struct lpfc_iocbq *elsiocb;
4894 cmdsize = 2 * sizeof(uint32_t);
4895 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4896 ndlp->nlp_DID, ELS_CMD_LS_RJT);
4900 icmd = &elsiocb->iocb;
4901 oldcmd = &oldiocb->iocb;
4902 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4903 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4904 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4906 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
4907 pcmd += sizeof(uint32_t);
4908 *((uint32_t *) (pcmd)) = rejectError;
4911 elsiocb->context_un.mbox = mbox;
4913 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
4914 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4915 "0129 Xmit ELS RJT x%x response tag x%x "
4916 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
4918 rejectError, elsiocb->iotag,
4919 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
4920 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
4921 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4922 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
4923 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
4925 phba->fc_stat.elsXmitLSRJT++;
4926 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4927 elsiocb->context1 = lpfc_nlp_get(ndlp);
4928 if (!elsiocb->context1)
4931 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4932 if (rc == IOCB_ERROR)
4940 lpfc_els_free_iocb(phba, elsiocb);
4945 * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
4946 * @vport: pointer to a virtual N_Port data structure.
4947 * @oldiocb: pointer to the original lpfc command iocb data structure.
4948 * @ndlp: pointer to a node-list data structure.
4950 * This routine prepares and issues an Accept (ACC) response to Address
4951 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
4952 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
4954 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4955 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4956 * will be stored into the context1 field of the IOCB for the completion
4957 * callback function to the ADISC Accept response ELS IOCB command.
4960 * 0 - Successfully issued acc adisc response
4961 * 1 - Failed to issue adisc acc response
4964 lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
4965 struct lpfc_nodelist *ndlp)
4967 struct lpfc_hba *phba = vport->phba;
4969 IOCB_t *icmd, *oldcmd;
4970 struct lpfc_iocbq *elsiocb;
4975 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
4976 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4977 ndlp->nlp_DID, ELS_CMD_ACC);
4981 icmd = &elsiocb->iocb;
4982 oldcmd = &oldiocb->iocb;
4983 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4984 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4986 /* Xmit ADISC ACC response tag <ulpIoTag> */
4987 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4988 "0130 Xmit ADISC ACC response iotag x%x xri: "
4989 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
4990 elsiocb->iotag, elsiocb->iocb.ulpContext,
4991 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4993 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4995 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4996 pcmd += sizeof(uint32_t);
4998 ap = (ADISC *) (pcmd);
4999 ap->hardAL_PA = phba->fc_pref_ALPA;
5000 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
5001 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
5002 ap->DID = be32_to_cpu(vport->fc_myDID);
5004 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
5005 "Issue ACC ADISC: did:x%x flg:x%x refcnt %d",
5006 ndlp->nlp_DID, ndlp->nlp_flag, kref_read(&ndlp->kref));
5008 phba->fc_stat.elsXmitACC++;
5009 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5010 elsiocb->context1 = lpfc_nlp_get(ndlp);
5011 if (!elsiocb->context1)
5014 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5015 if (rc == IOCB_ERROR)
5018 /* Xmit ELS ACC response tag <ulpIoTag> */
5019 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5020 "0128 Xmit ELS ACC response Status: x%x, IoTag: x%x, "
5021 "XRI: x%x, DID: x%x, nlp_flag: x%x nlp_state: x%x "
5022 "RPI: x%x, fc_flag x%x\n",
5023 rc, elsiocb->iotag, elsiocb->sli4_xritag,
5024 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5025 ndlp->nlp_rpi, vport->fc_flag);
5031 lpfc_els_free_iocb(phba, elsiocb);
5036 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
5037 * @vport: pointer to a virtual N_Port data structure.
5038 * @oldiocb: pointer to the original lpfc command iocb data structure.
5039 * @ndlp: pointer to a node-list data structure.
5041 * This routine prepares and issues an Accept (ACC) response to Process
5042 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
5043 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
5045 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5046 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5047 * will be stored into the context1 field of the IOCB for the completion
5048 * callback function to the PRLI Accept response ELS IOCB command.
5051 * 0 - Successfully issued acc prli response
5052 * 1 - Failed to issue acc prli response
5055 lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
5056 struct lpfc_nodelist *ndlp)
5058 struct lpfc_hba *phba = vport->phba;
5060 struct lpfc_nvme_prli *npr_nvme;
5064 struct lpfc_iocbq *elsiocb;
5067 uint32_t prli_fc4_req, *req_payload;
5068 struct lpfc_dmabuf *req_buf;
5072 /* Need the incoming PRLI payload to determine if the ACC is for an
5073 * FC4 or NVME PRLI type. The PRLI type is at word 1.
5075 req_buf = (struct lpfc_dmabuf *)oldiocb->context2;
5076 req_payload = (((uint32_t *)req_buf->virt) + 1);
5078 /* PRLI type payload is at byte 3 for FCP or NVME. */
5079 prli_fc4_req = be32_to_cpu(*req_payload);
5080 prli_fc4_req = (prli_fc4_req >> 24) & 0xff;
5081 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5082 "6127 PRLI_ACC: Req Type x%x, Word1 x%08x\n",
5083 prli_fc4_req, *((uint32_t *)req_payload));
5085 if (prli_fc4_req == PRLI_FCP_TYPE) {
5086 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
5087 elsrspcmd = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
5088 } else if (prli_fc4_req & PRLI_NVME_TYPE) {
5089 cmdsize = sizeof(uint32_t) + sizeof(struct lpfc_nvme_prli);
5090 elsrspcmd = (ELS_CMD_ACC | (ELS_CMD_NVMEPRLI & ~ELS_RSP_MASK));
5095 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
5096 ndlp->nlp_DID, elsrspcmd);
5100 icmd = &elsiocb->iocb;
5101 oldcmd = &oldiocb->iocb;
5102 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
5103 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
5105 /* Xmit PRLI ACC response tag <ulpIoTag> */
5106 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5107 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
5108 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
5109 elsiocb->iotag, elsiocb->iocb.ulpContext,
5110 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5112 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5113 memset(pcmd, 0, cmdsize);
5115 *((uint32_t *)(pcmd)) = elsrspcmd;
5116 pcmd += sizeof(uint32_t);
5118 /* For PRLI, remainder of payload is PRLI parameter page */
5121 if (prli_fc4_req == PRLI_FCP_TYPE) {
5123 * If the remote port is a target and our firmware version
5124 * is 3.20 or later, set the following bits for FC-TAPE
5127 npr = (PRLI *) pcmd;
5128 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
5129 (vpd->rev.feaLevelHigh >= 0x02)) {
5130 npr->ConfmComplAllowed = 1;
5132 npr->TaskRetryIdReq = 1;
5134 npr->acceptRspCode = PRLI_REQ_EXECUTED;
5135 npr->estabImagePair = 1;
5136 npr->readXferRdyDis = 1;
5137 npr->ConfmComplAllowed = 1;
5138 npr->prliType = PRLI_FCP_TYPE;
5139 npr->initiatorFunc = 1;
5140 } else if (prli_fc4_req & PRLI_NVME_TYPE) {
5141 /* Respond with an NVME PRLI Type */
5142 npr_nvme = (struct lpfc_nvme_prli *) pcmd;
5143 bf_set(prli_type_code, npr_nvme, PRLI_NVME_TYPE);
5144 bf_set(prli_estabImagePair, npr_nvme, 0); /* Should be 0 */
5145 bf_set(prli_acc_rsp_code, npr_nvme, PRLI_REQ_EXECUTED);
5146 if (phba->nvmet_support) {
5147 bf_set(prli_tgt, npr_nvme, 1);
5148 bf_set(prli_disc, npr_nvme, 1);
5149 if (phba->cfg_nvme_enable_fb) {
5150 bf_set(prli_fba, npr_nvme, 1);
5152 /* TBD. Target mode needs to post buffers
5153 * that support the configured first burst
5156 bf_set(prli_fb_sz, npr_nvme,
5157 phba->cfg_nvmet_fb_size);
5160 bf_set(prli_init, npr_nvme, 1);
5163 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
5164 "6015 NVME issue PRLI ACC word1 x%08x "
5165 "word4 x%08x word5 x%08x flag x%x, "
5166 "fcp_info x%x nlp_type x%x\n",
5167 npr_nvme->word1, npr_nvme->word4,
5168 npr_nvme->word5, ndlp->nlp_flag,
5169 ndlp->nlp_fcp_info, ndlp->nlp_type);
5170 npr_nvme->word1 = cpu_to_be32(npr_nvme->word1);
5171 npr_nvme->word4 = cpu_to_be32(npr_nvme->word4);
5172 npr_nvme->word5 = cpu_to_be32(npr_nvme->word5);
5174 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5175 "6128 Unknown FC_TYPE x%x x%x ndlp x%06x\n",
5176 prli_fc4_req, ndlp->nlp_fc4_type,
5179 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
5180 "Issue ACC PRLI: did:x%x flg:x%x",
5181 ndlp->nlp_DID, ndlp->nlp_flag, kref_read(&ndlp->kref));
5183 phba->fc_stat.elsXmitACC++;
5184 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5185 elsiocb->context1 = lpfc_nlp_get(ndlp);
5186 if (!elsiocb->context1)
5189 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5190 if (rc == IOCB_ERROR)
5197 lpfc_els_free_iocb(phba, elsiocb);
5202 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
5203 * @vport: pointer to a virtual N_Port data structure.
5204 * @format: rnid command format.
5205 * @oldiocb: pointer to the original lpfc command iocb data structure.
5206 * @ndlp: pointer to a node-list data structure.
5208 * This routine issues a Request Node Identification Data (RNID) Accept
5209 * (ACC) response. It constructs the RNID ACC response command according to
5210 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
5211 * issue the response. Note that this command does not need to hold the ndlp
5212 * reference count for the callback. So, the ndlp reference count taken by
5213 * the lpfc_prep_els_iocb() routine is put back and the context1 field of
5214 * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
5215 * there is no ndlp reference available.
5217 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5218 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5219 * will be stored into the context1 field of the IOCB for the completion
5220 * callback function. However, for the RNID Accept Response ELS command,
5221 * this is undone later by this routine after the IOCB is allocated.
5224 * 0 - Successfully issued acc rnid response
5225 * 1 - Failed to issue acc rnid response
5228 lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
5229 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
5231 struct lpfc_hba *phba = vport->phba;
5233 IOCB_t *icmd, *oldcmd;
5234 struct lpfc_iocbq *elsiocb;
5239 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
5240 + (2 * sizeof(struct lpfc_name));
5242 cmdsize += sizeof(RNID_TOP_DISC);
5244 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
5245 ndlp->nlp_DID, ELS_CMD_ACC);
5249 icmd = &elsiocb->iocb;
5250 oldcmd = &oldiocb->iocb;
5251 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
5252 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
5254 /* Xmit RNID ACC response tag <ulpIoTag> */
5255 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5256 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
5257 elsiocb->iotag, elsiocb->iocb.ulpContext);
5258 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5259 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5260 pcmd += sizeof(uint32_t);
5262 memset(pcmd, 0, sizeof(RNID));
5263 rn = (RNID *) (pcmd);
5264 rn->Format = format;
5265 rn->CommonLen = (2 * sizeof(struct lpfc_name));
5266 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
5267 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
5270 rn->SpecificLen = 0;
5272 case RNID_TOPOLOGY_DISC:
5273 rn->SpecificLen = sizeof(RNID_TOP_DISC);
5274 memcpy(&rn->un.topologyDisc.portName,
5275 &vport->fc_portname, sizeof(struct lpfc_name));
5276 rn->un.topologyDisc.unitType = RNID_HBA;
5277 rn->un.topologyDisc.physPort = 0;
5278 rn->un.topologyDisc.attachedNodes = 0;
5282 rn->SpecificLen = 0;
5286 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
5287 "Issue ACC RNID: did:x%x flg:x%x refcnt %d",
5288 ndlp->nlp_DID, ndlp->nlp_flag, kref_read(&ndlp->kref));
5290 phba->fc_stat.elsXmitACC++;
5291 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5292 elsiocb->context1 = lpfc_nlp_get(ndlp);
5293 if (!elsiocb->context1)
5296 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5297 if (rc == IOCB_ERROR)
5305 lpfc_els_free_iocb(phba, elsiocb);
5310 * lpfc_els_clear_rrq - Clear the rq that this rrq describes.
5311 * @vport: pointer to a virtual N_Port data structure.
5312 * @iocb: pointer to the lpfc command iocb data structure.
5313 * @ndlp: pointer to a node-list data structure.
5318 lpfc_els_clear_rrq(struct lpfc_vport *vport,
5319 struct lpfc_iocbq *iocb, struct lpfc_nodelist *ndlp)
5321 struct lpfc_hba *phba = vport->phba;
5326 struct lpfc_node_rrq *prrq;
5329 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) iocb->context2)->virt);
5330 pcmd += sizeof(uint32_t);
5331 rrq = (struct RRQ *)pcmd;
5332 rrq->rrq_exchg = be32_to_cpu(rrq->rrq_exchg);
5333 rxid = bf_get(rrq_rxid, rrq);
5335 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5336 "2883 Clear RRQ for SID:x%x OXID:x%x RXID:x%x"
5338 be32_to_cpu(bf_get(rrq_did, rrq)),
5339 bf_get(rrq_oxid, rrq),
5341 iocb->iotag, iocb->iocb.ulpContext);
5343 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
5344 "Clear RRQ: did:x%x flg:x%x exchg:x%.08x",
5345 ndlp->nlp_DID, ndlp->nlp_flag, rrq->rrq_exchg);
5346 if (vport->fc_myDID == be32_to_cpu(bf_get(rrq_did, rrq)))
5347 xri = bf_get(rrq_oxid, rrq);
5350 prrq = lpfc_get_active_rrq(vport, xri, ndlp->nlp_DID);
5352 lpfc_clr_rrq_active(phba, xri, prrq);
5357 * lpfc_els_rsp_echo_acc - Issue echo acc response
5358 * @vport: pointer to a virtual N_Port data structure.
5359 * @data: pointer to echo data to return in the accept.
5360 * @oldiocb: pointer to the original lpfc command iocb data structure.
5361 * @ndlp: pointer to a node-list data structure.
5364 * 0 - Successfully issued acc echo response
5365 * 1 - Failed to issue acc echo response
5368 lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data,
5369 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
5371 struct lpfc_hba *phba = vport->phba;
5372 struct lpfc_iocbq *elsiocb;
5377 cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len;
5379 /* The accumulated length can exceed the BPL_SIZE. For
5380 * now, use this as the limit
5382 if (cmdsize > LPFC_BPL_SIZE)
5383 cmdsize = LPFC_BPL_SIZE;
5384 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
5385 ndlp->nlp_DID, ELS_CMD_ACC);
5389 elsiocb->iocb.ulpContext = oldiocb->iocb.ulpContext; /* Xri / rx_id */
5390 elsiocb->iocb.unsli3.rcvsli3.ox_id = oldiocb->iocb.unsli3.rcvsli3.ox_id;
5392 /* Xmit ECHO ACC response tag <ulpIoTag> */
5393 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5394 "2876 Xmit ECHO ACC response tag x%x xri x%x\n",
5395 elsiocb->iotag, elsiocb->iocb.ulpContext);
5396 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5397 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5398 pcmd += sizeof(uint32_t);
5399 memcpy(pcmd, data, cmdsize - sizeof(uint32_t));
5401 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
5402 "Issue ACC ECHO: did:x%x flg:x%x refcnt %d",
5403 ndlp->nlp_DID, ndlp->nlp_flag, kref_read(&ndlp->kref));
5405 phba->fc_stat.elsXmitACC++;
5406 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5407 elsiocb->context1 = lpfc_nlp_get(ndlp);
5408 if (!elsiocb->context1)
5411 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5412 if (rc == IOCB_ERROR)
5419 lpfc_els_free_iocb(phba, elsiocb);
5424 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
5425 * @vport: pointer to a host virtual N_Port data structure.
5427 * This routine issues Address Discover (ADISC) ELS commands to those
5428 * N_Ports which are in node port recovery state and ADISC has not been issued
5429 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
5430 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
5431 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
5432 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
5433 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
5434 * IOCBs quit for later pick up. On the other hand, after walking through
5435 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
5436 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
5437 * no more ADISC need to be sent.
5440 * The number of N_Ports with adisc issued.
5443 lpfc_els_disc_adisc(struct lpfc_vport *vport)
5445 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5446 struct lpfc_nodelist *ndlp, *next_ndlp;
5449 /* go thru NPR nodes and issue any remaining ELS ADISCs */
5450 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
5451 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
5452 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
5453 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
5454 spin_lock_irq(shost->host_lock);
5455 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
5456 spin_unlock_irq(shost->host_lock);
5457 ndlp->nlp_prev_state = ndlp->nlp_state;
5458 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
5459 lpfc_issue_els_adisc(vport, ndlp, 0);
5461 vport->num_disc_nodes++;
5462 if (vport->num_disc_nodes >=
5463 vport->cfg_discovery_threads) {
5464 spin_lock_irq(shost->host_lock);
5465 vport->fc_flag |= FC_NLP_MORE;
5466 spin_unlock_irq(shost->host_lock);
5471 if (sentadisc == 0) {
5472 spin_lock_irq(shost->host_lock);
5473 vport->fc_flag &= ~FC_NLP_MORE;
5474 spin_unlock_irq(shost->host_lock);
5480 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
5481 * @vport: pointer to a host virtual N_Port data structure.
5483 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
5484 * which are in node port recovery state, with a @vport. Each time an ELS
5485 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
5486 * the per @vport number of discover count (num_disc_nodes) shall be
5487 * incremented. If the num_disc_nodes reaches a pre-configured threshold
5488 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
5489 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
5490 * later pick up. On the other hand, after walking through all the ndlps with
5491 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
5492 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
5493 * PLOGI need to be sent.
5496 * The number of N_Ports with plogi issued.
5499 lpfc_els_disc_plogi(struct lpfc_vport *vport)
5501 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5502 struct lpfc_nodelist *ndlp, *next_ndlp;
5505 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
5506 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
5507 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
5508 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
5509 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
5510 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
5511 ndlp->nlp_prev_state = ndlp->nlp_state;
5512 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
5513 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
5515 vport->num_disc_nodes++;
5516 if (vport->num_disc_nodes >=
5517 vport->cfg_discovery_threads) {
5518 spin_lock_irq(shost->host_lock);
5519 vport->fc_flag |= FC_NLP_MORE;
5520 spin_unlock_irq(shost->host_lock);
5526 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5527 "6452 Discover PLOGI %d flag x%x\n",
5528 sentplogi, vport->fc_flag);
5531 lpfc_set_disctmo(vport);
5534 spin_lock_irq(shost->host_lock);
5535 vport->fc_flag &= ~FC_NLP_MORE;
5536 spin_unlock_irq(shost->host_lock);
5542 lpfc_rdp_res_link_service(struct fc_rdp_link_service_desc *desc,
5546 desc->tag = cpu_to_be32(RDP_LINK_SERVICE_DESC_TAG);
5547 desc->payload.els_req = word0;
5548 desc->length = cpu_to_be32(sizeof(desc->payload));
5550 return sizeof(struct fc_rdp_link_service_desc);
5554 lpfc_rdp_res_sfp_desc(struct fc_rdp_sfp_desc *desc,
5555 uint8_t *page_a0, uint8_t *page_a2)
5557 uint16_t wavelength;
5558 uint16_t temperature;
5564 struct sff_trasnceiver_codes_byte4 *trasn_code_byte4;
5565 struct sff_trasnceiver_codes_byte5 *trasn_code_byte5;
5567 desc->tag = cpu_to_be32(RDP_SFP_DESC_TAG);
5569 trasn_code_byte4 = (struct sff_trasnceiver_codes_byte4 *)
5570 &page_a0[SSF_TRANSCEIVER_CODE_B4];
5571 trasn_code_byte5 = (struct sff_trasnceiver_codes_byte5 *)
5572 &page_a0[SSF_TRANSCEIVER_CODE_B5];
5574 if ((trasn_code_byte4->fc_sw_laser) ||
5575 (trasn_code_byte5->fc_sw_laser_sl) ||
5576 (trasn_code_byte5->fc_sw_laser_sn)) { /* check if its short WL */
5577 flag |= (SFP_FLAG_PT_SWLASER << SFP_FLAG_PT_SHIFT);
5578 } else if (trasn_code_byte4->fc_lw_laser) {
5579 wavelength = (page_a0[SSF_WAVELENGTH_B1] << 8) |
5580 page_a0[SSF_WAVELENGTH_B0];
5581 if (wavelength == SFP_WAVELENGTH_LC1310)
5582 flag |= SFP_FLAG_PT_LWLASER_LC1310 << SFP_FLAG_PT_SHIFT;
5583 if (wavelength == SFP_WAVELENGTH_LL1550)
5584 flag |= SFP_FLAG_PT_LWLASER_LL1550 << SFP_FLAG_PT_SHIFT;
5586 /* check if its SFP+ */
5587 flag |= ((page_a0[SSF_IDENTIFIER] == SFF_PG0_IDENT_SFP) ?
5588 SFP_FLAG_CT_SFP_PLUS : SFP_FLAG_CT_UNKNOWN)
5589 << SFP_FLAG_CT_SHIFT;
5591 /* check if its OPTICAL */
5592 flag |= ((page_a0[SSF_CONNECTOR] == SFF_PG0_CONNECTOR_LC) ?
5593 SFP_FLAG_IS_OPTICAL_PORT : 0)
5594 << SFP_FLAG_IS_OPTICAL_SHIFT;
5596 temperature = (page_a2[SFF_TEMPERATURE_B1] << 8 |
5597 page_a2[SFF_TEMPERATURE_B0]);
5598 vcc = (page_a2[SFF_VCC_B1] << 8 |
5599 page_a2[SFF_VCC_B0]);
5600 tx_power = (page_a2[SFF_TXPOWER_B1] << 8 |
5601 page_a2[SFF_TXPOWER_B0]);
5602 tx_bias = (page_a2[SFF_TX_BIAS_CURRENT_B1] << 8 |
5603 page_a2[SFF_TX_BIAS_CURRENT_B0]);
5604 rx_power = (page_a2[SFF_RXPOWER_B1] << 8 |
5605 page_a2[SFF_RXPOWER_B0]);
5606 desc->sfp_info.temperature = cpu_to_be16(temperature);
5607 desc->sfp_info.rx_power = cpu_to_be16(rx_power);
5608 desc->sfp_info.tx_bias = cpu_to_be16(tx_bias);
5609 desc->sfp_info.tx_power = cpu_to_be16(tx_power);
5610 desc->sfp_info.vcc = cpu_to_be16(vcc);
5612 desc->sfp_info.flags = cpu_to_be16(flag);
5613 desc->length = cpu_to_be32(sizeof(desc->sfp_info));
5615 return sizeof(struct fc_rdp_sfp_desc);
5619 lpfc_rdp_res_link_error(struct fc_rdp_link_error_status_desc *desc,
5624 desc->tag = cpu_to_be32(RDP_LINK_ERROR_STATUS_DESC_TAG);
5626 type = VN_PT_PHY_PF_PORT << VN_PT_PHY_SHIFT;
5628 desc->info.port_type = cpu_to_be32(type);
5630 desc->info.link_status.link_failure_cnt =
5631 cpu_to_be32(stat->linkFailureCnt);
5632 desc->info.link_status.loss_of_synch_cnt =
5633 cpu_to_be32(stat->lossSyncCnt);
5634 desc->info.link_status.loss_of_signal_cnt =
5635 cpu_to_be32(stat->lossSignalCnt);
5636 desc->info.link_status.primitive_seq_proto_err =
5637 cpu_to_be32(stat->primSeqErrCnt);
5638 desc->info.link_status.invalid_trans_word =
5639 cpu_to_be32(stat->invalidXmitWord);
5640 desc->info.link_status.invalid_crc_cnt = cpu_to_be32(stat->crcCnt);
5642 desc->length = cpu_to_be32(sizeof(desc->info));
5644 return sizeof(struct fc_rdp_link_error_status_desc);
5648 lpfc_rdp_res_bbc_desc(struct fc_rdp_bbc_desc *desc, READ_LNK_VAR *stat,
5649 struct lpfc_vport *vport)
5653 desc->tag = cpu_to_be32(RDP_BBC_DESC_TAG);
5655 bbCredit = vport->fc_sparam.cmn.bbCreditLsb |
5656 (vport->fc_sparam.cmn.bbCreditMsb << 8);
5657 desc->bbc_info.port_bbc = cpu_to_be32(bbCredit);
5658 if (vport->phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
5659 bbCredit = vport->phba->fc_fabparam.cmn.bbCreditLsb |
5660 (vport->phba->fc_fabparam.cmn.bbCreditMsb << 8);
5661 desc->bbc_info.attached_port_bbc = cpu_to_be32(bbCredit);
5663 desc->bbc_info.attached_port_bbc = 0;
5666 desc->bbc_info.rtt = 0;
5667 desc->length = cpu_to_be32(sizeof(desc->bbc_info));
5669 return sizeof(struct fc_rdp_bbc_desc);
5673 lpfc_rdp_res_oed_temp_desc(struct lpfc_hba *phba,
5674 struct fc_rdp_oed_sfp_desc *desc, uint8_t *page_a2)
5678 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5680 desc->oed_info.hi_alarm = page_a2[SSF_TEMP_HIGH_ALARM];
5681 desc->oed_info.lo_alarm = page_a2[SSF_TEMP_LOW_ALARM];
5682 desc->oed_info.hi_warning = page_a2[SSF_TEMP_HIGH_WARNING];
5683 desc->oed_info.lo_warning = page_a2[SSF_TEMP_LOW_WARNING];
5685 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TEMPERATURE)
5686 flags |= RDP_OET_HIGH_ALARM;
5687 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TEMPERATURE)
5688 flags |= RDP_OET_LOW_ALARM;
5689 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TEMPERATURE)
5690 flags |= RDP_OET_HIGH_WARNING;
5691 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TEMPERATURE)
5692 flags |= RDP_OET_LOW_WARNING;
5694 flags |= ((0xf & RDP_OED_TEMPERATURE) << RDP_OED_TYPE_SHIFT);
5695 desc->oed_info.function_flags = cpu_to_be32(flags);
5696 desc->length = cpu_to_be32(sizeof(desc->oed_info));
5697 return sizeof(struct fc_rdp_oed_sfp_desc);
5701 lpfc_rdp_res_oed_voltage_desc(struct lpfc_hba *phba,
5702 struct fc_rdp_oed_sfp_desc *desc,
5707 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5709 desc->oed_info.hi_alarm = page_a2[SSF_VOLTAGE_HIGH_ALARM];
5710 desc->oed_info.lo_alarm = page_a2[SSF_VOLTAGE_LOW_ALARM];
5711 desc->oed_info.hi_warning = page_a2[SSF_VOLTAGE_HIGH_WARNING];
5712 desc->oed_info.lo_warning = page_a2[SSF_VOLTAGE_LOW_WARNING];
5714 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_VOLTAGE)
5715 flags |= RDP_OET_HIGH_ALARM;
5716 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_VOLTAGE)
5717 flags |= RDP_OET_LOW_ALARM;
5718 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_VOLTAGE)
5719 flags |= RDP_OET_HIGH_WARNING;
5720 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_VOLTAGE)
5721 flags |= RDP_OET_LOW_WARNING;
5723 flags |= ((0xf & RDP_OED_VOLTAGE) << RDP_OED_TYPE_SHIFT);
5724 desc->oed_info.function_flags = cpu_to_be32(flags);
5725 desc->length = cpu_to_be32(sizeof(desc->oed_info));
5726 return sizeof(struct fc_rdp_oed_sfp_desc);
5730 lpfc_rdp_res_oed_txbias_desc(struct lpfc_hba *phba,
5731 struct fc_rdp_oed_sfp_desc *desc,
5736 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5738 desc->oed_info.hi_alarm = page_a2[SSF_BIAS_HIGH_ALARM];
5739 desc->oed_info.lo_alarm = page_a2[SSF_BIAS_LOW_ALARM];
5740 desc->oed_info.hi_warning = page_a2[SSF_BIAS_HIGH_WARNING];
5741 desc->oed_info.lo_warning = page_a2[SSF_BIAS_LOW_WARNING];
5743 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TXBIAS)
5744 flags |= RDP_OET_HIGH_ALARM;
5745 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TXBIAS)
5746 flags |= RDP_OET_LOW_ALARM;
5747 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TXBIAS)
5748 flags |= RDP_OET_HIGH_WARNING;
5749 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TXBIAS)
5750 flags |= RDP_OET_LOW_WARNING;
5752 flags |= ((0xf & RDP_OED_TXBIAS) << RDP_OED_TYPE_SHIFT);
5753 desc->oed_info.function_flags = cpu_to_be32(flags);
5754 desc->length = cpu_to_be32(sizeof(desc->oed_info));
5755 return sizeof(struct fc_rdp_oed_sfp_desc);
5759 lpfc_rdp_res_oed_txpower_desc(struct lpfc_hba *phba,
5760 struct fc_rdp_oed_sfp_desc *desc,
5765 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5767 desc->oed_info.hi_alarm = page_a2[SSF_TXPOWER_HIGH_ALARM];
5768 desc->oed_info.lo_alarm = page_a2[SSF_TXPOWER_LOW_ALARM];
5769 desc->oed_info.hi_warning = page_a2[SSF_TXPOWER_HIGH_WARNING];
5770 desc->oed_info.lo_warning = page_a2[SSF_TXPOWER_LOW_WARNING];
5772 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TXPOWER)
5773 flags |= RDP_OET_HIGH_ALARM;
5774 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TXPOWER)
5775 flags |= RDP_OET_LOW_ALARM;
5776 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TXPOWER)
5777 flags |= RDP_OET_HIGH_WARNING;
5778 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TXPOWER)
5779 flags |= RDP_OET_LOW_WARNING;
5781 flags |= ((0xf & RDP_OED_TXPOWER) << RDP_OED_TYPE_SHIFT);
5782 desc->oed_info.function_flags = cpu_to_be32(flags);
5783 desc->length = cpu_to_be32(sizeof(desc->oed_info));
5784 return sizeof(struct fc_rdp_oed_sfp_desc);
5789 lpfc_rdp_res_oed_rxpower_desc(struct lpfc_hba *phba,
5790 struct fc_rdp_oed_sfp_desc *desc,
5795 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5797 desc->oed_info.hi_alarm = page_a2[SSF_RXPOWER_HIGH_ALARM];
5798 desc->oed_info.lo_alarm = page_a2[SSF_RXPOWER_LOW_ALARM];
5799 desc->oed_info.hi_warning = page_a2[SSF_RXPOWER_HIGH_WARNING];
5800 desc->oed_info.lo_warning = page_a2[SSF_RXPOWER_LOW_WARNING];
5802 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_RXPOWER)
5803 flags |= RDP_OET_HIGH_ALARM;
5804 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_RXPOWER)
5805 flags |= RDP_OET_LOW_ALARM;
5806 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_RXPOWER)
5807 flags |= RDP_OET_HIGH_WARNING;
5808 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_RXPOWER)
5809 flags |= RDP_OET_LOW_WARNING;
5811 flags |= ((0xf & RDP_OED_RXPOWER) << RDP_OED_TYPE_SHIFT);
5812 desc->oed_info.function_flags = cpu_to_be32(flags);
5813 desc->length = cpu_to_be32(sizeof(desc->oed_info));
5814 return sizeof(struct fc_rdp_oed_sfp_desc);
5818 lpfc_rdp_res_opd_desc(struct fc_rdp_opd_sfp_desc *desc,
5819 uint8_t *page_a0, struct lpfc_vport *vport)
5821 desc->tag = cpu_to_be32(RDP_OPD_DESC_TAG);
5822 memcpy(desc->opd_info.vendor_name, &page_a0[SSF_VENDOR_NAME], 16);
5823 memcpy(desc->opd_info.model_number, &page_a0[SSF_VENDOR_PN], 16);
5824 memcpy(desc->opd_info.serial_number, &page_a0[SSF_VENDOR_SN], 16);
5825 memcpy(desc->opd_info.revision, &page_a0[SSF_VENDOR_REV], 4);
5826 memcpy(desc->opd_info.date, &page_a0[SSF_DATE_CODE], 8);
5827 desc->length = cpu_to_be32(sizeof(desc->opd_info));
5828 return sizeof(struct fc_rdp_opd_sfp_desc);
5832 lpfc_rdp_res_fec_desc(struct fc_fec_rdp_desc *desc, READ_LNK_VAR *stat)
5834 if (bf_get(lpfc_read_link_stat_gec2, stat) == 0)
5836 desc->tag = cpu_to_be32(RDP_FEC_DESC_TAG);
5838 desc->info.CorrectedBlocks =
5839 cpu_to_be32(stat->fecCorrBlkCount);
5840 desc->info.UncorrectableBlocks =
5841 cpu_to_be32(stat->fecUncorrBlkCount);
5843 desc->length = cpu_to_be32(sizeof(desc->info));
5845 return sizeof(struct fc_fec_rdp_desc);
5849 lpfc_rdp_res_speed(struct fc_rdp_port_speed_desc *desc, struct lpfc_hba *phba)
5851 uint16_t rdp_cap = 0;
5854 desc->tag = cpu_to_be32(RDP_PORT_SPEED_DESC_TAG);
5856 switch (phba->fc_linkspeed) {
5857 case LPFC_LINK_SPEED_1GHZ:
5858 rdp_speed = RDP_PS_1GB;
5860 case LPFC_LINK_SPEED_2GHZ:
5861 rdp_speed = RDP_PS_2GB;
5863 case LPFC_LINK_SPEED_4GHZ:
5864 rdp_speed = RDP_PS_4GB;
5866 case LPFC_LINK_SPEED_8GHZ:
5867 rdp_speed = RDP_PS_8GB;
5869 case LPFC_LINK_SPEED_10GHZ:
5870 rdp_speed = RDP_PS_10GB;
5872 case LPFC_LINK_SPEED_16GHZ:
5873 rdp_speed = RDP_PS_16GB;
5875 case LPFC_LINK_SPEED_32GHZ:
5876 rdp_speed = RDP_PS_32GB;
5878 case LPFC_LINK_SPEED_64GHZ:
5879 rdp_speed = RDP_PS_64GB;
5882 rdp_speed = RDP_PS_UNKNOWN;
5886 desc->info.port_speed.speed = cpu_to_be16(rdp_speed);
5888 if (phba->lmt & LMT_128Gb)
5889 rdp_cap |= RDP_PS_128GB;
5890 if (phba->lmt & LMT_64Gb)
5891 rdp_cap |= RDP_PS_64GB;
5892 if (phba->lmt & LMT_32Gb)
5893 rdp_cap |= RDP_PS_32GB;
5894 if (phba->lmt & LMT_16Gb)
5895 rdp_cap |= RDP_PS_16GB;
5896 if (phba->lmt & LMT_10Gb)
5897 rdp_cap |= RDP_PS_10GB;
5898 if (phba->lmt & LMT_8Gb)
5899 rdp_cap |= RDP_PS_8GB;
5900 if (phba->lmt & LMT_4Gb)
5901 rdp_cap |= RDP_PS_4GB;
5902 if (phba->lmt & LMT_2Gb)
5903 rdp_cap |= RDP_PS_2GB;
5904 if (phba->lmt & LMT_1Gb)
5905 rdp_cap |= RDP_PS_1GB;
5908 rdp_cap = RDP_CAP_UNKNOWN;
5909 if (phba->cfg_link_speed != LPFC_USER_LINK_SPEED_AUTO)
5910 rdp_cap |= RDP_CAP_USER_CONFIGURED;
5912 desc->info.port_speed.capabilities = cpu_to_be16(rdp_cap);
5913 desc->length = cpu_to_be32(sizeof(desc->info));
5914 return sizeof(struct fc_rdp_port_speed_desc);
5918 lpfc_rdp_res_diag_port_names(struct fc_rdp_port_name_desc *desc,
5919 struct lpfc_vport *vport)
5922 desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG);
5924 memcpy(desc->port_names.wwnn, &vport->fc_nodename,
5925 sizeof(desc->port_names.wwnn));
5927 memcpy(desc->port_names.wwpn, &vport->fc_portname,
5928 sizeof(desc->port_names.wwpn));
5930 desc->length = cpu_to_be32(sizeof(desc->port_names));
5931 return sizeof(struct fc_rdp_port_name_desc);
5935 lpfc_rdp_res_attach_port_names(struct fc_rdp_port_name_desc *desc,
5936 struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
5939 desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG);
5940 if (vport->fc_flag & FC_FABRIC) {
5941 memcpy(desc->port_names.wwnn, &vport->fabric_nodename,
5942 sizeof(desc->port_names.wwnn));
5944 memcpy(desc->port_names.wwpn, &vport->fabric_portname,
5945 sizeof(desc->port_names.wwpn));
5946 } else { /* Point to Point */
5947 memcpy(desc->port_names.wwnn, &ndlp->nlp_nodename,
5948 sizeof(desc->port_names.wwnn));
5950 memcpy(desc->port_names.wwpn, &ndlp->nlp_portname,
5951 sizeof(desc->port_names.wwpn));
5954 desc->length = cpu_to_be32(sizeof(desc->port_names));
5955 return sizeof(struct fc_rdp_port_name_desc);
5959 lpfc_els_rdp_cmpl(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context,
5962 struct lpfc_nodelist *ndlp = rdp_context->ndlp;
5963 struct lpfc_vport *vport = ndlp->vport;
5964 struct lpfc_iocbq *elsiocb;
5965 struct ulp_bde64 *bpl;
5968 struct ls_rjt *stat;
5969 struct fc_rdp_res_frame *rdp_res;
5970 uint32_t cmdsize, len;
5974 if (status != SUCCESS)
5977 /* This will change once we know the true size of the RDP payload */
5978 cmdsize = sizeof(struct fc_rdp_res_frame);
5980 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize,
5981 lpfc_max_els_tries, rdp_context->ndlp,
5982 rdp_context->ndlp->nlp_DID, ELS_CMD_ACC);
5984 goto free_rdp_context;
5986 icmd = &elsiocb->iocb;
5987 icmd->ulpContext = rdp_context->rx_id;
5988 icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id;
5990 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5991 "2171 Xmit RDP response tag x%x xri x%x, "
5992 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x",
5993 elsiocb->iotag, elsiocb->iocb.ulpContext,
5994 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5996 rdp_res = (struct fc_rdp_res_frame *)
5997 (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5998 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5999 memset(pcmd, 0, sizeof(struct fc_rdp_res_frame));
6000 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
6002 /* Update Alarm and Warning */
6003 flag_ptr = (uint16_t *)(rdp_context->page_a2 + SSF_ALARM_FLAGS);
6004 phba->sfp_alarm |= *flag_ptr;
6005 flag_ptr = (uint16_t *)(rdp_context->page_a2 + SSF_WARNING_FLAGS);
6006 phba->sfp_warning |= *flag_ptr;
6008 /* For RDP payload */
6010 len += lpfc_rdp_res_link_service((struct fc_rdp_link_service_desc *)
6011 (len + pcmd), ELS_CMD_RDP);
6013 len += lpfc_rdp_res_sfp_desc((struct fc_rdp_sfp_desc *)(len + pcmd),
6014 rdp_context->page_a0, rdp_context->page_a2);
6015 len += lpfc_rdp_res_speed((struct fc_rdp_port_speed_desc *)(len + pcmd),
6017 len += lpfc_rdp_res_link_error((struct fc_rdp_link_error_status_desc *)
6018 (len + pcmd), &rdp_context->link_stat);
6019 len += lpfc_rdp_res_diag_port_names((struct fc_rdp_port_name_desc *)
6020 (len + pcmd), vport);
6021 len += lpfc_rdp_res_attach_port_names((struct fc_rdp_port_name_desc *)
6022 (len + pcmd), vport, ndlp);
6023 len += lpfc_rdp_res_fec_desc((struct fc_fec_rdp_desc *)(len + pcmd),
6024 &rdp_context->link_stat);
6025 len += lpfc_rdp_res_bbc_desc((struct fc_rdp_bbc_desc *)(len + pcmd),
6026 &rdp_context->link_stat, vport);
6027 len += lpfc_rdp_res_oed_temp_desc(phba,
6028 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
6029 rdp_context->page_a2);
6030 len += lpfc_rdp_res_oed_voltage_desc(phba,
6031 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
6032 rdp_context->page_a2);
6033 len += lpfc_rdp_res_oed_txbias_desc(phba,
6034 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
6035 rdp_context->page_a2);
6036 len += lpfc_rdp_res_oed_txpower_desc(phba,
6037 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
6038 rdp_context->page_a2);
6039 len += lpfc_rdp_res_oed_rxpower_desc(phba,
6040 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
6041 rdp_context->page_a2);
6042 len += lpfc_rdp_res_opd_desc((struct fc_rdp_opd_sfp_desc *)(len + pcmd),
6043 rdp_context->page_a0, vport);
6045 rdp_res->length = cpu_to_be32(len - 8);
6046 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
6048 /* Now that we know the true size of the payload, update the BPL */
6049 bpl = (struct ulp_bde64 *)
6050 (((struct lpfc_dmabuf *)(elsiocb->context3))->virt);
6051 bpl->tus.f.bdeSize = len;
6052 bpl->tus.f.bdeFlags = 0;
6053 bpl->tus.w = le32_to_cpu(bpl->tus.w);
6055 phba->fc_stat.elsXmitACC++;
6056 elsiocb->context1 = lpfc_nlp_get(ndlp);
6057 if (!elsiocb->context1) {
6058 lpfc_els_free_iocb(phba, elsiocb);
6059 goto free_rdp_context;
6062 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
6063 if (rc == IOCB_ERROR) {
6065 lpfc_els_free_iocb(phba, elsiocb);
6068 goto free_rdp_context;
6071 cmdsize = 2 * sizeof(uint32_t);
6072 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, lpfc_max_els_tries,
6073 ndlp, ndlp->nlp_DID, ELS_CMD_LS_RJT);
6075 goto free_rdp_context;
6077 icmd = &elsiocb->iocb;
6078 icmd->ulpContext = rdp_context->rx_id;
6079 icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id;
6080 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6082 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
6083 stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t));
6084 stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6086 phba->fc_stat.elsXmitLSRJT++;
6087 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
6088 elsiocb->context1 = lpfc_nlp_get(ndlp);
6089 if (!elsiocb->context1) {
6090 lpfc_els_free_iocb(phba, elsiocb);
6091 goto free_rdp_context;
6094 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
6095 if (rc == IOCB_ERROR) {
6097 lpfc_els_free_iocb(phba, elsiocb);
6101 /* This reference put is for the original unsolicited RDP. If the
6102 * iocb prep failed, there is no reference to remove.
6109 lpfc_get_rdp_info(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context)
6111 LPFC_MBOXQ_t *mbox = NULL;
6114 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6116 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_ELS,
6117 "7105 failed to allocate mailbox memory");
6121 if (lpfc_sli4_dump_page_a0(phba, mbox))
6122 goto prep_mbox_fail;
6123 mbox->vport = rdp_context->ndlp->vport;
6124 mbox->mbox_cmpl = lpfc_mbx_cmpl_rdp_page_a0;
6125 mbox->ctx_ndlp = (struct lpfc_rdp_context *)rdp_context;
6126 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
6127 if (rc == MBX_NOT_FINISHED)
6128 goto issue_mbox_fail;
6134 mempool_free(mbox, phba->mbox_mem_pool);
6139 * lpfc_els_rcv_rdp - Process an unsolicited RDP ELS.
6140 * @vport: pointer to a host virtual N_Port data structure.
6141 * @cmdiocb: pointer to lpfc command iocb data structure.
6142 * @ndlp: pointer to a node-list data structure.
6144 * This routine processes an unsolicited RDP(Read Diagnostic Parameters)
6145 * IOCB. First, the payload of the unsolicited RDP is checked.
6146 * Then it will (1) send MBX_DUMP_MEMORY, Embedded DMP_LMSD sub command TYPE-3
6147 * for Page A0, (2) send MBX_DUMP_MEMORY, DMP_LMSD for Page A2,
6148 * (3) send MBX_READ_LNK_STAT to get link stat, (4) Call lpfc_els_rdp_cmpl
6149 * gather all data and send RDP response.
6152 * 0 - Sent the acc response
6153 * 1 - Sent the reject response.
6156 lpfc_els_rcv_rdp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6157 struct lpfc_nodelist *ndlp)
6159 struct lpfc_hba *phba = vport->phba;
6160 struct lpfc_dmabuf *pcmd;
6161 uint8_t rjt_err, rjt_expl = LSEXP_NOTHING_MORE;
6162 struct fc_rdp_req_frame *rdp_req;
6163 struct lpfc_rdp_context *rdp_context;
6167 if (phba->sli_rev < LPFC_SLI_REV4 ||
6168 bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
6169 LPFC_SLI_INTF_IF_TYPE_2) {
6170 rjt_err = LSRJT_UNABLE_TPC;
6171 rjt_expl = LSEXP_REQ_UNSUPPORTED;
6175 if (phba->sli_rev < LPFC_SLI_REV4 || (phba->hba_flag & HBA_FCOE_MODE)) {
6176 rjt_err = LSRJT_UNABLE_TPC;
6177 rjt_expl = LSEXP_REQ_UNSUPPORTED;
6181 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6182 rdp_req = (struct fc_rdp_req_frame *) pcmd->virt;
6184 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6185 "2422 ELS RDP Request "
6186 "dec len %d tag x%x port_id %d len %d\n",
6187 be32_to_cpu(rdp_req->rdp_des_length),
6188 be32_to_cpu(rdp_req->nport_id_desc.tag),
6189 be32_to_cpu(rdp_req->nport_id_desc.nport_id),
6190 be32_to_cpu(rdp_req->nport_id_desc.length));
6192 if (sizeof(struct fc_rdp_nport_desc) !=
6193 be32_to_cpu(rdp_req->rdp_des_length))
6195 if (RDP_N_PORT_DESC_TAG != be32_to_cpu(rdp_req->nport_id_desc.tag))
6197 if (RDP_NPORT_ID_SIZE !=
6198 be32_to_cpu(rdp_req->nport_id_desc.length))
6200 rdp_context = kzalloc(sizeof(struct lpfc_rdp_context), GFP_KERNEL);
6202 rjt_err = LSRJT_UNABLE_TPC;
6206 cmd = &cmdiocb->iocb;
6207 rdp_context->ndlp = lpfc_nlp_get(ndlp);
6208 if (!rdp_context->ndlp) {
6210 rjt_err = LSRJT_UNABLE_TPC;
6213 rdp_context->ox_id = cmd->unsli3.rcvsli3.ox_id;
6214 rdp_context->rx_id = cmd->ulpContext;
6215 rdp_context->cmpl = lpfc_els_rdp_cmpl;
6216 if (lpfc_get_rdp_info(phba, rdp_context)) {
6217 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_ELS,
6218 "2423 Unable to send mailbox");
6220 rjt_err = LSRJT_UNABLE_TPC;
6228 rjt_err = LSRJT_LOGICAL_ERR;
6231 memset(&stat, 0, sizeof(stat));
6232 stat.un.b.lsRjtRsnCode = rjt_err;
6233 stat.un.b.lsRjtRsnCodeExp = rjt_expl;
6234 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
6240 lpfc_els_lcb_rsp(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
6245 struct lpfc_iocbq *elsiocb;
6246 struct lpfc_nodelist *ndlp;
6247 struct ls_rjt *stat;
6248 union lpfc_sli4_cfg_shdr *shdr;
6249 struct lpfc_lcb_context *lcb_context;
6250 struct fc_lcb_res_frame *lcb_res;
6251 uint32_t cmdsize, shdr_status, shdr_add_status;
6255 lcb_context = (struct lpfc_lcb_context *)pmb->ctx_ndlp;
6256 ndlp = lcb_context->ndlp;
6257 pmb->ctx_ndlp = NULL;
6258 pmb->ctx_buf = NULL;
6260 shdr = (union lpfc_sli4_cfg_shdr *)
6261 &pmb->u.mqe.un.beacon_config.header.cfg_shdr;
6262 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
6263 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
6265 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX,
6266 "0194 SET_BEACON_CONFIG mailbox "
6267 "completed with status x%x add_status x%x,"
6268 " mbx status x%x\n",
6269 shdr_status, shdr_add_status, mb->mbxStatus);
6271 if ((mb->mbxStatus != MBX_SUCCESS) || shdr_status ||
6272 (shdr_add_status == ADD_STATUS_OPERATION_ALREADY_ACTIVE) ||
6273 (shdr_add_status == ADD_STATUS_INVALID_REQUEST)) {
6274 mempool_free(pmb, phba->mbox_mem_pool);
6278 mempool_free(pmb, phba->mbox_mem_pool);
6279 cmdsize = sizeof(struct fc_lcb_res_frame);
6280 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
6281 lpfc_max_els_tries, ndlp,
6282 ndlp->nlp_DID, ELS_CMD_ACC);
6284 /* Decrement the ndlp reference count from previous mbox command */
6288 goto free_lcb_context;
6290 lcb_res = (struct fc_lcb_res_frame *)
6291 (((struct lpfc_dmabuf *)elsiocb->context2)->virt);
6293 memset(lcb_res, 0, sizeof(struct fc_lcb_res_frame));
6294 icmd = &elsiocb->iocb;
6295 icmd->ulpContext = lcb_context->rx_id;
6296 icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id;
6298 pcmd = (uint8_t *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt);
6299 *((uint32_t *)(pcmd)) = ELS_CMD_ACC;
6300 lcb_res->lcb_sub_command = lcb_context->sub_command;
6301 lcb_res->lcb_type = lcb_context->type;
6302 lcb_res->capability = lcb_context->capability;
6303 lcb_res->lcb_frequency = lcb_context->frequency;
6304 lcb_res->lcb_duration = lcb_context->duration;
6305 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
6306 phba->fc_stat.elsXmitACC++;
6308 elsiocb->context1 = lpfc_nlp_get(ndlp);
6309 if (!elsiocb->context1)
6312 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
6318 lpfc_els_free_iocb(phba, elsiocb);
6324 cmdsize = sizeof(struct fc_lcb_res_frame);
6325 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
6326 lpfc_max_els_tries, ndlp,
6327 ndlp->nlp_DID, ELS_CMD_LS_RJT);
6330 goto free_lcb_context;
6332 icmd = &elsiocb->iocb;
6333 icmd->ulpContext = lcb_context->rx_id;
6334 icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id;
6335 pcmd = (uint8_t *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt);
6337 *((uint32_t *)(pcmd)) = ELS_CMD_LS_RJT;
6338 stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t));
6339 stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6341 if (shdr_add_status == ADD_STATUS_OPERATION_ALREADY_ACTIVE)
6342 stat->un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS;
6344 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
6345 phba->fc_stat.elsXmitLSRJT++;
6346 elsiocb->context1 = lpfc_nlp_get(ndlp);
6347 if (!elsiocb->context1) {
6348 lpfc_els_free_iocb(phba, elsiocb);
6349 goto free_lcb_context;
6352 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
6353 if (rc == IOCB_ERROR) {
6355 lpfc_els_free_iocb(phba, elsiocb);
6362 lpfc_sli4_set_beacon(struct lpfc_vport *vport,
6363 struct lpfc_lcb_context *lcb_context,
6364 uint32_t beacon_state)
6366 struct lpfc_hba *phba = vport->phba;
6367 union lpfc_sli4_cfg_shdr *cfg_shdr;
6368 LPFC_MBOXQ_t *mbox = NULL;
6372 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6376 cfg_shdr = &mbox->u.mqe.un.sli4_config.header.cfg_shdr;
6377 len = sizeof(struct lpfc_mbx_set_beacon_config) -
6378 sizeof(struct lpfc_sli4_cfg_mhdr);
6379 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
6380 LPFC_MBOX_OPCODE_SET_BEACON_CONFIG, len,
6381 LPFC_SLI4_MBX_EMBED);
6382 mbox->ctx_ndlp = (void *)lcb_context;
6383 mbox->vport = phba->pport;
6384 mbox->mbox_cmpl = lpfc_els_lcb_rsp;
6385 bf_set(lpfc_mbx_set_beacon_port_num, &mbox->u.mqe.un.beacon_config,
6386 phba->sli4_hba.physical_port);
6387 bf_set(lpfc_mbx_set_beacon_state, &mbox->u.mqe.un.beacon_config,
6389 mbox->u.mqe.un.beacon_config.word5 = 0; /* Reserved */
6392 * Check bv1s bit before issuing the mailbox
6393 * if bv1s == 1, LCB V1 supported
6394 * else, LCB V0 supported
6397 if (phba->sli4_hba.pc_sli4_params.bv1s) {
6398 /* COMMON_SET_BEACON_CONFIG_V1 */
6399 cfg_shdr->request.word9 = BEACON_VERSION_V1;
6400 lcb_context->capability |= LCB_CAPABILITY_DURATION;
6401 bf_set(lpfc_mbx_set_beacon_port_type,
6402 &mbox->u.mqe.un.beacon_config, 0);
6403 bf_set(lpfc_mbx_set_beacon_duration_v1,
6404 &mbox->u.mqe.un.beacon_config,
6405 be16_to_cpu(lcb_context->duration));
6407 /* COMMON_SET_BEACON_CONFIG_V0 */
6408 if (be16_to_cpu(lcb_context->duration) != 0) {
6409 mempool_free(mbox, phba->mbox_mem_pool);
6412 cfg_shdr->request.word9 = BEACON_VERSION_V0;
6413 lcb_context->capability &= ~(LCB_CAPABILITY_DURATION);
6414 bf_set(lpfc_mbx_set_beacon_state,
6415 &mbox->u.mqe.un.beacon_config, beacon_state);
6416 bf_set(lpfc_mbx_set_beacon_port_type,
6417 &mbox->u.mqe.un.beacon_config, 1);
6418 bf_set(lpfc_mbx_set_beacon_duration,
6419 &mbox->u.mqe.un.beacon_config,
6420 be16_to_cpu(lcb_context->duration));
6423 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
6424 if (rc == MBX_NOT_FINISHED) {
6425 mempool_free(mbox, phba->mbox_mem_pool);
6434 * lpfc_els_rcv_lcb - Process an unsolicited LCB
6435 * @vport: pointer to a host virtual N_Port data structure.
6436 * @cmdiocb: pointer to lpfc command iocb data structure.
6437 * @ndlp: pointer to a node-list data structure.
6439 * This routine processes an unsolicited LCB(LINK CABLE BEACON) IOCB.
6440 * First, the payload of the unsolicited LCB is checked.
6441 * Then based on Subcommand beacon will either turn on or off.
6444 * 0 - Sent the acc response
6445 * 1 - Sent the reject response.
6448 lpfc_els_rcv_lcb(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6449 struct lpfc_nodelist *ndlp)
6451 struct lpfc_hba *phba = vport->phba;
6452 struct lpfc_dmabuf *pcmd;
6454 struct fc_lcb_request_frame *beacon;
6455 struct lpfc_lcb_context *lcb_context;
6456 u8 state, rjt_err = 0;
6459 pcmd = (struct lpfc_dmabuf *)cmdiocb->context2;
6460 lp = (uint8_t *)pcmd->virt;
6461 beacon = (struct fc_lcb_request_frame *)pcmd->virt;
6463 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6464 "0192 ELS LCB Data x%x x%x x%x x%x sub x%x "
6465 "type x%x frequency %x duration x%x\n",
6466 lp[0], lp[1], lp[2],
6467 beacon->lcb_command,
6468 beacon->lcb_sub_command,
6470 beacon->lcb_frequency,
6471 be16_to_cpu(beacon->lcb_duration));
6473 if (beacon->lcb_sub_command != LPFC_LCB_ON &&
6474 beacon->lcb_sub_command != LPFC_LCB_OFF) {
6475 rjt_err = LSRJT_CMD_UNSUPPORTED;
6479 if (phba->sli_rev < LPFC_SLI_REV4 ||
6480 phba->hba_flag & HBA_FCOE_MODE ||
6481 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
6482 LPFC_SLI_INTF_IF_TYPE_2)) {
6483 rjt_err = LSRJT_CMD_UNSUPPORTED;
6487 lcb_context = kmalloc(sizeof(*lcb_context), GFP_KERNEL);
6489 rjt_err = LSRJT_UNABLE_TPC;
6493 state = (beacon->lcb_sub_command == LPFC_LCB_ON) ? 1 : 0;
6494 lcb_context->sub_command = beacon->lcb_sub_command;
6495 lcb_context->capability = 0;
6496 lcb_context->type = beacon->lcb_type;
6497 lcb_context->frequency = beacon->lcb_frequency;
6498 lcb_context->duration = beacon->lcb_duration;
6499 lcb_context->ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id;
6500 lcb_context->rx_id = cmdiocb->iocb.ulpContext;
6501 lcb_context->ndlp = lpfc_nlp_get(ndlp);
6502 if (!lcb_context->ndlp) {
6503 rjt_err = LSRJT_UNABLE_TPC;
6507 if (lpfc_sli4_set_beacon(vport, lcb_context, state)) {
6508 lpfc_printf_vlog(ndlp->vport, KERN_ERR, LOG_TRACE_EVENT,
6509 "0193 failed to send mail box");
6512 rjt_err = LSRJT_UNABLE_TPC;
6517 memset(&stat, 0, sizeof(stat));
6518 stat.un.b.lsRjtRsnCode = rjt_err;
6519 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
6525 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
6526 * @vport: pointer to a host virtual N_Port data structure.
6528 * This routine cleans up any Registration State Change Notification
6529 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
6530 * @vport together with the host_lock is used to prevent multiple thread
6531 * trying to access the RSCN array on a same @vport at the same time.
6534 lpfc_els_flush_rscn(struct lpfc_vport *vport)
6536 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6537 struct lpfc_hba *phba = vport->phba;
6540 spin_lock_irq(shost->host_lock);
6541 if (vport->fc_rscn_flush) {
6542 /* Another thread is walking fc_rscn_id_list on this vport */
6543 spin_unlock_irq(shost->host_lock);
6546 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
6547 vport->fc_rscn_flush = 1;
6548 spin_unlock_irq(shost->host_lock);
6550 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
6551 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
6552 vport->fc_rscn_id_list[i] = NULL;
6554 spin_lock_irq(shost->host_lock);
6555 vport->fc_rscn_id_cnt = 0;
6556 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
6557 spin_unlock_irq(shost->host_lock);
6558 lpfc_can_disctmo(vport);
6559 /* Indicate we are done walking this fc_rscn_id_list */
6560 vport->fc_rscn_flush = 0;
6564 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
6565 * @vport: pointer to a host virtual N_Port data structure.
6566 * @did: remote destination port identifier.
6568 * This routine checks whether there is any pending Registration State
6569 * Configuration Notification (RSCN) to a @did on @vport.
6572 * None zero - The @did matched with a pending rscn
6573 * 0 - not able to match @did with a pending rscn
6576 lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
6581 uint32_t payload_len, i;
6582 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6584 ns_did.un.word = did;
6586 /* Never match fabric nodes for RSCNs */
6587 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
6590 /* If we are doing a FULL RSCN rediscovery, match everything */
6591 if (vport->fc_flag & FC_RSCN_DISCOVERY)
6594 spin_lock_irq(shost->host_lock);
6595 if (vport->fc_rscn_flush) {
6596 /* Another thread is walking fc_rscn_id_list on this vport */
6597 spin_unlock_irq(shost->host_lock);
6600 /* Indicate we are walking fc_rscn_id_list on this vport */
6601 vport->fc_rscn_flush = 1;
6602 spin_unlock_irq(shost->host_lock);
6603 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
6604 lp = vport->fc_rscn_id_list[i]->virt;
6605 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
6606 payload_len -= sizeof(uint32_t); /* take off word 0 */
6607 while (payload_len) {
6608 rscn_did.un.word = be32_to_cpu(*lp++);
6609 payload_len -= sizeof(uint32_t);
6610 switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) {
6611 case RSCN_ADDRESS_FORMAT_PORT:
6612 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
6613 && (ns_did.un.b.area == rscn_did.un.b.area)
6614 && (ns_did.un.b.id == rscn_did.un.b.id))
6615 goto return_did_out;
6617 case RSCN_ADDRESS_FORMAT_AREA:
6618 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
6619 && (ns_did.un.b.area == rscn_did.un.b.area))
6620 goto return_did_out;
6622 case RSCN_ADDRESS_FORMAT_DOMAIN:
6623 if (ns_did.un.b.domain == rscn_did.un.b.domain)
6624 goto return_did_out;
6626 case RSCN_ADDRESS_FORMAT_FABRIC:
6627 goto return_did_out;
6631 /* Indicate we are done with walking fc_rscn_id_list on this vport */
6632 vport->fc_rscn_flush = 0;
6635 /* Indicate we are done with walking fc_rscn_id_list on this vport */
6636 vport->fc_rscn_flush = 0;
6641 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
6642 * @vport: pointer to a host virtual N_Port data structure.
6644 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
6645 * state machine for a @vport's nodes that are with pending RSCN (Registration
6646 * State Change Notification).
6649 * 0 - Successful (currently alway return 0)
6652 lpfc_rscn_recovery_check(struct lpfc_vport *vport)
6654 struct lpfc_nodelist *ndlp = NULL;
6656 /* Move all affected nodes by pending RSCNs to NPR state. */
6657 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
6658 if ((ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
6659 !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
6662 /* NVME Target mode does not do RSCN Recovery. */
6663 if (vport->phba->nvmet_support)
6666 /* If we are in the process of doing discovery on this
6667 * NPort, let it continue on its own.
6669 switch (ndlp->nlp_state) {
6670 case NLP_STE_PLOGI_ISSUE:
6671 case NLP_STE_ADISC_ISSUE:
6672 case NLP_STE_REG_LOGIN_ISSUE:
6673 case NLP_STE_PRLI_ISSUE:
6674 case NLP_STE_LOGO_ISSUE:
6678 /* Check to see if we need to NVME rescan this target
6681 if (ndlp->nlp_fc4_type & NLP_FC4_NVME &&
6682 ndlp->nlp_type & (NLP_NVME_TARGET | NLP_NVME_DISCOVERY))
6683 lpfc_nvme_rescan_port(vport, ndlp);
6685 lpfc_disc_state_machine(vport, ndlp, NULL,
6686 NLP_EVT_DEVICE_RECOVERY);
6687 lpfc_cancel_retry_delay_tmo(vport, ndlp);
6693 * lpfc_send_rscn_event - Send an RSCN event to management application
6694 * @vport: pointer to a host virtual N_Port data structure.
6695 * @cmdiocb: pointer to lpfc command iocb data structure.
6697 * lpfc_send_rscn_event sends an RSCN netlink event to management
6701 lpfc_send_rscn_event(struct lpfc_vport *vport,
6702 struct lpfc_iocbq *cmdiocb)
6704 struct lpfc_dmabuf *pcmd;
6705 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6706 uint32_t *payload_ptr;
6707 uint32_t payload_len;
6708 struct lpfc_rscn_event_header *rscn_event_data;
6710 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6711 payload_ptr = (uint32_t *) pcmd->virt;
6712 payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK);
6714 rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) +
6715 payload_len, GFP_KERNEL);
6716 if (!rscn_event_data) {
6717 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
6718 "0147 Failed to allocate memory for RSCN event\n");
6721 rscn_event_data->event_type = FC_REG_RSCN_EVENT;
6722 rscn_event_data->payload_length = payload_len;
6723 memcpy(rscn_event_data->rscn_payload, payload_ptr,
6726 fc_host_post_vendor_event(shost,
6727 fc_get_event_number(),
6728 sizeof(struct lpfc_rscn_event_header) + payload_len,
6729 (char *)rscn_event_data,
6732 kfree(rscn_event_data);
6736 * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
6737 * @vport: pointer to a host virtual N_Port data structure.
6738 * @cmdiocb: pointer to lpfc command iocb data structure.
6739 * @ndlp: pointer to a node-list data structure.
6741 * This routine processes an unsolicited RSCN (Registration State Change
6742 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
6743 * to invoke fc_host_post_event() routine to the FC transport layer. If the
6744 * discover state machine is about to begin discovery, it just accepts the
6745 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
6746 * contains N_Port IDs for other vports on this HBA, it just accepts the
6747 * RSCN and ignore processing it. If the state machine is in the recovery
6748 * state, the fc_rscn_id_list of this @vport is walked and the
6749 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
6750 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
6751 * routine is invoked to handle the RSCN event.
6754 * 0 - Just sent the acc response
6755 * 1 - Sent the acc response and waited for name server completion
6758 lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6759 struct lpfc_nodelist *ndlp)
6761 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6762 struct lpfc_hba *phba = vport->phba;
6763 struct lpfc_dmabuf *pcmd;
6764 uint32_t *lp, *datap;
6765 uint32_t payload_len, length, nportid, *cmd;
6767 int rscn_id = 0, hba_id = 0;
6770 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6771 lp = (uint32_t *) pcmd->virt;
6773 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
6774 payload_len -= sizeof(uint32_t); /* take off word 0 */
6776 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6777 "0214 RSCN received Data: x%x x%x x%x x%x\n",
6778 vport->fc_flag, payload_len, *lp,
6779 vport->fc_rscn_id_cnt);
6781 /* Send an RSCN event to the management application */
6782 lpfc_send_rscn_event(vport, cmdiocb);
6784 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
6785 fc_host_post_event(shost, fc_get_event_number(),
6786 FCH_EVT_RSCN, lp[i]);
6788 /* Check if RSCN is coming from a direct-connected remote NPort */
6789 if (vport->fc_flag & FC_PT2PT) {
6790 /* If so, just ACC it, no other action needed for now */
6791 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6792 "2024 pt2pt RSCN %08x Data: x%x x%x\n",
6793 *lp, vport->fc_flag, payload_len);
6794 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
6796 /* Check to see if we need to NVME rescan this target
6799 if (ndlp->nlp_fc4_type & NLP_FC4_NVME &&
6800 ndlp->nlp_type & (NLP_NVME_TARGET | NLP_NVME_DISCOVERY))
6801 lpfc_nvme_rescan_port(vport, ndlp);
6805 /* If we are about to begin discovery, just ACC the RSCN.
6806 * Discovery processing will satisfy it.
6808 if (vport->port_state <= LPFC_NS_QRY) {
6809 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6810 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
6811 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
6813 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
6817 /* If this RSCN just contains NPortIDs for other vports on this HBA,
6818 * just ACC and ignore it.
6820 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
6821 !(vport->cfg_peer_port_login)) {
6826 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
6827 i -= sizeof(uint32_t);
6829 if (lpfc_find_vport_by_did(phba, nportid))
6832 if (rscn_id == hba_id) {
6833 /* ALL NPortIDs in RSCN are on HBA */
6834 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6836 "Data: x%x x%x x%x x%x\n",
6837 vport->fc_flag, payload_len,
6838 *lp, vport->fc_rscn_id_cnt);
6839 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6840 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
6841 ndlp->nlp_DID, vport->port_state,
6844 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
6850 spin_lock_irq(shost->host_lock);
6851 if (vport->fc_rscn_flush) {
6852 /* Another thread is walking fc_rscn_id_list on this vport */
6853 vport->fc_flag |= FC_RSCN_DISCOVERY;
6854 spin_unlock_irq(shost->host_lock);
6856 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
6859 /* Indicate we are walking fc_rscn_id_list on this vport */
6860 vport->fc_rscn_flush = 1;
6861 spin_unlock_irq(shost->host_lock);
6862 /* Get the array count after successfully have the token */
6863 rscn_cnt = vport->fc_rscn_id_cnt;
6864 /* If we are already processing an RSCN, save the received
6865 * RSCN payload buffer, cmdiocb->context2 to process later.
6867 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
6868 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6869 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
6870 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
6872 spin_lock_irq(shost->host_lock);
6873 vport->fc_flag |= FC_RSCN_DEFERRED;
6875 /* Restart disctmo if its already running */
6876 if (vport->fc_flag & FC_DISC_TMO) {
6877 tmo = ((phba->fc_ratov * 3) + 3);
6878 mod_timer(&vport->fc_disctmo,
6879 jiffies + msecs_to_jiffies(1000 * tmo));
6881 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
6882 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
6883 vport->fc_flag |= FC_RSCN_MODE;
6884 spin_unlock_irq(shost->host_lock);
6886 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
6887 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
6890 (payload_len + length <= LPFC_BPL_SIZE)) {
6891 *cmd &= ELS_CMD_MASK;
6892 *cmd |= cpu_to_be32(payload_len + length);
6893 memcpy(((uint8_t *)cmd) + length, lp,
6896 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
6897 vport->fc_rscn_id_cnt++;
6898 /* If we zero, cmdiocb->context2, the calling
6899 * routine will not try to free it.
6901 cmdiocb->context2 = NULL;
6904 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6905 "0235 Deferred RSCN "
6906 "Data: x%x x%x x%x\n",
6907 vport->fc_rscn_id_cnt, vport->fc_flag,
6910 vport->fc_flag |= FC_RSCN_DISCOVERY;
6911 spin_unlock_irq(shost->host_lock);
6912 /* ReDiscovery RSCN */
6913 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6914 "0234 ReDiscovery RSCN "
6915 "Data: x%x x%x x%x\n",
6916 vport->fc_rscn_id_cnt, vport->fc_flag,
6919 /* Indicate we are done walking fc_rscn_id_list on this vport */
6920 vport->fc_rscn_flush = 0;
6922 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
6923 /* send RECOVERY event for ALL nodes that match RSCN payload */
6924 lpfc_rscn_recovery_check(vport);
6927 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6928 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
6929 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
6931 spin_lock_irq(shost->host_lock);
6932 vport->fc_flag |= FC_RSCN_MODE;
6933 spin_unlock_irq(shost->host_lock);
6934 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
6935 /* Indicate we are done walking fc_rscn_id_list on this vport */
6936 vport->fc_rscn_flush = 0;
6938 * If we zero, cmdiocb->context2, the calling routine will
6939 * not try to free it.
6941 cmdiocb->context2 = NULL;
6942 lpfc_set_disctmo(vport);
6944 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
6945 /* send RECOVERY event for ALL nodes that match RSCN payload */
6946 lpfc_rscn_recovery_check(vport);
6947 return lpfc_els_handle_rscn(vport);
6951 * lpfc_els_handle_rscn - Handle rscn for a vport
6952 * @vport: pointer to a host virtual N_Port data structure.
6954 * This routine handles the Registration State Configuration Notification
6955 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
6956 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
6957 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
6958 * NameServer shall be issued. If CT command to the NameServer fails to be
6959 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
6960 * RSCN activities with the @vport.
6963 * 0 - Cleaned up rscn on the @vport
6964 * 1 - Wait for plogi to name server before proceed
6967 lpfc_els_handle_rscn(struct lpfc_vport *vport)
6969 struct lpfc_nodelist *ndlp;
6970 struct lpfc_hba *phba = vport->phba;
6972 /* Ignore RSCN if the port is being torn down. */
6973 if (vport->load_flag & FC_UNLOADING) {
6974 lpfc_els_flush_rscn(vport);
6978 /* Start timer for RSCN processing */
6979 lpfc_set_disctmo(vport);
6981 /* RSCN processed */
6982 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6983 "0215 RSCN processed Data: x%x x%x x%x x%x x%x x%x\n",
6984 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
6985 vport->port_state, vport->num_disc_nodes,
6988 /* To process RSCN, first compare RSCN data with NameServer */
6989 vport->fc_ns_retry = 0;
6990 vport->num_disc_nodes = 0;
6992 ndlp = lpfc_findnode_did(vport, NameServer_DID);
6993 if (ndlp && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
6994 /* Good ndlp, issue CT Request to NameServer. Need to
6995 * know how many gidfts were issued. If none, then just
6996 * flush the RSCN. Otherwise, the outstanding requests
6999 if (phba->cfg_ns_query == LPFC_NS_QUERY_GID_FT) {
7000 if (lpfc_issue_gidft(vport) > 0)
7002 } else if (phba->cfg_ns_query == LPFC_NS_QUERY_GID_PT) {
7003 if (lpfc_issue_gidpt(vport) > 0)
7009 /* Nameserver login in question. Revalidate. */
7011 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
7012 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
7014 ndlp = lpfc_nlp_init(vport, NameServer_DID);
7016 lpfc_els_flush_rscn(vport);
7019 ndlp->nlp_prev_state = ndlp->nlp_state;
7020 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
7022 ndlp->nlp_type |= NLP_FABRIC;
7023 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
7024 /* Wait for NameServer login cmpl before we can
7030 lpfc_els_flush_rscn(vport);
7035 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
7036 * @vport: pointer to a host virtual N_Port data structure.
7037 * @cmdiocb: pointer to lpfc command iocb data structure.
7038 * @ndlp: pointer to a node-list data structure.
7040 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
7041 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
7042 * point topology. As an unsolicited FLOGI should not be received in a loop
7043 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
7044 * lpfc_check_sparm() routine is invoked to check the parameters in the
7045 * unsolicited FLOGI. If parameters validation failed, the routine
7046 * lpfc_els_rsp_reject() shall be called with reject reason code set to
7047 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
7048 * FLOGI shall be compared with the Port WWN of the @vport to determine who
7049 * will initiate PLOGI. The higher lexicographical value party shall has
7050 * higher priority (as the winning port) and will initiate PLOGI and
7051 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
7052 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
7053 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
7056 * 0 - Successfully processed the unsolicited flogi
7057 * 1 - Failed to process the unsolicited flogi
7060 lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7061 struct lpfc_nodelist *ndlp)
7063 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7064 struct lpfc_hba *phba = vport->phba;
7065 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7066 uint32_t *lp = (uint32_t *) pcmd->virt;
7067 IOCB_t *icmd = &cmdiocb->iocb;
7068 struct serv_parm *sp;
7072 uint32_t fc_flag = 0;
7073 uint32_t port_state = 0;
7076 sp = (struct serv_parm *) lp;
7078 /* FLOGI received */
7080 lpfc_set_disctmo(vport);
7082 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
7083 /* We should never receive a FLOGI in loop mode, ignore it */
7084 did = icmd->un.elsreq64.remoteID;
7086 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
7088 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
7089 "0113 An FLOGI ELS command x%x was "
7090 "received from DID x%x in Loop Mode\n",
7095 (void) lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1);
7098 * If our portname is greater than the remote portname,
7099 * then we initiate Nport login.
7102 rc = memcmp(&vport->fc_portname, &sp->portName,
7103 sizeof(struct lpfc_name));
7106 if (phba->sli_rev < LPFC_SLI_REV4) {
7107 mbox = mempool_alloc(phba->mbox_mem_pool,
7111 lpfc_linkdown(phba);
7112 lpfc_init_link(phba, mbox,
7114 phba->cfg_link_speed);
7115 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
7116 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
7117 mbox->vport = vport;
7118 rc = lpfc_sli_issue_mbox(phba, mbox,
7120 lpfc_set_loopback_flag(phba);
7121 if (rc == MBX_NOT_FINISHED)
7122 mempool_free(mbox, phba->mbox_mem_pool);
7126 /* abort the flogi coming back to ourselves
7127 * due to external loopback on the port.
7129 lpfc_els_abort_flogi(phba);
7132 } else if (rc > 0) { /* greater than */
7133 spin_lock_irq(shost->host_lock);
7134 vport->fc_flag |= FC_PT2PT_PLOGI;
7135 spin_unlock_irq(shost->host_lock);
7137 /* If we have the high WWPN we can assign our own
7138 * myDID; otherwise, we have to WAIT for a PLOGI
7139 * from the remote NPort to find out what it
7142 vport->fc_myDID = PT2PT_LocalID;
7144 vport->fc_myDID = PT2PT_RemoteID;
7148 * The vport state should go to LPFC_FLOGI only
7149 * AFTER we issue a FLOGI, not receive one.
7151 spin_lock_irq(shost->host_lock);
7152 fc_flag = vport->fc_flag;
7153 port_state = vport->port_state;
7154 vport->fc_flag |= FC_PT2PT;
7155 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
7157 /* Acking an unsol FLOGI. Count 1 for link bounce
7160 vport->rcv_flogi_cnt++;
7161 spin_unlock_irq(shost->host_lock);
7162 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7163 "3311 Rcv Flogi PS x%x new PS x%x "
7164 "fc_flag x%x new fc_flag x%x\n",
7165 port_state, vport->port_state,
7166 fc_flag, vport->fc_flag);
7169 * We temporarily set fc_myDID to make it look like we are
7170 * a Fabric. This is done just so we end up with the right
7171 * did / sid on the FLOGI ACC rsp.
7173 did = vport->fc_myDID;
7174 vport->fc_myDID = Fabric_DID;
7176 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
7178 /* Defer ACC response until AFTER we issue a FLOGI */
7179 if (!(phba->hba_flag & HBA_FLOGI_ISSUED)) {
7180 phba->defer_flogi_acc_rx_id = cmdiocb->iocb.ulpContext;
7181 phba->defer_flogi_acc_ox_id =
7182 cmdiocb->iocb.unsli3.rcvsli3.ox_id;
7184 vport->fc_myDID = did;
7186 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7187 "3344 Deferring FLOGI ACC: rx_id: x%x,"
7188 " ox_id: x%x, hba_flag x%x\n",
7189 phba->defer_flogi_acc_rx_id,
7190 phba->defer_flogi_acc_ox_id, phba->hba_flag);
7192 phba->defer_flogi_acc_flag = true;
7198 lpfc_els_rsp_acc(vport, ELS_CMD_FLOGI, cmdiocb, ndlp, NULL);
7200 /* Now lets put fc_myDID back to what its supposed to be */
7201 vport->fc_myDID = did;
7207 * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
7208 * @vport: pointer to a host virtual N_Port data structure.
7209 * @cmdiocb: pointer to lpfc command iocb data structure.
7210 * @ndlp: pointer to a node-list data structure.
7212 * This routine processes Request Node Identification Data (RNID) IOCB
7213 * received as an ELS unsolicited event. Only when the RNID specified format
7214 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
7215 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
7216 * Accept (ACC) the RNID ELS command. All the other RNID formats are
7217 * rejected by invoking the lpfc_els_rsp_reject() routine.
7220 * 0 - Successfully processed rnid iocb (currently always return 0)
7223 lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7224 struct lpfc_nodelist *ndlp)
7226 struct lpfc_dmabuf *pcmd;
7231 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7232 lp = (uint32_t *) pcmd->virt;
7239 switch (rn->Format) {
7241 case RNID_TOPOLOGY_DISC:
7243 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
7246 /* Reject this request because format not supported */
7247 stat.un.b.lsRjtRsvd0 = 0;
7248 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
7249 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
7250 stat.un.b.vendorUnique = 0;
7251 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
7258 * lpfc_els_rcv_echo - Process an unsolicited echo iocb
7259 * @vport: pointer to a host virtual N_Port data structure.
7260 * @cmdiocb: pointer to lpfc command iocb data structure.
7261 * @ndlp: pointer to a node-list data structure.
7264 * 0 - Successfully processed echo iocb (currently always return 0)
7267 lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7268 struct lpfc_nodelist *ndlp)
7272 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
7274 /* skip over first word of echo command to find echo data */
7275 pcmd += sizeof(uint32_t);
7277 lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp);
7282 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
7283 * @vport: pointer to a host virtual N_Port data structure.
7284 * @cmdiocb: pointer to lpfc command iocb data structure.
7285 * @ndlp: pointer to a node-list data structure.
7287 * This routine processes a Link Incident Report Registration(LIRR) IOCB
7288 * received as an ELS unsolicited event. Currently, this function just invokes
7289 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
7292 * 0 - Successfully processed lirr iocb (currently always return 0)
7295 lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7296 struct lpfc_nodelist *ndlp)
7300 /* For now, unconditionally reject this command */
7301 stat.un.b.lsRjtRsvd0 = 0;
7302 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
7303 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
7304 stat.un.b.vendorUnique = 0;
7305 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
7310 * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb
7311 * @vport: pointer to a host virtual N_Port data structure.
7312 * @cmdiocb: pointer to lpfc command iocb data structure.
7313 * @ndlp: pointer to a node-list data structure.
7315 * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB
7316 * received as an ELS unsolicited event. A request to RRQ shall only
7317 * be accepted if the Originator Nx_Port N_Port_ID or the Responder
7318 * Nx_Port N_Port_ID of the target Exchange is the same as the
7319 * N_Port_ID of the Nx_Port that makes the request. If the RRQ is
7320 * not accepted, an LS_RJT with reason code "Unable to perform
7321 * command request" and reason code explanation "Invalid Originator
7322 * S_ID" shall be returned. For now, we just unconditionally accept
7323 * RRQ from the target.
7326 lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7327 struct lpfc_nodelist *ndlp)
7329 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
7330 if (vport->phba->sli_rev == LPFC_SLI_REV4)
7331 lpfc_els_clear_rrq(vport, cmdiocb, ndlp);
7335 * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
7336 * @phba: pointer to lpfc hba data structure.
7337 * @pmb: pointer to the driver internal queue element for mailbox command.
7339 * This routine is the completion callback function for the MBX_READ_LNK_STAT
7340 * mailbox command. This callback function is to actually send the Accept
7341 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
7342 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
7343 * mailbox command, constructs the RPS response with the link statistics
7344 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
7345 * response to the RPS.
7347 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7348 * will be incremented by 1 for holding the ndlp and the reference to ndlp
7349 * will be stored into the context1 field of the IOCB for the completion
7350 * callback function to the RPS Accept Response ELS IOCB command.
7354 lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
7359 struct RLS_RSP *rls_rsp;
7361 struct lpfc_iocbq *elsiocb;
7362 struct lpfc_nodelist *ndlp;
7369 ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
7370 rxid = (uint16_t)((unsigned long)(pmb->ctx_buf) & 0xffff);
7371 oxid = (uint16_t)(((unsigned long)(pmb->ctx_buf) >> 16) & 0xffff);
7372 pmb->ctx_buf = NULL;
7373 pmb->ctx_ndlp = NULL;
7375 if (mb->mbxStatus) {
7376 mempool_free(pmb, phba->mbox_mem_pool);
7380 cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t);
7381 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
7382 lpfc_max_els_tries, ndlp,
7383 ndlp->nlp_DID, ELS_CMD_ACC);
7385 /* Decrement the ndlp reference count from previous mbox command */
7389 mempool_free(pmb, phba->mbox_mem_pool);
7393 icmd = &elsiocb->iocb;
7394 icmd->ulpContext = rxid;
7395 icmd->unsli3.rcvsli3.ox_id = oxid;
7397 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7398 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
7399 pcmd += sizeof(uint32_t); /* Skip past command */
7400 rls_rsp = (struct RLS_RSP *)pcmd;
7402 rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
7403 rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
7404 rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
7405 rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
7406 rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
7407 rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
7408 mempool_free(pmb, phba->mbox_mem_pool);
7409 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
7410 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
7411 "2874 Xmit ELS RLS ACC response tag x%x xri x%x, "
7412 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
7413 elsiocb->iotag, elsiocb->iocb.ulpContext,
7414 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
7416 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
7417 phba->fc_stat.elsXmitACC++;
7418 elsiocb->context1 = lpfc_nlp_get(ndlp);
7419 if (!elsiocb->context1)
7422 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
7423 if (rc == IOCB_ERROR)
7430 lpfc_els_free_iocb(phba, elsiocb);
7434 * lpfc_els_rcv_rls - Process an unsolicited rls iocb
7435 * @vport: pointer to a host virtual N_Port data structure.
7436 * @cmdiocb: pointer to lpfc command iocb data structure.
7437 * @ndlp: pointer to a node-list data structure.
7439 * This routine processes Read Link Status (RLS) IOCB received as an
7440 * ELS unsolicited event. It first checks the remote port state. If the
7441 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
7442 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
7443 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
7444 * for reading the HBA link statistics. It is for the callback function,
7445 * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command
7446 * to actually sending out RPL Accept (ACC) response.
7449 * 0 - Successfully processed rls iocb (currently always return 0)
7452 lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7453 struct lpfc_nodelist *ndlp)
7455 struct lpfc_hba *phba = vport->phba;
7459 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
7460 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
7461 /* reject the unsolicited RLS request and done with it */
7464 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
7466 lpfc_read_lnk_stat(phba, mbox);
7467 mbox->ctx_buf = (void *)((unsigned long)
7468 ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) |
7469 cmdiocb->iocb.ulpContext)); /* rx_id */
7470 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
7471 if (!mbox->ctx_ndlp)
7473 mbox->vport = vport;
7474 mbox->mbox_cmpl = lpfc_els_rsp_rls_acc;
7475 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
7476 != MBX_NOT_FINISHED)
7477 /* Mbox completion will send ELS Response */
7479 /* Decrement reference count used for the failed mbox
7484 mempool_free(mbox, phba->mbox_mem_pool);
7487 /* issue rejection response */
7488 stat.un.b.lsRjtRsvd0 = 0;
7489 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
7490 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
7491 stat.un.b.vendorUnique = 0;
7492 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
7497 * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb
7498 * @vport: pointer to a host virtual N_Port data structure.
7499 * @cmdiocb: pointer to lpfc command iocb data structure.
7500 * @ndlp: pointer to a node-list data structure.
7502 * This routine processes Read Timout Value (RTV) IOCB received as an
7503 * ELS unsolicited event. It first checks the remote port state. If the
7504 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
7505 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
7506 * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout
7507 * Value (RTV) unsolicited IOCB event.
7509 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7510 * will be incremented by 1 for holding the ndlp and the reference to ndlp
7511 * will be stored into the context1 field of the IOCB for the completion
7512 * callback function to the RTV Accept Response ELS IOCB command.
7515 * 0 - Successfully processed rtv iocb (currently always return 0)
7518 lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7519 struct lpfc_nodelist *ndlp)
7522 struct lpfc_hba *phba = vport->phba;
7524 struct RTV_RSP *rtv_rsp;
7526 struct lpfc_iocbq *elsiocb;
7530 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
7531 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
7532 /* reject the unsolicited RTV request and done with it */
7535 cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t);
7536 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
7537 lpfc_max_els_tries, ndlp,
7538 ndlp->nlp_DID, ELS_CMD_ACC);
7543 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7544 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
7545 pcmd += sizeof(uint32_t); /* Skip past command */
7547 /* use the command's xri in the response */
7548 elsiocb->iocb.ulpContext = cmdiocb->iocb.ulpContext; /* Xri / rx_id */
7549 elsiocb->iocb.unsli3.rcvsli3.ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id;
7551 rtv_rsp = (struct RTV_RSP *)pcmd;
7553 /* populate RTV payload */
7554 rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000); /* report msecs */
7555 rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov);
7556 bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0);
7557 bf_set(qtov_rttov, rtv_rsp, 0); /* Field is for FC ONLY */
7558 rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov);
7560 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
7561 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
7562 "2875 Xmit ELS RTV ACC response tag x%x xri x%x, "
7563 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, "
7564 "Data: x%x x%x x%x\n",
7565 elsiocb->iotag, elsiocb->iocb.ulpContext,
7566 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
7568 rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov);
7569 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
7570 phba->fc_stat.elsXmitACC++;
7571 elsiocb->context1 = lpfc_nlp_get(ndlp);
7572 if (!elsiocb->context1) {
7573 lpfc_els_free_iocb(phba, elsiocb);
7577 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
7578 if (rc == IOCB_ERROR) {
7580 lpfc_els_free_iocb(phba, elsiocb);
7585 /* issue rejection response */
7586 stat.un.b.lsRjtRsvd0 = 0;
7587 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
7588 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
7589 stat.un.b.vendorUnique = 0;
7590 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
7594 /* lpfc_issue_els_rrq - Process an unsolicited rrq iocb
7595 * @vport: pointer to a host virtual N_Port data structure.
7596 * @ndlp: pointer to a node-list data structure.
7597 * @did: DID of the target.
7598 * @rrq: Pointer to the rrq struct.
7600 * Build a ELS RRQ command and send it to the target. If the issue_iocb is
7601 * Successful the the completion handler will clear the RRQ.
7604 * 0 - Successfully sent rrq els iocb.
7605 * 1 - Failed to send rrq els iocb.
7608 lpfc_issue_els_rrq(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
7609 uint32_t did, struct lpfc_node_rrq *rrq)
7611 struct lpfc_hba *phba = vport->phba;
7612 struct RRQ *els_rrq;
7613 struct lpfc_iocbq *elsiocb;
7619 if (ndlp != rrq->ndlp)
7624 /* If ndlp is not NULL, we will bump the reference count on it */
7625 cmdsize = (sizeof(uint32_t) + sizeof(struct RRQ));
7626 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, did,
7631 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7633 /* For RRQ request, remainder of payload is Exchange IDs */
7634 *((uint32_t *) (pcmd)) = ELS_CMD_RRQ;
7635 pcmd += sizeof(uint32_t);
7636 els_rrq = (struct RRQ *) pcmd;
7638 bf_set(rrq_oxid, els_rrq, phba->sli4_hba.xri_ids[rrq->xritag]);
7639 bf_set(rrq_rxid, els_rrq, rrq->rxid);
7640 bf_set(rrq_did, els_rrq, vport->fc_myDID);
7641 els_rrq->rrq = cpu_to_be32(els_rrq->rrq);
7642 els_rrq->rrq_exchg = cpu_to_be32(els_rrq->rrq_exchg);
7645 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7646 "Issue RRQ: did:x%x",
7647 did, rrq->xritag, rrq->rxid);
7648 elsiocb->context_un.rrq = rrq;
7649 elsiocb->iocb_cmpl = lpfc_cmpl_els_rrq;
7650 elsiocb->context1 = lpfc_nlp_get(ndlp);
7651 if (!elsiocb->context1)
7654 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
7655 if (ret == IOCB_ERROR)
7662 lpfc_els_free_iocb(phba, elsiocb);
7667 * lpfc_send_rrq - Sends ELS RRQ if needed.
7668 * @phba: pointer to lpfc hba data structure.
7669 * @rrq: pointer to the active rrq.
7671 * This routine will call the lpfc_issue_els_rrq if the rrq is
7672 * still active for the xri. If this function returns a failure then
7673 * the caller needs to clean up the RRQ by calling lpfc_clr_active_rrq.
7675 * Returns 0 Success.
7679 lpfc_send_rrq(struct lpfc_hba *phba, struct lpfc_node_rrq *rrq)
7681 struct lpfc_nodelist *ndlp = lpfc_findnode_did(rrq->vport,
7686 if (lpfc_test_rrq_active(phba, ndlp, rrq->xritag))
7687 return lpfc_issue_els_rrq(rrq->vport, ndlp,
7694 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
7695 * @vport: pointer to a host virtual N_Port data structure.
7696 * @cmdsize: size of the ELS command.
7697 * @oldiocb: pointer to the original lpfc command iocb data structure.
7698 * @ndlp: pointer to a node-list data structure.
7700 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
7701 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
7703 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7704 * will be incremented by 1 for holding the ndlp and the reference to ndlp
7705 * will be stored into the context1 field of the IOCB for the completion
7706 * callback function to the RPL Accept Response ELS command.
7709 * 0 - Successfully issued ACC RPL ELS command
7710 * 1 - Failed to issue ACC RPL ELS command
7713 lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
7714 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
7717 struct lpfc_hba *phba = vport->phba;
7718 IOCB_t *icmd, *oldcmd;
7720 struct lpfc_iocbq *elsiocb;
7723 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
7724 ndlp->nlp_DID, ELS_CMD_ACC);
7729 icmd = &elsiocb->iocb;
7730 oldcmd = &oldiocb->iocb;
7731 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
7732 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
7734 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7735 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
7736 pcmd += sizeof(uint16_t);
7737 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
7738 pcmd += sizeof(uint16_t);
7740 /* Setup the RPL ACC payload */
7741 rpl_rsp.listLen = be32_to_cpu(1);
7743 rpl_rsp.port_num_blk.portNum = 0;
7744 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
7745 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
7746 sizeof(struct lpfc_name));
7747 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
7748 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
7749 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7750 "0120 Xmit ELS RPL ACC response tag x%x "
7751 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
7753 elsiocb->iotag, elsiocb->iocb.ulpContext,
7754 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
7756 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
7757 phba->fc_stat.elsXmitACC++;
7758 elsiocb->context1 = lpfc_nlp_get(ndlp);
7759 if (!elsiocb->context1)
7762 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
7763 if (rc == IOCB_ERROR)
7770 lpfc_els_free_iocb(phba, elsiocb);
7775 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
7776 * @vport: pointer to a host virtual N_Port data structure.
7777 * @cmdiocb: pointer to lpfc command iocb data structure.
7778 * @ndlp: pointer to a node-list data structure.
7780 * This routine processes Read Port List (RPL) IOCB received as an ELS
7781 * unsolicited event. It first checks the remote port state. If the remote
7782 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
7783 * invokes the lpfc_els_rsp_reject() routine to send reject response.
7784 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
7785 * to accept the RPL.
7788 * 0 - Successfully processed rpl iocb (currently always return 0)
7791 lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7792 struct lpfc_nodelist *ndlp)
7794 struct lpfc_dmabuf *pcmd;
7801 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
7802 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
7803 /* issue rejection response */
7804 stat.un.b.lsRjtRsvd0 = 0;
7805 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
7806 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
7807 stat.un.b.vendorUnique = 0;
7808 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
7810 /* rejected the unsolicited RPL request and done with it */
7814 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7815 lp = (uint32_t *) pcmd->virt;
7816 rpl = (RPL *) (lp + 1);
7817 maxsize = be32_to_cpu(rpl->maxsize);
7819 /* We support only one port */
7820 if ((rpl->index == 0) &&
7822 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
7823 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
7825 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
7827 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
7833 * lpfc_els_rcv_farp - Process an unsolicited farp request els command
7834 * @vport: pointer to a virtual N_Port data structure.
7835 * @cmdiocb: pointer to lpfc command iocb data structure.
7836 * @ndlp: pointer to a node-list data structure.
7838 * This routine processes Fibre Channel Address Resolution Protocol
7839 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
7840 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
7841 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
7842 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
7843 * remote PortName is compared against the FC PortName stored in the @vport
7844 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
7845 * compared against the FC NodeName stored in the @vport data structure.
7846 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
7847 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
7848 * invoked to send out FARP Response to the remote node. Before sending the
7849 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
7850 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
7851 * routine is invoked to log into the remote port first.
7854 * 0 - Either the FARP Match Mode not supported or successfully processed
7857 lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7858 struct lpfc_nodelist *ndlp)
7860 struct lpfc_dmabuf *pcmd;
7866 icmd = &cmdiocb->iocb;
7867 did = icmd->un.elsreq64.remoteID;
7868 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7869 lp = (uint32_t *) pcmd->virt;
7873 /* FARP-REQ received from DID <did> */
7874 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7875 "0601 FARP-REQ received from DID x%x\n", did);
7876 /* We will only support match on WWPN or WWNN */
7877 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
7882 /* If this FARP command is searching for my portname */
7883 if (fp->Mflags & FARP_MATCH_PORT) {
7884 if (memcmp(&fp->RportName, &vport->fc_portname,
7885 sizeof(struct lpfc_name)) == 0)
7889 /* If this FARP command is searching for my nodename */
7890 if (fp->Mflags & FARP_MATCH_NODE) {
7891 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
7892 sizeof(struct lpfc_name)) == 0)
7897 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
7898 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
7899 /* Log back into the node before sending the FARP. */
7900 if (fp->Rflags & FARP_REQUEST_PLOGI) {
7901 ndlp->nlp_prev_state = ndlp->nlp_state;
7902 lpfc_nlp_set_state(vport, ndlp,
7903 NLP_STE_PLOGI_ISSUE);
7904 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
7907 /* Send a FARP response to that node */
7908 if (fp->Rflags & FARP_REQUEST_FARPR)
7909 lpfc_issue_els_farpr(vport, did, 0);
7916 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
7917 * @vport: pointer to a host virtual N_Port data structure.
7918 * @cmdiocb: pointer to lpfc command iocb data structure.
7919 * @ndlp: pointer to a node-list data structure.
7921 * This routine processes Fibre Channel Address Resolution Protocol
7922 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
7923 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
7924 * the FARP response request.
7927 * 0 - Successfully processed FARPR IOCB (currently always return 0)
7930 lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7931 struct lpfc_nodelist *ndlp)
7933 struct lpfc_dmabuf *pcmd;
7938 icmd = &cmdiocb->iocb;
7939 did = icmd->un.elsreq64.remoteID;
7940 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7941 lp = (uint32_t *) pcmd->virt;
7944 /* FARP-RSP received from DID <did> */
7945 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7946 "0600 FARP-RSP received from DID x%x\n", did);
7947 /* ACCEPT the Farp resp request */
7948 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
7954 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
7955 * @vport: pointer to a host virtual N_Port data structure.
7956 * @cmdiocb: pointer to lpfc command iocb data structure.
7957 * @fan_ndlp: pointer to a node-list data structure.
7959 * This routine processes a Fabric Address Notification (FAN) IOCB
7960 * command received as an ELS unsolicited event. The FAN ELS command will
7961 * only be processed on a physical port (i.e., the @vport represents the
7962 * physical port). The fabric NodeName and PortName from the FAN IOCB are
7963 * compared against those in the phba data structure. If any of those is
7964 * different, the lpfc_initial_flogi() routine is invoked to initialize
7965 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
7966 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
7967 * is invoked to register login to the fabric.
7970 * 0 - Successfully processed fan iocb (currently always return 0).
7973 lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7974 struct lpfc_nodelist *fan_ndlp)
7976 struct lpfc_hba *phba = vport->phba;
7980 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
7981 lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
7983 /* FAN received; Fan does not have a reply sequence */
7984 if ((vport == phba->pport) &&
7985 (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
7986 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
7987 sizeof(struct lpfc_name))) ||
7988 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
7989 sizeof(struct lpfc_name)))) {
7990 /* This port has switched fabrics. FLOGI is required */
7991 lpfc_issue_init_vfi(vport);
7993 /* FAN verified - skip FLOGI */
7994 vport->fc_myDID = vport->fc_prevDID;
7995 if (phba->sli_rev < LPFC_SLI_REV4)
7996 lpfc_issue_fabric_reglogin(vport);
7998 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7999 "3138 Need register VFI: (x%x/%x)\n",
8000 vport->fc_prevDID, vport->fc_myDID);
8001 lpfc_issue_reg_vfi(vport);
8009 * lpfc_els_timeout - Handler funciton to the els timer
8010 * @t: timer context used to obtain the vport.
8012 * This routine is invoked by the ELS timer after timeout. It posts the ELS
8013 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
8014 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
8015 * up the worker thread. It is for the worker thread to invoke the routine
8016 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
8019 lpfc_els_timeout(struct timer_list *t)
8021 struct lpfc_vport *vport = from_timer(vport, t, els_tmofunc);
8022 struct lpfc_hba *phba = vport->phba;
8023 uint32_t tmo_posted;
8024 unsigned long iflag;
8026 spin_lock_irqsave(&vport->work_port_lock, iflag);
8027 tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
8028 if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING)))
8029 vport->work_port_events |= WORKER_ELS_TMO;
8030 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
8032 if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING)))
8033 lpfc_worker_wake_up(phba);
8039 * lpfc_els_timeout_handler - Process an els timeout event
8040 * @vport: pointer to a virtual N_Port data structure.
8042 * This routine is the actual handler function that processes an ELS timeout
8043 * event. It walks the ELS ring to get and abort all the IOCBs (except the
8044 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
8045 * invoking the lpfc_sli_issue_abort_iotag() routine.
8048 lpfc_els_timeout_handler(struct lpfc_vport *vport)
8050 struct lpfc_hba *phba = vport->phba;
8051 struct lpfc_sli_ring *pring;
8052 struct lpfc_iocbq *tmp_iocb, *piocb;
8054 struct lpfc_dmabuf *pcmd;
8055 uint32_t els_command = 0;
8057 uint32_t remote_ID = 0xffffffff;
8058 LIST_HEAD(abort_list);
8061 timeout = (uint32_t)(phba->fc_ratov << 1);
8063 pring = lpfc_phba_elsring(phba);
8064 if (unlikely(!pring))
8067 if (phba->pport->load_flag & FC_UNLOADING)
8070 spin_lock_irq(&phba->hbalock);
8071 if (phba->sli_rev == LPFC_SLI_REV4)
8072 spin_lock(&pring->ring_lock);
8074 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
8077 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
8078 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
8079 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
8082 if (piocb->vport != vport)
8085 pcmd = (struct lpfc_dmabuf *) piocb->context2;
8087 els_command = *(uint32_t *) (pcmd->virt);
8089 if (els_command == ELS_CMD_FARP ||
8090 els_command == ELS_CMD_FARPR ||
8091 els_command == ELS_CMD_FDISC)
8094 if (piocb->drvrTimeout > 0) {
8095 if (piocb->drvrTimeout >= timeout)
8096 piocb->drvrTimeout -= timeout;
8098 piocb->drvrTimeout = 0;
8102 remote_ID = 0xffffffff;
8103 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
8104 remote_ID = cmd->un.elsreq64.remoteID;
8106 struct lpfc_nodelist *ndlp;
8107 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
8109 remote_ID = ndlp->nlp_DID;
8111 list_add_tail(&piocb->dlist, &abort_list);
8113 if (phba->sli_rev == LPFC_SLI_REV4)
8114 spin_unlock(&pring->ring_lock);
8115 spin_unlock_irq(&phba->hbalock);
8117 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
8119 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
8120 "0127 ELS timeout Data: x%x x%x x%x "
8121 "x%x\n", els_command,
8122 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
8123 spin_lock_irq(&phba->hbalock);
8124 list_del_init(&piocb->dlist);
8125 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
8126 spin_unlock_irq(&phba->hbalock);
8129 if (!list_empty(&pring->txcmplq))
8130 if (!(phba->pport->load_flag & FC_UNLOADING))
8131 mod_timer(&vport->els_tmofunc,
8132 jiffies + msecs_to_jiffies(1000 * timeout));
8136 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
8137 * @vport: pointer to a host virtual N_Port data structure.
8139 * This routine is used to clean up all the outstanding ELS commands on a
8140 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
8141 * routine. After that, it walks the ELS transmit queue to remove all the
8142 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
8143 * the IOCBs with a non-NULL completion callback function, the callback
8144 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
8145 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
8146 * callback function, the IOCB will simply be released. Finally, it walks
8147 * the ELS transmit completion queue to issue an abort IOCB to any transmit
8148 * completion queue IOCB that is associated with the @vport and is not
8149 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
8150 * part of the discovery state machine) out to HBA by invoking the
8151 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
8152 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
8153 * the IOCBs are aborted when this function returns.
8156 lpfc_els_flush_cmd(struct lpfc_vport *vport)
8158 LIST_HEAD(abort_list);
8159 struct lpfc_hba *phba = vport->phba;
8160 struct lpfc_sli_ring *pring;
8161 struct lpfc_iocbq *tmp_iocb, *piocb;
8163 unsigned long iflags = 0;
8165 lpfc_fabric_abort_vport(vport);
8168 * For SLI3, only the hbalock is required. But SLI4 needs to coordinate
8169 * with the ring insert operation. Because lpfc_sli_issue_abort_iotag
8170 * ultimately grabs the ring_lock, the driver must splice the list into
8171 * a working list and release the locks before calling the abort.
8173 spin_lock_irqsave(&phba->hbalock, iflags);
8174 pring = lpfc_phba_elsring(phba);
8176 /* Bail out if we've no ELS wq, like in PCI error recovery case. */
8177 if (unlikely(!pring)) {
8178 spin_unlock_irqrestore(&phba->hbalock, iflags);
8182 if (phba->sli_rev == LPFC_SLI_REV4)
8183 spin_lock(&pring->ring_lock);
8185 /* First we need to issue aborts to outstanding cmds on txcmpl */
8186 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
8187 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
8190 if (piocb->vport != vport)
8193 if (piocb->iocb_flag & LPFC_DRIVER_ABORTED)
8196 /* On the ELS ring we can have ELS_REQUESTs or
8197 * GEN_REQUESTs waiting for a response.
8200 if (cmd->ulpCommand == CMD_ELS_REQUEST64_CR) {
8201 list_add_tail(&piocb->dlist, &abort_list);
8203 /* If the link is down when flushing ELS commands
8204 * the firmware will not complete them till after
8205 * the link comes back up. This may confuse
8206 * discovery for the new link up, so we need to
8207 * change the compl routine to just clean up the iocb
8208 * and avoid any retry logic.
8210 if (phba->link_state == LPFC_LINK_DOWN)
8211 piocb->iocb_cmpl = lpfc_cmpl_els_link_down;
8213 if (cmd->ulpCommand == CMD_GEN_REQUEST64_CR)
8214 list_add_tail(&piocb->dlist, &abort_list);
8217 if (phba->sli_rev == LPFC_SLI_REV4)
8218 spin_unlock(&pring->ring_lock);
8219 spin_unlock_irqrestore(&phba->hbalock, iflags);
8221 /* Abort each txcmpl iocb on aborted list and remove the dlist links. */
8222 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
8223 spin_lock_irqsave(&phba->hbalock, iflags);
8224 list_del_init(&piocb->dlist);
8225 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
8226 spin_unlock_irqrestore(&phba->hbalock, iflags);
8228 if (!list_empty(&abort_list))
8229 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
8230 "3387 abort list for txq not empty\n");
8231 INIT_LIST_HEAD(&abort_list);
8233 spin_lock_irqsave(&phba->hbalock, iflags);
8234 if (phba->sli_rev == LPFC_SLI_REV4)
8235 spin_lock(&pring->ring_lock);
8237 /* No need to abort the txq list,
8238 * just queue them up for lpfc_sli_cancel_iocbs
8240 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
8243 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
8247 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
8248 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
8249 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
8250 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
8251 cmd->ulpCommand == CMD_ABORT_XRI_CN)
8254 if (piocb->vport != vport)
8257 list_del_init(&piocb->list);
8258 list_add_tail(&piocb->list, &abort_list);
8261 /* The same holds true for any FLOGI/FDISC on the fabric_iocb_list */
8262 if (vport == phba->pport) {
8263 list_for_each_entry_safe(piocb, tmp_iocb,
8264 &phba->fabric_iocb_list, list) {
8266 list_del_init(&piocb->list);
8267 list_add_tail(&piocb->list, &abort_list);
8271 if (phba->sli_rev == LPFC_SLI_REV4)
8272 spin_unlock(&pring->ring_lock);
8273 spin_unlock_irqrestore(&phba->hbalock, iflags);
8275 /* Cancel all the IOCBs from the completions list */
8276 lpfc_sli_cancel_iocbs(phba, &abort_list,
8277 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
8283 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
8284 * @phba: pointer to lpfc hba data structure.
8286 * This routine is used to clean up all the outstanding ELS commands on a
8287 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
8288 * routine. After that, it walks the ELS transmit queue to remove all the
8289 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
8290 * the IOCBs with the completion callback function associated, the callback
8291 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
8292 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
8293 * callback function associated, the IOCB will simply be released. Finally,
8294 * it walks the ELS transmit completion queue to issue an abort IOCB to any
8295 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
8296 * management plane IOCBs that are not part of the discovery state machine)
8297 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
8300 lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
8302 struct lpfc_vport *vport;
8304 spin_lock_irq(&phba->port_list_lock);
8305 list_for_each_entry(vport, &phba->port_list, listentry)
8306 lpfc_els_flush_cmd(vport);
8307 spin_unlock_irq(&phba->port_list_lock);
8313 * lpfc_send_els_failure_event - Posts an ELS command failure event
8314 * @phba: Pointer to hba context object.
8315 * @cmdiocbp: Pointer to command iocb which reported error.
8316 * @rspiocbp: Pointer to response iocb which reported error.
8318 * This function sends an event when there is an ELS command
8322 lpfc_send_els_failure_event(struct lpfc_hba *phba,
8323 struct lpfc_iocbq *cmdiocbp,
8324 struct lpfc_iocbq *rspiocbp)
8326 struct lpfc_vport *vport = cmdiocbp->vport;
8327 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8328 struct lpfc_lsrjt_event lsrjt_event;
8329 struct lpfc_fabric_event_header fabric_event;
8331 struct lpfc_nodelist *ndlp;
8334 ndlp = cmdiocbp->context1;
8338 if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) {
8339 lsrjt_event.header.event_type = FC_REG_ELS_EVENT;
8340 lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV;
8341 memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname,
8342 sizeof(struct lpfc_name));
8343 memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename,
8344 sizeof(struct lpfc_name));
8345 pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
8346 cmdiocbp->context2)->virt);
8347 lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0;
8348 stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]);
8349 lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode;
8350 lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp;
8351 fc_host_post_vendor_event(shost,
8352 fc_get_event_number(),
8353 sizeof(lsrjt_event),
8354 (char *)&lsrjt_event,
8358 if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) ||
8359 (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) {
8360 fabric_event.event_type = FC_REG_FABRIC_EVENT;
8361 if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY)
8362 fabric_event.subcategory = LPFC_EVENT_PORT_BUSY;
8364 fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY;
8365 memcpy(fabric_event.wwpn, &ndlp->nlp_portname,
8366 sizeof(struct lpfc_name));
8367 memcpy(fabric_event.wwnn, &ndlp->nlp_nodename,
8368 sizeof(struct lpfc_name));
8369 fc_host_post_vendor_event(shost,
8370 fc_get_event_number(),
8371 sizeof(fabric_event),
8372 (char *)&fabric_event,
8380 * lpfc_send_els_event - Posts unsolicited els event
8381 * @vport: Pointer to vport object.
8382 * @ndlp: Pointer FC node object.
8383 * @payload: ELS command code type.
8385 * This function posts an event when there is an incoming
8386 * unsolicited ELS command.
8389 lpfc_send_els_event(struct lpfc_vport *vport,
8390 struct lpfc_nodelist *ndlp,
8393 struct lpfc_els_event_header *els_data = NULL;
8394 struct lpfc_logo_event *logo_data = NULL;
8395 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8397 if (*payload == ELS_CMD_LOGO) {
8398 logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL);
8400 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
8401 "0148 Failed to allocate memory "
8402 "for LOGO event\n");
8405 els_data = &logo_data->header;
8407 els_data = kmalloc(sizeof(struct lpfc_els_event_header),
8410 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
8411 "0149 Failed to allocate memory "
8416 els_data->event_type = FC_REG_ELS_EVENT;
8419 els_data->subcategory = LPFC_EVENT_PLOGI_RCV;
8422 els_data->subcategory = LPFC_EVENT_PRLO_RCV;
8425 els_data->subcategory = LPFC_EVENT_ADISC_RCV;
8428 els_data->subcategory = LPFC_EVENT_LOGO_RCV;
8429 /* Copy the WWPN in the LOGO payload */
8430 memcpy(logo_data->logo_wwpn, &payload[2],
8431 sizeof(struct lpfc_name));
8437 memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name));
8438 memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name));
8439 if (*payload == ELS_CMD_LOGO) {
8440 fc_host_post_vendor_event(shost,
8441 fc_get_event_number(),
8442 sizeof(struct lpfc_logo_event),
8447 fc_host_post_vendor_event(shost,
8448 fc_get_event_number(),
8449 sizeof(struct lpfc_els_event_header),
8459 DECLARE_ENUM2STR_LOOKUP(lpfc_get_tlv_dtag_nm, fc_ls_tlv_dtag,
8460 FC_LS_TLV_DTAG_INIT);
8462 DECLARE_ENUM2STR_LOOKUP(lpfc_get_fpin_li_event_nm, fc_fpin_li_event_types,
8463 FC_FPIN_LI_EVT_TYPES_INIT);
8466 * lpfc_els_rcv_fpin_li - Process an FPIN Link Integrity Event.
8467 * @vport: Pointer to vport object.
8468 * @tlv: Pointer to the Link Integrity Notification Descriptor.
8470 * This function processes a link integrity FPIN event by
8474 lpfc_els_rcv_fpin_li(struct lpfc_vport *vport, struct fc_tlv_desc *tlv)
8476 struct fc_fn_li_desc *li = (struct fc_fn_li_desc *)tlv;
8477 const char *li_evt_str;
8480 li_evt = be16_to_cpu(li->event_type);
8481 li_evt_str = lpfc_get_fpin_li_event_nm(li_evt);
8483 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
8484 "4680 FPIN Link Integrity %s (x%x) "
8485 "Detecting PN x%016llx Attached PN x%016llx "
8486 "Duration %d mSecs Count %d Port Cnt %d\n",
8488 be64_to_cpu(li->detecting_wwpn),
8489 be64_to_cpu(li->attached_wwpn),
8490 be32_to_cpu(li->event_threshold),
8491 be32_to_cpu(li->event_count),
8492 be32_to_cpu(li->pname_count));
8496 lpfc_els_rcv_fpin(struct lpfc_vport *vport, struct fc_els_fpin *fpin,
8499 struct fc_tlv_desc *tlv;
8500 const char *dtag_nm;
8501 uint32_t desc_cnt = 0, bytes_remain;
8504 /* FPINs handled only if we are in the right discovery state */
8505 if (vport->port_state < LPFC_DISC_AUTH)
8508 /* make sure there is the full fpin header */
8509 if (fpin_length < sizeof(struct fc_els_fpin))
8512 tlv = (struct fc_tlv_desc *)&fpin->fpin_desc[0];
8513 bytes_remain = fpin_length - offsetof(struct fc_els_fpin, fpin_desc);
8514 bytes_remain = min_t(u32, bytes_remain, be32_to_cpu(fpin->desc_len));
8516 /* process each descriptor */
8517 while (bytes_remain >= FC_TLV_DESC_HDR_SZ &&
8518 bytes_remain >= FC_TLV_DESC_SZ_FROM_LENGTH(tlv)) {
8520 dtag = be32_to_cpu(tlv->desc_tag);
8522 case ELS_DTAG_LNK_INTEGRITY:
8523 lpfc_els_rcv_fpin_li(vport, tlv);
8526 dtag_nm = lpfc_get_tlv_dtag_nm(dtag);
8527 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
8528 "4678 skipped FPIN descriptor[%d]: "
8530 desc_cnt, dtag, dtag_nm);
8535 bytes_remain -= FC_TLV_DESC_SZ_FROM_LENGTH(tlv);
8536 tlv = fc_tlv_next_desc(tlv);
8539 fc_host_fpin_rcv(lpfc_shost_from_vport(vport), fpin_length,
8544 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
8545 * @phba: pointer to lpfc hba data structure.
8546 * @pring: pointer to a SLI ring.
8547 * @vport: pointer to a host virtual N_Port data structure.
8548 * @elsiocb: pointer to lpfc els command iocb data structure.
8550 * This routine is used for processing the IOCB associated with a unsolicited
8551 * event. It first determines whether there is an existing ndlp that matches
8552 * the DID from the unsolicited IOCB. If not, it will create a new one with
8553 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
8554 * IOCB is then used to invoke the proper routine and to set up proper state
8555 * of the discovery state machine.
8558 lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
8559 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
8561 struct Scsi_Host *shost;
8562 struct lpfc_nodelist *ndlp;
8564 uint32_t *payload, payload_len;
8565 uint32_t cmd, did, newnode;
8566 uint8_t rjt_exp, rjt_err = 0, init_link = 0;
8567 IOCB_t *icmd = &elsiocb->iocb;
8570 if (!vport || !(elsiocb->context2))
8574 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
8575 payload_len = elsiocb->iocb.unsli3.rcvsli3.acc_len;
8577 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
8578 lpfc_post_buffer(phba, pring, 1);
8580 did = icmd->un.rcvels.remoteID;
8581 if (icmd->ulpStatus) {
8582 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8583 "RCV Unsol ELS: status:x%x/x%x did:x%x",
8584 icmd->ulpStatus, icmd->un.ulpWord[4], did);
8588 /* Check to see if link went down during discovery */
8589 if (lpfc_els_chk_latt(vport))
8592 /* Ignore traffic received during vport shutdown. */
8593 if (vport->load_flag & FC_UNLOADING)
8596 /* If NPort discovery is delayed drop incoming ELS */
8597 if ((vport->fc_flag & FC_DISC_DELAYED) &&
8598 (cmd != ELS_CMD_PLOGI))
8601 ndlp = lpfc_findnode_did(vport, did);
8603 /* Cannot find existing Fabric ndlp, so allocate a new one */
8604 ndlp = lpfc_nlp_init(vport, did);
8607 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
8609 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
8610 ndlp->nlp_type |= NLP_FABRIC;
8611 } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
8612 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
8616 phba->fc_stat.elsRcvFrame++;
8619 * Do not process any unsolicited ELS commands
8620 * if the ndlp is in DEV_LOSS
8622 shost = lpfc_shost_from_vport(vport);
8623 spin_lock_irq(shost->host_lock);
8624 if (ndlp->nlp_flag & NLP_IN_DEV_LOSS) {
8625 spin_unlock_irq(shost->host_lock);
8630 spin_unlock_irq(shost->host_lock);
8632 elsiocb->context1 = lpfc_nlp_get(ndlp);
8633 if (!elsiocb->context1)
8635 elsiocb->vport = vport;
8637 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
8638 cmd &= ELS_CMD_MASK;
8640 /* ELS command <elsCmd> received from NPORT <did> */
8641 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
8642 "0112 ELS command x%x received from NPORT x%x "
8643 "Data: x%x x%x x%x x%x\n",
8644 cmd, did, vport->port_state, vport->fc_flag,
8645 vport->fc_myDID, vport->fc_prevDID);
8647 /* reject till our FLOGI completes or PLOGI assigned DID via PT2PT */
8648 if ((vport->port_state < LPFC_FABRIC_CFG_LINK) &&
8649 (cmd != ELS_CMD_FLOGI) &&
8650 !((cmd == ELS_CMD_PLOGI) && (vport->fc_flag & FC_PT2PT))) {
8651 rjt_err = LSRJT_LOGICAL_BSY;
8652 rjt_exp = LSEXP_NOTHING_MORE;
8658 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8659 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
8660 did, vport->port_state, ndlp->nlp_flag);
8662 phba->fc_stat.elsRcvPLOGI++;
8663 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
8664 if (phba->sli_rev == LPFC_SLI_REV4 &&
8665 (phba->pport->fc_flag & FC_PT2PT)) {
8666 vport->fc_prevDID = vport->fc_myDID;
8667 /* Our DID needs to be updated before registering
8668 * the vfi. This is done in lpfc_rcv_plogi but
8669 * that is called after the reg_vfi.
8671 vport->fc_myDID = elsiocb->iocb.un.rcvels.parmRo;
8672 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
8673 "3312 Remote port assigned DID x%x "
8674 "%x\n", vport->fc_myDID,
8678 lpfc_send_els_event(vport, ndlp, payload);
8680 /* If Nport discovery is delayed, reject PLOGIs */
8681 if (vport->fc_flag & FC_DISC_DELAYED) {
8682 rjt_err = LSRJT_UNABLE_TPC;
8683 rjt_exp = LSEXP_NOTHING_MORE;
8687 if (vport->port_state < LPFC_DISC_AUTH) {
8688 if (!(phba->pport->fc_flag & FC_PT2PT) ||
8689 (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
8690 rjt_err = LSRJT_UNABLE_TPC;
8691 rjt_exp = LSEXP_NOTHING_MORE;
8696 spin_lock_irq(shost->host_lock);
8697 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
8698 spin_unlock_irq(shost->host_lock);
8700 lpfc_disc_state_machine(vport, ndlp, elsiocb,
8705 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8706 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
8707 did, vport->port_state, ndlp->nlp_flag);
8709 phba->fc_stat.elsRcvFLOGI++;
8711 /* If the driver believes fabric discovery is done and is ready,
8712 * bounce the link. There is some descrepancy.
8714 if (vport->port_state >= LPFC_LOCAL_CFG_LINK &&
8715 vport->fc_flag & FC_PT2PT &&
8716 vport->rcv_flogi_cnt >= 1) {
8717 rjt_err = LSRJT_LOGICAL_BSY;
8718 rjt_exp = LSEXP_NOTHING_MORE;
8723 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
8728 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8729 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
8730 did, vport->port_state, ndlp->nlp_flag);
8732 phba->fc_stat.elsRcvLOGO++;
8733 lpfc_send_els_event(vport, ndlp, payload);
8734 if (vport->port_state < LPFC_DISC_AUTH) {
8735 rjt_err = LSRJT_UNABLE_TPC;
8736 rjt_exp = LSEXP_NOTHING_MORE;
8739 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
8742 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8743 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
8744 did, vport->port_state, ndlp->nlp_flag);
8746 phba->fc_stat.elsRcvPRLO++;
8747 lpfc_send_els_event(vport, ndlp, payload);
8748 if (vport->port_state < LPFC_DISC_AUTH) {
8749 rjt_err = LSRJT_UNABLE_TPC;
8750 rjt_exp = LSEXP_NOTHING_MORE;
8753 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
8756 phba->fc_stat.elsRcvLCB++;
8757 lpfc_els_rcv_lcb(vport, elsiocb, ndlp);
8760 phba->fc_stat.elsRcvRDP++;
8761 lpfc_els_rcv_rdp(vport, elsiocb, ndlp);
8764 phba->fc_stat.elsRcvRSCN++;
8765 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
8770 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8771 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
8772 did, vport->port_state, ndlp->nlp_flag);
8774 lpfc_send_els_event(vport, ndlp, payload);
8775 phba->fc_stat.elsRcvADISC++;
8776 if (vport->port_state < LPFC_DISC_AUTH) {
8777 rjt_err = LSRJT_UNABLE_TPC;
8778 rjt_exp = LSEXP_NOTHING_MORE;
8781 lpfc_disc_state_machine(vport, ndlp, elsiocb,
8785 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8786 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
8787 did, vport->port_state, ndlp->nlp_flag);
8789 phba->fc_stat.elsRcvPDISC++;
8790 if (vport->port_state < LPFC_DISC_AUTH) {
8791 rjt_err = LSRJT_UNABLE_TPC;
8792 rjt_exp = LSEXP_NOTHING_MORE;
8795 lpfc_disc_state_machine(vport, ndlp, elsiocb,
8799 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8800 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
8801 did, vport->port_state, ndlp->nlp_flag);
8803 phba->fc_stat.elsRcvFARPR++;
8804 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
8807 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8808 "RCV FARP: did:x%x/ste:x%x flg:x%x",
8809 did, vport->port_state, ndlp->nlp_flag);
8811 phba->fc_stat.elsRcvFARP++;
8812 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
8815 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8816 "RCV FAN: did:x%x/ste:x%x flg:x%x",
8817 did, vport->port_state, ndlp->nlp_flag);
8819 phba->fc_stat.elsRcvFAN++;
8820 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
8823 case ELS_CMD_NVMEPRLI:
8824 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8825 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
8826 did, vport->port_state, ndlp->nlp_flag);
8828 phba->fc_stat.elsRcvPRLI++;
8829 if ((vport->port_state < LPFC_DISC_AUTH) &&
8830 (vport->fc_flag & FC_FABRIC)) {
8831 rjt_err = LSRJT_UNABLE_TPC;
8832 rjt_exp = LSEXP_NOTHING_MORE;
8835 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
8838 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8839 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
8840 did, vport->port_state, ndlp->nlp_flag);
8842 phba->fc_stat.elsRcvLIRR++;
8843 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
8848 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8849 "RCV RLS: did:x%x/ste:x%x flg:x%x",
8850 did, vport->port_state, ndlp->nlp_flag);
8852 phba->fc_stat.elsRcvRLS++;
8853 lpfc_els_rcv_rls(vport, elsiocb, ndlp);
8858 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8859 "RCV RPL: did:x%x/ste:x%x flg:x%x",
8860 did, vport->port_state, ndlp->nlp_flag);
8862 phba->fc_stat.elsRcvRPL++;
8863 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
8868 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8869 "RCV RNID: did:x%x/ste:x%x flg:x%x",
8870 did, vport->port_state, ndlp->nlp_flag);
8872 phba->fc_stat.elsRcvRNID++;
8873 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
8878 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8879 "RCV RTV: did:x%x/ste:x%x flg:x%x",
8880 did, vport->port_state, ndlp->nlp_flag);
8881 phba->fc_stat.elsRcvRTV++;
8882 lpfc_els_rcv_rtv(vport, elsiocb, ndlp);
8887 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8888 "RCV RRQ: did:x%x/ste:x%x flg:x%x",
8889 did, vport->port_state, ndlp->nlp_flag);
8891 phba->fc_stat.elsRcvRRQ++;
8892 lpfc_els_rcv_rrq(vport, elsiocb, ndlp);
8897 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8898 "RCV ECHO: did:x%x/ste:x%x flg:x%x",
8899 did, vport->port_state, ndlp->nlp_flag);
8901 phba->fc_stat.elsRcvECHO++;
8902 lpfc_els_rcv_echo(vport, elsiocb, ndlp);
8907 /* receive this due to exchange closed */
8908 rjt_err = LSRJT_UNABLE_TPC;
8909 rjt_exp = LSEXP_INVALID_OX_RX;
8912 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8913 "RCV FPIN: did:x%x/ste:x%x flg:x%x",
8914 did, vport->port_state, ndlp->nlp_flag);
8916 lpfc_els_rcv_fpin(vport, (struct fc_els_fpin *)payload,
8919 /* There are no replies, so no rjt codes */
8922 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8923 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
8924 cmd, did, vport->port_state);
8926 /* Unsupported ELS command, reject */
8927 rjt_err = LSRJT_CMD_UNSUPPORTED;
8928 rjt_exp = LSEXP_NOTHING_MORE;
8930 /* Unknown ELS command <elsCmd> received from NPORT <did> */
8931 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
8932 "0115 Unknown ELS command x%x "
8933 "received from NPORT x%x\n", cmd, did);
8940 /* check if need to LS_RJT received ELS cmd */
8942 memset(&stat, 0, sizeof(stat));
8943 stat.un.b.lsRjtRsnCode = rjt_err;
8944 stat.un.b.lsRjtRsnCodeExp = rjt_exp;
8945 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
8947 /* Remove the reference from above for new nodes. */
8952 lpfc_nlp_put(elsiocb->context1);
8953 elsiocb->context1 = NULL;
8955 /* Special case. Driver received an unsolicited command that
8956 * unsupportable given the driver's current state. Reset the
8957 * link and start over.
8960 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
8963 lpfc_linkdown(phba);
8964 lpfc_init_link(phba, mbox,
8966 phba->cfg_link_speed);
8967 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
8968 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
8969 mbox->vport = vport;
8970 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) ==
8972 mempool_free(mbox, phba->mbox_mem_pool);
8978 if (vport && !(vport->load_flag & FC_UNLOADING))
8979 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
8980 "0111 Dropping received ELS cmd "
8981 "Data: x%x x%x x%x\n",
8982 icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout);
8983 phba->fc_stat.elsRcvDrop++;
8987 * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
8988 * @phba: pointer to lpfc hba data structure.
8989 * @pring: pointer to a SLI ring.
8990 * @elsiocb: pointer to lpfc els iocb data structure.
8992 * This routine is used to process an unsolicited event received from a SLI
8993 * (Service Level Interface) ring. The actual processing of the data buffer
8994 * associated with the unsolicited event is done by invoking the routine
8995 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
8996 * SLI ring on which the unsolicited event was received.
8999 lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
9000 struct lpfc_iocbq *elsiocb)
9002 struct lpfc_vport *vport = phba->pport;
9003 IOCB_t *icmd = &elsiocb->iocb;
9005 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
9006 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
9008 elsiocb->context1 = NULL;
9009 elsiocb->context2 = NULL;
9010 elsiocb->context3 = NULL;
9012 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
9013 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
9014 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
9015 (icmd->un.ulpWord[4] & IOERR_PARAM_MASK) ==
9016 IOERR_RCV_BUFFER_WAITING) {
9017 phba->fc_stat.NoRcvBuf++;
9018 /* Not enough posted buffers; Try posting more buffers */
9019 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
9020 lpfc_post_buffer(phba, pring, 0);
9024 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
9025 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
9026 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
9027 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
9028 vport = phba->pport;
9030 vport = lpfc_find_vport_by_vpid(phba,
9031 icmd->unsli3.rcvsli3.vpi);
9034 /* If there are no BDEs associated
9035 * with this IOCB, there is nothing to do.
9037 if (icmd->ulpBdeCount == 0)
9040 /* type of ELS cmd is first 32bit word
9043 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
9044 elsiocb->context2 = bdeBuf1;
9046 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
9047 icmd->un.cont64[0].addrLow);
9048 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
9052 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
9054 * The different unsolicited event handlers would tell us
9055 * if they are done with "mp" by setting context2 to NULL.
9057 if (elsiocb->context2) {
9058 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
9059 elsiocb->context2 = NULL;
9062 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
9063 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
9064 icmd->ulpBdeCount == 2) {
9065 elsiocb->context2 = bdeBuf2;
9066 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
9067 /* free mp if we are done with it */
9068 if (elsiocb->context2) {
9069 lpfc_in_buf_free(phba, elsiocb->context2);
9070 elsiocb->context2 = NULL;
9076 lpfc_start_fdmi(struct lpfc_vport *vport)
9078 struct lpfc_nodelist *ndlp;
9080 /* If this is the first time, allocate an ndlp and initialize
9081 * it. Otherwise, make sure the node is enabled and then do the
9084 ndlp = lpfc_findnode_did(vport, FDMI_DID);
9086 ndlp = lpfc_nlp_init(vport, FDMI_DID);
9088 ndlp->nlp_type |= NLP_FABRIC;
9094 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
9095 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
9099 * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
9100 * @phba: pointer to lpfc hba data structure.
9101 * @vport: pointer to a virtual N_Port data structure.
9103 * This routine issues a Port Login (PLOGI) to the Name Server with
9104 * State Change Request (SCR) for a @vport. This routine will create an
9105 * ndlp for the Name Server associated to the @vport if such node does
9106 * not already exist. The PLOGI to Name Server is issued by invoking the
9107 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
9108 * (FDMI) is configured to the @vport, a FDMI node will be created and
9109 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
9112 lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
9114 struct lpfc_nodelist *ndlp;
9115 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
9118 * If lpfc_delay_discovery parameter is set and the clean address
9119 * bit is cleared and fc fabric parameters chenged, delay FC NPort
9122 spin_lock_irq(shost->host_lock);
9123 if (vport->fc_flag & FC_DISC_DELAYED) {
9124 spin_unlock_irq(shost->host_lock);
9125 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
9126 "3334 Delay fc port discovery for %d seconds\n",
9128 mod_timer(&vport->delayed_disc_tmo,
9129 jiffies + msecs_to_jiffies(1000 * phba->fc_ratov));
9132 spin_unlock_irq(shost->host_lock);
9134 ndlp = lpfc_findnode_did(vport, NameServer_DID);
9136 ndlp = lpfc_nlp_init(vport, NameServer_DID);
9138 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
9139 lpfc_disc_start(vport);
9142 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
9143 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
9144 "0251 NameServer login: no memory\n");
9149 ndlp->nlp_type |= NLP_FABRIC;
9151 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
9153 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
9154 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
9155 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
9156 "0252 Cannot issue NameServer login\n");
9160 if ((phba->cfg_enable_SmartSAN ||
9161 (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) &&
9162 (vport->load_flag & FC_ALLOW_FDMI))
9163 lpfc_start_fdmi(vport);
9167 * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
9168 * @phba: pointer to lpfc hba data structure.
9169 * @pmb: pointer to the driver internal queue element for mailbox command.
9171 * This routine is the completion callback function to register new vport
9172 * mailbox command. If the new vport mailbox command completes successfully,
9173 * the fabric registration login shall be performed on physical port (the
9174 * new vport created is actually a physical port, with VPI 0) or the port
9175 * login to Name Server for State Change Request (SCR) will be performed
9176 * on virtual port (real virtual port, with VPI greater than 0).
9179 lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
9181 struct lpfc_vport *vport = pmb->vport;
9182 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
9183 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
9184 MAILBOX_t *mb = &pmb->u.mb;
9187 spin_lock_irq(shost->host_lock);
9188 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
9189 spin_unlock_irq(shost->host_lock);
9191 if (mb->mbxStatus) {
9192 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
9193 "0915 Register VPI failed : Status: x%x"
9194 " upd bit: x%x \n", mb->mbxStatus,
9195 mb->un.varRegVpi.upd);
9196 if (phba->sli_rev == LPFC_SLI_REV4 &&
9197 mb->un.varRegVpi.upd)
9198 goto mbox_err_exit ;
9200 switch (mb->mbxStatus) {
9201 case 0x11: /* unsupported feature */
9202 case 0x9603: /* max_vpi exceeded */
9203 case 0x9602: /* Link event since CLEAR_LA */
9204 /* giving up on vport registration */
9205 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
9206 spin_lock_irq(shost->host_lock);
9207 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
9208 spin_unlock_irq(shost->host_lock);
9209 lpfc_can_disctmo(vport);
9211 /* If reg_vpi fail with invalid VPI status, re-init VPI */
9213 spin_lock_irq(shost->host_lock);
9214 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
9215 spin_unlock_irq(shost->host_lock);
9216 lpfc_init_vpi(phba, pmb, vport->vpi);
9218 pmb->mbox_cmpl = lpfc_init_vpi_cmpl;
9219 rc = lpfc_sli_issue_mbox(phba, pmb,
9221 if (rc == MBX_NOT_FINISHED) {
9222 lpfc_printf_vlog(vport, KERN_ERR,
9224 "2732 Failed to issue INIT_VPI"
9225 " mailbox command\n");
9232 /* Try to recover from this error */
9233 if (phba->sli_rev == LPFC_SLI_REV4)
9234 lpfc_sli4_unreg_all_rpis(vport);
9235 lpfc_mbx_unreg_vpi(vport);
9236 spin_lock_irq(shost->host_lock);
9237 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
9238 spin_unlock_irq(shost->host_lock);
9239 if (mb->mbxStatus == MBX_NOT_FINISHED)
9241 if ((vport->port_type == LPFC_PHYSICAL_PORT) &&
9242 !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG)) {
9243 if (phba->sli_rev == LPFC_SLI_REV4)
9244 lpfc_issue_init_vfi(vport);
9246 lpfc_initial_flogi(vport);
9248 lpfc_initial_fdisc(vport);
9253 spin_lock_irq(shost->host_lock);
9254 vport->vpi_state |= LPFC_VPI_REGISTERED;
9255 spin_unlock_irq(shost->host_lock);
9256 if (vport == phba->pport) {
9257 if (phba->sli_rev < LPFC_SLI_REV4)
9258 lpfc_issue_fabric_reglogin(vport);
9261 * If the physical port is instantiated using
9262 * FDISC, do not start vport discovery.
9264 if (vport->port_state != LPFC_FDISC)
9265 lpfc_start_fdiscs(phba);
9266 lpfc_do_scr_ns_plogi(phba, vport);
9269 lpfc_do_scr_ns_plogi(phba, vport);
9272 /* Now, we decrement the ndlp reference count held for this
9277 mempool_free(pmb, phba->mbox_mem_pool);
9282 * lpfc_register_new_vport - Register a new vport with a HBA
9283 * @phba: pointer to lpfc hba data structure.
9284 * @vport: pointer to a host virtual N_Port data structure.
9285 * @ndlp: pointer to a node-list data structure.
9287 * This routine registers the @vport as a new virtual port with a HBA.
9288 * It is done through a registering vpi mailbox command.
9291 lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
9292 struct lpfc_nodelist *ndlp)
9294 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
9297 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
9299 lpfc_reg_vpi(vport, mbox);
9300 mbox->vport = vport;
9301 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
9302 if (!mbox->ctx_ndlp) {
9303 mempool_free(mbox, phba->mbox_mem_pool);
9307 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
9308 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
9309 == MBX_NOT_FINISHED) {
9310 /* mailbox command not success, decrement ndlp
9311 * reference count for this command
9314 mempool_free(mbox, phba->mbox_mem_pool);
9316 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
9317 "0253 Register VPI: Can't send mbox\n");
9321 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
9322 "0254 Register VPI: no memory\n");
9328 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
9329 spin_lock_irq(shost->host_lock);
9330 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
9331 spin_unlock_irq(shost->host_lock);
9336 * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer
9337 * @phba: pointer to lpfc hba data structure.
9339 * This routine cancels the retry delay timers to all the vports.
9342 lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba)
9344 struct lpfc_vport **vports;
9345 struct lpfc_nodelist *ndlp;
9346 uint32_t link_state;
9349 /* Treat this failure as linkdown for all vports */
9350 link_state = phba->link_state;
9351 lpfc_linkdown(phba);
9352 phba->link_state = link_state;
9354 vports = lpfc_create_vport_work_array(phba);
9357 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
9358 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
9360 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
9361 lpfc_els_flush_cmd(vports[i]);
9363 lpfc_destroy_vport_work_array(phba, vports);
9368 * lpfc_retry_pport_discovery - Start timer to retry FLOGI.
9369 * @phba: pointer to lpfc hba data structure.
9371 * This routine abort all pending discovery commands and
9372 * start a timer to retry FLOGI for the physical port
9376 lpfc_retry_pport_discovery(struct lpfc_hba *phba)
9378 struct lpfc_nodelist *ndlp;
9379 struct Scsi_Host *shost;
9381 /* Cancel the all vports retry delay retry timers */
9382 lpfc_cancel_all_vport_retry_delay_timer(phba);
9384 /* If fabric require FLOGI, then re-instantiate physical login */
9385 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
9389 shost = lpfc_shost_from_vport(phba->pport);
9390 mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000));
9391 spin_lock_irq(shost->host_lock);
9392 ndlp->nlp_flag |= NLP_DELAY_TMO;
9393 spin_unlock_irq(shost->host_lock);
9394 ndlp->nlp_last_elscmd = ELS_CMD_FLOGI;
9395 phba->pport->port_state = LPFC_FLOGI;
9400 * lpfc_fabric_login_reqd - Check if FLOGI required.
9401 * @phba: pointer to lpfc hba data structure.
9402 * @cmdiocb: pointer to FDISC command iocb.
9403 * @rspiocb: pointer to FDISC response iocb.
9405 * This routine checks if a FLOGI is reguired for FDISC
9409 lpfc_fabric_login_reqd(struct lpfc_hba *phba,
9410 struct lpfc_iocbq *cmdiocb,
9411 struct lpfc_iocbq *rspiocb)
9414 if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) ||
9415 (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED))
9422 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
9423 * @phba: pointer to lpfc hba data structure.
9424 * @cmdiocb: pointer to lpfc command iocb data structure.
9425 * @rspiocb: pointer to lpfc response iocb data structure.
9427 * This routine is the completion callback function to a Fabric Discover
9428 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
9429 * single threaded, each FDISC completion callback function will reset
9430 * the discovery timer for all vports such that the timers will not get
9431 * unnecessary timeout. The function checks the FDISC IOCB status. If error
9432 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
9433 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
9434 * assigned to the vport has been changed with the completion of the FDISC
9435 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
9436 * are unregistered from the HBA, and then the lpfc_register_new_vport()
9437 * routine is invoked to register new vport with the HBA. Otherwise, the
9438 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
9439 * Server for State Change Request (SCR).
9442 lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
9443 struct lpfc_iocbq *rspiocb)
9445 struct lpfc_vport *vport = cmdiocb->vport;
9446 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
9447 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
9448 struct lpfc_nodelist *np;
9449 struct lpfc_nodelist *next_np;
9450 IOCB_t *irsp = &rspiocb->iocb;
9451 struct lpfc_iocbq *piocb;
9452 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
9453 struct serv_parm *sp;
9454 uint8_t fabric_param_changed;
9456 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
9457 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
9458 irsp->ulpStatus, irsp->un.ulpWord[4],
9460 /* Since all FDISCs are being single threaded, we
9461 * must reset the discovery timer for ALL vports
9462 * waiting to send FDISC when one completes.
9464 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
9465 lpfc_set_disctmo(piocb->vport);
9468 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
9469 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
9470 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
9472 if (irsp->ulpStatus) {
9474 if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) {
9475 lpfc_retry_pport_discovery(phba);
9479 /* Check for retry */
9480 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
9483 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
9484 "0126 FDISC failed. (x%x/x%x)\n",
9485 irsp->ulpStatus, irsp->un.ulpWord[4]);
9488 spin_lock_irq(shost->host_lock);
9489 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
9490 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
9491 vport->fc_flag |= FC_FABRIC;
9492 if (vport->phba->fc_topology == LPFC_TOPOLOGY_LOOP)
9493 vport->fc_flag |= FC_PUBLIC_LOOP;
9494 spin_unlock_irq(shost->host_lock);
9496 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
9497 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
9498 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
9501 sp = prsp->virt + sizeof(uint32_t);
9502 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
9503 memcpy(&vport->fabric_portname, &sp->portName,
9504 sizeof(struct lpfc_name));
9505 memcpy(&vport->fabric_nodename, &sp->nodeName,
9506 sizeof(struct lpfc_name));
9507 if (fabric_param_changed &&
9508 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
9509 /* If our NportID changed, we need to ensure all
9510 * remaining NPORTs get unreg_login'ed so we can
9513 list_for_each_entry_safe(np, next_np,
9514 &vport->fc_nodes, nlp_listp) {
9515 if ((np->nlp_state != NLP_STE_NPR_NODE) ||
9516 !(np->nlp_flag & NLP_NPR_ADISC))
9518 spin_lock_irq(shost->host_lock);
9519 np->nlp_flag &= ~NLP_NPR_ADISC;
9520 spin_unlock_irq(shost->host_lock);
9521 lpfc_unreg_rpi(vport, np);
9523 lpfc_cleanup_pending_mbox(vport);
9525 if (phba->sli_rev == LPFC_SLI_REV4)
9526 lpfc_sli4_unreg_all_rpis(vport);
9528 lpfc_mbx_unreg_vpi(vport);
9529 spin_lock_irq(shost->host_lock);
9530 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
9531 if (phba->sli_rev == LPFC_SLI_REV4)
9532 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
9534 vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG;
9535 spin_unlock_irq(shost->host_lock);
9536 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
9537 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
9539 * Driver needs to re-reg VPI in order for f/w
9540 * to update the MAC address.
9542 lpfc_register_new_vport(phba, vport, ndlp);
9546 if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)
9547 lpfc_issue_init_vpi(vport);
9548 else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
9549 lpfc_register_new_vport(phba, vport, ndlp);
9551 lpfc_do_scr_ns_plogi(phba, vport);
9554 if (vport->fc_vport &&
9555 (vport->fc_vport->vport_state != FC_VPORT_NO_FABRIC_RSCS))
9556 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
9557 /* Cancel discovery timer */
9558 lpfc_can_disctmo(vport);
9560 lpfc_els_free_iocb(phba, cmdiocb);
9565 * lpfc_issue_els_fdisc - Issue a fdisc iocb command
9566 * @vport: pointer to a virtual N_Port data structure.
9567 * @ndlp: pointer to a node-list data structure.
9568 * @retry: number of retries to the command IOCB.
9570 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
9571 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
9572 * routine to issue the IOCB, which makes sure only one outstanding fabric
9573 * IOCB will be sent off HBA at any given time.
9575 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
9576 * will be incremented by 1 for holding the ndlp and the reference to ndlp
9577 * will be stored into the context1 field of the IOCB for the completion
9578 * callback function to the FDISC ELS command.
9581 * 0 - Successfully issued fdisc iocb command
9582 * 1 - Failed to issue fdisc iocb command
9585 lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
9588 struct lpfc_hba *phba = vport->phba;
9590 struct lpfc_iocbq *elsiocb;
9591 struct serv_parm *sp;
9594 int did = ndlp->nlp_DID;
9597 vport->port_state = LPFC_FDISC;
9598 vport->fc_myDID = 0;
9599 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
9600 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
9603 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
9604 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
9605 "0255 Issue FDISC: no IOCB\n");
9609 icmd = &elsiocb->iocb;
9610 icmd->un.elsreq64.myID = 0;
9611 icmd->un.elsreq64.fl = 1;
9614 * SLI3 ports require a different context type value than SLI4.
9615 * Catch SLI3 ports here and override the prep.
9617 if (phba->sli_rev == LPFC_SLI_REV3) {
9622 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
9623 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
9624 pcmd += sizeof(uint32_t); /* CSP Word 1 */
9625 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
9626 sp = (struct serv_parm *) pcmd;
9627 /* Setup CSPs accordingly for Fabric */
9628 sp->cmn.e_d_tov = 0;
9629 sp->cmn.w2.r_a_tov = 0;
9630 sp->cmn.virtual_fabric_support = 0;
9631 sp->cls1.classValid = 0;
9632 sp->cls2.seqDelivery = 1;
9633 sp->cls3.seqDelivery = 1;
9635 pcmd += sizeof(uint32_t); /* CSP Word 2 */
9636 pcmd += sizeof(uint32_t); /* CSP Word 3 */
9637 pcmd += sizeof(uint32_t); /* CSP Word 4 */
9638 pcmd += sizeof(uint32_t); /* Port Name */
9639 memcpy(pcmd, &vport->fc_portname, 8);
9640 pcmd += sizeof(uint32_t); /* Node Name */
9641 pcmd += sizeof(uint32_t); /* Node Name */
9642 memcpy(pcmd, &vport->fc_nodename, 8);
9643 sp->cmn.valid_vendor_ver_level = 0;
9644 memset(sp->un.vendorVersion, 0, sizeof(sp->un.vendorVersion));
9645 lpfc_set_disctmo(vport);
9647 phba->fc_stat.elsXmitFDISC++;
9648 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
9650 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
9651 "Issue FDISC: did:x%x",
9654 elsiocb->context1 = lpfc_nlp_get(ndlp);
9655 if (!elsiocb->context1)
9658 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
9659 if (rc == IOCB_ERROR) {
9664 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
9668 lpfc_els_free_iocb(phba, elsiocb);
9669 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
9670 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
9671 "0256 Issue FDISC: Cannot send IOCB\n");
9676 * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
9677 * @phba: pointer to lpfc hba data structure.
9678 * @cmdiocb: pointer to lpfc command iocb data structure.
9679 * @rspiocb: pointer to lpfc response iocb data structure.
9681 * This routine is the completion callback function to the issuing of a LOGO
9682 * ELS command off a vport. It frees the command IOCB and then decrement the
9683 * reference count held on ndlp for this completion function, indicating that
9684 * the reference to the ndlp is no long needed. Note that the
9685 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
9686 * callback function and an additional explicit ndlp reference decrementation
9687 * will trigger the actual release of the ndlp.
9690 lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
9691 struct lpfc_iocbq *rspiocb)
9693 struct lpfc_vport *vport = cmdiocb->vport;
9695 struct lpfc_nodelist *ndlp;
9696 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
9698 ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
9699 irsp = &rspiocb->iocb;
9700 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
9701 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
9702 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
9705 lpfc_els_free_iocb(phba, cmdiocb);
9706 vport->unreg_vpi_cmpl = VPORT_ERROR;
9708 /* Trigger the release of the ndlp after logo */
9711 /* NPIV LOGO completes to NPort <nlp_DID> */
9712 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
9713 "2928 NPIV LOGO completes to NPort x%x "
9714 "Data: x%x x%x x%x x%x\n",
9715 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
9716 irsp->ulpTimeout, vport->num_disc_nodes);
9718 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
9719 spin_lock_irq(shost->host_lock);
9720 vport->fc_flag &= ~FC_NDISC_ACTIVE;
9721 vport->fc_flag &= ~FC_FABRIC;
9722 spin_unlock_irq(shost->host_lock);
9723 lpfc_can_disctmo(vport);
9729 * lpfc_issue_els_npiv_logo - Issue a logo off a vport
9730 * @vport: pointer to a virtual N_Port data structure.
9731 * @ndlp: pointer to a node-list data structure.
9733 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
9735 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
9736 * will be incremented by 1 for holding the ndlp and the reference to ndlp
9737 * will be stored into the context1 field of the IOCB for the completion
9738 * callback function to the LOGO ELS command.
9741 * 0 - Successfully issued logo off the @vport
9742 * 1 - Failed to issue logo off the @vport
9745 lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
9748 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
9749 struct lpfc_hba *phba = vport->phba;
9750 struct lpfc_iocbq *elsiocb;
9754 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
9755 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
9760 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
9761 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
9762 pcmd += sizeof(uint32_t);
9764 /* Fill in LOGO payload */
9765 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
9766 pcmd += sizeof(uint32_t);
9767 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
9769 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
9770 "Issue LOGO npiv did:x%x flg:x%x",
9771 ndlp->nlp_DID, ndlp->nlp_flag, 0);
9773 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
9774 spin_lock_irq(shost->host_lock);
9775 ndlp->nlp_flag |= NLP_LOGO_SND;
9776 spin_unlock_irq(shost->host_lock);
9777 elsiocb->context1 = lpfc_nlp_get(ndlp);
9778 if (!elsiocb->context1)
9780 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
9781 if (rc == IOCB_ERROR)
9788 spin_lock_irq(shost->host_lock);
9789 ndlp->nlp_flag &= ~NLP_LOGO_SND;
9790 spin_unlock_irq(shost->host_lock);
9791 lpfc_els_free_iocb(phba, elsiocb);
9796 * lpfc_fabric_block_timeout - Handler function to the fabric block timer
9797 * @t: timer context used to obtain the lpfc hba.
9799 * This routine is invoked by the fabric iocb block timer after
9800 * timeout. It posts the fabric iocb block timeout event by setting the
9801 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
9802 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
9803 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
9804 * posted event WORKER_FABRIC_BLOCK_TMO.
9807 lpfc_fabric_block_timeout(struct timer_list *t)
9809 struct lpfc_hba *phba = from_timer(phba, t, fabric_block_timer);
9810 unsigned long iflags;
9811 uint32_t tmo_posted;
9813 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
9814 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
9816 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
9817 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
9820 lpfc_worker_wake_up(phba);
9825 * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
9826 * @phba: pointer to lpfc hba data structure.
9828 * This routine issues one fabric iocb from the driver internal list to
9829 * the HBA. It first checks whether it's ready to issue one fabric iocb to
9830 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
9831 * remove one pending fabric iocb from the driver internal list and invokes
9832 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
9835 lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
9837 struct lpfc_iocbq *iocb;
9838 unsigned long iflags;
9844 spin_lock_irqsave(&phba->hbalock, iflags);
9845 /* Post any pending iocb to the SLI layer */
9846 if (atomic_read(&phba->fabric_iocb_count) == 0) {
9847 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
9850 /* Increment fabric iocb count to hold the position */
9851 atomic_inc(&phba->fabric_iocb_count);
9853 spin_unlock_irqrestore(&phba->hbalock, iflags);
9855 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
9856 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
9857 iocb->iocb_flag |= LPFC_IO_FABRIC;
9859 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
9860 "Fabric sched1: ste:x%x",
9861 iocb->vport->port_state, 0, 0);
9863 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
9865 if (ret == IOCB_ERROR) {
9866 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
9867 iocb->fabric_iocb_cmpl = NULL;
9868 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
9870 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
9871 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
9872 iocb->iocb_cmpl(phba, iocb, iocb);
9874 atomic_dec(&phba->fabric_iocb_count);
9881 * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
9882 * @phba: pointer to lpfc hba data structure.
9884 * This routine unblocks the issuing fabric iocb command. The function
9885 * will clear the fabric iocb block bit and then invoke the routine
9886 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
9887 * from the driver internal fabric iocb list.
9890 lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
9892 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
9894 lpfc_resume_fabric_iocbs(phba);
9899 * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
9900 * @phba: pointer to lpfc hba data structure.
9902 * This routine blocks the issuing fabric iocb for a specified amount of
9903 * time (currently 100 ms). This is done by set the fabric iocb block bit
9904 * and set up a timeout timer for 100ms. When the block bit is set, no more
9905 * fabric iocb will be issued out of the HBA.
9908 lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
9912 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
9913 /* Start a timer to unblock fabric iocbs after 100ms */
9915 mod_timer(&phba->fabric_block_timer,
9916 jiffies + msecs_to_jiffies(100));
9922 * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
9923 * @phba: pointer to lpfc hba data structure.
9924 * @cmdiocb: pointer to lpfc command iocb data structure.
9925 * @rspiocb: pointer to lpfc response iocb data structure.
9927 * This routine is the callback function that is put to the fabric iocb's
9928 * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
9929 * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
9930 * function first restores and invokes the original iocb's callback function
9931 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
9932 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
9935 lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
9936 struct lpfc_iocbq *rspiocb)
9940 BUG_ON((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC);
9942 switch (rspiocb->iocb.ulpStatus) {
9943 case IOSTAT_NPORT_RJT:
9944 case IOSTAT_FABRIC_RJT:
9945 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
9946 lpfc_block_fabric_iocbs(phba);
9950 case IOSTAT_NPORT_BSY:
9951 case IOSTAT_FABRIC_BSY:
9952 lpfc_block_fabric_iocbs(phba);
9956 stat.un.lsRjtError =
9957 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
9958 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
9959 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
9960 lpfc_block_fabric_iocbs(phba);
9964 BUG_ON(atomic_read(&phba->fabric_iocb_count) == 0);
9966 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
9967 cmdiocb->fabric_iocb_cmpl = NULL;
9968 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
9969 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
9971 atomic_dec(&phba->fabric_iocb_count);
9972 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
9973 /* Post any pending iocbs to HBA */
9974 lpfc_resume_fabric_iocbs(phba);
9979 * lpfc_issue_fabric_iocb - Issue a fabric iocb command
9980 * @phba: pointer to lpfc hba data structure.
9981 * @iocb: pointer to lpfc command iocb data structure.
9983 * This routine is used as the top-level API for issuing a fabric iocb command
9984 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
9985 * function makes sure that only one fabric bound iocb will be outstanding at
9986 * any given time. As such, this function will first check to see whether there
9987 * is already an outstanding fabric iocb on the wire. If so, it will put the
9988 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
9989 * issued later. Otherwise, it will issue the iocb on the wire and update the
9990 * fabric iocb count it indicate that there is one fabric iocb on the wire.
9992 * Note, this implementation has a potential sending out fabric IOCBs out of
9993 * order. The problem is caused by the construction of the "ready" boolen does
9994 * not include the condition that the internal fabric IOCB list is empty. As
9995 * such, it is possible a fabric IOCB issued by this routine might be "jump"
9996 * ahead of the fabric IOCBs in the internal list.
9999 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
10000 * IOCB_ERROR - failed to issue fabric iocb
10003 lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
10005 unsigned long iflags;
10009 BUG_ON(atomic_read(&phba->fabric_iocb_count) > 1);
10011 spin_lock_irqsave(&phba->hbalock, iflags);
10012 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
10013 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
10016 /* Increment fabric iocb count to hold the position */
10017 atomic_inc(&phba->fabric_iocb_count);
10018 spin_unlock_irqrestore(&phba->hbalock, iflags);
10020 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
10021 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
10022 iocb->iocb_flag |= LPFC_IO_FABRIC;
10024 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
10025 "Fabric sched2: ste:x%x",
10026 iocb->vport->port_state, 0, 0);
10028 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
10030 if (ret == IOCB_ERROR) {
10031 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
10032 iocb->fabric_iocb_cmpl = NULL;
10033 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
10034 atomic_dec(&phba->fabric_iocb_count);
10037 spin_lock_irqsave(&phba->hbalock, iflags);
10038 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
10039 spin_unlock_irqrestore(&phba->hbalock, iflags);
10040 ret = IOCB_SUCCESS;
10046 * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
10047 * @vport: pointer to a virtual N_Port data structure.
10049 * This routine aborts all the IOCBs associated with a @vport from the
10050 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
10051 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
10052 * list, removes each IOCB associated with the @vport off the list, set the
10053 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
10054 * associated with the IOCB.
10056 static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
10058 LIST_HEAD(completions);
10059 struct lpfc_hba *phba = vport->phba;
10060 struct lpfc_iocbq *tmp_iocb, *piocb;
10062 spin_lock_irq(&phba->hbalock);
10063 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
10066 if (piocb->vport != vport)
10069 list_move_tail(&piocb->list, &completions);
10071 spin_unlock_irq(&phba->hbalock);
10073 /* Cancel all the IOCBs from the completions list */
10074 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
10075 IOERR_SLI_ABORTED);
10079 * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
10080 * @ndlp: pointer to a node-list data structure.
10082 * This routine aborts all the IOCBs associated with an @ndlp from the
10083 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
10084 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
10085 * list, removes each IOCB associated with the @ndlp off the list, set the
10086 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
10087 * associated with the IOCB.
10089 void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
10091 LIST_HEAD(completions);
10092 struct lpfc_hba *phba = ndlp->phba;
10093 struct lpfc_iocbq *tmp_iocb, *piocb;
10094 struct lpfc_sli_ring *pring;
10096 pring = lpfc_phba_elsring(phba);
10098 if (unlikely(!pring))
10101 spin_lock_irq(&phba->hbalock);
10102 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
10104 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
10106 list_move_tail(&piocb->list, &completions);
10109 spin_unlock_irq(&phba->hbalock);
10111 /* Cancel all the IOCBs from the completions list */
10112 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
10113 IOERR_SLI_ABORTED);
10117 * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
10118 * @phba: pointer to lpfc hba data structure.
10120 * This routine aborts all the IOCBs currently on the driver internal
10121 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
10122 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
10123 * list, removes IOCBs off the list, set the status feild to
10124 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
10127 void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
10129 LIST_HEAD(completions);
10131 spin_lock_irq(&phba->hbalock);
10132 list_splice_init(&phba->fabric_iocb_list, &completions);
10133 spin_unlock_irq(&phba->hbalock);
10135 /* Cancel all the IOCBs from the completions list */
10136 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
10137 IOERR_SLI_ABORTED);
10141 * lpfc_sli4_vport_delete_els_xri_aborted -Remove all ndlp references for vport
10142 * @vport: pointer to lpfc vport data structure.
10144 * This routine is invoked by the vport cleanup for deletions and the cleanup
10145 * for an ndlp on removal.
10148 lpfc_sli4_vport_delete_els_xri_aborted(struct lpfc_vport *vport)
10150 struct lpfc_hba *phba = vport->phba;
10151 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
10152 unsigned long iflag = 0;
10154 spin_lock_irqsave(&phba->hbalock, iflag);
10155 spin_lock(&phba->sli4_hba.sgl_list_lock);
10156 list_for_each_entry_safe(sglq_entry, sglq_next,
10157 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
10158 if (sglq_entry->ndlp && sglq_entry->ndlp->vport == vport) {
10159 lpfc_nlp_put(sglq_entry->ndlp);
10160 sglq_entry->ndlp = NULL;
10163 spin_unlock(&phba->sli4_hba.sgl_list_lock);
10164 spin_unlock_irqrestore(&phba->hbalock, iflag);
10169 * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
10170 * @phba: pointer to lpfc hba data structure.
10171 * @axri: pointer to the els xri abort wcqe structure.
10173 * This routine is invoked by the worker thread to process a SLI4 slow-path
10177 lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba,
10178 struct sli4_wcqe_xri_aborted *axri)
10180 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
10181 uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri);
10184 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
10185 unsigned long iflag = 0;
10186 struct lpfc_nodelist *ndlp;
10187 struct lpfc_sli_ring *pring;
10189 pring = lpfc_phba_elsring(phba);
10191 spin_lock_irqsave(&phba->hbalock, iflag);
10192 spin_lock(&phba->sli4_hba.sgl_list_lock);
10193 list_for_each_entry_safe(sglq_entry, sglq_next,
10194 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
10195 if (sglq_entry->sli4_xritag == xri) {
10196 list_del(&sglq_entry->list);
10197 ndlp = sglq_entry->ndlp;
10198 sglq_entry->ndlp = NULL;
10199 list_add_tail(&sglq_entry->list,
10200 &phba->sli4_hba.lpfc_els_sgl_list);
10201 sglq_entry->state = SGL_FREED;
10202 spin_unlock(&phba->sli4_hba.sgl_list_lock);
10203 spin_unlock_irqrestore(&phba->hbalock, iflag);
10206 lpfc_set_rrq_active(phba, ndlp,
10207 sglq_entry->sli4_lxritag,
10209 lpfc_nlp_put(ndlp);
10212 /* Check if TXQ queue needs to be serviced */
10213 if (pring && !list_empty(&pring->txq))
10214 lpfc_worker_wake_up(phba);
10218 spin_unlock(&phba->sli4_hba.sgl_list_lock);
10219 lxri = lpfc_sli4_xri_inrange(phba, xri);
10220 if (lxri == NO_XRI) {
10221 spin_unlock_irqrestore(&phba->hbalock, iflag);
10224 spin_lock(&phba->sli4_hba.sgl_list_lock);
10225 sglq_entry = __lpfc_get_active_sglq(phba, lxri);
10226 if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) {
10227 spin_unlock(&phba->sli4_hba.sgl_list_lock);
10228 spin_unlock_irqrestore(&phba->hbalock, iflag);
10231 sglq_entry->state = SGL_XRI_ABORTED;
10232 spin_unlock(&phba->sli4_hba.sgl_list_lock);
10233 spin_unlock_irqrestore(&phba->hbalock, iflag);
10237 /* lpfc_sli_abts_recover_port - Recover a port that failed a BLS_ABORT req.
10238 * @vport: pointer to virtual port object.
10239 * @ndlp: nodelist pointer for the impacted node.
10241 * The driver calls this routine in response to an SLI4 XRI ABORT CQE
10242 * or an SLI3 ASYNC_STATUS_CN event from the port. For either event,
10243 * the driver is required to send a LOGO to the remote node before it
10244 * attempts to recover its login to the remote node.
10247 lpfc_sli_abts_recover_port(struct lpfc_vport *vport,
10248 struct lpfc_nodelist *ndlp)
10250 struct Scsi_Host *shost;
10251 struct lpfc_hba *phba;
10252 unsigned long flags = 0;
10254 shost = lpfc_shost_from_vport(vport);
10255 phba = vport->phba;
10256 if (ndlp->nlp_state != NLP_STE_MAPPED_NODE) {
10257 lpfc_printf_log(phba, KERN_INFO,
10258 LOG_SLI, "3093 No rport recovery needed. "
10259 "rport in state 0x%x\n", ndlp->nlp_state);
10262 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10263 "3094 Start rport recovery on shost id 0x%x "
10264 "fc_id 0x%06x vpi 0x%x rpi 0x%x state 0x%x "
10266 shost->host_no, ndlp->nlp_DID,
10267 vport->vpi, ndlp->nlp_rpi, ndlp->nlp_state,
10270 * The rport is not responding. Remove the FCP-2 flag to prevent
10271 * an ADISC in the follow-up recovery code.
10273 spin_lock_irqsave(shost->host_lock, flags);
10274 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
10275 ndlp->nlp_flag |= NLP_ISSUE_LOGO;
10276 spin_unlock_irqrestore(shost->host_lock, flags);
10277 lpfc_unreg_rpi(vport, ndlp);