1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2017-2018 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>
37 #include "lpfc_sli4.h"
39 #include "lpfc_disc.h"
40 #include "lpfc_scsi.h"
42 #include "lpfc_logmsg.h"
43 #include "lpfc_crtn.h"
44 #include "lpfc_vport.h"
45 #include "lpfc_debugfs.h"
47 static int lpfc_els_retry(struct lpfc_hba *, struct lpfc_iocbq *,
49 static void lpfc_cmpl_fabric_iocb(struct lpfc_hba *, struct lpfc_iocbq *,
51 static void lpfc_fabric_abort_vport(struct lpfc_vport *vport);
52 static int lpfc_issue_els_fdisc(struct lpfc_vport *vport,
53 struct lpfc_nodelist *ndlp, uint8_t retry);
54 static int lpfc_issue_fabric_iocb(struct lpfc_hba *phba,
55 struct lpfc_iocbq *iocb);
57 static int lpfc_max_els_tries = 3;
60 * lpfc_els_chk_latt - Check host link attention event for a vport
61 * @vport: pointer to a host virtual N_Port data structure.
63 * This routine checks whether there is an outstanding host link
64 * attention event during the discovery process with the @vport. It is done
65 * by reading the HBA's Host Attention (HA) register. If there is any host
66 * link attention events during this @vport's discovery process, the @vport
67 * shall be marked as FC_ABORT_DISCOVERY, a host link attention clear shall
68 * be issued if the link state is not already in host link cleared state,
69 * and a return code shall indicate whether the host link attention event
72 * Note that, if either the host link is in state LPFC_LINK_DOWN or @vport
73 * state in LPFC_VPORT_READY, the request for checking host link attention
74 * event will be ignored and a return code shall indicate no host link
75 * attention event had happened.
78 * 0 - no host link attention event happened
79 * 1 - host link attention event happened
82 lpfc_els_chk_latt(struct lpfc_vport *vport)
84 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
85 struct lpfc_hba *phba = vport->phba;
88 if (vport->port_state >= LPFC_VPORT_READY ||
89 phba->link_state == LPFC_LINK_DOWN ||
90 phba->sli_rev > LPFC_SLI_REV3)
93 /* Read the HBA Host Attention Register */
94 if (lpfc_readl(phba->HAregaddr, &ha_copy))
97 if (!(ha_copy & HA_LATT))
100 /* Pending Link Event during Discovery */
101 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
102 "0237 Pending Link Event during "
103 "Discovery: State x%x\n",
104 phba->pport->port_state);
106 /* CLEAR_LA should re-enable link attention events and
107 * we should then immediately take a LATT event. The
108 * LATT processing should call lpfc_linkdown() which
109 * will cleanup any left over in-progress discovery
112 spin_lock_irq(shost->host_lock);
113 vport->fc_flag |= FC_ABORT_DISCOVERY;
114 spin_unlock_irq(shost->host_lock);
116 if (phba->link_state != LPFC_CLEAR_LA)
117 lpfc_issue_clear_la(phba, vport);
123 * lpfc_prep_els_iocb - Allocate and prepare a lpfc iocb data structure
124 * @vport: pointer to a host virtual N_Port data structure.
125 * @expectRsp: flag indicating whether response is expected.
126 * @cmdSize: size of the ELS command.
127 * @retry: number of retries to the command IOCB when it fails.
128 * @ndlp: pointer to a node-list data structure.
129 * @did: destination identifier.
130 * @elscmd: the ELS command code.
132 * This routine is used for allocating a lpfc-IOCB data structure from
133 * the driver lpfc-IOCB free-list and prepare the IOCB with the parameters
134 * passed into the routine for discovery state machine to issue an Extended
135 * Link Service (ELS) commands. It is a generic lpfc-IOCB allocation
136 * and preparation routine that is used by all the discovery state machine
137 * routines and the ELS command-specific fields will be later set up by
138 * the individual discovery machine routines after calling this routine
139 * allocating and preparing a generic IOCB data structure. It fills in the
140 * Buffer Descriptor Entries (BDEs), allocates buffers for both command
141 * payload and response payload (if expected). The reference count on the
142 * ndlp is incremented by 1 and the reference to the ndlp is put into
143 * context1 of the IOCB data structure for this IOCB to hold the ndlp
144 * reference for the command's callback function to access later.
147 * Pointer to the newly allocated/prepared els iocb data structure
148 * NULL - when els iocb data structure allocation/preparation failed
151 lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp,
152 uint16_t cmdSize, uint8_t retry,
153 struct lpfc_nodelist *ndlp, uint32_t did,
156 struct lpfc_hba *phba = vport->phba;
157 struct lpfc_iocbq *elsiocb;
158 struct lpfc_dmabuf *pcmd, *prsp, *pbuflist;
159 struct ulp_bde64 *bpl;
163 if (!lpfc_is_link_up(phba))
166 /* Allocate buffer for command iocb */
167 elsiocb = lpfc_sli_get_iocbq(phba);
173 * If this command is for fabric controller and HBA running
174 * in FIP mode send FLOGI, FDISC and LOGO as FIP frames.
176 if ((did == Fabric_DID) &&
177 (phba->hba_flag & HBA_FIP_SUPPORT) &&
178 ((elscmd == ELS_CMD_FLOGI) ||
179 (elscmd == ELS_CMD_FDISC) ||
180 (elscmd == ELS_CMD_LOGO)))
183 elsiocb->iocb_flag |=
184 ((LPFC_ELS_ID_FLOGI << LPFC_FIP_ELS_ID_SHIFT)
185 & LPFC_FIP_ELS_ID_MASK);
188 elsiocb->iocb_flag |=
189 ((LPFC_ELS_ID_FDISC << LPFC_FIP_ELS_ID_SHIFT)
190 & LPFC_FIP_ELS_ID_MASK);
193 elsiocb->iocb_flag |=
194 ((LPFC_ELS_ID_LOGO << LPFC_FIP_ELS_ID_SHIFT)
195 & LPFC_FIP_ELS_ID_MASK);
199 elsiocb->iocb_flag &= ~LPFC_FIP_ELS_ID_MASK;
201 icmd = &elsiocb->iocb;
203 /* fill in BDEs for command */
204 /* Allocate buffer for command payload */
205 pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
207 pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys);
208 if (!pcmd || !pcmd->virt)
209 goto els_iocb_free_pcmb_exit;
211 INIT_LIST_HEAD(&pcmd->list);
213 /* Allocate buffer for response payload */
215 prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
217 prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
219 if (!prsp || !prsp->virt)
220 goto els_iocb_free_prsp_exit;
221 INIT_LIST_HEAD(&prsp->list);
225 /* Allocate buffer for Buffer ptr list */
226 pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
228 pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
230 if (!pbuflist || !pbuflist->virt)
231 goto els_iocb_free_pbuf_exit;
233 INIT_LIST_HEAD(&pbuflist->list);
236 icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
237 icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
238 icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
239 icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64));
241 icmd->un.elsreq64.remoteID = did; /* DID */
242 icmd->ulpCommand = CMD_ELS_REQUEST64_CR;
243 if (elscmd == ELS_CMD_FLOGI)
244 icmd->ulpTimeout = FF_DEF_RATOV * 2;
245 else if (elscmd == ELS_CMD_LOGO)
246 icmd->ulpTimeout = phba->fc_ratov;
248 icmd->ulpTimeout = phba->fc_ratov * 2;
250 icmd->un.xseq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
251 icmd->un.xseq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
252 icmd->un.xseq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
253 icmd->un.xseq64.bdl.bdeSize = sizeof(struct ulp_bde64);
254 icmd->un.xseq64.xmit_els_remoteID = did; /* DID */
255 icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX;
257 icmd->ulpBdeCount = 1;
259 icmd->ulpClass = CLASS3;
262 * If we have NPIV enabled, we want to send ELS traffic by VPI.
263 * For SLI4, since the driver controls VPIs we also want to include
264 * all ELS pt2pt protocol traffic as well.
266 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) ||
267 ((phba->sli_rev == LPFC_SLI_REV4) &&
268 (vport->fc_flag & FC_PT2PT))) {
271 icmd->un.elsreq64.myID = vport->fc_myDID;
273 /* For ELS_REQUEST64_CR, use the VPI by default */
274 icmd->ulpContext = phba->vpi_ids[vport->vpi];
278 /* The CT field must be 0=INVALID_RPI for the ECHO cmd */
279 if (elscmd == ELS_CMD_ECHO)
280 icmd->ulpCt_l = 0; /* context = invalid RPI */
282 icmd->ulpCt_l = 1; /* context = VPI */
285 bpl = (struct ulp_bde64 *) pbuflist->virt;
286 bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys));
287 bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys));
288 bpl->tus.f.bdeSize = cmdSize;
289 bpl->tus.f.bdeFlags = 0;
290 bpl->tus.w = le32_to_cpu(bpl->tus.w);
294 bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys));
295 bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys));
296 bpl->tus.f.bdeSize = FCELSSIZE;
297 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
298 bpl->tus.w = le32_to_cpu(bpl->tus.w);
301 /* prevent preparing iocb with NULL ndlp reference */
302 elsiocb->context1 = lpfc_nlp_get(ndlp);
303 if (!elsiocb->context1)
304 goto els_iocb_free_pbuf_exit;
305 elsiocb->context2 = pcmd;
306 elsiocb->context3 = pbuflist;
307 elsiocb->retry = retry;
308 elsiocb->vport = vport;
309 elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT;
312 list_add(&prsp->list, &pcmd->list);
315 /* Xmit ELS command <elsCmd> to remote NPORT <did> */
316 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
317 "0116 Xmit ELS command x%x to remote "
318 "NPORT x%x I/O tag: x%x, port state:x%x"
320 elscmd, did, elsiocb->iotag,
324 /* Xmit ELS response <elsCmd> to remote NPORT <did> */
325 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
326 "0117 Xmit ELS response x%x to remote "
327 "NPORT x%x I/O tag: x%x, size: x%x "
328 "port_state x%x fc_flag x%x\n",
329 elscmd, ndlp->nlp_DID, elsiocb->iotag,
330 cmdSize, vport->port_state,
335 els_iocb_free_pbuf_exit:
337 lpfc_mbuf_free(phba, prsp->virt, prsp->phys);
340 els_iocb_free_prsp_exit:
341 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
344 els_iocb_free_pcmb_exit:
346 lpfc_sli_release_iocbq(phba, elsiocb);
351 * lpfc_issue_fabric_reglogin - Issue fabric registration login for a vport
352 * @vport: pointer to a host virtual N_Port data structure.
354 * This routine issues a fabric registration login for a @vport. An
355 * active ndlp node with Fabric_DID must already exist for this @vport.
356 * The routine invokes two mailbox commands to carry out fabric registration
357 * login through the HBA firmware: the first mailbox command requests the
358 * HBA to perform link configuration for the @vport; and the second mailbox
359 * command requests the HBA to perform the actual fabric registration login
363 * 0 - successfully issued fabric registration login for @vport
364 * -ENXIO -- failed to issue fabric registration login for @vport
367 lpfc_issue_fabric_reglogin(struct lpfc_vport *vport)
369 struct lpfc_hba *phba = vport->phba;
371 struct lpfc_dmabuf *mp;
372 struct lpfc_nodelist *ndlp;
373 struct serv_parm *sp;
377 sp = &phba->fc_fabparam;
378 ndlp = lpfc_findnode_did(vport, Fabric_DID);
379 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
384 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
390 vport->port_state = LPFC_FABRIC_CFG_LINK;
391 lpfc_config_link(phba, mbox);
392 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
395 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
396 if (rc == MBX_NOT_FINISHED) {
401 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
406 rc = lpfc_reg_rpi(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox,
413 mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login;
415 /* increment the reference count on ndlp to hold reference
416 * for the callback routine.
418 mbox->context2 = lpfc_nlp_get(ndlp);
420 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
421 if (rc == MBX_NOT_FINISHED) {
423 goto fail_issue_reg_login;
428 fail_issue_reg_login:
429 /* decrement the reference count on ndlp just incremented
430 * for the failed mbox command.
433 mp = (struct lpfc_dmabuf *) mbox->context1;
434 lpfc_mbuf_free(phba, mp->virt, mp->phys);
437 mempool_free(mbox, phba->mbox_mem_pool);
440 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
441 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
442 "0249 Cannot issue Register Fabric login: Err %d\n", err);
447 * lpfc_issue_reg_vfi - Register VFI for this vport's fabric login
448 * @vport: pointer to a host virtual N_Port data structure.
450 * This routine issues a REG_VFI mailbox for the vfi, vpi, fcfi triplet for
451 * the @vport. This mailbox command is necessary for SLI4 port only.
454 * 0 - successfully issued REG_VFI for @vport
455 * A failure code otherwise.
458 lpfc_issue_reg_vfi(struct lpfc_vport *vport)
460 struct lpfc_hba *phba = vport->phba;
461 LPFC_MBOXQ_t *mboxq = NULL;
462 struct lpfc_nodelist *ndlp;
463 struct lpfc_dmabuf *dmabuf = NULL;
466 /* move forward in case of SLI4 FC port loopback test and pt2pt mode */
467 if ((phba->sli_rev == LPFC_SLI_REV4) &&
468 !(phba->link_flag & LS_LOOPBACK_MODE) &&
469 !(vport->fc_flag & FC_PT2PT)) {
470 ndlp = lpfc_findnode_did(vport, Fabric_DID);
471 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
477 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
483 /* Supply CSP's only if we are fabric connect or pt-to-pt connect */
484 if ((vport->fc_flag & FC_FABRIC) || (vport->fc_flag & FC_PT2PT)) {
485 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
490 dmabuf->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &dmabuf->phys);
495 memcpy(dmabuf->virt, &phba->fc_fabparam,
496 sizeof(struct serv_parm));
499 vport->port_state = LPFC_FABRIC_CFG_LINK;
501 lpfc_reg_vfi(mboxq, vport, dmabuf->phys);
503 lpfc_reg_vfi(mboxq, vport, 0);
505 mboxq->mbox_cmpl = lpfc_mbx_cmpl_reg_vfi;
506 mboxq->vport = vport;
507 mboxq->context1 = dmabuf;
508 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
509 if (rc == MBX_NOT_FINISHED) {
517 mempool_free(mboxq, phba->mbox_mem_pool);
520 lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys);
524 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
525 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
526 "0289 Issue Register VFI failed: Err %d\n", rc);
531 * lpfc_issue_unreg_vfi - Unregister VFI for this vport's fabric login
532 * @vport: pointer to a host virtual N_Port data structure.
534 * This routine issues a UNREG_VFI mailbox with the vfi, vpi, fcfi triplet for
535 * the @vport. This mailbox command is necessary for SLI4 port only.
538 * 0 - successfully issued REG_VFI for @vport
539 * A failure code otherwise.
542 lpfc_issue_unreg_vfi(struct lpfc_vport *vport)
544 struct lpfc_hba *phba = vport->phba;
545 struct Scsi_Host *shost;
549 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
551 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
552 "2556 UNREG_VFI mbox allocation failed"
553 "HBA state x%x\n", phba->pport->port_state);
557 lpfc_unreg_vfi(mboxq, vport);
558 mboxq->vport = vport;
559 mboxq->mbox_cmpl = lpfc_unregister_vfi_cmpl;
561 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
562 if (rc == MBX_NOT_FINISHED) {
563 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
564 "2557 UNREG_VFI issue mbox failed rc x%x "
566 rc, phba->pport->port_state);
567 mempool_free(mboxq, phba->mbox_mem_pool);
571 shost = lpfc_shost_from_vport(vport);
572 spin_lock_irq(shost->host_lock);
573 vport->fc_flag &= ~FC_VFI_REGISTERED;
574 spin_unlock_irq(shost->host_lock);
579 * lpfc_check_clean_addr_bit - Check whether assigned FCID is clean.
580 * @vport: pointer to a host virtual N_Port data structure.
581 * @sp: pointer to service parameter data structure.
583 * This routine is called from FLOGI/FDISC completion handler functions.
584 * lpfc_check_clean_addr_bit return 1 when FCID/Fabric portname/ Fabric
585 * node nodename is changed in the completion service parameter else return
586 * 0. This function also set flag in the vport data structure to delay
587 * NP_Port discovery after the FLOGI/FDISC completion if Clean address bit
588 * in FLOGI/FDISC response is cleared and FCID/Fabric portname/ Fabric
589 * node nodename is changed in the completion service parameter.
592 * 0 - FCID and Fabric Nodename and Fabric portname is not changed.
593 * 1 - FCID or Fabric Nodename or Fabric portname is changed.
597 lpfc_check_clean_addr_bit(struct lpfc_vport *vport,
598 struct serv_parm *sp)
600 struct lpfc_hba *phba = vport->phba;
601 uint8_t fabric_param_changed = 0;
602 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
604 if ((vport->fc_prevDID != vport->fc_myDID) ||
605 memcmp(&vport->fabric_portname, &sp->portName,
606 sizeof(struct lpfc_name)) ||
607 memcmp(&vport->fabric_nodename, &sp->nodeName,
608 sizeof(struct lpfc_name)) ||
609 (vport->vport_flag & FAWWPN_PARAM_CHG)) {
610 fabric_param_changed = 1;
611 vport->vport_flag &= ~FAWWPN_PARAM_CHG;
614 * Word 1 Bit 31 in common service parameter is overloaded.
615 * Word 1 Bit 31 in FLOGI request is multiple NPort request
616 * Word 1 Bit 31 in FLOGI response is clean address bit
618 * If fabric parameter is changed and clean address bit is
619 * cleared delay nport discovery if
620 * - vport->fc_prevDID != 0 (not initial discovery) OR
621 * - lpfc_delay_discovery module parameter is set.
623 if (fabric_param_changed && !sp->cmn.clean_address_bit &&
624 (vport->fc_prevDID || phba->cfg_delay_discovery)) {
625 spin_lock_irq(shost->host_lock);
626 vport->fc_flag |= FC_DISC_DELAYED;
627 spin_unlock_irq(shost->host_lock);
630 return fabric_param_changed;
635 * lpfc_cmpl_els_flogi_fabric - Completion function for flogi to a fabric port
636 * @vport: pointer to a host virtual N_Port data structure.
637 * @ndlp: pointer to a node-list data structure.
638 * @sp: pointer to service parameter data structure.
639 * @irsp: pointer to the IOCB within the lpfc response IOCB.
641 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
642 * function to handle the completion of a Fabric Login (FLOGI) into a fabric
643 * port in a fabric topology. It properly sets up the parameters to the @ndlp
644 * from the IOCB response. It also check the newly assigned N_Port ID to the
645 * @vport against the previously assigned N_Port ID. If it is different from
646 * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine
647 * is invoked on all the remaining nodes with the @vport to unregister the
648 * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin()
649 * is invoked to register login to the fabric.
652 * 0 - Success (currently, always return 0)
655 lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
656 struct serv_parm *sp, IOCB_t *irsp)
658 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
659 struct lpfc_hba *phba = vport->phba;
660 struct lpfc_nodelist *np;
661 struct lpfc_nodelist *next_np;
662 uint8_t fabric_param_changed;
664 spin_lock_irq(shost->host_lock);
665 vport->fc_flag |= FC_FABRIC;
666 spin_unlock_irq(shost->host_lock);
668 phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
669 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
670 phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
672 phba->fc_edtovResol = sp->cmn.edtovResolution;
673 phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
675 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
676 spin_lock_irq(shost->host_lock);
677 vport->fc_flag |= FC_PUBLIC_LOOP;
678 spin_unlock_irq(shost->host_lock);
681 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
682 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
683 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name));
684 ndlp->nlp_class_sup = 0;
685 if (sp->cls1.classValid)
686 ndlp->nlp_class_sup |= FC_COS_CLASS1;
687 if (sp->cls2.classValid)
688 ndlp->nlp_class_sup |= FC_COS_CLASS2;
689 if (sp->cls3.classValid)
690 ndlp->nlp_class_sup |= FC_COS_CLASS3;
691 if (sp->cls4.classValid)
692 ndlp->nlp_class_sup |= FC_COS_CLASS4;
693 ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
694 sp->cmn.bbRcvSizeLsb;
696 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
697 if (fabric_param_changed) {
698 /* Reset FDMI attribute masks based on config parameter */
699 if (phba->cfg_enable_SmartSAN ||
700 (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) {
701 /* Setup appropriate attribute masks */
702 vport->fdmi_hba_mask = LPFC_FDMI2_HBA_ATTR;
703 if (phba->cfg_enable_SmartSAN)
704 vport->fdmi_port_mask = LPFC_FDMI2_SMART_ATTR;
706 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
708 vport->fdmi_hba_mask = 0;
709 vport->fdmi_port_mask = 0;
713 memcpy(&vport->fabric_portname, &sp->portName,
714 sizeof(struct lpfc_name));
715 memcpy(&vport->fabric_nodename, &sp->nodeName,
716 sizeof(struct lpfc_name));
717 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
719 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
720 if (sp->cmn.response_multiple_NPort) {
721 lpfc_printf_vlog(vport, KERN_WARNING,
723 "1816 FLOGI NPIV supported, "
724 "response data 0x%x\n",
725 sp->cmn.response_multiple_NPort);
726 spin_lock_irq(&phba->hbalock);
727 phba->link_flag |= LS_NPIV_FAB_SUPPORTED;
728 spin_unlock_irq(&phba->hbalock);
730 /* Because we asked f/w for NPIV it still expects us
731 to call reg_vnpid atleast for the physcial host */
732 lpfc_printf_vlog(vport, KERN_WARNING,
734 "1817 Fabric does not support NPIV "
735 "- configuring single port mode.\n");
736 spin_lock_irq(&phba->hbalock);
737 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
738 spin_unlock_irq(&phba->hbalock);
743 * For FC we need to do some special processing because of the SLI
744 * Port's default settings of the Common Service Parameters.
746 if ((phba->sli_rev == LPFC_SLI_REV4) &&
747 (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC)) {
748 /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */
749 if (fabric_param_changed)
750 lpfc_unregister_fcf_prep(phba);
752 /* This should just update the VFI CSPs*/
753 if (vport->fc_flag & FC_VFI_REGISTERED)
754 lpfc_issue_reg_vfi(vport);
757 if (fabric_param_changed &&
758 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
760 /* If our NportID changed, we need to ensure all
761 * remaining NPORTs get unreg_login'ed.
763 list_for_each_entry_safe(np, next_np,
764 &vport->fc_nodes, nlp_listp) {
765 if (!NLP_CHK_NODE_ACT(np))
767 if ((np->nlp_state != NLP_STE_NPR_NODE) ||
768 !(np->nlp_flag & NLP_NPR_ADISC))
770 spin_lock_irq(shost->host_lock);
771 np->nlp_flag &= ~NLP_NPR_ADISC;
772 spin_unlock_irq(shost->host_lock);
773 lpfc_unreg_rpi(vport, np);
775 lpfc_cleanup_pending_mbox(vport);
777 if (phba->sli_rev == LPFC_SLI_REV4) {
778 lpfc_sli4_unreg_all_rpis(vport);
779 lpfc_mbx_unreg_vpi(vport);
780 spin_lock_irq(shost->host_lock);
781 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
782 spin_unlock_irq(shost->host_lock);
786 * For SLI3 and SLI4, the VPI needs to be reregistered in
787 * response to this fabric parameter change event.
789 spin_lock_irq(shost->host_lock);
790 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
791 spin_unlock_irq(shost->host_lock);
792 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
793 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
795 * Driver needs to re-reg VPI in order for f/w
796 * to update the MAC address.
798 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
799 lpfc_register_new_vport(phba, vport, ndlp);
803 if (phba->sli_rev < LPFC_SLI_REV4) {
804 lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
805 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED &&
806 vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
807 lpfc_register_new_vport(phba, vport, ndlp);
809 lpfc_issue_fabric_reglogin(vport);
811 ndlp->nlp_type |= NLP_FABRIC;
812 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
813 if ((!(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) &&
814 (vport->vpi_state & LPFC_VPI_REGISTERED)) {
815 lpfc_start_fdiscs(phba);
816 lpfc_do_scr_ns_plogi(phba, vport);
817 } else if (vport->fc_flag & FC_VFI_REGISTERED)
818 lpfc_issue_init_vpi(vport);
820 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
821 "3135 Need register VFI: (x%x/%x)\n",
822 vport->fc_prevDID, vport->fc_myDID);
823 lpfc_issue_reg_vfi(vport);
830 * lpfc_cmpl_els_flogi_nport - Completion function for flogi to an N_Port
831 * @vport: pointer to a host virtual N_Port data structure.
832 * @ndlp: pointer to a node-list data structure.
833 * @sp: pointer to service parameter data structure.
835 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
836 * function to handle the completion of a Fabric Login (FLOGI) into an N_Port
837 * in a point-to-point topology. First, the @vport's N_Port Name is compared
838 * with the received N_Port Name: if the @vport's N_Port Name is greater than
839 * the received N_Port Name lexicographically, this node shall assign local
840 * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and
841 * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise,
842 * this node shall just wait for the remote node to issue PLOGI and assign
850 lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
851 struct serv_parm *sp)
853 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
854 struct lpfc_hba *phba = vport->phba;
858 spin_lock_irq(shost->host_lock);
859 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
860 vport->fc_flag |= FC_PT2PT;
861 spin_unlock_irq(shost->host_lock);
863 /* If we are pt2pt with another NPort, force NPIV off! */
864 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
866 /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */
867 if ((phba->sli_rev == LPFC_SLI_REV4) && phba->fc_topology_changed) {
868 lpfc_unregister_fcf_prep(phba);
870 spin_lock_irq(shost->host_lock);
871 vport->fc_flag &= ~FC_VFI_REGISTERED;
872 spin_unlock_irq(shost->host_lock);
873 phba->fc_topology_changed = 0;
876 rc = memcmp(&vport->fc_portname, &sp->portName,
877 sizeof(vport->fc_portname));
880 /* This side will initiate the PLOGI */
881 spin_lock_irq(shost->host_lock);
882 vport->fc_flag |= FC_PT2PT_PLOGI;
883 spin_unlock_irq(shost->host_lock);
886 * N_Port ID cannot be 0, set our Id to LocalID
887 * the other side will be RemoteID.
892 vport->fc_myDID = PT2PT_LocalID;
894 /* Decrement ndlp reference count indicating that ndlp can be
895 * safely released when other references to it are done.
899 ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
902 * Cannot find existing Fabric ndlp, so allocate a
905 ndlp = lpfc_nlp_init(vport, PT2PT_RemoteID);
908 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
909 ndlp = lpfc_enable_node(vport, ndlp,
910 NLP_STE_UNUSED_NODE);
915 memcpy(&ndlp->nlp_portname, &sp->portName,
916 sizeof(struct lpfc_name));
917 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
918 sizeof(struct lpfc_name));
919 /* Set state will put ndlp onto node list if not already done */
920 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
921 spin_lock_irq(shost->host_lock);
922 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
923 spin_unlock_irq(shost->host_lock);
925 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
929 lpfc_config_link(phba, mbox);
931 mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link;
933 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
934 if (rc == MBX_NOT_FINISHED) {
935 mempool_free(mbox, phba->mbox_mem_pool);
939 /* This side will wait for the PLOGI, decrement ndlp reference
940 * count indicating that ndlp can be released when other
941 * references to it are done.
945 /* Start discovery - this should just do CLEAR_LA */
946 lpfc_disc_start(vport);
955 * lpfc_cmpl_els_flogi - Completion callback function for flogi
956 * @phba: pointer to lpfc hba data structure.
957 * @cmdiocb: pointer to lpfc command iocb data structure.
958 * @rspiocb: pointer to lpfc response iocb data structure.
960 * This routine is the top-level completion callback function for issuing
961 * a Fabric Login (FLOGI) command. If the response IOCB reported error,
962 * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If
963 * retry has been made (either immediately or delayed with lpfc_els_retry()
964 * returning 1), the command IOCB will be released and function returned.
965 * If the retry attempt has been given up (possibly reach the maximum
966 * number of retries), one additional decrement of ndlp reference shall be
967 * invoked before going out after releasing the command IOCB. This will
968 * actually release the remote node (Note, lpfc_els_free_iocb() will also
969 * invoke one decrement of ndlp reference count). If no error reported in
970 * the IOCB status, the command Port ID field is used to determine whether
971 * this is a point-to-point topology or a fabric topology: if the Port ID
972 * field is assigned, it is a fabric topology; otherwise, it is a
973 * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or
974 * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the
975 * specific topology completion conditions.
978 lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
979 struct lpfc_iocbq *rspiocb)
981 struct lpfc_vport *vport = cmdiocb->vport;
982 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
983 IOCB_t *irsp = &rspiocb->iocb;
984 struct lpfc_nodelist *ndlp = cmdiocb->context1;
985 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
986 struct serv_parm *sp;
990 /* Check to see if link went down during discovery */
991 if (lpfc_els_chk_latt(vport)) {
992 /* One additional decrement on node reference count to
993 * trigger the release of the node
999 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1000 "FLOGI cmpl: status:x%x/x%x state:x%x",
1001 irsp->ulpStatus, irsp->un.ulpWord[4],
1004 if (irsp->ulpStatus) {
1006 * In case of FIP mode, perform roundrobin FCF failover
1007 * due to new FCF discovery
1009 if ((phba->hba_flag & HBA_FIP_SUPPORT) &&
1010 (phba->fcf.fcf_flag & FCF_DISCOVERY)) {
1011 if (phba->link_state < LPFC_LINK_UP)
1012 goto stop_rr_fcf_flogi;
1013 if ((phba->fcoe_cvl_eventtag_attn ==
1014 phba->fcoe_cvl_eventtag) &&
1015 (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
1016 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1018 goto stop_rr_fcf_flogi;
1020 phba->fcoe_cvl_eventtag_attn =
1021 phba->fcoe_cvl_eventtag;
1022 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
1023 "2611 FLOGI failed on FCF (x%x), "
1024 "status:x%x/x%x, tmo:x%x, perform "
1025 "roundrobin FCF failover\n",
1026 phba->fcf.current_rec.fcf_indx,
1027 irsp->ulpStatus, irsp->un.ulpWord[4],
1029 lpfc_sli4_set_fcf_flogi_fail(phba,
1030 phba->fcf.current_rec.fcf_indx);
1031 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
1032 rc = lpfc_sli4_fcf_rr_next_proc(vport, fcf_index);
1039 if (!(irsp->ulpStatus == IOSTAT_LOCAL_REJECT &&
1040 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1041 IOERR_LOOP_OPEN_FAILURE)))
1042 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1043 "2858 FLOGI failure Status:x%x/x%x "
1044 "TMO:x%x Data x%x x%x\n",
1045 irsp->ulpStatus, irsp->un.ulpWord[4],
1046 irsp->ulpTimeout, phba->hba_flag,
1047 phba->fcf.fcf_flag);
1049 /* Check for retry */
1050 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
1053 /* If this is not a loop open failure, bail out */
1054 if (!(irsp->ulpStatus == IOSTAT_LOCAL_REJECT &&
1055 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1056 IOERR_LOOP_OPEN_FAILURE)))
1059 lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS,
1060 "0150 FLOGI failure Status:x%x/x%x xri x%x TMO:x%x\n",
1061 irsp->ulpStatus, irsp->un.ulpWord[4],
1062 cmdiocb->sli4_xritag, irsp->ulpTimeout);
1064 /* FLOGI failed, so there is no fabric */
1065 spin_lock_irq(shost->host_lock);
1066 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
1067 spin_unlock_irq(shost->host_lock);
1069 /* If private loop, then allow max outstanding els to be
1070 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
1071 * alpa map would take too long otherwise.
1073 if (phba->alpa_map[0] == 0)
1074 vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
1075 if ((phba->sli_rev == LPFC_SLI_REV4) &&
1076 (!(vport->fc_flag & FC_VFI_REGISTERED) ||
1077 (vport->fc_prevDID != vport->fc_myDID) ||
1078 phba->fc_topology_changed)) {
1079 if (vport->fc_flag & FC_VFI_REGISTERED) {
1080 if (phba->fc_topology_changed) {
1081 lpfc_unregister_fcf_prep(phba);
1082 spin_lock_irq(shost->host_lock);
1083 vport->fc_flag &= ~FC_VFI_REGISTERED;
1084 spin_unlock_irq(shost->host_lock);
1085 phba->fc_topology_changed = 0;
1087 lpfc_sli4_unreg_all_rpis(vport);
1091 /* Do not register VFI if the driver aborted FLOGI */
1092 if (!lpfc_error_lost_link(irsp))
1093 lpfc_issue_reg_vfi(vport);
1099 spin_lock_irq(shost->host_lock);
1100 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
1101 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
1102 spin_unlock_irq(shost->host_lock);
1105 * The FLogI succeeded. Sync the data for the CPU before
1108 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
1111 sp = prsp->virt + sizeof(uint32_t);
1113 /* FLOGI completes successfully */
1114 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1115 "0101 FLOGI completes successfully, I/O tag:x%x, "
1116 "xri x%x Data: x%x x%x x%x x%x x%x %x\n",
1117 cmdiocb->iotag, cmdiocb->sli4_xritag,
1118 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
1119 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution,
1120 vport->port_state, vport->fc_flag);
1122 if (vport->port_state == LPFC_FLOGI) {
1124 * If Common Service Parameters indicate Nport
1125 * we are point to point, if Fport we are Fabric.
1128 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
1129 else if (!(phba->hba_flag & HBA_FCOE_MODE))
1130 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
1132 lpfc_printf_vlog(vport, KERN_ERR,
1134 "2831 FLOGI response with cleared Fabric "
1135 "bit fcf_index 0x%x "
1136 "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x "
1138 "%02x%02x%02x%02x%02x%02x%02x%02x\n",
1139 phba->fcf.current_rec.fcf_indx,
1140 phba->fcf.current_rec.switch_name[0],
1141 phba->fcf.current_rec.switch_name[1],
1142 phba->fcf.current_rec.switch_name[2],
1143 phba->fcf.current_rec.switch_name[3],
1144 phba->fcf.current_rec.switch_name[4],
1145 phba->fcf.current_rec.switch_name[5],
1146 phba->fcf.current_rec.switch_name[6],
1147 phba->fcf.current_rec.switch_name[7],
1148 phba->fcf.current_rec.fabric_name[0],
1149 phba->fcf.current_rec.fabric_name[1],
1150 phba->fcf.current_rec.fabric_name[2],
1151 phba->fcf.current_rec.fabric_name[3],
1152 phba->fcf.current_rec.fabric_name[4],
1153 phba->fcf.current_rec.fabric_name[5],
1154 phba->fcf.current_rec.fabric_name[6],
1155 phba->fcf.current_rec.fabric_name[7]);
1157 spin_lock_irq(&phba->hbalock);
1158 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
1159 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
1160 spin_unlock_irq(&phba->hbalock);
1161 phba->fcf.fcf_redisc_attempted = 0; /* reset */
1165 /* Mark the FCF discovery process done */
1166 if (phba->hba_flag & HBA_FIP_SUPPORT)
1167 lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP |
1169 "2769 FLOGI to FCF (x%x) "
1170 "completed successfully\n",
1171 phba->fcf.current_rec.fcf_indx);
1172 spin_lock_irq(&phba->hbalock);
1173 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
1174 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
1175 spin_unlock_irq(&phba->hbalock);
1176 phba->fcf.fcf_redisc_attempted = 0; /* reset */
1179 } else if (vport->port_state > LPFC_FLOGI &&
1180 vport->fc_flag & FC_PT2PT) {
1182 * In a p2p topology, it is possible that discovery has
1183 * already progressed, and this completion can be ignored.
1184 * Recheck the indicated topology.
1191 spin_lock_irq(&phba->hbalock);
1192 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
1193 spin_unlock_irq(&phba->hbalock);
1197 if (!lpfc_error_lost_link(irsp)) {
1198 /* FLOGI failed, so just use loop map to make discovery list */
1199 lpfc_disc_list_loopmap(vport);
1201 /* Start discovery */
1202 lpfc_disc_start(vport);
1203 } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
1204 (((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
1205 IOERR_SLI_ABORTED) &&
1206 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
1207 IOERR_SLI_DOWN))) &&
1208 (phba->link_state != LPFC_CLEAR_LA)) {
1209 /* If FLOGI failed enable link interrupt. */
1210 lpfc_issue_clear_la(phba, vport);
1213 lpfc_els_free_iocb(phba, cmdiocb);
1217 * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport
1218 * @vport: pointer to a host virtual N_Port data structure.
1219 * @ndlp: pointer to a node-list data structure.
1220 * @retry: number of retries to the command IOCB.
1222 * This routine issues a Fabric Login (FLOGI) Request ELS command
1223 * for a @vport. The initiator service parameters are put into the payload
1224 * of the FLOGI Request IOCB and the top-level callback function pointer
1225 * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
1226 * function field. The lpfc_issue_fabric_iocb routine is invoked to send
1227 * out FLOGI ELS command with one outstanding fabric IOCB at a time.
1229 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1230 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1231 * will be stored into the context1 field of the IOCB for the completion
1232 * callback function to the FLOGI ELS command.
1235 * 0 - successfully issued flogi iocb for @vport
1236 * 1 - failed to issue flogi iocb for @vport
1239 lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1242 struct lpfc_hba *phba = vport->phba;
1243 struct serv_parm *sp;
1245 struct lpfc_iocbq *elsiocb;
1251 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
1252 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1253 ndlp->nlp_DID, ELS_CMD_FLOGI);
1258 icmd = &elsiocb->iocb;
1259 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1261 /* For FLOGI request, remainder of payload is service parameters */
1262 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
1263 pcmd += sizeof(uint32_t);
1264 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
1265 sp = (struct serv_parm *) pcmd;
1267 /* Setup CSPs accordingly for Fabric */
1268 sp->cmn.e_d_tov = 0;
1269 sp->cmn.w2.r_a_tov = 0;
1270 sp->cmn.virtual_fabric_support = 0;
1271 sp->cls1.classValid = 0;
1272 if (sp->cmn.fcphLow < FC_PH3)
1273 sp->cmn.fcphLow = FC_PH3;
1274 if (sp->cmn.fcphHigh < FC_PH3)
1275 sp->cmn.fcphHigh = FC_PH3;
1277 if (phba->sli_rev == LPFC_SLI_REV4) {
1278 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
1279 LPFC_SLI_INTF_IF_TYPE_0) {
1280 elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1);
1281 elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1);
1282 /* FLOGI needs to be 3 for WQE FCFI */
1283 /* Set the fcfi to the fcfi we registered with */
1284 elsiocb->iocb.ulpContext = phba->fcf.fcfi;
1286 /* Can't do SLI4 class2 without support sequence coalescing */
1287 sp->cls2.classValid = 0;
1288 sp->cls2.seqDelivery = 0;
1290 /* Historical, setting sequential-delivery bit for SLI3 */
1291 sp->cls2.seqDelivery = (sp->cls2.classValid) ? 1 : 0;
1292 sp->cls3.seqDelivery = (sp->cls3.classValid) ? 1 : 0;
1293 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
1294 sp->cmn.request_multiple_Nport = 1;
1295 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
1299 sp->cmn.request_multiple_Nport = 0;
1302 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
1303 icmd->un.elsreq64.myID = 0;
1304 icmd->un.elsreq64.fl = 1;
1307 tmo = phba->fc_ratov;
1308 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
1309 lpfc_set_disctmo(vport);
1310 phba->fc_ratov = tmo;
1312 phba->fc_stat.elsXmitFLOGI++;
1313 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
1315 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1316 "Issue FLOGI: opt:x%x",
1317 phba->sli3_options, 0, 0);
1319 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
1320 if (rc == IOCB_ERROR) {
1321 lpfc_els_free_iocb(phba, elsiocb);
1328 * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs
1329 * @phba: pointer to lpfc hba data structure.
1331 * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
1332 * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
1333 * list and issues an abort IOCB commond on each outstanding IOCB that
1334 * contains a active Fabric_DID ndlp. Note that this function is to issue
1335 * the abort IOCB command on all the outstanding IOCBs, thus when this
1336 * function returns, it does not guarantee all the IOCBs are actually aborted.
1339 * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0)
1342 lpfc_els_abort_flogi(struct lpfc_hba *phba)
1344 struct lpfc_sli_ring *pring;
1345 struct lpfc_iocbq *iocb, *next_iocb;
1346 struct lpfc_nodelist *ndlp;
1349 /* Abort outstanding I/O on NPort <nlp_DID> */
1350 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
1351 "0201 Abort outstanding I/O on NPort x%x\n",
1354 pring = lpfc_phba_elsring(phba);
1355 if (unlikely(!pring))
1359 * Check the txcmplq for an iocb that matches the nport the driver is
1362 spin_lock_irq(&phba->hbalock);
1363 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
1365 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR) {
1366 ndlp = (struct lpfc_nodelist *)(iocb->context1);
1367 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
1368 (ndlp->nlp_DID == Fabric_DID))
1369 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
1372 spin_unlock_irq(&phba->hbalock);
1378 * lpfc_initial_flogi - Issue an initial fabric login for a vport
1379 * @vport: pointer to a host virtual N_Port data structure.
1381 * This routine issues an initial Fabric Login (FLOGI) for the @vport
1382 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1383 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1384 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1385 * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
1386 * is then invoked with the @vport and the ndlp to perform the FLOGI for the
1390 * 0 - failed to issue initial flogi for @vport
1391 * 1 - successfully issued initial flogi for @vport
1394 lpfc_initial_flogi(struct lpfc_vport *vport)
1396 struct lpfc_nodelist *ndlp;
1398 vport->port_state = LPFC_FLOGI;
1399 lpfc_set_disctmo(vport);
1401 /* First look for the Fabric ndlp */
1402 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1404 /* Cannot find existing Fabric ndlp, so allocate a new one */
1405 ndlp = lpfc_nlp_init(vport, Fabric_DID);
1408 /* Set the node type */
1409 ndlp->nlp_type |= NLP_FABRIC;
1410 /* Put ndlp onto node list */
1411 lpfc_enqueue_node(vport, ndlp);
1412 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1413 /* re-setup ndlp without removing from node list */
1414 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1419 if (lpfc_issue_els_flogi(vport, ndlp, 0)) {
1420 /* This decrement of reference count to node shall kick off
1421 * the release of the node.
1430 * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport
1431 * @vport: pointer to a host virtual N_Port data structure.
1433 * This routine issues an initial Fabric Discover (FDISC) for the @vport
1434 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1435 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1436 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1437 * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
1438 * is then invoked with the @vport and the ndlp to perform the FDISC for the
1442 * 0 - failed to issue initial fdisc for @vport
1443 * 1 - successfully issued initial fdisc for @vport
1446 lpfc_initial_fdisc(struct lpfc_vport *vport)
1448 struct lpfc_nodelist *ndlp;
1450 /* First look for the Fabric ndlp */
1451 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1453 /* Cannot find existing Fabric ndlp, so allocate a new one */
1454 ndlp = lpfc_nlp_init(vport, Fabric_DID);
1457 /* Put ndlp onto node list */
1458 lpfc_enqueue_node(vport, ndlp);
1459 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1460 /* re-setup ndlp without removing from node list */
1461 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1466 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
1467 /* decrement node reference count to trigger the release of
1477 * lpfc_more_plogi - Check and issue remaining plogis for a vport
1478 * @vport: pointer to a host virtual N_Port data structure.
1480 * This routine checks whether there are more remaining Port Logins
1481 * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
1482 * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
1483 * to issue ELS PLOGIs up to the configured discover threads with the
1484 * @vport (@vport->cfg_discovery_threads). The function also decrement
1485 * the @vport's num_disc_node by 1 if it is not already 0.
1488 lpfc_more_plogi(struct lpfc_vport *vport)
1490 if (vport->num_disc_nodes)
1491 vport->num_disc_nodes--;
1493 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
1494 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1495 "0232 Continue discovery with %d PLOGIs to go "
1496 "Data: x%x x%x x%x\n",
1497 vport->num_disc_nodes, vport->fc_plogi_cnt,
1498 vport->fc_flag, vport->port_state);
1499 /* Check to see if there are more PLOGIs to be sent */
1500 if (vport->fc_flag & FC_NLP_MORE)
1501 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
1502 lpfc_els_disc_plogi(vport);
1508 * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp
1509 * @phba: pointer to lpfc hba data structure.
1510 * @prsp: pointer to response IOCB payload.
1511 * @ndlp: pointer to a node-list data structure.
1513 * This routine checks and indicates whether the WWPN of an N_Port, retrieved
1514 * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
1515 * The following cases are considered N_Port confirmed:
1516 * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
1517 * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
1518 * it does not have WWPN assigned either. If the WWPN is confirmed, the
1519 * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
1520 * 1) if there is a node on vport list other than the @ndlp with the same
1521 * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
1522 * on that node to release the RPI associated with the node; 2) if there is
1523 * no node found on vport list with the same WWPN of the N_Port PLOGI logged
1524 * into, a new node shall be allocated (or activated). In either case, the
1525 * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
1526 * be released and the new_ndlp shall be put on to the vport node list and
1527 * its pointer returned as the confirmed node.
1529 * Note that before the @ndlp got "released", the keepDID from not-matching
1530 * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
1531 * of the @ndlp. This is because the release of @ndlp is actually to put it
1532 * into an inactive state on the vport node list and the vport node list
1533 * management algorithm does not allow two node with a same DID.
1536 * pointer to the PLOGI N_Port @ndlp
1538 static struct lpfc_nodelist *
1539 lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
1540 struct lpfc_nodelist *ndlp)
1542 struct lpfc_vport *vport = ndlp->vport;
1543 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1544 struct lpfc_nodelist *new_ndlp;
1545 struct lpfc_rport_data *rdata;
1546 struct fc_rport *rport;
1547 struct serv_parm *sp;
1548 uint8_t name[sizeof(struct lpfc_name)];
1549 uint32_t rc, keepDID = 0, keep_nlp_flag = 0;
1550 uint16_t keep_nlp_state;
1551 struct lpfc_nvme_rport *keep_nrport = NULL;
1554 unsigned long *active_rrqs_xri_bitmap = NULL;
1556 /* Fabric nodes can have the same WWPN so we don't bother searching
1557 * by WWPN. Just return the ndlp that was given to us.
1559 if (ndlp->nlp_type & NLP_FABRIC)
1562 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
1563 memset(name, 0, sizeof(struct lpfc_name));
1565 /* Now we find out if the NPort we are logging into, matches the WWPN
1566 * we have for that ndlp. If not, we have some work to do.
1568 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
1570 /* return immediately if the WWPN matches ndlp */
1571 if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp))
1574 if (phba->sli_rev == LPFC_SLI_REV4) {
1575 active_rrqs_xri_bitmap = mempool_alloc(phba->active_rrq_pool,
1577 if (active_rrqs_xri_bitmap)
1578 memset(active_rrqs_xri_bitmap, 0,
1579 phba->cfg_rrq_xri_bitmap_sz);
1582 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_NODE,
1583 "3178 PLOGI confirm: ndlp x%x x%x x%x: "
1584 "new_ndlp x%x x%x x%x\n",
1585 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_fc4_type,
1586 (new_ndlp ? new_ndlp->nlp_DID : 0),
1587 (new_ndlp ? new_ndlp->nlp_flag : 0),
1588 (new_ndlp ? new_ndlp->nlp_fc4_type : 0));
1591 rc = memcmp(&ndlp->nlp_portname, name,
1592 sizeof(struct lpfc_name));
1594 if (active_rrqs_xri_bitmap)
1595 mempool_free(active_rrqs_xri_bitmap,
1596 phba->active_rrq_pool);
1599 new_ndlp = lpfc_nlp_init(vport, ndlp->nlp_DID);
1601 if (active_rrqs_xri_bitmap)
1602 mempool_free(active_rrqs_xri_bitmap,
1603 phba->active_rrq_pool);
1606 } else if (!NLP_CHK_NODE_ACT(new_ndlp)) {
1607 rc = memcmp(&ndlp->nlp_portname, name,
1608 sizeof(struct lpfc_name));
1610 if (active_rrqs_xri_bitmap)
1611 mempool_free(active_rrqs_xri_bitmap,
1612 phba->active_rrq_pool);
1615 new_ndlp = lpfc_enable_node(vport, new_ndlp,
1616 NLP_STE_UNUSED_NODE);
1618 if (active_rrqs_xri_bitmap)
1619 mempool_free(active_rrqs_xri_bitmap,
1620 phba->active_rrq_pool);
1623 keepDID = new_ndlp->nlp_DID;
1624 if ((phba->sli_rev == LPFC_SLI_REV4) && active_rrqs_xri_bitmap)
1625 memcpy(active_rrqs_xri_bitmap,
1626 new_ndlp->active_rrqs_xri_bitmap,
1627 phba->cfg_rrq_xri_bitmap_sz);
1629 keepDID = new_ndlp->nlp_DID;
1630 if (phba->sli_rev == LPFC_SLI_REV4 &&
1631 active_rrqs_xri_bitmap)
1632 memcpy(active_rrqs_xri_bitmap,
1633 new_ndlp->active_rrqs_xri_bitmap,
1634 phba->cfg_rrq_xri_bitmap_sz);
1637 /* At this point in this routine, we know new_ndlp will be
1638 * returned. however, any previous GID_FTs that were done
1639 * would have updated nlp_fc4_type in ndlp, so we must ensure
1640 * new_ndlp has the right value.
1642 if (vport->fc_flag & FC_FABRIC)
1643 new_ndlp->nlp_fc4_type = ndlp->nlp_fc4_type;
1645 lpfc_unreg_rpi(vport, new_ndlp);
1646 new_ndlp->nlp_DID = ndlp->nlp_DID;
1647 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
1648 if (phba->sli_rev == LPFC_SLI_REV4)
1649 memcpy(new_ndlp->active_rrqs_xri_bitmap,
1650 ndlp->active_rrqs_xri_bitmap,
1651 phba->cfg_rrq_xri_bitmap_sz);
1653 spin_lock_irq(shost->host_lock);
1654 keep_nlp_flag = new_ndlp->nlp_flag;
1655 new_ndlp->nlp_flag = ndlp->nlp_flag;
1656 ndlp->nlp_flag = keep_nlp_flag;
1657 spin_unlock_irq(shost->host_lock);
1659 /* Set nlp_states accordingly */
1660 keep_nlp_state = new_ndlp->nlp_state;
1661 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
1663 /* interchange the nvme remoteport structs */
1664 keep_nrport = new_ndlp->nrport;
1665 new_ndlp->nrport = ndlp->nrport;
1667 /* Move this back to NPR state */
1668 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
1669 /* The new_ndlp is replacing ndlp totally, so we need
1670 * to put ndlp on UNUSED list and try to free it.
1672 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1673 "3179 PLOGI confirm NEW: %x %x\n",
1674 new_ndlp->nlp_DID, keepDID);
1676 /* Fix up the rport accordingly */
1677 rport = ndlp->rport;
1679 rdata = rport->dd_data;
1680 if (rdata->pnode == ndlp) {
1681 /* break the link before dropping the ref */
1684 rdata->pnode = lpfc_nlp_get(new_ndlp);
1685 new_ndlp->rport = rport;
1687 new_ndlp->nlp_type = ndlp->nlp_type;
1690 /* Fix up the nvme rport */
1692 ndlp->nrport = NULL;
1696 /* We shall actually free the ndlp with both nlp_DID and
1697 * nlp_portname fields equals 0 to avoid any ndlp on the
1698 * nodelist never to be used.
1700 if (ndlp->nlp_DID == 0) {
1701 spin_lock_irq(&phba->ndlp_lock);
1702 NLP_SET_FREE_REQ(ndlp);
1703 spin_unlock_irq(&phba->ndlp_lock);
1706 /* Two ndlps cannot have the same did on the nodelist */
1707 ndlp->nlp_DID = keepDID;
1708 lpfc_nlp_set_state(vport, ndlp, keep_nlp_state);
1709 if (phba->sli_rev == LPFC_SLI_REV4 &&
1710 active_rrqs_xri_bitmap)
1711 memcpy(ndlp->active_rrqs_xri_bitmap,
1712 active_rrqs_xri_bitmap,
1713 phba->cfg_rrq_xri_bitmap_sz);
1715 if (!NLP_CHK_NODE_ACT(ndlp))
1716 lpfc_drop_node(vport, ndlp);
1719 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1720 "3180 PLOGI confirm SWAP: %x %x\n",
1721 new_ndlp->nlp_DID, keepDID);
1723 lpfc_unreg_rpi(vport, ndlp);
1725 /* Two ndlps cannot have the same did */
1726 ndlp->nlp_DID = keepDID;
1727 if (phba->sli_rev == LPFC_SLI_REV4 &&
1728 active_rrqs_xri_bitmap)
1729 memcpy(ndlp->active_rrqs_xri_bitmap,
1730 active_rrqs_xri_bitmap,
1731 phba->cfg_rrq_xri_bitmap_sz);
1733 /* Since we are switching over to the new_ndlp,
1734 * reset the old ndlp state
1736 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
1737 (ndlp->nlp_state == NLP_STE_MAPPED_NODE))
1738 keep_nlp_state = NLP_STE_NPR_NODE;
1739 lpfc_nlp_set_state(vport, ndlp, keep_nlp_state);
1741 /* Previous ndlp no longer active with nvme host transport.
1742 * Remove reference from earlier registration unless the
1743 * nvme host took care of it.
1747 ndlp->nrport = keep_nrport;
1749 /* Fix up the rport accordingly */
1750 rport = ndlp->rport;
1752 rdata = rport->dd_data;
1753 put_node = rdata->pnode != NULL;
1754 put_rport = ndlp->rport != NULL;
1755 rdata->pnode = NULL;
1760 put_device(&rport->dev);
1763 if (phba->sli_rev == LPFC_SLI_REV4 &&
1764 active_rrqs_xri_bitmap)
1765 mempool_free(active_rrqs_xri_bitmap,
1766 phba->active_rrq_pool);
1768 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_NODE,
1769 "3173 PLOGI confirm exit: new_ndlp x%x x%x x%x\n",
1770 new_ndlp->nlp_DID, new_ndlp->nlp_flag,
1771 new_ndlp->nlp_fc4_type);
1777 * lpfc_end_rscn - Check and handle more rscn for a vport
1778 * @vport: pointer to a host virtual N_Port data structure.
1780 * This routine checks whether more Registration State Change
1781 * Notifications (RSCNs) came in while the discovery state machine was in
1782 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1783 * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1784 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1785 * handling the RSCNs.
1788 lpfc_end_rscn(struct lpfc_vport *vport)
1790 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1792 if (vport->fc_flag & FC_RSCN_MODE) {
1794 * Check to see if more RSCNs came in while we were
1795 * processing this one.
1797 if (vport->fc_rscn_id_cnt ||
1798 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
1799 lpfc_els_handle_rscn(vport);
1801 spin_lock_irq(shost->host_lock);
1802 vport->fc_flag &= ~FC_RSCN_MODE;
1803 spin_unlock_irq(shost->host_lock);
1809 * lpfc_cmpl_els_rrq - Completion handled for els RRQs.
1810 * @phba: pointer to lpfc hba data structure.
1811 * @cmdiocb: pointer to lpfc command iocb data structure.
1812 * @rspiocb: pointer to lpfc response iocb data structure.
1814 * This routine will call the clear rrq function to free the rrq and
1815 * clear the xri's bit in the ndlp's xri_bitmap. If the ndlp does not
1816 * exist then the clear_rrq is still called because the rrq needs to
1821 lpfc_cmpl_els_rrq(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1822 struct lpfc_iocbq *rspiocb)
1824 struct lpfc_vport *vport = cmdiocb->vport;
1826 struct lpfc_nodelist *ndlp;
1827 struct lpfc_node_rrq *rrq;
1829 /* we pass cmdiocb to state machine which needs rspiocb as well */
1830 rrq = cmdiocb->context_un.rrq;
1831 cmdiocb->context_un.rsp_iocb = rspiocb;
1833 irsp = &rspiocb->iocb;
1834 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1835 "RRQ cmpl: status:x%x/x%x did:x%x",
1836 irsp->ulpStatus, irsp->un.ulpWord[4],
1837 irsp->un.elsreq64.remoteID);
1839 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
1840 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || ndlp != rrq->ndlp) {
1841 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1842 "2882 RRQ completes to NPort x%x "
1843 "with no ndlp. Data: x%x x%x x%x\n",
1844 irsp->un.elsreq64.remoteID,
1845 irsp->ulpStatus, irsp->un.ulpWord[4],
1850 /* rrq completes to NPort <nlp_DID> */
1851 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1852 "2880 RRQ completes to NPort x%x "
1853 "Data: x%x x%x x%x x%x x%x\n",
1854 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1855 irsp->ulpTimeout, rrq->xritag, rrq->rxid);
1857 if (irsp->ulpStatus) {
1858 /* Check for retry */
1859 /* RRQ failed Don't print the vport to vport rjts */
1860 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1861 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1862 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1863 (phba)->pport->cfg_log_verbose & LOG_ELS)
1864 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1865 "2881 RRQ failure DID:%06X Status:x%x/x%x\n",
1866 ndlp->nlp_DID, irsp->ulpStatus,
1867 irsp->un.ulpWord[4]);
1871 lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
1872 lpfc_els_free_iocb(phba, cmdiocb);
1876 * lpfc_cmpl_els_plogi - Completion callback function for plogi
1877 * @phba: pointer to lpfc hba data structure.
1878 * @cmdiocb: pointer to lpfc command iocb data structure.
1879 * @rspiocb: pointer to lpfc response iocb data structure.
1881 * This routine is the completion callback function for issuing the Port
1882 * Login (PLOGI) command. For PLOGI completion, there must be an active
1883 * ndlp on the vport node list that matches the remote node ID from the
1884 * PLOGI response IOCB. If such ndlp does not exist, the PLOGI is simply
1885 * ignored and command IOCB released. The PLOGI response IOCB status is
1886 * checked for error conditons. If there is error status reported, PLOGI
1887 * retry shall be attempted by invoking the lpfc_els_retry() routine.
1888 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1889 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1890 * (DSM) is set for this PLOGI completion. Finally, it checks whether
1891 * there are additional N_Port nodes with the vport that need to perform
1892 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
1896 lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1897 struct lpfc_iocbq *rspiocb)
1899 struct lpfc_vport *vport = cmdiocb->vport;
1900 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1902 struct lpfc_nodelist *ndlp;
1903 struct lpfc_dmabuf *prsp;
1906 /* we pass cmdiocb to state machine which needs rspiocb as well */
1907 cmdiocb->context_un.rsp_iocb = rspiocb;
1909 irsp = &rspiocb->iocb;
1910 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1911 "PLOGI cmpl: status:x%x/x%x did:x%x",
1912 irsp->ulpStatus, irsp->un.ulpWord[4],
1913 irsp->un.elsreq64.remoteID);
1915 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
1916 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
1917 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1918 "0136 PLOGI completes to NPort x%x "
1919 "with no ndlp. Data: x%x x%x x%x\n",
1920 irsp->un.elsreq64.remoteID,
1921 irsp->ulpStatus, irsp->un.ulpWord[4],
1926 /* Since ndlp can be freed in the disc state machine, note if this node
1927 * is being used during discovery.
1929 spin_lock_irq(shost->host_lock);
1930 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
1931 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1932 spin_unlock_irq(shost->host_lock);
1935 /* PLOGI completes to NPort <nlp_DID> */
1936 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1937 "0102 PLOGI completes to NPort x%06x "
1938 "Data: x%x x%x x%x x%x x%x\n",
1939 ndlp->nlp_DID, ndlp->nlp_fc4_type,
1940 irsp->ulpStatus, irsp->un.ulpWord[4],
1941 disc, vport->num_disc_nodes);
1943 /* Check to see if link went down during discovery */
1944 if (lpfc_els_chk_latt(vport)) {
1945 spin_lock_irq(shost->host_lock);
1946 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1947 spin_unlock_irq(shost->host_lock);
1951 if (irsp->ulpStatus) {
1952 /* Check for retry */
1953 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1954 /* ELS command is being retried */
1956 spin_lock_irq(shost->host_lock);
1957 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1958 spin_unlock_irq(shost->host_lock);
1962 /* PLOGI failed Don't print the vport to vport rjts */
1963 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1964 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1965 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1966 (phba)->pport->cfg_log_verbose & LOG_ELS)
1967 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1968 "2753 PLOGI failure DID:%06X Status:x%x/x%x\n",
1969 ndlp->nlp_DID, irsp->ulpStatus,
1970 irsp->un.ulpWord[4]);
1971 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1972 if (lpfc_error_lost_link(irsp))
1973 rc = NLP_STE_FREED_NODE;
1975 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1976 NLP_EVT_CMPL_PLOGI);
1978 /* Good status, call state machine */
1979 prsp = list_entry(((struct lpfc_dmabuf *)
1980 cmdiocb->context2)->list.next,
1981 struct lpfc_dmabuf, list);
1982 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
1983 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1984 NLP_EVT_CMPL_PLOGI);
1987 if (disc && vport->num_disc_nodes) {
1988 /* Check to see if there are more PLOGIs to be sent */
1989 lpfc_more_plogi(vport);
1991 if (vport->num_disc_nodes == 0) {
1992 spin_lock_irq(shost->host_lock);
1993 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1994 spin_unlock_irq(shost->host_lock);
1996 lpfc_can_disctmo(vport);
1997 lpfc_end_rscn(vport);
2002 lpfc_els_free_iocb(phba, cmdiocb);
2007 * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
2008 * @vport: pointer to a host virtual N_Port data structure.
2009 * @did: destination port identifier.
2010 * @retry: number of retries to the command IOCB.
2012 * This routine issues a Port Login (PLOGI) command to a remote N_Port
2013 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
2014 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
2015 * This routine constructs the proper feilds of the PLOGI IOCB and invokes
2016 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
2018 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2019 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2020 * will be stored into the context1 field of the IOCB for the completion
2021 * callback function to the PLOGI ELS command.
2024 * 0 - Successfully issued a plogi for @vport
2025 * 1 - failed to issue a plogi for @vport
2028 lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
2030 struct lpfc_hba *phba = vport->phba;
2031 struct Scsi_Host *shost;
2032 struct serv_parm *sp;
2033 struct lpfc_nodelist *ndlp;
2034 struct lpfc_iocbq *elsiocb;
2039 ndlp = lpfc_findnode_did(vport, did);
2040 if (ndlp && !NLP_CHK_NODE_ACT(ndlp))
2043 /* If ndlp is not NULL, we will bump the reference count on it */
2044 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
2045 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
2050 shost = lpfc_shost_from_vport(vport);
2051 spin_lock_irq(shost->host_lock);
2052 ndlp->nlp_flag &= ~NLP_FCP_PRLI_RJT;
2053 spin_unlock_irq(shost->host_lock);
2055 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2057 /* For PLOGI request, remainder of payload is service parameters */
2058 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
2059 pcmd += sizeof(uint32_t);
2060 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
2061 sp = (struct serv_parm *) pcmd;
2064 * If we are a N-port connected to a Fabric, fix-up paramm's so logins
2065 * to device on remote loops work.
2067 if ((vport->fc_flag & FC_FABRIC) && !(vport->fc_flag & FC_PUBLIC_LOOP))
2068 sp->cmn.altBbCredit = 1;
2070 if (sp->cmn.fcphLow < FC_PH_4_3)
2071 sp->cmn.fcphLow = FC_PH_4_3;
2073 if (sp->cmn.fcphHigh < FC_PH3)
2074 sp->cmn.fcphHigh = FC_PH3;
2076 sp->cmn.valid_vendor_ver_level = 0;
2077 memset(sp->un.vendorVersion, 0, sizeof(sp->un.vendorVersion));
2078 sp->cmn.bbRcvSizeMsb &= 0xF;
2080 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2081 "Issue PLOGI: did:x%x",
2084 /* If our firmware supports this feature, convey that
2085 * information to the target using the vendor specific field.
2087 if (phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) {
2088 sp->cmn.valid_vendor_ver_level = 1;
2089 sp->un.vv.vid = cpu_to_be32(LPFC_VV_EMLX_ID);
2090 sp->un.vv.flags = cpu_to_be32(LPFC_VV_SUPPRESS_RSP);
2093 phba->fc_stat.elsXmitPLOGI++;
2094 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
2095 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
2097 if (ret == IOCB_ERROR) {
2098 lpfc_els_free_iocb(phba, elsiocb);
2105 * lpfc_cmpl_els_prli - Completion callback function for prli
2106 * @phba: pointer to lpfc hba data structure.
2107 * @cmdiocb: pointer to lpfc command iocb data structure.
2108 * @rspiocb: pointer to lpfc response iocb data structure.
2110 * This routine is the completion callback function for a Process Login
2111 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
2112 * status. If there is error status reported, PRLI retry shall be attempted
2113 * by invoking the lpfc_els_retry() routine. Otherwise, the state
2114 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
2115 * ndlp to mark the PRLI completion.
2118 lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2119 struct lpfc_iocbq *rspiocb)
2121 struct lpfc_vport *vport = cmdiocb->vport;
2122 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2124 struct lpfc_nodelist *ndlp;
2126 /* we pass cmdiocb to state machine which needs rspiocb as well */
2127 cmdiocb->context_un.rsp_iocb = rspiocb;
2129 irsp = &(rspiocb->iocb);
2130 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2131 spin_lock_irq(shost->host_lock);
2132 ndlp->nlp_flag &= ~NLP_PRLI_SND;
2134 /* Driver supports multiple FC4 types. Counters matter. */
2135 vport->fc_prli_sent--;
2136 ndlp->fc4_prli_sent--;
2137 spin_unlock_irq(shost->host_lock);
2139 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2140 "PRLI cmpl: status:x%x/x%x did:x%x",
2141 irsp->ulpStatus, irsp->un.ulpWord[4],
2144 /* PRLI completes to NPort <nlp_DID> */
2145 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2146 "0103 PRLI completes to NPort x%06x "
2147 "Data: x%x x%x x%x x%x\n",
2148 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2149 vport->num_disc_nodes, ndlp->fc4_prli_sent);
2151 /* Check to see if link went down during discovery */
2152 if (lpfc_els_chk_latt(vport))
2155 if (irsp->ulpStatus) {
2156 /* Check for retry */
2157 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2158 /* ELS command is being retried */
2163 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2164 "2754 PRLI failure DID:%06X Status:x%x/x%x, "
2166 ndlp->nlp_DID, irsp->ulpStatus,
2167 irsp->un.ulpWord[4], ndlp->fc4_prli_sent);
2169 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2170 if (lpfc_error_lost_link(irsp))
2173 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2176 /* Good status, call state machine. However, if another
2177 * PRLI is outstanding, don't call the state machine
2178 * because final disposition to Mapped or Unmapped is
2181 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2185 lpfc_els_free_iocb(phba, cmdiocb);
2190 * lpfc_issue_els_prli - Issue a prli iocb command for a vport
2191 * @vport: pointer to a host virtual N_Port data structure.
2192 * @ndlp: pointer to a node-list data structure.
2193 * @retry: number of retries to the command IOCB.
2195 * This routine issues a Process Login (PRLI) ELS command for the
2196 * @vport. The PRLI service parameters are set up in the payload of the
2197 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
2198 * is put to the IOCB completion callback func field before invoking the
2199 * routine lpfc_sli_issue_iocb() to send out PRLI command.
2201 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2202 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2203 * will be stored into the context1 field of the IOCB for the completion
2204 * callback function to the PRLI ELS command.
2207 * 0 - successfully issued prli iocb command for @vport
2208 * 1 - failed to issue prli iocb command for @vport
2211 lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2214 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2215 struct lpfc_hba *phba = vport->phba;
2217 struct lpfc_nvme_prli *npr_nvme;
2218 struct lpfc_iocbq *elsiocb;
2221 u32 local_nlp_type, elscmd;
2224 * If we are in RSCN mode, the FC4 types supported from a
2225 * previous GFT_ID command may not be accurate. So, if we
2226 * are a NVME Initiator, always look for the possibility of
2227 * the remote NPort beng a NVME Target.
2229 if (phba->sli_rev == LPFC_SLI_REV4 &&
2230 vport->fc_flag & FC_RSCN_MODE &&
2231 vport->nvmei_support)
2232 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
2233 local_nlp_type = ndlp->nlp_fc4_type;
2235 /* This routine will issue 1 or 2 PRLIs, so zero all the ndlp
2236 * fields here before any of them can complete.
2238 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
2239 ndlp->nlp_type &= ~(NLP_NVME_TARGET | NLP_NVME_INITIATOR);
2240 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
2241 ndlp->nlp_flag &= ~NLP_FIRSTBURST;
2242 ndlp->nvme_fb_size = 0;
2245 if (local_nlp_type & NLP_FC4_FCP) {
2246 /* Payload is 4 + 16 = 20 x14 bytes. */
2247 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
2248 elscmd = ELS_CMD_PRLI;
2249 } else if (local_nlp_type & NLP_FC4_NVME) {
2250 /* Payload is 4 + 20 = 24 x18 bytes. */
2251 cmdsize = (sizeof(uint32_t) + sizeof(struct lpfc_nvme_prli));
2252 elscmd = ELS_CMD_NVMEPRLI;
2254 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2255 "3083 Unknown FC_TYPE x%x ndlp x%06x\n",
2256 ndlp->nlp_fc4_type, ndlp->nlp_DID);
2260 /* SLI3 ports don't support NVME. If this rport is a strict NVME
2261 * FC4 type, implicitly LOGO.
2263 if (phba->sli_rev == LPFC_SLI_REV3 &&
2264 ndlp->nlp_fc4_type == NLP_FC4_NVME) {
2265 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2266 "3088 Rport fc4 type 0x%x not supported by SLI3 adapter\n",
2268 lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM);
2272 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2273 ndlp->nlp_DID, elscmd);
2277 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2279 /* For PRLI request, remainder of payload is service parameters */
2280 memset(pcmd, 0, cmdsize);
2282 if (local_nlp_type & NLP_FC4_FCP) {
2283 /* Remainder of payload is FCP PRLI parameter page.
2284 * Note: this data structure is defined as
2285 * BE/LE in the structure definition so no
2286 * byte swap call is made.
2288 *((uint32_t *)(pcmd)) = ELS_CMD_PRLI;
2289 pcmd += sizeof(uint32_t);
2293 * If our firmware version is 3.20 or later,
2294 * set the following bits for FC-TAPE support.
2296 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
2297 npr->ConfmComplAllowed = 1;
2299 npr->TaskRetryIdReq = 1;
2301 npr->estabImagePair = 1;
2302 npr->readXferRdyDis = 1;
2303 if (vport->cfg_first_burst_size)
2304 npr->writeXferRdyDis = 1;
2306 /* For FCP support */
2307 npr->prliType = PRLI_FCP_TYPE;
2308 npr->initiatorFunc = 1;
2309 elsiocb->iocb_flag |= LPFC_PRLI_FCP_REQ;
2311 /* Remove FCP type - processed. */
2312 local_nlp_type &= ~NLP_FC4_FCP;
2313 } else if (local_nlp_type & NLP_FC4_NVME) {
2314 /* Remainder of payload is NVME PRLI parameter page.
2315 * This data structure is the newer definition that
2316 * uses bf macros so a byte swap is required.
2318 *((uint32_t *)(pcmd)) = ELS_CMD_NVMEPRLI;
2319 pcmd += sizeof(uint32_t);
2320 npr_nvme = (struct lpfc_nvme_prli *)pcmd;
2321 bf_set(prli_type_code, npr_nvme, PRLI_NVME_TYPE);
2322 bf_set(prli_estabImagePair, npr_nvme, 0); /* Should be 0 */
2324 /* Only initiators request first burst. */
2325 if ((phba->cfg_nvme_enable_fb) &&
2326 !phba->nvmet_support)
2327 bf_set(prli_fba, npr_nvme, 1);
2329 if (phba->nvmet_support) {
2330 bf_set(prli_tgt, npr_nvme, 1);
2331 bf_set(prli_disc, npr_nvme, 1);
2333 bf_set(prli_init, npr_nvme, 1);
2334 bf_set(prli_conf, npr_nvme, 1);
2337 npr_nvme->word1 = cpu_to_be32(npr_nvme->word1);
2338 npr_nvme->word4 = cpu_to_be32(npr_nvme->word4);
2339 elsiocb->iocb_flag |= LPFC_PRLI_NVME_REQ;
2341 /* Remove NVME type - processed. */
2342 local_nlp_type &= ~NLP_FC4_NVME;
2345 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2346 "Issue PRLI: did:x%x",
2347 ndlp->nlp_DID, 0, 0);
2349 phba->fc_stat.elsXmitPRLI++;
2350 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
2351 spin_lock_irq(shost->host_lock);
2352 ndlp->nlp_flag |= NLP_PRLI_SND;
2354 /* The vport counters are used for lpfc_scan_finished, but
2355 * the ndlp is used to track outstanding PRLIs for different
2358 vport->fc_prli_sent++;
2359 ndlp->fc4_prli_sent++;
2360 spin_unlock_irq(shost->host_lock);
2361 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2363 spin_lock_irq(shost->host_lock);
2364 ndlp->nlp_flag &= ~NLP_PRLI_SND;
2365 spin_unlock_irq(shost->host_lock);
2366 lpfc_els_free_iocb(phba, elsiocb);
2371 /* The driver supports 2 FC4 types. Make sure
2372 * a PRLI is issued for all types before exiting.
2374 if (phba->sli_rev == LPFC_SLI_REV4 &&
2375 local_nlp_type & (NLP_FC4_FCP | NLP_FC4_NVME))
2376 goto send_next_prli;
2382 * lpfc_rscn_disc - Perform rscn discovery for a vport
2383 * @vport: pointer to a host virtual N_Port data structure.
2385 * This routine performs Registration State Change Notification (RSCN)
2386 * discovery for a @vport. If the @vport's node port recovery count is not
2387 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
2388 * the nodes that need recovery. If none of the PLOGI were needed through
2389 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
2390 * invoked to check and handle possible more RSCN came in during the period
2391 * of processing the current ones.
2394 lpfc_rscn_disc(struct lpfc_vport *vport)
2396 lpfc_can_disctmo(vport);
2398 /* RSCN discovery */
2399 /* go thru NPR nodes and issue ELS PLOGIs */
2400 if (vport->fc_npr_cnt)
2401 if (lpfc_els_disc_plogi(vport))
2404 lpfc_end_rscn(vport);
2408 * lpfc_adisc_done - Complete the adisc phase of discovery
2409 * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
2411 * This function is called when the final ADISC is completed during discovery.
2412 * This function handles clearing link attention or issuing reg_vpi depending
2413 * on whether npiv is enabled. This function also kicks off the PLOGI phase of
2415 * This function is called with no locks held.
2418 lpfc_adisc_done(struct lpfc_vport *vport)
2420 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2421 struct lpfc_hba *phba = vport->phba;
2424 * For NPIV, cmpl_reg_vpi will set port_state to READY,
2425 * and continue discovery.
2427 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2428 !(vport->fc_flag & FC_RSCN_MODE) &&
2429 (phba->sli_rev < LPFC_SLI_REV4)) {
2430 /* The ADISCs are complete. Doesn't matter if they
2431 * succeeded or failed because the ADISC completion
2432 * routine guarantees to call the state machine and
2433 * the RPI is either unregistered (failed ADISC response)
2434 * or the RPI is still valid and the node is marked
2435 * mapped for a target. The exchanges should be in the
2436 * correct state. This code is specific to SLI3.
2438 lpfc_issue_clear_la(phba, vport);
2439 lpfc_issue_reg_vpi(phba, vport);
2443 * For SLI2, we need to set port_state to READY
2444 * and continue discovery.
2446 if (vport->port_state < LPFC_VPORT_READY) {
2447 /* If we get here, there is nothing to ADISC */
2448 lpfc_issue_clear_la(phba, vport);
2449 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
2450 vport->num_disc_nodes = 0;
2451 /* go thru NPR list, issue ELS PLOGIs */
2452 if (vport->fc_npr_cnt)
2453 lpfc_els_disc_plogi(vport);
2454 if (!vport->num_disc_nodes) {
2455 spin_lock_irq(shost->host_lock);
2456 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2457 spin_unlock_irq(shost->host_lock);
2458 lpfc_can_disctmo(vport);
2459 lpfc_end_rscn(vport);
2462 vport->port_state = LPFC_VPORT_READY;
2464 lpfc_rscn_disc(vport);
2468 * lpfc_more_adisc - Issue more adisc as needed
2469 * @vport: pointer to a host virtual N_Port data structure.
2471 * This routine determines whether there are more ndlps on a @vport
2472 * node list need to have Address Discover (ADISC) issued. If so, it will
2473 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
2474 * remaining nodes which need to have ADISC sent.
2477 lpfc_more_adisc(struct lpfc_vport *vport)
2479 if (vport->num_disc_nodes)
2480 vport->num_disc_nodes--;
2481 /* Continue discovery with <num_disc_nodes> ADISCs to go */
2482 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2483 "0210 Continue discovery with %d ADISCs to go "
2484 "Data: x%x x%x x%x\n",
2485 vport->num_disc_nodes, vport->fc_adisc_cnt,
2486 vport->fc_flag, vport->port_state);
2487 /* Check to see if there are more ADISCs to be sent */
2488 if (vport->fc_flag & FC_NLP_MORE) {
2489 lpfc_set_disctmo(vport);
2490 /* go thru NPR nodes and issue any remaining ELS ADISCs */
2491 lpfc_els_disc_adisc(vport);
2493 if (!vport->num_disc_nodes)
2494 lpfc_adisc_done(vport);
2499 * lpfc_cmpl_els_adisc - Completion callback function for adisc
2500 * @phba: pointer to lpfc hba data structure.
2501 * @cmdiocb: pointer to lpfc command iocb data structure.
2502 * @rspiocb: pointer to lpfc response iocb data structure.
2504 * This routine is the completion function for issuing the Address Discover
2505 * (ADISC) command. It first checks to see whether link went down during
2506 * the discovery process. If so, the node will be marked as node port
2507 * recovery for issuing discover IOCB by the link attention handler and
2508 * exit. Otherwise, the response status is checked. If error was reported
2509 * in the response status, the ADISC command shall be retried by invoking
2510 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
2511 * the response status, the state machine is invoked to set transition
2512 * with respect to NLP_EVT_CMPL_ADISC event.
2515 lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2516 struct lpfc_iocbq *rspiocb)
2518 struct lpfc_vport *vport = cmdiocb->vport;
2519 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2521 struct lpfc_nodelist *ndlp;
2524 /* we pass cmdiocb to state machine which needs rspiocb as well */
2525 cmdiocb->context_un.rsp_iocb = rspiocb;
2527 irsp = &(rspiocb->iocb);
2528 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2530 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2531 "ADISC cmpl: status:x%x/x%x did:x%x",
2532 irsp->ulpStatus, irsp->un.ulpWord[4],
2535 /* Since ndlp can be freed in the disc state machine, note if this node
2536 * is being used during discovery.
2538 spin_lock_irq(shost->host_lock);
2539 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
2540 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
2541 spin_unlock_irq(shost->host_lock);
2542 /* ADISC completes to NPort <nlp_DID> */
2543 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2544 "0104 ADISC completes to NPort x%x "
2545 "Data: x%x x%x x%x x%x x%x\n",
2546 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2547 irsp->ulpTimeout, disc, vport->num_disc_nodes);
2548 /* Check to see if link went down during discovery */
2549 if (lpfc_els_chk_latt(vport)) {
2550 spin_lock_irq(shost->host_lock);
2551 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2552 spin_unlock_irq(shost->host_lock);
2556 if (irsp->ulpStatus) {
2557 /* Check for retry */
2558 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2559 /* ELS command is being retried */
2561 spin_lock_irq(shost->host_lock);
2562 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2563 spin_unlock_irq(shost->host_lock);
2564 lpfc_set_disctmo(vport);
2569 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2570 "2755 ADISC failure DID:%06X Status:x%x/x%x\n",
2571 ndlp->nlp_DID, irsp->ulpStatus,
2572 irsp->un.ulpWord[4]);
2573 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2574 if (!lpfc_error_lost_link(irsp))
2575 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2576 NLP_EVT_CMPL_ADISC);
2578 /* Good status, call state machine */
2579 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2580 NLP_EVT_CMPL_ADISC);
2582 /* Check to see if there are more ADISCs to be sent */
2583 if (disc && vport->num_disc_nodes)
2584 lpfc_more_adisc(vport);
2586 lpfc_els_free_iocb(phba, cmdiocb);
2591 * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
2592 * @vport: pointer to a virtual N_Port data structure.
2593 * @ndlp: pointer to a node-list data structure.
2594 * @retry: number of retries to the command IOCB.
2596 * This routine issues an Address Discover (ADISC) for an @ndlp on a
2597 * @vport. It prepares the payload of the ADISC ELS command, updates the
2598 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
2599 * to issue the ADISC ELS command.
2601 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2602 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2603 * will be stored into the context1 field of the IOCB for the completion
2604 * callback function to the ADISC ELS command.
2607 * 0 - successfully issued adisc
2608 * 1 - failed to issue adisc
2611 lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2614 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2615 struct lpfc_hba *phba = vport->phba;
2617 struct lpfc_iocbq *elsiocb;
2621 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
2622 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2623 ndlp->nlp_DID, ELS_CMD_ADISC);
2627 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2629 /* For ADISC request, remainder of payload is service parameters */
2630 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
2631 pcmd += sizeof(uint32_t);
2633 /* Fill in ADISC payload */
2634 ap = (ADISC *) pcmd;
2635 ap->hardAL_PA = phba->fc_pref_ALPA;
2636 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2637 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
2638 ap->DID = be32_to_cpu(vport->fc_myDID);
2640 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2641 "Issue ADISC: did:x%x",
2642 ndlp->nlp_DID, 0, 0);
2644 phba->fc_stat.elsXmitADISC++;
2645 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
2646 spin_lock_irq(shost->host_lock);
2647 ndlp->nlp_flag |= NLP_ADISC_SND;
2648 spin_unlock_irq(shost->host_lock);
2649 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2651 spin_lock_irq(shost->host_lock);
2652 ndlp->nlp_flag &= ~NLP_ADISC_SND;
2653 spin_unlock_irq(shost->host_lock);
2654 lpfc_els_free_iocb(phba, elsiocb);
2661 * lpfc_cmpl_els_logo - Completion callback function for logo
2662 * @phba: pointer to lpfc hba data structure.
2663 * @cmdiocb: pointer to lpfc command iocb data structure.
2664 * @rspiocb: pointer to lpfc response iocb data structure.
2666 * This routine is the completion function for issuing the ELS Logout (LOGO)
2667 * command. If no error status was reported from the LOGO response, the
2668 * state machine of the associated ndlp shall be invoked for transition with
2669 * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
2670 * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
2673 lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2674 struct lpfc_iocbq *rspiocb)
2676 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2677 struct lpfc_vport *vport = ndlp->vport;
2678 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2680 struct lpfcMboxq *mbox;
2681 unsigned long flags;
2682 uint32_t skip_recovery = 0;
2684 /* we pass cmdiocb to state machine which needs rspiocb as well */
2685 cmdiocb->context_un.rsp_iocb = rspiocb;
2687 irsp = &(rspiocb->iocb);
2688 spin_lock_irq(shost->host_lock);
2689 ndlp->nlp_flag &= ~NLP_LOGO_SND;
2690 spin_unlock_irq(shost->host_lock);
2692 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2693 "LOGO cmpl: status:x%x/x%x did:x%x",
2694 irsp->ulpStatus, irsp->un.ulpWord[4],
2697 /* LOGO completes to NPort <nlp_DID> */
2698 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2699 "0105 LOGO completes to NPort x%x "
2700 "Data: x%x x%x x%x x%x\n",
2701 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2702 irsp->ulpTimeout, vport->num_disc_nodes);
2704 if (lpfc_els_chk_latt(vport)) {
2709 /* Check to see if link went down during discovery */
2710 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
2711 /* NLP_EVT_DEVICE_RM should unregister the RPI
2712 * which should abort all outstanding IOs.
2714 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2720 /* The LOGO will not be retried on failure. A LOGO was
2721 * issued to the remote rport and a ACC or RJT or no Answer are
2722 * all acceptable. Note the failure and move forward with
2723 * discovery. The PLOGI will retry.
2725 if (irsp->ulpStatus) {
2727 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2728 "2756 LOGO failure, No Retry DID:%06X Status:x%x/x%x\n",
2729 ndlp->nlp_DID, irsp->ulpStatus,
2730 irsp->un.ulpWord[4]);
2731 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2732 if (lpfc_error_lost_link(irsp)) {
2738 /* Call state machine. This will unregister the rpi if needed. */
2739 lpfc_disc_state_machine(vport, ndlp, cmdiocb, NLP_EVT_CMPL_LOGO);
2742 lpfc_els_free_iocb(phba, cmdiocb);
2743 /* If we are in pt2pt mode, we could rcv new S_ID on PLOGI */
2744 if ((vport->fc_flag & FC_PT2PT) &&
2745 !(vport->fc_flag & FC_PT2PT_PLOGI)) {
2746 phba->pport->fc_myDID = 0;
2748 if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
2749 (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
2750 if (phba->nvmet_support)
2751 lpfc_nvmet_update_targetport(phba);
2753 lpfc_nvme_update_localport(phba->pport);
2756 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2758 lpfc_config_link(phba, mbox);
2759 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
2760 mbox->vport = vport;
2761 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) ==
2763 mempool_free(mbox, phba->mbox_mem_pool);
2770 * If the node is a target, the handling attempts to recover the port.
2771 * For any other port type, the rpi is unregistered as an implicit
2774 if (ndlp->nlp_type & (NLP_FCP_TARGET | NLP_NVME_TARGET) &&
2775 skip_recovery == 0) {
2776 lpfc_cancel_retry_delay_tmo(vport, ndlp);
2777 spin_lock_irqsave(shost->host_lock, flags);
2778 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2779 spin_unlock_irqrestore(shost->host_lock, flags);
2781 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2782 "3187 LOGO completes to NPort x%x: Start "
2783 "Recovery Data: x%x x%x x%x x%x\n",
2784 ndlp->nlp_DID, irsp->ulpStatus,
2785 irsp->un.ulpWord[4], irsp->ulpTimeout,
2786 vport->num_disc_nodes);
2787 lpfc_disc_start(vport);
2793 * lpfc_issue_els_logo - Issue a logo to an node on a vport
2794 * @vport: pointer to a virtual N_Port data structure.
2795 * @ndlp: pointer to a node-list data structure.
2796 * @retry: number of retries to the command IOCB.
2798 * This routine constructs and issues an ELS Logout (LOGO) iocb command
2799 * to a remote node, referred by an @ndlp on a @vport. It constructs the
2800 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
2801 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
2803 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2804 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2805 * will be stored into the context1 field of the IOCB for the completion
2806 * callback function to the LOGO ELS command.
2808 * Callers of this routine are expected to unregister the RPI first
2811 * 0 - successfully issued logo
2812 * 1 - failed to issue logo
2815 lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2818 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2819 struct lpfc_hba *phba = vport->phba;
2820 struct lpfc_iocbq *elsiocb;
2825 spin_lock_irq(shost->host_lock);
2826 if (ndlp->nlp_flag & NLP_LOGO_SND) {
2827 spin_unlock_irq(shost->host_lock);
2830 spin_unlock_irq(shost->host_lock);
2832 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
2833 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2834 ndlp->nlp_DID, ELS_CMD_LOGO);
2838 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2839 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
2840 pcmd += sizeof(uint32_t);
2842 /* Fill in LOGO payload */
2843 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
2844 pcmd += sizeof(uint32_t);
2845 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
2847 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2848 "Issue LOGO: did:x%x",
2849 ndlp->nlp_DID, 0, 0);
2851 phba->fc_stat.elsXmitLOGO++;
2852 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
2853 spin_lock_irq(shost->host_lock);
2854 ndlp->nlp_flag |= NLP_LOGO_SND;
2855 ndlp->nlp_flag &= ~NLP_ISSUE_LOGO;
2856 spin_unlock_irq(shost->host_lock);
2857 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
2858 if (rc == IOCB_ERROR) {
2859 spin_lock_irq(shost->host_lock);
2860 ndlp->nlp_flag &= ~NLP_LOGO_SND;
2861 spin_unlock_irq(shost->host_lock);
2862 lpfc_els_free_iocb(phba, elsiocb);
2866 spin_lock_irq(shost->host_lock);
2867 ndlp->nlp_prev_state = ndlp->nlp_state;
2868 spin_unlock_irq(shost->host_lock);
2869 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
2874 * lpfc_cmpl_els_cmd - Completion callback function for generic els command
2875 * @phba: pointer to lpfc hba data structure.
2876 * @cmdiocb: pointer to lpfc command iocb data structure.
2877 * @rspiocb: pointer to lpfc response iocb data structure.
2879 * This routine is a generic completion callback function for ELS commands.
2880 * Specifically, it is the callback function which does not need to perform
2881 * any command specific operations. It is currently used by the ELS command
2882 * issuing routines for the ELS State Change Request (SCR),
2883 * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution
2884 * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than
2885 * certain debug loggings, this callback function simply invokes the
2886 * lpfc_els_chk_latt() routine to check whether link went down during the
2887 * discovery process.
2890 lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2891 struct lpfc_iocbq *rspiocb)
2893 struct lpfc_vport *vport = cmdiocb->vport;
2896 irsp = &rspiocb->iocb;
2898 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2899 "ELS cmd cmpl: status:x%x/x%x did:x%x",
2900 irsp->ulpStatus, irsp->un.ulpWord[4],
2901 irsp->un.elsreq64.remoteID);
2902 /* ELS cmd tag <ulpIoTag> completes */
2903 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2904 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
2905 irsp->ulpIoTag, irsp->ulpStatus,
2906 irsp->un.ulpWord[4], irsp->ulpTimeout);
2907 /* Check to see if link went down during discovery */
2908 lpfc_els_chk_latt(vport);
2909 lpfc_els_free_iocb(phba, cmdiocb);
2914 * lpfc_issue_els_scr - Issue a scr to an node on a vport
2915 * @vport: pointer to a host virtual N_Port data structure.
2916 * @nportid: N_Port identifier to the remote node.
2917 * @retry: number of retries to the command IOCB.
2919 * This routine issues a State Change Request (SCR) to a fabric node
2920 * on a @vport. The remote node @nportid is passed into the function. It
2921 * first search the @vport node list to find the matching ndlp. If no such
2922 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
2923 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
2924 * routine is invoked to send the SCR IOCB.
2926 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2927 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2928 * will be stored into the context1 field of the IOCB for the completion
2929 * callback function to the SCR ELS command.
2932 * 0 - Successfully issued scr command
2933 * 1 - Failed to issue scr command
2936 lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
2938 struct lpfc_hba *phba = vport->phba;
2939 struct lpfc_iocbq *elsiocb;
2942 struct lpfc_nodelist *ndlp;
2944 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
2946 ndlp = lpfc_findnode_did(vport, nportid);
2948 ndlp = lpfc_nlp_init(vport, nportid);
2951 lpfc_enqueue_node(vport, ndlp);
2952 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2953 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2958 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2959 ndlp->nlp_DID, ELS_CMD_SCR);
2962 /* This will trigger the release of the node just
2969 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2971 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
2972 pcmd += sizeof(uint32_t);
2974 /* For SCR, remainder of payload is SCR parameter page */
2975 memset(pcmd, 0, sizeof(SCR));
2976 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
2978 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2979 "Issue SCR: did:x%x",
2980 ndlp->nlp_DID, 0, 0);
2982 phba->fc_stat.elsXmitSCR++;
2983 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
2984 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2986 /* The additional lpfc_nlp_put will cause the following
2987 * lpfc_els_free_iocb routine to trigger the rlease of
2991 lpfc_els_free_iocb(phba, elsiocb);
2994 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2995 * trigger the release of node.
2997 if (!(vport->fc_flag & FC_PT2PT))
3003 * lpfc_issue_els_farpr - Issue a farp to an node on a vport
3004 * @vport: pointer to a host virtual N_Port data structure.
3005 * @nportid: N_Port identifier to the remote node.
3006 * @retry: number of retries to the command IOCB.
3008 * This routine issues a Fibre Channel Address Resolution Response
3009 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
3010 * is passed into the function. It first search the @vport node list to find
3011 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
3012 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
3013 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
3015 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3016 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3017 * will be stored into the context1 field of the IOCB for the completion
3018 * callback function to the PARPR ELS command.
3021 * 0 - Successfully issued farpr command
3022 * 1 - Failed to issue farpr command
3025 lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
3027 struct lpfc_hba *phba = vport->phba;
3028 struct lpfc_iocbq *elsiocb;
3033 struct lpfc_nodelist *ondlp;
3034 struct lpfc_nodelist *ndlp;
3036 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
3038 ndlp = lpfc_findnode_did(vport, nportid);
3040 ndlp = lpfc_nlp_init(vport, nportid);
3043 lpfc_enqueue_node(vport, ndlp);
3044 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
3045 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
3050 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
3051 ndlp->nlp_DID, ELS_CMD_RNID);
3053 /* This will trigger the release of the node just
3060 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3062 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
3063 pcmd += sizeof(uint32_t);
3065 /* Fill in FARPR payload */
3066 fp = (FARP *) (pcmd);
3067 memset(fp, 0, sizeof(FARP));
3068 lp = (uint32_t *) pcmd;
3069 *lp++ = be32_to_cpu(nportid);
3070 *lp++ = be32_to_cpu(vport->fc_myDID);
3072 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
3074 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
3075 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
3076 ondlp = lpfc_findnode_did(vport, nportid);
3077 if (ondlp && NLP_CHK_NODE_ACT(ondlp)) {
3078 memcpy(&fp->OportName, &ondlp->nlp_portname,
3079 sizeof(struct lpfc_name));
3080 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
3081 sizeof(struct lpfc_name));
3084 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3085 "Issue FARPR: did:x%x",
3086 ndlp->nlp_DID, 0, 0);
3088 phba->fc_stat.elsXmitFARPR++;
3089 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
3090 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
3092 /* The additional lpfc_nlp_put will cause the following
3093 * lpfc_els_free_iocb routine to trigger the release of
3097 lpfc_els_free_iocb(phba, elsiocb);
3100 /* This will cause the callback-function lpfc_cmpl_els_cmd to
3101 * trigger the release of the node.
3108 * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
3109 * @vport: pointer to a host virtual N_Port data structure.
3110 * @nlp: pointer to a node-list data structure.
3112 * This routine cancels the timer with a delayed IOCB-command retry for
3113 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
3114 * removes the ELS retry event if it presents. In addition, if the
3115 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
3116 * commands are sent for the @vport's nodes that require issuing discovery
3120 lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
3122 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3123 struct lpfc_work_evt *evtp;
3125 if (!(nlp->nlp_flag & NLP_DELAY_TMO))
3127 spin_lock_irq(shost->host_lock);
3128 nlp->nlp_flag &= ~NLP_DELAY_TMO;
3129 spin_unlock_irq(shost->host_lock);
3130 del_timer_sync(&nlp->nlp_delayfunc);
3131 nlp->nlp_last_elscmd = 0;
3132 if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
3133 list_del_init(&nlp->els_retry_evt.evt_listp);
3134 /* Decrement nlp reference count held for the delayed retry */
3135 evtp = &nlp->els_retry_evt;
3136 lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
3138 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
3139 spin_lock_irq(shost->host_lock);
3140 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
3141 spin_unlock_irq(shost->host_lock);
3142 if (vport->num_disc_nodes) {
3143 if (vport->port_state < LPFC_VPORT_READY) {
3144 /* Check if there are more ADISCs to be sent */
3145 lpfc_more_adisc(vport);
3147 /* Check if there are more PLOGIs to be sent */
3148 lpfc_more_plogi(vport);
3149 if (vport->num_disc_nodes == 0) {
3150 spin_lock_irq(shost->host_lock);
3151 vport->fc_flag &= ~FC_NDISC_ACTIVE;
3152 spin_unlock_irq(shost->host_lock);
3153 lpfc_can_disctmo(vport);
3154 lpfc_end_rscn(vport);
3163 * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
3164 * @ptr: holder for the pointer to the timer function associated data (ndlp).
3166 * This routine is invoked by the ndlp delayed-function timer to check
3167 * whether there is any pending ELS retry event(s) with the node. If not, it
3168 * simply returns. Otherwise, if there is at least one ELS delayed event, it
3169 * adds the delayed events to the HBA work list and invokes the
3170 * lpfc_worker_wake_up() routine to wake up worker thread to process the
3171 * event. Note that lpfc_nlp_get() is called before posting the event to
3172 * the work list to hold reference count of ndlp so that it guarantees the
3173 * reference to ndlp will still be available when the worker thread gets
3174 * to the event associated with the ndlp.
3177 lpfc_els_retry_delay(struct timer_list *t)
3179 struct lpfc_nodelist *ndlp = from_timer(ndlp, t, nlp_delayfunc);
3180 struct lpfc_vport *vport = ndlp->vport;
3181 struct lpfc_hba *phba = vport->phba;
3182 unsigned long flags;
3183 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
3185 spin_lock_irqsave(&phba->hbalock, flags);
3186 if (!list_empty(&evtp->evt_listp)) {
3187 spin_unlock_irqrestore(&phba->hbalock, flags);
3191 /* We need to hold the node by incrementing the reference
3192 * count until the queued work is done
3194 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
3195 if (evtp->evt_arg1) {
3196 evtp->evt = LPFC_EVT_ELS_RETRY;
3197 list_add_tail(&evtp->evt_listp, &phba->work_list);
3198 lpfc_worker_wake_up(phba);
3200 spin_unlock_irqrestore(&phba->hbalock, flags);
3205 * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
3206 * @ndlp: pointer to a node-list data structure.
3208 * This routine is the worker-thread handler for processing the @ndlp delayed
3209 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
3210 * the last ELS command from the associated ndlp and invokes the proper ELS
3211 * function according to the delayed ELS command to retry the command.
3214 lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
3216 struct lpfc_vport *vport = ndlp->vport;
3217 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3218 uint32_t cmd, retry;
3220 spin_lock_irq(shost->host_lock);
3221 cmd = ndlp->nlp_last_elscmd;
3222 ndlp->nlp_last_elscmd = 0;
3224 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
3225 spin_unlock_irq(shost->host_lock);
3229 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
3230 spin_unlock_irq(shost->host_lock);
3232 * If a discovery event readded nlp_delayfunc after timer
3233 * firing and before processing the timer, cancel the
3236 del_timer_sync(&ndlp->nlp_delayfunc);
3237 retry = ndlp->nlp_retry;
3238 ndlp->nlp_retry = 0;
3242 lpfc_issue_els_flogi(vport, ndlp, retry);
3245 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
3246 ndlp->nlp_prev_state = ndlp->nlp_state;
3247 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
3251 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
3252 ndlp->nlp_prev_state = ndlp->nlp_state;
3253 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
3257 case ELS_CMD_NVMEPRLI:
3258 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
3259 ndlp->nlp_prev_state = ndlp->nlp_state;
3260 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
3264 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
3265 ndlp->nlp_prev_state = ndlp->nlp_state;
3266 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
3270 if (!(vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI))
3271 lpfc_issue_els_fdisc(vport, ndlp, retry);
3278 * lpfc_els_retry - Make retry decision on an els command iocb
3279 * @phba: pointer to lpfc hba data structure.
3280 * @cmdiocb: pointer to lpfc command iocb data structure.
3281 * @rspiocb: pointer to lpfc response iocb data structure.
3283 * This routine makes a retry decision on an ELS command IOCB, which has
3284 * failed. The following ELS IOCBs use this function for retrying the command
3285 * when previously issued command responsed with error status: FLOGI, PLOGI,
3286 * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
3287 * returned error status, it makes the decision whether a retry shall be
3288 * issued for the command, and whether a retry shall be made immediately or
3289 * delayed. In the former case, the corresponding ELS command issuing-function
3290 * is called to retry the command. In the later case, the ELS command shall
3291 * be posted to the ndlp delayed event and delayed function timer set to the
3292 * ndlp for the delayed command issusing.
3295 * 0 - No retry of els command is made
3296 * 1 - Immediate or delayed retry of els command is made
3299 lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3300 struct lpfc_iocbq *rspiocb)
3302 struct lpfc_vport *vport = cmdiocb->vport;
3303 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3304 IOCB_t *irsp = &rspiocb->iocb;
3305 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3306 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3309 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
3315 /* Note: context2 may be 0 for internal driver abort
3316 * of delays ELS command.
3319 if (pcmd && pcmd->virt) {
3320 elscmd = (uint32_t *) (pcmd->virt);
3324 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
3325 did = ndlp->nlp_DID;
3327 /* We should only hit this case for retrying PLOGI */
3328 did = irsp->un.elsreq64.remoteID;
3329 ndlp = lpfc_findnode_did(vport, did);
3330 if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp))
3331 && (cmd != ELS_CMD_PLOGI))
3335 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3336 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
3337 *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
3339 switch (irsp->ulpStatus) {
3340 case IOSTAT_FCP_RSP_ERROR:
3342 case IOSTAT_REMOTE_STOP:
3343 if (phba->sli_rev == LPFC_SLI_REV4) {
3344 /* This IO was aborted by the target, we don't
3345 * know the rxid and because we did not send the
3346 * ABTS we cannot generate and RRQ.
3348 lpfc_set_rrq_active(phba, ndlp,
3349 cmdiocb->sli4_lxritag, 0, 0);
3352 case IOSTAT_LOCAL_REJECT:
3353 switch ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK)) {
3354 case IOERR_LOOP_OPEN_FAILURE:
3355 if (cmd == ELS_CMD_FLOGI) {
3356 if (PCI_DEVICE_ID_HORNET ==
3357 phba->pcidev->device) {
3358 phba->fc_topology = LPFC_TOPOLOGY_LOOP;
3359 phba->pport->fc_myDID = 0;
3360 phba->alpa_map[0] = 0;
3361 phba->alpa_map[1] = 0;
3364 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
3369 case IOERR_ILLEGAL_COMMAND:
3370 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3371 "0124 Retry illegal cmd x%x "
3372 "retry:x%x delay:x%x\n",
3373 cmd, cmdiocb->retry, delay);
3375 /* All command's retry policy */
3377 if (cmdiocb->retry > 2)
3381 case IOERR_NO_RESOURCES:
3382 logerr = 1; /* HBA out of resources */
3384 if (cmdiocb->retry > 100)
3389 case IOERR_ILLEGAL_FRAME:
3394 case IOERR_SEQUENCE_TIMEOUT:
3395 case IOERR_INVALID_RPI:
3396 if (cmd == ELS_CMD_PLOGI &&
3397 did == NameServer_DID) {
3398 /* Continue forever if plogi to */
3399 /* the nameserver fails */
3408 case IOSTAT_NPORT_RJT:
3409 case IOSTAT_FABRIC_RJT:
3410 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
3416 case IOSTAT_NPORT_BSY:
3417 case IOSTAT_FABRIC_BSY:
3418 logerr = 1; /* Fabric / Remote NPort out of resources */
3423 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
3424 /* Added for Vendor specifc support
3425 * Just keep retrying for these Rsn / Exp codes
3427 switch (stat.un.b.lsRjtRsnCode) {
3428 case LSRJT_UNABLE_TPC:
3429 /* The driver has a VALID PLOGI but the rport has
3430 * rejected the PRLI - can't do it now. Delay
3431 * for 1 second and try again - don't care about
3434 if (cmd == ELS_CMD_PRLI || cmd == ELS_CMD_NVMEPRLI) {
3436 maxretry = lpfc_max_els_tries + 1;
3441 /* Legacy bug fix code for targets with PLOGI delays. */
3442 if (stat.un.b.lsRjtRsnCodeExp ==
3443 LSEXP_CMD_IN_PROGRESS) {
3444 if (cmd == ELS_CMD_PLOGI) {
3451 if (stat.un.b.lsRjtRsnCodeExp ==
3452 LSEXP_CANT_GIVE_DATA) {
3453 if (cmd == ELS_CMD_PLOGI) {
3460 if (cmd == ELS_CMD_PLOGI) {
3462 maxretry = lpfc_max_els_tries + 1;
3466 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
3467 (cmd == ELS_CMD_FDISC) &&
3468 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
3469 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3470 "0125 FDISC Failed (x%x). "
3471 "Fabric out of resources\n",
3472 stat.un.lsRjtError);
3473 lpfc_vport_set_state(vport,
3474 FC_VPORT_NO_FABRIC_RSCS);
3478 case LSRJT_LOGICAL_BSY:
3479 if ((cmd == ELS_CMD_PLOGI) ||
3480 (cmd == ELS_CMD_PRLI) ||
3481 (cmd == ELS_CMD_NVMEPRLI)) {
3484 } else if (cmd == ELS_CMD_FDISC) {
3485 /* FDISC retry policy */
3487 if (cmdiocb->retry >= 32)
3493 case LSRJT_LOGICAL_ERR:
3494 /* There are some cases where switches return this
3495 * error when they are not ready and should be returning
3496 * Logical Busy. We should delay every time.
3498 if (cmd == ELS_CMD_FDISC &&
3499 stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
3503 } else if (cmd == ELS_CMD_FLOGI &&
3504 stat.un.b.lsRjtRsnCodeExp ==
3505 LSEXP_NOTHING_MORE) {
3506 vport->fc_sparam.cmn.bbRcvSizeMsb &= 0xf;
3508 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3509 "0820 FLOGI Failed (x%x). "
3510 "BBCredit Not Supported\n",
3511 stat.un.lsRjtError);
3515 case LSRJT_PROTOCOL_ERR:
3516 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
3517 (cmd == ELS_CMD_FDISC) &&
3518 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
3519 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
3521 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3522 "0122 FDISC Failed (x%x). "
3523 "Fabric Detected Bad WWN\n",
3524 stat.un.lsRjtError);
3525 lpfc_vport_set_state(vport,
3526 FC_VPORT_FABRIC_REJ_WWN);
3529 case LSRJT_VENDOR_UNIQUE:
3530 if ((stat.un.b.vendorUnique == 0x45) &&
3531 (cmd == ELS_CMD_FLOGI)) {
3535 case LSRJT_CMD_UNSUPPORTED:
3536 /* lpfc nvmet returns this type of LS_RJT when it
3537 * receives an FCP PRLI because lpfc nvmet only
3538 * support NVME. ELS request is terminated for FCP4
3541 if (stat.un.b.lsRjtRsnCodeExp ==
3542 LSEXP_REQ_UNSUPPORTED && cmd == ELS_CMD_PRLI) {
3543 spin_lock_irq(shost->host_lock);
3544 ndlp->nlp_flag |= NLP_FCP_PRLI_RJT;
3545 spin_unlock_irq(shost->host_lock);
3553 case IOSTAT_INTERMED_RSP:
3561 if (did == FDMI_DID)
3564 if ((cmd == ELS_CMD_FLOGI) &&
3565 (phba->fc_topology != LPFC_TOPOLOGY_LOOP) &&
3566 !lpfc_error_lost_link(irsp)) {
3567 /* FLOGI retry policy */
3569 /* retry FLOGI forever */
3570 if (phba->link_flag != LS_LOOPBACK_MODE)
3575 if (cmdiocb->retry >= 100)
3577 else if (cmdiocb->retry >= 32)
3579 } else if ((cmd == ELS_CMD_FDISC) && !lpfc_error_lost_link(irsp)) {
3580 /* retry FDISCs every second up to devloss */
3582 maxretry = vport->cfg_devloss_tmo;
3587 if (maxretry && (cmdiocb->retry >= maxretry)) {
3588 phba->fc_stat.elsRetryExceeded++;
3592 if ((vport->load_flag & FC_UNLOADING) != 0)
3597 if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) {
3598 /* Stop retrying PLOGI and FDISC if in FCF discovery */
3599 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
3600 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3601 "2849 Stop retry ELS command "
3602 "x%x to remote NPORT x%x, "
3603 "Data: x%x x%x\n", cmd, did,
3604 cmdiocb->retry, delay);
3609 /* Retry ELS command <elsCmd> to remote NPORT <did> */
3610 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3611 "0107 Retry ELS command x%x to remote "
3612 "NPORT x%x Data: x%x x%x\n",
3613 cmd, did, cmdiocb->retry, delay);
3615 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
3616 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
3617 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
3618 IOERR_NO_RESOURCES))) {
3619 /* Don't reset timer for no resources */
3621 /* If discovery / RSCN timer is running, reset it */
3622 if (timer_pending(&vport->fc_disctmo) ||
3623 (vport->fc_flag & FC_RSCN_MODE))
3624 lpfc_set_disctmo(vport);
3627 phba->fc_stat.elsXmitRetry++;
3628 if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) {
3629 phba->fc_stat.elsDelayRetry++;
3630 ndlp->nlp_retry = cmdiocb->retry;
3632 /* delay is specified in milliseconds */
3633 mod_timer(&ndlp->nlp_delayfunc,
3634 jiffies + msecs_to_jiffies(delay));
3635 spin_lock_irq(shost->host_lock);
3636 ndlp->nlp_flag |= NLP_DELAY_TMO;
3637 spin_unlock_irq(shost->host_lock);
3639 ndlp->nlp_prev_state = ndlp->nlp_state;
3640 if ((cmd == ELS_CMD_PRLI) ||
3641 (cmd == ELS_CMD_NVMEPRLI))
3642 lpfc_nlp_set_state(vport, ndlp,
3643 NLP_STE_PRLI_ISSUE);
3645 lpfc_nlp_set_state(vport, ndlp,
3647 ndlp->nlp_last_elscmd = cmd;
3653 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
3656 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
3659 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
3660 ndlp->nlp_prev_state = ndlp->nlp_state;
3661 lpfc_nlp_set_state(vport, ndlp,
3662 NLP_STE_PLOGI_ISSUE);
3664 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
3667 ndlp->nlp_prev_state = ndlp->nlp_state;
3668 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
3669 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
3672 case ELS_CMD_NVMEPRLI:
3673 ndlp->nlp_prev_state = ndlp->nlp_state;
3674 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
3675 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
3678 ndlp->nlp_prev_state = ndlp->nlp_state;
3679 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
3680 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
3684 /* No retry ELS command <elsCmd> to remote NPORT <did> */
3686 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3687 "0137 No retry ELS command x%x to remote "
3688 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
3689 cmd, did, irsp->ulpStatus,
3690 irsp->un.ulpWord[4]);
3693 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3694 "0108 No retry ELS command x%x to remote "
3695 "NPORT x%x Retried:%d Error:x%x/%x\n",
3696 cmd, did, cmdiocb->retry, irsp->ulpStatus,
3697 irsp->un.ulpWord[4]);
3703 * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
3704 * @phba: pointer to lpfc hba data structure.
3705 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
3707 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
3708 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
3709 * checks to see whether there is a lpfc DMA buffer associated with the
3710 * response of the command IOCB. If so, it will be released before releasing
3711 * the lpfc DMA buffer associated with the IOCB itself.
3714 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3717 lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
3719 struct lpfc_dmabuf *buf_ptr;
3721 /* Free the response before processing the command. */
3722 if (!list_empty(&buf_ptr1->list)) {
3723 list_remove_head(&buf_ptr1->list, buf_ptr,
3726 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3729 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
3735 * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
3736 * @phba: pointer to lpfc hba data structure.
3737 * @buf_ptr: pointer to the lpfc dma buffer data structure.
3739 * This routine releases the lpfc Direct Memory Access (DMA) buffer
3740 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
3744 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3747 lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
3749 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3755 * lpfc_els_free_iocb - Free a command iocb and its associated resources
3756 * @phba: pointer to lpfc hba data structure.
3757 * @elsiocb: pointer to lpfc els command iocb data structure.
3759 * This routine frees a command IOCB and its associated resources. The
3760 * command IOCB data structure contains the reference to various associated
3761 * resources, these fields must be set to NULL if the associated reference
3763 * context1 - reference to ndlp
3764 * context2 - reference to cmd
3765 * context2->next - reference to rsp
3766 * context3 - reference to bpl
3768 * It first properly decrements the reference count held on ndlp for the
3769 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
3770 * set, it invokes the lpfc_els_free_data() routine to release the Direct
3771 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
3772 * adds the DMA buffer the @phba data structure for the delayed release.
3773 * If reference to the Buffer Pointer List (BPL) is present, the
3774 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
3775 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
3776 * invoked to release the IOCB data structure back to @phba IOCBQ list.
3779 * 0 - Success (currently, always return 0)
3782 lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
3784 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
3785 struct lpfc_nodelist *ndlp;
3787 ndlp = (struct lpfc_nodelist *)elsiocb->context1;
3789 if (ndlp->nlp_flag & NLP_DEFER_RM) {
3792 /* If the ndlp is not being used by another discovery
3795 if (!lpfc_nlp_not_used(ndlp)) {
3796 /* If ndlp is being used by another discovery
3797 * thread, just clear NLP_DEFER_RM
3799 ndlp->nlp_flag &= ~NLP_DEFER_RM;
3804 elsiocb->context1 = NULL;
3806 /* context2 = cmd, context2->next = rsp, context3 = bpl */
3807 if (elsiocb->context2) {
3808 if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
3809 /* Firmware could still be in progress of DMAing
3810 * payload, so don't free data buffer till after
3813 elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
3814 buf_ptr = elsiocb->context2;
3815 elsiocb->context2 = NULL;
3818 spin_lock_irq(&phba->hbalock);
3819 if (!list_empty(&buf_ptr->list)) {
3820 list_remove_head(&buf_ptr->list,
3821 buf_ptr1, struct lpfc_dmabuf,
3823 INIT_LIST_HEAD(&buf_ptr1->list);
3824 list_add_tail(&buf_ptr1->list,
3828 INIT_LIST_HEAD(&buf_ptr->list);
3829 list_add_tail(&buf_ptr->list, &phba->elsbuf);
3831 spin_unlock_irq(&phba->hbalock);
3834 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
3835 lpfc_els_free_data(phba, buf_ptr1);
3836 elsiocb->context2 = NULL;
3840 if (elsiocb->context3) {
3841 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
3842 lpfc_els_free_bpl(phba, buf_ptr);
3843 elsiocb->context3 = NULL;
3845 lpfc_sli_release_iocbq(phba, elsiocb);
3850 * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
3851 * @phba: pointer to lpfc hba data structure.
3852 * @cmdiocb: pointer to lpfc command iocb data structure.
3853 * @rspiocb: pointer to lpfc response iocb data structure.
3855 * This routine is the completion callback function to the Logout (LOGO)
3856 * Accept (ACC) Response ELS command. This routine is invoked to indicate
3857 * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
3858 * release the ndlp if it has the last reference remaining (reference count
3859 * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
3860 * field to NULL to inform the following lpfc_els_free_iocb() routine no
3861 * ndlp reference count needs to be decremented. Otherwise, the ndlp
3862 * reference use-count shall be decremented by the lpfc_els_free_iocb()
3863 * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
3864 * IOCB data structure.
3867 lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3868 struct lpfc_iocbq *rspiocb)
3870 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3871 struct lpfc_vport *vport = cmdiocb->vport;
3874 irsp = &rspiocb->iocb;
3875 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3876 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
3877 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
3878 /* ACC to LOGO completes to NPort <nlp_DID> */
3879 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3880 "0109 ACC to LOGO completes to NPort x%x "
3881 "Data: x%x x%x x%x\n",
3882 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3885 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
3886 /* NPort Recovery mode or node is just allocated */
3887 if (!lpfc_nlp_not_used(ndlp)) {
3888 /* If the ndlp is being used by another discovery
3889 * thread, just unregister the RPI.
3891 lpfc_unreg_rpi(vport, ndlp);
3893 /* Indicate the node has already released, should
3894 * not reference to it from within lpfc_els_free_iocb.
3896 cmdiocb->context1 = NULL;
3901 * The driver received a LOGO from the rport and has ACK'd it.
3902 * At this point, the driver is done so release the IOCB
3904 lpfc_els_free_iocb(phba, cmdiocb);
3908 * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
3909 * @phba: pointer to lpfc hba data structure.
3910 * @pmb: pointer to the driver internal queue element for mailbox command.
3912 * This routine is the completion callback function for unregister default
3913 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
3914 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
3915 * decrements the ndlp reference count held for this completion callback
3916 * function. After that, it invokes the lpfc_nlp_not_used() to check
3917 * whether there is only one reference left on the ndlp. If so, it will
3918 * perform one more decrement and trigger the release of the ndlp.
3921 lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3923 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
3924 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
3926 pmb->context1 = NULL;
3927 pmb->context2 = NULL;
3929 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3931 mempool_free(pmb, phba->mbox_mem_pool);
3933 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
3934 "0006 rpi%x DID:%x flg:%x %d map:%x %p\n",
3935 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
3936 kref_read(&ndlp->kref),
3937 ndlp->nlp_usg_map, ndlp);
3938 if (NLP_CHK_NODE_ACT(ndlp)) {
3940 /* This is the end of the default RPI cleanup logic for
3941 * this ndlp. If no other discovery threads are using
3942 * this ndlp, free all resources associated with it.
3944 lpfc_nlp_not_used(ndlp);
3946 lpfc_drop_node(ndlp->vport, ndlp);
3954 * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
3955 * @phba: pointer to lpfc hba data structure.
3956 * @cmdiocb: pointer to lpfc command iocb data structure.
3957 * @rspiocb: pointer to lpfc response iocb data structure.
3959 * This routine is the completion callback function for ELS Response IOCB
3960 * command. In normal case, this callback function just properly sets the
3961 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
3962 * field in the command IOCB is not NULL, the referred mailbox command will
3963 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
3964 * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
3965 * link down event occurred during the discovery, the lpfc_nlp_not_used()
3966 * routine shall be invoked trying to release the ndlp if no other threads
3967 * are currently referring it.
3970 lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3971 struct lpfc_iocbq *rspiocb)
3973 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3974 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
3975 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
3978 LPFC_MBOXQ_t *mbox = NULL;
3979 struct lpfc_dmabuf *mp = NULL;
3980 uint32_t ls_rjt = 0;
3982 irsp = &rspiocb->iocb;
3984 if (cmdiocb->context_un.mbox)
3985 mbox = cmdiocb->context_un.mbox;
3987 /* First determine if this is a LS_RJT cmpl. Note, this callback
3988 * function can have cmdiocb->contest1 (ndlp) field set to NULL.
3990 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
3991 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3992 (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) {
3993 /* A LS_RJT associated with Default RPI cleanup has its own
3994 * separate code path.
3996 if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
4000 /* Check to see if link went down during discovery */
4001 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) {
4003 mp = (struct lpfc_dmabuf *) mbox->context1;
4005 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4008 mempool_free(mbox, phba->mbox_mem_pool);
4010 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
4011 (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
4012 if (lpfc_nlp_not_used(ndlp)) {
4014 /* Indicate the node has already released,
4015 * should not reference to it from within
4016 * the routine lpfc_els_free_iocb.
4018 cmdiocb->context1 = NULL;
4023 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4024 "ELS rsp cmpl: status:x%x/x%x did:x%x",
4025 irsp->ulpStatus, irsp->un.ulpWord[4],
4026 cmdiocb->iocb.un.elsreq64.remoteID);
4027 /* ELS response tag <ulpIoTag> completes */
4028 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4029 "0110 ELS response tag x%x completes "
4030 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
4031 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
4032 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
4033 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4036 if ((rspiocb->iocb.ulpStatus == 0)
4037 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
4038 if (!lpfc_unreg_rpi(vport, ndlp) &&
4039 (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
4040 ndlp->nlp_state == NLP_STE_REG_LOGIN_ISSUE)) {
4041 lpfc_printf_vlog(vport, KERN_INFO,
4043 "0314 PLOGI recov DID x%x "
4044 "Data: x%x x%x x%x\n",
4045 ndlp->nlp_DID, ndlp->nlp_state,
4046 ndlp->nlp_rpi, ndlp->nlp_flag);
4047 mp = mbox->context1;
4049 lpfc_mbuf_free(phba, mp->virt,
4053 mempool_free(mbox, phba->mbox_mem_pool);
4057 /* Increment reference count to ndlp to hold the
4058 * reference to ndlp for the callback function.
4060 mbox->context2 = lpfc_nlp_get(ndlp);
4061 mbox->vport = vport;
4062 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
4063 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
4064 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
4067 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
4068 ndlp->nlp_prev_state = ndlp->nlp_state;
4069 lpfc_nlp_set_state(vport, ndlp,
4070 NLP_STE_REG_LOGIN_ISSUE);
4073 ndlp->nlp_flag |= NLP_REG_LOGIN_SEND;
4074 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
4075 != MBX_NOT_FINISHED)
4078 /* Decrement the ndlp reference count we
4079 * set for this failed mailbox command.
4082 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
4084 /* ELS rsp: Cannot issue reg_login for <NPortid> */
4085 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4086 "0138 ELS rsp: Cannot issue reg_login for x%x "
4087 "Data: x%x x%x x%x\n",
4088 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4091 if (lpfc_nlp_not_used(ndlp)) {
4093 /* Indicate node has already been released,
4094 * should not reference to it from within
4095 * the routine lpfc_els_free_iocb.
4097 cmdiocb->context1 = NULL;
4100 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
4101 if (!lpfc_error_lost_link(irsp) &&
4102 ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
4103 if (lpfc_nlp_not_used(ndlp)) {
4105 /* Indicate node has already been
4106 * released, should not reference
4107 * to it from within the routine
4108 * lpfc_els_free_iocb.
4110 cmdiocb->context1 = NULL;
4114 mp = (struct lpfc_dmabuf *) mbox->context1;
4116 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4119 mempool_free(mbox, phba->mbox_mem_pool);
4122 if (ndlp && NLP_CHK_NODE_ACT(ndlp) && shost) {
4123 spin_lock_irq(shost->host_lock);
4125 ndlp->nlp_flag &= ~NLP_ACC_REGLOGIN;
4126 ndlp->nlp_flag &= ~NLP_RM_DFLT_RPI;
4127 spin_unlock_irq(shost->host_lock);
4129 /* If the node is not being used by another discovery thread,
4130 * and we are sending a reject, we are done with it.
4131 * Release driver reference count here and free associated
4135 if (lpfc_nlp_not_used(ndlp))
4136 /* Indicate node has already been released,
4137 * should not reference to it from within
4138 * the routine lpfc_els_free_iocb.
4140 cmdiocb->context1 = NULL;
4144 lpfc_els_free_iocb(phba, cmdiocb);
4149 * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
4150 * @vport: pointer to a host virtual N_Port data structure.
4151 * @flag: the els command code to be accepted.
4152 * @oldiocb: pointer to the original lpfc command iocb data structure.
4153 * @ndlp: pointer to a node-list data structure.
4154 * @mbox: pointer to the driver internal queue element for mailbox command.
4156 * This routine prepares and issues an Accept (ACC) response IOCB
4157 * command. It uses the @flag to properly set up the IOCB field for the
4158 * specific ACC response command to be issued and invokes the
4159 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
4160 * @mbox pointer is passed in, it will be put into the context_un.mbox
4161 * field of the IOCB for the completion callback function to issue the
4162 * mailbox command to the HBA later when callback is invoked.
4164 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4165 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4166 * will be stored into the context1 field of the IOCB for the completion
4167 * callback function to the corresponding response ELS IOCB command.
4170 * 0 - Successfully issued acc response
4171 * 1 - Failed to issue acc response
4174 lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
4175 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
4178 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4179 struct lpfc_hba *phba = vport->phba;
4182 struct lpfc_iocbq *elsiocb;
4184 struct serv_parm *sp;
4187 ELS_PKT *els_pkt_ptr;
4189 oldcmd = &oldiocb->iocb;
4193 cmdsize = sizeof(uint32_t);
4194 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
4195 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
4197 spin_lock_irq(shost->host_lock);
4198 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
4199 spin_unlock_irq(shost->host_lock);
4203 icmd = &elsiocb->iocb;
4204 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4205 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4206 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4207 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4208 pcmd += sizeof(uint32_t);
4210 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4211 "Issue ACC: did:x%x flg:x%x",
4212 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4216 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
4217 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
4218 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
4222 icmd = &elsiocb->iocb;
4223 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4224 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4225 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4228 elsiocb->context_un.mbox = mbox;
4230 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4231 pcmd += sizeof(uint32_t);
4232 sp = (struct serv_parm *)pcmd;
4234 if (flag == ELS_CMD_FLOGI) {
4235 /* Copy the received service parameters back */
4236 memcpy(sp, &phba->fc_fabparam,
4237 sizeof(struct serv_parm));
4239 /* Clear the F_Port bit */
4242 /* Mark all class service parameters as invalid */
4243 sp->cls1.classValid = 0;
4244 sp->cls2.classValid = 0;
4245 sp->cls3.classValid = 0;
4246 sp->cls4.classValid = 0;
4248 /* Copy our worldwide names */
4249 memcpy(&sp->portName, &vport->fc_sparam.portName,
4250 sizeof(struct lpfc_name));
4251 memcpy(&sp->nodeName, &vport->fc_sparam.nodeName,
4252 sizeof(struct lpfc_name));
4254 memcpy(pcmd, &vport->fc_sparam,
4255 sizeof(struct serv_parm));
4257 sp->cmn.valid_vendor_ver_level = 0;
4258 memset(sp->un.vendorVersion, 0,
4259 sizeof(sp->un.vendorVersion));
4260 sp->cmn.bbRcvSizeMsb &= 0xF;
4262 /* If our firmware supports this feature, convey that
4263 * info to the target using the vendor specific field.
4265 if (phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) {
4266 sp->cmn.valid_vendor_ver_level = 1;
4267 sp->un.vv.vid = cpu_to_be32(LPFC_VV_EMLX_ID);
4269 cpu_to_be32(LPFC_VV_SUPPRESS_RSP);
4273 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4274 "Issue ACC FLOGI/PLOGI: did:x%x flg:x%x",
4275 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4278 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
4279 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
4280 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
4284 icmd = &elsiocb->iocb;
4285 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4286 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4287 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4289 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
4290 sizeof(uint32_t) + sizeof(PRLO));
4291 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
4292 els_pkt_ptr = (ELS_PKT *) pcmd;
4293 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
4295 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4296 "Issue ACC PRLO: did:x%x flg:x%x",
4297 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4302 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
4303 spin_lock_irq(shost->host_lock);
4304 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED ||
4305 ndlp->nlp_flag & NLP_REG_LOGIN_SEND))
4306 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
4307 spin_unlock_irq(shost->host_lock);
4308 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
4310 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4313 phba->fc_stat.elsXmitACC++;
4314 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4315 if (rc == IOCB_ERROR) {
4316 lpfc_els_free_iocb(phba, elsiocb);
4323 * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command
4324 * @vport: pointer to a virtual N_Port data structure.
4326 * @oldiocb: pointer to the original lpfc command iocb data structure.
4327 * @ndlp: pointer to a node-list data structure.
4328 * @mbox: pointer to the driver internal queue element for mailbox command.
4330 * This routine prepares and issue an Reject (RJT) response IOCB
4331 * command. If a @mbox pointer is passed in, it will be put into the
4332 * context_un.mbox field of the IOCB for the completion callback function
4333 * to issue to the HBA later.
4335 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4336 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4337 * will be stored into the context1 field of the IOCB for the completion
4338 * callback function to the reject response ELS IOCB command.
4341 * 0 - Successfully issued reject response
4342 * 1 - Failed to issue reject response
4345 lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
4346 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
4349 struct lpfc_hba *phba = vport->phba;
4352 struct lpfc_iocbq *elsiocb;
4357 cmdsize = 2 * sizeof(uint32_t);
4358 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4359 ndlp->nlp_DID, ELS_CMD_LS_RJT);
4363 icmd = &elsiocb->iocb;
4364 oldcmd = &oldiocb->iocb;
4365 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4366 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4367 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4369 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
4370 pcmd += sizeof(uint32_t);
4371 *((uint32_t *) (pcmd)) = rejectError;
4374 elsiocb->context_un.mbox = mbox;
4376 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
4377 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4378 "0129 Xmit ELS RJT x%x response tag x%x "
4379 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
4381 rejectError, elsiocb->iotag,
4382 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
4383 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
4384 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4385 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
4386 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
4388 phba->fc_stat.elsXmitLSRJT++;
4389 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4390 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4392 if (rc == IOCB_ERROR) {
4393 lpfc_els_free_iocb(phba, elsiocb);
4400 * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
4401 * @vport: pointer to a virtual N_Port data structure.
4402 * @oldiocb: pointer to the original lpfc command iocb data structure.
4403 * @ndlp: pointer to a node-list data structure.
4405 * This routine prepares and issues an Accept (ACC) response to Address
4406 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
4407 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
4409 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4410 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4411 * will be stored into the context1 field of the IOCB for the completion
4412 * callback function to the ADISC Accept response ELS IOCB command.
4415 * 0 - Successfully issued acc adisc response
4416 * 1 - Failed to issue adisc acc response
4419 lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
4420 struct lpfc_nodelist *ndlp)
4422 struct lpfc_hba *phba = vport->phba;
4424 IOCB_t *icmd, *oldcmd;
4425 struct lpfc_iocbq *elsiocb;
4430 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
4431 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4432 ndlp->nlp_DID, ELS_CMD_ACC);
4436 icmd = &elsiocb->iocb;
4437 oldcmd = &oldiocb->iocb;
4438 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4439 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4441 /* Xmit ADISC ACC response tag <ulpIoTag> */
4442 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4443 "0130 Xmit ADISC ACC response iotag x%x xri: "
4444 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
4445 elsiocb->iotag, elsiocb->iocb.ulpContext,
4446 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4448 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4450 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4451 pcmd += sizeof(uint32_t);
4453 ap = (ADISC *) (pcmd);
4454 ap->hardAL_PA = phba->fc_pref_ALPA;
4455 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
4456 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
4457 ap->DID = be32_to_cpu(vport->fc_myDID);
4459 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4460 "Issue ACC ADISC: did:x%x flg:x%x",
4461 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4463 phba->fc_stat.elsXmitACC++;
4464 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4465 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4466 if (rc == IOCB_ERROR) {
4467 lpfc_els_free_iocb(phba, elsiocb);
4471 /* Xmit ELS ACC response tag <ulpIoTag> */
4472 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4473 "0128 Xmit ELS ACC response Status: x%x, IoTag: x%x, "
4474 "XRI: x%x, DID: x%x, nlp_flag: x%x nlp_state: x%x "
4475 "RPI: x%x, fc_flag x%x\n",
4476 rc, elsiocb->iotag, elsiocb->sli4_xritag,
4477 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4478 ndlp->nlp_rpi, vport->fc_flag);
4483 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
4484 * @vport: pointer to a virtual N_Port data structure.
4485 * @oldiocb: pointer to the original lpfc command iocb data structure.
4486 * @ndlp: pointer to a node-list data structure.
4488 * This routine prepares and issues an Accept (ACC) response to Process
4489 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
4490 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
4492 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4493 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4494 * will be stored into the context1 field of the IOCB for the completion
4495 * callback function to the PRLI Accept response ELS IOCB command.
4498 * 0 - Successfully issued acc prli response
4499 * 1 - Failed to issue acc prli response
4502 lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
4503 struct lpfc_nodelist *ndlp)
4505 struct lpfc_hba *phba = vport->phba;
4507 struct lpfc_nvme_prli *npr_nvme;
4511 struct lpfc_iocbq *elsiocb;
4514 uint32_t prli_fc4_req, *req_payload;
4515 struct lpfc_dmabuf *req_buf;
4519 /* Need the incoming PRLI payload to determine if the ACC is for an
4520 * FC4 or NVME PRLI type. The PRLI type is at word 1.
4522 req_buf = (struct lpfc_dmabuf *)oldiocb->context2;
4523 req_payload = (((uint32_t *)req_buf->virt) + 1);
4525 /* PRLI type payload is at byte 3 for FCP or NVME. */
4526 prli_fc4_req = be32_to_cpu(*req_payload);
4527 prli_fc4_req = (prli_fc4_req >> 24) & 0xff;
4528 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4529 "6127 PRLI_ACC: Req Type x%x, Word1 x%08x\n",
4530 prli_fc4_req, *((uint32_t *)req_payload));
4532 if (prli_fc4_req == PRLI_FCP_TYPE) {
4533 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
4534 elsrspcmd = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
4535 } else if (prli_fc4_req & PRLI_NVME_TYPE) {
4536 cmdsize = sizeof(uint32_t) + sizeof(struct lpfc_nvme_prli);
4537 elsrspcmd = (ELS_CMD_ACC | (ELS_CMD_NVMEPRLI & ~ELS_RSP_MASK));
4542 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4543 ndlp->nlp_DID, elsrspcmd);
4547 icmd = &elsiocb->iocb;
4548 oldcmd = &oldiocb->iocb;
4549 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4550 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4552 /* Xmit PRLI ACC response tag <ulpIoTag> */
4553 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4554 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
4555 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
4556 elsiocb->iotag, elsiocb->iocb.ulpContext,
4557 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4559 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4560 memset(pcmd, 0, cmdsize);
4562 *((uint32_t *)(pcmd)) = elsrspcmd;
4563 pcmd += sizeof(uint32_t);
4565 /* For PRLI, remainder of payload is PRLI parameter page */
4568 if (prli_fc4_req == PRLI_FCP_TYPE) {
4570 * If the remote port is a target and our firmware version
4571 * is 3.20 or later, set the following bits for FC-TAPE
4574 npr = (PRLI *) pcmd;
4575 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
4576 (vpd->rev.feaLevelHigh >= 0x02)) {
4577 npr->ConfmComplAllowed = 1;
4579 npr->TaskRetryIdReq = 1;
4581 npr->acceptRspCode = PRLI_REQ_EXECUTED;
4582 npr->estabImagePair = 1;
4583 npr->readXferRdyDis = 1;
4584 npr->ConfmComplAllowed = 1;
4585 npr->prliType = PRLI_FCP_TYPE;
4586 npr->initiatorFunc = 1;
4587 } else if (prli_fc4_req & PRLI_NVME_TYPE) {
4588 /* Respond with an NVME PRLI Type */
4589 npr_nvme = (struct lpfc_nvme_prli *) pcmd;
4590 bf_set(prli_type_code, npr_nvme, PRLI_NVME_TYPE);
4591 bf_set(prli_estabImagePair, npr_nvme, 0); /* Should be 0 */
4592 bf_set(prli_acc_rsp_code, npr_nvme, PRLI_REQ_EXECUTED);
4593 if (phba->nvmet_support) {
4594 bf_set(prli_tgt, npr_nvme, 1);
4595 bf_set(prli_disc, npr_nvme, 1);
4596 if (phba->cfg_nvme_enable_fb) {
4597 bf_set(prli_fba, npr_nvme, 1);
4599 /* TBD. Target mode needs to post buffers
4600 * that support the configured first burst
4603 bf_set(prli_fb_sz, npr_nvme,
4604 phba->cfg_nvmet_fb_size);
4607 bf_set(prli_init, npr_nvme, 1);
4610 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
4611 "6015 NVME issue PRLI ACC word1 x%08x "
4612 "word4 x%08x word5 x%08x flag x%x, "
4613 "fcp_info x%x nlp_type x%x\n",
4614 npr_nvme->word1, npr_nvme->word4,
4615 npr_nvme->word5, ndlp->nlp_flag,
4616 ndlp->nlp_fcp_info, ndlp->nlp_type);
4617 npr_nvme->word1 = cpu_to_be32(npr_nvme->word1);
4618 npr_nvme->word4 = cpu_to_be32(npr_nvme->word4);
4619 npr_nvme->word5 = cpu_to_be32(npr_nvme->word5);
4621 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4622 "6128 Unknown FC_TYPE x%x x%x ndlp x%06x\n",
4623 prli_fc4_req, ndlp->nlp_fc4_type,
4626 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4627 "Issue ACC PRLI: did:x%x flg:x%x",
4628 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4630 phba->fc_stat.elsXmitACC++;
4631 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4633 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4634 if (rc == IOCB_ERROR) {
4635 lpfc_els_free_iocb(phba, elsiocb);
4642 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
4643 * @vport: pointer to a virtual N_Port data structure.
4644 * @format: rnid command format.
4645 * @oldiocb: pointer to the original lpfc command iocb data structure.
4646 * @ndlp: pointer to a node-list data structure.
4648 * This routine issues a Request Node Identification Data (RNID) Accept
4649 * (ACC) response. It constructs the RNID ACC response command according to
4650 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
4651 * issue the response. Note that this command does not need to hold the ndlp
4652 * reference count for the callback. So, the ndlp reference count taken by
4653 * the lpfc_prep_els_iocb() routine is put back and the context1 field of
4654 * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
4655 * there is no ndlp reference available.
4657 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4658 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4659 * will be stored into the context1 field of the IOCB for the completion
4660 * callback function. However, for the RNID Accept Response ELS command,
4661 * this is undone later by this routine after the IOCB is allocated.
4664 * 0 - Successfully issued acc rnid response
4665 * 1 - Failed to issue acc rnid response
4668 lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
4669 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
4671 struct lpfc_hba *phba = vport->phba;
4673 IOCB_t *icmd, *oldcmd;
4674 struct lpfc_iocbq *elsiocb;
4679 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
4680 + (2 * sizeof(struct lpfc_name));
4682 cmdsize += sizeof(RNID_TOP_DISC);
4684 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4685 ndlp->nlp_DID, ELS_CMD_ACC);
4689 icmd = &elsiocb->iocb;
4690 oldcmd = &oldiocb->iocb;
4691 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4692 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4694 /* Xmit RNID ACC response tag <ulpIoTag> */
4695 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4696 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
4697 elsiocb->iotag, elsiocb->iocb.ulpContext);
4698 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4699 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4700 pcmd += sizeof(uint32_t);
4702 memset(pcmd, 0, sizeof(RNID));
4703 rn = (RNID *) (pcmd);
4704 rn->Format = format;
4705 rn->CommonLen = (2 * sizeof(struct lpfc_name));
4706 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
4707 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
4710 rn->SpecificLen = 0;
4712 case RNID_TOPOLOGY_DISC:
4713 rn->SpecificLen = sizeof(RNID_TOP_DISC);
4714 memcpy(&rn->un.topologyDisc.portName,
4715 &vport->fc_portname, sizeof(struct lpfc_name));
4716 rn->un.topologyDisc.unitType = RNID_HBA;
4717 rn->un.topologyDisc.physPort = 0;
4718 rn->un.topologyDisc.attachedNodes = 0;
4722 rn->SpecificLen = 0;
4726 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4727 "Issue ACC RNID: did:x%x flg:x%x",
4728 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4730 phba->fc_stat.elsXmitACC++;
4731 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4733 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4734 if (rc == IOCB_ERROR) {
4735 lpfc_els_free_iocb(phba, elsiocb);
4742 * lpfc_els_clear_rrq - Clear the rq that this rrq describes.
4743 * @vport: pointer to a virtual N_Port data structure.
4744 * @iocb: pointer to the lpfc command iocb data structure.
4745 * @ndlp: pointer to a node-list data structure.
4750 lpfc_els_clear_rrq(struct lpfc_vport *vport,
4751 struct lpfc_iocbq *iocb, struct lpfc_nodelist *ndlp)
4753 struct lpfc_hba *phba = vport->phba;
4758 struct lpfc_node_rrq *prrq;
4761 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) iocb->context2)->virt);
4762 pcmd += sizeof(uint32_t);
4763 rrq = (struct RRQ *)pcmd;
4764 rrq->rrq_exchg = be32_to_cpu(rrq->rrq_exchg);
4765 rxid = bf_get(rrq_rxid, rrq);
4767 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4768 "2883 Clear RRQ for SID:x%x OXID:x%x RXID:x%x"
4770 be32_to_cpu(bf_get(rrq_did, rrq)),
4771 bf_get(rrq_oxid, rrq),
4773 iocb->iotag, iocb->iocb.ulpContext);
4775 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4776 "Clear RRQ: did:x%x flg:x%x exchg:x%.08x",
4777 ndlp->nlp_DID, ndlp->nlp_flag, rrq->rrq_exchg);
4778 if (vport->fc_myDID == be32_to_cpu(bf_get(rrq_did, rrq)))
4779 xri = bf_get(rrq_oxid, rrq);
4782 prrq = lpfc_get_active_rrq(vport, xri, ndlp->nlp_DID);
4784 lpfc_clr_rrq_active(phba, xri, prrq);
4789 * lpfc_els_rsp_echo_acc - Issue echo acc response
4790 * @vport: pointer to a virtual N_Port data structure.
4791 * @data: pointer to echo data to return in the accept.
4792 * @oldiocb: pointer to the original lpfc command iocb data structure.
4793 * @ndlp: pointer to a node-list data structure.
4796 * 0 - Successfully issued acc echo response
4797 * 1 - Failed to issue acc echo response
4800 lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data,
4801 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
4803 struct lpfc_hba *phba = vport->phba;
4804 struct lpfc_iocbq *elsiocb;
4809 cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len;
4811 /* The accumulated length can exceed the BPL_SIZE. For
4812 * now, use this as the limit
4814 if (cmdsize > LPFC_BPL_SIZE)
4815 cmdsize = LPFC_BPL_SIZE;
4816 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4817 ndlp->nlp_DID, ELS_CMD_ACC);
4821 elsiocb->iocb.ulpContext = oldiocb->iocb.ulpContext; /* Xri / rx_id */
4822 elsiocb->iocb.unsli3.rcvsli3.ox_id = oldiocb->iocb.unsli3.rcvsli3.ox_id;
4824 /* Xmit ECHO ACC response tag <ulpIoTag> */
4825 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4826 "2876 Xmit ECHO ACC response tag x%x xri x%x\n",
4827 elsiocb->iotag, elsiocb->iocb.ulpContext);
4828 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4829 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4830 pcmd += sizeof(uint32_t);
4831 memcpy(pcmd, data, cmdsize - sizeof(uint32_t));
4833 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4834 "Issue ACC ECHO: did:x%x flg:x%x",
4835 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4837 phba->fc_stat.elsXmitACC++;
4838 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4840 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4841 if (rc == IOCB_ERROR) {
4842 lpfc_els_free_iocb(phba, elsiocb);
4849 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
4850 * @vport: pointer to a host virtual N_Port data structure.
4852 * This routine issues Address Discover (ADISC) ELS commands to those
4853 * N_Ports which are in node port recovery state and ADISC has not been issued
4854 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
4855 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
4856 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
4857 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
4858 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
4859 * IOCBs quit for later pick up. On the other hand, after walking through
4860 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
4861 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
4862 * no more ADISC need to be sent.
4865 * The number of N_Ports with adisc issued.
4868 lpfc_els_disc_adisc(struct lpfc_vport *vport)
4870 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4871 struct lpfc_nodelist *ndlp, *next_ndlp;
4874 /* go thru NPR nodes and issue any remaining ELS ADISCs */
4875 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
4876 if (!NLP_CHK_NODE_ACT(ndlp))
4878 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
4879 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
4880 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
4881 spin_lock_irq(shost->host_lock);
4882 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
4883 spin_unlock_irq(shost->host_lock);
4884 ndlp->nlp_prev_state = ndlp->nlp_state;
4885 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
4886 lpfc_issue_els_adisc(vport, ndlp, 0);
4888 vport->num_disc_nodes++;
4889 if (vport->num_disc_nodes >=
4890 vport->cfg_discovery_threads) {
4891 spin_lock_irq(shost->host_lock);
4892 vport->fc_flag |= FC_NLP_MORE;
4893 spin_unlock_irq(shost->host_lock);
4898 if (sentadisc == 0) {
4899 spin_lock_irq(shost->host_lock);
4900 vport->fc_flag &= ~FC_NLP_MORE;
4901 spin_unlock_irq(shost->host_lock);
4907 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
4908 * @vport: pointer to a host virtual N_Port data structure.
4910 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
4911 * which are in node port recovery state, with a @vport. Each time an ELS
4912 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
4913 * the per @vport number of discover count (num_disc_nodes) shall be
4914 * incremented. If the num_disc_nodes reaches a pre-configured threshold
4915 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
4916 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
4917 * later pick up. On the other hand, after walking through all the ndlps with
4918 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
4919 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
4920 * PLOGI need to be sent.
4923 * The number of N_Ports with plogi issued.
4926 lpfc_els_disc_plogi(struct lpfc_vport *vport)
4928 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4929 struct lpfc_nodelist *ndlp, *next_ndlp;
4932 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
4933 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
4934 if (!NLP_CHK_NODE_ACT(ndlp))
4936 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
4937 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
4938 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
4939 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
4940 ndlp->nlp_prev_state = ndlp->nlp_state;
4941 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
4942 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
4944 vport->num_disc_nodes++;
4945 if (vport->num_disc_nodes >=
4946 vport->cfg_discovery_threads) {
4947 spin_lock_irq(shost->host_lock);
4948 vport->fc_flag |= FC_NLP_MORE;
4949 spin_unlock_irq(shost->host_lock);
4955 lpfc_set_disctmo(vport);
4958 spin_lock_irq(shost->host_lock);
4959 vport->fc_flag &= ~FC_NLP_MORE;
4960 spin_unlock_irq(shost->host_lock);
4966 lpfc_rdp_res_link_service(struct fc_rdp_link_service_desc *desc,
4970 desc->tag = cpu_to_be32(RDP_LINK_SERVICE_DESC_TAG);
4971 desc->payload.els_req = word0;
4972 desc->length = cpu_to_be32(sizeof(desc->payload));
4974 return sizeof(struct fc_rdp_link_service_desc);
4978 lpfc_rdp_res_sfp_desc(struct fc_rdp_sfp_desc *desc,
4979 uint8_t *page_a0, uint8_t *page_a2)
4981 uint16_t wavelength;
4982 uint16_t temperature;
4988 struct sff_trasnceiver_codes_byte4 *trasn_code_byte4;
4989 struct sff_trasnceiver_codes_byte5 *trasn_code_byte5;
4991 desc->tag = cpu_to_be32(RDP_SFP_DESC_TAG);
4993 trasn_code_byte4 = (struct sff_trasnceiver_codes_byte4 *)
4994 &page_a0[SSF_TRANSCEIVER_CODE_B4];
4995 trasn_code_byte5 = (struct sff_trasnceiver_codes_byte5 *)
4996 &page_a0[SSF_TRANSCEIVER_CODE_B5];
4998 if ((trasn_code_byte4->fc_sw_laser) ||
4999 (trasn_code_byte5->fc_sw_laser_sl) ||
5000 (trasn_code_byte5->fc_sw_laser_sn)) { /* check if its short WL */
5001 flag |= (SFP_FLAG_PT_SWLASER << SFP_FLAG_PT_SHIFT);
5002 } else if (trasn_code_byte4->fc_lw_laser) {
5003 wavelength = (page_a0[SSF_WAVELENGTH_B1] << 8) |
5004 page_a0[SSF_WAVELENGTH_B0];
5005 if (wavelength == SFP_WAVELENGTH_LC1310)
5006 flag |= SFP_FLAG_PT_LWLASER_LC1310 << SFP_FLAG_PT_SHIFT;
5007 if (wavelength == SFP_WAVELENGTH_LL1550)
5008 flag |= SFP_FLAG_PT_LWLASER_LL1550 << SFP_FLAG_PT_SHIFT;
5010 /* check if its SFP+ */
5011 flag |= ((page_a0[SSF_IDENTIFIER] == SFF_PG0_IDENT_SFP) ?
5012 SFP_FLAG_CT_SFP_PLUS : SFP_FLAG_CT_UNKNOWN)
5013 << SFP_FLAG_CT_SHIFT;
5015 /* check if its OPTICAL */
5016 flag |= ((page_a0[SSF_CONNECTOR] == SFF_PG0_CONNECTOR_LC) ?
5017 SFP_FLAG_IS_OPTICAL_PORT : 0)
5018 << SFP_FLAG_IS_OPTICAL_SHIFT;
5020 temperature = (page_a2[SFF_TEMPERATURE_B1] << 8 |
5021 page_a2[SFF_TEMPERATURE_B0]);
5022 vcc = (page_a2[SFF_VCC_B1] << 8 |
5023 page_a2[SFF_VCC_B0]);
5024 tx_power = (page_a2[SFF_TXPOWER_B1] << 8 |
5025 page_a2[SFF_TXPOWER_B0]);
5026 tx_bias = (page_a2[SFF_TX_BIAS_CURRENT_B1] << 8 |
5027 page_a2[SFF_TX_BIAS_CURRENT_B0]);
5028 rx_power = (page_a2[SFF_RXPOWER_B1] << 8 |
5029 page_a2[SFF_RXPOWER_B0]);
5030 desc->sfp_info.temperature = cpu_to_be16(temperature);
5031 desc->sfp_info.rx_power = cpu_to_be16(rx_power);
5032 desc->sfp_info.tx_bias = cpu_to_be16(tx_bias);
5033 desc->sfp_info.tx_power = cpu_to_be16(tx_power);
5034 desc->sfp_info.vcc = cpu_to_be16(vcc);
5036 desc->sfp_info.flags = cpu_to_be16(flag);
5037 desc->length = cpu_to_be32(sizeof(desc->sfp_info));
5039 return sizeof(struct fc_rdp_sfp_desc);
5043 lpfc_rdp_res_link_error(struct fc_rdp_link_error_status_desc *desc,
5048 desc->tag = cpu_to_be32(RDP_LINK_ERROR_STATUS_DESC_TAG);
5050 type = VN_PT_PHY_PF_PORT << VN_PT_PHY_SHIFT;
5052 desc->info.port_type = cpu_to_be32(type);
5054 desc->info.link_status.link_failure_cnt =
5055 cpu_to_be32(stat->linkFailureCnt);
5056 desc->info.link_status.loss_of_synch_cnt =
5057 cpu_to_be32(stat->lossSyncCnt);
5058 desc->info.link_status.loss_of_signal_cnt =
5059 cpu_to_be32(stat->lossSignalCnt);
5060 desc->info.link_status.primitive_seq_proto_err =
5061 cpu_to_be32(stat->primSeqErrCnt);
5062 desc->info.link_status.invalid_trans_word =
5063 cpu_to_be32(stat->invalidXmitWord);
5064 desc->info.link_status.invalid_crc_cnt = cpu_to_be32(stat->crcCnt);
5066 desc->length = cpu_to_be32(sizeof(desc->info));
5068 return sizeof(struct fc_rdp_link_error_status_desc);
5072 lpfc_rdp_res_bbc_desc(struct fc_rdp_bbc_desc *desc, READ_LNK_VAR *stat,
5073 struct lpfc_vport *vport)
5077 desc->tag = cpu_to_be32(RDP_BBC_DESC_TAG);
5079 bbCredit = vport->fc_sparam.cmn.bbCreditLsb |
5080 (vport->fc_sparam.cmn.bbCreditMsb << 8);
5081 desc->bbc_info.port_bbc = cpu_to_be32(bbCredit);
5082 if (vport->phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
5083 bbCredit = vport->phba->fc_fabparam.cmn.bbCreditLsb |
5084 (vport->phba->fc_fabparam.cmn.bbCreditMsb << 8);
5085 desc->bbc_info.attached_port_bbc = cpu_to_be32(bbCredit);
5087 desc->bbc_info.attached_port_bbc = 0;
5090 desc->bbc_info.rtt = 0;
5091 desc->length = cpu_to_be32(sizeof(desc->bbc_info));
5093 return sizeof(struct fc_rdp_bbc_desc);
5097 lpfc_rdp_res_oed_temp_desc(struct lpfc_hba *phba,
5098 struct fc_rdp_oed_sfp_desc *desc, uint8_t *page_a2)
5102 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5104 desc->oed_info.hi_alarm = page_a2[SSF_TEMP_HIGH_ALARM];
5105 desc->oed_info.lo_alarm = page_a2[SSF_TEMP_LOW_ALARM];
5106 desc->oed_info.hi_warning = page_a2[SSF_TEMP_HIGH_WARNING];
5107 desc->oed_info.lo_warning = page_a2[SSF_TEMP_LOW_WARNING];
5109 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TEMPERATURE)
5110 flags |= RDP_OET_HIGH_ALARM;
5111 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TEMPERATURE)
5112 flags |= RDP_OET_LOW_ALARM;
5113 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TEMPERATURE)
5114 flags |= RDP_OET_HIGH_WARNING;
5115 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TEMPERATURE)
5116 flags |= RDP_OET_LOW_WARNING;
5118 flags |= ((0xf & RDP_OED_TEMPERATURE) << RDP_OED_TYPE_SHIFT);
5119 desc->oed_info.function_flags = cpu_to_be32(flags);
5120 desc->length = cpu_to_be32(sizeof(desc->oed_info));
5121 return sizeof(struct fc_rdp_oed_sfp_desc);
5125 lpfc_rdp_res_oed_voltage_desc(struct lpfc_hba *phba,
5126 struct fc_rdp_oed_sfp_desc *desc,
5131 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5133 desc->oed_info.hi_alarm = page_a2[SSF_VOLTAGE_HIGH_ALARM];
5134 desc->oed_info.lo_alarm = page_a2[SSF_VOLTAGE_LOW_ALARM];
5135 desc->oed_info.hi_warning = page_a2[SSF_VOLTAGE_HIGH_WARNING];
5136 desc->oed_info.lo_warning = page_a2[SSF_VOLTAGE_LOW_WARNING];
5138 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_VOLTAGE)
5139 flags |= RDP_OET_HIGH_ALARM;
5140 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_VOLTAGE)
5141 flags |= RDP_OET_LOW_ALARM;
5142 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_VOLTAGE)
5143 flags |= RDP_OET_HIGH_WARNING;
5144 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_VOLTAGE)
5145 flags |= RDP_OET_LOW_WARNING;
5147 flags |= ((0xf & RDP_OED_VOLTAGE) << RDP_OED_TYPE_SHIFT);
5148 desc->oed_info.function_flags = cpu_to_be32(flags);
5149 desc->length = cpu_to_be32(sizeof(desc->oed_info));
5150 return sizeof(struct fc_rdp_oed_sfp_desc);
5154 lpfc_rdp_res_oed_txbias_desc(struct lpfc_hba *phba,
5155 struct fc_rdp_oed_sfp_desc *desc,
5160 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5162 desc->oed_info.hi_alarm = page_a2[SSF_BIAS_HIGH_ALARM];
5163 desc->oed_info.lo_alarm = page_a2[SSF_BIAS_LOW_ALARM];
5164 desc->oed_info.hi_warning = page_a2[SSF_BIAS_HIGH_WARNING];
5165 desc->oed_info.lo_warning = page_a2[SSF_BIAS_LOW_WARNING];
5167 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TXBIAS)
5168 flags |= RDP_OET_HIGH_ALARM;
5169 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TXBIAS)
5170 flags |= RDP_OET_LOW_ALARM;
5171 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TXBIAS)
5172 flags |= RDP_OET_HIGH_WARNING;
5173 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TXBIAS)
5174 flags |= RDP_OET_LOW_WARNING;
5176 flags |= ((0xf & RDP_OED_TXBIAS) << RDP_OED_TYPE_SHIFT);
5177 desc->oed_info.function_flags = cpu_to_be32(flags);
5178 desc->length = cpu_to_be32(sizeof(desc->oed_info));
5179 return sizeof(struct fc_rdp_oed_sfp_desc);
5183 lpfc_rdp_res_oed_txpower_desc(struct lpfc_hba *phba,
5184 struct fc_rdp_oed_sfp_desc *desc,
5189 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5191 desc->oed_info.hi_alarm = page_a2[SSF_TXPOWER_HIGH_ALARM];
5192 desc->oed_info.lo_alarm = page_a2[SSF_TXPOWER_LOW_ALARM];
5193 desc->oed_info.hi_warning = page_a2[SSF_TXPOWER_HIGH_WARNING];
5194 desc->oed_info.lo_warning = page_a2[SSF_TXPOWER_LOW_WARNING];
5196 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TXPOWER)
5197 flags |= RDP_OET_HIGH_ALARM;
5198 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TXPOWER)
5199 flags |= RDP_OET_LOW_ALARM;
5200 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TXPOWER)
5201 flags |= RDP_OET_HIGH_WARNING;
5202 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TXPOWER)
5203 flags |= RDP_OET_LOW_WARNING;
5205 flags |= ((0xf & RDP_OED_TXPOWER) << RDP_OED_TYPE_SHIFT);
5206 desc->oed_info.function_flags = cpu_to_be32(flags);
5207 desc->length = cpu_to_be32(sizeof(desc->oed_info));
5208 return sizeof(struct fc_rdp_oed_sfp_desc);
5213 lpfc_rdp_res_oed_rxpower_desc(struct lpfc_hba *phba,
5214 struct fc_rdp_oed_sfp_desc *desc,
5219 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5221 desc->oed_info.hi_alarm = page_a2[SSF_RXPOWER_HIGH_ALARM];
5222 desc->oed_info.lo_alarm = page_a2[SSF_RXPOWER_LOW_ALARM];
5223 desc->oed_info.hi_warning = page_a2[SSF_RXPOWER_HIGH_WARNING];
5224 desc->oed_info.lo_warning = page_a2[SSF_RXPOWER_LOW_WARNING];
5226 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_RXPOWER)
5227 flags |= RDP_OET_HIGH_ALARM;
5228 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_RXPOWER)
5229 flags |= RDP_OET_LOW_ALARM;
5230 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_RXPOWER)
5231 flags |= RDP_OET_HIGH_WARNING;
5232 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_RXPOWER)
5233 flags |= RDP_OET_LOW_WARNING;
5235 flags |= ((0xf & RDP_OED_RXPOWER) << RDP_OED_TYPE_SHIFT);
5236 desc->oed_info.function_flags = cpu_to_be32(flags);
5237 desc->length = cpu_to_be32(sizeof(desc->oed_info));
5238 return sizeof(struct fc_rdp_oed_sfp_desc);
5242 lpfc_rdp_res_opd_desc(struct fc_rdp_opd_sfp_desc *desc,
5243 uint8_t *page_a0, struct lpfc_vport *vport)
5245 desc->tag = cpu_to_be32(RDP_OPD_DESC_TAG);
5246 memcpy(desc->opd_info.vendor_name, &page_a0[SSF_VENDOR_NAME], 16);
5247 memcpy(desc->opd_info.model_number, &page_a0[SSF_VENDOR_PN], 16);
5248 memcpy(desc->opd_info.serial_number, &page_a0[SSF_VENDOR_SN], 16);
5249 memcpy(desc->opd_info.revision, &page_a0[SSF_VENDOR_REV], 4);
5250 memcpy(desc->opd_info.date, &page_a0[SSF_DATE_CODE], 8);
5251 desc->length = cpu_to_be32(sizeof(desc->opd_info));
5252 return sizeof(struct fc_rdp_opd_sfp_desc);
5256 lpfc_rdp_res_fec_desc(struct fc_fec_rdp_desc *desc, READ_LNK_VAR *stat)
5258 if (bf_get(lpfc_read_link_stat_gec2, stat) == 0)
5260 desc->tag = cpu_to_be32(RDP_FEC_DESC_TAG);
5262 desc->info.CorrectedBlocks =
5263 cpu_to_be32(stat->fecCorrBlkCount);
5264 desc->info.UncorrectableBlocks =
5265 cpu_to_be32(stat->fecUncorrBlkCount);
5267 desc->length = cpu_to_be32(sizeof(desc->info));
5269 return sizeof(struct fc_fec_rdp_desc);
5273 lpfc_rdp_res_speed(struct fc_rdp_port_speed_desc *desc, struct lpfc_hba *phba)
5275 uint16_t rdp_cap = 0;
5278 desc->tag = cpu_to_be32(RDP_PORT_SPEED_DESC_TAG);
5280 switch (phba->fc_linkspeed) {
5281 case LPFC_LINK_SPEED_1GHZ:
5282 rdp_speed = RDP_PS_1GB;
5284 case LPFC_LINK_SPEED_2GHZ:
5285 rdp_speed = RDP_PS_2GB;
5287 case LPFC_LINK_SPEED_4GHZ:
5288 rdp_speed = RDP_PS_4GB;
5290 case LPFC_LINK_SPEED_8GHZ:
5291 rdp_speed = RDP_PS_8GB;
5293 case LPFC_LINK_SPEED_10GHZ:
5294 rdp_speed = RDP_PS_10GB;
5296 case LPFC_LINK_SPEED_16GHZ:
5297 rdp_speed = RDP_PS_16GB;
5299 case LPFC_LINK_SPEED_32GHZ:
5300 rdp_speed = RDP_PS_32GB;
5302 case LPFC_LINK_SPEED_64GHZ:
5303 rdp_speed = RDP_PS_64GB;
5306 rdp_speed = RDP_PS_UNKNOWN;
5310 desc->info.port_speed.speed = cpu_to_be16(rdp_speed);
5312 if (phba->lmt & LMT_64Gb)
5313 rdp_cap |= RDP_PS_64GB;
5314 if (phba->lmt & LMT_32Gb)
5315 rdp_cap |= RDP_PS_32GB;
5316 if (phba->lmt & LMT_16Gb)
5317 rdp_cap |= RDP_PS_16GB;
5318 if (phba->lmt & LMT_10Gb)
5319 rdp_cap |= RDP_PS_10GB;
5320 if (phba->lmt & LMT_8Gb)
5321 rdp_cap |= RDP_PS_8GB;
5322 if (phba->lmt & LMT_4Gb)
5323 rdp_cap |= RDP_PS_4GB;
5324 if (phba->lmt & LMT_2Gb)
5325 rdp_cap |= RDP_PS_2GB;
5326 if (phba->lmt & LMT_1Gb)
5327 rdp_cap |= RDP_PS_1GB;
5330 rdp_cap = RDP_CAP_UNKNOWN;
5331 if (phba->cfg_link_speed != LPFC_USER_LINK_SPEED_AUTO)
5332 rdp_cap |= RDP_CAP_USER_CONFIGURED;
5334 desc->info.port_speed.capabilities = cpu_to_be16(rdp_cap);
5335 desc->length = cpu_to_be32(sizeof(desc->info));
5336 return sizeof(struct fc_rdp_port_speed_desc);
5340 lpfc_rdp_res_diag_port_names(struct fc_rdp_port_name_desc *desc,
5341 struct lpfc_vport *vport)
5344 desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG);
5346 memcpy(desc->port_names.wwnn, &vport->fc_nodename,
5347 sizeof(desc->port_names.wwnn));
5349 memcpy(desc->port_names.wwpn, &vport->fc_portname,
5350 sizeof(desc->port_names.wwpn));
5352 desc->length = cpu_to_be32(sizeof(desc->port_names));
5353 return sizeof(struct fc_rdp_port_name_desc);
5357 lpfc_rdp_res_attach_port_names(struct fc_rdp_port_name_desc *desc,
5358 struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
5361 desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG);
5362 if (vport->fc_flag & FC_FABRIC) {
5363 memcpy(desc->port_names.wwnn, &vport->fabric_nodename,
5364 sizeof(desc->port_names.wwnn));
5366 memcpy(desc->port_names.wwpn, &vport->fabric_portname,
5367 sizeof(desc->port_names.wwpn));
5368 } else { /* Point to Point */
5369 memcpy(desc->port_names.wwnn, &ndlp->nlp_nodename,
5370 sizeof(desc->port_names.wwnn));
5372 memcpy(desc->port_names.wwnn, &ndlp->nlp_portname,
5373 sizeof(desc->port_names.wwpn));
5376 desc->length = cpu_to_be32(sizeof(desc->port_names));
5377 return sizeof(struct fc_rdp_port_name_desc);
5381 lpfc_els_rdp_cmpl(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context,
5384 struct lpfc_nodelist *ndlp = rdp_context->ndlp;
5385 struct lpfc_vport *vport = ndlp->vport;
5386 struct lpfc_iocbq *elsiocb;
5387 struct ulp_bde64 *bpl;
5390 struct ls_rjt *stat;
5391 struct fc_rdp_res_frame *rdp_res;
5392 uint32_t cmdsize, len;
5396 if (status != SUCCESS)
5399 /* This will change once we know the true size of the RDP payload */
5400 cmdsize = sizeof(struct fc_rdp_res_frame);
5402 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize,
5403 lpfc_max_els_tries, rdp_context->ndlp,
5404 rdp_context->ndlp->nlp_DID, ELS_CMD_ACC);
5407 goto free_rdp_context;
5409 icmd = &elsiocb->iocb;
5410 icmd->ulpContext = rdp_context->rx_id;
5411 icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id;
5413 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5414 "2171 Xmit RDP response tag x%x xri x%x, "
5415 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x",
5416 elsiocb->iotag, elsiocb->iocb.ulpContext,
5417 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5419 rdp_res = (struct fc_rdp_res_frame *)
5420 (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5421 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5422 memset(pcmd, 0, sizeof(struct fc_rdp_res_frame));
5423 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5425 /* Update Alarm and Warning */
5426 flag_ptr = (uint16_t *)(rdp_context->page_a2 + SSF_ALARM_FLAGS);
5427 phba->sfp_alarm |= *flag_ptr;
5428 flag_ptr = (uint16_t *)(rdp_context->page_a2 + SSF_WARNING_FLAGS);
5429 phba->sfp_warning |= *flag_ptr;
5431 /* For RDP payload */
5433 len += lpfc_rdp_res_link_service((struct fc_rdp_link_service_desc *)
5434 (len + pcmd), ELS_CMD_RDP);
5436 len += lpfc_rdp_res_sfp_desc((struct fc_rdp_sfp_desc *)(len + pcmd),
5437 rdp_context->page_a0, rdp_context->page_a2);
5438 len += lpfc_rdp_res_speed((struct fc_rdp_port_speed_desc *)(len + pcmd),
5440 len += lpfc_rdp_res_link_error((struct fc_rdp_link_error_status_desc *)
5441 (len + pcmd), &rdp_context->link_stat);
5442 len += lpfc_rdp_res_diag_port_names((struct fc_rdp_port_name_desc *)
5443 (len + pcmd), vport);
5444 len += lpfc_rdp_res_attach_port_names((struct fc_rdp_port_name_desc *)
5445 (len + pcmd), vport, ndlp);
5446 len += lpfc_rdp_res_fec_desc((struct fc_fec_rdp_desc *)(len + pcmd),
5447 &rdp_context->link_stat);
5448 len += lpfc_rdp_res_bbc_desc((struct fc_rdp_bbc_desc *)(len + pcmd),
5449 &rdp_context->link_stat, vport);
5450 len += lpfc_rdp_res_oed_temp_desc(phba,
5451 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5452 rdp_context->page_a2);
5453 len += lpfc_rdp_res_oed_voltage_desc(phba,
5454 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5455 rdp_context->page_a2);
5456 len += lpfc_rdp_res_oed_txbias_desc(phba,
5457 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5458 rdp_context->page_a2);
5459 len += lpfc_rdp_res_oed_txpower_desc(phba,
5460 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5461 rdp_context->page_a2);
5462 len += lpfc_rdp_res_oed_rxpower_desc(phba,
5463 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5464 rdp_context->page_a2);
5465 len += lpfc_rdp_res_opd_desc((struct fc_rdp_opd_sfp_desc *)(len + pcmd),
5466 rdp_context->page_a0, vport);
5468 rdp_res->length = cpu_to_be32(len - 8);
5469 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5471 /* Now that we know the true size of the payload, update the BPL */
5472 bpl = (struct ulp_bde64 *)
5473 (((struct lpfc_dmabuf *)(elsiocb->context3))->virt);
5474 bpl->tus.f.bdeSize = len;
5475 bpl->tus.f.bdeFlags = 0;
5476 bpl->tus.w = le32_to_cpu(bpl->tus.w);
5478 phba->fc_stat.elsXmitACC++;
5479 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5480 if (rc == IOCB_ERROR)
5481 lpfc_els_free_iocb(phba, elsiocb);
5487 cmdsize = 2 * sizeof(uint32_t);
5488 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, lpfc_max_els_tries,
5489 ndlp, ndlp->nlp_DID, ELS_CMD_LS_RJT);
5492 goto free_rdp_context;
5494 icmd = &elsiocb->iocb;
5495 icmd->ulpContext = rdp_context->rx_id;
5496 icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id;
5497 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5499 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
5500 stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t));
5501 stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5503 phba->fc_stat.elsXmitLSRJT++;
5504 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5505 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5507 if (rc == IOCB_ERROR)
5508 lpfc_els_free_iocb(phba, elsiocb);
5514 lpfc_get_rdp_info(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context)
5516 LPFC_MBOXQ_t *mbox = NULL;
5519 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5521 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_ELS,
5522 "7105 failed to allocate mailbox memory");
5526 if (lpfc_sli4_dump_page_a0(phba, mbox))
5527 goto prep_mbox_fail;
5528 mbox->vport = rdp_context->ndlp->vport;
5529 mbox->mbox_cmpl = lpfc_mbx_cmpl_rdp_page_a0;
5530 mbox->context2 = (struct lpfc_rdp_context *) rdp_context;
5531 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
5532 if (rc == MBX_NOT_FINISHED)
5533 goto issue_mbox_fail;
5539 mempool_free(mbox, phba->mbox_mem_pool);
5544 * lpfc_els_rcv_rdp - Process an unsolicited RDP ELS.
5545 * @vport: pointer to a host virtual N_Port data structure.
5546 * @cmdiocb: pointer to lpfc command iocb data structure.
5547 * @ndlp: pointer to a node-list data structure.
5549 * This routine processes an unsolicited RDP(Read Diagnostic Parameters)
5550 * IOCB. First, the payload of the unsolicited RDP is checked.
5551 * Then it will (1) send MBX_DUMP_MEMORY, Embedded DMP_LMSD sub command TYPE-3
5552 * for Page A0, (2) send MBX_DUMP_MEMORY, DMP_LMSD for Page A2,
5553 * (3) send MBX_READ_LNK_STAT to get link stat, (4) Call lpfc_els_rdp_cmpl
5554 * gather all data and send RDP response.
5557 * 0 - Sent the acc response
5558 * 1 - Sent the reject response.
5561 lpfc_els_rcv_rdp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5562 struct lpfc_nodelist *ndlp)
5564 struct lpfc_hba *phba = vport->phba;
5565 struct lpfc_dmabuf *pcmd;
5566 uint8_t rjt_err, rjt_expl = LSEXP_NOTHING_MORE;
5567 struct fc_rdp_req_frame *rdp_req;
5568 struct lpfc_rdp_context *rdp_context;
5572 if (phba->sli_rev < LPFC_SLI_REV4 ||
5573 bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
5574 LPFC_SLI_INTF_IF_TYPE_2) {
5575 rjt_err = LSRJT_UNABLE_TPC;
5576 rjt_expl = LSEXP_REQ_UNSUPPORTED;
5580 if (phba->sli_rev < LPFC_SLI_REV4 || (phba->hba_flag & HBA_FCOE_MODE)) {
5581 rjt_err = LSRJT_UNABLE_TPC;
5582 rjt_expl = LSEXP_REQ_UNSUPPORTED;
5586 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5587 rdp_req = (struct fc_rdp_req_frame *) pcmd->virt;
5589 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5590 "2422 ELS RDP Request "
5591 "dec len %d tag x%x port_id %d len %d\n",
5592 be32_to_cpu(rdp_req->rdp_des_length),
5593 be32_to_cpu(rdp_req->nport_id_desc.tag),
5594 be32_to_cpu(rdp_req->nport_id_desc.nport_id),
5595 be32_to_cpu(rdp_req->nport_id_desc.length));
5597 if (sizeof(struct fc_rdp_nport_desc) !=
5598 be32_to_cpu(rdp_req->rdp_des_length))
5600 if (RDP_N_PORT_DESC_TAG != be32_to_cpu(rdp_req->nport_id_desc.tag))
5602 if (RDP_NPORT_ID_SIZE !=
5603 be32_to_cpu(rdp_req->nport_id_desc.length))
5605 rdp_context = kzalloc(sizeof(struct lpfc_rdp_context), GFP_KERNEL);
5607 rjt_err = LSRJT_UNABLE_TPC;
5611 cmd = &cmdiocb->iocb;
5612 rdp_context->ndlp = lpfc_nlp_get(ndlp);
5613 rdp_context->ox_id = cmd->unsli3.rcvsli3.ox_id;
5614 rdp_context->rx_id = cmd->ulpContext;
5615 rdp_context->cmpl = lpfc_els_rdp_cmpl;
5616 if (lpfc_get_rdp_info(phba, rdp_context)) {
5617 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_ELS,
5618 "2423 Unable to send mailbox");
5620 rjt_err = LSRJT_UNABLE_TPC;
5628 rjt_err = LSRJT_LOGICAL_ERR;
5631 memset(&stat, 0, sizeof(stat));
5632 stat.un.b.lsRjtRsnCode = rjt_err;
5633 stat.un.b.lsRjtRsnCodeExp = rjt_expl;
5634 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5640 lpfc_els_lcb_rsp(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
5645 struct lpfc_iocbq *elsiocb;
5646 struct lpfc_nodelist *ndlp;
5647 struct ls_rjt *stat;
5648 union lpfc_sli4_cfg_shdr *shdr;
5649 struct lpfc_lcb_context *lcb_context;
5650 struct fc_lcb_res_frame *lcb_res;
5651 uint32_t cmdsize, shdr_status, shdr_add_status;
5655 lcb_context = (struct lpfc_lcb_context *)pmb->context1;
5656 ndlp = lcb_context->ndlp;
5657 pmb->context1 = NULL;
5658 pmb->context2 = NULL;
5660 shdr = (union lpfc_sli4_cfg_shdr *)
5661 &pmb->u.mqe.un.beacon_config.header.cfg_shdr;
5662 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
5663 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
5665 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX,
5666 "0194 SET_BEACON_CONFIG mailbox "
5667 "completed with status x%x add_status x%x,"
5668 " mbx status x%x\n",
5669 shdr_status, shdr_add_status, mb->mbxStatus);
5671 if ((mb->mbxStatus != MBX_SUCCESS) || shdr_status ||
5672 (shdr_add_status == ADD_STATUS_OPERATION_ALREADY_ACTIVE) ||
5673 (shdr_add_status == ADD_STATUS_INVALID_REQUEST)) {
5674 mempool_free(pmb, phba->mbox_mem_pool);
5678 mempool_free(pmb, phba->mbox_mem_pool);
5679 cmdsize = sizeof(struct fc_lcb_res_frame);
5680 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5681 lpfc_max_els_tries, ndlp,
5682 ndlp->nlp_DID, ELS_CMD_ACC);
5684 /* Decrement the ndlp reference count from previous mbox command */
5688 goto free_lcb_context;
5690 lcb_res = (struct fc_lcb_res_frame *)
5691 (((struct lpfc_dmabuf *)elsiocb->context2)->virt);
5693 memset(lcb_res, 0, sizeof(struct fc_lcb_res_frame));
5694 icmd = &elsiocb->iocb;
5695 icmd->ulpContext = lcb_context->rx_id;
5696 icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id;
5698 pcmd = (uint8_t *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt);
5699 *((uint32_t *)(pcmd)) = ELS_CMD_ACC;
5700 lcb_res->lcb_sub_command = lcb_context->sub_command;
5701 lcb_res->lcb_type = lcb_context->type;
5702 lcb_res->capability = lcb_context->capability;
5703 lcb_res->lcb_frequency = lcb_context->frequency;
5704 lcb_res->lcb_duration = lcb_context->duration;
5705 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5706 phba->fc_stat.elsXmitACC++;
5707 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5708 if (rc == IOCB_ERROR)
5709 lpfc_els_free_iocb(phba, elsiocb);
5715 cmdsize = sizeof(struct fc_lcb_res_frame);
5716 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5717 lpfc_max_els_tries, ndlp,
5718 ndlp->nlp_DID, ELS_CMD_LS_RJT);
5721 goto free_lcb_context;
5723 icmd = &elsiocb->iocb;
5724 icmd->ulpContext = lcb_context->rx_id;
5725 icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id;
5726 pcmd = (uint8_t *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt);
5728 *((uint32_t *)(pcmd)) = ELS_CMD_LS_RJT;
5729 stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t));
5730 stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5732 if (shdr_add_status == ADD_STATUS_OPERATION_ALREADY_ACTIVE)
5733 stat->un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS;
5735 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5736 phba->fc_stat.elsXmitLSRJT++;
5737 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5738 if (rc == IOCB_ERROR)
5739 lpfc_els_free_iocb(phba, elsiocb);
5745 lpfc_sli4_set_beacon(struct lpfc_vport *vport,
5746 struct lpfc_lcb_context *lcb_context,
5747 uint32_t beacon_state)
5749 struct lpfc_hba *phba = vport->phba;
5750 union lpfc_sli4_cfg_shdr *cfg_shdr;
5751 LPFC_MBOXQ_t *mbox = NULL;
5755 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5759 cfg_shdr = &mbox->u.mqe.un.sli4_config.header.cfg_shdr;
5760 len = sizeof(struct lpfc_mbx_set_beacon_config) -
5761 sizeof(struct lpfc_sli4_cfg_mhdr);
5762 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
5763 LPFC_MBOX_OPCODE_SET_BEACON_CONFIG, len,
5764 LPFC_SLI4_MBX_EMBED);
5765 mbox->context1 = (void *)lcb_context;
5766 mbox->vport = phba->pport;
5767 mbox->mbox_cmpl = lpfc_els_lcb_rsp;
5768 bf_set(lpfc_mbx_set_beacon_port_num, &mbox->u.mqe.un.beacon_config,
5769 phba->sli4_hba.physical_port);
5770 bf_set(lpfc_mbx_set_beacon_state, &mbox->u.mqe.un.beacon_config,
5772 mbox->u.mqe.un.beacon_config.word5 = 0; /* Reserved */
5775 * Check bv1s bit before issuing the mailbox
5776 * if bv1s == 1, LCB V1 supported
5777 * else, LCB V0 supported
5780 if (phba->sli4_hba.pc_sli4_params.bv1s) {
5781 /* COMMON_SET_BEACON_CONFIG_V1 */
5782 cfg_shdr->request.word9 = BEACON_VERSION_V1;
5783 lcb_context->capability |= LCB_CAPABILITY_DURATION;
5784 bf_set(lpfc_mbx_set_beacon_port_type,
5785 &mbox->u.mqe.un.beacon_config, 0);
5786 bf_set(lpfc_mbx_set_beacon_duration_v1,
5787 &mbox->u.mqe.un.beacon_config,
5788 be16_to_cpu(lcb_context->duration));
5790 /* COMMON_SET_BEACON_CONFIG_V0 */
5791 if (be16_to_cpu(lcb_context->duration) != 0) {
5792 mempool_free(mbox, phba->mbox_mem_pool);
5795 cfg_shdr->request.word9 = BEACON_VERSION_V0;
5796 lcb_context->capability &= ~(LCB_CAPABILITY_DURATION);
5797 bf_set(lpfc_mbx_set_beacon_state,
5798 &mbox->u.mqe.un.beacon_config, beacon_state);
5799 bf_set(lpfc_mbx_set_beacon_port_type,
5800 &mbox->u.mqe.un.beacon_config, 1);
5801 bf_set(lpfc_mbx_set_beacon_duration,
5802 &mbox->u.mqe.un.beacon_config,
5803 be16_to_cpu(lcb_context->duration));
5806 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
5807 if (rc == MBX_NOT_FINISHED) {
5808 mempool_free(mbox, phba->mbox_mem_pool);
5817 * lpfc_els_rcv_lcb - Process an unsolicited LCB
5818 * @vport: pointer to a host virtual N_Port data structure.
5819 * @cmdiocb: pointer to lpfc command iocb data structure.
5820 * @ndlp: pointer to a node-list data structure.
5822 * This routine processes an unsolicited LCB(LINK CABLE BEACON) IOCB.
5823 * First, the payload of the unsolicited LCB is checked.
5824 * Then based on Subcommand beacon will either turn on or off.
5827 * 0 - Sent the acc response
5828 * 1 - Sent the reject response.
5831 lpfc_els_rcv_lcb(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5832 struct lpfc_nodelist *ndlp)
5834 struct lpfc_hba *phba = vport->phba;
5835 struct lpfc_dmabuf *pcmd;
5837 struct fc_lcb_request_frame *beacon;
5838 struct lpfc_lcb_context *lcb_context;
5839 uint8_t state, rjt_err;
5842 pcmd = (struct lpfc_dmabuf *)cmdiocb->context2;
5843 lp = (uint8_t *)pcmd->virt;
5844 beacon = (struct fc_lcb_request_frame *)pcmd->virt;
5846 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5847 "0192 ELS LCB Data x%x x%x x%x x%x sub x%x "
5848 "type x%x frequency %x duration x%x\n",
5849 lp[0], lp[1], lp[2],
5850 beacon->lcb_command,
5851 beacon->lcb_sub_command,
5853 beacon->lcb_frequency,
5854 be16_to_cpu(beacon->lcb_duration));
5856 if (beacon->lcb_sub_command != LPFC_LCB_ON &&
5857 beacon->lcb_sub_command != LPFC_LCB_OFF) {
5858 rjt_err = LSRJT_CMD_UNSUPPORTED;
5862 if (phba->sli_rev < LPFC_SLI_REV4 ||
5863 phba->hba_flag & HBA_FCOE_MODE ||
5864 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
5865 LPFC_SLI_INTF_IF_TYPE_2)) {
5866 rjt_err = LSRJT_CMD_UNSUPPORTED;
5870 lcb_context = kmalloc(sizeof(*lcb_context), GFP_KERNEL);
5872 rjt_err = LSRJT_UNABLE_TPC;
5876 state = (beacon->lcb_sub_command == LPFC_LCB_ON) ? 1 : 0;
5877 lcb_context->sub_command = beacon->lcb_sub_command;
5878 lcb_context->capability = 0;
5879 lcb_context->type = beacon->lcb_type;
5880 lcb_context->frequency = beacon->lcb_frequency;
5881 lcb_context->duration = beacon->lcb_duration;
5882 lcb_context->ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id;
5883 lcb_context->rx_id = cmdiocb->iocb.ulpContext;
5884 lcb_context->ndlp = lpfc_nlp_get(ndlp);
5885 if (lpfc_sli4_set_beacon(vport, lcb_context, state)) {
5886 lpfc_printf_vlog(ndlp->vport, KERN_ERR,
5887 LOG_ELS, "0193 failed to send mail box");
5890 rjt_err = LSRJT_UNABLE_TPC;
5895 memset(&stat, 0, sizeof(stat));
5896 stat.un.b.lsRjtRsnCode = rjt_err;
5897 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5903 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
5904 * @vport: pointer to a host virtual N_Port data structure.
5906 * This routine cleans up any Registration State Change Notification
5907 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
5908 * @vport together with the host_lock is used to prevent multiple thread
5909 * trying to access the RSCN array on a same @vport at the same time.
5912 lpfc_els_flush_rscn(struct lpfc_vport *vport)
5914 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5915 struct lpfc_hba *phba = vport->phba;
5918 spin_lock_irq(shost->host_lock);
5919 if (vport->fc_rscn_flush) {
5920 /* Another thread is walking fc_rscn_id_list on this vport */
5921 spin_unlock_irq(shost->host_lock);
5924 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
5925 vport->fc_rscn_flush = 1;
5926 spin_unlock_irq(shost->host_lock);
5928 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
5929 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
5930 vport->fc_rscn_id_list[i] = NULL;
5932 spin_lock_irq(shost->host_lock);
5933 vport->fc_rscn_id_cnt = 0;
5934 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
5935 spin_unlock_irq(shost->host_lock);
5936 lpfc_can_disctmo(vport);
5937 /* Indicate we are done walking this fc_rscn_id_list */
5938 vport->fc_rscn_flush = 0;
5942 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
5943 * @vport: pointer to a host virtual N_Port data structure.
5944 * @did: remote destination port identifier.
5946 * This routine checks whether there is any pending Registration State
5947 * Configuration Notification (RSCN) to a @did on @vport.
5950 * None zero - The @did matched with a pending rscn
5951 * 0 - not able to match @did with a pending rscn
5954 lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
5959 uint32_t payload_len, i;
5960 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5962 ns_did.un.word = did;
5964 /* Never match fabric nodes for RSCNs */
5965 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
5968 /* If we are doing a FULL RSCN rediscovery, match everything */
5969 if (vport->fc_flag & FC_RSCN_DISCOVERY)
5972 spin_lock_irq(shost->host_lock);
5973 if (vport->fc_rscn_flush) {
5974 /* Another thread is walking fc_rscn_id_list on this vport */
5975 spin_unlock_irq(shost->host_lock);
5978 /* Indicate we are walking fc_rscn_id_list on this vport */
5979 vport->fc_rscn_flush = 1;
5980 spin_unlock_irq(shost->host_lock);
5981 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
5982 lp = vport->fc_rscn_id_list[i]->virt;
5983 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
5984 payload_len -= sizeof(uint32_t); /* take off word 0 */
5985 while (payload_len) {
5986 rscn_did.un.word = be32_to_cpu(*lp++);
5987 payload_len -= sizeof(uint32_t);
5988 switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) {
5989 case RSCN_ADDRESS_FORMAT_PORT:
5990 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
5991 && (ns_did.un.b.area == rscn_did.un.b.area)
5992 && (ns_did.un.b.id == rscn_did.un.b.id))
5993 goto return_did_out;
5995 case RSCN_ADDRESS_FORMAT_AREA:
5996 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
5997 && (ns_did.un.b.area == rscn_did.un.b.area))
5998 goto return_did_out;
6000 case RSCN_ADDRESS_FORMAT_DOMAIN:
6001 if (ns_did.un.b.domain == rscn_did.un.b.domain)
6002 goto return_did_out;
6004 case RSCN_ADDRESS_FORMAT_FABRIC:
6005 goto return_did_out;
6009 /* Indicate we are done with walking fc_rscn_id_list on this vport */
6010 vport->fc_rscn_flush = 0;
6013 /* Indicate we are done with walking fc_rscn_id_list on this vport */
6014 vport->fc_rscn_flush = 0;
6019 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
6020 * @vport: pointer to a host virtual N_Port data structure.
6022 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
6023 * state machine for a @vport's nodes that are with pending RSCN (Registration
6024 * State Change Notification).
6027 * 0 - Successful (currently alway return 0)
6030 lpfc_rscn_recovery_check(struct lpfc_vport *vport)
6032 struct lpfc_nodelist *ndlp = NULL;
6034 /* Move all affected nodes by pending RSCNs to NPR state. */
6035 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
6036 if (!NLP_CHK_NODE_ACT(ndlp) ||
6037 (ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
6038 !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
6041 /* NVME Target mode does not do RSCN Recovery. */
6042 if (vport->phba->nvmet_support)
6045 lpfc_disc_state_machine(vport, ndlp, NULL,
6046 NLP_EVT_DEVICE_RECOVERY);
6047 lpfc_cancel_retry_delay_tmo(vport, ndlp);
6053 * lpfc_send_rscn_event - Send an RSCN event to management application
6054 * @vport: pointer to a host virtual N_Port data structure.
6055 * @cmdiocb: pointer to lpfc command iocb data structure.
6057 * lpfc_send_rscn_event sends an RSCN netlink event to management
6061 lpfc_send_rscn_event(struct lpfc_vport *vport,
6062 struct lpfc_iocbq *cmdiocb)
6064 struct lpfc_dmabuf *pcmd;
6065 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6066 uint32_t *payload_ptr;
6067 uint32_t payload_len;
6068 struct lpfc_rscn_event_header *rscn_event_data;
6070 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6071 payload_ptr = (uint32_t *) pcmd->virt;
6072 payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK);
6074 rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) +
6075 payload_len, GFP_KERNEL);
6076 if (!rscn_event_data) {
6077 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6078 "0147 Failed to allocate memory for RSCN event\n");
6081 rscn_event_data->event_type = FC_REG_RSCN_EVENT;
6082 rscn_event_data->payload_length = payload_len;
6083 memcpy(rscn_event_data->rscn_payload, payload_ptr,
6086 fc_host_post_vendor_event(shost,
6087 fc_get_event_number(),
6088 sizeof(struct lpfc_rscn_event_header) + payload_len,
6089 (char *)rscn_event_data,
6092 kfree(rscn_event_data);
6096 * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
6097 * @vport: pointer to a host virtual N_Port data structure.
6098 * @cmdiocb: pointer to lpfc command iocb data structure.
6099 * @ndlp: pointer to a node-list data structure.
6101 * This routine processes an unsolicited RSCN (Registration State Change
6102 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
6103 * to invoke fc_host_post_event() routine to the FC transport layer. If the
6104 * discover state machine is about to begin discovery, it just accepts the
6105 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
6106 * contains N_Port IDs for other vports on this HBA, it just accepts the
6107 * RSCN and ignore processing it. If the state machine is in the recovery
6108 * state, the fc_rscn_id_list of this @vport is walked and the
6109 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
6110 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
6111 * routine is invoked to handle the RSCN event.
6114 * 0 - Just sent the acc response
6115 * 1 - Sent the acc response and waited for name server completion
6118 lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6119 struct lpfc_nodelist *ndlp)
6121 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6122 struct lpfc_hba *phba = vport->phba;
6123 struct lpfc_dmabuf *pcmd;
6124 uint32_t *lp, *datap;
6125 uint32_t payload_len, length, nportid, *cmd;
6127 int rscn_id = 0, hba_id = 0;
6130 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6131 lp = (uint32_t *) pcmd->virt;
6133 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
6134 payload_len -= sizeof(uint32_t); /* take off word 0 */
6136 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6137 "0214 RSCN received Data: x%x x%x x%x x%x\n",
6138 vport->fc_flag, payload_len, *lp,
6139 vport->fc_rscn_id_cnt);
6141 /* Send an RSCN event to the management application */
6142 lpfc_send_rscn_event(vport, cmdiocb);
6144 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
6145 fc_host_post_event(shost, fc_get_event_number(),
6146 FCH_EVT_RSCN, lp[i]);
6148 /* If we are about to begin discovery, just ACC the RSCN.
6149 * Discovery processing will satisfy it.
6151 if (vport->port_state <= LPFC_NS_QRY) {
6152 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6153 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
6154 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
6156 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
6160 /* If this RSCN just contains NPortIDs for other vports on this HBA,
6161 * just ACC and ignore it.
6163 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
6164 !(vport->cfg_peer_port_login)) {
6169 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
6170 i -= sizeof(uint32_t);
6172 if (lpfc_find_vport_by_did(phba, nportid))
6175 if (rscn_id == hba_id) {
6176 /* ALL NPortIDs in RSCN are on HBA */
6177 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6179 "Data: x%x x%x x%x x%x\n",
6180 vport->fc_flag, payload_len,
6181 *lp, vport->fc_rscn_id_cnt);
6182 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6183 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
6184 ndlp->nlp_DID, vport->port_state,
6187 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
6193 spin_lock_irq(shost->host_lock);
6194 if (vport->fc_rscn_flush) {
6195 /* Another thread is walking fc_rscn_id_list on this vport */
6196 vport->fc_flag |= FC_RSCN_DISCOVERY;
6197 spin_unlock_irq(shost->host_lock);
6199 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
6202 /* Indicate we are walking fc_rscn_id_list on this vport */
6203 vport->fc_rscn_flush = 1;
6204 spin_unlock_irq(shost->host_lock);
6205 /* Get the array count after successfully have the token */
6206 rscn_cnt = vport->fc_rscn_id_cnt;
6207 /* If we are already processing an RSCN, save the received
6208 * RSCN payload buffer, cmdiocb->context2 to process later.
6210 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
6211 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6212 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
6213 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
6215 spin_lock_irq(shost->host_lock);
6216 vport->fc_flag |= FC_RSCN_DEFERRED;
6217 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
6218 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
6219 vport->fc_flag |= FC_RSCN_MODE;
6220 spin_unlock_irq(shost->host_lock);
6222 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
6223 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
6226 (payload_len + length <= LPFC_BPL_SIZE)) {
6227 *cmd &= ELS_CMD_MASK;
6228 *cmd |= cpu_to_be32(payload_len + length);
6229 memcpy(((uint8_t *)cmd) + length, lp,
6232 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
6233 vport->fc_rscn_id_cnt++;
6234 /* If we zero, cmdiocb->context2, the calling
6235 * routine will not try to free it.
6237 cmdiocb->context2 = NULL;
6240 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6241 "0235 Deferred RSCN "
6242 "Data: x%x x%x x%x\n",
6243 vport->fc_rscn_id_cnt, vport->fc_flag,
6246 vport->fc_flag |= FC_RSCN_DISCOVERY;
6247 spin_unlock_irq(shost->host_lock);
6248 /* ReDiscovery RSCN */
6249 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6250 "0234 ReDiscovery RSCN "
6251 "Data: x%x x%x x%x\n",
6252 vport->fc_rscn_id_cnt, vport->fc_flag,
6255 /* Indicate we are done walking fc_rscn_id_list on this vport */
6256 vport->fc_rscn_flush = 0;
6258 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
6259 /* send RECOVERY event for ALL nodes that match RSCN payload */
6260 lpfc_rscn_recovery_check(vport);
6263 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6264 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
6265 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
6267 spin_lock_irq(shost->host_lock);
6268 vport->fc_flag |= FC_RSCN_MODE;
6269 spin_unlock_irq(shost->host_lock);
6270 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
6271 /* Indicate we are done walking fc_rscn_id_list on this vport */
6272 vport->fc_rscn_flush = 0;
6274 * If we zero, cmdiocb->context2, the calling routine will
6275 * not try to free it.
6277 cmdiocb->context2 = NULL;
6278 lpfc_set_disctmo(vport);
6280 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
6281 /* send RECOVERY event for ALL nodes that match RSCN payload */
6282 lpfc_rscn_recovery_check(vport);
6283 return lpfc_els_handle_rscn(vport);
6287 * lpfc_els_handle_rscn - Handle rscn for a vport
6288 * @vport: pointer to a host virtual N_Port data structure.
6290 * This routine handles the Registration State Configuration Notification
6291 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
6292 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
6293 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
6294 * NameServer shall be issued. If CT command to the NameServer fails to be
6295 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
6296 * RSCN activities with the @vport.
6299 * 0 - Cleaned up rscn on the @vport
6300 * 1 - Wait for plogi to name server before proceed
6303 lpfc_els_handle_rscn(struct lpfc_vport *vport)
6305 struct lpfc_nodelist *ndlp;
6307 /* Ignore RSCN if the port is being torn down. */
6308 if (vport->load_flag & FC_UNLOADING) {
6309 lpfc_els_flush_rscn(vport);
6313 /* Start timer for RSCN processing */
6314 lpfc_set_disctmo(vport);
6316 /* RSCN processed */
6317 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6318 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
6319 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
6322 /* To process RSCN, first compare RSCN data with NameServer */
6323 vport->fc_ns_retry = 0;
6324 vport->num_disc_nodes = 0;
6326 ndlp = lpfc_findnode_did(vport, NameServer_DID);
6327 if (ndlp && NLP_CHK_NODE_ACT(ndlp)
6328 && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
6329 /* Good ndlp, issue CT Request to NameServer. Need to
6330 * know how many gidfts were issued. If none, then just
6331 * flush the RSCN. Otherwise, the outstanding requests
6334 if (lpfc_issue_gidft(vport) > 0)
6337 /* Nameserver login in question. Revalidate. */
6339 ndlp = lpfc_enable_node(vport, ndlp,
6340 NLP_STE_PLOGI_ISSUE);
6342 lpfc_els_flush_rscn(vport);
6345 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
6347 ndlp = lpfc_nlp_init(vport, NameServer_DID);
6349 lpfc_els_flush_rscn(vport);
6352 ndlp->nlp_prev_state = ndlp->nlp_state;
6353 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
6355 ndlp->nlp_type |= NLP_FABRIC;
6356 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
6357 /* Wait for NameServer login cmpl before we can
6363 lpfc_els_flush_rscn(vport);
6368 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
6369 * @vport: pointer to a host virtual N_Port data structure.
6370 * @cmdiocb: pointer to lpfc command iocb data structure.
6371 * @ndlp: pointer to a node-list data structure.
6373 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
6374 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
6375 * point topology. As an unsolicited FLOGI should not be received in a loop
6376 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
6377 * lpfc_check_sparm() routine is invoked to check the parameters in the
6378 * unsolicited FLOGI. If parameters validation failed, the routine
6379 * lpfc_els_rsp_reject() shall be called with reject reason code set to
6380 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
6381 * FLOGI shall be compared with the Port WWN of the @vport to determine who
6382 * will initiate PLOGI. The higher lexicographical value party shall has
6383 * higher priority (as the winning port) and will initiate PLOGI and
6384 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
6385 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
6386 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
6389 * 0 - Successfully processed the unsolicited flogi
6390 * 1 - Failed to process the unsolicited flogi
6393 lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6394 struct lpfc_nodelist *ndlp)
6396 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6397 struct lpfc_hba *phba = vport->phba;
6398 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6399 uint32_t *lp = (uint32_t *) pcmd->virt;
6400 IOCB_t *icmd = &cmdiocb->iocb;
6401 struct serv_parm *sp;
6405 uint32_t fc_flag = 0;
6406 uint32_t port_state = 0;
6409 sp = (struct serv_parm *) lp;
6411 /* FLOGI received */
6413 lpfc_set_disctmo(vport);
6415 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
6416 /* We should never receive a FLOGI in loop mode, ignore it */
6417 did = icmd->un.elsreq64.remoteID;
6419 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
6421 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6422 "0113 An FLOGI ELS command x%x was "
6423 "received from DID x%x in Loop Mode\n",
6428 (void) lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1);
6431 * If our portname is greater than the remote portname,
6432 * then we initiate Nport login.
6435 rc = memcmp(&vport->fc_portname, &sp->portName,
6436 sizeof(struct lpfc_name));
6439 if (phba->sli_rev < LPFC_SLI_REV4) {
6440 mbox = mempool_alloc(phba->mbox_mem_pool,
6444 lpfc_linkdown(phba);
6445 lpfc_init_link(phba, mbox,
6447 phba->cfg_link_speed);
6448 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
6449 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
6450 mbox->vport = vport;
6451 rc = lpfc_sli_issue_mbox(phba, mbox,
6453 lpfc_set_loopback_flag(phba);
6454 if (rc == MBX_NOT_FINISHED)
6455 mempool_free(mbox, phba->mbox_mem_pool);
6459 /* abort the flogi coming back to ourselves
6460 * due to external loopback on the port.
6462 lpfc_els_abort_flogi(phba);
6465 } else if (rc > 0) { /* greater than */
6466 spin_lock_irq(shost->host_lock);
6467 vport->fc_flag |= FC_PT2PT_PLOGI;
6468 spin_unlock_irq(shost->host_lock);
6470 /* If we have the high WWPN we can assign our own
6471 * myDID; otherwise, we have to WAIT for a PLOGI
6472 * from the remote NPort to find out what it
6475 vport->fc_myDID = PT2PT_LocalID;
6477 vport->fc_myDID = PT2PT_RemoteID;
6481 * The vport state should go to LPFC_FLOGI only
6482 * AFTER we issue a FLOGI, not receive one.
6484 spin_lock_irq(shost->host_lock);
6485 fc_flag = vport->fc_flag;
6486 port_state = vport->port_state;
6487 vport->fc_flag |= FC_PT2PT;
6488 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
6490 /* Acking an unsol FLOGI. Count 1 for link bounce
6493 vport->rcv_flogi_cnt++;
6494 spin_unlock_irq(shost->host_lock);
6495 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6496 "3311 Rcv Flogi PS x%x new PS x%x "
6497 "fc_flag x%x new fc_flag x%x\n",
6498 port_state, vport->port_state,
6499 fc_flag, vport->fc_flag);
6502 * We temporarily set fc_myDID to make it look like we are
6503 * a Fabric. This is done just so we end up with the right
6504 * did / sid on the FLOGI ACC rsp.
6506 did = vport->fc_myDID;
6507 vport->fc_myDID = Fabric_DID;
6509 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
6512 lpfc_els_rsp_acc(vport, ELS_CMD_FLOGI, cmdiocb, ndlp, NULL);
6514 /* Now lets put fc_myDID back to what its supposed to be */
6515 vport->fc_myDID = did;
6521 * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
6522 * @vport: pointer to a host virtual N_Port data structure.
6523 * @cmdiocb: pointer to lpfc command iocb data structure.
6524 * @ndlp: pointer to a node-list data structure.
6526 * This routine processes Request Node Identification Data (RNID) IOCB
6527 * received as an ELS unsolicited event. Only when the RNID specified format
6528 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
6529 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
6530 * Accept (ACC) the RNID ELS command. All the other RNID formats are
6531 * rejected by invoking the lpfc_els_rsp_reject() routine.
6534 * 0 - Successfully processed rnid iocb (currently always return 0)
6537 lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6538 struct lpfc_nodelist *ndlp)
6540 struct lpfc_dmabuf *pcmd;
6546 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6547 lp = (uint32_t *) pcmd->virt;
6554 switch (rn->Format) {
6556 case RNID_TOPOLOGY_DISC:
6558 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
6561 /* Reject this request because format not supported */
6562 stat.un.b.lsRjtRsvd0 = 0;
6563 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6564 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
6565 stat.un.b.vendorUnique = 0;
6566 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
6573 * lpfc_els_rcv_echo - Process an unsolicited echo iocb
6574 * @vport: pointer to a host virtual N_Port data structure.
6575 * @cmdiocb: pointer to lpfc command iocb data structure.
6576 * @ndlp: pointer to a node-list data structure.
6579 * 0 - Successfully processed echo iocb (currently always return 0)
6582 lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6583 struct lpfc_nodelist *ndlp)
6587 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
6589 /* skip over first word of echo command to find echo data */
6590 pcmd += sizeof(uint32_t);
6592 lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp);
6597 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
6598 * @vport: pointer to a host virtual N_Port data structure.
6599 * @cmdiocb: pointer to lpfc command iocb data structure.
6600 * @ndlp: pointer to a node-list data structure.
6602 * This routine processes a Link Incident Report Registration(LIRR) IOCB
6603 * received as an ELS unsolicited event. Currently, this function just invokes
6604 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
6607 * 0 - Successfully processed lirr iocb (currently always return 0)
6610 lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6611 struct lpfc_nodelist *ndlp)
6615 /* For now, unconditionally reject this command */
6616 stat.un.b.lsRjtRsvd0 = 0;
6617 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6618 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
6619 stat.un.b.vendorUnique = 0;
6620 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
6625 * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb
6626 * @vport: pointer to a host virtual N_Port data structure.
6627 * @cmdiocb: pointer to lpfc command iocb data structure.
6628 * @ndlp: pointer to a node-list data structure.
6630 * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB
6631 * received as an ELS unsolicited event. A request to RRQ shall only
6632 * be accepted if the Originator Nx_Port N_Port_ID or the Responder
6633 * Nx_Port N_Port_ID of the target Exchange is the same as the
6634 * N_Port_ID of the Nx_Port that makes the request. If the RRQ is
6635 * not accepted, an LS_RJT with reason code "Unable to perform
6636 * command request" and reason code explanation "Invalid Originator
6637 * S_ID" shall be returned. For now, we just unconditionally accept
6638 * RRQ from the target.
6641 lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6642 struct lpfc_nodelist *ndlp)
6644 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
6645 if (vport->phba->sli_rev == LPFC_SLI_REV4)
6646 lpfc_els_clear_rrq(vport, cmdiocb, ndlp);
6650 * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
6651 * @phba: pointer to lpfc hba data structure.
6652 * @pmb: pointer to the driver internal queue element for mailbox command.
6654 * This routine is the completion callback function for the MBX_READ_LNK_STAT
6655 * mailbox command. This callback function is to actually send the Accept
6656 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
6657 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
6658 * mailbox command, constructs the RPS response with the link statistics
6659 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
6660 * response to the RPS.
6662 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6663 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6664 * will be stored into the context1 field of the IOCB for the completion
6665 * callback function to the RPS Accept Response ELS IOCB command.
6669 lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
6673 struct RLS_RSP *rls_rsp;
6675 struct lpfc_iocbq *elsiocb;
6676 struct lpfc_nodelist *ndlp;
6683 ndlp = (struct lpfc_nodelist *) pmb->context2;
6684 rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff);
6685 oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff);
6686 pmb->context1 = NULL;
6687 pmb->context2 = NULL;
6689 if (mb->mbxStatus) {
6690 mempool_free(pmb, phba->mbox_mem_pool);
6694 cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t);
6695 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
6696 lpfc_max_els_tries, ndlp,
6697 ndlp->nlp_DID, ELS_CMD_ACC);
6699 /* Decrement the ndlp reference count from previous mbox command */
6703 mempool_free(pmb, phba->mbox_mem_pool);
6707 icmd = &elsiocb->iocb;
6708 icmd->ulpContext = rxid;
6709 icmd->unsli3.rcvsli3.ox_id = oxid;
6711 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6712 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
6713 pcmd += sizeof(uint32_t); /* Skip past command */
6714 rls_rsp = (struct RLS_RSP *)pcmd;
6716 rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
6717 rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
6718 rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
6719 rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
6720 rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
6721 rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
6722 mempool_free(pmb, phba->mbox_mem_pool);
6723 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
6724 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
6725 "2874 Xmit ELS RLS ACC response tag x%x xri x%x, "
6726 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
6727 elsiocb->iotag, elsiocb->iocb.ulpContext,
6728 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
6730 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
6731 phba->fc_stat.elsXmitACC++;
6732 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
6733 lpfc_els_free_iocb(phba, elsiocb);
6737 * lpfc_els_rsp_rps_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
6738 * @phba: pointer to lpfc hba data structure.
6739 * @pmb: pointer to the driver internal queue element for mailbox command.
6741 * This routine is the completion callback function for the MBX_READ_LNK_STAT
6742 * mailbox command. This callback function is to actually send the Accept
6743 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
6744 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
6745 * mailbox command, constructs the RPS response with the link statistics
6746 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
6747 * response to the RPS.
6749 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6750 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6751 * will be stored into the context1 field of the IOCB for the completion
6752 * callback function to the RPS Accept Response ELS IOCB command.
6756 lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
6762 struct lpfc_iocbq *elsiocb;
6763 struct lpfc_nodelist *ndlp;
6771 ndlp = (struct lpfc_nodelist *) pmb->context2;
6772 rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff);
6773 oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff);
6774 pmb->context1 = NULL;
6775 pmb->context2 = NULL;
6777 if (mb->mbxStatus) {
6778 mempool_free(pmb, phba->mbox_mem_pool);
6782 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
6783 mempool_free(pmb, phba->mbox_mem_pool);
6784 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
6785 lpfc_max_els_tries, ndlp,
6786 ndlp->nlp_DID, ELS_CMD_ACC);
6788 /* Decrement the ndlp reference count from previous mbox command */
6794 icmd = &elsiocb->iocb;
6795 icmd->ulpContext = rxid;
6796 icmd->unsli3.rcvsli3.ox_id = oxid;
6798 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6799 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
6800 pcmd += sizeof(uint32_t); /* Skip past command */
6801 rps_rsp = (RPS_RSP *)pcmd;
6803 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP)
6807 if (phba->pport->fc_flag & FC_FABRIC)
6811 rps_rsp->portStatus = cpu_to_be16(status);
6812 rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
6813 rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
6814 rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
6815 rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
6816 rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
6817 rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
6818 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
6819 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
6820 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
6821 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
6822 elsiocb->iotag, elsiocb->iocb.ulpContext,
6823 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
6825 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
6826 phba->fc_stat.elsXmitACC++;
6827 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
6828 lpfc_els_free_iocb(phba, elsiocb);
6833 * lpfc_els_rcv_rls - Process an unsolicited rls iocb
6834 * @vport: pointer to a host virtual N_Port data structure.
6835 * @cmdiocb: pointer to lpfc command iocb data structure.
6836 * @ndlp: pointer to a node-list data structure.
6838 * This routine processes Read Port Status (RPL) IOCB received as an
6839 * ELS unsolicited event. It first checks the remote port state. If the
6840 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
6841 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
6842 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
6843 * for reading the HBA link statistics. It is for the callback function,
6844 * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command
6845 * to actually sending out RPL Accept (ACC) response.
6848 * 0 - Successfully processed rls iocb (currently always return 0)
6851 lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6852 struct lpfc_nodelist *ndlp)
6854 struct lpfc_hba *phba = vport->phba;
6858 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
6859 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
6860 /* reject the unsolicited RPS request and done with it */
6863 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
6865 lpfc_read_lnk_stat(phba, mbox);
6866 mbox->context1 = (void *)((unsigned long)
6867 ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) |
6868 cmdiocb->iocb.ulpContext)); /* rx_id */
6869 mbox->context2 = lpfc_nlp_get(ndlp);
6870 mbox->vport = vport;
6871 mbox->mbox_cmpl = lpfc_els_rsp_rls_acc;
6872 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
6873 != MBX_NOT_FINISHED)
6874 /* Mbox completion will send ELS Response */
6876 /* Decrement reference count used for the failed mbox
6880 mempool_free(mbox, phba->mbox_mem_pool);
6883 /* issue rejection response */
6884 stat.un.b.lsRjtRsvd0 = 0;
6885 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6886 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
6887 stat.un.b.vendorUnique = 0;
6888 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
6893 * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb
6894 * @vport: pointer to a host virtual N_Port data structure.
6895 * @cmdiocb: pointer to lpfc command iocb data structure.
6896 * @ndlp: pointer to a node-list data structure.
6898 * This routine processes Read Timout Value (RTV) IOCB received as an
6899 * ELS unsolicited event. It first checks the remote port state. If the
6900 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
6901 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
6902 * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout
6903 * Value (RTV) unsolicited IOCB event.
6905 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6906 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6907 * will be stored into the context1 field of the IOCB for the completion
6908 * callback function to the RPS Accept Response ELS IOCB command.
6911 * 0 - Successfully processed rtv iocb (currently always return 0)
6914 lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6915 struct lpfc_nodelist *ndlp)
6917 struct lpfc_hba *phba = vport->phba;
6919 struct RTV_RSP *rtv_rsp;
6921 struct lpfc_iocbq *elsiocb;
6925 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
6926 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
6927 /* reject the unsolicited RPS request and done with it */
6930 cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t);
6931 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
6932 lpfc_max_els_tries, ndlp,
6933 ndlp->nlp_DID, ELS_CMD_ACC);
6938 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6939 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
6940 pcmd += sizeof(uint32_t); /* Skip past command */
6942 /* use the command's xri in the response */
6943 elsiocb->iocb.ulpContext = cmdiocb->iocb.ulpContext; /* Xri / rx_id */
6944 elsiocb->iocb.unsli3.rcvsli3.ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id;
6946 rtv_rsp = (struct RTV_RSP *)pcmd;
6948 /* populate RTV payload */
6949 rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000); /* report msecs */
6950 rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov);
6951 bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0);
6952 bf_set(qtov_rttov, rtv_rsp, 0); /* Field is for FC ONLY */
6953 rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov);
6955 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
6956 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
6957 "2875 Xmit ELS RTV ACC response tag x%x xri x%x, "
6958 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, "
6959 "Data: x%x x%x x%x\n",
6960 elsiocb->iotag, elsiocb->iocb.ulpContext,
6961 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
6963 rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov);
6964 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
6965 phba->fc_stat.elsXmitACC++;
6966 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
6967 lpfc_els_free_iocb(phba, elsiocb);
6971 /* issue rejection response */
6972 stat.un.b.lsRjtRsvd0 = 0;
6973 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6974 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
6975 stat.un.b.vendorUnique = 0;
6976 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
6980 /* lpfc_els_rcv_rps - Process an unsolicited rps iocb
6981 * @vport: pointer to a host virtual N_Port data structure.
6982 * @cmdiocb: pointer to lpfc command iocb data structure.
6983 * @ndlp: pointer to a node-list data structure.
6985 * This routine processes Read Port Status (RPS) IOCB received as an
6986 * ELS unsolicited event. It first checks the remote port state. If the
6987 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
6988 * state, it invokes the lpfc_els_rsp_reject() routine to send the reject
6989 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
6990 * for reading the HBA link statistics. It is for the callback function,
6991 * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command
6992 * to actually sending out RPS Accept (ACC) response.
6995 * 0 - Successfully processed rps iocb (currently always return 0)
6998 lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6999 struct lpfc_nodelist *ndlp)
7001 struct lpfc_hba *phba = vport->phba;
7005 struct lpfc_dmabuf *pcmd;
7009 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
7010 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
7011 /* reject the unsolicited RPS request and done with it */
7014 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7015 lp = (uint32_t *) pcmd->virt;
7016 flag = (be32_to_cpu(*lp++) & 0xf);
7020 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
7021 ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
7022 sizeof(struct lpfc_name)) == 0))) {
7024 printk("Fix me....\n");
7026 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
7028 lpfc_read_lnk_stat(phba, mbox);
7029 mbox->context1 = (void *)((unsigned long)
7030 ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) |
7031 cmdiocb->iocb.ulpContext)); /* rx_id */
7032 mbox->context2 = lpfc_nlp_get(ndlp);
7033 mbox->vport = vport;
7034 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
7035 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
7036 != MBX_NOT_FINISHED)
7037 /* Mbox completion will send ELS Response */
7039 /* Decrement reference count used for the failed mbox
7043 mempool_free(mbox, phba->mbox_mem_pool);
7048 /* issue rejection response */
7049 stat.un.b.lsRjtRsvd0 = 0;
7050 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
7051 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
7052 stat.un.b.vendorUnique = 0;
7053 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
7057 /* lpfc_issue_els_rrq - Process an unsolicited rps iocb
7058 * @vport: pointer to a host virtual N_Port data structure.
7059 * @ndlp: pointer to a node-list data structure.
7060 * @did: DID of the target.
7061 * @rrq: Pointer to the rrq struct.
7063 * Build a ELS RRQ command and send it to the target. If the issue_iocb is
7064 * Successful the the completion handler will clear the RRQ.
7067 * 0 - Successfully sent rrq els iocb.
7068 * 1 - Failed to send rrq els iocb.
7071 lpfc_issue_els_rrq(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
7072 uint32_t did, struct lpfc_node_rrq *rrq)
7074 struct lpfc_hba *phba = vport->phba;
7075 struct RRQ *els_rrq;
7076 struct lpfc_iocbq *elsiocb;
7082 if (ndlp != rrq->ndlp)
7084 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
7087 /* If ndlp is not NULL, we will bump the reference count on it */
7088 cmdsize = (sizeof(uint32_t) + sizeof(struct RRQ));
7089 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, did,
7094 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7096 /* For RRQ request, remainder of payload is Exchange IDs */
7097 *((uint32_t *) (pcmd)) = ELS_CMD_RRQ;
7098 pcmd += sizeof(uint32_t);
7099 els_rrq = (struct RRQ *) pcmd;
7101 bf_set(rrq_oxid, els_rrq, phba->sli4_hba.xri_ids[rrq->xritag]);
7102 bf_set(rrq_rxid, els_rrq, rrq->rxid);
7103 bf_set(rrq_did, els_rrq, vport->fc_myDID);
7104 els_rrq->rrq = cpu_to_be32(els_rrq->rrq);
7105 els_rrq->rrq_exchg = cpu_to_be32(els_rrq->rrq_exchg);
7108 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7109 "Issue RRQ: did:x%x",
7110 did, rrq->xritag, rrq->rxid);
7111 elsiocb->context_un.rrq = rrq;
7112 elsiocb->iocb_cmpl = lpfc_cmpl_els_rrq;
7113 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
7115 if (ret == IOCB_ERROR) {
7116 lpfc_els_free_iocb(phba, elsiocb);
7123 * lpfc_send_rrq - Sends ELS RRQ if needed.
7124 * @phba: pointer to lpfc hba data structure.
7125 * @rrq: pointer to the active rrq.
7127 * This routine will call the lpfc_issue_els_rrq if the rrq is
7128 * still active for the xri. If this function returns a failure then
7129 * the caller needs to clean up the RRQ by calling lpfc_clr_active_rrq.
7131 * Returns 0 Success.
7135 lpfc_send_rrq(struct lpfc_hba *phba, struct lpfc_node_rrq *rrq)
7137 struct lpfc_nodelist *ndlp = lpfc_findnode_did(rrq->vport,
7142 if (lpfc_test_rrq_active(phba, ndlp, rrq->xritag))
7143 return lpfc_issue_els_rrq(rrq->vport, ndlp,
7150 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
7151 * @vport: pointer to a host virtual N_Port data structure.
7152 * @cmdsize: size of the ELS command.
7153 * @oldiocb: pointer to the original lpfc command iocb data structure.
7154 * @ndlp: pointer to a node-list data structure.
7156 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
7157 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
7159 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7160 * will be incremented by 1 for holding the ndlp and the reference to ndlp
7161 * will be stored into the context1 field of the IOCB for the completion
7162 * callback function to the RPL Accept Response ELS command.
7165 * 0 - Successfully issued ACC RPL ELS command
7166 * 1 - Failed to issue ACC RPL ELS command
7169 lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
7170 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
7172 struct lpfc_hba *phba = vport->phba;
7173 IOCB_t *icmd, *oldcmd;
7175 struct lpfc_iocbq *elsiocb;
7178 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
7179 ndlp->nlp_DID, ELS_CMD_ACC);
7184 icmd = &elsiocb->iocb;
7185 oldcmd = &oldiocb->iocb;
7186 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
7187 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
7189 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7190 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
7191 pcmd += sizeof(uint16_t);
7192 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
7193 pcmd += sizeof(uint16_t);
7195 /* Setup the RPL ACC payload */
7196 rpl_rsp.listLen = be32_to_cpu(1);
7198 rpl_rsp.port_num_blk.portNum = 0;
7199 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
7200 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
7201 sizeof(struct lpfc_name));
7202 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
7203 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
7204 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7205 "0120 Xmit ELS RPL ACC response tag x%x "
7206 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
7208 elsiocb->iotag, elsiocb->iocb.ulpContext,
7209 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
7211 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
7212 phba->fc_stat.elsXmitACC++;
7213 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
7215 lpfc_els_free_iocb(phba, elsiocb);
7222 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
7223 * @vport: pointer to a host virtual N_Port data structure.
7224 * @cmdiocb: pointer to lpfc command iocb data structure.
7225 * @ndlp: pointer to a node-list data structure.
7227 * This routine processes Read Port List (RPL) IOCB received as an ELS
7228 * unsolicited event. It first checks the remote port state. If the remote
7229 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
7230 * invokes the lpfc_els_rsp_reject() routine to send reject response.
7231 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
7232 * to accept the RPL.
7235 * 0 - Successfully processed rpl iocb (currently always return 0)
7238 lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7239 struct lpfc_nodelist *ndlp)
7241 struct lpfc_dmabuf *pcmd;
7248 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
7249 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
7250 /* issue rejection response */
7251 stat.un.b.lsRjtRsvd0 = 0;
7252 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
7253 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
7254 stat.un.b.vendorUnique = 0;
7255 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
7257 /* rejected the unsolicited RPL request and done with it */
7261 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7262 lp = (uint32_t *) pcmd->virt;
7263 rpl = (RPL *) (lp + 1);
7264 maxsize = be32_to_cpu(rpl->maxsize);
7266 /* We support only one port */
7267 if ((rpl->index == 0) &&
7269 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
7270 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
7272 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
7274 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
7280 * lpfc_els_rcv_farp - Process an unsolicited farp request els command
7281 * @vport: pointer to a virtual N_Port data structure.
7282 * @cmdiocb: pointer to lpfc command iocb data structure.
7283 * @ndlp: pointer to a node-list data structure.
7285 * This routine processes Fibre Channel Address Resolution Protocol
7286 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
7287 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
7288 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
7289 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
7290 * remote PortName is compared against the FC PortName stored in the @vport
7291 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
7292 * compared against the FC NodeName stored in the @vport data structure.
7293 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
7294 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
7295 * invoked to send out FARP Response to the remote node. Before sending the
7296 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
7297 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
7298 * routine is invoked to log into the remote port first.
7301 * 0 - Either the FARP Match Mode not supported or successfully processed
7304 lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7305 struct lpfc_nodelist *ndlp)
7307 struct lpfc_dmabuf *pcmd;
7311 uint32_t cmd, cnt, did;
7313 icmd = &cmdiocb->iocb;
7314 did = icmd->un.elsreq64.remoteID;
7315 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7316 lp = (uint32_t *) pcmd->virt;
7320 /* FARP-REQ received from DID <did> */
7321 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7322 "0601 FARP-REQ received from DID x%x\n", did);
7323 /* We will only support match on WWPN or WWNN */
7324 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
7329 /* If this FARP command is searching for my portname */
7330 if (fp->Mflags & FARP_MATCH_PORT) {
7331 if (memcmp(&fp->RportName, &vport->fc_portname,
7332 sizeof(struct lpfc_name)) == 0)
7336 /* If this FARP command is searching for my nodename */
7337 if (fp->Mflags & FARP_MATCH_NODE) {
7338 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
7339 sizeof(struct lpfc_name)) == 0)
7344 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
7345 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
7346 /* Log back into the node before sending the FARP. */
7347 if (fp->Rflags & FARP_REQUEST_PLOGI) {
7348 ndlp->nlp_prev_state = ndlp->nlp_state;
7349 lpfc_nlp_set_state(vport, ndlp,
7350 NLP_STE_PLOGI_ISSUE);
7351 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
7354 /* Send a FARP response to that node */
7355 if (fp->Rflags & FARP_REQUEST_FARPR)
7356 lpfc_issue_els_farpr(vport, did, 0);
7363 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
7364 * @vport: pointer to a host virtual N_Port data structure.
7365 * @cmdiocb: pointer to lpfc command iocb data structure.
7366 * @ndlp: pointer to a node-list data structure.
7368 * This routine processes Fibre Channel Address Resolution Protocol
7369 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
7370 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
7371 * the FARP response request.
7374 * 0 - Successfully processed FARPR IOCB (currently always return 0)
7377 lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7378 struct lpfc_nodelist *ndlp)
7380 struct lpfc_dmabuf *pcmd;
7385 icmd = &cmdiocb->iocb;
7386 did = icmd->un.elsreq64.remoteID;
7387 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7388 lp = (uint32_t *) pcmd->virt;
7391 /* FARP-RSP received from DID <did> */
7392 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7393 "0600 FARP-RSP received from DID x%x\n", did);
7394 /* ACCEPT the Farp resp request */
7395 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
7401 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
7402 * @vport: pointer to a host virtual N_Port data structure.
7403 * @cmdiocb: pointer to lpfc command iocb data structure.
7404 * @fan_ndlp: pointer to a node-list data structure.
7406 * This routine processes a Fabric Address Notification (FAN) IOCB
7407 * command received as an ELS unsolicited event. The FAN ELS command will
7408 * only be processed on a physical port (i.e., the @vport represents the
7409 * physical port). The fabric NodeName and PortName from the FAN IOCB are
7410 * compared against those in the phba data structure. If any of those is
7411 * different, the lpfc_initial_flogi() routine is invoked to initialize
7412 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
7413 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
7414 * is invoked to register login to the fabric.
7417 * 0 - Successfully processed fan iocb (currently always return 0).
7420 lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7421 struct lpfc_nodelist *fan_ndlp)
7423 struct lpfc_hba *phba = vport->phba;
7427 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
7428 lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
7430 /* FAN received; Fan does not have a reply sequence */
7431 if ((vport == phba->pport) &&
7432 (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
7433 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
7434 sizeof(struct lpfc_name))) ||
7435 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
7436 sizeof(struct lpfc_name)))) {
7437 /* This port has switched fabrics. FLOGI is required */
7438 lpfc_issue_init_vfi(vport);
7440 /* FAN verified - skip FLOGI */
7441 vport->fc_myDID = vport->fc_prevDID;
7442 if (phba->sli_rev < LPFC_SLI_REV4)
7443 lpfc_issue_fabric_reglogin(vport);
7445 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7446 "3138 Need register VFI: (x%x/%x)\n",
7447 vport->fc_prevDID, vport->fc_myDID);
7448 lpfc_issue_reg_vfi(vport);
7456 * lpfc_els_timeout - Handler funciton to the els timer
7457 * @ptr: holder for the timer function associated data.
7459 * This routine is invoked by the ELS timer after timeout. It posts the ELS
7460 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
7461 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
7462 * up the worker thread. It is for the worker thread to invoke the routine
7463 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
7466 lpfc_els_timeout(struct timer_list *t)
7468 struct lpfc_vport *vport = from_timer(vport, t, els_tmofunc);
7469 struct lpfc_hba *phba = vport->phba;
7470 uint32_t tmo_posted;
7471 unsigned long iflag;
7473 spin_lock_irqsave(&vport->work_port_lock, iflag);
7474 tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
7475 if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING)))
7476 vport->work_port_events |= WORKER_ELS_TMO;
7477 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
7479 if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING)))
7480 lpfc_worker_wake_up(phba);
7486 * lpfc_els_timeout_handler - Process an els timeout event
7487 * @vport: pointer to a virtual N_Port data structure.
7489 * This routine is the actual handler function that processes an ELS timeout
7490 * event. It walks the ELS ring to get and abort all the IOCBs (except the
7491 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
7492 * invoking the lpfc_sli_issue_abort_iotag() routine.
7495 lpfc_els_timeout_handler(struct lpfc_vport *vport)
7497 struct lpfc_hba *phba = vport->phba;
7498 struct lpfc_sli_ring *pring;
7499 struct lpfc_iocbq *tmp_iocb, *piocb;
7501 struct lpfc_dmabuf *pcmd;
7502 uint32_t els_command = 0;
7504 uint32_t remote_ID = 0xffffffff;
7505 LIST_HEAD(abort_list);
7508 timeout = (uint32_t)(phba->fc_ratov << 1);
7510 pring = lpfc_phba_elsring(phba);
7511 if (unlikely(!pring))
7514 if ((phba->pport->load_flag & FC_UNLOADING))
7516 spin_lock_irq(&phba->hbalock);
7517 if (phba->sli_rev == LPFC_SLI_REV4)
7518 spin_lock(&pring->ring_lock);
7520 if ((phba->pport->load_flag & FC_UNLOADING)) {
7521 if (phba->sli_rev == LPFC_SLI_REV4)
7522 spin_unlock(&pring->ring_lock);
7523 spin_unlock_irq(&phba->hbalock);
7527 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
7530 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
7531 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
7532 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
7535 if (piocb->vport != vport)
7538 pcmd = (struct lpfc_dmabuf *) piocb->context2;
7540 els_command = *(uint32_t *) (pcmd->virt);
7542 if (els_command == ELS_CMD_FARP ||
7543 els_command == ELS_CMD_FARPR ||
7544 els_command == ELS_CMD_FDISC)
7547 if (piocb->drvrTimeout > 0) {
7548 if (piocb->drvrTimeout >= timeout)
7549 piocb->drvrTimeout -= timeout;
7551 piocb->drvrTimeout = 0;
7555 remote_ID = 0xffffffff;
7556 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
7557 remote_ID = cmd->un.elsreq64.remoteID;
7559 struct lpfc_nodelist *ndlp;
7560 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
7561 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
7562 remote_ID = ndlp->nlp_DID;
7564 list_add_tail(&piocb->dlist, &abort_list);
7566 if (phba->sli_rev == LPFC_SLI_REV4)
7567 spin_unlock(&pring->ring_lock);
7568 spin_unlock_irq(&phba->hbalock);
7570 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
7572 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7573 "0127 ELS timeout Data: x%x x%x x%x "
7574 "x%x\n", els_command,
7575 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
7576 spin_lock_irq(&phba->hbalock);
7577 list_del_init(&piocb->dlist);
7578 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
7579 spin_unlock_irq(&phba->hbalock);
7582 if (!list_empty(&pring->txcmplq))
7583 if (!(phba->pport->load_flag & FC_UNLOADING))
7584 mod_timer(&vport->els_tmofunc,
7585 jiffies + msecs_to_jiffies(1000 * timeout));
7589 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
7590 * @vport: pointer to a host virtual N_Port data structure.
7592 * This routine is used to clean up all the outstanding ELS commands on a
7593 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
7594 * routine. After that, it walks the ELS transmit queue to remove all the
7595 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
7596 * the IOCBs with a non-NULL completion callback function, the callback
7597 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
7598 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
7599 * callback function, the IOCB will simply be released. Finally, it walks
7600 * the ELS transmit completion queue to issue an abort IOCB to any transmit
7601 * completion queue IOCB that is associated with the @vport and is not
7602 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
7603 * part of the discovery state machine) out to HBA by invoking the
7604 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
7605 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
7606 * the IOCBs are aborted when this function returns.
7609 lpfc_els_flush_cmd(struct lpfc_vport *vport)
7611 LIST_HEAD(abort_list);
7612 struct lpfc_hba *phba = vport->phba;
7613 struct lpfc_sli_ring *pring;
7614 struct lpfc_iocbq *tmp_iocb, *piocb;
7617 lpfc_fabric_abort_vport(vport);
7619 * For SLI3, only the hbalock is required. But SLI4 needs to coordinate
7620 * with the ring insert operation. Because lpfc_sli_issue_abort_iotag
7621 * ultimately grabs the ring_lock, the driver must splice the list into
7622 * a working list and release the locks before calling the abort.
7624 spin_lock_irq(&phba->hbalock);
7625 pring = lpfc_phba_elsring(phba);
7627 /* Bail out if we've no ELS wq, like in PCI error recovery case. */
7628 if (unlikely(!pring)) {
7629 spin_unlock_irq(&phba->hbalock);
7633 if (phba->sli_rev == LPFC_SLI_REV4)
7634 spin_lock(&pring->ring_lock);
7636 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
7637 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
7640 if (piocb->vport != vport)
7642 list_add_tail(&piocb->dlist, &abort_list);
7644 if (phba->sli_rev == LPFC_SLI_REV4)
7645 spin_unlock(&pring->ring_lock);
7646 spin_unlock_irq(&phba->hbalock);
7647 /* Abort each iocb on the aborted list and remove the dlist links. */
7648 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
7649 spin_lock_irq(&phba->hbalock);
7650 list_del_init(&piocb->dlist);
7651 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
7652 spin_unlock_irq(&phba->hbalock);
7654 if (!list_empty(&abort_list))
7655 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7656 "3387 abort list for txq not empty\n");
7657 INIT_LIST_HEAD(&abort_list);
7659 spin_lock_irq(&phba->hbalock);
7660 if (phba->sli_rev == LPFC_SLI_REV4)
7661 spin_lock(&pring->ring_lock);
7663 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
7666 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
7670 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
7671 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
7672 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
7673 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
7674 cmd->ulpCommand == CMD_ABORT_XRI_CN)
7677 if (piocb->vport != vport)
7680 list_del_init(&piocb->list);
7681 list_add_tail(&piocb->list, &abort_list);
7683 if (phba->sli_rev == LPFC_SLI_REV4)
7684 spin_unlock(&pring->ring_lock);
7685 spin_unlock_irq(&phba->hbalock);
7687 /* Cancell all the IOCBs from the completions list */
7688 lpfc_sli_cancel_iocbs(phba, &abort_list,
7689 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
7695 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
7696 * @phba: pointer to lpfc hba data structure.
7698 * This routine is used to clean up all the outstanding ELS commands on a
7699 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
7700 * routine. After that, it walks the ELS transmit queue to remove all the
7701 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
7702 * the IOCBs with the completion callback function associated, the callback
7703 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
7704 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
7705 * callback function associated, the IOCB will simply be released. Finally,
7706 * it walks the ELS transmit completion queue to issue an abort IOCB to any
7707 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
7708 * management plane IOCBs that are not part of the discovery state machine)
7709 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
7712 lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
7714 struct lpfc_vport *vport;
7715 list_for_each_entry(vport, &phba->port_list, listentry)
7716 lpfc_els_flush_cmd(vport);
7722 * lpfc_send_els_failure_event - Posts an ELS command failure event
7723 * @phba: Pointer to hba context object.
7724 * @cmdiocbp: Pointer to command iocb which reported error.
7725 * @rspiocbp: Pointer to response iocb which reported error.
7727 * This function sends an event when there is an ELS command
7731 lpfc_send_els_failure_event(struct lpfc_hba *phba,
7732 struct lpfc_iocbq *cmdiocbp,
7733 struct lpfc_iocbq *rspiocbp)
7735 struct lpfc_vport *vport = cmdiocbp->vport;
7736 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7737 struct lpfc_lsrjt_event lsrjt_event;
7738 struct lpfc_fabric_event_header fabric_event;
7740 struct lpfc_nodelist *ndlp;
7743 ndlp = cmdiocbp->context1;
7744 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
7747 if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) {
7748 lsrjt_event.header.event_type = FC_REG_ELS_EVENT;
7749 lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV;
7750 memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname,
7751 sizeof(struct lpfc_name));
7752 memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename,
7753 sizeof(struct lpfc_name));
7754 pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
7755 cmdiocbp->context2)->virt);
7756 lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0;
7757 stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]);
7758 lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode;
7759 lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp;
7760 fc_host_post_vendor_event(shost,
7761 fc_get_event_number(),
7762 sizeof(lsrjt_event),
7763 (char *)&lsrjt_event,
7767 if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) ||
7768 (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) {
7769 fabric_event.event_type = FC_REG_FABRIC_EVENT;
7770 if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY)
7771 fabric_event.subcategory = LPFC_EVENT_PORT_BUSY;
7773 fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY;
7774 memcpy(fabric_event.wwpn, &ndlp->nlp_portname,
7775 sizeof(struct lpfc_name));
7776 memcpy(fabric_event.wwnn, &ndlp->nlp_nodename,
7777 sizeof(struct lpfc_name));
7778 fc_host_post_vendor_event(shost,
7779 fc_get_event_number(),
7780 sizeof(fabric_event),
7781 (char *)&fabric_event,
7789 * lpfc_send_els_event - Posts unsolicited els event
7790 * @vport: Pointer to vport object.
7791 * @ndlp: Pointer FC node object.
7792 * @cmd: ELS command code.
7794 * This function posts an event when there is an incoming
7795 * unsolicited ELS command.
7798 lpfc_send_els_event(struct lpfc_vport *vport,
7799 struct lpfc_nodelist *ndlp,
7802 struct lpfc_els_event_header *els_data = NULL;
7803 struct lpfc_logo_event *logo_data = NULL;
7804 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7806 if (*payload == ELS_CMD_LOGO) {
7807 logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL);
7809 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7810 "0148 Failed to allocate memory "
7811 "for LOGO event\n");
7814 els_data = &logo_data->header;
7816 els_data = kmalloc(sizeof(struct lpfc_els_event_header),
7819 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7820 "0149 Failed to allocate memory "
7825 els_data->event_type = FC_REG_ELS_EVENT;
7828 els_data->subcategory = LPFC_EVENT_PLOGI_RCV;
7831 els_data->subcategory = LPFC_EVENT_PRLO_RCV;
7834 els_data->subcategory = LPFC_EVENT_ADISC_RCV;
7837 els_data->subcategory = LPFC_EVENT_LOGO_RCV;
7838 /* Copy the WWPN in the LOGO payload */
7839 memcpy(logo_data->logo_wwpn, &payload[2],
7840 sizeof(struct lpfc_name));
7846 memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name));
7847 memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name));
7848 if (*payload == ELS_CMD_LOGO) {
7849 fc_host_post_vendor_event(shost,
7850 fc_get_event_number(),
7851 sizeof(struct lpfc_logo_event),
7856 fc_host_post_vendor_event(shost,
7857 fc_get_event_number(),
7858 sizeof(struct lpfc_els_event_header),
7869 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
7870 * @phba: pointer to lpfc hba data structure.
7871 * @pring: pointer to a SLI ring.
7872 * @vport: pointer to a host virtual N_Port data structure.
7873 * @elsiocb: pointer to lpfc els command iocb data structure.
7875 * This routine is used for processing the IOCB associated with a unsolicited
7876 * event. It first determines whether there is an existing ndlp that matches
7877 * the DID from the unsolicited IOCB. If not, it will create a new one with
7878 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
7879 * IOCB is then used to invoke the proper routine and to set up proper state
7880 * of the discovery state machine.
7883 lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
7884 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
7886 struct Scsi_Host *shost;
7887 struct lpfc_nodelist *ndlp;
7890 uint32_t cmd, did, newnode;
7891 uint8_t rjt_exp, rjt_err = 0, init_link = 0;
7892 IOCB_t *icmd = &elsiocb->iocb;
7895 if (!vport || !(elsiocb->context2))
7899 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
7901 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
7902 lpfc_post_buffer(phba, pring, 1);
7904 did = icmd->un.rcvels.remoteID;
7905 if (icmd->ulpStatus) {
7906 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7907 "RCV Unsol ELS: status:x%x/x%x did:x%x",
7908 icmd->ulpStatus, icmd->un.ulpWord[4], did);
7912 /* Check to see if link went down during discovery */
7913 if (lpfc_els_chk_latt(vport))
7916 /* Ignore traffic received during vport shutdown. */
7917 if (vport->load_flag & FC_UNLOADING)
7920 /* If NPort discovery is delayed drop incoming ELS */
7921 if ((vport->fc_flag & FC_DISC_DELAYED) &&
7922 (cmd != ELS_CMD_PLOGI))
7925 ndlp = lpfc_findnode_did(vport, did);
7927 /* Cannot find existing Fabric ndlp, so allocate a new one */
7928 ndlp = lpfc_nlp_init(vport, did);
7931 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
7933 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
7934 ndlp->nlp_type |= NLP_FABRIC;
7935 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
7936 ndlp = lpfc_enable_node(vport, ndlp,
7937 NLP_STE_UNUSED_NODE);
7940 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
7942 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
7943 ndlp->nlp_type |= NLP_FABRIC;
7944 } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
7945 /* This is similar to the new node path */
7946 ndlp = lpfc_nlp_get(ndlp);
7949 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
7953 phba->fc_stat.elsRcvFrame++;
7956 * Do not process any unsolicited ELS commands
7957 * if the ndlp is in DEV_LOSS
7959 shost = lpfc_shost_from_vport(vport);
7960 spin_lock_irq(shost->host_lock);
7961 if (ndlp->nlp_flag & NLP_IN_DEV_LOSS) {
7962 spin_unlock_irq(shost->host_lock);
7967 spin_unlock_irq(shost->host_lock);
7969 elsiocb->context1 = lpfc_nlp_get(ndlp);
7970 elsiocb->vport = vport;
7972 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
7973 cmd &= ELS_CMD_MASK;
7975 /* ELS command <elsCmd> received from NPORT <did> */
7976 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7977 "0112 ELS command x%x received from NPORT x%x "
7978 "Data: x%x x%x x%x x%x\n",
7979 cmd, did, vport->port_state, vport->fc_flag,
7980 vport->fc_myDID, vport->fc_prevDID);
7982 /* reject till our FLOGI completes */
7983 if ((vport->port_state < LPFC_FABRIC_CFG_LINK) &&
7984 (cmd != ELS_CMD_FLOGI)) {
7985 rjt_err = LSRJT_LOGICAL_BSY;
7986 rjt_exp = LSEXP_NOTHING_MORE;
7992 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7993 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
7994 did, vport->port_state, ndlp->nlp_flag);
7996 phba->fc_stat.elsRcvPLOGI++;
7997 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
7998 if (phba->sli_rev == LPFC_SLI_REV4 &&
7999 (phba->pport->fc_flag & FC_PT2PT)) {
8000 vport->fc_prevDID = vport->fc_myDID;
8001 /* Our DID needs to be updated before registering
8002 * the vfi. This is done in lpfc_rcv_plogi but
8003 * that is called after the reg_vfi.
8005 vport->fc_myDID = elsiocb->iocb.un.rcvels.parmRo;
8006 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
8007 "3312 Remote port assigned DID x%x "
8008 "%x\n", vport->fc_myDID,
8012 lpfc_send_els_event(vport, ndlp, payload);
8014 /* If Nport discovery is delayed, reject PLOGIs */
8015 if (vport->fc_flag & FC_DISC_DELAYED) {
8016 rjt_err = LSRJT_UNABLE_TPC;
8017 rjt_exp = LSEXP_NOTHING_MORE;
8021 if (vport->port_state < LPFC_DISC_AUTH) {
8022 if (!(phba->pport->fc_flag & FC_PT2PT) ||
8023 (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
8024 rjt_err = LSRJT_UNABLE_TPC;
8025 rjt_exp = LSEXP_NOTHING_MORE;
8030 spin_lock_irq(shost->host_lock);
8031 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
8032 spin_unlock_irq(shost->host_lock);
8034 lpfc_disc_state_machine(vport, ndlp, elsiocb,
8039 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8040 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
8041 did, vport->port_state, ndlp->nlp_flag);
8043 phba->fc_stat.elsRcvFLOGI++;
8045 /* If the driver believes fabric discovery is done and is ready,
8046 * bounce the link. There is some descrepancy.
8048 if (vport->port_state >= LPFC_LOCAL_CFG_LINK &&
8049 vport->fc_flag & FC_PT2PT &&
8050 vport->rcv_flogi_cnt >= 1) {
8051 rjt_err = LSRJT_LOGICAL_BSY;
8052 rjt_exp = LSEXP_NOTHING_MORE;
8057 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
8062 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8063 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
8064 did, vport->port_state, ndlp->nlp_flag);
8066 phba->fc_stat.elsRcvLOGO++;
8067 lpfc_send_els_event(vport, ndlp, payload);
8068 if (vport->port_state < LPFC_DISC_AUTH) {
8069 rjt_err = LSRJT_UNABLE_TPC;
8070 rjt_exp = LSEXP_NOTHING_MORE;
8073 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
8076 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8077 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
8078 did, vport->port_state, ndlp->nlp_flag);
8080 phba->fc_stat.elsRcvPRLO++;
8081 lpfc_send_els_event(vport, ndlp, payload);
8082 if (vport->port_state < LPFC_DISC_AUTH) {
8083 rjt_err = LSRJT_UNABLE_TPC;
8084 rjt_exp = LSEXP_NOTHING_MORE;
8087 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
8090 phba->fc_stat.elsRcvLCB++;
8091 lpfc_els_rcv_lcb(vport, elsiocb, ndlp);
8094 phba->fc_stat.elsRcvRDP++;
8095 lpfc_els_rcv_rdp(vport, elsiocb, ndlp);
8098 phba->fc_stat.elsRcvRSCN++;
8099 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
8104 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8105 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
8106 did, vport->port_state, ndlp->nlp_flag);
8108 lpfc_send_els_event(vport, ndlp, payload);
8109 phba->fc_stat.elsRcvADISC++;
8110 if (vport->port_state < LPFC_DISC_AUTH) {
8111 rjt_err = LSRJT_UNABLE_TPC;
8112 rjt_exp = LSEXP_NOTHING_MORE;
8115 lpfc_disc_state_machine(vport, ndlp, elsiocb,
8119 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8120 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
8121 did, vport->port_state, ndlp->nlp_flag);
8123 phba->fc_stat.elsRcvPDISC++;
8124 if (vport->port_state < LPFC_DISC_AUTH) {
8125 rjt_err = LSRJT_UNABLE_TPC;
8126 rjt_exp = LSEXP_NOTHING_MORE;
8129 lpfc_disc_state_machine(vport, ndlp, elsiocb,
8133 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8134 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
8135 did, vport->port_state, ndlp->nlp_flag);
8137 phba->fc_stat.elsRcvFARPR++;
8138 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
8141 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8142 "RCV FARP: did:x%x/ste:x%x flg:x%x",
8143 did, vport->port_state, ndlp->nlp_flag);
8145 phba->fc_stat.elsRcvFARP++;
8146 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
8149 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8150 "RCV FAN: did:x%x/ste:x%x flg:x%x",
8151 did, vport->port_state, ndlp->nlp_flag);
8153 phba->fc_stat.elsRcvFAN++;
8154 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
8157 case ELS_CMD_NVMEPRLI:
8158 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8159 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
8160 did, vport->port_state, ndlp->nlp_flag);
8162 phba->fc_stat.elsRcvPRLI++;
8163 if ((vport->port_state < LPFC_DISC_AUTH) &&
8164 (vport->fc_flag & FC_FABRIC)) {
8165 rjt_err = LSRJT_UNABLE_TPC;
8166 rjt_exp = LSEXP_NOTHING_MORE;
8169 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
8172 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8173 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
8174 did, vport->port_state, ndlp->nlp_flag);
8176 phba->fc_stat.elsRcvLIRR++;
8177 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
8182 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8183 "RCV RLS: did:x%x/ste:x%x flg:x%x",
8184 did, vport->port_state, ndlp->nlp_flag);
8186 phba->fc_stat.elsRcvRLS++;
8187 lpfc_els_rcv_rls(vport, elsiocb, ndlp);
8192 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8193 "RCV RPS: did:x%x/ste:x%x flg:x%x",
8194 did, vport->port_state, ndlp->nlp_flag);
8196 phba->fc_stat.elsRcvRPS++;
8197 lpfc_els_rcv_rps(vport, elsiocb, ndlp);
8202 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8203 "RCV RPL: did:x%x/ste:x%x flg:x%x",
8204 did, vport->port_state, ndlp->nlp_flag);
8206 phba->fc_stat.elsRcvRPL++;
8207 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
8212 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8213 "RCV RNID: did:x%x/ste:x%x flg:x%x",
8214 did, vport->port_state, ndlp->nlp_flag);
8216 phba->fc_stat.elsRcvRNID++;
8217 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
8222 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8223 "RCV RTV: did:x%x/ste:x%x flg:x%x",
8224 did, vport->port_state, ndlp->nlp_flag);
8225 phba->fc_stat.elsRcvRTV++;
8226 lpfc_els_rcv_rtv(vport, elsiocb, ndlp);
8231 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8232 "RCV RRQ: did:x%x/ste:x%x flg:x%x",
8233 did, vport->port_state, ndlp->nlp_flag);
8235 phba->fc_stat.elsRcvRRQ++;
8236 lpfc_els_rcv_rrq(vport, elsiocb, ndlp);
8241 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8242 "RCV ECHO: did:x%x/ste:x%x flg:x%x",
8243 did, vport->port_state, ndlp->nlp_flag);
8245 phba->fc_stat.elsRcvECHO++;
8246 lpfc_els_rcv_echo(vport, elsiocb, ndlp);
8251 /* receive this due to exchange closed */
8252 rjt_err = LSRJT_UNABLE_TPC;
8253 rjt_exp = LSEXP_INVALID_OX_RX;
8256 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8257 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
8258 cmd, did, vport->port_state);
8260 /* Unsupported ELS command, reject */
8261 rjt_err = LSRJT_CMD_UNSUPPORTED;
8262 rjt_exp = LSEXP_NOTHING_MORE;
8264 /* Unknown ELS command <elsCmd> received from NPORT <did> */
8265 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8266 "0115 Unknown ELS command x%x "
8267 "received from NPORT x%x\n", cmd, did);
8274 /* check if need to LS_RJT received ELS cmd */
8276 memset(&stat, 0, sizeof(stat));
8277 stat.un.b.lsRjtRsnCode = rjt_err;
8278 stat.un.b.lsRjtRsnCodeExp = rjt_exp;
8279 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
8283 lpfc_nlp_put(elsiocb->context1);
8284 elsiocb->context1 = NULL;
8286 /* Special case. Driver received an unsolicited command that
8287 * unsupportable given the driver's current state. Reset the
8288 * link and start over.
8291 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
8294 lpfc_linkdown(phba);
8295 lpfc_init_link(phba, mbox,
8297 phba->cfg_link_speed);
8298 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
8299 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
8300 mbox->vport = vport;
8301 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) ==
8303 mempool_free(mbox, phba->mbox_mem_pool);
8309 if (vport && !(vport->load_flag & FC_UNLOADING))
8310 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8311 "0111 Dropping received ELS cmd "
8312 "Data: x%x x%x x%x\n",
8313 icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout);
8314 phba->fc_stat.elsRcvDrop++;
8318 * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
8319 * @phba: pointer to lpfc hba data structure.
8320 * @pring: pointer to a SLI ring.
8321 * @elsiocb: pointer to lpfc els iocb data structure.
8323 * This routine is used to process an unsolicited event received from a SLI
8324 * (Service Level Interface) ring. The actual processing of the data buffer
8325 * associated with the unsolicited event is done by invoking the routine
8326 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
8327 * SLI ring on which the unsolicited event was received.
8330 lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
8331 struct lpfc_iocbq *elsiocb)
8333 struct lpfc_vport *vport = phba->pport;
8334 IOCB_t *icmd = &elsiocb->iocb;
8336 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
8337 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
8339 elsiocb->context1 = NULL;
8340 elsiocb->context2 = NULL;
8341 elsiocb->context3 = NULL;
8343 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
8344 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
8345 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
8346 (icmd->un.ulpWord[4] & IOERR_PARAM_MASK) ==
8347 IOERR_RCV_BUFFER_WAITING) {
8348 phba->fc_stat.NoRcvBuf++;
8349 /* Not enough posted buffers; Try posting more buffers */
8350 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
8351 lpfc_post_buffer(phba, pring, 0);
8355 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
8356 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
8357 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
8358 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
8359 vport = phba->pport;
8361 vport = lpfc_find_vport_by_vpid(phba,
8362 icmd->unsli3.rcvsli3.vpi);
8365 /* If there are no BDEs associated
8366 * with this IOCB, there is nothing to do.
8368 if (icmd->ulpBdeCount == 0)
8371 /* type of ELS cmd is first 32bit word
8374 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
8375 elsiocb->context2 = bdeBuf1;
8377 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
8378 icmd->un.cont64[0].addrLow);
8379 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
8383 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
8385 * The different unsolicited event handlers would tell us
8386 * if they are done with "mp" by setting context2 to NULL.
8388 if (elsiocb->context2) {
8389 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
8390 elsiocb->context2 = NULL;
8393 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
8394 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
8395 icmd->ulpBdeCount == 2) {
8396 elsiocb->context2 = bdeBuf2;
8397 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
8398 /* free mp if we are done with it */
8399 if (elsiocb->context2) {
8400 lpfc_in_buf_free(phba, elsiocb->context2);
8401 elsiocb->context2 = NULL;
8407 lpfc_start_fdmi(struct lpfc_vport *vport)
8409 struct lpfc_nodelist *ndlp;
8411 /* If this is the first time, allocate an ndlp and initialize
8412 * it. Otherwise, make sure the node is enabled and then do the
8415 ndlp = lpfc_findnode_did(vport, FDMI_DID);
8417 ndlp = lpfc_nlp_init(vport, FDMI_DID);
8419 ndlp->nlp_type |= NLP_FABRIC;
8424 if (!NLP_CHK_NODE_ACT(ndlp))
8425 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_NPR_NODE);
8428 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
8429 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
8434 * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
8435 * @phba: pointer to lpfc hba data structure.
8436 * @vport: pointer to a virtual N_Port data structure.
8438 * This routine issues a Port Login (PLOGI) to the Name Server with
8439 * State Change Request (SCR) for a @vport. This routine will create an
8440 * ndlp for the Name Server associated to the @vport if such node does
8441 * not already exist. The PLOGI to Name Server is issued by invoking the
8442 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
8443 * (FDMI) is configured to the @vport, a FDMI node will be created and
8444 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
8447 lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
8449 struct lpfc_nodelist *ndlp;
8450 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8453 * If lpfc_delay_discovery parameter is set and the clean address
8454 * bit is cleared and fc fabric parameters chenged, delay FC NPort
8457 spin_lock_irq(shost->host_lock);
8458 if (vport->fc_flag & FC_DISC_DELAYED) {
8459 spin_unlock_irq(shost->host_lock);
8460 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
8461 "3334 Delay fc port discovery for %d seconds\n",
8463 mod_timer(&vport->delayed_disc_tmo,
8464 jiffies + msecs_to_jiffies(1000 * phba->fc_ratov));
8467 spin_unlock_irq(shost->host_lock);
8469 ndlp = lpfc_findnode_did(vport, NameServer_DID);
8471 ndlp = lpfc_nlp_init(vport, NameServer_DID);
8473 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
8474 lpfc_disc_start(vport);
8477 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
8478 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8479 "0251 NameServer login: no memory\n");
8482 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
8483 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
8485 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
8486 lpfc_disc_start(vport);
8489 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
8490 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8491 "0348 NameServer login: node freed\n");
8495 ndlp->nlp_type |= NLP_FABRIC;
8497 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
8499 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
8500 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
8501 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8502 "0252 Cannot issue NameServer login\n");
8506 if ((phba->cfg_enable_SmartSAN ||
8507 (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) &&
8508 (vport->load_flag & FC_ALLOW_FDMI))
8509 lpfc_start_fdmi(vport);
8513 * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
8514 * @phba: pointer to lpfc hba data structure.
8515 * @pmb: pointer to the driver internal queue element for mailbox command.
8517 * This routine is the completion callback function to register new vport
8518 * mailbox command. If the new vport mailbox command completes successfully,
8519 * the fabric registration login shall be performed on physical port (the
8520 * new vport created is actually a physical port, with VPI 0) or the port
8521 * login to Name Server for State Change Request (SCR) will be performed
8522 * on virtual port (real virtual port, with VPI greater than 0).
8525 lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
8527 struct lpfc_vport *vport = pmb->vport;
8528 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8529 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
8530 MAILBOX_t *mb = &pmb->u.mb;
8533 spin_lock_irq(shost->host_lock);
8534 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
8535 spin_unlock_irq(shost->host_lock);
8537 if (mb->mbxStatus) {
8538 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
8539 "0915 Register VPI failed : Status: x%x"
8540 " upd bit: x%x \n", mb->mbxStatus,
8541 mb->un.varRegVpi.upd);
8542 if (phba->sli_rev == LPFC_SLI_REV4 &&
8543 mb->un.varRegVpi.upd)
8544 goto mbox_err_exit ;
8546 switch (mb->mbxStatus) {
8547 case 0x11: /* unsupported feature */
8548 case 0x9603: /* max_vpi exceeded */
8549 case 0x9602: /* Link event since CLEAR_LA */
8550 /* giving up on vport registration */
8551 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
8552 spin_lock_irq(shost->host_lock);
8553 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
8554 spin_unlock_irq(shost->host_lock);
8555 lpfc_can_disctmo(vport);
8557 /* If reg_vpi fail with invalid VPI status, re-init VPI */
8559 spin_lock_irq(shost->host_lock);
8560 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
8561 spin_unlock_irq(shost->host_lock);
8562 lpfc_init_vpi(phba, pmb, vport->vpi);
8564 pmb->mbox_cmpl = lpfc_init_vpi_cmpl;
8565 rc = lpfc_sli_issue_mbox(phba, pmb,
8567 if (rc == MBX_NOT_FINISHED) {
8568 lpfc_printf_vlog(vport,
8570 "2732 Failed to issue INIT_VPI"
8571 " mailbox command\n");
8578 /* Try to recover from this error */
8579 if (phba->sli_rev == LPFC_SLI_REV4)
8580 lpfc_sli4_unreg_all_rpis(vport);
8581 lpfc_mbx_unreg_vpi(vport);
8582 spin_lock_irq(shost->host_lock);
8583 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
8584 spin_unlock_irq(shost->host_lock);
8585 if (mb->mbxStatus == MBX_NOT_FINISHED)
8587 if ((vport->port_type == LPFC_PHYSICAL_PORT) &&
8588 !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG)) {
8589 if (phba->sli_rev == LPFC_SLI_REV4)
8590 lpfc_issue_init_vfi(vport);
8592 lpfc_initial_flogi(vport);
8594 lpfc_initial_fdisc(vport);
8599 spin_lock_irq(shost->host_lock);
8600 vport->vpi_state |= LPFC_VPI_REGISTERED;
8601 spin_unlock_irq(shost->host_lock);
8602 if (vport == phba->pport) {
8603 if (phba->sli_rev < LPFC_SLI_REV4)
8604 lpfc_issue_fabric_reglogin(vport);
8607 * If the physical port is instantiated using
8608 * FDISC, do not start vport discovery.
8610 if (vport->port_state != LPFC_FDISC)
8611 lpfc_start_fdiscs(phba);
8612 lpfc_do_scr_ns_plogi(phba, vport);
8615 lpfc_do_scr_ns_plogi(phba, vport);
8618 /* Now, we decrement the ndlp reference count held for this
8623 mempool_free(pmb, phba->mbox_mem_pool);
8628 * lpfc_register_new_vport - Register a new vport with a HBA
8629 * @phba: pointer to lpfc hba data structure.
8630 * @vport: pointer to a host virtual N_Port data structure.
8631 * @ndlp: pointer to a node-list data structure.
8633 * This routine registers the @vport as a new virtual port with a HBA.
8634 * It is done through a registering vpi mailbox command.
8637 lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
8638 struct lpfc_nodelist *ndlp)
8640 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8643 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
8645 lpfc_reg_vpi(vport, mbox);
8646 mbox->vport = vport;
8647 mbox->context2 = lpfc_nlp_get(ndlp);
8648 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
8649 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
8650 == MBX_NOT_FINISHED) {
8651 /* mailbox command not success, decrement ndlp
8652 * reference count for this command
8655 mempool_free(mbox, phba->mbox_mem_pool);
8657 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
8658 "0253 Register VPI: Can't send mbox\n");
8662 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
8663 "0254 Register VPI: no memory\n");
8669 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
8670 spin_lock_irq(shost->host_lock);
8671 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
8672 spin_unlock_irq(shost->host_lock);
8677 * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer
8678 * @phba: pointer to lpfc hba data structure.
8680 * This routine cancels the retry delay timers to all the vports.
8683 lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba)
8685 struct lpfc_vport **vports;
8686 struct lpfc_nodelist *ndlp;
8687 uint32_t link_state;
8690 /* Treat this failure as linkdown for all vports */
8691 link_state = phba->link_state;
8692 lpfc_linkdown(phba);
8693 phba->link_state = link_state;
8695 vports = lpfc_create_vport_work_array(phba);
8698 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
8699 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
8701 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
8702 lpfc_els_flush_cmd(vports[i]);
8704 lpfc_destroy_vport_work_array(phba, vports);
8709 * lpfc_retry_pport_discovery - Start timer to retry FLOGI.
8710 * @phba: pointer to lpfc hba data structure.
8712 * This routine abort all pending discovery commands and
8713 * start a timer to retry FLOGI for the physical port
8717 lpfc_retry_pport_discovery(struct lpfc_hba *phba)
8719 struct lpfc_nodelist *ndlp;
8720 struct Scsi_Host *shost;
8722 /* Cancel the all vports retry delay retry timers */
8723 lpfc_cancel_all_vport_retry_delay_timer(phba);
8725 /* If fabric require FLOGI, then re-instantiate physical login */
8726 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
8730 shost = lpfc_shost_from_vport(phba->pport);
8731 mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000));
8732 spin_lock_irq(shost->host_lock);
8733 ndlp->nlp_flag |= NLP_DELAY_TMO;
8734 spin_unlock_irq(shost->host_lock);
8735 ndlp->nlp_last_elscmd = ELS_CMD_FLOGI;
8736 phba->pport->port_state = LPFC_FLOGI;
8741 * lpfc_fabric_login_reqd - Check if FLOGI required.
8742 * @phba: pointer to lpfc hba data structure.
8743 * @cmdiocb: pointer to FDISC command iocb.
8744 * @rspiocb: pointer to FDISC response iocb.
8746 * This routine checks if a FLOGI is reguired for FDISC
8750 lpfc_fabric_login_reqd(struct lpfc_hba *phba,
8751 struct lpfc_iocbq *cmdiocb,
8752 struct lpfc_iocbq *rspiocb)
8755 if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) ||
8756 (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED))
8763 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
8764 * @phba: pointer to lpfc hba data structure.
8765 * @cmdiocb: pointer to lpfc command iocb data structure.
8766 * @rspiocb: pointer to lpfc response iocb data structure.
8768 * This routine is the completion callback function to a Fabric Discover
8769 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
8770 * single threaded, each FDISC completion callback function will reset
8771 * the discovery timer for all vports such that the timers will not get
8772 * unnecessary timeout. The function checks the FDISC IOCB status. If error
8773 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
8774 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
8775 * assigned to the vport has been changed with the completion of the FDISC
8776 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
8777 * are unregistered from the HBA, and then the lpfc_register_new_vport()
8778 * routine is invoked to register new vport with the HBA. Otherwise, the
8779 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
8780 * Server for State Change Request (SCR).
8783 lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
8784 struct lpfc_iocbq *rspiocb)
8786 struct lpfc_vport *vport = cmdiocb->vport;
8787 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8788 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
8789 struct lpfc_nodelist *np;
8790 struct lpfc_nodelist *next_np;
8791 IOCB_t *irsp = &rspiocb->iocb;
8792 struct lpfc_iocbq *piocb;
8793 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
8794 struct serv_parm *sp;
8795 uint8_t fabric_param_changed;
8797 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
8798 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
8799 irsp->ulpStatus, irsp->un.ulpWord[4],
8801 /* Since all FDISCs are being single threaded, we
8802 * must reset the discovery timer for ALL vports
8803 * waiting to send FDISC when one completes.
8805 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
8806 lpfc_set_disctmo(piocb->vport);
8809 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
8810 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
8811 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
8813 if (irsp->ulpStatus) {
8815 if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) {
8816 lpfc_retry_pport_discovery(phba);
8820 /* Check for retry */
8821 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
8824 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8825 "0126 FDISC failed. (x%x/x%x)\n",
8826 irsp->ulpStatus, irsp->un.ulpWord[4]);
8829 spin_lock_irq(shost->host_lock);
8830 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
8831 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
8832 vport->fc_flag |= FC_FABRIC;
8833 if (vport->phba->fc_topology == LPFC_TOPOLOGY_LOOP)
8834 vport->fc_flag |= FC_PUBLIC_LOOP;
8835 spin_unlock_irq(shost->host_lock);
8837 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
8838 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
8839 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
8842 sp = prsp->virt + sizeof(uint32_t);
8843 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
8844 memcpy(&vport->fabric_portname, &sp->portName,
8845 sizeof(struct lpfc_name));
8846 memcpy(&vport->fabric_nodename, &sp->nodeName,
8847 sizeof(struct lpfc_name));
8848 if (fabric_param_changed &&
8849 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
8850 /* If our NportID changed, we need to ensure all
8851 * remaining NPORTs get unreg_login'ed so we can
8854 list_for_each_entry_safe(np, next_np,
8855 &vport->fc_nodes, nlp_listp) {
8856 if (!NLP_CHK_NODE_ACT(ndlp) ||
8857 (np->nlp_state != NLP_STE_NPR_NODE) ||
8858 !(np->nlp_flag & NLP_NPR_ADISC))
8860 spin_lock_irq(shost->host_lock);
8861 np->nlp_flag &= ~NLP_NPR_ADISC;
8862 spin_unlock_irq(shost->host_lock);
8863 lpfc_unreg_rpi(vport, np);
8865 lpfc_cleanup_pending_mbox(vport);
8867 if (phba->sli_rev == LPFC_SLI_REV4)
8868 lpfc_sli4_unreg_all_rpis(vport);
8870 lpfc_mbx_unreg_vpi(vport);
8871 spin_lock_irq(shost->host_lock);
8872 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
8873 if (phba->sli_rev == LPFC_SLI_REV4)
8874 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
8876 vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG;
8877 spin_unlock_irq(shost->host_lock);
8878 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
8879 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
8881 * Driver needs to re-reg VPI in order for f/w
8882 * to update the MAC address.
8884 lpfc_register_new_vport(phba, vport, ndlp);
8888 if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)
8889 lpfc_issue_init_vpi(vport);
8890 else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
8891 lpfc_register_new_vport(phba, vport, ndlp);
8893 lpfc_do_scr_ns_plogi(phba, vport);
8896 if (vport->fc_vport &&
8897 (vport->fc_vport->vport_state != FC_VPORT_NO_FABRIC_RSCS))
8898 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
8899 /* Cancel discovery timer */
8900 lpfc_can_disctmo(vport);
8903 lpfc_els_free_iocb(phba, cmdiocb);
8907 * lpfc_issue_els_fdisc - Issue a fdisc iocb command
8908 * @vport: pointer to a virtual N_Port data structure.
8909 * @ndlp: pointer to a node-list data structure.
8910 * @retry: number of retries to the command IOCB.
8912 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
8913 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
8914 * routine to issue the IOCB, which makes sure only one outstanding fabric
8915 * IOCB will be sent off HBA at any given time.
8917 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
8918 * will be incremented by 1 for holding the ndlp and the reference to ndlp
8919 * will be stored into the context1 field of the IOCB for the completion
8920 * callback function to the FDISC ELS command.
8923 * 0 - Successfully issued fdisc iocb command
8924 * 1 - Failed to issue fdisc iocb command
8927 lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
8930 struct lpfc_hba *phba = vport->phba;
8932 struct lpfc_iocbq *elsiocb;
8933 struct serv_parm *sp;
8936 int did = ndlp->nlp_DID;
8939 vport->port_state = LPFC_FDISC;
8940 vport->fc_myDID = 0;
8941 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
8942 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
8945 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
8946 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8947 "0255 Issue FDISC: no IOCB\n");
8951 icmd = &elsiocb->iocb;
8952 icmd->un.elsreq64.myID = 0;
8953 icmd->un.elsreq64.fl = 1;
8956 * SLI3 ports require a different context type value than SLI4.
8957 * Catch SLI3 ports here and override the prep.
8959 if (phba->sli_rev == LPFC_SLI_REV3) {
8964 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
8965 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
8966 pcmd += sizeof(uint32_t); /* CSP Word 1 */
8967 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
8968 sp = (struct serv_parm *) pcmd;
8969 /* Setup CSPs accordingly for Fabric */
8970 sp->cmn.e_d_tov = 0;
8971 sp->cmn.w2.r_a_tov = 0;
8972 sp->cmn.virtual_fabric_support = 0;
8973 sp->cls1.classValid = 0;
8974 sp->cls2.seqDelivery = 1;
8975 sp->cls3.seqDelivery = 1;
8977 pcmd += sizeof(uint32_t); /* CSP Word 2 */
8978 pcmd += sizeof(uint32_t); /* CSP Word 3 */
8979 pcmd += sizeof(uint32_t); /* CSP Word 4 */
8980 pcmd += sizeof(uint32_t); /* Port Name */
8981 memcpy(pcmd, &vport->fc_portname, 8);
8982 pcmd += sizeof(uint32_t); /* Node Name */
8983 pcmd += sizeof(uint32_t); /* Node Name */
8984 memcpy(pcmd, &vport->fc_nodename, 8);
8985 sp->cmn.valid_vendor_ver_level = 0;
8986 memset(sp->un.vendorVersion, 0, sizeof(sp->un.vendorVersion));
8987 lpfc_set_disctmo(vport);
8989 phba->fc_stat.elsXmitFDISC++;
8990 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
8992 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
8993 "Issue FDISC: did:x%x",
8996 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
8997 if (rc == IOCB_ERROR) {
8998 lpfc_els_free_iocb(phba, elsiocb);
8999 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
9000 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
9001 "0256 Issue FDISC: Cannot send IOCB\n");
9004 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
9009 * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
9010 * @phba: pointer to lpfc hba data structure.
9011 * @cmdiocb: pointer to lpfc command iocb data structure.
9012 * @rspiocb: pointer to lpfc response iocb data structure.
9014 * This routine is the completion callback function to the issuing of a LOGO
9015 * ELS command off a vport. It frees the command IOCB and then decrement the
9016 * reference count held on ndlp for this completion function, indicating that
9017 * the reference to the ndlp is no long needed. Note that the
9018 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
9019 * callback function and an additional explicit ndlp reference decrementation
9020 * will trigger the actual release of the ndlp.
9023 lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
9024 struct lpfc_iocbq *rspiocb)
9026 struct lpfc_vport *vport = cmdiocb->vport;
9028 struct lpfc_nodelist *ndlp;
9029 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
9031 ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
9032 irsp = &rspiocb->iocb;
9033 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
9034 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
9035 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
9037 lpfc_els_free_iocb(phba, cmdiocb);
9038 vport->unreg_vpi_cmpl = VPORT_ERROR;
9040 /* Trigger the release of the ndlp after logo */
9043 /* NPIV LOGO completes to NPort <nlp_DID> */
9044 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
9045 "2928 NPIV LOGO completes to NPort x%x "
9046 "Data: x%x x%x x%x x%x\n",
9047 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
9048 irsp->ulpTimeout, vport->num_disc_nodes);
9050 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
9051 spin_lock_irq(shost->host_lock);
9052 vport->fc_flag &= ~FC_NDISC_ACTIVE;
9053 vport->fc_flag &= ~FC_FABRIC;
9054 spin_unlock_irq(shost->host_lock);
9055 lpfc_can_disctmo(vport);
9060 * lpfc_issue_els_npiv_logo - Issue a logo off a vport
9061 * @vport: pointer to a virtual N_Port data structure.
9062 * @ndlp: pointer to a node-list data structure.
9064 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
9066 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
9067 * will be incremented by 1 for holding the ndlp and the reference to ndlp
9068 * will be stored into the context1 field of the IOCB for the completion
9069 * callback function to the LOGO ELS command.
9072 * 0 - Successfully issued logo off the @vport
9073 * 1 - Failed to issue logo off the @vport
9076 lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
9078 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
9079 struct lpfc_hba *phba = vport->phba;
9080 struct lpfc_iocbq *elsiocb;
9084 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
9085 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
9090 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
9091 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
9092 pcmd += sizeof(uint32_t);
9094 /* Fill in LOGO payload */
9095 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
9096 pcmd += sizeof(uint32_t);
9097 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
9099 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
9100 "Issue LOGO npiv did:x%x flg:x%x",
9101 ndlp->nlp_DID, ndlp->nlp_flag, 0);
9103 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
9104 spin_lock_irq(shost->host_lock);
9105 ndlp->nlp_flag |= NLP_LOGO_SND;
9106 spin_unlock_irq(shost->host_lock);
9107 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
9109 spin_lock_irq(shost->host_lock);
9110 ndlp->nlp_flag &= ~NLP_LOGO_SND;
9111 spin_unlock_irq(shost->host_lock);
9112 lpfc_els_free_iocb(phba, elsiocb);
9119 * lpfc_fabric_block_timeout - Handler function to the fabric block timer
9120 * @ptr: holder for the timer function associated data.
9122 * This routine is invoked by the fabric iocb block timer after
9123 * timeout. It posts the fabric iocb block timeout event by setting the
9124 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
9125 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
9126 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
9127 * posted event WORKER_FABRIC_BLOCK_TMO.
9130 lpfc_fabric_block_timeout(struct timer_list *t)
9132 struct lpfc_hba *phba = from_timer(phba, t, fabric_block_timer);
9133 unsigned long iflags;
9134 uint32_t tmo_posted;
9136 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
9137 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
9139 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
9140 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
9143 lpfc_worker_wake_up(phba);
9148 * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
9149 * @phba: pointer to lpfc hba data structure.
9151 * This routine issues one fabric iocb from the driver internal list to
9152 * the HBA. It first checks whether it's ready to issue one fabric iocb to
9153 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
9154 * remove one pending fabric iocb from the driver internal list and invokes
9155 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
9158 lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
9160 struct lpfc_iocbq *iocb;
9161 unsigned long iflags;
9167 spin_lock_irqsave(&phba->hbalock, iflags);
9168 /* Post any pending iocb to the SLI layer */
9169 if (atomic_read(&phba->fabric_iocb_count) == 0) {
9170 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
9173 /* Increment fabric iocb count to hold the position */
9174 atomic_inc(&phba->fabric_iocb_count);
9176 spin_unlock_irqrestore(&phba->hbalock, iflags);
9178 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
9179 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
9180 iocb->iocb_flag |= LPFC_IO_FABRIC;
9182 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
9183 "Fabric sched1: ste:x%x",
9184 iocb->vport->port_state, 0, 0);
9186 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
9188 if (ret == IOCB_ERROR) {
9189 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
9190 iocb->fabric_iocb_cmpl = NULL;
9191 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
9193 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
9194 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
9195 iocb->iocb_cmpl(phba, iocb, iocb);
9197 atomic_dec(&phba->fabric_iocb_count);
9206 * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
9207 * @phba: pointer to lpfc hba data structure.
9209 * This routine unblocks the issuing fabric iocb command. The function
9210 * will clear the fabric iocb block bit and then invoke the routine
9211 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
9212 * from the driver internal fabric iocb list.
9215 lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
9217 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
9219 lpfc_resume_fabric_iocbs(phba);
9224 * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
9225 * @phba: pointer to lpfc hba data structure.
9227 * This routine blocks the issuing fabric iocb for a specified amount of
9228 * time (currently 100 ms). This is done by set the fabric iocb block bit
9229 * and set up a timeout timer for 100ms. When the block bit is set, no more
9230 * fabric iocb will be issued out of the HBA.
9233 lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
9237 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
9238 /* Start a timer to unblock fabric iocbs after 100ms */
9240 mod_timer(&phba->fabric_block_timer,
9241 jiffies + msecs_to_jiffies(100));
9247 * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
9248 * @phba: pointer to lpfc hba data structure.
9249 * @cmdiocb: pointer to lpfc command iocb data structure.
9250 * @rspiocb: pointer to lpfc response iocb data structure.
9252 * This routine is the callback function that is put to the fabric iocb's
9253 * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
9254 * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
9255 * function first restores and invokes the original iocb's callback function
9256 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
9257 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
9260 lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
9261 struct lpfc_iocbq *rspiocb)
9265 BUG_ON((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC);
9267 switch (rspiocb->iocb.ulpStatus) {
9268 case IOSTAT_NPORT_RJT:
9269 case IOSTAT_FABRIC_RJT:
9270 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
9271 lpfc_block_fabric_iocbs(phba);
9275 case IOSTAT_NPORT_BSY:
9276 case IOSTAT_FABRIC_BSY:
9277 lpfc_block_fabric_iocbs(phba);
9281 stat.un.lsRjtError =
9282 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
9283 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
9284 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
9285 lpfc_block_fabric_iocbs(phba);
9289 BUG_ON(atomic_read(&phba->fabric_iocb_count) == 0);
9291 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
9292 cmdiocb->fabric_iocb_cmpl = NULL;
9293 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
9294 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
9296 atomic_dec(&phba->fabric_iocb_count);
9297 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
9298 /* Post any pending iocbs to HBA */
9299 lpfc_resume_fabric_iocbs(phba);
9304 * lpfc_issue_fabric_iocb - Issue a fabric iocb command
9305 * @phba: pointer to lpfc hba data structure.
9306 * @iocb: pointer to lpfc command iocb data structure.
9308 * This routine is used as the top-level API for issuing a fabric iocb command
9309 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
9310 * function makes sure that only one fabric bound iocb will be outstanding at
9311 * any given time. As such, this function will first check to see whether there
9312 * is already an outstanding fabric iocb on the wire. If so, it will put the
9313 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
9314 * issued later. Otherwise, it will issue the iocb on the wire and update the
9315 * fabric iocb count it indicate that there is one fabric iocb on the wire.
9317 * Note, this implementation has a potential sending out fabric IOCBs out of
9318 * order. The problem is caused by the construction of the "ready" boolen does
9319 * not include the condition that the internal fabric IOCB list is empty. As
9320 * such, it is possible a fabric IOCB issued by this routine might be "jump"
9321 * ahead of the fabric IOCBs in the internal list.
9324 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
9325 * IOCB_ERROR - failed to issue fabric iocb
9328 lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
9330 unsigned long iflags;
9334 BUG_ON(atomic_read(&phba->fabric_iocb_count) > 1);
9336 spin_lock_irqsave(&phba->hbalock, iflags);
9337 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
9338 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
9341 /* Increment fabric iocb count to hold the position */
9342 atomic_inc(&phba->fabric_iocb_count);
9343 spin_unlock_irqrestore(&phba->hbalock, iflags);
9345 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
9346 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
9347 iocb->iocb_flag |= LPFC_IO_FABRIC;
9349 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
9350 "Fabric sched2: ste:x%x",
9351 iocb->vport->port_state, 0, 0);
9353 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
9355 if (ret == IOCB_ERROR) {
9356 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
9357 iocb->fabric_iocb_cmpl = NULL;
9358 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
9359 atomic_dec(&phba->fabric_iocb_count);
9362 spin_lock_irqsave(&phba->hbalock, iflags);
9363 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
9364 spin_unlock_irqrestore(&phba->hbalock, iflags);
9371 * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
9372 * @vport: pointer to a virtual N_Port data structure.
9374 * This routine aborts all the IOCBs associated with a @vport from the
9375 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
9376 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
9377 * list, removes each IOCB associated with the @vport off the list, set the
9378 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
9379 * associated with the IOCB.
9381 static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
9383 LIST_HEAD(completions);
9384 struct lpfc_hba *phba = vport->phba;
9385 struct lpfc_iocbq *tmp_iocb, *piocb;
9387 spin_lock_irq(&phba->hbalock);
9388 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
9391 if (piocb->vport != vport)
9394 list_move_tail(&piocb->list, &completions);
9396 spin_unlock_irq(&phba->hbalock);
9398 /* Cancel all the IOCBs from the completions list */
9399 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
9404 * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
9405 * @ndlp: pointer to a node-list data structure.
9407 * This routine aborts all the IOCBs associated with an @ndlp from the
9408 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
9409 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
9410 * list, removes each IOCB associated with the @ndlp off the list, set the
9411 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
9412 * associated with the IOCB.
9414 void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
9416 LIST_HEAD(completions);
9417 struct lpfc_hba *phba = ndlp->phba;
9418 struct lpfc_iocbq *tmp_iocb, *piocb;
9419 struct lpfc_sli_ring *pring;
9421 pring = lpfc_phba_elsring(phba);
9423 if (unlikely(!pring))
9426 spin_lock_irq(&phba->hbalock);
9427 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
9429 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
9431 list_move_tail(&piocb->list, &completions);
9434 spin_unlock_irq(&phba->hbalock);
9436 /* Cancel all the IOCBs from the completions list */
9437 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
9442 * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
9443 * @phba: pointer to lpfc hba data structure.
9445 * This routine aborts all the IOCBs currently on the driver internal
9446 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
9447 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
9448 * list, removes IOCBs off the list, set the status feild to
9449 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
9452 void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
9454 LIST_HEAD(completions);
9456 spin_lock_irq(&phba->hbalock);
9457 list_splice_init(&phba->fabric_iocb_list, &completions);
9458 spin_unlock_irq(&phba->hbalock);
9460 /* Cancel all the IOCBs from the completions list */
9461 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
9466 * lpfc_sli4_vport_delete_els_xri_aborted -Remove all ndlp references for vport
9467 * @vport: pointer to lpfc vport data structure.
9469 * This routine is invoked by the vport cleanup for deletions and the cleanup
9470 * for an ndlp on removal.
9473 lpfc_sli4_vport_delete_els_xri_aborted(struct lpfc_vport *vport)
9475 struct lpfc_hba *phba = vport->phba;
9476 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
9477 unsigned long iflag = 0;
9479 spin_lock_irqsave(&phba->hbalock, iflag);
9480 spin_lock(&phba->sli4_hba.sgl_list_lock);
9481 list_for_each_entry_safe(sglq_entry, sglq_next,
9482 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
9483 if (sglq_entry->ndlp && sglq_entry->ndlp->vport == vport)
9484 sglq_entry->ndlp = NULL;
9486 spin_unlock(&phba->sli4_hba.sgl_list_lock);
9487 spin_unlock_irqrestore(&phba->hbalock, iflag);
9492 * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
9493 * @phba: pointer to lpfc hba data structure.
9494 * @axri: pointer to the els xri abort wcqe structure.
9496 * This routine is invoked by the worker thread to process a SLI4 slow-path
9500 lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba,
9501 struct sli4_wcqe_xri_aborted *axri)
9503 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
9504 uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri);
9507 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
9508 unsigned long iflag = 0;
9509 struct lpfc_nodelist *ndlp;
9510 struct lpfc_sli_ring *pring;
9512 pring = lpfc_phba_elsring(phba);
9514 spin_lock_irqsave(&phba->hbalock, iflag);
9515 spin_lock(&phba->sli4_hba.sgl_list_lock);
9516 list_for_each_entry_safe(sglq_entry, sglq_next,
9517 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
9518 if (sglq_entry->sli4_xritag == xri) {
9519 list_del(&sglq_entry->list);
9520 ndlp = sglq_entry->ndlp;
9521 sglq_entry->ndlp = NULL;
9522 list_add_tail(&sglq_entry->list,
9523 &phba->sli4_hba.lpfc_els_sgl_list);
9524 sglq_entry->state = SGL_FREED;
9525 spin_unlock(&phba->sli4_hba.sgl_list_lock);
9526 spin_unlock_irqrestore(&phba->hbalock, iflag);
9527 lpfc_set_rrq_active(phba, ndlp,
9528 sglq_entry->sli4_lxritag,
9531 /* Check if TXQ queue needs to be serviced */
9532 if (pring && !list_empty(&pring->txq))
9533 lpfc_worker_wake_up(phba);
9537 spin_unlock(&phba->sli4_hba.sgl_list_lock);
9538 lxri = lpfc_sli4_xri_inrange(phba, xri);
9539 if (lxri == NO_XRI) {
9540 spin_unlock_irqrestore(&phba->hbalock, iflag);
9543 spin_lock(&phba->sli4_hba.sgl_list_lock);
9544 sglq_entry = __lpfc_get_active_sglq(phba, lxri);
9545 if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) {
9546 spin_unlock(&phba->sli4_hba.sgl_list_lock);
9547 spin_unlock_irqrestore(&phba->hbalock, iflag);
9550 sglq_entry->state = SGL_XRI_ABORTED;
9551 spin_unlock(&phba->sli4_hba.sgl_list_lock);
9552 spin_unlock_irqrestore(&phba->hbalock, iflag);
9556 /* lpfc_sli_abts_recover_port - Recover a port that failed a BLS_ABORT req.
9557 * @vport: pointer to virtual port object.
9558 * @ndlp: nodelist pointer for the impacted node.
9560 * The driver calls this routine in response to an SLI4 XRI ABORT CQE
9561 * or an SLI3 ASYNC_STATUS_CN event from the port. For either event,
9562 * the driver is required to send a LOGO to the remote node before it
9563 * attempts to recover its login to the remote node.
9566 lpfc_sli_abts_recover_port(struct lpfc_vport *vport,
9567 struct lpfc_nodelist *ndlp)
9569 struct Scsi_Host *shost;
9570 struct lpfc_hba *phba;
9571 unsigned long flags = 0;
9573 shost = lpfc_shost_from_vport(vport);
9575 if (ndlp->nlp_state != NLP_STE_MAPPED_NODE) {
9576 lpfc_printf_log(phba, KERN_INFO,
9577 LOG_SLI, "3093 No rport recovery needed. "
9578 "rport in state 0x%x\n", ndlp->nlp_state);
9581 lpfc_printf_log(phba, KERN_ERR,
9582 LOG_ELS | LOG_FCP_ERROR | LOG_NVME_IOERR,
9583 "3094 Start rport recovery on shost id 0x%x "
9584 "fc_id 0x%06x vpi 0x%x rpi 0x%x state 0x%x "
9586 shost->host_no, ndlp->nlp_DID,
9587 vport->vpi, ndlp->nlp_rpi, ndlp->nlp_state,
9590 * The rport is not responding. Remove the FCP-2 flag to prevent
9591 * an ADISC in the follow-up recovery code.
9593 spin_lock_irqsave(shost->host_lock, flags);
9594 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
9595 ndlp->nlp_flag |= NLP_ISSUE_LOGO;
9596 spin_unlock_irqrestore(shost->host_lock, flags);
9597 lpfc_unreg_rpi(vport, ndlp);