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 TMO:x%x\n",
1061 irsp->ulpStatus, irsp->un.ulpWord[4],
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 "Data: x%x x%x x%x x%x x%x x%x\n", cmdiocb->iotag,
1117 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
1118 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution,
1119 vport->port_state, vport->fc_flag);
1121 if (vport->port_state == LPFC_FLOGI) {
1123 * If Common Service Parameters indicate Nport
1124 * we are point to point, if Fport we are Fabric.
1127 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
1128 else if (!(phba->hba_flag & HBA_FCOE_MODE))
1129 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
1131 lpfc_printf_vlog(vport, KERN_ERR,
1133 "2831 FLOGI response with cleared Fabric "
1134 "bit fcf_index 0x%x "
1135 "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x "
1137 "%02x%02x%02x%02x%02x%02x%02x%02x\n",
1138 phba->fcf.current_rec.fcf_indx,
1139 phba->fcf.current_rec.switch_name[0],
1140 phba->fcf.current_rec.switch_name[1],
1141 phba->fcf.current_rec.switch_name[2],
1142 phba->fcf.current_rec.switch_name[3],
1143 phba->fcf.current_rec.switch_name[4],
1144 phba->fcf.current_rec.switch_name[5],
1145 phba->fcf.current_rec.switch_name[6],
1146 phba->fcf.current_rec.switch_name[7],
1147 phba->fcf.current_rec.fabric_name[0],
1148 phba->fcf.current_rec.fabric_name[1],
1149 phba->fcf.current_rec.fabric_name[2],
1150 phba->fcf.current_rec.fabric_name[3],
1151 phba->fcf.current_rec.fabric_name[4],
1152 phba->fcf.current_rec.fabric_name[5],
1153 phba->fcf.current_rec.fabric_name[6],
1154 phba->fcf.current_rec.fabric_name[7]);
1156 spin_lock_irq(&phba->hbalock);
1157 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
1158 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
1159 spin_unlock_irq(&phba->hbalock);
1163 /* Mark the FCF discovery process done */
1164 if (phba->hba_flag & HBA_FIP_SUPPORT)
1165 lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP |
1167 "2769 FLOGI to FCF (x%x) "
1168 "completed successfully\n",
1169 phba->fcf.current_rec.fcf_indx);
1170 spin_lock_irq(&phba->hbalock);
1171 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
1172 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
1173 spin_unlock_irq(&phba->hbalock);
1179 spin_lock_irq(&phba->hbalock);
1180 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
1181 spin_unlock_irq(&phba->hbalock);
1185 if (!lpfc_error_lost_link(irsp)) {
1186 /* FLOGI failed, so just use loop map to make discovery list */
1187 lpfc_disc_list_loopmap(vport);
1189 /* Start discovery */
1190 lpfc_disc_start(vport);
1191 } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
1192 (((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
1193 IOERR_SLI_ABORTED) &&
1194 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
1195 IOERR_SLI_DOWN))) &&
1196 (phba->link_state != LPFC_CLEAR_LA)) {
1197 /* If FLOGI failed enable link interrupt. */
1198 lpfc_issue_clear_la(phba, vport);
1201 lpfc_els_free_iocb(phba, cmdiocb);
1205 * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport
1206 * @vport: pointer to a host virtual N_Port data structure.
1207 * @ndlp: pointer to a node-list data structure.
1208 * @retry: number of retries to the command IOCB.
1210 * This routine issues a Fabric Login (FLOGI) Request ELS command
1211 * for a @vport. The initiator service parameters are put into the payload
1212 * of the FLOGI Request IOCB and the top-level callback function pointer
1213 * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
1214 * function field. The lpfc_issue_fabric_iocb routine is invoked to send
1215 * out FLOGI ELS command with one outstanding fabric IOCB at a time.
1217 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1218 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1219 * will be stored into the context1 field of the IOCB for the completion
1220 * callback function to the FLOGI ELS command.
1223 * 0 - successfully issued flogi iocb for @vport
1224 * 1 - failed to issue flogi iocb for @vport
1227 lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1230 struct lpfc_hba *phba = vport->phba;
1231 struct serv_parm *sp;
1233 struct lpfc_iocbq *elsiocb;
1239 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
1240 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1241 ndlp->nlp_DID, ELS_CMD_FLOGI);
1246 icmd = &elsiocb->iocb;
1247 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1249 /* For FLOGI request, remainder of payload is service parameters */
1250 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
1251 pcmd += sizeof(uint32_t);
1252 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
1253 sp = (struct serv_parm *) pcmd;
1255 /* Setup CSPs accordingly for Fabric */
1256 sp->cmn.e_d_tov = 0;
1257 sp->cmn.w2.r_a_tov = 0;
1258 sp->cmn.virtual_fabric_support = 0;
1259 sp->cls1.classValid = 0;
1260 if (sp->cmn.fcphLow < FC_PH3)
1261 sp->cmn.fcphLow = FC_PH3;
1262 if (sp->cmn.fcphHigh < FC_PH3)
1263 sp->cmn.fcphHigh = FC_PH3;
1265 if (phba->sli_rev == LPFC_SLI_REV4) {
1266 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
1267 LPFC_SLI_INTF_IF_TYPE_0) {
1268 elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1);
1269 elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1);
1270 /* FLOGI needs to be 3 for WQE FCFI */
1271 /* Set the fcfi to the fcfi we registered with */
1272 elsiocb->iocb.ulpContext = phba->fcf.fcfi;
1274 /* Can't do SLI4 class2 without support sequence coalescing */
1275 sp->cls2.classValid = 0;
1276 sp->cls2.seqDelivery = 0;
1278 /* Historical, setting sequential-delivery bit for SLI3 */
1279 sp->cls2.seqDelivery = (sp->cls2.classValid) ? 1 : 0;
1280 sp->cls3.seqDelivery = (sp->cls3.classValid) ? 1 : 0;
1281 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
1282 sp->cmn.request_multiple_Nport = 1;
1283 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
1287 sp->cmn.request_multiple_Nport = 0;
1290 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
1291 icmd->un.elsreq64.myID = 0;
1292 icmd->un.elsreq64.fl = 1;
1295 tmo = phba->fc_ratov;
1296 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
1297 lpfc_set_disctmo(vport);
1298 phba->fc_ratov = tmo;
1300 phba->fc_stat.elsXmitFLOGI++;
1301 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
1303 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1304 "Issue FLOGI: opt:x%x",
1305 phba->sli3_options, 0, 0);
1307 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
1308 if (rc == IOCB_ERROR) {
1309 lpfc_els_free_iocb(phba, elsiocb);
1316 * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs
1317 * @phba: pointer to lpfc hba data structure.
1319 * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
1320 * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
1321 * list and issues an abort IOCB commond on each outstanding IOCB that
1322 * contains a active Fabric_DID ndlp. Note that this function is to issue
1323 * the abort IOCB command on all the outstanding IOCBs, thus when this
1324 * function returns, it does not guarantee all the IOCBs are actually aborted.
1327 * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0)
1330 lpfc_els_abort_flogi(struct lpfc_hba *phba)
1332 struct lpfc_sli_ring *pring;
1333 struct lpfc_iocbq *iocb, *next_iocb;
1334 struct lpfc_nodelist *ndlp;
1337 /* Abort outstanding I/O on NPort <nlp_DID> */
1338 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
1339 "0201 Abort outstanding I/O on NPort x%x\n",
1342 pring = lpfc_phba_elsring(phba);
1345 * Check the txcmplq for an iocb that matches the nport the driver is
1348 spin_lock_irq(&phba->hbalock);
1349 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
1351 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR) {
1352 ndlp = (struct lpfc_nodelist *)(iocb->context1);
1353 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
1354 (ndlp->nlp_DID == Fabric_DID))
1355 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
1358 spin_unlock_irq(&phba->hbalock);
1364 * lpfc_initial_flogi - Issue an initial fabric login for a vport
1365 * @vport: pointer to a host virtual N_Port data structure.
1367 * This routine issues an initial Fabric Login (FLOGI) for the @vport
1368 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1369 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1370 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1371 * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
1372 * is then invoked with the @vport and the ndlp to perform the FLOGI for the
1376 * 0 - failed to issue initial flogi for @vport
1377 * 1 - successfully issued initial flogi for @vport
1380 lpfc_initial_flogi(struct lpfc_vport *vport)
1382 struct lpfc_nodelist *ndlp;
1384 vport->port_state = LPFC_FLOGI;
1385 lpfc_set_disctmo(vport);
1387 /* First look for the Fabric ndlp */
1388 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1390 /* Cannot find existing Fabric ndlp, so allocate a new one */
1391 ndlp = lpfc_nlp_init(vport, Fabric_DID);
1394 /* Set the node type */
1395 ndlp->nlp_type |= NLP_FABRIC;
1396 /* Put ndlp onto node list */
1397 lpfc_enqueue_node(vport, ndlp);
1398 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1399 /* re-setup ndlp without removing from node list */
1400 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1405 if (lpfc_issue_els_flogi(vport, ndlp, 0)) {
1406 /* This decrement of reference count to node shall kick off
1407 * the release of the node.
1416 * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport
1417 * @vport: pointer to a host virtual N_Port data structure.
1419 * This routine issues an initial Fabric Discover (FDISC) for the @vport
1420 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1421 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1422 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1423 * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
1424 * is then invoked with the @vport and the ndlp to perform the FDISC for the
1428 * 0 - failed to issue initial fdisc for @vport
1429 * 1 - successfully issued initial fdisc for @vport
1432 lpfc_initial_fdisc(struct lpfc_vport *vport)
1434 struct lpfc_nodelist *ndlp;
1436 /* First look for the Fabric ndlp */
1437 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1439 /* Cannot find existing Fabric ndlp, so allocate a new one */
1440 ndlp = lpfc_nlp_init(vport, Fabric_DID);
1443 /* Put ndlp onto node list */
1444 lpfc_enqueue_node(vport, ndlp);
1445 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1446 /* re-setup ndlp without removing from node list */
1447 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1452 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
1453 /* decrement node reference count to trigger the release of
1463 * lpfc_more_plogi - Check and issue remaining plogis for a vport
1464 * @vport: pointer to a host virtual N_Port data structure.
1466 * This routine checks whether there are more remaining Port Logins
1467 * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
1468 * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
1469 * to issue ELS PLOGIs up to the configured discover threads with the
1470 * @vport (@vport->cfg_discovery_threads). The function also decrement
1471 * the @vport's num_disc_node by 1 if it is not already 0.
1474 lpfc_more_plogi(struct lpfc_vport *vport)
1476 if (vport->num_disc_nodes)
1477 vport->num_disc_nodes--;
1479 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
1480 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1481 "0232 Continue discovery with %d PLOGIs to go "
1482 "Data: x%x x%x x%x\n",
1483 vport->num_disc_nodes, vport->fc_plogi_cnt,
1484 vport->fc_flag, vport->port_state);
1485 /* Check to see if there are more PLOGIs to be sent */
1486 if (vport->fc_flag & FC_NLP_MORE)
1487 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
1488 lpfc_els_disc_plogi(vport);
1494 * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp
1495 * @phba: pointer to lpfc hba data structure.
1496 * @prsp: pointer to response IOCB payload.
1497 * @ndlp: pointer to a node-list data structure.
1499 * This routine checks and indicates whether the WWPN of an N_Port, retrieved
1500 * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
1501 * The following cases are considered N_Port confirmed:
1502 * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
1503 * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
1504 * it does not have WWPN assigned either. If the WWPN is confirmed, the
1505 * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
1506 * 1) if there is a node on vport list other than the @ndlp with the same
1507 * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
1508 * on that node to release the RPI associated with the node; 2) if there is
1509 * no node found on vport list with the same WWPN of the N_Port PLOGI logged
1510 * into, a new node shall be allocated (or activated). In either case, the
1511 * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
1512 * be released and the new_ndlp shall be put on to the vport node list and
1513 * its pointer returned as the confirmed node.
1515 * Note that before the @ndlp got "released", the keepDID from not-matching
1516 * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
1517 * of the @ndlp. This is because the release of @ndlp is actually to put it
1518 * into an inactive state on the vport node list and the vport node list
1519 * management algorithm does not allow two node with a same DID.
1522 * pointer to the PLOGI N_Port @ndlp
1524 static struct lpfc_nodelist *
1525 lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
1526 struct lpfc_nodelist *ndlp)
1528 struct lpfc_vport *vport = ndlp->vport;
1529 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1530 struct lpfc_nodelist *new_ndlp;
1531 struct lpfc_rport_data *rdata;
1532 struct fc_rport *rport;
1533 struct serv_parm *sp;
1534 uint8_t name[sizeof(struct lpfc_name)];
1535 uint32_t rc, keepDID = 0, keep_nlp_flag = 0;
1536 uint16_t keep_nlp_state;
1537 struct lpfc_nvme_rport *keep_nrport = NULL;
1540 unsigned long *active_rrqs_xri_bitmap = NULL;
1542 /* Fabric nodes can have the same WWPN so we don't bother searching
1543 * by WWPN. Just return the ndlp that was given to us.
1545 if (ndlp->nlp_type & NLP_FABRIC)
1548 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
1549 memset(name, 0, sizeof(struct lpfc_name));
1551 /* Now we find out if the NPort we are logging into, matches the WWPN
1552 * we have for that ndlp. If not, we have some work to do.
1554 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
1556 if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp))
1558 if (phba->sli_rev == LPFC_SLI_REV4) {
1559 active_rrqs_xri_bitmap = mempool_alloc(phba->active_rrq_pool,
1561 if (active_rrqs_xri_bitmap)
1562 memset(active_rrqs_xri_bitmap, 0,
1563 phba->cfg_rrq_xri_bitmap_sz);
1566 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1567 "3178 PLOGI confirm: ndlp %p x%x: new_ndlp %p\n",
1568 ndlp, ndlp->nlp_DID, new_ndlp);
1571 rc = memcmp(&ndlp->nlp_portname, name,
1572 sizeof(struct lpfc_name));
1574 if (active_rrqs_xri_bitmap)
1575 mempool_free(active_rrqs_xri_bitmap,
1576 phba->active_rrq_pool);
1579 new_ndlp = lpfc_nlp_init(vport, ndlp->nlp_DID);
1581 if (active_rrqs_xri_bitmap)
1582 mempool_free(active_rrqs_xri_bitmap,
1583 phba->active_rrq_pool);
1586 } else if (!NLP_CHK_NODE_ACT(new_ndlp)) {
1587 rc = memcmp(&ndlp->nlp_portname, name,
1588 sizeof(struct lpfc_name));
1590 if (active_rrqs_xri_bitmap)
1591 mempool_free(active_rrqs_xri_bitmap,
1592 phba->active_rrq_pool);
1595 new_ndlp = lpfc_enable_node(vport, new_ndlp,
1596 NLP_STE_UNUSED_NODE);
1598 if (active_rrqs_xri_bitmap)
1599 mempool_free(active_rrqs_xri_bitmap,
1600 phba->active_rrq_pool);
1603 keepDID = new_ndlp->nlp_DID;
1604 if ((phba->sli_rev == LPFC_SLI_REV4) && active_rrqs_xri_bitmap)
1605 memcpy(active_rrqs_xri_bitmap,
1606 new_ndlp->active_rrqs_xri_bitmap,
1607 phba->cfg_rrq_xri_bitmap_sz);
1609 keepDID = new_ndlp->nlp_DID;
1610 if (phba->sli_rev == LPFC_SLI_REV4 &&
1611 active_rrqs_xri_bitmap)
1612 memcpy(active_rrqs_xri_bitmap,
1613 new_ndlp->active_rrqs_xri_bitmap,
1614 phba->cfg_rrq_xri_bitmap_sz);
1617 lpfc_unreg_rpi(vport, new_ndlp);
1618 new_ndlp->nlp_DID = ndlp->nlp_DID;
1619 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
1620 if (phba->sli_rev == LPFC_SLI_REV4)
1621 memcpy(new_ndlp->active_rrqs_xri_bitmap,
1622 ndlp->active_rrqs_xri_bitmap,
1623 phba->cfg_rrq_xri_bitmap_sz);
1625 spin_lock_irq(shost->host_lock);
1626 keep_nlp_flag = new_ndlp->nlp_flag;
1627 new_ndlp->nlp_flag = ndlp->nlp_flag;
1628 ndlp->nlp_flag = keep_nlp_flag;
1629 spin_unlock_irq(shost->host_lock);
1631 /* Set nlp_states accordingly */
1632 keep_nlp_state = new_ndlp->nlp_state;
1633 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
1635 /* interchange the nvme remoteport structs */
1636 keep_nrport = new_ndlp->nrport;
1637 new_ndlp->nrport = ndlp->nrport;
1639 /* Move this back to NPR state */
1640 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
1641 /* The new_ndlp is replacing ndlp totally, so we need
1642 * to put ndlp on UNUSED list and try to free it.
1644 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1645 "3179 PLOGI confirm NEW: %x %x\n",
1646 new_ndlp->nlp_DID, keepDID);
1648 /* Fix up the rport accordingly */
1649 rport = ndlp->rport;
1651 rdata = rport->dd_data;
1652 if (rdata->pnode == ndlp) {
1653 /* break the link before dropping the ref */
1656 rdata->pnode = lpfc_nlp_get(new_ndlp);
1657 new_ndlp->rport = rport;
1659 new_ndlp->nlp_type = ndlp->nlp_type;
1662 /* Fix up the nvme rport */
1664 ndlp->nrport = NULL;
1666 new_ndlp->nlp_fc4_type = ndlp->nlp_fc4_type;
1669 /* We shall actually free the ndlp with both nlp_DID and
1670 * nlp_portname fields equals 0 to avoid any ndlp on the
1671 * nodelist never to be used.
1673 if (ndlp->nlp_DID == 0) {
1674 spin_lock_irq(&phba->ndlp_lock);
1675 NLP_SET_FREE_REQ(ndlp);
1676 spin_unlock_irq(&phba->ndlp_lock);
1679 /* Two ndlps cannot have the same did on the nodelist */
1680 ndlp->nlp_DID = keepDID;
1681 lpfc_nlp_set_state(vport, ndlp, keep_nlp_state);
1682 if (phba->sli_rev == LPFC_SLI_REV4 &&
1683 active_rrqs_xri_bitmap)
1684 memcpy(ndlp->active_rrqs_xri_bitmap,
1685 active_rrqs_xri_bitmap,
1686 phba->cfg_rrq_xri_bitmap_sz);
1688 if (!NLP_CHK_NODE_ACT(ndlp))
1689 lpfc_drop_node(vport, ndlp);
1692 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1693 "3180 PLOGI confirm SWAP: %x %x\n",
1694 new_ndlp->nlp_DID, keepDID);
1696 lpfc_unreg_rpi(vport, ndlp);
1698 /* Two ndlps cannot have the same did */
1699 ndlp->nlp_DID = keepDID;
1700 if (phba->sli_rev == LPFC_SLI_REV4 &&
1701 active_rrqs_xri_bitmap)
1702 memcpy(ndlp->active_rrqs_xri_bitmap,
1703 active_rrqs_xri_bitmap,
1704 phba->cfg_rrq_xri_bitmap_sz);
1706 /* Since we are switching over to the new_ndlp,
1707 * reset the old ndlp state
1709 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
1710 (ndlp->nlp_state == NLP_STE_MAPPED_NODE))
1711 keep_nlp_state = NLP_STE_NPR_NODE;
1712 lpfc_nlp_set_state(vport, ndlp, keep_nlp_state);
1714 /* Previous ndlp no longer active with nvme host transport.
1715 * Remove reference from earlier registration unless the
1716 * nvme host took care of it.
1720 ndlp->nrport = keep_nrport;
1722 /* Fix up the rport accordingly */
1723 rport = ndlp->rport;
1725 rdata = rport->dd_data;
1726 put_node = rdata->pnode != NULL;
1727 put_rport = ndlp->rport != NULL;
1728 rdata->pnode = NULL;
1733 put_device(&rport->dev);
1736 if (phba->sli_rev == LPFC_SLI_REV4 &&
1737 active_rrqs_xri_bitmap)
1738 mempool_free(active_rrqs_xri_bitmap,
1739 phba->active_rrq_pool);
1744 * lpfc_end_rscn - Check and handle more rscn for a vport
1745 * @vport: pointer to a host virtual N_Port data structure.
1747 * This routine checks whether more Registration State Change
1748 * Notifications (RSCNs) came in while the discovery state machine was in
1749 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1750 * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1751 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1752 * handling the RSCNs.
1755 lpfc_end_rscn(struct lpfc_vport *vport)
1757 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1759 if (vport->fc_flag & FC_RSCN_MODE) {
1761 * Check to see if more RSCNs came in while we were
1762 * processing this one.
1764 if (vport->fc_rscn_id_cnt ||
1765 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
1766 lpfc_els_handle_rscn(vport);
1768 spin_lock_irq(shost->host_lock);
1769 vport->fc_flag &= ~FC_RSCN_MODE;
1770 spin_unlock_irq(shost->host_lock);
1776 * lpfc_cmpl_els_rrq - Completion handled for els RRQs.
1777 * @phba: pointer to lpfc hba data structure.
1778 * @cmdiocb: pointer to lpfc command iocb data structure.
1779 * @rspiocb: pointer to lpfc response iocb data structure.
1781 * This routine will call the clear rrq function to free the rrq and
1782 * clear the xri's bit in the ndlp's xri_bitmap. If the ndlp does not
1783 * exist then the clear_rrq is still called because the rrq needs to
1788 lpfc_cmpl_els_rrq(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1789 struct lpfc_iocbq *rspiocb)
1791 struct lpfc_vport *vport = cmdiocb->vport;
1793 struct lpfc_nodelist *ndlp;
1794 struct lpfc_node_rrq *rrq;
1796 /* we pass cmdiocb to state machine which needs rspiocb as well */
1797 rrq = cmdiocb->context_un.rrq;
1798 cmdiocb->context_un.rsp_iocb = rspiocb;
1800 irsp = &rspiocb->iocb;
1801 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1802 "RRQ cmpl: status:x%x/x%x did:x%x",
1803 irsp->ulpStatus, irsp->un.ulpWord[4],
1804 irsp->un.elsreq64.remoteID);
1806 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
1807 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || ndlp != rrq->ndlp) {
1808 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1809 "2882 RRQ completes to NPort x%x "
1810 "with no ndlp. Data: x%x x%x x%x\n",
1811 irsp->un.elsreq64.remoteID,
1812 irsp->ulpStatus, irsp->un.ulpWord[4],
1817 /* rrq completes to NPort <nlp_DID> */
1818 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1819 "2880 RRQ completes to NPort x%x "
1820 "Data: x%x x%x x%x x%x x%x\n",
1821 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1822 irsp->ulpTimeout, rrq->xritag, rrq->rxid);
1824 if (irsp->ulpStatus) {
1825 /* Check for retry */
1826 /* RRQ failed Don't print the vport to vport rjts */
1827 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1828 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1829 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1830 (phba)->pport->cfg_log_verbose & LOG_ELS)
1831 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1832 "2881 RRQ failure DID:%06X Status:x%x/x%x\n",
1833 ndlp->nlp_DID, irsp->ulpStatus,
1834 irsp->un.ulpWord[4]);
1838 lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
1839 lpfc_els_free_iocb(phba, cmdiocb);
1843 * lpfc_cmpl_els_plogi - Completion callback function for plogi
1844 * @phba: pointer to lpfc hba data structure.
1845 * @cmdiocb: pointer to lpfc command iocb data structure.
1846 * @rspiocb: pointer to lpfc response iocb data structure.
1848 * This routine is the completion callback function for issuing the Port
1849 * Login (PLOGI) command. For PLOGI completion, there must be an active
1850 * ndlp on the vport node list that matches the remote node ID from the
1851 * PLOGI response IOCB. If such ndlp does not exist, the PLOGI is simply
1852 * ignored and command IOCB released. The PLOGI response IOCB status is
1853 * checked for error conditons. If there is error status reported, PLOGI
1854 * retry shall be attempted by invoking the lpfc_els_retry() routine.
1855 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1856 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1857 * (DSM) is set for this PLOGI completion. Finally, it checks whether
1858 * there are additional N_Port nodes with the vport that need to perform
1859 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
1863 lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1864 struct lpfc_iocbq *rspiocb)
1866 struct lpfc_vport *vport = cmdiocb->vport;
1867 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1869 struct lpfc_nodelist *ndlp;
1870 struct lpfc_dmabuf *prsp;
1873 /* we pass cmdiocb to state machine which needs rspiocb as well */
1874 cmdiocb->context_un.rsp_iocb = rspiocb;
1876 irsp = &rspiocb->iocb;
1877 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1878 "PLOGI cmpl: status:x%x/x%x did:x%x",
1879 irsp->ulpStatus, irsp->un.ulpWord[4],
1880 irsp->un.elsreq64.remoteID);
1882 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
1883 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
1884 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1885 "0136 PLOGI completes to NPort x%x "
1886 "with no ndlp. Data: x%x x%x x%x\n",
1887 irsp->un.elsreq64.remoteID,
1888 irsp->ulpStatus, irsp->un.ulpWord[4],
1893 /* Since ndlp can be freed in the disc state machine, note if this node
1894 * is being used during discovery.
1896 spin_lock_irq(shost->host_lock);
1897 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
1898 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1899 spin_unlock_irq(shost->host_lock);
1902 /* PLOGI completes to NPort <nlp_DID> */
1903 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1904 "0102 PLOGI completes to NPort x%06x "
1905 "Data: x%x x%x x%x x%x x%x\n",
1906 ndlp->nlp_DID, ndlp->nlp_fc4_type,
1907 irsp->ulpStatus, irsp->un.ulpWord[4],
1908 disc, vport->num_disc_nodes);
1910 /* Check to see if link went down during discovery */
1911 if (lpfc_els_chk_latt(vport)) {
1912 spin_lock_irq(shost->host_lock);
1913 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1914 spin_unlock_irq(shost->host_lock);
1918 if (irsp->ulpStatus) {
1919 /* Check for retry */
1920 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1921 /* ELS command is being retried */
1923 spin_lock_irq(shost->host_lock);
1924 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1925 spin_unlock_irq(shost->host_lock);
1929 /* PLOGI failed Don't print the vport to vport rjts */
1930 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1931 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1932 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1933 (phba)->pport->cfg_log_verbose & LOG_ELS)
1934 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1935 "2753 PLOGI failure DID:%06X Status:x%x/x%x\n",
1936 ndlp->nlp_DID, irsp->ulpStatus,
1937 irsp->un.ulpWord[4]);
1938 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1939 if (lpfc_error_lost_link(irsp))
1940 rc = NLP_STE_FREED_NODE;
1942 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1943 NLP_EVT_CMPL_PLOGI);
1945 /* Good status, call state machine */
1946 prsp = list_entry(((struct lpfc_dmabuf *)
1947 cmdiocb->context2)->list.next,
1948 struct lpfc_dmabuf, list);
1949 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
1950 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1951 NLP_EVT_CMPL_PLOGI);
1954 if (disc && vport->num_disc_nodes) {
1955 /* Check to see if there are more PLOGIs to be sent */
1956 lpfc_more_plogi(vport);
1958 if (vport->num_disc_nodes == 0) {
1959 spin_lock_irq(shost->host_lock);
1960 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1961 spin_unlock_irq(shost->host_lock);
1963 lpfc_can_disctmo(vport);
1964 lpfc_end_rscn(vport);
1969 lpfc_els_free_iocb(phba, cmdiocb);
1974 * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
1975 * @vport: pointer to a host virtual N_Port data structure.
1976 * @did: destination port identifier.
1977 * @retry: number of retries to the command IOCB.
1979 * This routine issues a Port Login (PLOGI) command to a remote N_Port
1980 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
1981 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
1982 * This routine constructs the proper feilds of the PLOGI IOCB and invokes
1983 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
1985 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1986 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1987 * will be stored into the context1 field of the IOCB for the completion
1988 * callback function to the PLOGI ELS command.
1991 * 0 - Successfully issued a plogi for @vport
1992 * 1 - failed to issue a plogi for @vport
1995 lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
1997 struct lpfc_hba *phba = vport->phba;
1998 struct Scsi_Host *shost;
1999 struct serv_parm *sp;
2000 struct lpfc_nodelist *ndlp;
2001 struct lpfc_iocbq *elsiocb;
2006 ndlp = lpfc_findnode_did(vport, did);
2007 if (ndlp && !NLP_CHK_NODE_ACT(ndlp))
2010 /* If ndlp is not NULL, we will bump the reference count on it */
2011 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
2012 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
2017 shost = lpfc_shost_from_vport(vport);
2018 spin_lock_irq(shost->host_lock);
2019 ndlp->nlp_flag &= ~NLP_FCP_PRLI_RJT;
2020 spin_unlock_irq(shost->host_lock);
2022 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2024 /* For PLOGI request, remainder of payload is service parameters */
2025 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
2026 pcmd += sizeof(uint32_t);
2027 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
2028 sp = (struct serv_parm *) pcmd;
2031 * If we are a N-port connected to a Fabric, fix-up paramm's so logins
2032 * to device on remote loops work.
2034 if ((vport->fc_flag & FC_FABRIC) && !(vport->fc_flag & FC_PUBLIC_LOOP))
2035 sp->cmn.altBbCredit = 1;
2037 if (sp->cmn.fcphLow < FC_PH_4_3)
2038 sp->cmn.fcphLow = FC_PH_4_3;
2040 if (sp->cmn.fcphHigh < FC_PH3)
2041 sp->cmn.fcphHigh = FC_PH3;
2043 sp->cmn.valid_vendor_ver_level = 0;
2044 memset(sp->un.vendorVersion, 0, sizeof(sp->un.vendorVersion));
2045 sp->cmn.bbRcvSizeMsb &= 0xF;
2047 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2048 "Issue PLOGI: did:x%x",
2051 /* If our firmware supports this feature, convey that
2052 * information to the target using the vendor specific field.
2054 if (phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) {
2055 sp->cmn.valid_vendor_ver_level = 1;
2056 sp->un.vv.vid = cpu_to_be32(LPFC_VV_EMLX_ID);
2057 sp->un.vv.flags = cpu_to_be32(LPFC_VV_SUPPRESS_RSP);
2060 phba->fc_stat.elsXmitPLOGI++;
2061 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
2062 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
2064 if (ret == IOCB_ERROR) {
2065 lpfc_els_free_iocb(phba, elsiocb);
2072 * lpfc_cmpl_els_prli - Completion callback function for prli
2073 * @phba: pointer to lpfc hba data structure.
2074 * @cmdiocb: pointer to lpfc command iocb data structure.
2075 * @rspiocb: pointer to lpfc response iocb data structure.
2077 * This routine is the completion callback function for a Process Login
2078 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
2079 * status. If there is error status reported, PRLI retry shall be attempted
2080 * by invoking the lpfc_els_retry() routine. Otherwise, the state
2081 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
2082 * ndlp to mark the PRLI completion.
2085 lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2086 struct lpfc_iocbq *rspiocb)
2088 struct lpfc_vport *vport = cmdiocb->vport;
2089 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2091 struct lpfc_nodelist *ndlp;
2093 /* we pass cmdiocb to state machine which needs rspiocb as well */
2094 cmdiocb->context_un.rsp_iocb = rspiocb;
2096 irsp = &(rspiocb->iocb);
2097 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2098 spin_lock_irq(shost->host_lock);
2099 ndlp->nlp_flag &= ~NLP_PRLI_SND;
2101 /* Driver supports multiple FC4 types. Counters matter. */
2102 vport->fc_prli_sent--;
2103 ndlp->fc4_prli_sent--;
2104 spin_unlock_irq(shost->host_lock);
2106 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2107 "PRLI cmpl: status:x%x/x%x did:x%x",
2108 irsp->ulpStatus, irsp->un.ulpWord[4],
2111 /* PRLI completes to NPort <nlp_DID> */
2112 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2113 "0103 PRLI completes to NPort x%06x "
2114 "Data: x%x x%x x%x x%x\n",
2115 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2116 vport->num_disc_nodes, ndlp->fc4_prli_sent);
2118 /* Check to see if link went down during discovery */
2119 if (lpfc_els_chk_latt(vport))
2122 if (irsp->ulpStatus) {
2123 /* Check for retry */
2124 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2125 /* ELS command is being retried */
2130 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2131 "2754 PRLI failure DID:%06X Status:x%x/x%x, "
2133 ndlp->nlp_DID, irsp->ulpStatus,
2134 irsp->un.ulpWord[4], ndlp->fc4_prli_sent);
2136 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2137 if (lpfc_error_lost_link(irsp))
2140 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2143 /* Good status, call state machine. However, if another
2144 * PRLI is outstanding, don't call the state machine
2145 * because final disposition to Mapped or Unmapped is
2148 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2152 lpfc_els_free_iocb(phba, cmdiocb);
2157 * lpfc_issue_els_prli - Issue a prli iocb command for a vport
2158 * @vport: pointer to a host virtual N_Port data structure.
2159 * @ndlp: pointer to a node-list data structure.
2160 * @retry: number of retries to the command IOCB.
2162 * This routine issues a Process Login (PRLI) ELS command for the
2163 * @vport. The PRLI service parameters are set up in the payload of the
2164 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
2165 * is put to the IOCB completion callback func field before invoking the
2166 * routine lpfc_sli_issue_iocb() to send out PRLI command.
2168 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2169 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2170 * will be stored into the context1 field of the IOCB for the completion
2171 * callback function to the PRLI ELS command.
2174 * 0 - successfully issued prli iocb command for @vport
2175 * 1 - failed to issue prli iocb command for @vport
2178 lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2181 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2182 struct lpfc_hba *phba = vport->phba;
2184 struct lpfc_nvme_prli *npr_nvme;
2185 struct lpfc_iocbq *elsiocb;
2188 u32 local_nlp_type, elscmd;
2191 * If we are in RSCN mode, the FC4 types supported from a
2192 * previous GFT_ID command may not be accurate. So, if we
2193 * are a NVME Initiator, always look for the possibility of
2194 * the remote NPort beng a NVME Target.
2196 if (phba->sli_rev == LPFC_SLI_REV4 &&
2197 vport->fc_flag & FC_RSCN_MODE &&
2198 vport->nvmei_support)
2199 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
2200 local_nlp_type = ndlp->nlp_fc4_type;
2202 /* This routine will issue 1 or 2 PRLIs, so zero all the ndlp
2203 * fields here before any of them can complete.
2205 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
2206 ndlp->nlp_type &= ~(NLP_NVME_TARGET | NLP_NVME_INITIATOR);
2207 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
2208 ndlp->nlp_flag &= ~NLP_FIRSTBURST;
2209 ndlp->nvme_fb_size = 0;
2212 if (local_nlp_type & NLP_FC4_FCP) {
2213 /* Payload is 4 + 16 = 20 x14 bytes. */
2214 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
2215 elscmd = ELS_CMD_PRLI;
2216 } else if (local_nlp_type & NLP_FC4_NVME) {
2217 /* Payload is 4 + 20 = 24 x18 bytes. */
2218 cmdsize = (sizeof(uint32_t) + sizeof(struct lpfc_nvme_prli));
2219 elscmd = ELS_CMD_NVMEPRLI;
2221 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2222 "3083 Unknown FC_TYPE x%x ndlp x%06x\n",
2223 ndlp->nlp_fc4_type, ndlp->nlp_DID);
2227 /* SLI3 ports don't support NVME. If this rport is a strict NVME
2228 * FC4 type, implicitly LOGO.
2230 if (phba->sli_rev == LPFC_SLI_REV3 &&
2231 ndlp->nlp_fc4_type == NLP_FC4_NVME) {
2232 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2233 "3088 Rport fc4 type 0x%x not supported by SLI3 adapter\n",
2235 lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM);
2239 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2240 ndlp->nlp_DID, elscmd);
2244 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2246 /* For PRLI request, remainder of payload is service parameters */
2247 memset(pcmd, 0, cmdsize);
2249 if (local_nlp_type & NLP_FC4_FCP) {
2250 /* Remainder of payload is FCP PRLI parameter page.
2251 * Note: this data structure is defined as
2252 * BE/LE in the structure definition so no
2253 * byte swap call is made.
2255 *((uint32_t *)(pcmd)) = ELS_CMD_PRLI;
2256 pcmd += sizeof(uint32_t);
2260 * If our firmware version is 3.20 or later,
2261 * set the following bits for FC-TAPE support.
2263 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
2264 npr->ConfmComplAllowed = 1;
2266 npr->TaskRetryIdReq = 1;
2268 npr->estabImagePair = 1;
2269 npr->readXferRdyDis = 1;
2270 if (vport->cfg_first_burst_size)
2271 npr->writeXferRdyDis = 1;
2273 /* For FCP support */
2274 npr->prliType = PRLI_FCP_TYPE;
2275 npr->initiatorFunc = 1;
2276 elsiocb->iocb_flag |= LPFC_PRLI_FCP_REQ;
2278 /* Remove FCP type - processed. */
2279 local_nlp_type &= ~NLP_FC4_FCP;
2280 } else if (local_nlp_type & NLP_FC4_NVME) {
2281 /* Remainder of payload is NVME PRLI parameter page.
2282 * This data structure is the newer definition that
2283 * uses bf macros so a byte swap is required.
2285 *((uint32_t *)(pcmd)) = ELS_CMD_NVMEPRLI;
2286 pcmd += sizeof(uint32_t);
2287 npr_nvme = (struct lpfc_nvme_prli *)pcmd;
2288 bf_set(prli_type_code, npr_nvme, PRLI_NVME_TYPE);
2289 bf_set(prli_estabImagePair, npr_nvme, 0); /* Should be 0 */
2291 /* Only initiators request first burst. */
2292 if ((phba->cfg_nvme_enable_fb) &&
2293 !phba->nvmet_support)
2294 bf_set(prli_fba, npr_nvme, 1);
2296 if (phba->nvmet_support) {
2297 bf_set(prli_tgt, npr_nvme, 1);
2298 bf_set(prli_disc, npr_nvme, 1);
2300 bf_set(prli_init, npr_nvme, 1);
2301 bf_set(prli_conf, npr_nvme, 1);
2304 npr_nvme->word1 = cpu_to_be32(npr_nvme->word1);
2305 npr_nvme->word4 = cpu_to_be32(npr_nvme->word4);
2306 elsiocb->iocb_flag |= LPFC_PRLI_NVME_REQ;
2308 /* Remove NVME type - processed. */
2309 local_nlp_type &= ~NLP_FC4_NVME;
2312 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2313 "Issue PRLI: did:x%x",
2314 ndlp->nlp_DID, 0, 0);
2316 phba->fc_stat.elsXmitPRLI++;
2317 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
2318 spin_lock_irq(shost->host_lock);
2319 ndlp->nlp_flag |= NLP_PRLI_SND;
2321 /* The vport counters are used for lpfc_scan_finished, but
2322 * the ndlp is used to track outstanding PRLIs for different
2325 vport->fc_prli_sent++;
2326 ndlp->fc4_prli_sent++;
2327 spin_unlock_irq(shost->host_lock);
2328 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2330 spin_lock_irq(shost->host_lock);
2331 ndlp->nlp_flag &= ~NLP_PRLI_SND;
2332 spin_unlock_irq(shost->host_lock);
2333 lpfc_els_free_iocb(phba, elsiocb);
2338 /* The driver supports 2 FC4 types. Make sure
2339 * a PRLI is issued for all types before exiting.
2341 if (phba->sli_rev == LPFC_SLI_REV4 &&
2342 local_nlp_type & (NLP_FC4_FCP | NLP_FC4_NVME))
2343 goto send_next_prli;
2349 * lpfc_rscn_disc - Perform rscn discovery for a vport
2350 * @vport: pointer to a host virtual N_Port data structure.
2352 * This routine performs Registration State Change Notification (RSCN)
2353 * discovery for a @vport. If the @vport's node port recovery count is not
2354 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
2355 * the nodes that need recovery. If none of the PLOGI were needed through
2356 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
2357 * invoked to check and handle possible more RSCN came in during the period
2358 * of processing the current ones.
2361 lpfc_rscn_disc(struct lpfc_vport *vport)
2363 lpfc_can_disctmo(vport);
2365 /* RSCN discovery */
2366 /* go thru NPR nodes and issue ELS PLOGIs */
2367 if (vport->fc_npr_cnt)
2368 if (lpfc_els_disc_plogi(vport))
2371 lpfc_end_rscn(vport);
2375 * lpfc_adisc_done - Complete the adisc phase of discovery
2376 * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
2378 * This function is called when the final ADISC is completed during discovery.
2379 * This function handles clearing link attention or issuing reg_vpi depending
2380 * on whether npiv is enabled. This function also kicks off the PLOGI phase of
2382 * This function is called with no locks held.
2385 lpfc_adisc_done(struct lpfc_vport *vport)
2387 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2388 struct lpfc_hba *phba = vport->phba;
2391 * For NPIV, cmpl_reg_vpi will set port_state to READY,
2392 * and continue discovery.
2394 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2395 !(vport->fc_flag & FC_RSCN_MODE) &&
2396 (phba->sli_rev < LPFC_SLI_REV4)) {
2397 /* The ADISCs are complete. Doesn't matter if they
2398 * succeeded or failed because the ADISC completion
2399 * routine guarantees to call the state machine and
2400 * the RPI is either unregistered (failed ADISC response)
2401 * or the RPI is still valid and the node is marked
2402 * mapped for a target. The exchanges should be in the
2403 * correct state. This code is specific to SLI3.
2405 lpfc_issue_clear_la(phba, vport);
2406 lpfc_issue_reg_vpi(phba, vport);
2410 * For SLI2, we need to set port_state to READY
2411 * and continue discovery.
2413 if (vport->port_state < LPFC_VPORT_READY) {
2414 /* If we get here, there is nothing to ADISC */
2415 lpfc_issue_clear_la(phba, vport);
2416 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
2417 vport->num_disc_nodes = 0;
2418 /* go thru NPR list, issue ELS PLOGIs */
2419 if (vport->fc_npr_cnt)
2420 lpfc_els_disc_plogi(vport);
2421 if (!vport->num_disc_nodes) {
2422 spin_lock_irq(shost->host_lock);
2423 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2424 spin_unlock_irq(shost->host_lock);
2425 lpfc_can_disctmo(vport);
2426 lpfc_end_rscn(vport);
2429 vport->port_state = LPFC_VPORT_READY;
2431 lpfc_rscn_disc(vport);
2435 * lpfc_more_adisc - Issue more adisc as needed
2436 * @vport: pointer to a host virtual N_Port data structure.
2438 * This routine determines whether there are more ndlps on a @vport
2439 * node list need to have Address Discover (ADISC) issued. If so, it will
2440 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
2441 * remaining nodes which need to have ADISC sent.
2444 lpfc_more_adisc(struct lpfc_vport *vport)
2446 if (vport->num_disc_nodes)
2447 vport->num_disc_nodes--;
2448 /* Continue discovery with <num_disc_nodes> ADISCs to go */
2449 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2450 "0210 Continue discovery with %d ADISCs to go "
2451 "Data: x%x x%x x%x\n",
2452 vport->num_disc_nodes, vport->fc_adisc_cnt,
2453 vport->fc_flag, vport->port_state);
2454 /* Check to see if there are more ADISCs to be sent */
2455 if (vport->fc_flag & FC_NLP_MORE) {
2456 lpfc_set_disctmo(vport);
2457 /* go thru NPR nodes and issue any remaining ELS ADISCs */
2458 lpfc_els_disc_adisc(vport);
2460 if (!vport->num_disc_nodes)
2461 lpfc_adisc_done(vport);
2466 * lpfc_cmpl_els_adisc - Completion callback function for adisc
2467 * @phba: pointer to lpfc hba data structure.
2468 * @cmdiocb: pointer to lpfc command iocb data structure.
2469 * @rspiocb: pointer to lpfc response iocb data structure.
2471 * This routine is the completion function for issuing the Address Discover
2472 * (ADISC) command. It first checks to see whether link went down during
2473 * the discovery process. If so, the node will be marked as node port
2474 * recovery for issuing discover IOCB by the link attention handler and
2475 * exit. Otherwise, the response status is checked. If error was reported
2476 * in the response status, the ADISC command shall be retried by invoking
2477 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
2478 * the response status, the state machine is invoked to set transition
2479 * with respect to NLP_EVT_CMPL_ADISC event.
2482 lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2483 struct lpfc_iocbq *rspiocb)
2485 struct lpfc_vport *vport = cmdiocb->vport;
2486 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2488 struct lpfc_nodelist *ndlp;
2491 /* we pass cmdiocb to state machine which needs rspiocb as well */
2492 cmdiocb->context_un.rsp_iocb = rspiocb;
2494 irsp = &(rspiocb->iocb);
2495 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2497 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2498 "ADISC cmpl: status:x%x/x%x did:x%x",
2499 irsp->ulpStatus, irsp->un.ulpWord[4],
2502 /* Since ndlp can be freed in the disc state machine, note if this node
2503 * is being used during discovery.
2505 spin_lock_irq(shost->host_lock);
2506 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
2507 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
2508 spin_unlock_irq(shost->host_lock);
2509 /* ADISC completes to NPort <nlp_DID> */
2510 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2511 "0104 ADISC completes to NPort x%x "
2512 "Data: x%x x%x x%x x%x x%x\n",
2513 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2514 irsp->ulpTimeout, disc, vport->num_disc_nodes);
2515 /* Check to see if link went down during discovery */
2516 if (lpfc_els_chk_latt(vport)) {
2517 spin_lock_irq(shost->host_lock);
2518 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2519 spin_unlock_irq(shost->host_lock);
2523 if (irsp->ulpStatus) {
2524 /* Check for retry */
2525 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2526 /* ELS command is being retried */
2528 spin_lock_irq(shost->host_lock);
2529 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2530 spin_unlock_irq(shost->host_lock);
2531 lpfc_set_disctmo(vport);
2536 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2537 "2755 ADISC failure DID:%06X Status:x%x/x%x\n",
2538 ndlp->nlp_DID, irsp->ulpStatus,
2539 irsp->un.ulpWord[4]);
2540 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2541 if (!lpfc_error_lost_link(irsp))
2542 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2543 NLP_EVT_CMPL_ADISC);
2545 /* Good status, call state machine */
2546 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2547 NLP_EVT_CMPL_ADISC);
2549 /* Check to see if there are more ADISCs to be sent */
2550 if (disc && vport->num_disc_nodes)
2551 lpfc_more_adisc(vport);
2553 lpfc_els_free_iocb(phba, cmdiocb);
2558 * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
2559 * @vport: pointer to a virtual N_Port data structure.
2560 * @ndlp: pointer to a node-list data structure.
2561 * @retry: number of retries to the command IOCB.
2563 * This routine issues an Address Discover (ADISC) for an @ndlp on a
2564 * @vport. It prepares the payload of the ADISC ELS command, updates the
2565 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
2566 * to issue the ADISC ELS command.
2568 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2569 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2570 * will be stored into the context1 field of the IOCB for the completion
2571 * callback function to the ADISC ELS command.
2574 * 0 - successfully issued adisc
2575 * 1 - failed to issue adisc
2578 lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2581 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2582 struct lpfc_hba *phba = vport->phba;
2584 struct lpfc_iocbq *elsiocb;
2588 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
2589 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2590 ndlp->nlp_DID, ELS_CMD_ADISC);
2594 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2596 /* For ADISC request, remainder of payload is service parameters */
2597 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
2598 pcmd += sizeof(uint32_t);
2600 /* Fill in ADISC payload */
2601 ap = (ADISC *) pcmd;
2602 ap->hardAL_PA = phba->fc_pref_ALPA;
2603 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2604 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
2605 ap->DID = be32_to_cpu(vport->fc_myDID);
2607 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2608 "Issue ADISC: did:x%x",
2609 ndlp->nlp_DID, 0, 0);
2611 phba->fc_stat.elsXmitADISC++;
2612 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
2613 spin_lock_irq(shost->host_lock);
2614 ndlp->nlp_flag |= NLP_ADISC_SND;
2615 spin_unlock_irq(shost->host_lock);
2616 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2618 spin_lock_irq(shost->host_lock);
2619 ndlp->nlp_flag &= ~NLP_ADISC_SND;
2620 spin_unlock_irq(shost->host_lock);
2621 lpfc_els_free_iocb(phba, elsiocb);
2628 * lpfc_cmpl_els_logo - Completion callback function for logo
2629 * @phba: pointer to lpfc hba data structure.
2630 * @cmdiocb: pointer to lpfc command iocb data structure.
2631 * @rspiocb: pointer to lpfc response iocb data structure.
2633 * This routine is the completion function for issuing the ELS Logout (LOGO)
2634 * command. If no error status was reported from the LOGO response, the
2635 * state machine of the associated ndlp shall be invoked for transition with
2636 * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
2637 * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
2640 lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2641 struct lpfc_iocbq *rspiocb)
2643 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2644 struct lpfc_vport *vport = ndlp->vport;
2645 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2647 struct lpfcMboxq *mbox;
2648 unsigned long flags;
2649 uint32_t skip_recovery = 0;
2651 /* we pass cmdiocb to state machine which needs rspiocb as well */
2652 cmdiocb->context_un.rsp_iocb = rspiocb;
2654 irsp = &(rspiocb->iocb);
2655 spin_lock_irq(shost->host_lock);
2656 ndlp->nlp_flag &= ~NLP_LOGO_SND;
2657 spin_unlock_irq(shost->host_lock);
2659 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2660 "LOGO cmpl: status:x%x/x%x did:x%x",
2661 irsp->ulpStatus, irsp->un.ulpWord[4],
2664 /* LOGO completes to NPort <nlp_DID> */
2665 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2666 "0105 LOGO completes to NPort x%x "
2667 "Data: x%x x%x x%x x%x\n",
2668 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2669 irsp->ulpTimeout, vport->num_disc_nodes);
2671 if (lpfc_els_chk_latt(vport)) {
2676 /* Check to see if link went down during discovery */
2677 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
2678 /* NLP_EVT_DEVICE_RM should unregister the RPI
2679 * which should abort all outstanding IOs.
2681 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2687 /* The LOGO will not be retried on failure. A LOGO was
2688 * issued to the remote rport and a ACC or RJT or no Answer are
2689 * all acceptable. Note the failure and move forward with
2690 * discovery. The PLOGI will retry.
2692 if (irsp->ulpStatus) {
2694 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2695 "2756 LOGO failure, No Retry DID:%06X Status:x%x/x%x\n",
2696 ndlp->nlp_DID, irsp->ulpStatus,
2697 irsp->un.ulpWord[4]);
2698 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2699 if (lpfc_error_lost_link(irsp)) {
2705 /* Call state machine. This will unregister the rpi if needed. */
2706 lpfc_disc_state_machine(vport, ndlp, cmdiocb, NLP_EVT_CMPL_LOGO);
2709 lpfc_els_free_iocb(phba, cmdiocb);
2710 /* If we are in pt2pt mode, we could rcv new S_ID on PLOGI */
2711 if ((vport->fc_flag & FC_PT2PT) &&
2712 !(vport->fc_flag & FC_PT2PT_PLOGI)) {
2713 phba->pport->fc_myDID = 0;
2715 if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
2716 (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
2717 if (phba->nvmet_support)
2718 lpfc_nvmet_update_targetport(phba);
2720 lpfc_nvme_update_localport(phba->pport);
2723 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2725 lpfc_config_link(phba, mbox);
2726 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
2727 mbox->vport = vport;
2728 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) ==
2730 mempool_free(mbox, phba->mbox_mem_pool);
2737 * If the node is a target, the handling attempts to recover the port.
2738 * For any other port type, the rpi is unregistered as an implicit
2741 if (ndlp->nlp_type & (NLP_FCP_TARGET | NLP_NVME_TARGET) &&
2742 skip_recovery == 0) {
2743 lpfc_cancel_retry_delay_tmo(vport, ndlp);
2744 spin_lock_irqsave(shost->host_lock, flags);
2745 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2746 spin_unlock_irqrestore(shost->host_lock, flags);
2748 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2749 "3187 LOGO completes to NPort x%x: Start "
2750 "Recovery Data: x%x x%x x%x x%x\n",
2751 ndlp->nlp_DID, irsp->ulpStatus,
2752 irsp->un.ulpWord[4], irsp->ulpTimeout,
2753 vport->num_disc_nodes);
2754 lpfc_disc_start(vport);
2760 * lpfc_issue_els_logo - Issue a logo to an node on a vport
2761 * @vport: pointer to a virtual N_Port data structure.
2762 * @ndlp: pointer to a node-list data structure.
2763 * @retry: number of retries to the command IOCB.
2765 * This routine constructs and issues an ELS Logout (LOGO) iocb command
2766 * to a remote node, referred by an @ndlp on a @vport. It constructs the
2767 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
2768 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
2770 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2771 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2772 * will be stored into the context1 field of the IOCB for the completion
2773 * callback function to the LOGO ELS command.
2775 * Callers of this routine are expected to unregister the RPI first
2778 * 0 - successfully issued logo
2779 * 1 - failed to issue logo
2782 lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2785 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2786 struct lpfc_hba *phba = vport->phba;
2787 struct lpfc_iocbq *elsiocb;
2792 spin_lock_irq(shost->host_lock);
2793 if (ndlp->nlp_flag & NLP_LOGO_SND) {
2794 spin_unlock_irq(shost->host_lock);
2797 spin_unlock_irq(shost->host_lock);
2799 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
2800 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2801 ndlp->nlp_DID, ELS_CMD_LOGO);
2805 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2806 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
2807 pcmd += sizeof(uint32_t);
2809 /* Fill in LOGO payload */
2810 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
2811 pcmd += sizeof(uint32_t);
2812 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
2814 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2815 "Issue LOGO: did:x%x",
2816 ndlp->nlp_DID, 0, 0);
2818 phba->fc_stat.elsXmitLOGO++;
2819 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
2820 spin_lock_irq(shost->host_lock);
2821 ndlp->nlp_flag |= NLP_LOGO_SND;
2822 ndlp->nlp_flag &= ~NLP_ISSUE_LOGO;
2823 spin_unlock_irq(shost->host_lock);
2824 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
2825 if (rc == IOCB_ERROR) {
2826 spin_lock_irq(shost->host_lock);
2827 ndlp->nlp_flag &= ~NLP_LOGO_SND;
2828 spin_unlock_irq(shost->host_lock);
2829 lpfc_els_free_iocb(phba, elsiocb);
2833 spin_lock_irq(shost->host_lock);
2834 ndlp->nlp_prev_state = ndlp->nlp_state;
2835 spin_unlock_irq(shost->host_lock);
2836 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
2841 * lpfc_cmpl_els_cmd - Completion callback function for generic els command
2842 * @phba: pointer to lpfc hba data structure.
2843 * @cmdiocb: pointer to lpfc command iocb data structure.
2844 * @rspiocb: pointer to lpfc response iocb data structure.
2846 * This routine is a generic completion callback function for ELS commands.
2847 * Specifically, it is the callback function which does not need to perform
2848 * any command specific operations. It is currently used by the ELS command
2849 * issuing routines for the ELS State Change Request (SCR),
2850 * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution
2851 * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than
2852 * certain debug loggings, this callback function simply invokes the
2853 * lpfc_els_chk_latt() routine to check whether link went down during the
2854 * discovery process.
2857 lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2858 struct lpfc_iocbq *rspiocb)
2860 struct lpfc_vport *vport = cmdiocb->vport;
2863 irsp = &rspiocb->iocb;
2865 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2866 "ELS cmd cmpl: status:x%x/x%x did:x%x",
2867 irsp->ulpStatus, irsp->un.ulpWord[4],
2868 irsp->un.elsreq64.remoteID);
2869 /* ELS cmd tag <ulpIoTag> completes */
2870 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2871 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
2872 irsp->ulpIoTag, irsp->ulpStatus,
2873 irsp->un.ulpWord[4], irsp->ulpTimeout);
2874 /* Check to see if link went down during discovery */
2875 lpfc_els_chk_latt(vport);
2876 lpfc_els_free_iocb(phba, cmdiocb);
2881 * lpfc_issue_els_scr - Issue a scr to an node on a vport
2882 * @vport: pointer to a host virtual N_Port data structure.
2883 * @nportid: N_Port identifier to the remote node.
2884 * @retry: number of retries to the command IOCB.
2886 * This routine issues a State Change Request (SCR) to a fabric node
2887 * on a @vport. The remote node @nportid is passed into the function. It
2888 * first search the @vport node list to find the matching ndlp. If no such
2889 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
2890 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
2891 * routine is invoked to send the SCR IOCB.
2893 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2894 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2895 * will be stored into the context1 field of the IOCB for the completion
2896 * callback function to the SCR ELS command.
2899 * 0 - Successfully issued scr command
2900 * 1 - Failed to issue scr command
2903 lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
2905 struct lpfc_hba *phba = vport->phba;
2906 struct lpfc_iocbq *elsiocb;
2909 struct lpfc_nodelist *ndlp;
2911 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
2913 ndlp = lpfc_findnode_did(vport, nportid);
2915 ndlp = lpfc_nlp_init(vport, nportid);
2918 lpfc_enqueue_node(vport, ndlp);
2919 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2920 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2925 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2926 ndlp->nlp_DID, ELS_CMD_SCR);
2929 /* This will trigger the release of the node just
2936 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2938 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
2939 pcmd += sizeof(uint32_t);
2941 /* For SCR, remainder of payload is SCR parameter page */
2942 memset(pcmd, 0, sizeof(SCR));
2943 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
2945 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2946 "Issue SCR: did:x%x",
2947 ndlp->nlp_DID, 0, 0);
2949 phba->fc_stat.elsXmitSCR++;
2950 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
2951 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2953 /* The additional lpfc_nlp_put will cause the following
2954 * lpfc_els_free_iocb routine to trigger the rlease of
2958 lpfc_els_free_iocb(phba, elsiocb);
2961 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2962 * trigger the release of node.
2964 if (!(vport->fc_flag & FC_PT2PT))
2970 * lpfc_issue_els_farpr - Issue a farp to an node on a vport
2971 * @vport: pointer to a host virtual N_Port data structure.
2972 * @nportid: N_Port identifier to the remote node.
2973 * @retry: number of retries to the command IOCB.
2975 * This routine issues a Fibre Channel Address Resolution Response
2976 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
2977 * is passed into the function. It first search the @vport node list to find
2978 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
2979 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
2980 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
2982 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2983 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2984 * will be stored into the context1 field of the IOCB for the completion
2985 * callback function to the PARPR ELS command.
2988 * 0 - Successfully issued farpr command
2989 * 1 - Failed to issue farpr command
2992 lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
2994 struct lpfc_hba *phba = vport->phba;
2995 struct lpfc_iocbq *elsiocb;
3000 struct lpfc_nodelist *ondlp;
3001 struct lpfc_nodelist *ndlp;
3003 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
3005 ndlp = lpfc_findnode_did(vport, nportid);
3007 ndlp = lpfc_nlp_init(vport, nportid);
3010 lpfc_enqueue_node(vport, ndlp);
3011 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
3012 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
3017 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
3018 ndlp->nlp_DID, ELS_CMD_RNID);
3020 /* This will trigger the release of the node just
3027 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3029 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
3030 pcmd += sizeof(uint32_t);
3032 /* Fill in FARPR payload */
3033 fp = (FARP *) (pcmd);
3034 memset(fp, 0, sizeof(FARP));
3035 lp = (uint32_t *) pcmd;
3036 *lp++ = be32_to_cpu(nportid);
3037 *lp++ = be32_to_cpu(vport->fc_myDID);
3039 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
3041 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
3042 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
3043 ondlp = lpfc_findnode_did(vport, nportid);
3044 if (ondlp && NLP_CHK_NODE_ACT(ondlp)) {
3045 memcpy(&fp->OportName, &ondlp->nlp_portname,
3046 sizeof(struct lpfc_name));
3047 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
3048 sizeof(struct lpfc_name));
3051 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3052 "Issue FARPR: did:x%x",
3053 ndlp->nlp_DID, 0, 0);
3055 phba->fc_stat.elsXmitFARPR++;
3056 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
3057 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
3059 /* The additional lpfc_nlp_put will cause the following
3060 * lpfc_els_free_iocb routine to trigger the release of
3064 lpfc_els_free_iocb(phba, elsiocb);
3067 /* This will cause the callback-function lpfc_cmpl_els_cmd to
3068 * trigger the release of the node.
3075 * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
3076 * @vport: pointer to a host virtual N_Port data structure.
3077 * @nlp: pointer to a node-list data structure.
3079 * This routine cancels the timer with a delayed IOCB-command retry for
3080 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
3081 * removes the ELS retry event if it presents. In addition, if the
3082 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
3083 * commands are sent for the @vport's nodes that require issuing discovery
3087 lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
3089 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3090 struct lpfc_work_evt *evtp;
3092 if (!(nlp->nlp_flag & NLP_DELAY_TMO))
3094 spin_lock_irq(shost->host_lock);
3095 nlp->nlp_flag &= ~NLP_DELAY_TMO;
3096 spin_unlock_irq(shost->host_lock);
3097 del_timer_sync(&nlp->nlp_delayfunc);
3098 nlp->nlp_last_elscmd = 0;
3099 if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
3100 list_del_init(&nlp->els_retry_evt.evt_listp);
3101 /* Decrement nlp reference count held for the delayed retry */
3102 evtp = &nlp->els_retry_evt;
3103 lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
3105 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
3106 spin_lock_irq(shost->host_lock);
3107 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
3108 spin_unlock_irq(shost->host_lock);
3109 if (vport->num_disc_nodes) {
3110 if (vport->port_state < LPFC_VPORT_READY) {
3111 /* Check if there are more ADISCs to be sent */
3112 lpfc_more_adisc(vport);
3114 /* Check if there are more PLOGIs to be sent */
3115 lpfc_more_plogi(vport);
3116 if (vport->num_disc_nodes == 0) {
3117 spin_lock_irq(shost->host_lock);
3118 vport->fc_flag &= ~FC_NDISC_ACTIVE;
3119 spin_unlock_irq(shost->host_lock);
3120 lpfc_can_disctmo(vport);
3121 lpfc_end_rscn(vport);
3130 * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
3131 * @ptr: holder for the pointer to the timer function associated data (ndlp).
3133 * This routine is invoked by the ndlp delayed-function timer to check
3134 * whether there is any pending ELS retry event(s) with the node. If not, it
3135 * simply returns. Otherwise, if there is at least one ELS delayed event, it
3136 * adds the delayed events to the HBA work list and invokes the
3137 * lpfc_worker_wake_up() routine to wake up worker thread to process the
3138 * event. Note that lpfc_nlp_get() is called before posting the event to
3139 * the work list to hold reference count of ndlp so that it guarantees the
3140 * reference to ndlp will still be available when the worker thread gets
3141 * to the event associated with the ndlp.
3144 lpfc_els_retry_delay(struct timer_list *t)
3146 struct lpfc_nodelist *ndlp = from_timer(ndlp, t, nlp_delayfunc);
3147 struct lpfc_vport *vport = ndlp->vport;
3148 struct lpfc_hba *phba = vport->phba;
3149 unsigned long flags;
3150 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
3152 spin_lock_irqsave(&phba->hbalock, flags);
3153 if (!list_empty(&evtp->evt_listp)) {
3154 spin_unlock_irqrestore(&phba->hbalock, flags);
3158 /* We need to hold the node by incrementing the reference
3159 * count until the queued work is done
3161 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
3162 if (evtp->evt_arg1) {
3163 evtp->evt = LPFC_EVT_ELS_RETRY;
3164 list_add_tail(&evtp->evt_listp, &phba->work_list);
3165 lpfc_worker_wake_up(phba);
3167 spin_unlock_irqrestore(&phba->hbalock, flags);
3172 * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
3173 * @ndlp: pointer to a node-list data structure.
3175 * This routine is the worker-thread handler for processing the @ndlp delayed
3176 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
3177 * the last ELS command from the associated ndlp and invokes the proper ELS
3178 * function according to the delayed ELS command to retry the command.
3181 lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
3183 struct lpfc_vport *vport = ndlp->vport;
3184 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3185 uint32_t cmd, retry;
3187 spin_lock_irq(shost->host_lock);
3188 cmd = ndlp->nlp_last_elscmd;
3189 ndlp->nlp_last_elscmd = 0;
3191 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
3192 spin_unlock_irq(shost->host_lock);
3196 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
3197 spin_unlock_irq(shost->host_lock);
3199 * If a discovery event readded nlp_delayfunc after timer
3200 * firing and before processing the timer, cancel the
3203 del_timer_sync(&ndlp->nlp_delayfunc);
3204 retry = ndlp->nlp_retry;
3205 ndlp->nlp_retry = 0;
3209 lpfc_issue_els_flogi(vport, ndlp, retry);
3212 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
3213 ndlp->nlp_prev_state = ndlp->nlp_state;
3214 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
3218 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
3219 ndlp->nlp_prev_state = ndlp->nlp_state;
3220 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
3224 case ELS_CMD_NVMEPRLI:
3225 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
3226 ndlp->nlp_prev_state = ndlp->nlp_state;
3227 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
3231 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
3232 ndlp->nlp_prev_state = ndlp->nlp_state;
3233 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
3237 if (!(vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI))
3238 lpfc_issue_els_fdisc(vport, ndlp, retry);
3245 * lpfc_link_reset - Issue link reset
3246 * @vport: pointer to a virtual N_Port data structure.
3248 * This routine performs link reset by sending INIT_LINK mailbox command.
3249 * For SLI-3 adapter, link attention interrupt is enabled before issuing
3250 * INIT_LINK mailbox command.
3253 * 0 - Link reset initiated successfully
3254 * 1 - Failed to initiate link reset
3257 lpfc_link_reset(struct lpfc_vport *vport)
3259 struct lpfc_hba *phba = vport->phba;
3264 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3265 "2851 Attempt link reset\n");
3266 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3268 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
3269 "2852 Failed to allocate mbox memory");
3273 /* Enable Link attention interrupts */
3274 if (phba->sli_rev <= LPFC_SLI_REV3) {
3275 spin_lock_irq(&phba->hbalock);
3276 phba->sli.sli_flag |= LPFC_PROCESS_LA;
3277 control = readl(phba->HCregaddr);
3278 control |= HC_LAINT_ENA;
3279 writel(control, phba->HCregaddr);
3280 readl(phba->HCregaddr); /* flush */
3281 spin_unlock_irq(&phba->hbalock);
3284 lpfc_init_link(phba, mbox, phba->cfg_topology,
3285 phba->cfg_link_speed);
3286 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
3287 mbox->vport = vport;
3288 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
3289 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
3290 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
3291 "2853 Failed to issue INIT_LINK "
3292 "mbox command, rc:x%x\n", rc);
3293 mempool_free(mbox, phba->mbox_mem_pool);
3301 * lpfc_els_retry - Make retry decision on an els command iocb
3302 * @phba: pointer to lpfc hba data structure.
3303 * @cmdiocb: pointer to lpfc command iocb data structure.
3304 * @rspiocb: pointer to lpfc response iocb data structure.
3306 * This routine makes a retry decision on an ELS command IOCB, which has
3307 * failed. The following ELS IOCBs use this function for retrying the command
3308 * when previously issued command responsed with error status: FLOGI, PLOGI,
3309 * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
3310 * returned error status, it makes the decision whether a retry shall be
3311 * issued for the command, and whether a retry shall be made immediately or
3312 * delayed. In the former case, the corresponding ELS command issuing-function
3313 * is called to retry the command. In the later case, the ELS command shall
3314 * be posted to the ndlp delayed event and delayed function timer set to the
3315 * ndlp for the delayed command issusing.
3318 * 0 - No retry of els command is made
3319 * 1 - Immediate or delayed retry of els command is made
3322 lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3323 struct lpfc_iocbq *rspiocb)
3325 struct lpfc_vport *vport = cmdiocb->vport;
3326 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3327 IOCB_t *irsp = &rspiocb->iocb;
3328 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3329 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3332 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
3336 int link_reset = 0, rc;
3339 /* Note: context2 may be 0 for internal driver abort
3340 * of delays ELS command.
3343 if (pcmd && pcmd->virt) {
3344 elscmd = (uint32_t *) (pcmd->virt);
3348 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
3349 did = ndlp->nlp_DID;
3351 /* We should only hit this case for retrying PLOGI */
3352 did = irsp->un.elsreq64.remoteID;
3353 ndlp = lpfc_findnode_did(vport, did);
3354 if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp))
3355 && (cmd != ELS_CMD_PLOGI))
3359 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3360 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
3361 *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
3363 switch (irsp->ulpStatus) {
3364 case IOSTAT_FCP_RSP_ERROR:
3366 case IOSTAT_REMOTE_STOP:
3367 if (phba->sli_rev == LPFC_SLI_REV4) {
3368 /* This IO was aborted by the target, we don't
3369 * know the rxid and because we did not send the
3370 * ABTS we cannot generate and RRQ.
3372 lpfc_set_rrq_active(phba, ndlp,
3373 cmdiocb->sli4_lxritag, 0, 0);
3376 case IOSTAT_LOCAL_REJECT:
3377 switch ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK)) {
3378 case IOERR_LOOP_OPEN_FAILURE:
3379 if (cmd == ELS_CMD_FLOGI) {
3380 if (PCI_DEVICE_ID_HORNET ==
3381 phba->pcidev->device) {
3382 phba->fc_topology = LPFC_TOPOLOGY_LOOP;
3383 phba->pport->fc_myDID = 0;
3384 phba->alpa_map[0] = 0;
3385 phba->alpa_map[1] = 0;
3388 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
3393 case IOERR_ILLEGAL_COMMAND:
3394 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3395 "0124 Retry illegal cmd x%x "
3396 "retry:x%x delay:x%x\n",
3397 cmd, cmdiocb->retry, delay);
3399 /* All command's retry policy */
3401 if (cmdiocb->retry > 2)
3405 case IOERR_NO_RESOURCES:
3406 logerr = 1; /* HBA out of resources */
3408 if (cmdiocb->retry > 100)
3413 case IOERR_ILLEGAL_FRAME:
3418 case IOERR_INVALID_RPI:
3419 if (cmd == ELS_CMD_PLOGI &&
3420 did == NameServer_DID) {
3421 /* Continue forever if plogi to */
3422 /* the nameserver fails */
3429 case IOERR_SEQUENCE_TIMEOUT:
3430 if (cmd == ELS_CMD_PLOGI &&
3431 did == NameServer_DID &&
3432 (cmdiocb->retry + 1) == maxretry) {
3433 /* Reset the Link */
3443 case IOSTAT_NPORT_RJT:
3444 case IOSTAT_FABRIC_RJT:
3445 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
3451 case IOSTAT_NPORT_BSY:
3452 case IOSTAT_FABRIC_BSY:
3453 logerr = 1; /* Fabric / Remote NPort out of resources */
3458 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
3459 /* Added for Vendor specifc support
3460 * Just keep retrying for these Rsn / Exp codes
3462 switch (stat.un.b.lsRjtRsnCode) {
3463 case LSRJT_UNABLE_TPC:
3464 /* The driver has a VALID PLOGI but the rport has
3465 * rejected the PRLI - can't do it now. Delay
3466 * for 1 second and try again - don't care about
3469 if (cmd == ELS_CMD_PRLI || cmd == ELS_CMD_NVMEPRLI) {
3471 maxretry = lpfc_max_els_tries + 1;
3476 /* Legacy bug fix code for targets with PLOGI delays. */
3477 if (stat.un.b.lsRjtRsnCodeExp ==
3478 LSEXP_CMD_IN_PROGRESS) {
3479 if (cmd == ELS_CMD_PLOGI) {
3486 if (stat.un.b.lsRjtRsnCodeExp ==
3487 LSEXP_CANT_GIVE_DATA) {
3488 if (cmd == ELS_CMD_PLOGI) {
3495 if (cmd == ELS_CMD_PLOGI) {
3497 maxretry = lpfc_max_els_tries + 1;
3501 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
3502 (cmd == ELS_CMD_FDISC) &&
3503 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
3504 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3505 "0125 FDISC Failed (x%x). "
3506 "Fabric out of resources\n",
3507 stat.un.lsRjtError);
3508 lpfc_vport_set_state(vport,
3509 FC_VPORT_NO_FABRIC_RSCS);
3513 case LSRJT_LOGICAL_BSY:
3514 if ((cmd == ELS_CMD_PLOGI) ||
3515 (cmd == ELS_CMD_PRLI) ||
3516 (cmd == ELS_CMD_NVMEPRLI)) {
3519 } else if (cmd == ELS_CMD_FDISC) {
3520 /* FDISC retry policy */
3522 if (cmdiocb->retry >= 32)
3528 case LSRJT_LOGICAL_ERR:
3529 /* There are some cases where switches return this
3530 * error when they are not ready and should be returning
3531 * Logical Busy. We should delay every time.
3533 if (cmd == ELS_CMD_FDISC &&
3534 stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
3538 } else if (cmd == ELS_CMD_FLOGI &&
3539 stat.un.b.lsRjtRsnCodeExp ==
3540 LSEXP_NOTHING_MORE) {
3541 vport->fc_sparam.cmn.bbRcvSizeMsb &= 0xf;
3543 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3544 "0820 FLOGI Failed (x%x). "
3545 "BBCredit Not Supported\n",
3546 stat.un.lsRjtError);
3550 case LSRJT_PROTOCOL_ERR:
3551 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
3552 (cmd == ELS_CMD_FDISC) &&
3553 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
3554 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
3556 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3557 "0122 FDISC Failed (x%x). "
3558 "Fabric Detected Bad WWN\n",
3559 stat.un.lsRjtError);
3560 lpfc_vport_set_state(vport,
3561 FC_VPORT_FABRIC_REJ_WWN);
3564 case LSRJT_VENDOR_UNIQUE:
3565 if ((stat.un.b.vendorUnique == 0x45) &&
3566 (cmd == ELS_CMD_FLOGI)) {
3570 case LSRJT_CMD_UNSUPPORTED:
3571 /* lpfc nvmet returns this type of LS_RJT when it
3572 * receives an FCP PRLI because lpfc nvmet only
3573 * support NVME. ELS request is terminated for FCP4
3576 if (stat.un.b.lsRjtRsnCodeExp ==
3577 LSEXP_REQ_UNSUPPORTED && cmd == ELS_CMD_PRLI) {
3578 spin_lock_irq(shost->host_lock);
3579 ndlp->nlp_flag |= NLP_FCP_PRLI_RJT;
3580 spin_unlock_irq(shost->host_lock);
3588 case IOSTAT_INTERMED_RSP:
3597 rc = lpfc_link_reset(vport);
3599 /* Do not give up. Retry PLOGI one more time and attempt
3600 * link reset if PLOGI fails again.
3609 if (did == FDMI_DID)
3612 if ((cmd == ELS_CMD_FLOGI) &&
3613 (phba->fc_topology != LPFC_TOPOLOGY_LOOP) &&
3614 !lpfc_error_lost_link(irsp)) {
3615 /* FLOGI retry policy */
3617 /* retry FLOGI forever */
3618 if (phba->link_flag != LS_LOOPBACK_MODE)
3623 if (cmdiocb->retry >= 100)
3625 else if (cmdiocb->retry >= 32)
3627 } else if ((cmd == ELS_CMD_FDISC) && !lpfc_error_lost_link(irsp)) {
3628 /* retry FDISCs every second up to devloss */
3630 maxretry = vport->cfg_devloss_tmo;
3635 if (maxretry && (cmdiocb->retry >= maxretry)) {
3636 phba->fc_stat.elsRetryExceeded++;
3640 if ((vport->load_flag & FC_UNLOADING) != 0)
3645 if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) {
3646 /* Stop retrying PLOGI and FDISC if in FCF discovery */
3647 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
3648 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3649 "2849 Stop retry ELS command "
3650 "x%x to remote NPORT x%x, "
3651 "Data: x%x x%x\n", cmd, did,
3652 cmdiocb->retry, delay);
3657 /* Retry ELS command <elsCmd> to remote NPORT <did> */
3658 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3659 "0107 Retry ELS command x%x to remote "
3660 "NPORT x%x Data: x%x x%x\n",
3661 cmd, did, cmdiocb->retry, delay);
3663 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
3664 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
3665 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
3666 IOERR_NO_RESOURCES))) {
3667 /* Don't reset timer for no resources */
3669 /* If discovery / RSCN timer is running, reset it */
3670 if (timer_pending(&vport->fc_disctmo) ||
3671 (vport->fc_flag & FC_RSCN_MODE))
3672 lpfc_set_disctmo(vport);
3675 phba->fc_stat.elsXmitRetry++;
3676 if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) {
3677 phba->fc_stat.elsDelayRetry++;
3678 ndlp->nlp_retry = cmdiocb->retry;
3680 /* delay is specified in milliseconds */
3681 mod_timer(&ndlp->nlp_delayfunc,
3682 jiffies + msecs_to_jiffies(delay));
3683 spin_lock_irq(shost->host_lock);
3684 ndlp->nlp_flag |= NLP_DELAY_TMO;
3685 spin_unlock_irq(shost->host_lock);
3687 ndlp->nlp_prev_state = ndlp->nlp_state;
3688 if ((cmd == ELS_CMD_PRLI) ||
3689 (cmd == ELS_CMD_NVMEPRLI))
3690 lpfc_nlp_set_state(vport, ndlp,
3691 NLP_STE_PRLI_ISSUE);
3693 lpfc_nlp_set_state(vport, ndlp,
3695 ndlp->nlp_last_elscmd = cmd;
3701 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
3704 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
3707 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
3708 ndlp->nlp_prev_state = ndlp->nlp_state;
3709 lpfc_nlp_set_state(vport, ndlp,
3710 NLP_STE_PLOGI_ISSUE);
3712 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
3715 ndlp->nlp_prev_state = ndlp->nlp_state;
3716 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
3717 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
3720 case ELS_CMD_NVMEPRLI:
3721 ndlp->nlp_prev_state = ndlp->nlp_state;
3722 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
3723 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
3726 ndlp->nlp_prev_state = ndlp->nlp_state;
3727 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
3728 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
3732 /* No retry ELS command <elsCmd> to remote NPORT <did> */
3734 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3735 "0137 No retry ELS command x%x to remote "
3736 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
3737 cmd, did, irsp->ulpStatus,
3738 irsp->un.ulpWord[4]);
3741 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3742 "0108 No retry ELS command x%x to remote "
3743 "NPORT x%x Retried:%d Error:x%x/%x\n",
3744 cmd, did, cmdiocb->retry, irsp->ulpStatus,
3745 irsp->un.ulpWord[4]);
3751 * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
3752 * @phba: pointer to lpfc hba data structure.
3753 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
3755 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
3756 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
3757 * checks to see whether there is a lpfc DMA buffer associated with the
3758 * response of the command IOCB. If so, it will be released before releasing
3759 * the lpfc DMA buffer associated with the IOCB itself.
3762 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3765 lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
3767 struct lpfc_dmabuf *buf_ptr;
3769 /* Free the response before processing the command. */
3770 if (!list_empty(&buf_ptr1->list)) {
3771 list_remove_head(&buf_ptr1->list, buf_ptr,
3774 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3777 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
3783 * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
3784 * @phba: pointer to lpfc hba data structure.
3785 * @buf_ptr: pointer to the lpfc dma buffer data structure.
3787 * This routine releases the lpfc Direct Memory Access (DMA) buffer
3788 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
3792 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3795 lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
3797 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3803 * lpfc_els_free_iocb - Free a command iocb and its associated resources
3804 * @phba: pointer to lpfc hba data structure.
3805 * @elsiocb: pointer to lpfc els command iocb data structure.
3807 * This routine frees a command IOCB and its associated resources. The
3808 * command IOCB data structure contains the reference to various associated
3809 * resources, these fields must be set to NULL if the associated reference
3811 * context1 - reference to ndlp
3812 * context2 - reference to cmd
3813 * context2->next - reference to rsp
3814 * context3 - reference to bpl
3816 * It first properly decrements the reference count held on ndlp for the
3817 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
3818 * set, it invokes the lpfc_els_free_data() routine to release the Direct
3819 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
3820 * adds the DMA buffer the @phba data structure for the delayed release.
3821 * If reference to the Buffer Pointer List (BPL) is present, the
3822 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
3823 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
3824 * invoked to release the IOCB data structure back to @phba IOCBQ list.
3827 * 0 - Success (currently, always return 0)
3830 lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
3832 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
3833 struct lpfc_nodelist *ndlp;
3835 ndlp = (struct lpfc_nodelist *)elsiocb->context1;
3837 if (ndlp->nlp_flag & NLP_DEFER_RM) {
3840 /* If the ndlp is not being used by another discovery
3843 if (!lpfc_nlp_not_used(ndlp)) {
3844 /* If ndlp is being used by another discovery
3845 * thread, just clear NLP_DEFER_RM
3847 ndlp->nlp_flag &= ~NLP_DEFER_RM;
3852 elsiocb->context1 = NULL;
3854 /* context2 = cmd, context2->next = rsp, context3 = bpl */
3855 if (elsiocb->context2) {
3856 if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
3857 /* Firmware could still be in progress of DMAing
3858 * payload, so don't free data buffer till after
3861 elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
3862 buf_ptr = elsiocb->context2;
3863 elsiocb->context2 = NULL;
3866 spin_lock_irq(&phba->hbalock);
3867 if (!list_empty(&buf_ptr->list)) {
3868 list_remove_head(&buf_ptr->list,
3869 buf_ptr1, struct lpfc_dmabuf,
3871 INIT_LIST_HEAD(&buf_ptr1->list);
3872 list_add_tail(&buf_ptr1->list,
3876 INIT_LIST_HEAD(&buf_ptr->list);
3877 list_add_tail(&buf_ptr->list, &phba->elsbuf);
3879 spin_unlock_irq(&phba->hbalock);
3882 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
3883 lpfc_els_free_data(phba, buf_ptr1);
3884 elsiocb->context2 = NULL;
3888 if (elsiocb->context3) {
3889 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
3890 lpfc_els_free_bpl(phba, buf_ptr);
3891 elsiocb->context3 = NULL;
3893 lpfc_sli_release_iocbq(phba, elsiocb);
3898 * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
3899 * @phba: pointer to lpfc hba data structure.
3900 * @cmdiocb: pointer to lpfc command iocb data structure.
3901 * @rspiocb: pointer to lpfc response iocb data structure.
3903 * This routine is the completion callback function to the Logout (LOGO)
3904 * Accept (ACC) Response ELS command. This routine is invoked to indicate
3905 * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
3906 * release the ndlp if it has the last reference remaining (reference count
3907 * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
3908 * field to NULL to inform the following lpfc_els_free_iocb() routine no
3909 * ndlp reference count needs to be decremented. Otherwise, the ndlp
3910 * reference use-count shall be decremented by the lpfc_els_free_iocb()
3911 * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
3912 * IOCB data structure.
3915 lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3916 struct lpfc_iocbq *rspiocb)
3918 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3919 struct lpfc_vport *vport = cmdiocb->vport;
3922 irsp = &rspiocb->iocb;
3923 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3924 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
3925 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
3926 /* ACC to LOGO completes to NPort <nlp_DID> */
3927 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3928 "0109 ACC to LOGO completes to NPort x%x "
3929 "Data: x%x x%x x%x\n",
3930 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3933 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
3934 /* NPort Recovery mode or node is just allocated */
3935 if (!lpfc_nlp_not_used(ndlp)) {
3936 /* If the ndlp is being used by another discovery
3937 * thread, just unregister the RPI.
3939 lpfc_unreg_rpi(vport, ndlp);
3941 /* Indicate the node has already released, should
3942 * not reference to it from within lpfc_els_free_iocb.
3944 cmdiocb->context1 = NULL;
3949 * The driver received a LOGO from the rport and has ACK'd it.
3950 * At this point, the driver is done so release the IOCB
3952 lpfc_els_free_iocb(phba, cmdiocb);
3956 * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
3957 * @phba: pointer to lpfc hba data structure.
3958 * @pmb: pointer to the driver internal queue element for mailbox command.
3960 * This routine is the completion callback function for unregister default
3961 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
3962 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
3963 * decrements the ndlp reference count held for this completion callback
3964 * function. After that, it invokes the lpfc_nlp_not_used() to check
3965 * whether there is only one reference left on the ndlp. If so, it will
3966 * perform one more decrement and trigger the release of the ndlp.
3969 lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3971 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
3972 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
3974 pmb->context1 = NULL;
3975 pmb->context2 = NULL;
3977 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3979 mempool_free(pmb, phba->mbox_mem_pool);
3981 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
3982 "0006 rpi%x DID:%x flg:%x %d map:%x %p\n",
3983 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
3984 kref_read(&ndlp->kref),
3985 ndlp->nlp_usg_map, ndlp);
3986 if (NLP_CHK_NODE_ACT(ndlp)) {
3988 /* This is the end of the default RPI cleanup logic for
3989 * this ndlp. If no other discovery threads are using
3990 * this ndlp, free all resources associated with it.
3992 lpfc_nlp_not_used(ndlp);
3994 lpfc_drop_node(ndlp->vport, ndlp);
4002 * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
4003 * @phba: pointer to lpfc hba data structure.
4004 * @cmdiocb: pointer to lpfc command iocb data structure.
4005 * @rspiocb: pointer to lpfc response iocb data structure.
4007 * This routine is the completion callback function for ELS Response IOCB
4008 * command. In normal case, this callback function just properly sets the
4009 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
4010 * field in the command IOCB is not NULL, the referred mailbox command will
4011 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
4012 * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
4013 * link down event occurred during the discovery, the lpfc_nlp_not_used()
4014 * routine shall be invoked trying to release the ndlp if no other threads
4015 * are currently referring it.
4018 lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
4019 struct lpfc_iocbq *rspiocb)
4021 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
4022 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
4023 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
4026 LPFC_MBOXQ_t *mbox = NULL;
4027 struct lpfc_dmabuf *mp = NULL;
4028 uint32_t ls_rjt = 0;
4030 irsp = &rspiocb->iocb;
4032 if (cmdiocb->context_un.mbox)
4033 mbox = cmdiocb->context_un.mbox;
4035 /* First determine if this is a LS_RJT cmpl. Note, this callback
4036 * function can have cmdiocb->contest1 (ndlp) field set to NULL.
4038 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
4039 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
4040 (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) {
4041 /* A LS_RJT associated with Default RPI cleanup has its own
4042 * separate code path.
4044 if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
4048 /* Check to see if link went down during discovery */
4049 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) {
4051 mp = (struct lpfc_dmabuf *) mbox->context1;
4053 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4056 mempool_free(mbox, phba->mbox_mem_pool);
4058 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
4059 (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
4060 if (lpfc_nlp_not_used(ndlp)) {
4062 /* Indicate the node has already released,
4063 * should not reference to it from within
4064 * the routine lpfc_els_free_iocb.
4066 cmdiocb->context1 = NULL;
4071 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4072 "ELS rsp cmpl: status:x%x/x%x did:x%x",
4073 irsp->ulpStatus, irsp->un.ulpWord[4],
4074 cmdiocb->iocb.un.elsreq64.remoteID);
4075 /* ELS response tag <ulpIoTag> completes */
4076 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4077 "0110 ELS response tag x%x completes "
4078 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
4079 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
4080 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
4081 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4084 if ((rspiocb->iocb.ulpStatus == 0)
4085 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
4086 if (!lpfc_unreg_rpi(vport, ndlp) &&
4087 (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
4088 ndlp->nlp_state == NLP_STE_REG_LOGIN_ISSUE)) {
4089 lpfc_printf_vlog(vport, KERN_INFO,
4091 "0314 PLOGI recov DID x%x "
4092 "Data: x%x x%x x%x\n",
4093 ndlp->nlp_DID, ndlp->nlp_state,
4094 ndlp->nlp_rpi, ndlp->nlp_flag);
4095 mp = mbox->context1;
4097 lpfc_mbuf_free(phba, mp->virt,
4101 mempool_free(mbox, phba->mbox_mem_pool);
4105 /* Increment reference count to ndlp to hold the
4106 * reference to ndlp for the callback function.
4108 mbox->context2 = lpfc_nlp_get(ndlp);
4109 mbox->vport = vport;
4110 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
4111 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
4112 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
4115 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
4116 ndlp->nlp_prev_state = ndlp->nlp_state;
4117 lpfc_nlp_set_state(vport, ndlp,
4118 NLP_STE_REG_LOGIN_ISSUE);
4121 ndlp->nlp_flag |= NLP_REG_LOGIN_SEND;
4122 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
4123 != MBX_NOT_FINISHED)
4126 /* Decrement the ndlp reference count we
4127 * set for this failed mailbox command.
4130 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
4132 /* ELS rsp: Cannot issue reg_login for <NPortid> */
4133 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4134 "0138 ELS rsp: Cannot issue reg_login for x%x "
4135 "Data: x%x x%x x%x\n",
4136 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4139 if (lpfc_nlp_not_used(ndlp)) {
4141 /* Indicate node has already been released,
4142 * should not reference to it from within
4143 * the routine lpfc_els_free_iocb.
4145 cmdiocb->context1 = NULL;
4148 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
4149 if (!lpfc_error_lost_link(irsp) &&
4150 ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
4151 if (lpfc_nlp_not_used(ndlp)) {
4153 /* Indicate node has already been
4154 * released, should not reference
4155 * to it from within the routine
4156 * lpfc_els_free_iocb.
4158 cmdiocb->context1 = NULL;
4162 mp = (struct lpfc_dmabuf *) mbox->context1;
4164 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4167 mempool_free(mbox, phba->mbox_mem_pool);
4170 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
4171 spin_lock_irq(shost->host_lock);
4172 ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI);
4173 spin_unlock_irq(shost->host_lock);
4175 /* If the node is not being used by another discovery thread,
4176 * and we are sending a reject, we are done with it.
4177 * Release driver reference count here and free associated
4181 if (lpfc_nlp_not_used(ndlp))
4182 /* Indicate node has already been released,
4183 * should not reference to it from within
4184 * the routine lpfc_els_free_iocb.
4186 cmdiocb->context1 = NULL;
4190 lpfc_els_free_iocb(phba, cmdiocb);
4195 * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
4196 * @vport: pointer to a host virtual N_Port data structure.
4197 * @flag: the els command code to be accepted.
4198 * @oldiocb: pointer to the original lpfc command iocb data structure.
4199 * @ndlp: pointer to a node-list data structure.
4200 * @mbox: pointer to the driver internal queue element for mailbox command.
4202 * This routine prepares and issues an Accept (ACC) response IOCB
4203 * command. It uses the @flag to properly set up the IOCB field for the
4204 * specific ACC response command to be issued and invokes the
4205 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
4206 * @mbox pointer is passed in, it will be put into the context_un.mbox
4207 * field of the IOCB for the completion callback function to issue the
4208 * mailbox command to the HBA later when callback is invoked.
4210 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4211 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4212 * will be stored into the context1 field of the IOCB for the completion
4213 * callback function to the corresponding response ELS IOCB command.
4216 * 0 - Successfully issued acc response
4217 * 1 - Failed to issue acc response
4220 lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
4221 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
4224 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4225 struct lpfc_hba *phba = vport->phba;
4228 struct lpfc_iocbq *elsiocb;
4230 struct serv_parm *sp;
4233 ELS_PKT *els_pkt_ptr;
4235 oldcmd = &oldiocb->iocb;
4239 cmdsize = sizeof(uint32_t);
4240 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
4241 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
4243 spin_lock_irq(shost->host_lock);
4244 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
4245 spin_unlock_irq(shost->host_lock);
4249 icmd = &elsiocb->iocb;
4250 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4251 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4252 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4253 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4254 pcmd += sizeof(uint32_t);
4256 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4257 "Issue ACC: did:x%x flg:x%x",
4258 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4262 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
4263 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
4264 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
4268 icmd = &elsiocb->iocb;
4269 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4270 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4271 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4274 elsiocb->context_un.mbox = mbox;
4276 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4277 pcmd += sizeof(uint32_t);
4278 sp = (struct serv_parm *)pcmd;
4280 if (flag == ELS_CMD_FLOGI) {
4281 /* Copy the received service parameters back */
4282 memcpy(sp, &phba->fc_fabparam,
4283 sizeof(struct serv_parm));
4285 /* Clear the F_Port bit */
4288 /* Mark all class service parameters as invalid */
4289 sp->cls1.classValid = 0;
4290 sp->cls2.classValid = 0;
4291 sp->cls3.classValid = 0;
4292 sp->cls4.classValid = 0;
4294 /* Copy our worldwide names */
4295 memcpy(&sp->portName, &vport->fc_sparam.portName,
4296 sizeof(struct lpfc_name));
4297 memcpy(&sp->nodeName, &vport->fc_sparam.nodeName,
4298 sizeof(struct lpfc_name));
4300 memcpy(pcmd, &vport->fc_sparam,
4301 sizeof(struct serv_parm));
4303 sp->cmn.valid_vendor_ver_level = 0;
4304 memset(sp->un.vendorVersion, 0,
4305 sizeof(sp->un.vendorVersion));
4306 sp->cmn.bbRcvSizeMsb &= 0xF;
4308 /* If our firmware supports this feature, convey that
4309 * info to the target using the vendor specific field.
4311 if (phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) {
4312 sp->cmn.valid_vendor_ver_level = 1;
4313 sp->un.vv.vid = cpu_to_be32(LPFC_VV_EMLX_ID);
4315 cpu_to_be32(LPFC_VV_SUPPRESS_RSP);
4319 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4320 "Issue ACC FLOGI/PLOGI: did:x%x flg:x%x",
4321 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4324 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
4325 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
4326 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
4330 icmd = &elsiocb->iocb;
4331 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4332 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4333 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4335 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
4336 sizeof(uint32_t) + sizeof(PRLO));
4337 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
4338 els_pkt_ptr = (ELS_PKT *) pcmd;
4339 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
4341 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4342 "Issue ACC PRLO: did:x%x flg:x%x",
4343 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4348 /* Xmit ELS ACC response tag <ulpIoTag> */
4349 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4350 "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
4351 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x "
4353 elsiocb->iotag, elsiocb->iocb.ulpContext,
4354 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4355 ndlp->nlp_rpi, vport->fc_flag);
4356 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
4357 spin_lock_irq(shost->host_lock);
4358 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED ||
4359 ndlp->nlp_flag & NLP_REG_LOGIN_SEND))
4360 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
4361 spin_unlock_irq(shost->host_lock);
4362 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
4364 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4367 phba->fc_stat.elsXmitACC++;
4368 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4369 if (rc == IOCB_ERROR) {
4370 lpfc_els_free_iocb(phba, elsiocb);
4377 * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command
4378 * @vport: pointer to a virtual N_Port data structure.
4380 * @oldiocb: pointer to the original lpfc command iocb data structure.
4381 * @ndlp: pointer to a node-list data structure.
4382 * @mbox: pointer to the driver internal queue element for mailbox command.
4384 * This routine prepares and issue an Reject (RJT) response IOCB
4385 * command. If a @mbox pointer is passed in, it will be put into the
4386 * context_un.mbox field of the IOCB for the completion callback function
4387 * to issue to the HBA later.
4389 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4390 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4391 * will be stored into the context1 field of the IOCB for the completion
4392 * callback function to the reject response ELS IOCB command.
4395 * 0 - Successfully issued reject response
4396 * 1 - Failed to issue reject response
4399 lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
4400 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
4403 struct lpfc_hba *phba = vport->phba;
4406 struct lpfc_iocbq *elsiocb;
4411 cmdsize = 2 * sizeof(uint32_t);
4412 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4413 ndlp->nlp_DID, ELS_CMD_LS_RJT);
4417 icmd = &elsiocb->iocb;
4418 oldcmd = &oldiocb->iocb;
4419 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4420 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4421 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4423 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
4424 pcmd += sizeof(uint32_t);
4425 *((uint32_t *) (pcmd)) = rejectError;
4428 elsiocb->context_un.mbox = mbox;
4430 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
4431 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4432 "0129 Xmit ELS RJT x%x response tag x%x "
4433 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
4435 rejectError, elsiocb->iotag,
4436 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
4437 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
4438 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4439 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
4440 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
4442 phba->fc_stat.elsXmitLSRJT++;
4443 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4444 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4446 if (rc == IOCB_ERROR) {
4447 lpfc_els_free_iocb(phba, elsiocb);
4454 * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
4455 * @vport: pointer to a virtual N_Port data structure.
4456 * @oldiocb: pointer to the original lpfc command iocb data structure.
4457 * @ndlp: pointer to a node-list data structure.
4459 * This routine prepares and issues an Accept (ACC) response to Address
4460 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
4461 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
4463 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4464 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4465 * will be stored into the context1 field of the IOCB for the completion
4466 * callback function to the ADISC Accept response ELS IOCB command.
4469 * 0 - Successfully issued acc adisc response
4470 * 1 - Failed to issue adisc acc response
4473 lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
4474 struct lpfc_nodelist *ndlp)
4476 struct lpfc_hba *phba = vport->phba;
4478 IOCB_t *icmd, *oldcmd;
4479 struct lpfc_iocbq *elsiocb;
4484 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
4485 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4486 ndlp->nlp_DID, ELS_CMD_ACC);
4490 icmd = &elsiocb->iocb;
4491 oldcmd = &oldiocb->iocb;
4492 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4493 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4495 /* Xmit ADISC ACC response tag <ulpIoTag> */
4496 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4497 "0130 Xmit ADISC ACC response iotag x%x xri: "
4498 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
4499 elsiocb->iotag, elsiocb->iocb.ulpContext,
4500 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4502 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4504 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4505 pcmd += sizeof(uint32_t);
4507 ap = (ADISC *) (pcmd);
4508 ap->hardAL_PA = phba->fc_pref_ALPA;
4509 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
4510 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
4511 ap->DID = be32_to_cpu(vport->fc_myDID);
4513 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4514 "Issue ACC ADISC: did:x%x flg:x%x",
4515 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4517 phba->fc_stat.elsXmitACC++;
4518 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4519 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4520 if (rc == IOCB_ERROR) {
4521 lpfc_els_free_iocb(phba, elsiocb);
4528 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
4529 * @vport: pointer to a virtual N_Port data structure.
4530 * @oldiocb: pointer to the original lpfc command iocb data structure.
4531 * @ndlp: pointer to a node-list data structure.
4533 * This routine prepares and issues an Accept (ACC) response to Process
4534 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
4535 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
4537 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4538 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4539 * will be stored into the context1 field of the IOCB for the completion
4540 * callback function to the PRLI Accept response ELS IOCB command.
4543 * 0 - Successfully issued acc prli response
4544 * 1 - Failed to issue acc prli response
4547 lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
4548 struct lpfc_nodelist *ndlp)
4550 struct lpfc_hba *phba = vport->phba;
4552 struct lpfc_nvme_prli *npr_nvme;
4556 struct lpfc_iocbq *elsiocb;
4559 uint32_t prli_fc4_req, *req_payload;
4560 struct lpfc_dmabuf *req_buf;
4564 /* Need the incoming PRLI payload to determine if the ACC is for an
4565 * FC4 or NVME PRLI type. The PRLI type is at word 1.
4567 req_buf = (struct lpfc_dmabuf *)oldiocb->context2;
4568 req_payload = (((uint32_t *)req_buf->virt) + 1);
4570 /* PRLI type payload is at byte 3 for FCP or NVME. */
4571 prli_fc4_req = be32_to_cpu(*req_payload);
4572 prli_fc4_req = (prli_fc4_req >> 24) & 0xff;
4573 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4574 "6127 PRLI_ACC: Req Type x%x, Word1 x%08x\n",
4575 prli_fc4_req, *((uint32_t *)req_payload));
4577 if (prli_fc4_req == PRLI_FCP_TYPE) {
4578 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
4579 elsrspcmd = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
4580 } else if (prli_fc4_req & PRLI_NVME_TYPE) {
4581 cmdsize = sizeof(uint32_t) + sizeof(struct lpfc_nvme_prli);
4582 elsrspcmd = (ELS_CMD_ACC | (ELS_CMD_NVMEPRLI & ~ELS_RSP_MASK));
4587 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4588 ndlp->nlp_DID, elsrspcmd);
4592 icmd = &elsiocb->iocb;
4593 oldcmd = &oldiocb->iocb;
4594 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4595 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4597 /* Xmit PRLI ACC response tag <ulpIoTag> */
4598 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4599 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
4600 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
4601 elsiocb->iotag, elsiocb->iocb.ulpContext,
4602 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4604 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4605 memset(pcmd, 0, cmdsize);
4607 *((uint32_t *)(pcmd)) = elsrspcmd;
4608 pcmd += sizeof(uint32_t);
4610 /* For PRLI, remainder of payload is PRLI parameter page */
4613 if (prli_fc4_req == PRLI_FCP_TYPE) {
4615 * If the remote port is a target and our firmware version
4616 * is 3.20 or later, set the following bits for FC-TAPE
4619 npr = (PRLI *) pcmd;
4620 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
4621 (vpd->rev.feaLevelHigh >= 0x02)) {
4622 npr->ConfmComplAllowed = 1;
4624 npr->TaskRetryIdReq = 1;
4626 npr->acceptRspCode = PRLI_REQ_EXECUTED;
4627 npr->estabImagePair = 1;
4628 npr->readXferRdyDis = 1;
4629 npr->ConfmComplAllowed = 1;
4630 npr->prliType = PRLI_FCP_TYPE;
4631 npr->initiatorFunc = 1;
4632 } else if (prli_fc4_req & PRLI_NVME_TYPE) {
4633 /* Respond with an NVME PRLI Type */
4634 npr_nvme = (struct lpfc_nvme_prli *) pcmd;
4635 bf_set(prli_type_code, npr_nvme, PRLI_NVME_TYPE);
4636 bf_set(prli_estabImagePair, npr_nvme, 0); /* Should be 0 */
4637 bf_set(prli_acc_rsp_code, npr_nvme, PRLI_REQ_EXECUTED);
4638 if (phba->nvmet_support) {
4639 bf_set(prli_tgt, npr_nvme, 1);
4640 bf_set(prli_disc, npr_nvme, 1);
4641 if (phba->cfg_nvme_enable_fb) {
4642 bf_set(prli_fba, npr_nvme, 1);
4644 /* TBD. Target mode needs to post buffers
4645 * that support the configured first burst
4648 bf_set(prli_fb_sz, npr_nvme,
4649 phba->cfg_nvmet_fb_size);
4652 bf_set(prli_init, npr_nvme, 1);
4655 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
4656 "6015 NVME issue PRLI ACC word1 x%08x "
4657 "word4 x%08x word5 x%08x flag x%x, "
4658 "fcp_info x%x nlp_type x%x\n",
4659 npr_nvme->word1, npr_nvme->word4,
4660 npr_nvme->word5, ndlp->nlp_flag,
4661 ndlp->nlp_fcp_info, ndlp->nlp_type);
4662 npr_nvme->word1 = cpu_to_be32(npr_nvme->word1);
4663 npr_nvme->word4 = cpu_to_be32(npr_nvme->word4);
4664 npr_nvme->word5 = cpu_to_be32(npr_nvme->word5);
4666 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4667 "6128 Unknown FC_TYPE x%x x%x ndlp x%06x\n",
4668 prli_fc4_req, ndlp->nlp_fc4_type,
4671 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4672 "Issue ACC PRLI: did:x%x flg:x%x",
4673 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4675 phba->fc_stat.elsXmitACC++;
4676 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4678 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4679 if (rc == IOCB_ERROR) {
4680 lpfc_els_free_iocb(phba, elsiocb);
4687 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
4688 * @vport: pointer to a virtual N_Port data structure.
4689 * @format: rnid command format.
4690 * @oldiocb: pointer to the original lpfc command iocb data structure.
4691 * @ndlp: pointer to a node-list data structure.
4693 * This routine issues a Request Node Identification Data (RNID) Accept
4694 * (ACC) response. It constructs the RNID ACC response command according to
4695 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
4696 * issue the response. Note that this command does not need to hold the ndlp
4697 * reference count for the callback. So, the ndlp reference count taken by
4698 * the lpfc_prep_els_iocb() routine is put back and the context1 field of
4699 * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
4700 * there is no ndlp reference available.
4702 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4703 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4704 * will be stored into the context1 field of the IOCB for the completion
4705 * callback function. However, for the RNID Accept Response ELS command,
4706 * this is undone later by this routine after the IOCB is allocated.
4709 * 0 - Successfully issued acc rnid response
4710 * 1 - Failed to issue acc rnid response
4713 lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
4714 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
4716 struct lpfc_hba *phba = vport->phba;
4718 IOCB_t *icmd, *oldcmd;
4719 struct lpfc_iocbq *elsiocb;
4724 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
4725 + (2 * sizeof(struct lpfc_name));
4727 cmdsize += sizeof(RNID_TOP_DISC);
4729 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4730 ndlp->nlp_DID, ELS_CMD_ACC);
4734 icmd = &elsiocb->iocb;
4735 oldcmd = &oldiocb->iocb;
4736 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4737 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4739 /* Xmit RNID ACC response tag <ulpIoTag> */
4740 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4741 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
4742 elsiocb->iotag, elsiocb->iocb.ulpContext);
4743 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4744 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4745 pcmd += sizeof(uint32_t);
4747 memset(pcmd, 0, sizeof(RNID));
4748 rn = (RNID *) (pcmd);
4749 rn->Format = format;
4750 rn->CommonLen = (2 * sizeof(struct lpfc_name));
4751 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
4752 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
4755 rn->SpecificLen = 0;
4757 case RNID_TOPOLOGY_DISC:
4758 rn->SpecificLen = sizeof(RNID_TOP_DISC);
4759 memcpy(&rn->un.topologyDisc.portName,
4760 &vport->fc_portname, sizeof(struct lpfc_name));
4761 rn->un.topologyDisc.unitType = RNID_HBA;
4762 rn->un.topologyDisc.physPort = 0;
4763 rn->un.topologyDisc.attachedNodes = 0;
4767 rn->SpecificLen = 0;
4771 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4772 "Issue ACC RNID: did:x%x flg:x%x",
4773 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4775 phba->fc_stat.elsXmitACC++;
4776 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4778 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4779 if (rc == IOCB_ERROR) {
4780 lpfc_els_free_iocb(phba, elsiocb);
4787 * lpfc_els_clear_rrq - Clear the rq that this rrq describes.
4788 * @vport: pointer to a virtual N_Port data structure.
4789 * @iocb: pointer to the lpfc command iocb data structure.
4790 * @ndlp: pointer to a node-list data structure.
4795 lpfc_els_clear_rrq(struct lpfc_vport *vport,
4796 struct lpfc_iocbq *iocb, struct lpfc_nodelist *ndlp)
4798 struct lpfc_hba *phba = vport->phba;
4803 struct lpfc_node_rrq *prrq;
4806 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) iocb->context2)->virt);
4807 pcmd += sizeof(uint32_t);
4808 rrq = (struct RRQ *)pcmd;
4809 rrq->rrq_exchg = be32_to_cpu(rrq->rrq_exchg);
4810 rxid = bf_get(rrq_rxid, rrq);
4812 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4813 "2883 Clear RRQ for SID:x%x OXID:x%x RXID:x%x"
4815 be32_to_cpu(bf_get(rrq_did, rrq)),
4816 bf_get(rrq_oxid, rrq),
4818 iocb->iotag, iocb->iocb.ulpContext);
4820 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4821 "Clear RRQ: did:x%x flg:x%x exchg:x%.08x",
4822 ndlp->nlp_DID, ndlp->nlp_flag, rrq->rrq_exchg);
4823 if (vport->fc_myDID == be32_to_cpu(bf_get(rrq_did, rrq)))
4824 xri = bf_get(rrq_oxid, rrq);
4827 prrq = lpfc_get_active_rrq(vport, xri, ndlp->nlp_DID);
4829 lpfc_clr_rrq_active(phba, xri, prrq);
4834 * lpfc_els_rsp_echo_acc - Issue echo acc response
4835 * @vport: pointer to a virtual N_Port data structure.
4836 * @data: pointer to echo data to return in the accept.
4837 * @oldiocb: pointer to the original lpfc command iocb data structure.
4838 * @ndlp: pointer to a node-list data structure.
4841 * 0 - Successfully issued acc echo response
4842 * 1 - Failed to issue acc echo response
4845 lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data,
4846 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
4848 struct lpfc_hba *phba = vport->phba;
4849 struct lpfc_iocbq *elsiocb;
4854 cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len;
4856 /* The accumulated length can exceed the BPL_SIZE. For
4857 * now, use this as the limit
4859 if (cmdsize > LPFC_BPL_SIZE)
4860 cmdsize = LPFC_BPL_SIZE;
4861 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4862 ndlp->nlp_DID, ELS_CMD_ACC);
4866 elsiocb->iocb.ulpContext = oldiocb->iocb.ulpContext; /* Xri / rx_id */
4867 elsiocb->iocb.unsli3.rcvsli3.ox_id = oldiocb->iocb.unsli3.rcvsli3.ox_id;
4869 /* Xmit ECHO ACC response tag <ulpIoTag> */
4870 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4871 "2876 Xmit ECHO ACC response tag x%x xri x%x\n",
4872 elsiocb->iotag, elsiocb->iocb.ulpContext);
4873 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4874 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4875 pcmd += sizeof(uint32_t);
4876 memcpy(pcmd, data, cmdsize - sizeof(uint32_t));
4878 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4879 "Issue ACC ECHO: did:x%x flg:x%x",
4880 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4882 phba->fc_stat.elsXmitACC++;
4883 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4885 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4886 if (rc == IOCB_ERROR) {
4887 lpfc_els_free_iocb(phba, elsiocb);
4894 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
4895 * @vport: pointer to a host virtual N_Port data structure.
4897 * This routine issues Address Discover (ADISC) ELS commands to those
4898 * N_Ports which are in node port recovery state and ADISC has not been issued
4899 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
4900 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
4901 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
4902 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
4903 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
4904 * IOCBs quit for later pick up. On the other hand, after walking through
4905 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
4906 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
4907 * no more ADISC need to be sent.
4910 * The number of N_Ports with adisc issued.
4913 lpfc_els_disc_adisc(struct lpfc_vport *vport)
4915 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4916 struct lpfc_nodelist *ndlp, *next_ndlp;
4919 /* go thru NPR nodes and issue any remaining ELS ADISCs */
4920 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
4921 if (!NLP_CHK_NODE_ACT(ndlp))
4923 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
4924 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
4925 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
4926 spin_lock_irq(shost->host_lock);
4927 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
4928 spin_unlock_irq(shost->host_lock);
4929 ndlp->nlp_prev_state = ndlp->nlp_state;
4930 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
4931 lpfc_issue_els_adisc(vport, ndlp, 0);
4933 vport->num_disc_nodes++;
4934 if (vport->num_disc_nodes >=
4935 vport->cfg_discovery_threads) {
4936 spin_lock_irq(shost->host_lock);
4937 vport->fc_flag |= FC_NLP_MORE;
4938 spin_unlock_irq(shost->host_lock);
4943 if (sentadisc == 0) {
4944 spin_lock_irq(shost->host_lock);
4945 vport->fc_flag &= ~FC_NLP_MORE;
4946 spin_unlock_irq(shost->host_lock);
4952 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
4953 * @vport: pointer to a host virtual N_Port data structure.
4955 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
4956 * which are in node port recovery state, with a @vport. Each time an ELS
4957 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
4958 * the per @vport number of discover count (num_disc_nodes) shall be
4959 * incremented. If the num_disc_nodes reaches a pre-configured threshold
4960 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
4961 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
4962 * later pick up. On the other hand, after walking through all the ndlps with
4963 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
4964 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
4965 * PLOGI need to be sent.
4968 * The number of N_Ports with plogi issued.
4971 lpfc_els_disc_plogi(struct lpfc_vport *vport)
4973 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4974 struct lpfc_nodelist *ndlp, *next_ndlp;
4977 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
4978 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
4979 if (!NLP_CHK_NODE_ACT(ndlp))
4981 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
4982 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
4983 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
4984 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
4985 ndlp->nlp_prev_state = ndlp->nlp_state;
4986 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
4987 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
4989 vport->num_disc_nodes++;
4990 if (vport->num_disc_nodes >=
4991 vport->cfg_discovery_threads) {
4992 spin_lock_irq(shost->host_lock);
4993 vport->fc_flag |= FC_NLP_MORE;
4994 spin_unlock_irq(shost->host_lock);
5000 lpfc_set_disctmo(vport);
5003 spin_lock_irq(shost->host_lock);
5004 vport->fc_flag &= ~FC_NLP_MORE;
5005 spin_unlock_irq(shost->host_lock);
5011 lpfc_rdp_res_link_service(struct fc_rdp_link_service_desc *desc,
5015 desc->tag = cpu_to_be32(RDP_LINK_SERVICE_DESC_TAG);
5016 desc->payload.els_req = word0;
5017 desc->length = cpu_to_be32(sizeof(desc->payload));
5019 return sizeof(struct fc_rdp_link_service_desc);
5023 lpfc_rdp_res_sfp_desc(struct fc_rdp_sfp_desc *desc,
5024 uint8_t *page_a0, uint8_t *page_a2)
5026 uint16_t wavelength;
5027 uint16_t temperature;
5033 struct sff_trasnceiver_codes_byte4 *trasn_code_byte4;
5034 struct sff_trasnceiver_codes_byte5 *trasn_code_byte5;
5036 desc->tag = cpu_to_be32(RDP_SFP_DESC_TAG);
5038 trasn_code_byte4 = (struct sff_trasnceiver_codes_byte4 *)
5039 &page_a0[SSF_TRANSCEIVER_CODE_B4];
5040 trasn_code_byte5 = (struct sff_trasnceiver_codes_byte5 *)
5041 &page_a0[SSF_TRANSCEIVER_CODE_B5];
5043 if ((trasn_code_byte4->fc_sw_laser) ||
5044 (trasn_code_byte5->fc_sw_laser_sl) ||
5045 (trasn_code_byte5->fc_sw_laser_sn)) { /* check if its short WL */
5046 flag |= (SFP_FLAG_PT_SWLASER << SFP_FLAG_PT_SHIFT);
5047 } else if (trasn_code_byte4->fc_lw_laser) {
5048 wavelength = (page_a0[SSF_WAVELENGTH_B1] << 8) |
5049 page_a0[SSF_WAVELENGTH_B0];
5050 if (wavelength == SFP_WAVELENGTH_LC1310)
5051 flag |= SFP_FLAG_PT_LWLASER_LC1310 << SFP_FLAG_PT_SHIFT;
5052 if (wavelength == SFP_WAVELENGTH_LL1550)
5053 flag |= SFP_FLAG_PT_LWLASER_LL1550 << SFP_FLAG_PT_SHIFT;
5055 /* check if its SFP+ */
5056 flag |= ((page_a0[SSF_IDENTIFIER] == SFF_PG0_IDENT_SFP) ?
5057 SFP_FLAG_CT_SFP_PLUS : SFP_FLAG_CT_UNKNOWN)
5058 << SFP_FLAG_CT_SHIFT;
5060 /* check if its OPTICAL */
5061 flag |= ((page_a0[SSF_CONNECTOR] == SFF_PG0_CONNECTOR_LC) ?
5062 SFP_FLAG_IS_OPTICAL_PORT : 0)
5063 << SFP_FLAG_IS_OPTICAL_SHIFT;
5065 temperature = (page_a2[SFF_TEMPERATURE_B1] << 8 |
5066 page_a2[SFF_TEMPERATURE_B0]);
5067 vcc = (page_a2[SFF_VCC_B1] << 8 |
5068 page_a2[SFF_VCC_B0]);
5069 tx_power = (page_a2[SFF_TXPOWER_B1] << 8 |
5070 page_a2[SFF_TXPOWER_B0]);
5071 tx_bias = (page_a2[SFF_TX_BIAS_CURRENT_B1] << 8 |
5072 page_a2[SFF_TX_BIAS_CURRENT_B0]);
5073 rx_power = (page_a2[SFF_RXPOWER_B1] << 8 |
5074 page_a2[SFF_RXPOWER_B0]);
5075 desc->sfp_info.temperature = cpu_to_be16(temperature);
5076 desc->sfp_info.rx_power = cpu_to_be16(rx_power);
5077 desc->sfp_info.tx_bias = cpu_to_be16(tx_bias);
5078 desc->sfp_info.tx_power = cpu_to_be16(tx_power);
5079 desc->sfp_info.vcc = cpu_to_be16(vcc);
5081 desc->sfp_info.flags = cpu_to_be16(flag);
5082 desc->length = cpu_to_be32(sizeof(desc->sfp_info));
5084 return sizeof(struct fc_rdp_sfp_desc);
5088 lpfc_rdp_res_link_error(struct fc_rdp_link_error_status_desc *desc,
5093 desc->tag = cpu_to_be32(RDP_LINK_ERROR_STATUS_DESC_TAG);
5095 type = VN_PT_PHY_PF_PORT << VN_PT_PHY_SHIFT;
5097 desc->info.port_type = cpu_to_be32(type);
5099 desc->info.link_status.link_failure_cnt =
5100 cpu_to_be32(stat->linkFailureCnt);
5101 desc->info.link_status.loss_of_synch_cnt =
5102 cpu_to_be32(stat->lossSyncCnt);
5103 desc->info.link_status.loss_of_signal_cnt =
5104 cpu_to_be32(stat->lossSignalCnt);
5105 desc->info.link_status.primitive_seq_proto_err =
5106 cpu_to_be32(stat->primSeqErrCnt);
5107 desc->info.link_status.invalid_trans_word =
5108 cpu_to_be32(stat->invalidXmitWord);
5109 desc->info.link_status.invalid_crc_cnt = cpu_to_be32(stat->crcCnt);
5111 desc->length = cpu_to_be32(sizeof(desc->info));
5113 return sizeof(struct fc_rdp_link_error_status_desc);
5117 lpfc_rdp_res_bbc_desc(struct fc_rdp_bbc_desc *desc, READ_LNK_VAR *stat,
5118 struct lpfc_vport *vport)
5122 desc->tag = cpu_to_be32(RDP_BBC_DESC_TAG);
5124 bbCredit = vport->fc_sparam.cmn.bbCreditLsb |
5125 (vport->fc_sparam.cmn.bbCreditMsb << 8);
5126 desc->bbc_info.port_bbc = cpu_to_be32(bbCredit);
5127 if (vport->phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
5128 bbCredit = vport->phba->fc_fabparam.cmn.bbCreditLsb |
5129 (vport->phba->fc_fabparam.cmn.bbCreditMsb << 8);
5130 desc->bbc_info.attached_port_bbc = cpu_to_be32(bbCredit);
5132 desc->bbc_info.attached_port_bbc = 0;
5135 desc->bbc_info.rtt = 0;
5136 desc->length = cpu_to_be32(sizeof(desc->bbc_info));
5138 return sizeof(struct fc_rdp_bbc_desc);
5142 lpfc_rdp_res_oed_temp_desc(struct lpfc_hba *phba,
5143 struct fc_rdp_oed_sfp_desc *desc, uint8_t *page_a2)
5147 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5149 desc->oed_info.hi_alarm = page_a2[SSF_TEMP_HIGH_ALARM];
5150 desc->oed_info.lo_alarm = page_a2[SSF_TEMP_LOW_ALARM];
5151 desc->oed_info.hi_warning = page_a2[SSF_TEMP_HIGH_WARNING];
5152 desc->oed_info.lo_warning = page_a2[SSF_TEMP_LOW_WARNING];
5154 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TEMPERATURE)
5155 flags |= RDP_OET_HIGH_ALARM;
5156 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TEMPERATURE)
5157 flags |= RDP_OET_LOW_ALARM;
5158 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TEMPERATURE)
5159 flags |= RDP_OET_HIGH_WARNING;
5160 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TEMPERATURE)
5161 flags |= RDP_OET_LOW_WARNING;
5163 flags |= ((0xf & RDP_OED_TEMPERATURE) << RDP_OED_TYPE_SHIFT);
5164 desc->oed_info.function_flags = cpu_to_be32(flags);
5165 desc->length = cpu_to_be32(sizeof(desc->oed_info));
5166 return sizeof(struct fc_rdp_oed_sfp_desc);
5170 lpfc_rdp_res_oed_voltage_desc(struct lpfc_hba *phba,
5171 struct fc_rdp_oed_sfp_desc *desc,
5176 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5178 desc->oed_info.hi_alarm = page_a2[SSF_VOLTAGE_HIGH_ALARM];
5179 desc->oed_info.lo_alarm = page_a2[SSF_VOLTAGE_LOW_ALARM];
5180 desc->oed_info.hi_warning = page_a2[SSF_VOLTAGE_HIGH_WARNING];
5181 desc->oed_info.lo_warning = page_a2[SSF_VOLTAGE_LOW_WARNING];
5183 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_VOLTAGE)
5184 flags |= RDP_OET_HIGH_ALARM;
5185 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_VOLTAGE)
5186 flags |= RDP_OET_LOW_ALARM;
5187 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_VOLTAGE)
5188 flags |= RDP_OET_HIGH_WARNING;
5189 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_VOLTAGE)
5190 flags |= RDP_OET_LOW_WARNING;
5192 flags |= ((0xf & RDP_OED_VOLTAGE) << RDP_OED_TYPE_SHIFT);
5193 desc->oed_info.function_flags = cpu_to_be32(flags);
5194 desc->length = cpu_to_be32(sizeof(desc->oed_info));
5195 return sizeof(struct fc_rdp_oed_sfp_desc);
5199 lpfc_rdp_res_oed_txbias_desc(struct lpfc_hba *phba,
5200 struct fc_rdp_oed_sfp_desc *desc,
5205 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5207 desc->oed_info.hi_alarm = page_a2[SSF_BIAS_HIGH_ALARM];
5208 desc->oed_info.lo_alarm = page_a2[SSF_BIAS_LOW_ALARM];
5209 desc->oed_info.hi_warning = page_a2[SSF_BIAS_HIGH_WARNING];
5210 desc->oed_info.lo_warning = page_a2[SSF_BIAS_LOW_WARNING];
5212 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TXBIAS)
5213 flags |= RDP_OET_HIGH_ALARM;
5214 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TXBIAS)
5215 flags |= RDP_OET_LOW_ALARM;
5216 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TXBIAS)
5217 flags |= RDP_OET_HIGH_WARNING;
5218 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TXBIAS)
5219 flags |= RDP_OET_LOW_WARNING;
5221 flags |= ((0xf & RDP_OED_TXBIAS) << RDP_OED_TYPE_SHIFT);
5222 desc->oed_info.function_flags = cpu_to_be32(flags);
5223 desc->length = cpu_to_be32(sizeof(desc->oed_info));
5224 return sizeof(struct fc_rdp_oed_sfp_desc);
5228 lpfc_rdp_res_oed_txpower_desc(struct lpfc_hba *phba,
5229 struct fc_rdp_oed_sfp_desc *desc,
5234 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5236 desc->oed_info.hi_alarm = page_a2[SSF_TXPOWER_HIGH_ALARM];
5237 desc->oed_info.lo_alarm = page_a2[SSF_TXPOWER_LOW_ALARM];
5238 desc->oed_info.hi_warning = page_a2[SSF_TXPOWER_HIGH_WARNING];
5239 desc->oed_info.lo_warning = page_a2[SSF_TXPOWER_LOW_WARNING];
5241 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TXPOWER)
5242 flags |= RDP_OET_HIGH_ALARM;
5243 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TXPOWER)
5244 flags |= RDP_OET_LOW_ALARM;
5245 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TXPOWER)
5246 flags |= RDP_OET_HIGH_WARNING;
5247 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TXPOWER)
5248 flags |= RDP_OET_LOW_WARNING;
5250 flags |= ((0xf & RDP_OED_TXPOWER) << RDP_OED_TYPE_SHIFT);
5251 desc->oed_info.function_flags = cpu_to_be32(flags);
5252 desc->length = cpu_to_be32(sizeof(desc->oed_info));
5253 return sizeof(struct fc_rdp_oed_sfp_desc);
5258 lpfc_rdp_res_oed_rxpower_desc(struct lpfc_hba *phba,
5259 struct fc_rdp_oed_sfp_desc *desc,
5264 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5266 desc->oed_info.hi_alarm = page_a2[SSF_RXPOWER_HIGH_ALARM];
5267 desc->oed_info.lo_alarm = page_a2[SSF_RXPOWER_LOW_ALARM];
5268 desc->oed_info.hi_warning = page_a2[SSF_RXPOWER_HIGH_WARNING];
5269 desc->oed_info.lo_warning = page_a2[SSF_RXPOWER_LOW_WARNING];
5271 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_RXPOWER)
5272 flags |= RDP_OET_HIGH_ALARM;
5273 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_RXPOWER)
5274 flags |= RDP_OET_LOW_ALARM;
5275 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_RXPOWER)
5276 flags |= RDP_OET_HIGH_WARNING;
5277 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_RXPOWER)
5278 flags |= RDP_OET_LOW_WARNING;
5280 flags |= ((0xf & RDP_OED_RXPOWER) << RDP_OED_TYPE_SHIFT);
5281 desc->oed_info.function_flags = cpu_to_be32(flags);
5282 desc->length = cpu_to_be32(sizeof(desc->oed_info));
5283 return sizeof(struct fc_rdp_oed_sfp_desc);
5287 lpfc_rdp_res_opd_desc(struct fc_rdp_opd_sfp_desc *desc,
5288 uint8_t *page_a0, struct lpfc_vport *vport)
5290 desc->tag = cpu_to_be32(RDP_OPD_DESC_TAG);
5291 memcpy(desc->opd_info.vendor_name, &page_a0[SSF_VENDOR_NAME], 16);
5292 memcpy(desc->opd_info.model_number, &page_a0[SSF_VENDOR_PN], 16);
5293 memcpy(desc->opd_info.serial_number, &page_a0[SSF_VENDOR_SN], 16);
5294 memcpy(desc->opd_info.revision, &page_a0[SSF_VENDOR_REV], 4);
5295 memcpy(desc->opd_info.date, &page_a0[SSF_DATE_CODE], 8);
5296 desc->length = cpu_to_be32(sizeof(desc->opd_info));
5297 return sizeof(struct fc_rdp_opd_sfp_desc);
5301 lpfc_rdp_res_fec_desc(struct fc_fec_rdp_desc *desc, READ_LNK_VAR *stat)
5303 if (bf_get(lpfc_read_link_stat_gec2, stat) == 0)
5305 desc->tag = cpu_to_be32(RDP_FEC_DESC_TAG);
5307 desc->info.CorrectedBlocks =
5308 cpu_to_be32(stat->fecCorrBlkCount);
5309 desc->info.UncorrectableBlocks =
5310 cpu_to_be32(stat->fecUncorrBlkCount);
5312 desc->length = cpu_to_be32(sizeof(desc->info));
5314 return sizeof(struct fc_fec_rdp_desc);
5318 lpfc_rdp_res_speed(struct fc_rdp_port_speed_desc *desc, struct lpfc_hba *phba)
5320 uint16_t rdp_cap = 0;
5323 desc->tag = cpu_to_be32(RDP_PORT_SPEED_DESC_TAG);
5325 switch (phba->fc_linkspeed) {
5326 case LPFC_LINK_SPEED_1GHZ:
5327 rdp_speed = RDP_PS_1GB;
5329 case LPFC_LINK_SPEED_2GHZ:
5330 rdp_speed = RDP_PS_2GB;
5332 case LPFC_LINK_SPEED_4GHZ:
5333 rdp_speed = RDP_PS_4GB;
5335 case LPFC_LINK_SPEED_8GHZ:
5336 rdp_speed = RDP_PS_8GB;
5338 case LPFC_LINK_SPEED_10GHZ:
5339 rdp_speed = RDP_PS_10GB;
5341 case LPFC_LINK_SPEED_16GHZ:
5342 rdp_speed = RDP_PS_16GB;
5344 case LPFC_LINK_SPEED_32GHZ:
5345 rdp_speed = RDP_PS_32GB;
5347 case LPFC_LINK_SPEED_64GHZ:
5348 rdp_speed = RDP_PS_64GB;
5351 rdp_speed = RDP_PS_UNKNOWN;
5355 desc->info.port_speed.speed = cpu_to_be16(rdp_speed);
5357 if (phba->lmt & LMT_64Gb)
5358 rdp_cap |= RDP_PS_64GB;
5359 if (phba->lmt & LMT_32Gb)
5360 rdp_cap |= RDP_PS_32GB;
5361 if (phba->lmt & LMT_16Gb)
5362 rdp_cap |= RDP_PS_16GB;
5363 if (phba->lmt & LMT_10Gb)
5364 rdp_cap |= RDP_PS_10GB;
5365 if (phba->lmt & LMT_8Gb)
5366 rdp_cap |= RDP_PS_8GB;
5367 if (phba->lmt & LMT_4Gb)
5368 rdp_cap |= RDP_PS_4GB;
5369 if (phba->lmt & LMT_2Gb)
5370 rdp_cap |= RDP_PS_2GB;
5371 if (phba->lmt & LMT_1Gb)
5372 rdp_cap |= RDP_PS_1GB;
5375 rdp_cap = RDP_CAP_UNKNOWN;
5376 if (phba->cfg_link_speed != LPFC_USER_LINK_SPEED_AUTO)
5377 rdp_cap |= RDP_CAP_USER_CONFIGURED;
5379 desc->info.port_speed.capabilities = cpu_to_be16(rdp_cap);
5380 desc->length = cpu_to_be32(sizeof(desc->info));
5381 return sizeof(struct fc_rdp_port_speed_desc);
5385 lpfc_rdp_res_diag_port_names(struct fc_rdp_port_name_desc *desc,
5386 struct lpfc_vport *vport)
5389 desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG);
5391 memcpy(desc->port_names.wwnn, &vport->fc_nodename,
5392 sizeof(desc->port_names.wwnn));
5394 memcpy(desc->port_names.wwpn, &vport->fc_portname,
5395 sizeof(desc->port_names.wwpn));
5397 desc->length = cpu_to_be32(sizeof(desc->port_names));
5398 return sizeof(struct fc_rdp_port_name_desc);
5402 lpfc_rdp_res_attach_port_names(struct fc_rdp_port_name_desc *desc,
5403 struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
5406 desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG);
5407 if (vport->fc_flag & FC_FABRIC) {
5408 memcpy(desc->port_names.wwnn, &vport->fabric_nodename,
5409 sizeof(desc->port_names.wwnn));
5411 memcpy(desc->port_names.wwpn, &vport->fabric_portname,
5412 sizeof(desc->port_names.wwpn));
5413 } else { /* Point to Point */
5414 memcpy(desc->port_names.wwnn, &ndlp->nlp_nodename,
5415 sizeof(desc->port_names.wwnn));
5417 memcpy(desc->port_names.wwnn, &ndlp->nlp_portname,
5418 sizeof(desc->port_names.wwpn));
5421 desc->length = cpu_to_be32(sizeof(desc->port_names));
5422 return sizeof(struct fc_rdp_port_name_desc);
5426 lpfc_els_rdp_cmpl(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context,
5429 struct lpfc_nodelist *ndlp = rdp_context->ndlp;
5430 struct lpfc_vport *vport = ndlp->vport;
5431 struct lpfc_iocbq *elsiocb;
5432 struct ulp_bde64 *bpl;
5435 struct ls_rjt *stat;
5436 struct fc_rdp_res_frame *rdp_res;
5437 uint32_t cmdsize, len;
5441 if (status != SUCCESS)
5444 /* This will change once we know the true size of the RDP payload */
5445 cmdsize = sizeof(struct fc_rdp_res_frame);
5447 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize,
5448 lpfc_max_els_tries, rdp_context->ndlp,
5449 rdp_context->ndlp->nlp_DID, ELS_CMD_ACC);
5452 goto free_rdp_context;
5454 icmd = &elsiocb->iocb;
5455 icmd->ulpContext = rdp_context->rx_id;
5456 icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id;
5458 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5459 "2171 Xmit RDP response tag x%x xri x%x, "
5460 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x",
5461 elsiocb->iotag, elsiocb->iocb.ulpContext,
5462 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5464 rdp_res = (struct fc_rdp_res_frame *)
5465 (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5466 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5467 memset(pcmd, 0, sizeof(struct fc_rdp_res_frame));
5468 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5470 /* Update Alarm and Warning */
5471 flag_ptr = (uint16_t *)(rdp_context->page_a2 + SSF_ALARM_FLAGS);
5472 phba->sfp_alarm |= *flag_ptr;
5473 flag_ptr = (uint16_t *)(rdp_context->page_a2 + SSF_WARNING_FLAGS);
5474 phba->sfp_warning |= *flag_ptr;
5476 /* For RDP payload */
5478 len += lpfc_rdp_res_link_service((struct fc_rdp_link_service_desc *)
5479 (len + pcmd), ELS_CMD_RDP);
5481 len += lpfc_rdp_res_sfp_desc((struct fc_rdp_sfp_desc *)(len + pcmd),
5482 rdp_context->page_a0, rdp_context->page_a2);
5483 len += lpfc_rdp_res_speed((struct fc_rdp_port_speed_desc *)(len + pcmd),
5485 len += lpfc_rdp_res_link_error((struct fc_rdp_link_error_status_desc *)
5486 (len + pcmd), &rdp_context->link_stat);
5487 len += lpfc_rdp_res_diag_port_names((struct fc_rdp_port_name_desc *)
5488 (len + pcmd), vport);
5489 len += lpfc_rdp_res_attach_port_names((struct fc_rdp_port_name_desc *)
5490 (len + pcmd), vport, ndlp);
5491 len += lpfc_rdp_res_fec_desc((struct fc_fec_rdp_desc *)(len + pcmd),
5492 &rdp_context->link_stat);
5493 len += lpfc_rdp_res_bbc_desc((struct fc_rdp_bbc_desc *)(len + pcmd),
5494 &rdp_context->link_stat, vport);
5495 len += lpfc_rdp_res_oed_temp_desc(phba,
5496 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5497 rdp_context->page_a2);
5498 len += lpfc_rdp_res_oed_voltage_desc(phba,
5499 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5500 rdp_context->page_a2);
5501 len += lpfc_rdp_res_oed_txbias_desc(phba,
5502 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5503 rdp_context->page_a2);
5504 len += lpfc_rdp_res_oed_txpower_desc(phba,
5505 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5506 rdp_context->page_a2);
5507 len += lpfc_rdp_res_oed_rxpower_desc(phba,
5508 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5509 rdp_context->page_a2);
5510 len += lpfc_rdp_res_opd_desc((struct fc_rdp_opd_sfp_desc *)(len + pcmd),
5511 rdp_context->page_a0, vport);
5513 rdp_res->length = cpu_to_be32(len - 8);
5514 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5516 /* Now that we know the true size of the payload, update the BPL */
5517 bpl = (struct ulp_bde64 *)
5518 (((struct lpfc_dmabuf *)(elsiocb->context3))->virt);
5519 bpl->tus.f.bdeSize = len;
5520 bpl->tus.f.bdeFlags = 0;
5521 bpl->tus.w = le32_to_cpu(bpl->tus.w);
5523 phba->fc_stat.elsXmitACC++;
5524 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5525 if (rc == IOCB_ERROR)
5526 lpfc_els_free_iocb(phba, elsiocb);
5532 cmdsize = 2 * sizeof(uint32_t);
5533 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, lpfc_max_els_tries,
5534 ndlp, ndlp->nlp_DID, ELS_CMD_LS_RJT);
5537 goto free_rdp_context;
5539 icmd = &elsiocb->iocb;
5540 icmd->ulpContext = rdp_context->rx_id;
5541 icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id;
5542 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5544 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
5545 stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t));
5546 stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5548 phba->fc_stat.elsXmitLSRJT++;
5549 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5550 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5552 if (rc == IOCB_ERROR)
5553 lpfc_els_free_iocb(phba, elsiocb);
5559 lpfc_get_rdp_info(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context)
5561 LPFC_MBOXQ_t *mbox = NULL;
5564 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5566 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_ELS,
5567 "7105 failed to allocate mailbox memory");
5571 if (lpfc_sli4_dump_page_a0(phba, mbox))
5572 goto prep_mbox_fail;
5573 mbox->vport = rdp_context->ndlp->vport;
5574 mbox->mbox_cmpl = lpfc_mbx_cmpl_rdp_page_a0;
5575 mbox->context2 = (struct lpfc_rdp_context *) rdp_context;
5576 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
5577 if (rc == MBX_NOT_FINISHED)
5578 goto issue_mbox_fail;
5584 mempool_free(mbox, phba->mbox_mem_pool);
5589 * lpfc_els_rcv_rdp - Process an unsolicited RDP ELS.
5590 * @vport: pointer to a host virtual N_Port data structure.
5591 * @cmdiocb: pointer to lpfc command iocb data structure.
5592 * @ndlp: pointer to a node-list data structure.
5594 * This routine processes an unsolicited RDP(Read Diagnostic Parameters)
5595 * IOCB. First, the payload of the unsolicited RDP is checked.
5596 * Then it will (1) send MBX_DUMP_MEMORY, Embedded DMP_LMSD sub command TYPE-3
5597 * for Page A0, (2) send MBX_DUMP_MEMORY, DMP_LMSD for Page A2,
5598 * (3) send MBX_READ_LNK_STAT to get link stat, (4) Call lpfc_els_rdp_cmpl
5599 * gather all data and send RDP response.
5602 * 0 - Sent the acc response
5603 * 1 - Sent the reject response.
5606 lpfc_els_rcv_rdp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5607 struct lpfc_nodelist *ndlp)
5609 struct lpfc_hba *phba = vport->phba;
5610 struct lpfc_dmabuf *pcmd;
5611 uint8_t rjt_err, rjt_expl = LSEXP_NOTHING_MORE;
5612 struct fc_rdp_req_frame *rdp_req;
5613 struct lpfc_rdp_context *rdp_context;
5617 if (phba->sli_rev < LPFC_SLI_REV4 ||
5618 bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
5619 LPFC_SLI_INTF_IF_TYPE_2) {
5620 rjt_err = LSRJT_UNABLE_TPC;
5621 rjt_expl = LSEXP_REQ_UNSUPPORTED;
5625 if (phba->sli_rev < LPFC_SLI_REV4 || (phba->hba_flag & HBA_FCOE_MODE)) {
5626 rjt_err = LSRJT_UNABLE_TPC;
5627 rjt_expl = LSEXP_REQ_UNSUPPORTED;
5631 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5632 rdp_req = (struct fc_rdp_req_frame *) pcmd->virt;
5634 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5635 "2422 ELS RDP Request "
5636 "dec len %d tag x%x port_id %d len %d\n",
5637 be32_to_cpu(rdp_req->rdp_des_length),
5638 be32_to_cpu(rdp_req->nport_id_desc.tag),
5639 be32_to_cpu(rdp_req->nport_id_desc.nport_id),
5640 be32_to_cpu(rdp_req->nport_id_desc.length));
5642 if (sizeof(struct fc_rdp_nport_desc) !=
5643 be32_to_cpu(rdp_req->rdp_des_length))
5645 if (RDP_N_PORT_DESC_TAG != be32_to_cpu(rdp_req->nport_id_desc.tag))
5647 if (RDP_NPORT_ID_SIZE !=
5648 be32_to_cpu(rdp_req->nport_id_desc.length))
5650 rdp_context = kzalloc(sizeof(struct lpfc_rdp_context), GFP_KERNEL);
5652 rjt_err = LSRJT_UNABLE_TPC;
5656 cmd = &cmdiocb->iocb;
5657 rdp_context->ndlp = lpfc_nlp_get(ndlp);
5658 rdp_context->ox_id = cmd->unsli3.rcvsli3.ox_id;
5659 rdp_context->rx_id = cmd->ulpContext;
5660 rdp_context->cmpl = lpfc_els_rdp_cmpl;
5661 if (lpfc_get_rdp_info(phba, rdp_context)) {
5662 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_ELS,
5663 "2423 Unable to send mailbox");
5665 rjt_err = LSRJT_UNABLE_TPC;
5673 rjt_err = LSRJT_LOGICAL_ERR;
5676 memset(&stat, 0, sizeof(stat));
5677 stat.un.b.lsRjtRsnCode = rjt_err;
5678 stat.un.b.lsRjtRsnCodeExp = rjt_expl;
5679 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5685 lpfc_els_lcb_rsp(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
5690 struct lpfc_iocbq *elsiocb;
5691 struct lpfc_nodelist *ndlp;
5692 struct ls_rjt *stat;
5693 union lpfc_sli4_cfg_shdr *shdr;
5694 struct lpfc_lcb_context *lcb_context;
5695 struct fc_lcb_res_frame *lcb_res;
5696 uint32_t cmdsize, shdr_status, shdr_add_status;
5700 lcb_context = (struct lpfc_lcb_context *)pmb->context1;
5701 ndlp = lcb_context->ndlp;
5702 pmb->context1 = NULL;
5703 pmb->context2 = NULL;
5705 shdr = (union lpfc_sli4_cfg_shdr *)
5706 &pmb->u.mqe.un.beacon_config.header.cfg_shdr;
5707 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
5708 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
5710 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX,
5711 "0194 SET_BEACON_CONFIG mailbox "
5712 "completed with status x%x add_status x%x,"
5713 " mbx status x%x\n",
5714 shdr_status, shdr_add_status, mb->mbxStatus);
5716 if ((mb->mbxStatus != MBX_SUCCESS) || shdr_status ||
5717 (shdr_add_status == ADD_STATUS_OPERATION_ALREADY_ACTIVE) ||
5718 (shdr_add_status == ADD_STATUS_INVALID_REQUEST)) {
5719 mempool_free(pmb, phba->mbox_mem_pool);
5723 mempool_free(pmb, phba->mbox_mem_pool);
5724 cmdsize = sizeof(struct fc_lcb_res_frame);
5725 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5726 lpfc_max_els_tries, ndlp,
5727 ndlp->nlp_DID, ELS_CMD_ACC);
5729 /* Decrement the ndlp reference count from previous mbox command */
5733 goto free_lcb_context;
5735 lcb_res = (struct fc_lcb_res_frame *)
5736 (((struct lpfc_dmabuf *)elsiocb->context2)->virt);
5738 memset(lcb_res, 0, sizeof(struct fc_lcb_res_frame));
5739 icmd = &elsiocb->iocb;
5740 icmd->ulpContext = lcb_context->rx_id;
5741 icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id;
5743 pcmd = (uint8_t *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt);
5744 *((uint32_t *)(pcmd)) = ELS_CMD_ACC;
5745 lcb_res->lcb_sub_command = lcb_context->sub_command;
5746 lcb_res->lcb_type = lcb_context->type;
5747 lcb_res->capability = lcb_context->capability;
5748 lcb_res->lcb_frequency = lcb_context->frequency;
5749 lcb_res->lcb_duration = lcb_context->duration;
5750 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5751 phba->fc_stat.elsXmitACC++;
5752 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5753 if (rc == IOCB_ERROR)
5754 lpfc_els_free_iocb(phba, elsiocb);
5760 cmdsize = sizeof(struct fc_lcb_res_frame);
5761 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5762 lpfc_max_els_tries, ndlp,
5763 ndlp->nlp_DID, ELS_CMD_LS_RJT);
5766 goto free_lcb_context;
5768 icmd = &elsiocb->iocb;
5769 icmd->ulpContext = lcb_context->rx_id;
5770 icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id;
5771 pcmd = (uint8_t *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt);
5773 *((uint32_t *)(pcmd)) = ELS_CMD_LS_RJT;
5774 stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t));
5775 stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5777 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5778 phba->fc_stat.elsXmitLSRJT++;
5779 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5780 if (rc == IOCB_ERROR)
5781 lpfc_els_free_iocb(phba, elsiocb);
5787 lpfc_sli4_set_beacon(struct lpfc_vport *vport,
5788 struct lpfc_lcb_context *lcb_context,
5789 uint32_t beacon_state)
5791 struct lpfc_hba *phba = vport->phba;
5792 union lpfc_sli4_cfg_shdr *cfg_shdr;
5793 LPFC_MBOXQ_t *mbox = NULL;
5797 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5801 cfg_shdr = &mbox->u.mqe.un.sli4_config.header.cfg_shdr;
5802 len = sizeof(struct lpfc_mbx_set_beacon_config) -
5803 sizeof(struct lpfc_sli4_cfg_mhdr);
5804 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
5805 LPFC_MBOX_OPCODE_SET_BEACON_CONFIG, len,
5806 LPFC_SLI4_MBX_EMBED);
5807 mbox->context1 = (void *)lcb_context;
5808 mbox->vport = phba->pport;
5809 mbox->mbox_cmpl = lpfc_els_lcb_rsp;
5810 bf_set(lpfc_mbx_set_beacon_port_num, &mbox->u.mqe.un.beacon_config,
5811 phba->sli4_hba.physical_port);
5812 bf_set(lpfc_mbx_set_beacon_state, &mbox->u.mqe.un.beacon_config,
5814 mbox->u.mqe.un.beacon_config.word5 = 0; /* Reserved */
5817 * Check bv1s bit before issuing the mailbox
5818 * if bv1s == 1, LCB V1 supported
5819 * else, LCB V0 supported
5822 if (phba->sli4_hba.pc_sli4_params.bv1s) {
5823 /* COMMON_SET_BEACON_CONFIG_V1 */
5824 cfg_shdr->request.word9 = BEACON_VERSION_V1;
5825 lcb_context->capability |= LCB_CAPABILITY_DURATION;
5826 bf_set(lpfc_mbx_set_beacon_port_type,
5827 &mbox->u.mqe.un.beacon_config, 0);
5828 bf_set(lpfc_mbx_set_beacon_duration_v1,
5829 &mbox->u.mqe.un.beacon_config,
5830 be16_to_cpu(lcb_context->duration));
5832 /* COMMON_SET_BEACON_CONFIG_V0 */
5833 if (be16_to_cpu(lcb_context->duration) != 0) {
5834 mempool_free(mbox, phba->mbox_mem_pool);
5837 cfg_shdr->request.word9 = BEACON_VERSION_V0;
5838 lcb_context->capability &= ~(LCB_CAPABILITY_DURATION);
5839 bf_set(lpfc_mbx_set_beacon_state,
5840 &mbox->u.mqe.un.beacon_config, beacon_state);
5841 bf_set(lpfc_mbx_set_beacon_port_type,
5842 &mbox->u.mqe.un.beacon_config, 1);
5843 bf_set(lpfc_mbx_set_beacon_duration,
5844 &mbox->u.mqe.un.beacon_config,
5845 be16_to_cpu(lcb_context->duration));
5848 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
5849 if (rc == MBX_NOT_FINISHED) {
5850 mempool_free(mbox, phba->mbox_mem_pool);
5859 * lpfc_els_rcv_lcb - Process an unsolicited LCB
5860 * @vport: pointer to a host virtual N_Port data structure.
5861 * @cmdiocb: pointer to lpfc command iocb data structure.
5862 * @ndlp: pointer to a node-list data structure.
5864 * This routine processes an unsolicited LCB(LINK CABLE BEACON) IOCB.
5865 * First, the payload of the unsolicited LCB is checked.
5866 * Then based on Subcommand beacon will either turn on or off.
5869 * 0 - Sent the acc response
5870 * 1 - Sent the reject response.
5873 lpfc_els_rcv_lcb(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5874 struct lpfc_nodelist *ndlp)
5876 struct lpfc_hba *phba = vport->phba;
5877 struct lpfc_dmabuf *pcmd;
5879 struct fc_lcb_request_frame *beacon;
5880 struct lpfc_lcb_context *lcb_context;
5881 uint8_t state, rjt_err;
5884 pcmd = (struct lpfc_dmabuf *)cmdiocb->context2;
5885 lp = (uint8_t *)pcmd->virt;
5886 beacon = (struct fc_lcb_request_frame *)pcmd->virt;
5888 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5889 "0192 ELS LCB Data x%x x%x x%x x%x sub x%x "
5890 "type x%x frequency %x duration x%x\n",
5891 lp[0], lp[1], lp[2],
5892 beacon->lcb_command,
5893 beacon->lcb_sub_command,
5895 beacon->lcb_frequency,
5896 be16_to_cpu(beacon->lcb_duration));
5898 if (beacon->lcb_sub_command != LPFC_LCB_ON &&
5899 beacon->lcb_sub_command != LPFC_LCB_OFF) {
5900 rjt_err = LSRJT_CMD_UNSUPPORTED;
5904 if (phba->sli_rev < LPFC_SLI_REV4 ||
5905 phba->hba_flag & HBA_FCOE_MODE ||
5906 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
5907 LPFC_SLI_INTF_IF_TYPE_2)) {
5908 rjt_err = LSRJT_CMD_UNSUPPORTED;
5912 lcb_context = kmalloc(sizeof(*lcb_context), GFP_KERNEL);
5914 rjt_err = LSRJT_UNABLE_TPC;
5918 state = (beacon->lcb_sub_command == LPFC_LCB_ON) ? 1 : 0;
5919 lcb_context->sub_command = beacon->lcb_sub_command;
5920 lcb_context->capability = 0;
5921 lcb_context->type = beacon->lcb_type;
5922 lcb_context->frequency = beacon->lcb_frequency;
5923 lcb_context->duration = beacon->lcb_duration;
5924 lcb_context->ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id;
5925 lcb_context->rx_id = cmdiocb->iocb.ulpContext;
5926 lcb_context->ndlp = lpfc_nlp_get(ndlp);
5927 if (lpfc_sli4_set_beacon(vport, lcb_context, state)) {
5928 lpfc_printf_vlog(ndlp->vport, KERN_ERR,
5929 LOG_ELS, "0193 failed to send mail box");
5932 rjt_err = LSRJT_UNABLE_TPC;
5937 memset(&stat, 0, sizeof(stat));
5938 stat.un.b.lsRjtRsnCode = rjt_err;
5939 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5945 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
5946 * @vport: pointer to a host virtual N_Port data structure.
5948 * This routine cleans up any Registration State Change Notification
5949 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
5950 * @vport together with the host_lock is used to prevent multiple thread
5951 * trying to access the RSCN array on a same @vport at the same time.
5954 lpfc_els_flush_rscn(struct lpfc_vport *vport)
5956 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5957 struct lpfc_hba *phba = vport->phba;
5960 spin_lock_irq(shost->host_lock);
5961 if (vport->fc_rscn_flush) {
5962 /* Another thread is walking fc_rscn_id_list on this vport */
5963 spin_unlock_irq(shost->host_lock);
5966 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
5967 vport->fc_rscn_flush = 1;
5968 spin_unlock_irq(shost->host_lock);
5970 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
5971 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
5972 vport->fc_rscn_id_list[i] = NULL;
5974 spin_lock_irq(shost->host_lock);
5975 vport->fc_rscn_id_cnt = 0;
5976 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
5977 spin_unlock_irq(shost->host_lock);
5978 lpfc_can_disctmo(vport);
5979 /* Indicate we are done walking this fc_rscn_id_list */
5980 vport->fc_rscn_flush = 0;
5984 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
5985 * @vport: pointer to a host virtual N_Port data structure.
5986 * @did: remote destination port identifier.
5988 * This routine checks whether there is any pending Registration State
5989 * Configuration Notification (RSCN) to a @did on @vport.
5992 * None zero - The @did matched with a pending rscn
5993 * 0 - not able to match @did with a pending rscn
5996 lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
6001 uint32_t payload_len, i;
6002 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6004 ns_did.un.word = did;
6006 /* Never match fabric nodes for RSCNs */
6007 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
6010 /* If we are doing a FULL RSCN rediscovery, match everything */
6011 if (vport->fc_flag & FC_RSCN_DISCOVERY)
6014 spin_lock_irq(shost->host_lock);
6015 if (vport->fc_rscn_flush) {
6016 /* Another thread is walking fc_rscn_id_list on this vport */
6017 spin_unlock_irq(shost->host_lock);
6020 /* Indicate we are walking fc_rscn_id_list on this vport */
6021 vport->fc_rscn_flush = 1;
6022 spin_unlock_irq(shost->host_lock);
6023 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
6024 lp = vport->fc_rscn_id_list[i]->virt;
6025 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
6026 payload_len -= sizeof(uint32_t); /* take off word 0 */
6027 while (payload_len) {
6028 rscn_did.un.word = be32_to_cpu(*lp++);
6029 payload_len -= sizeof(uint32_t);
6030 switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) {
6031 case RSCN_ADDRESS_FORMAT_PORT:
6032 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
6033 && (ns_did.un.b.area == rscn_did.un.b.area)
6034 && (ns_did.un.b.id == rscn_did.un.b.id))
6035 goto return_did_out;
6037 case RSCN_ADDRESS_FORMAT_AREA:
6038 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
6039 && (ns_did.un.b.area == rscn_did.un.b.area))
6040 goto return_did_out;
6042 case RSCN_ADDRESS_FORMAT_DOMAIN:
6043 if (ns_did.un.b.domain == rscn_did.un.b.domain)
6044 goto return_did_out;
6046 case RSCN_ADDRESS_FORMAT_FABRIC:
6047 goto return_did_out;
6051 /* Indicate we are done with walking fc_rscn_id_list on this vport */
6052 vport->fc_rscn_flush = 0;
6055 /* Indicate we are done with walking fc_rscn_id_list on this vport */
6056 vport->fc_rscn_flush = 0;
6061 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
6062 * @vport: pointer to a host virtual N_Port data structure.
6064 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
6065 * state machine for a @vport's nodes that are with pending RSCN (Registration
6066 * State Change Notification).
6069 * 0 - Successful (currently alway return 0)
6072 lpfc_rscn_recovery_check(struct lpfc_vport *vport)
6074 struct lpfc_nodelist *ndlp = NULL;
6076 /* Move all affected nodes by pending RSCNs to NPR state. */
6077 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
6078 if (!NLP_CHK_NODE_ACT(ndlp) ||
6079 (ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
6080 !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
6083 /* NVME Target mode does not do RSCN Recovery. */
6084 if (vport->phba->nvmet_support)
6087 lpfc_disc_state_machine(vport, ndlp, NULL,
6088 NLP_EVT_DEVICE_RECOVERY);
6089 lpfc_cancel_retry_delay_tmo(vport, ndlp);
6095 * lpfc_send_rscn_event - Send an RSCN event to management application
6096 * @vport: pointer to a host virtual N_Port data structure.
6097 * @cmdiocb: pointer to lpfc command iocb data structure.
6099 * lpfc_send_rscn_event sends an RSCN netlink event to management
6103 lpfc_send_rscn_event(struct lpfc_vport *vport,
6104 struct lpfc_iocbq *cmdiocb)
6106 struct lpfc_dmabuf *pcmd;
6107 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6108 uint32_t *payload_ptr;
6109 uint32_t payload_len;
6110 struct lpfc_rscn_event_header *rscn_event_data;
6112 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6113 payload_ptr = (uint32_t *) pcmd->virt;
6114 payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK);
6116 rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) +
6117 payload_len, GFP_KERNEL);
6118 if (!rscn_event_data) {
6119 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6120 "0147 Failed to allocate memory for RSCN event\n");
6123 rscn_event_data->event_type = FC_REG_RSCN_EVENT;
6124 rscn_event_data->payload_length = payload_len;
6125 memcpy(rscn_event_data->rscn_payload, payload_ptr,
6128 fc_host_post_vendor_event(shost,
6129 fc_get_event_number(),
6130 sizeof(struct lpfc_rscn_event_header) + payload_len,
6131 (char *)rscn_event_data,
6134 kfree(rscn_event_data);
6138 * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
6139 * @vport: pointer to a host virtual N_Port data structure.
6140 * @cmdiocb: pointer to lpfc command iocb data structure.
6141 * @ndlp: pointer to a node-list data structure.
6143 * This routine processes an unsolicited RSCN (Registration State Change
6144 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
6145 * to invoke fc_host_post_event() routine to the FC transport layer. If the
6146 * discover state machine is about to begin discovery, it just accepts the
6147 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
6148 * contains N_Port IDs for other vports on this HBA, it just accepts the
6149 * RSCN and ignore processing it. If the state machine is in the recovery
6150 * state, the fc_rscn_id_list of this @vport is walked and the
6151 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
6152 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
6153 * routine is invoked to handle the RSCN event.
6156 * 0 - Just sent the acc response
6157 * 1 - Sent the acc response and waited for name server completion
6160 lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6161 struct lpfc_nodelist *ndlp)
6163 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6164 struct lpfc_hba *phba = vport->phba;
6165 struct lpfc_dmabuf *pcmd;
6166 uint32_t *lp, *datap;
6167 uint32_t payload_len, length, nportid, *cmd;
6169 int rscn_id = 0, hba_id = 0;
6172 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6173 lp = (uint32_t *) pcmd->virt;
6175 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
6176 payload_len -= sizeof(uint32_t); /* take off word 0 */
6178 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6179 "0214 RSCN received Data: x%x x%x x%x x%x\n",
6180 vport->fc_flag, payload_len, *lp,
6181 vport->fc_rscn_id_cnt);
6183 /* Send an RSCN event to the management application */
6184 lpfc_send_rscn_event(vport, cmdiocb);
6186 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
6187 fc_host_post_event(shost, fc_get_event_number(),
6188 FCH_EVT_RSCN, lp[i]);
6190 /* If we are about to begin discovery, just ACC the RSCN.
6191 * Discovery processing will satisfy it.
6193 if (vport->port_state <= LPFC_NS_QRY) {
6194 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6195 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
6196 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
6198 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
6202 /* If this RSCN just contains NPortIDs for other vports on this HBA,
6203 * just ACC and ignore it.
6205 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
6206 !(vport->cfg_peer_port_login)) {
6211 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
6212 i -= sizeof(uint32_t);
6214 if (lpfc_find_vport_by_did(phba, nportid))
6217 if (rscn_id == hba_id) {
6218 /* ALL NPortIDs in RSCN are on HBA */
6219 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6221 "Data: x%x x%x x%x x%x\n",
6222 vport->fc_flag, payload_len,
6223 *lp, vport->fc_rscn_id_cnt);
6224 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6225 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
6226 ndlp->nlp_DID, vport->port_state,
6229 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
6235 spin_lock_irq(shost->host_lock);
6236 if (vport->fc_rscn_flush) {
6237 /* Another thread is walking fc_rscn_id_list on this vport */
6238 vport->fc_flag |= FC_RSCN_DISCOVERY;
6239 spin_unlock_irq(shost->host_lock);
6241 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
6244 /* Indicate we are walking fc_rscn_id_list on this vport */
6245 vport->fc_rscn_flush = 1;
6246 spin_unlock_irq(shost->host_lock);
6247 /* Get the array count after successfully have the token */
6248 rscn_cnt = vport->fc_rscn_id_cnt;
6249 /* If we are already processing an RSCN, save the received
6250 * RSCN payload buffer, cmdiocb->context2 to process later.
6252 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
6253 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6254 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
6255 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
6257 spin_lock_irq(shost->host_lock);
6258 vport->fc_flag |= FC_RSCN_DEFERRED;
6259 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
6260 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
6261 vport->fc_flag |= FC_RSCN_MODE;
6262 spin_unlock_irq(shost->host_lock);
6264 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
6265 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
6268 (payload_len + length <= LPFC_BPL_SIZE)) {
6269 *cmd &= ELS_CMD_MASK;
6270 *cmd |= cpu_to_be32(payload_len + length);
6271 memcpy(((uint8_t *)cmd) + length, lp,
6274 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
6275 vport->fc_rscn_id_cnt++;
6276 /* If we zero, cmdiocb->context2, the calling
6277 * routine will not try to free it.
6279 cmdiocb->context2 = NULL;
6282 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6283 "0235 Deferred RSCN "
6284 "Data: x%x x%x x%x\n",
6285 vport->fc_rscn_id_cnt, vport->fc_flag,
6288 vport->fc_flag |= FC_RSCN_DISCOVERY;
6289 spin_unlock_irq(shost->host_lock);
6290 /* ReDiscovery RSCN */
6291 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6292 "0234 ReDiscovery RSCN "
6293 "Data: x%x x%x x%x\n",
6294 vport->fc_rscn_id_cnt, vport->fc_flag,
6297 /* Indicate we are done walking fc_rscn_id_list on this vport */
6298 vport->fc_rscn_flush = 0;
6300 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
6301 /* send RECOVERY event for ALL nodes that match RSCN payload */
6302 lpfc_rscn_recovery_check(vport);
6305 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6306 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
6307 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
6309 spin_lock_irq(shost->host_lock);
6310 vport->fc_flag |= FC_RSCN_MODE;
6311 spin_unlock_irq(shost->host_lock);
6312 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
6313 /* Indicate we are done walking fc_rscn_id_list on this vport */
6314 vport->fc_rscn_flush = 0;
6316 * If we zero, cmdiocb->context2, the calling routine will
6317 * not try to free it.
6319 cmdiocb->context2 = NULL;
6320 lpfc_set_disctmo(vport);
6322 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
6323 /* send RECOVERY event for ALL nodes that match RSCN payload */
6324 lpfc_rscn_recovery_check(vport);
6325 return lpfc_els_handle_rscn(vport);
6329 * lpfc_els_handle_rscn - Handle rscn for a vport
6330 * @vport: pointer to a host virtual N_Port data structure.
6332 * This routine handles the Registration State Configuration Notification
6333 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
6334 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
6335 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
6336 * NameServer shall be issued. If CT command to the NameServer fails to be
6337 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
6338 * RSCN activities with the @vport.
6341 * 0 - Cleaned up rscn on the @vport
6342 * 1 - Wait for plogi to name server before proceed
6345 lpfc_els_handle_rscn(struct lpfc_vport *vport)
6347 struct lpfc_nodelist *ndlp;
6349 /* Ignore RSCN if the port is being torn down. */
6350 if (vport->load_flag & FC_UNLOADING) {
6351 lpfc_els_flush_rscn(vport);
6355 /* Start timer for RSCN processing */
6356 lpfc_set_disctmo(vport);
6358 /* RSCN processed */
6359 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6360 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
6361 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
6364 /* To process RSCN, first compare RSCN data with NameServer */
6365 vport->fc_ns_retry = 0;
6366 vport->num_disc_nodes = 0;
6368 ndlp = lpfc_findnode_did(vport, NameServer_DID);
6369 if (ndlp && NLP_CHK_NODE_ACT(ndlp)
6370 && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
6371 /* Good ndlp, issue CT Request to NameServer. Need to
6372 * know how many gidfts were issued. If none, then just
6373 * flush the RSCN. Otherwise, the outstanding requests
6376 if (lpfc_issue_gidft(vport) > 0)
6379 /* Nameserver login in question. Revalidate. */
6381 ndlp = lpfc_enable_node(vport, ndlp,
6382 NLP_STE_PLOGI_ISSUE);
6384 lpfc_els_flush_rscn(vport);
6387 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
6389 ndlp = lpfc_nlp_init(vport, NameServer_DID);
6391 lpfc_els_flush_rscn(vport);
6394 ndlp->nlp_prev_state = ndlp->nlp_state;
6395 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
6397 ndlp->nlp_type |= NLP_FABRIC;
6398 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
6399 /* Wait for NameServer login cmpl before we can
6405 lpfc_els_flush_rscn(vport);
6410 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
6411 * @vport: pointer to a host virtual N_Port data structure.
6412 * @cmdiocb: pointer to lpfc command iocb data structure.
6413 * @ndlp: pointer to a node-list data structure.
6415 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
6416 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
6417 * point topology. As an unsolicited FLOGI should not be received in a loop
6418 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
6419 * lpfc_check_sparm() routine is invoked to check the parameters in the
6420 * unsolicited FLOGI. If parameters validation failed, the routine
6421 * lpfc_els_rsp_reject() shall be called with reject reason code set to
6422 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
6423 * FLOGI shall be compared with the Port WWN of the @vport to determine who
6424 * will initiate PLOGI. The higher lexicographical value party shall has
6425 * higher priority (as the winning port) and will initiate PLOGI and
6426 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
6427 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
6428 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
6431 * 0 - Successfully processed the unsolicited flogi
6432 * 1 - Failed to process the unsolicited flogi
6435 lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6436 struct lpfc_nodelist *ndlp)
6438 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6439 struct lpfc_hba *phba = vport->phba;
6440 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6441 uint32_t *lp = (uint32_t *) pcmd->virt;
6442 IOCB_t *icmd = &cmdiocb->iocb;
6443 struct serv_parm *sp;
6447 uint32_t fc_flag = 0;
6448 uint32_t port_state = 0;
6451 sp = (struct serv_parm *) lp;
6453 /* FLOGI received */
6455 lpfc_set_disctmo(vport);
6457 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
6458 /* We should never receive a FLOGI in loop mode, ignore it */
6459 did = icmd->un.elsreq64.remoteID;
6461 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
6463 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6464 "0113 An FLOGI ELS command x%x was "
6465 "received from DID x%x in Loop Mode\n",
6470 (void) lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1);
6473 * If our portname is greater than the remote portname,
6474 * then we initiate Nport login.
6477 rc = memcmp(&vport->fc_portname, &sp->portName,
6478 sizeof(struct lpfc_name));
6481 if (phba->sli_rev < LPFC_SLI_REV4) {
6482 mbox = mempool_alloc(phba->mbox_mem_pool,
6486 lpfc_linkdown(phba);
6487 lpfc_init_link(phba, mbox,
6489 phba->cfg_link_speed);
6490 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
6491 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
6492 mbox->vport = vport;
6493 rc = lpfc_sli_issue_mbox(phba, mbox,
6495 lpfc_set_loopback_flag(phba);
6496 if (rc == MBX_NOT_FINISHED)
6497 mempool_free(mbox, phba->mbox_mem_pool);
6501 /* abort the flogi coming back to ourselves
6502 * due to external loopback on the port.
6504 lpfc_els_abort_flogi(phba);
6507 } else if (rc > 0) { /* greater than */
6508 spin_lock_irq(shost->host_lock);
6509 vport->fc_flag |= FC_PT2PT_PLOGI;
6510 spin_unlock_irq(shost->host_lock);
6512 /* If we have the high WWPN we can assign our own
6513 * myDID; otherwise, we have to WAIT for a PLOGI
6514 * from the remote NPort to find out what it
6517 vport->fc_myDID = PT2PT_LocalID;
6519 vport->fc_myDID = PT2PT_RemoteID;
6523 * The vport state should go to LPFC_FLOGI only
6524 * AFTER we issue a FLOGI, not receive one.
6526 spin_lock_irq(shost->host_lock);
6527 fc_flag = vport->fc_flag;
6528 port_state = vport->port_state;
6529 vport->fc_flag |= FC_PT2PT;
6530 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
6531 spin_unlock_irq(shost->host_lock);
6532 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6533 "3311 Rcv Flogi PS x%x new PS x%x "
6534 "fc_flag x%x new fc_flag x%x\n",
6535 port_state, vport->port_state,
6536 fc_flag, vport->fc_flag);
6539 * We temporarily set fc_myDID to make it look like we are
6540 * a Fabric. This is done just so we end up with the right
6541 * did / sid on the FLOGI ACC rsp.
6543 did = vport->fc_myDID;
6544 vport->fc_myDID = Fabric_DID;
6546 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
6549 lpfc_els_rsp_acc(vport, ELS_CMD_FLOGI, cmdiocb, ndlp, NULL);
6551 /* Now lets put fc_myDID back to what its supposed to be */
6552 vport->fc_myDID = did;
6558 * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
6559 * @vport: pointer to a host virtual N_Port data structure.
6560 * @cmdiocb: pointer to lpfc command iocb data structure.
6561 * @ndlp: pointer to a node-list data structure.
6563 * This routine processes Request Node Identification Data (RNID) IOCB
6564 * received as an ELS unsolicited event. Only when the RNID specified format
6565 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
6566 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
6567 * Accept (ACC) the RNID ELS command. All the other RNID formats are
6568 * rejected by invoking the lpfc_els_rsp_reject() routine.
6571 * 0 - Successfully processed rnid iocb (currently always return 0)
6574 lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6575 struct lpfc_nodelist *ndlp)
6577 struct lpfc_dmabuf *pcmd;
6583 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6584 lp = (uint32_t *) pcmd->virt;
6591 switch (rn->Format) {
6593 case RNID_TOPOLOGY_DISC:
6595 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
6598 /* Reject this request because format not supported */
6599 stat.un.b.lsRjtRsvd0 = 0;
6600 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6601 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
6602 stat.un.b.vendorUnique = 0;
6603 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
6610 * lpfc_els_rcv_echo - Process an unsolicited echo iocb
6611 * @vport: pointer to a host virtual N_Port data structure.
6612 * @cmdiocb: pointer to lpfc command iocb data structure.
6613 * @ndlp: pointer to a node-list data structure.
6616 * 0 - Successfully processed echo iocb (currently always return 0)
6619 lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6620 struct lpfc_nodelist *ndlp)
6624 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
6626 /* skip over first word of echo command to find echo data */
6627 pcmd += sizeof(uint32_t);
6629 lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp);
6634 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
6635 * @vport: pointer to a host virtual N_Port data structure.
6636 * @cmdiocb: pointer to lpfc command iocb data structure.
6637 * @ndlp: pointer to a node-list data structure.
6639 * This routine processes a Link Incident Report Registration(LIRR) IOCB
6640 * received as an ELS unsolicited event. Currently, this function just invokes
6641 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
6644 * 0 - Successfully processed lirr iocb (currently always return 0)
6647 lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6648 struct lpfc_nodelist *ndlp)
6652 /* For now, unconditionally reject this command */
6653 stat.un.b.lsRjtRsvd0 = 0;
6654 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6655 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
6656 stat.un.b.vendorUnique = 0;
6657 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
6662 * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb
6663 * @vport: pointer to a host virtual N_Port data structure.
6664 * @cmdiocb: pointer to lpfc command iocb data structure.
6665 * @ndlp: pointer to a node-list data structure.
6667 * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB
6668 * received as an ELS unsolicited event. A request to RRQ shall only
6669 * be accepted if the Originator Nx_Port N_Port_ID or the Responder
6670 * Nx_Port N_Port_ID of the target Exchange is the same as the
6671 * N_Port_ID of the Nx_Port that makes the request. If the RRQ is
6672 * not accepted, an LS_RJT with reason code "Unable to perform
6673 * command request" and reason code explanation "Invalid Originator
6674 * S_ID" shall be returned. For now, we just unconditionally accept
6675 * RRQ from the target.
6678 lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6679 struct lpfc_nodelist *ndlp)
6681 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
6682 if (vport->phba->sli_rev == LPFC_SLI_REV4)
6683 lpfc_els_clear_rrq(vport, cmdiocb, ndlp);
6687 * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
6688 * @phba: pointer to lpfc hba data structure.
6689 * @pmb: pointer to the driver internal queue element for mailbox command.
6691 * This routine is the completion callback function for the MBX_READ_LNK_STAT
6692 * mailbox command. This callback function is to actually send the Accept
6693 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
6694 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
6695 * mailbox command, constructs the RPS response with the link statistics
6696 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
6697 * response to the RPS.
6699 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6700 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6701 * will be stored into the context1 field of the IOCB for the completion
6702 * callback function to the RPS Accept Response ELS IOCB command.
6706 lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
6710 struct RLS_RSP *rls_rsp;
6712 struct lpfc_iocbq *elsiocb;
6713 struct lpfc_nodelist *ndlp;
6720 ndlp = (struct lpfc_nodelist *) pmb->context2;
6721 rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff);
6722 oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff);
6723 pmb->context1 = NULL;
6724 pmb->context2 = NULL;
6726 if (mb->mbxStatus) {
6727 mempool_free(pmb, phba->mbox_mem_pool);
6731 cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t);
6732 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
6733 lpfc_max_els_tries, ndlp,
6734 ndlp->nlp_DID, ELS_CMD_ACC);
6736 /* Decrement the ndlp reference count from previous mbox command */
6740 mempool_free(pmb, phba->mbox_mem_pool);
6744 icmd = &elsiocb->iocb;
6745 icmd->ulpContext = rxid;
6746 icmd->unsli3.rcvsli3.ox_id = oxid;
6748 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6749 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
6750 pcmd += sizeof(uint32_t); /* Skip past command */
6751 rls_rsp = (struct RLS_RSP *)pcmd;
6753 rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
6754 rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
6755 rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
6756 rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
6757 rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
6758 rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
6759 mempool_free(pmb, phba->mbox_mem_pool);
6760 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
6761 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
6762 "2874 Xmit ELS RLS ACC response tag x%x xri x%x, "
6763 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
6764 elsiocb->iotag, elsiocb->iocb.ulpContext,
6765 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
6767 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
6768 phba->fc_stat.elsXmitACC++;
6769 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
6770 lpfc_els_free_iocb(phba, elsiocb);
6774 * lpfc_els_rsp_rps_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
6775 * @phba: pointer to lpfc hba data structure.
6776 * @pmb: pointer to the driver internal queue element for mailbox command.
6778 * This routine is the completion callback function for the MBX_READ_LNK_STAT
6779 * mailbox command. This callback function is to actually send the Accept
6780 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
6781 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
6782 * mailbox command, constructs the RPS response with the link statistics
6783 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
6784 * response to the RPS.
6786 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6787 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6788 * will be stored into the context1 field of the IOCB for the completion
6789 * callback function to the RPS Accept Response ELS IOCB command.
6793 lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
6799 struct lpfc_iocbq *elsiocb;
6800 struct lpfc_nodelist *ndlp;
6808 ndlp = (struct lpfc_nodelist *) pmb->context2;
6809 rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff);
6810 oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff);
6811 pmb->context1 = NULL;
6812 pmb->context2 = NULL;
6814 if (mb->mbxStatus) {
6815 mempool_free(pmb, phba->mbox_mem_pool);
6819 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
6820 mempool_free(pmb, phba->mbox_mem_pool);
6821 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
6822 lpfc_max_els_tries, ndlp,
6823 ndlp->nlp_DID, ELS_CMD_ACC);
6825 /* Decrement the ndlp reference count from previous mbox command */
6831 icmd = &elsiocb->iocb;
6832 icmd->ulpContext = rxid;
6833 icmd->unsli3.rcvsli3.ox_id = oxid;
6835 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6836 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
6837 pcmd += sizeof(uint32_t); /* Skip past command */
6838 rps_rsp = (RPS_RSP *)pcmd;
6840 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP)
6844 if (phba->pport->fc_flag & FC_FABRIC)
6848 rps_rsp->portStatus = cpu_to_be16(status);
6849 rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
6850 rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
6851 rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
6852 rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
6853 rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
6854 rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
6855 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
6856 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
6857 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
6858 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
6859 elsiocb->iotag, elsiocb->iocb.ulpContext,
6860 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
6862 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
6863 phba->fc_stat.elsXmitACC++;
6864 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
6865 lpfc_els_free_iocb(phba, elsiocb);
6870 * lpfc_els_rcv_rls - Process an unsolicited rls iocb
6871 * @vport: pointer to a host virtual N_Port data structure.
6872 * @cmdiocb: pointer to lpfc command iocb data structure.
6873 * @ndlp: pointer to a node-list data structure.
6875 * This routine processes Read Port Status (RPL) IOCB received as an
6876 * ELS unsolicited event. It first checks the remote port state. If the
6877 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
6878 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
6879 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
6880 * for reading the HBA link statistics. It is for the callback function,
6881 * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command
6882 * to actually sending out RPL Accept (ACC) response.
6885 * 0 - Successfully processed rls iocb (currently always return 0)
6888 lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6889 struct lpfc_nodelist *ndlp)
6891 struct lpfc_hba *phba = vport->phba;
6895 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
6896 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
6897 /* reject the unsolicited RPS request and done with it */
6900 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
6902 lpfc_read_lnk_stat(phba, mbox);
6903 mbox->context1 = (void *)((unsigned long)
6904 ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) |
6905 cmdiocb->iocb.ulpContext)); /* rx_id */
6906 mbox->context2 = lpfc_nlp_get(ndlp);
6907 mbox->vport = vport;
6908 mbox->mbox_cmpl = lpfc_els_rsp_rls_acc;
6909 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
6910 != MBX_NOT_FINISHED)
6911 /* Mbox completion will send ELS Response */
6913 /* Decrement reference count used for the failed mbox
6917 mempool_free(mbox, phba->mbox_mem_pool);
6920 /* issue rejection response */
6921 stat.un.b.lsRjtRsvd0 = 0;
6922 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6923 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
6924 stat.un.b.vendorUnique = 0;
6925 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
6930 * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb
6931 * @vport: pointer to a host virtual N_Port data structure.
6932 * @cmdiocb: pointer to lpfc command iocb data structure.
6933 * @ndlp: pointer to a node-list data structure.
6935 * This routine processes Read Timout Value (RTV) IOCB received as an
6936 * ELS unsolicited event. It first checks the remote port state. If the
6937 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
6938 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
6939 * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout
6940 * Value (RTV) unsolicited IOCB event.
6942 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6943 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6944 * will be stored into the context1 field of the IOCB for the completion
6945 * callback function to the RPS Accept Response ELS IOCB command.
6948 * 0 - Successfully processed rtv iocb (currently always return 0)
6951 lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6952 struct lpfc_nodelist *ndlp)
6954 struct lpfc_hba *phba = vport->phba;
6956 struct RTV_RSP *rtv_rsp;
6958 struct lpfc_iocbq *elsiocb;
6962 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
6963 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
6964 /* reject the unsolicited RPS request and done with it */
6967 cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t);
6968 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
6969 lpfc_max_els_tries, ndlp,
6970 ndlp->nlp_DID, ELS_CMD_ACC);
6975 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6976 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
6977 pcmd += sizeof(uint32_t); /* Skip past command */
6979 /* use the command's xri in the response */
6980 elsiocb->iocb.ulpContext = cmdiocb->iocb.ulpContext; /* Xri / rx_id */
6981 elsiocb->iocb.unsli3.rcvsli3.ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id;
6983 rtv_rsp = (struct RTV_RSP *)pcmd;
6985 /* populate RTV payload */
6986 rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000); /* report msecs */
6987 rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov);
6988 bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0);
6989 bf_set(qtov_rttov, rtv_rsp, 0); /* Field is for FC ONLY */
6990 rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov);
6992 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
6993 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
6994 "2875 Xmit ELS RTV ACC response tag x%x xri x%x, "
6995 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, "
6996 "Data: x%x x%x x%x\n",
6997 elsiocb->iotag, elsiocb->iocb.ulpContext,
6998 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
7000 rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov);
7001 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
7002 phba->fc_stat.elsXmitACC++;
7003 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
7004 lpfc_els_free_iocb(phba, elsiocb);
7008 /* issue rejection response */
7009 stat.un.b.lsRjtRsvd0 = 0;
7010 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
7011 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
7012 stat.un.b.vendorUnique = 0;
7013 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
7017 /* lpfc_els_rcv_rps - Process an unsolicited rps iocb
7018 * @vport: pointer to a host virtual N_Port data structure.
7019 * @cmdiocb: pointer to lpfc command iocb data structure.
7020 * @ndlp: pointer to a node-list data structure.
7022 * This routine processes Read Port Status (RPS) IOCB received as an
7023 * ELS unsolicited event. It first checks the remote port state. If the
7024 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
7025 * state, it invokes the lpfc_els_rsp_reject() routine to send the reject
7026 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
7027 * for reading the HBA link statistics. It is for the callback function,
7028 * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command
7029 * to actually sending out RPS Accept (ACC) response.
7032 * 0 - Successfully processed rps iocb (currently always return 0)
7035 lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7036 struct lpfc_nodelist *ndlp)
7038 struct lpfc_hba *phba = vport->phba;
7042 struct lpfc_dmabuf *pcmd;
7046 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
7047 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
7048 /* reject the unsolicited RPS request and done with it */
7051 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7052 lp = (uint32_t *) pcmd->virt;
7053 flag = (be32_to_cpu(*lp++) & 0xf);
7057 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
7058 ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
7059 sizeof(struct lpfc_name)) == 0))) {
7061 printk("Fix me....\n");
7063 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
7065 lpfc_read_lnk_stat(phba, mbox);
7066 mbox->context1 = (void *)((unsigned long)
7067 ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) |
7068 cmdiocb->iocb.ulpContext)); /* rx_id */
7069 mbox->context2 = lpfc_nlp_get(ndlp);
7070 mbox->vport = vport;
7071 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
7072 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
7073 != MBX_NOT_FINISHED)
7074 /* Mbox completion will send ELS Response */
7076 /* Decrement reference count used for the failed mbox
7080 mempool_free(mbox, phba->mbox_mem_pool);
7085 /* issue rejection response */
7086 stat.un.b.lsRjtRsvd0 = 0;
7087 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
7088 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
7089 stat.un.b.vendorUnique = 0;
7090 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
7094 /* lpfc_issue_els_rrq - Process an unsolicited rps iocb
7095 * @vport: pointer to a host virtual N_Port data structure.
7096 * @ndlp: pointer to a node-list data structure.
7097 * @did: DID of the target.
7098 * @rrq: Pointer to the rrq struct.
7100 * Build a ELS RRQ command and send it to the target. If the issue_iocb is
7101 * Successful the the completion handler will clear the RRQ.
7104 * 0 - Successfully sent rrq els iocb.
7105 * 1 - Failed to send rrq els iocb.
7108 lpfc_issue_els_rrq(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
7109 uint32_t did, struct lpfc_node_rrq *rrq)
7111 struct lpfc_hba *phba = vport->phba;
7112 struct RRQ *els_rrq;
7113 struct lpfc_iocbq *elsiocb;
7119 if (ndlp != rrq->ndlp)
7121 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
7124 /* If ndlp is not NULL, we will bump the reference count on it */
7125 cmdsize = (sizeof(uint32_t) + sizeof(struct RRQ));
7126 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, did,
7131 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7133 /* For RRQ request, remainder of payload is Exchange IDs */
7134 *((uint32_t *) (pcmd)) = ELS_CMD_RRQ;
7135 pcmd += sizeof(uint32_t);
7136 els_rrq = (struct RRQ *) pcmd;
7138 bf_set(rrq_oxid, els_rrq, phba->sli4_hba.xri_ids[rrq->xritag]);
7139 bf_set(rrq_rxid, els_rrq, rrq->rxid);
7140 bf_set(rrq_did, els_rrq, vport->fc_myDID);
7141 els_rrq->rrq = cpu_to_be32(els_rrq->rrq);
7142 els_rrq->rrq_exchg = cpu_to_be32(els_rrq->rrq_exchg);
7145 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7146 "Issue RRQ: did:x%x",
7147 did, rrq->xritag, rrq->rxid);
7148 elsiocb->context_un.rrq = rrq;
7149 elsiocb->iocb_cmpl = lpfc_cmpl_els_rrq;
7150 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
7152 if (ret == IOCB_ERROR) {
7153 lpfc_els_free_iocb(phba, elsiocb);
7160 * lpfc_send_rrq - Sends ELS RRQ if needed.
7161 * @phba: pointer to lpfc hba data structure.
7162 * @rrq: pointer to the active rrq.
7164 * This routine will call the lpfc_issue_els_rrq if the rrq is
7165 * still active for the xri. If this function returns a failure then
7166 * the caller needs to clean up the RRQ by calling lpfc_clr_active_rrq.
7168 * Returns 0 Success.
7172 lpfc_send_rrq(struct lpfc_hba *phba, struct lpfc_node_rrq *rrq)
7174 struct lpfc_nodelist *ndlp = lpfc_findnode_did(rrq->vport,
7176 if (lpfc_test_rrq_active(phba, ndlp, rrq->xritag))
7177 return lpfc_issue_els_rrq(rrq->vport, ndlp,
7184 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
7185 * @vport: pointer to a host virtual N_Port data structure.
7186 * @cmdsize: size of the ELS command.
7187 * @oldiocb: pointer to the original lpfc command iocb data structure.
7188 * @ndlp: pointer to a node-list data structure.
7190 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
7191 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
7193 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7194 * will be incremented by 1 for holding the ndlp and the reference to ndlp
7195 * will be stored into the context1 field of the IOCB for the completion
7196 * callback function to the RPL Accept Response ELS command.
7199 * 0 - Successfully issued ACC RPL ELS command
7200 * 1 - Failed to issue ACC RPL ELS command
7203 lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
7204 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
7206 struct lpfc_hba *phba = vport->phba;
7207 IOCB_t *icmd, *oldcmd;
7209 struct lpfc_iocbq *elsiocb;
7212 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
7213 ndlp->nlp_DID, ELS_CMD_ACC);
7218 icmd = &elsiocb->iocb;
7219 oldcmd = &oldiocb->iocb;
7220 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
7221 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
7223 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7224 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
7225 pcmd += sizeof(uint16_t);
7226 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
7227 pcmd += sizeof(uint16_t);
7229 /* Setup the RPL ACC payload */
7230 rpl_rsp.listLen = be32_to_cpu(1);
7232 rpl_rsp.port_num_blk.portNum = 0;
7233 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
7234 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
7235 sizeof(struct lpfc_name));
7236 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
7237 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
7238 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7239 "0120 Xmit ELS RPL ACC response tag x%x "
7240 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
7242 elsiocb->iotag, elsiocb->iocb.ulpContext,
7243 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
7245 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
7246 phba->fc_stat.elsXmitACC++;
7247 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
7249 lpfc_els_free_iocb(phba, elsiocb);
7256 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
7257 * @vport: pointer to a host virtual N_Port data structure.
7258 * @cmdiocb: pointer to lpfc command iocb data structure.
7259 * @ndlp: pointer to a node-list data structure.
7261 * This routine processes Read Port List (RPL) IOCB received as an ELS
7262 * unsolicited event. It first checks the remote port state. If the remote
7263 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
7264 * invokes the lpfc_els_rsp_reject() routine to send reject response.
7265 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
7266 * to accept the RPL.
7269 * 0 - Successfully processed rpl iocb (currently always return 0)
7272 lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7273 struct lpfc_nodelist *ndlp)
7275 struct lpfc_dmabuf *pcmd;
7282 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
7283 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
7284 /* issue rejection response */
7285 stat.un.b.lsRjtRsvd0 = 0;
7286 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
7287 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
7288 stat.un.b.vendorUnique = 0;
7289 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
7291 /* rejected the unsolicited RPL request and done with it */
7295 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7296 lp = (uint32_t *) pcmd->virt;
7297 rpl = (RPL *) (lp + 1);
7298 maxsize = be32_to_cpu(rpl->maxsize);
7300 /* We support only one port */
7301 if ((rpl->index == 0) &&
7303 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
7304 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
7306 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
7308 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
7314 * lpfc_els_rcv_farp - Process an unsolicited farp request els command
7315 * @vport: pointer to a virtual N_Port data structure.
7316 * @cmdiocb: pointer to lpfc command iocb data structure.
7317 * @ndlp: pointer to a node-list data structure.
7319 * This routine processes Fibre Channel Address Resolution Protocol
7320 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
7321 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
7322 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
7323 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
7324 * remote PortName is compared against the FC PortName stored in the @vport
7325 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
7326 * compared against the FC NodeName stored in the @vport data structure.
7327 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
7328 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
7329 * invoked to send out FARP Response to the remote node. Before sending the
7330 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
7331 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
7332 * routine is invoked to log into the remote port first.
7335 * 0 - Either the FARP Match Mode not supported or successfully processed
7338 lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7339 struct lpfc_nodelist *ndlp)
7341 struct lpfc_dmabuf *pcmd;
7345 uint32_t cmd, cnt, did;
7347 icmd = &cmdiocb->iocb;
7348 did = icmd->un.elsreq64.remoteID;
7349 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7350 lp = (uint32_t *) pcmd->virt;
7354 /* FARP-REQ received from DID <did> */
7355 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7356 "0601 FARP-REQ received from DID x%x\n", did);
7357 /* We will only support match on WWPN or WWNN */
7358 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
7363 /* If this FARP command is searching for my portname */
7364 if (fp->Mflags & FARP_MATCH_PORT) {
7365 if (memcmp(&fp->RportName, &vport->fc_portname,
7366 sizeof(struct lpfc_name)) == 0)
7370 /* If this FARP command is searching for my nodename */
7371 if (fp->Mflags & FARP_MATCH_NODE) {
7372 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
7373 sizeof(struct lpfc_name)) == 0)
7378 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
7379 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
7380 /* Log back into the node before sending the FARP. */
7381 if (fp->Rflags & FARP_REQUEST_PLOGI) {
7382 ndlp->nlp_prev_state = ndlp->nlp_state;
7383 lpfc_nlp_set_state(vport, ndlp,
7384 NLP_STE_PLOGI_ISSUE);
7385 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
7388 /* Send a FARP response to that node */
7389 if (fp->Rflags & FARP_REQUEST_FARPR)
7390 lpfc_issue_els_farpr(vport, did, 0);
7397 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
7398 * @vport: pointer to a host virtual N_Port data structure.
7399 * @cmdiocb: pointer to lpfc command iocb data structure.
7400 * @ndlp: pointer to a node-list data structure.
7402 * This routine processes Fibre Channel Address Resolution Protocol
7403 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
7404 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
7405 * the FARP response request.
7408 * 0 - Successfully processed FARPR IOCB (currently always return 0)
7411 lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7412 struct lpfc_nodelist *ndlp)
7414 struct lpfc_dmabuf *pcmd;
7419 icmd = &cmdiocb->iocb;
7420 did = icmd->un.elsreq64.remoteID;
7421 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7422 lp = (uint32_t *) pcmd->virt;
7425 /* FARP-RSP received from DID <did> */
7426 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7427 "0600 FARP-RSP received from DID x%x\n", did);
7428 /* ACCEPT the Farp resp request */
7429 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
7435 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
7436 * @vport: pointer to a host virtual N_Port data structure.
7437 * @cmdiocb: pointer to lpfc command iocb data structure.
7438 * @fan_ndlp: pointer to a node-list data structure.
7440 * This routine processes a Fabric Address Notification (FAN) IOCB
7441 * command received as an ELS unsolicited event. The FAN ELS command will
7442 * only be processed on a physical port (i.e., the @vport represents the
7443 * physical port). The fabric NodeName and PortName from the FAN IOCB are
7444 * compared against those in the phba data structure. If any of those is
7445 * different, the lpfc_initial_flogi() routine is invoked to initialize
7446 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
7447 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
7448 * is invoked to register login to the fabric.
7451 * 0 - Successfully processed fan iocb (currently always return 0).
7454 lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7455 struct lpfc_nodelist *fan_ndlp)
7457 struct lpfc_hba *phba = vport->phba;
7461 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
7462 lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
7464 /* FAN received; Fan does not have a reply sequence */
7465 if ((vport == phba->pport) &&
7466 (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
7467 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
7468 sizeof(struct lpfc_name))) ||
7469 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
7470 sizeof(struct lpfc_name)))) {
7471 /* This port has switched fabrics. FLOGI is required */
7472 lpfc_issue_init_vfi(vport);
7474 /* FAN verified - skip FLOGI */
7475 vport->fc_myDID = vport->fc_prevDID;
7476 if (phba->sli_rev < LPFC_SLI_REV4)
7477 lpfc_issue_fabric_reglogin(vport);
7479 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7480 "3138 Need register VFI: (x%x/%x)\n",
7481 vport->fc_prevDID, vport->fc_myDID);
7482 lpfc_issue_reg_vfi(vport);
7490 * lpfc_els_timeout - Handler funciton to the els timer
7491 * @ptr: holder for the timer function associated data.
7493 * This routine is invoked by the ELS timer after timeout. It posts the ELS
7494 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
7495 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
7496 * up the worker thread. It is for the worker thread to invoke the routine
7497 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
7500 lpfc_els_timeout(struct timer_list *t)
7502 struct lpfc_vport *vport = from_timer(vport, t, els_tmofunc);
7503 struct lpfc_hba *phba = vport->phba;
7504 uint32_t tmo_posted;
7505 unsigned long iflag;
7507 spin_lock_irqsave(&vport->work_port_lock, iflag);
7508 tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
7509 if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING)))
7510 vport->work_port_events |= WORKER_ELS_TMO;
7511 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
7513 if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING)))
7514 lpfc_worker_wake_up(phba);
7520 * lpfc_els_timeout_handler - Process an els timeout event
7521 * @vport: pointer to a virtual N_Port data structure.
7523 * This routine is the actual handler function that processes an ELS timeout
7524 * event. It walks the ELS ring to get and abort all the IOCBs (except the
7525 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
7526 * invoking the lpfc_sli_issue_abort_iotag() routine.
7529 lpfc_els_timeout_handler(struct lpfc_vport *vport)
7531 struct lpfc_hba *phba = vport->phba;
7532 struct lpfc_sli_ring *pring;
7533 struct lpfc_iocbq *tmp_iocb, *piocb;
7535 struct lpfc_dmabuf *pcmd;
7536 uint32_t els_command = 0;
7538 uint32_t remote_ID = 0xffffffff;
7539 LIST_HEAD(abort_list);
7542 timeout = (uint32_t)(phba->fc_ratov << 1);
7544 pring = lpfc_phba_elsring(phba);
7545 if (unlikely(!pring))
7548 if ((phba->pport->load_flag & FC_UNLOADING))
7550 spin_lock_irq(&phba->hbalock);
7551 if (phba->sli_rev == LPFC_SLI_REV4)
7552 spin_lock(&pring->ring_lock);
7554 if ((phba->pport->load_flag & FC_UNLOADING)) {
7555 if (phba->sli_rev == LPFC_SLI_REV4)
7556 spin_unlock(&pring->ring_lock);
7557 spin_unlock_irq(&phba->hbalock);
7561 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
7564 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
7565 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
7566 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
7569 if (piocb->vport != vport)
7572 pcmd = (struct lpfc_dmabuf *) piocb->context2;
7574 els_command = *(uint32_t *) (pcmd->virt);
7576 if (els_command == ELS_CMD_FARP ||
7577 els_command == ELS_CMD_FARPR ||
7578 els_command == ELS_CMD_FDISC)
7581 if (piocb->drvrTimeout > 0) {
7582 if (piocb->drvrTimeout >= timeout)
7583 piocb->drvrTimeout -= timeout;
7585 piocb->drvrTimeout = 0;
7589 remote_ID = 0xffffffff;
7590 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
7591 remote_ID = cmd->un.elsreq64.remoteID;
7593 struct lpfc_nodelist *ndlp;
7594 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
7595 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
7596 remote_ID = ndlp->nlp_DID;
7598 list_add_tail(&piocb->dlist, &abort_list);
7600 if (phba->sli_rev == LPFC_SLI_REV4)
7601 spin_unlock(&pring->ring_lock);
7602 spin_unlock_irq(&phba->hbalock);
7604 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
7606 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7607 "0127 ELS timeout Data: x%x x%x x%x "
7608 "x%x\n", els_command,
7609 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
7610 spin_lock_irq(&phba->hbalock);
7611 list_del_init(&piocb->dlist);
7612 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
7613 spin_unlock_irq(&phba->hbalock);
7616 if (!list_empty(&pring->txcmplq))
7617 if (!(phba->pport->load_flag & FC_UNLOADING))
7618 mod_timer(&vport->els_tmofunc,
7619 jiffies + msecs_to_jiffies(1000 * timeout));
7623 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
7624 * @vport: pointer to a host virtual N_Port data structure.
7626 * This routine is used to clean up all the outstanding ELS commands on a
7627 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
7628 * routine. After that, it walks the ELS transmit queue to remove all the
7629 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
7630 * the IOCBs with a non-NULL completion callback function, the callback
7631 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
7632 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
7633 * callback function, the IOCB will simply be released. Finally, it walks
7634 * the ELS transmit completion queue to issue an abort IOCB to any transmit
7635 * completion queue IOCB that is associated with the @vport and is not
7636 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
7637 * part of the discovery state machine) out to HBA by invoking the
7638 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
7639 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
7640 * the IOCBs are aborted when this function returns.
7643 lpfc_els_flush_cmd(struct lpfc_vport *vport)
7645 LIST_HEAD(abort_list);
7646 struct lpfc_hba *phba = vport->phba;
7647 struct lpfc_sli_ring *pring;
7648 struct lpfc_iocbq *tmp_iocb, *piocb;
7651 lpfc_fabric_abort_vport(vport);
7653 * For SLI3, only the hbalock is required. But SLI4 needs to coordinate
7654 * with the ring insert operation. Because lpfc_sli_issue_abort_iotag
7655 * ultimately grabs the ring_lock, the driver must splice the list into
7656 * a working list and release the locks before calling the abort.
7658 spin_lock_irq(&phba->hbalock);
7659 pring = lpfc_phba_elsring(phba);
7661 /* Bail out if we've no ELS wq, like in PCI error recovery case. */
7662 if (unlikely(!pring)) {
7663 spin_unlock_irq(&phba->hbalock);
7667 if (phba->sli_rev == LPFC_SLI_REV4)
7668 spin_lock(&pring->ring_lock);
7670 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
7671 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
7674 if (piocb->vport != vport)
7676 list_add_tail(&piocb->dlist, &abort_list);
7678 if (phba->sli_rev == LPFC_SLI_REV4)
7679 spin_unlock(&pring->ring_lock);
7680 spin_unlock_irq(&phba->hbalock);
7681 /* Abort each iocb on the aborted list and remove the dlist links. */
7682 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
7683 spin_lock_irq(&phba->hbalock);
7684 list_del_init(&piocb->dlist);
7685 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
7686 spin_unlock_irq(&phba->hbalock);
7688 if (!list_empty(&abort_list))
7689 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7690 "3387 abort list for txq not empty\n");
7691 INIT_LIST_HEAD(&abort_list);
7693 spin_lock_irq(&phba->hbalock);
7694 if (phba->sli_rev == LPFC_SLI_REV4)
7695 spin_lock(&pring->ring_lock);
7697 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
7700 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
7704 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
7705 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
7706 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
7707 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
7708 cmd->ulpCommand == CMD_ABORT_XRI_CN)
7711 if (piocb->vport != vport)
7714 list_del_init(&piocb->list);
7715 list_add_tail(&piocb->list, &abort_list);
7717 if (phba->sli_rev == LPFC_SLI_REV4)
7718 spin_unlock(&pring->ring_lock);
7719 spin_unlock_irq(&phba->hbalock);
7721 /* Cancell all the IOCBs from the completions list */
7722 lpfc_sli_cancel_iocbs(phba, &abort_list,
7723 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
7729 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
7730 * @phba: pointer to lpfc hba data structure.
7732 * This routine is used to clean up all the outstanding ELS commands on a
7733 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
7734 * routine. After that, it walks the ELS transmit queue to remove all the
7735 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
7736 * the IOCBs with the completion callback function associated, the callback
7737 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
7738 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
7739 * callback function associated, the IOCB will simply be released. Finally,
7740 * it walks the ELS transmit completion queue to issue an abort IOCB to any
7741 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
7742 * management plane IOCBs that are not part of the discovery state machine)
7743 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
7746 lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
7748 struct lpfc_vport *vport;
7750 spin_lock_irq(&phba->port_list_lock);
7751 list_for_each_entry(vport, &phba->port_list, listentry)
7752 lpfc_els_flush_cmd(vport);
7753 spin_unlock_irq(&phba->port_list_lock);
7759 * lpfc_send_els_failure_event - Posts an ELS command failure event
7760 * @phba: Pointer to hba context object.
7761 * @cmdiocbp: Pointer to command iocb which reported error.
7762 * @rspiocbp: Pointer to response iocb which reported error.
7764 * This function sends an event when there is an ELS command
7768 lpfc_send_els_failure_event(struct lpfc_hba *phba,
7769 struct lpfc_iocbq *cmdiocbp,
7770 struct lpfc_iocbq *rspiocbp)
7772 struct lpfc_vport *vport = cmdiocbp->vport;
7773 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7774 struct lpfc_lsrjt_event lsrjt_event;
7775 struct lpfc_fabric_event_header fabric_event;
7777 struct lpfc_nodelist *ndlp;
7780 ndlp = cmdiocbp->context1;
7781 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
7784 if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) {
7785 lsrjt_event.header.event_type = FC_REG_ELS_EVENT;
7786 lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV;
7787 memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname,
7788 sizeof(struct lpfc_name));
7789 memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename,
7790 sizeof(struct lpfc_name));
7791 pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
7792 cmdiocbp->context2)->virt);
7793 lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0;
7794 stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]);
7795 lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode;
7796 lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp;
7797 fc_host_post_vendor_event(shost,
7798 fc_get_event_number(),
7799 sizeof(lsrjt_event),
7800 (char *)&lsrjt_event,
7804 if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) ||
7805 (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) {
7806 fabric_event.event_type = FC_REG_FABRIC_EVENT;
7807 if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY)
7808 fabric_event.subcategory = LPFC_EVENT_PORT_BUSY;
7810 fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY;
7811 memcpy(fabric_event.wwpn, &ndlp->nlp_portname,
7812 sizeof(struct lpfc_name));
7813 memcpy(fabric_event.wwnn, &ndlp->nlp_nodename,
7814 sizeof(struct lpfc_name));
7815 fc_host_post_vendor_event(shost,
7816 fc_get_event_number(),
7817 sizeof(fabric_event),
7818 (char *)&fabric_event,
7826 * lpfc_send_els_event - Posts unsolicited els event
7827 * @vport: Pointer to vport object.
7828 * @ndlp: Pointer FC node object.
7829 * @cmd: ELS command code.
7831 * This function posts an event when there is an incoming
7832 * unsolicited ELS command.
7835 lpfc_send_els_event(struct lpfc_vport *vport,
7836 struct lpfc_nodelist *ndlp,
7839 struct lpfc_els_event_header *els_data = NULL;
7840 struct lpfc_logo_event *logo_data = NULL;
7841 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7843 if (*payload == ELS_CMD_LOGO) {
7844 logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL);
7846 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7847 "0148 Failed to allocate memory "
7848 "for LOGO event\n");
7851 els_data = &logo_data->header;
7853 els_data = kmalloc(sizeof(struct lpfc_els_event_header),
7856 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7857 "0149 Failed to allocate memory "
7862 els_data->event_type = FC_REG_ELS_EVENT;
7865 els_data->subcategory = LPFC_EVENT_PLOGI_RCV;
7868 els_data->subcategory = LPFC_EVENT_PRLO_RCV;
7871 els_data->subcategory = LPFC_EVENT_ADISC_RCV;
7874 els_data->subcategory = LPFC_EVENT_LOGO_RCV;
7875 /* Copy the WWPN in the LOGO payload */
7876 memcpy(logo_data->logo_wwpn, &payload[2],
7877 sizeof(struct lpfc_name));
7883 memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name));
7884 memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name));
7885 if (*payload == ELS_CMD_LOGO) {
7886 fc_host_post_vendor_event(shost,
7887 fc_get_event_number(),
7888 sizeof(struct lpfc_logo_event),
7893 fc_host_post_vendor_event(shost,
7894 fc_get_event_number(),
7895 sizeof(struct lpfc_els_event_header),
7906 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
7907 * @phba: pointer to lpfc hba data structure.
7908 * @pring: pointer to a SLI ring.
7909 * @vport: pointer to a host virtual N_Port data structure.
7910 * @elsiocb: pointer to lpfc els command iocb data structure.
7912 * This routine is used for processing the IOCB associated with a unsolicited
7913 * event. It first determines whether there is an existing ndlp that matches
7914 * the DID from the unsolicited IOCB. If not, it will create a new one with
7915 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
7916 * IOCB is then used to invoke the proper routine and to set up proper state
7917 * of the discovery state machine.
7920 lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
7921 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
7923 struct Scsi_Host *shost;
7924 struct lpfc_nodelist *ndlp;
7927 uint32_t cmd, did, newnode;
7928 uint8_t rjt_exp, rjt_err = 0;
7929 IOCB_t *icmd = &elsiocb->iocb;
7931 if (!vport || !(elsiocb->context2))
7935 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
7937 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
7938 lpfc_post_buffer(phba, pring, 1);
7940 did = icmd->un.rcvels.remoteID;
7941 if (icmd->ulpStatus) {
7942 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7943 "RCV Unsol ELS: status:x%x/x%x did:x%x",
7944 icmd->ulpStatus, icmd->un.ulpWord[4], did);
7948 /* Check to see if link went down during discovery */
7949 if (lpfc_els_chk_latt(vport))
7952 /* Ignore traffic received during vport shutdown. */
7953 if (vport->load_flag & FC_UNLOADING)
7956 /* If NPort discovery is delayed drop incoming ELS */
7957 if ((vport->fc_flag & FC_DISC_DELAYED) &&
7958 (cmd != ELS_CMD_PLOGI))
7961 ndlp = lpfc_findnode_did(vport, did);
7963 /* Cannot find existing Fabric ndlp, so allocate a new one */
7964 ndlp = lpfc_nlp_init(vport, did);
7967 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
7969 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
7970 ndlp->nlp_type |= NLP_FABRIC;
7971 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
7972 ndlp = lpfc_enable_node(vport, ndlp,
7973 NLP_STE_UNUSED_NODE);
7976 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
7978 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
7979 ndlp->nlp_type |= NLP_FABRIC;
7980 } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
7981 /* This is similar to the new node path */
7982 ndlp = lpfc_nlp_get(ndlp);
7985 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
7989 phba->fc_stat.elsRcvFrame++;
7992 * Do not process any unsolicited ELS commands
7993 * if the ndlp is in DEV_LOSS
7995 shost = lpfc_shost_from_vport(vport);
7996 spin_lock_irq(shost->host_lock);
7997 if (ndlp->nlp_flag & NLP_IN_DEV_LOSS) {
7998 spin_unlock_irq(shost->host_lock);
8001 spin_unlock_irq(shost->host_lock);
8003 elsiocb->context1 = lpfc_nlp_get(ndlp);
8004 elsiocb->vport = vport;
8006 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
8007 cmd &= ELS_CMD_MASK;
8009 /* ELS command <elsCmd> received from NPORT <did> */
8010 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
8011 "0112 ELS command x%x received from NPORT x%x "
8012 "Data: x%x x%x x%x x%x\n",
8013 cmd, did, vport->port_state, vport->fc_flag,
8014 vport->fc_myDID, vport->fc_prevDID);
8016 /* reject till our FLOGI completes */
8017 if ((vport->port_state < LPFC_FABRIC_CFG_LINK) &&
8018 (cmd != ELS_CMD_FLOGI)) {
8019 rjt_err = LSRJT_LOGICAL_BSY;
8020 rjt_exp = LSEXP_NOTHING_MORE;
8026 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8027 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
8028 did, vport->port_state, ndlp->nlp_flag);
8030 phba->fc_stat.elsRcvPLOGI++;
8031 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
8032 if (phba->sli_rev == LPFC_SLI_REV4 &&
8033 (phba->pport->fc_flag & FC_PT2PT)) {
8034 vport->fc_prevDID = vport->fc_myDID;
8035 /* Our DID needs to be updated before registering
8036 * the vfi. This is done in lpfc_rcv_plogi but
8037 * that is called after the reg_vfi.
8039 vport->fc_myDID = elsiocb->iocb.un.rcvels.parmRo;
8040 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
8041 "3312 Remote port assigned DID x%x "
8042 "%x\n", vport->fc_myDID,
8046 lpfc_send_els_event(vport, ndlp, payload);
8048 /* If Nport discovery is delayed, reject PLOGIs */
8049 if (vport->fc_flag & FC_DISC_DELAYED) {
8050 rjt_err = LSRJT_UNABLE_TPC;
8051 rjt_exp = LSEXP_NOTHING_MORE;
8055 if (vport->port_state < LPFC_DISC_AUTH) {
8056 if (!(phba->pport->fc_flag & FC_PT2PT) ||
8057 (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
8058 rjt_err = LSRJT_UNABLE_TPC;
8059 rjt_exp = LSEXP_NOTHING_MORE;
8064 spin_lock_irq(shost->host_lock);
8065 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
8066 spin_unlock_irq(shost->host_lock);
8068 lpfc_disc_state_machine(vport, ndlp, elsiocb,
8073 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8074 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
8075 did, vport->port_state, ndlp->nlp_flag);
8077 phba->fc_stat.elsRcvFLOGI++;
8078 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
8083 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8084 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
8085 did, vport->port_state, ndlp->nlp_flag);
8087 phba->fc_stat.elsRcvLOGO++;
8088 lpfc_send_els_event(vport, ndlp, payload);
8089 if (vport->port_state < LPFC_DISC_AUTH) {
8090 rjt_err = LSRJT_UNABLE_TPC;
8091 rjt_exp = LSEXP_NOTHING_MORE;
8094 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
8097 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8098 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
8099 did, vport->port_state, ndlp->nlp_flag);
8101 phba->fc_stat.elsRcvPRLO++;
8102 lpfc_send_els_event(vport, ndlp, payload);
8103 if (vport->port_state < LPFC_DISC_AUTH) {
8104 rjt_err = LSRJT_UNABLE_TPC;
8105 rjt_exp = LSEXP_NOTHING_MORE;
8108 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
8111 phba->fc_stat.elsRcvLCB++;
8112 lpfc_els_rcv_lcb(vport, elsiocb, ndlp);
8115 phba->fc_stat.elsRcvRDP++;
8116 lpfc_els_rcv_rdp(vport, elsiocb, ndlp);
8119 phba->fc_stat.elsRcvRSCN++;
8120 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
8125 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8126 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
8127 did, vport->port_state, ndlp->nlp_flag);
8129 lpfc_send_els_event(vport, ndlp, payload);
8130 phba->fc_stat.elsRcvADISC++;
8131 if (vport->port_state < LPFC_DISC_AUTH) {
8132 rjt_err = LSRJT_UNABLE_TPC;
8133 rjt_exp = LSEXP_NOTHING_MORE;
8136 lpfc_disc_state_machine(vport, ndlp, elsiocb,
8140 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8141 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
8142 did, vport->port_state, ndlp->nlp_flag);
8144 phba->fc_stat.elsRcvPDISC++;
8145 if (vport->port_state < LPFC_DISC_AUTH) {
8146 rjt_err = LSRJT_UNABLE_TPC;
8147 rjt_exp = LSEXP_NOTHING_MORE;
8150 lpfc_disc_state_machine(vport, ndlp, elsiocb,
8154 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8155 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
8156 did, vport->port_state, ndlp->nlp_flag);
8158 phba->fc_stat.elsRcvFARPR++;
8159 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
8162 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8163 "RCV FARP: did:x%x/ste:x%x flg:x%x",
8164 did, vport->port_state, ndlp->nlp_flag);
8166 phba->fc_stat.elsRcvFARP++;
8167 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
8170 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8171 "RCV FAN: did:x%x/ste:x%x flg:x%x",
8172 did, vport->port_state, ndlp->nlp_flag);
8174 phba->fc_stat.elsRcvFAN++;
8175 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
8178 case ELS_CMD_NVMEPRLI:
8179 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8180 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
8181 did, vport->port_state, ndlp->nlp_flag);
8183 phba->fc_stat.elsRcvPRLI++;
8184 if ((vport->port_state < LPFC_DISC_AUTH) &&
8185 (vport->fc_flag & FC_FABRIC)) {
8186 rjt_err = LSRJT_UNABLE_TPC;
8187 rjt_exp = LSEXP_NOTHING_MORE;
8190 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
8193 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8194 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
8195 did, vport->port_state, ndlp->nlp_flag);
8197 phba->fc_stat.elsRcvLIRR++;
8198 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
8203 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8204 "RCV RLS: did:x%x/ste:x%x flg:x%x",
8205 did, vport->port_state, ndlp->nlp_flag);
8207 phba->fc_stat.elsRcvRLS++;
8208 lpfc_els_rcv_rls(vport, elsiocb, ndlp);
8213 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8214 "RCV RPS: did:x%x/ste:x%x flg:x%x",
8215 did, vport->port_state, ndlp->nlp_flag);
8217 phba->fc_stat.elsRcvRPS++;
8218 lpfc_els_rcv_rps(vport, elsiocb, ndlp);
8223 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8224 "RCV RPL: did:x%x/ste:x%x flg:x%x",
8225 did, vport->port_state, ndlp->nlp_flag);
8227 phba->fc_stat.elsRcvRPL++;
8228 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
8233 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8234 "RCV RNID: did:x%x/ste:x%x flg:x%x",
8235 did, vport->port_state, ndlp->nlp_flag);
8237 phba->fc_stat.elsRcvRNID++;
8238 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
8243 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8244 "RCV RTV: did:x%x/ste:x%x flg:x%x",
8245 did, vport->port_state, ndlp->nlp_flag);
8246 phba->fc_stat.elsRcvRTV++;
8247 lpfc_els_rcv_rtv(vport, elsiocb, ndlp);
8252 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8253 "RCV RRQ: did:x%x/ste:x%x flg:x%x",
8254 did, vport->port_state, ndlp->nlp_flag);
8256 phba->fc_stat.elsRcvRRQ++;
8257 lpfc_els_rcv_rrq(vport, elsiocb, ndlp);
8262 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8263 "RCV ECHO: did:x%x/ste:x%x flg:x%x",
8264 did, vport->port_state, ndlp->nlp_flag);
8266 phba->fc_stat.elsRcvECHO++;
8267 lpfc_els_rcv_echo(vport, elsiocb, ndlp);
8272 /* receive this due to exchange closed */
8273 rjt_err = LSRJT_UNABLE_TPC;
8274 rjt_exp = LSEXP_INVALID_OX_RX;
8277 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8278 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
8279 cmd, did, vport->port_state);
8281 /* Unsupported ELS command, reject */
8282 rjt_err = LSRJT_CMD_UNSUPPORTED;
8283 rjt_exp = LSEXP_NOTHING_MORE;
8285 /* Unknown ELS command <elsCmd> received from NPORT <did> */
8286 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8287 "0115 Unknown ELS command x%x "
8288 "received from NPORT x%x\n", cmd, did);
8295 /* check if need to LS_RJT received ELS cmd */
8297 memset(&stat, 0, sizeof(stat));
8298 stat.un.b.lsRjtRsnCode = rjt_err;
8299 stat.un.b.lsRjtRsnCodeExp = rjt_exp;
8300 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
8304 lpfc_nlp_put(elsiocb->context1);
8305 elsiocb->context1 = NULL;
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);