1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2017 Broadcom. All Rights Reserved. The term *
5 * “Broadcom” refers to Broadcom Limited 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 physical FC port changed, unreg VFI and ALL VPIs / RPIs */
864 if ((phba->sli_rev == LPFC_SLI_REV4) && phba->fc_topology_changed) {
865 lpfc_unregister_fcf_prep(phba);
867 spin_lock_irq(shost->host_lock);
868 vport->fc_flag &= ~FC_VFI_REGISTERED;
869 spin_unlock_irq(shost->host_lock);
870 phba->fc_topology_changed = 0;
873 rc = memcmp(&vport->fc_portname, &sp->portName,
874 sizeof(vport->fc_portname));
877 /* This side will initiate the PLOGI */
878 spin_lock_irq(shost->host_lock);
879 vport->fc_flag |= FC_PT2PT_PLOGI;
880 spin_unlock_irq(shost->host_lock);
883 * N_Port ID cannot be 0, set our Id to LocalID
884 * the other side will be RemoteID.
889 vport->fc_myDID = PT2PT_LocalID;
891 /* Decrement ndlp reference count indicating that ndlp can be
892 * safely released when other references to it are done.
896 ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
899 * Cannot find existing Fabric ndlp, so allocate a
902 ndlp = lpfc_nlp_init(vport, PT2PT_RemoteID);
905 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
906 ndlp = lpfc_enable_node(vport, ndlp,
907 NLP_STE_UNUSED_NODE);
912 memcpy(&ndlp->nlp_portname, &sp->portName,
913 sizeof(struct lpfc_name));
914 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
915 sizeof(struct lpfc_name));
916 /* Set state will put ndlp onto node list if not already done */
917 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
918 spin_lock_irq(shost->host_lock);
919 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
920 spin_unlock_irq(shost->host_lock);
922 /* This side will wait for the PLOGI, decrement ndlp reference
923 * count indicating that ndlp can be released when other
924 * references to it are done.
928 /* If we are pt2pt with another NPort, force NPIV off! */
929 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
931 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
935 lpfc_config_link(phba, mbox);
937 mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link;
939 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
940 if (rc == MBX_NOT_FINISHED) {
941 mempool_free(mbox, phba->mbox_mem_pool);
951 * lpfc_cmpl_els_flogi - Completion callback function for flogi
952 * @phba: pointer to lpfc hba data structure.
953 * @cmdiocb: pointer to lpfc command iocb data structure.
954 * @rspiocb: pointer to lpfc response iocb data structure.
956 * This routine is the top-level completion callback function for issuing
957 * a Fabric Login (FLOGI) command. If the response IOCB reported error,
958 * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If
959 * retry has been made (either immediately or delayed with lpfc_els_retry()
960 * returning 1), the command IOCB will be released and function returned.
961 * If the retry attempt has been given up (possibly reach the maximum
962 * number of retries), one additional decrement of ndlp reference shall be
963 * invoked before going out after releasing the command IOCB. This will
964 * actually release the remote node (Note, lpfc_els_free_iocb() will also
965 * invoke one decrement of ndlp reference count). If no error reported in
966 * the IOCB status, the command Port ID field is used to determine whether
967 * this is a point-to-point topology or a fabric topology: if the Port ID
968 * field is assigned, it is a fabric topology; otherwise, it is a
969 * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or
970 * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the
971 * specific topology completion conditions.
974 lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
975 struct lpfc_iocbq *rspiocb)
977 struct lpfc_vport *vport = cmdiocb->vport;
978 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
979 IOCB_t *irsp = &rspiocb->iocb;
980 struct lpfc_nodelist *ndlp = cmdiocb->context1;
981 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
982 struct serv_parm *sp;
986 /* Check to see if link went down during discovery */
987 if (lpfc_els_chk_latt(vport)) {
988 /* One additional decrement on node reference count to
989 * trigger the release of the node
995 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
996 "FLOGI cmpl: status:x%x/x%x state:x%x",
997 irsp->ulpStatus, irsp->un.ulpWord[4],
1000 if (irsp->ulpStatus) {
1002 * In case of FIP mode, perform roundrobin FCF failover
1003 * due to new FCF discovery
1005 if ((phba->hba_flag & HBA_FIP_SUPPORT) &&
1006 (phba->fcf.fcf_flag & FCF_DISCOVERY)) {
1007 if (phba->link_state < LPFC_LINK_UP)
1008 goto stop_rr_fcf_flogi;
1009 if ((phba->fcoe_cvl_eventtag_attn ==
1010 phba->fcoe_cvl_eventtag) &&
1011 (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
1012 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1014 goto stop_rr_fcf_flogi;
1016 phba->fcoe_cvl_eventtag_attn =
1017 phba->fcoe_cvl_eventtag;
1018 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
1019 "2611 FLOGI failed on FCF (x%x), "
1020 "status:x%x/x%x, tmo:x%x, perform "
1021 "roundrobin FCF failover\n",
1022 phba->fcf.current_rec.fcf_indx,
1023 irsp->ulpStatus, irsp->un.ulpWord[4],
1025 lpfc_sli4_set_fcf_flogi_fail(phba,
1026 phba->fcf.current_rec.fcf_indx);
1027 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
1028 rc = lpfc_sli4_fcf_rr_next_proc(vport, fcf_index);
1035 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1036 "2858 FLOGI failure Status:x%x/x%x TMO:x%x "
1038 irsp->ulpStatus, irsp->un.ulpWord[4],
1039 irsp->ulpTimeout, phba->hba_flag,
1040 phba->fcf.fcf_flag);
1042 /* Check for retry */
1043 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
1047 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1048 "0100 FLOGI failure Status:x%x/x%x TMO:x%x\n",
1049 irsp->ulpStatus, irsp->un.ulpWord[4],
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 /* FLOGI failed, so there is no fabric */
1060 spin_lock_irq(shost->host_lock);
1061 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
1062 spin_unlock_irq(shost->host_lock);
1064 /* If private loop, then allow max outstanding els to be
1065 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
1066 * alpa map would take too long otherwise.
1068 if (phba->alpa_map[0] == 0)
1069 vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
1070 if ((phba->sli_rev == LPFC_SLI_REV4) &&
1071 (!(vport->fc_flag & FC_VFI_REGISTERED) ||
1072 (vport->fc_prevDID != vport->fc_myDID) ||
1073 phba->fc_topology_changed)) {
1074 if (vport->fc_flag & FC_VFI_REGISTERED) {
1075 if (phba->fc_topology_changed) {
1076 lpfc_unregister_fcf_prep(phba);
1077 spin_lock_irq(shost->host_lock);
1078 vport->fc_flag &= ~FC_VFI_REGISTERED;
1079 spin_unlock_irq(shost->host_lock);
1080 phba->fc_topology_changed = 0;
1082 lpfc_sli4_unreg_all_rpis(vport);
1086 /* Do not register VFI if the driver aborted FLOGI */
1087 if (!lpfc_error_lost_link(irsp))
1088 lpfc_issue_reg_vfi(vport);
1094 spin_lock_irq(shost->host_lock);
1095 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
1096 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
1097 spin_unlock_irq(shost->host_lock);
1100 * The FLogI succeeded. Sync the data for the CPU before
1103 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
1106 sp = prsp->virt + sizeof(uint32_t);
1108 /* FLOGI completes successfully */
1109 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1110 "0101 FLOGI completes successfully, I/O tag:x%x, "
1111 "Data: x%x x%x x%x x%x x%x x%x\n", cmdiocb->iotag,
1112 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
1113 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution,
1114 vport->port_state, vport->fc_flag);
1116 if (vport->port_state == LPFC_FLOGI) {
1118 * If Common Service Parameters indicate Nport
1119 * we are point to point, if Fport we are Fabric.
1122 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
1123 else if (!(phba->hba_flag & HBA_FCOE_MODE))
1124 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
1126 lpfc_printf_vlog(vport, KERN_ERR,
1128 "2831 FLOGI response with cleared Fabric "
1129 "bit fcf_index 0x%x "
1130 "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x "
1132 "%02x%02x%02x%02x%02x%02x%02x%02x\n",
1133 phba->fcf.current_rec.fcf_indx,
1134 phba->fcf.current_rec.switch_name[0],
1135 phba->fcf.current_rec.switch_name[1],
1136 phba->fcf.current_rec.switch_name[2],
1137 phba->fcf.current_rec.switch_name[3],
1138 phba->fcf.current_rec.switch_name[4],
1139 phba->fcf.current_rec.switch_name[5],
1140 phba->fcf.current_rec.switch_name[6],
1141 phba->fcf.current_rec.switch_name[7],
1142 phba->fcf.current_rec.fabric_name[0],
1143 phba->fcf.current_rec.fabric_name[1],
1144 phba->fcf.current_rec.fabric_name[2],
1145 phba->fcf.current_rec.fabric_name[3],
1146 phba->fcf.current_rec.fabric_name[4],
1147 phba->fcf.current_rec.fabric_name[5],
1148 phba->fcf.current_rec.fabric_name[6],
1149 phba->fcf.current_rec.fabric_name[7]);
1151 spin_lock_irq(&phba->hbalock);
1152 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
1153 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
1154 spin_unlock_irq(&phba->hbalock);
1155 phba->fcf.fcf_redisc_attempted = 0; /* reset */
1159 /* Mark the FCF discovery process done */
1160 if (phba->hba_flag & HBA_FIP_SUPPORT)
1161 lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP |
1163 "2769 FLOGI to FCF (x%x) "
1164 "completed successfully\n",
1165 phba->fcf.current_rec.fcf_indx);
1166 spin_lock_irq(&phba->hbalock);
1167 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
1168 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
1169 spin_unlock_irq(&phba->hbalock);
1170 phba->fcf.fcf_redisc_attempted = 0; /* reset */
1173 } else if (vport->port_state > LPFC_FLOGI &&
1174 vport->fc_flag & FC_PT2PT) {
1176 * In a p2p topology, it is possible that discovery has
1177 * already progressed, and this completion can be ignored.
1178 * Recheck the indicated topology.
1185 spin_lock_irq(&phba->hbalock);
1186 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
1187 spin_unlock_irq(&phba->hbalock);
1191 if (!lpfc_error_lost_link(irsp)) {
1192 /* FLOGI failed, so just use loop map to make discovery list */
1193 lpfc_disc_list_loopmap(vport);
1195 /* Start discovery */
1196 lpfc_disc_start(vport);
1197 } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
1198 (((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
1199 IOERR_SLI_ABORTED) &&
1200 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
1201 IOERR_SLI_DOWN))) &&
1202 (phba->link_state != LPFC_CLEAR_LA)) {
1203 /* If FLOGI failed enable link interrupt. */
1204 lpfc_issue_clear_la(phba, vport);
1207 lpfc_els_free_iocb(phba, cmdiocb);
1211 * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport
1212 * @vport: pointer to a host virtual N_Port data structure.
1213 * @ndlp: pointer to a node-list data structure.
1214 * @retry: number of retries to the command IOCB.
1216 * This routine issues a Fabric Login (FLOGI) Request ELS command
1217 * for a @vport. The initiator service parameters are put into the payload
1218 * of the FLOGI Request IOCB and the top-level callback function pointer
1219 * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
1220 * function field. The lpfc_issue_fabric_iocb routine is invoked to send
1221 * out FLOGI ELS command with one outstanding fabric IOCB at a time.
1223 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1224 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1225 * will be stored into the context1 field of the IOCB for the completion
1226 * callback function to the FLOGI ELS command.
1229 * 0 - successfully issued flogi iocb for @vport
1230 * 1 - failed to issue flogi iocb for @vport
1233 lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1236 struct lpfc_hba *phba = vport->phba;
1237 struct serv_parm *sp;
1239 struct lpfc_iocbq *elsiocb;
1245 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
1246 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1247 ndlp->nlp_DID, ELS_CMD_FLOGI);
1252 icmd = &elsiocb->iocb;
1253 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1255 /* For FLOGI request, remainder of payload is service parameters */
1256 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
1257 pcmd += sizeof(uint32_t);
1258 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
1259 sp = (struct serv_parm *) pcmd;
1261 /* Setup CSPs accordingly for Fabric */
1262 sp->cmn.e_d_tov = 0;
1263 sp->cmn.w2.r_a_tov = 0;
1264 sp->cmn.virtual_fabric_support = 0;
1265 sp->cls1.classValid = 0;
1266 if (sp->cmn.fcphLow < FC_PH3)
1267 sp->cmn.fcphLow = FC_PH3;
1268 if (sp->cmn.fcphHigh < FC_PH3)
1269 sp->cmn.fcphHigh = FC_PH3;
1271 if (phba->sli_rev == LPFC_SLI_REV4) {
1272 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
1273 LPFC_SLI_INTF_IF_TYPE_0) {
1274 elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1);
1275 elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1);
1276 /* FLOGI needs to be 3 for WQE FCFI */
1277 /* Set the fcfi to the fcfi we registered with */
1278 elsiocb->iocb.ulpContext = phba->fcf.fcfi;
1280 /* Can't do SLI4 class2 without support sequence coalescing */
1281 sp->cls2.classValid = 0;
1282 sp->cls2.seqDelivery = 0;
1284 /* Historical, setting sequential-delivery bit for SLI3 */
1285 sp->cls2.seqDelivery = (sp->cls2.classValid) ? 1 : 0;
1286 sp->cls3.seqDelivery = (sp->cls3.classValid) ? 1 : 0;
1287 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
1288 sp->cmn.request_multiple_Nport = 1;
1289 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
1293 sp->cmn.request_multiple_Nport = 0;
1296 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
1297 icmd->un.elsreq64.myID = 0;
1298 icmd->un.elsreq64.fl = 1;
1301 tmo = phba->fc_ratov;
1302 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
1303 lpfc_set_disctmo(vport);
1304 phba->fc_ratov = tmo;
1306 phba->fc_stat.elsXmitFLOGI++;
1307 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
1309 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1310 "Issue FLOGI: opt:x%x",
1311 phba->sli3_options, 0, 0);
1313 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
1314 if (rc == IOCB_ERROR) {
1315 lpfc_els_free_iocb(phba, elsiocb);
1322 * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs
1323 * @phba: pointer to lpfc hba data structure.
1325 * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
1326 * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
1327 * list and issues an abort IOCB commond on each outstanding IOCB that
1328 * contains a active Fabric_DID ndlp. Note that this function is to issue
1329 * the abort IOCB command on all the outstanding IOCBs, thus when this
1330 * function returns, it does not guarantee all the IOCBs are actually aborted.
1333 * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0)
1336 lpfc_els_abort_flogi(struct lpfc_hba *phba)
1338 struct lpfc_sli_ring *pring;
1339 struct lpfc_iocbq *iocb, *next_iocb;
1340 struct lpfc_nodelist *ndlp;
1343 /* Abort outstanding I/O on NPort <nlp_DID> */
1344 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
1345 "0201 Abort outstanding I/O on NPort x%x\n",
1348 pring = lpfc_phba_elsring(phba);
1349 if (unlikely(!pring))
1353 * Check the txcmplq for an iocb that matches the nport the driver is
1356 spin_lock_irq(&phba->hbalock);
1357 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
1359 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR) {
1360 ndlp = (struct lpfc_nodelist *)(iocb->context1);
1361 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
1362 (ndlp->nlp_DID == Fabric_DID))
1363 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
1366 spin_unlock_irq(&phba->hbalock);
1372 * lpfc_initial_flogi - Issue an initial fabric login for a vport
1373 * @vport: pointer to a host virtual N_Port data structure.
1375 * This routine issues an initial Fabric Login (FLOGI) for the @vport
1376 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1377 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1378 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1379 * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
1380 * is then invoked with the @vport and the ndlp to perform the FLOGI for the
1384 * 0 - failed to issue initial flogi for @vport
1385 * 1 - successfully issued initial flogi for @vport
1388 lpfc_initial_flogi(struct lpfc_vport *vport)
1390 struct lpfc_nodelist *ndlp;
1392 vport->port_state = LPFC_FLOGI;
1393 lpfc_set_disctmo(vport);
1395 /* First look for the Fabric ndlp */
1396 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1398 /* Cannot find existing Fabric ndlp, so allocate a new one */
1399 ndlp = lpfc_nlp_init(vport, Fabric_DID);
1402 /* Set the node type */
1403 ndlp->nlp_type |= NLP_FABRIC;
1404 /* Put ndlp onto node list */
1405 lpfc_enqueue_node(vport, ndlp);
1406 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1407 /* re-setup ndlp without removing from node list */
1408 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1413 if (lpfc_issue_els_flogi(vport, ndlp, 0)) {
1414 /* This decrement of reference count to node shall kick off
1415 * the release of the node.
1424 * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport
1425 * @vport: pointer to a host virtual N_Port data structure.
1427 * This routine issues an initial Fabric Discover (FDISC) for the @vport
1428 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1429 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1430 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1431 * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
1432 * is then invoked with the @vport and the ndlp to perform the FDISC for the
1436 * 0 - failed to issue initial fdisc for @vport
1437 * 1 - successfully issued initial fdisc for @vport
1440 lpfc_initial_fdisc(struct lpfc_vport *vport)
1442 struct lpfc_nodelist *ndlp;
1444 /* First look for the Fabric ndlp */
1445 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1447 /* Cannot find existing Fabric ndlp, so allocate a new one */
1448 ndlp = lpfc_nlp_init(vport, Fabric_DID);
1451 /* Put ndlp onto node list */
1452 lpfc_enqueue_node(vport, ndlp);
1453 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1454 /* re-setup ndlp without removing from node list */
1455 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1460 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
1461 /* decrement node reference count to trigger the release of
1471 * lpfc_more_plogi - Check and issue remaining plogis for a vport
1472 * @vport: pointer to a host virtual N_Port data structure.
1474 * This routine checks whether there are more remaining Port Logins
1475 * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
1476 * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
1477 * to issue ELS PLOGIs up to the configured discover threads with the
1478 * @vport (@vport->cfg_discovery_threads). The function also decrement
1479 * the @vport's num_disc_node by 1 if it is not already 0.
1482 lpfc_more_plogi(struct lpfc_vport *vport)
1484 if (vport->num_disc_nodes)
1485 vport->num_disc_nodes--;
1487 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
1488 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1489 "0232 Continue discovery with %d PLOGIs to go "
1490 "Data: x%x x%x x%x\n",
1491 vport->num_disc_nodes, vport->fc_plogi_cnt,
1492 vport->fc_flag, vport->port_state);
1493 /* Check to see if there are more PLOGIs to be sent */
1494 if (vport->fc_flag & FC_NLP_MORE)
1495 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
1496 lpfc_els_disc_plogi(vport);
1502 * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp
1503 * @phba: pointer to lpfc hba data structure.
1504 * @prsp: pointer to response IOCB payload.
1505 * @ndlp: pointer to a node-list data structure.
1507 * This routine checks and indicates whether the WWPN of an N_Port, retrieved
1508 * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
1509 * The following cases are considered N_Port confirmed:
1510 * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
1511 * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
1512 * it does not have WWPN assigned either. If the WWPN is confirmed, the
1513 * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
1514 * 1) if there is a node on vport list other than the @ndlp with the same
1515 * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
1516 * on that node to release the RPI associated with the node; 2) if there is
1517 * no node found on vport list with the same WWPN of the N_Port PLOGI logged
1518 * into, a new node shall be allocated (or activated). In either case, the
1519 * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
1520 * be released and the new_ndlp shall be put on to the vport node list and
1521 * its pointer returned as the confirmed node.
1523 * Note that before the @ndlp got "released", the keepDID from not-matching
1524 * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
1525 * of the @ndlp. This is because the release of @ndlp is actually to put it
1526 * into an inactive state on the vport node list and the vport node list
1527 * management algorithm does not allow two node with a same DID.
1530 * pointer to the PLOGI N_Port @ndlp
1532 static struct lpfc_nodelist *
1533 lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
1534 struct lpfc_nodelist *ndlp)
1536 struct lpfc_vport *vport = ndlp->vport;
1537 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1538 struct lpfc_nodelist *new_ndlp;
1539 struct lpfc_rport_data *rdata;
1540 struct fc_rport *rport;
1541 struct serv_parm *sp;
1542 uint8_t name[sizeof(struct lpfc_name)];
1543 uint32_t rc, keepDID = 0, keep_nlp_flag = 0;
1544 uint16_t keep_nlp_state;
1545 struct lpfc_nvme_rport *keep_nrport = NULL;
1548 unsigned long *active_rrqs_xri_bitmap = NULL;
1550 /* Fabric nodes can have the same WWPN so we don't bother searching
1551 * by WWPN. Just return the ndlp that was given to us.
1553 if (ndlp->nlp_type & NLP_FABRIC)
1556 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
1557 memset(name, 0, sizeof(struct lpfc_name));
1559 /* Now we find out if the NPort we are logging into, matches the WWPN
1560 * we have for that ndlp. If not, we have some work to do.
1562 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
1564 /* return immediately if the WWPN matches ndlp */
1565 if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp))
1568 if (phba->sli_rev == LPFC_SLI_REV4) {
1569 active_rrqs_xri_bitmap = mempool_alloc(phba->active_rrq_pool,
1571 if (active_rrqs_xri_bitmap)
1572 memset(active_rrqs_xri_bitmap, 0,
1573 phba->cfg_rrq_xri_bitmap_sz);
1576 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_NODE,
1577 "3178 PLOGI confirm: ndlp x%x x%x x%x: "
1578 "new_ndlp x%x x%x x%x\n",
1579 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_fc4_type,
1580 (new_ndlp ? new_ndlp->nlp_DID : 0),
1581 (new_ndlp ? new_ndlp->nlp_flag : 0),
1582 (new_ndlp ? new_ndlp->nlp_fc4_type : 0));
1585 rc = memcmp(&ndlp->nlp_portname, name,
1586 sizeof(struct lpfc_name));
1588 if (active_rrqs_xri_bitmap)
1589 mempool_free(active_rrqs_xri_bitmap,
1590 phba->active_rrq_pool);
1593 new_ndlp = lpfc_nlp_init(vport, ndlp->nlp_DID);
1595 if (active_rrqs_xri_bitmap)
1596 mempool_free(active_rrqs_xri_bitmap,
1597 phba->active_rrq_pool);
1600 } else if (!NLP_CHK_NODE_ACT(new_ndlp)) {
1601 rc = memcmp(&ndlp->nlp_portname, name,
1602 sizeof(struct lpfc_name));
1604 if (active_rrqs_xri_bitmap)
1605 mempool_free(active_rrqs_xri_bitmap,
1606 phba->active_rrq_pool);
1609 new_ndlp = lpfc_enable_node(vport, new_ndlp,
1610 NLP_STE_UNUSED_NODE);
1612 if (active_rrqs_xri_bitmap)
1613 mempool_free(active_rrqs_xri_bitmap,
1614 phba->active_rrq_pool);
1617 keepDID = new_ndlp->nlp_DID;
1618 if ((phba->sli_rev == LPFC_SLI_REV4) && active_rrqs_xri_bitmap)
1619 memcpy(active_rrqs_xri_bitmap,
1620 new_ndlp->active_rrqs_xri_bitmap,
1621 phba->cfg_rrq_xri_bitmap_sz);
1623 keepDID = new_ndlp->nlp_DID;
1624 if (phba->sli_rev == LPFC_SLI_REV4 &&
1625 active_rrqs_xri_bitmap)
1626 memcpy(active_rrqs_xri_bitmap,
1627 new_ndlp->active_rrqs_xri_bitmap,
1628 phba->cfg_rrq_xri_bitmap_sz);
1631 /* At this point in this routine, we know new_ndlp will be
1632 * returned. however, any previous GID_FTs that were done
1633 * would have updated nlp_fc4_type in ndlp, so we must ensure
1634 * new_ndlp has the right value.
1636 if (vport->fc_flag & FC_FABRIC)
1637 new_ndlp->nlp_fc4_type = ndlp->nlp_fc4_type;
1639 lpfc_unreg_rpi(vport, new_ndlp);
1640 new_ndlp->nlp_DID = ndlp->nlp_DID;
1641 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
1642 if (phba->sli_rev == LPFC_SLI_REV4)
1643 memcpy(new_ndlp->active_rrqs_xri_bitmap,
1644 ndlp->active_rrqs_xri_bitmap,
1645 phba->cfg_rrq_xri_bitmap_sz);
1647 spin_lock_irq(shost->host_lock);
1648 keep_nlp_flag = new_ndlp->nlp_flag;
1649 new_ndlp->nlp_flag = ndlp->nlp_flag;
1650 ndlp->nlp_flag = keep_nlp_flag;
1651 spin_unlock_irq(shost->host_lock);
1653 /* Set nlp_states accordingly */
1654 keep_nlp_state = new_ndlp->nlp_state;
1655 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
1657 /* interchange the nvme remoteport structs */
1658 keep_nrport = new_ndlp->nrport;
1659 new_ndlp->nrport = ndlp->nrport;
1661 /* Move this back to NPR state */
1662 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
1663 /* The new_ndlp is replacing ndlp totally, so we need
1664 * to put ndlp on UNUSED list and try to free it.
1666 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1667 "3179 PLOGI confirm NEW: %x %x\n",
1668 new_ndlp->nlp_DID, keepDID);
1670 /* Fix up the rport accordingly */
1671 rport = ndlp->rport;
1673 rdata = rport->dd_data;
1674 if (rdata->pnode == ndlp) {
1675 /* break the link before dropping the ref */
1678 rdata->pnode = lpfc_nlp_get(new_ndlp);
1679 new_ndlp->rport = rport;
1681 new_ndlp->nlp_type = ndlp->nlp_type;
1684 /* Fix up the nvme rport */
1686 ndlp->nrport = NULL;
1690 /* We shall actually free the ndlp with both nlp_DID and
1691 * nlp_portname fields equals 0 to avoid any ndlp on the
1692 * nodelist never to be used.
1694 if (ndlp->nlp_DID == 0) {
1695 spin_lock_irq(&phba->ndlp_lock);
1696 NLP_SET_FREE_REQ(ndlp);
1697 spin_unlock_irq(&phba->ndlp_lock);
1700 /* Two ndlps cannot have the same did on the nodelist */
1701 ndlp->nlp_DID = keepDID;
1702 if (phba->sli_rev == LPFC_SLI_REV4 &&
1703 active_rrqs_xri_bitmap)
1704 memcpy(ndlp->active_rrqs_xri_bitmap,
1705 active_rrqs_xri_bitmap,
1706 phba->cfg_rrq_xri_bitmap_sz);
1708 if (!NLP_CHK_NODE_ACT(ndlp))
1709 lpfc_drop_node(vport, ndlp);
1712 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1713 "3180 PLOGI confirm SWAP: %x %x\n",
1714 new_ndlp->nlp_DID, keepDID);
1716 lpfc_unreg_rpi(vport, ndlp);
1718 /* Two ndlps cannot have the same did */
1719 ndlp->nlp_DID = keepDID;
1720 if (phba->sli_rev == LPFC_SLI_REV4 &&
1721 active_rrqs_xri_bitmap)
1722 memcpy(ndlp->active_rrqs_xri_bitmap,
1723 active_rrqs_xri_bitmap,
1724 phba->cfg_rrq_xri_bitmap_sz);
1726 /* Since we are switching over to the new_ndlp,
1727 * reset the old ndlp state
1729 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
1730 (ndlp->nlp_state == NLP_STE_MAPPED_NODE))
1731 keep_nlp_state = NLP_STE_NPR_NODE;
1732 lpfc_nlp_set_state(vport, ndlp, keep_nlp_state);
1734 /* Previous ndlp no longer active with nvme host transport.
1735 * Remove reference from earlier registration unless the
1736 * nvme host took care of it.
1740 ndlp->nrport = keep_nrport;
1742 /* Fix up the rport accordingly */
1743 rport = ndlp->rport;
1745 rdata = rport->dd_data;
1746 put_node = rdata->pnode != NULL;
1747 put_rport = ndlp->rport != NULL;
1748 rdata->pnode = NULL;
1753 put_device(&rport->dev);
1756 if (phba->sli_rev == LPFC_SLI_REV4 &&
1757 active_rrqs_xri_bitmap)
1758 mempool_free(active_rrqs_xri_bitmap,
1759 phba->active_rrq_pool);
1761 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_NODE,
1762 "3173 PLOGI confirm exit: new_ndlp x%x x%x x%x\n",
1763 new_ndlp->nlp_DID, new_ndlp->nlp_flag,
1764 new_ndlp->nlp_fc4_type);
1770 * lpfc_end_rscn - Check and handle more rscn for a vport
1771 * @vport: pointer to a host virtual N_Port data structure.
1773 * This routine checks whether more Registration State Change
1774 * Notifications (RSCNs) came in while the discovery state machine was in
1775 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1776 * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1777 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1778 * handling the RSCNs.
1781 lpfc_end_rscn(struct lpfc_vport *vport)
1783 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1785 if (vport->fc_flag & FC_RSCN_MODE) {
1787 * Check to see if more RSCNs came in while we were
1788 * processing this one.
1790 if (vport->fc_rscn_id_cnt ||
1791 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
1792 lpfc_els_handle_rscn(vport);
1794 spin_lock_irq(shost->host_lock);
1795 vport->fc_flag &= ~FC_RSCN_MODE;
1796 spin_unlock_irq(shost->host_lock);
1802 * lpfc_cmpl_els_rrq - Completion handled for els RRQs.
1803 * @phba: pointer to lpfc hba data structure.
1804 * @cmdiocb: pointer to lpfc command iocb data structure.
1805 * @rspiocb: pointer to lpfc response iocb data structure.
1807 * This routine will call the clear rrq function to free the rrq and
1808 * clear the xri's bit in the ndlp's xri_bitmap. If the ndlp does not
1809 * exist then the clear_rrq is still called because the rrq needs to
1814 lpfc_cmpl_els_rrq(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1815 struct lpfc_iocbq *rspiocb)
1817 struct lpfc_vport *vport = cmdiocb->vport;
1819 struct lpfc_nodelist *ndlp;
1820 struct lpfc_node_rrq *rrq;
1822 /* we pass cmdiocb to state machine which needs rspiocb as well */
1823 rrq = cmdiocb->context_un.rrq;
1824 cmdiocb->context_un.rsp_iocb = rspiocb;
1826 irsp = &rspiocb->iocb;
1827 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1828 "RRQ cmpl: status:x%x/x%x did:x%x",
1829 irsp->ulpStatus, irsp->un.ulpWord[4],
1830 irsp->un.elsreq64.remoteID);
1832 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
1833 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || ndlp != rrq->ndlp) {
1834 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1835 "2882 RRQ completes to NPort x%x "
1836 "with no ndlp. Data: x%x x%x x%x\n",
1837 irsp->un.elsreq64.remoteID,
1838 irsp->ulpStatus, irsp->un.ulpWord[4],
1843 /* rrq completes to NPort <nlp_DID> */
1844 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1845 "2880 RRQ completes to NPort x%x "
1846 "Data: x%x x%x x%x x%x x%x\n",
1847 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1848 irsp->ulpTimeout, rrq->xritag, rrq->rxid);
1850 if (irsp->ulpStatus) {
1851 /* Check for retry */
1852 /* RRQ failed Don't print the vport to vport rjts */
1853 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1854 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1855 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1856 (phba)->pport->cfg_log_verbose & LOG_ELS)
1857 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1858 "2881 RRQ failure DID:%06X Status:x%x/x%x\n",
1859 ndlp->nlp_DID, irsp->ulpStatus,
1860 irsp->un.ulpWord[4]);
1864 lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
1865 lpfc_els_free_iocb(phba, cmdiocb);
1869 * lpfc_cmpl_els_plogi - Completion callback function for plogi
1870 * @phba: pointer to lpfc hba data structure.
1871 * @cmdiocb: pointer to lpfc command iocb data structure.
1872 * @rspiocb: pointer to lpfc response iocb data structure.
1874 * This routine is the completion callback function for issuing the Port
1875 * Login (PLOGI) command. For PLOGI completion, there must be an active
1876 * ndlp on the vport node list that matches the remote node ID from the
1877 * PLOGI response IOCB. If such ndlp does not exist, the PLOGI is simply
1878 * ignored and command IOCB released. The PLOGI response IOCB status is
1879 * checked for error conditons. If there is error status reported, PLOGI
1880 * retry shall be attempted by invoking the lpfc_els_retry() routine.
1881 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1882 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1883 * (DSM) is set for this PLOGI completion. Finally, it checks whether
1884 * there are additional N_Port nodes with the vport that need to perform
1885 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
1889 lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1890 struct lpfc_iocbq *rspiocb)
1892 struct lpfc_vport *vport = cmdiocb->vport;
1893 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1895 struct lpfc_nodelist *ndlp;
1896 struct lpfc_dmabuf *prsp;
1899 /* we pass cmdiocb to state machine which needs rspiocb as well */
1900 cmdiocb->context_un.rsp_iocb = rspiocb;
1902 irsp = &rspiocb->iocb;
1903 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1904 "PLOGI cmpl: status:x%x/x%x did:x%x",
1905 irsp->ulpStatus, irsp->un.ulpWord[4],
1906 irsp->un.elsreq64.remoteID);
1908 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
1909 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
1910 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1911 "0136 PLOGI completes to NPort x%x "
1912 "with no ndlp. Data: x%x x%x x%x\n",
1913 irsp->un.elsreq64.remoteID,
1914 irsp->ulpStatus, irsp->un.ulpWord[4],
1919 /* Since ndlp can be freed in the disc state machine, note if this node
1920 * is being used during discovery.
1922 spin_lock_irq(shost->host_lock);
1923 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
1924 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1925 spin_unlock_irq(shost->host_lock);
1928 /* PLOGI completes to NPort <nlp_DID> */
1929 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1930 "0102 PLOGI completes to NPort x%06x "
1931 "Data: x%x x%x x%x x%x x%x\n",
1932 ndlp->nlp_DID, ndlp->nlp_fc4_type,
1933 irsp->ulpStatus, irsp->un.ulpWord[4],
1934 disc, vport->num_disc_nodes);
1936 /* Check to see if link went down during discovery */
1937 if (lpfc_els_chk_latt(vport)) {
1938 spin_lock_irq(shost->host_lock);
1939 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1940 spin_unlock_irq(shost->host_lock);
1944 if (irsp->ulpStatus) {
1945 /* Check for retry */
1946 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1947 /* ELS command is being retried */
1949 spin_lock_irq(shost->host_lock);
1950 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1951 spin_unlock_irq(shost->host_lock);
1955 /* PLOGI failed Don't print the vport to vport rjts */
1956 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1957 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1958 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1959 (phba)->pport->cfg_log_verbose & LOG_ELS)
1960 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1961 "2753 PLOGI failure DID:%06X Status:x%x/x%x\n",
1962 ndlp->nlp_DID, irsp->ulpStatus,
1963 irsp->un.ulpWord[4]);
1964 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1965 if (lpfc_error_lost_link(irsp))
1966 rc = NLP_STE_FREED_NODE;
1968 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1969 NLP_EVT_CMPL_PLOGI);
1971 /* Good status, call state machine */
1972 prsp = list_entry(((struct lpfc_dmabuf *)
1973 cmdiocb->context2)->list.next,
1974 struct lpfc_dmabuf, list);
1975 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
1976 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1977 NLP_EVT_CMPL_PLOGI);
1980 if (disc && vport->num_disc_nodes) {
1981 /* Check to see if there are more PLOGIs to be sent */
1982 lpfc_more_plogi(vport);
1984 if (vport->num_disc_nodes == 0) {
1985 spin_lock_irq(shost->host_lock);
1986 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1987 spin_unlock_irq(shost->host_lock);
1989 lpfc_can_disctmo(vport);
1990 lpfc_end_rscn(vport);
1995 lpfc_els_free_iocb(phba, cmdiocb);
2000 * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
2001 * @vport: pointer to a host virtual N_Port data structure.
2002 * @did: destination port identifier.
2003 * @retry: number of retries to the command IOCB.
2005 * This routine issues a Port Login (PLOGI) command to a remote N_Port
2006 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
2007 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
2008 * This routine constructs the proper feilds of the PLOGI IOCB and invokes
2009 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
2011 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2012 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2013 * will be stored into the context1 field of the IOCB for the completion
2014 * callback function to the PLOGI ELS command.
2017 * 0 - Successfully issued a plogi for @vport
2018 * 1 - failed to issue a plogi for @vport
2021 lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
2023 struct lpfc_hba *phba = vport->phba;
2024 struct Scsi_Host *shost;
2025 struct serv_parm *sp;
2026 struct lpfc_nodelist *ndlp;
2027 struct lpfc_iocbq *elsiocb;
2032 ndlp = lpfc_findnode_did(vport, did);
2033 if (ndlp && !NLP_CHK_NODE_ACT(ndlp))
2036 /* If ndlp is not NULL, we will bump the reference count on it */
2037 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
2038 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
2043 shost = lpfc_shost_from_vport(vport);
2044 spin_lock_irq(shost->host_lock);
2045 ndlp->nlp_flag &= ~NLP_FCP_PRLI_RJT;
2046 spin_unlock_irq(shost->host_lock);
2048 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2050 /* For PLOGI request, remainder of payload is service parameters */
2051 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
2052 pcmd += sizeof(uint32_t);
2053 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
2054 sp = (struct serv_parm *) pcmd;
2057 * If we are a N-port connected to a Fabric, fix-up paramm's so logins
2058 * to device on remote loops work.
2060 if ((vport->fc_flag & FC_FABRIC) && !(vport->fc_flag & FC_PUBLIC_LOOP))
2061 sp->cmn.altBbCredit = 1;
2063 if (sp->cmn.fcphLow < FC_PH_4_3)
2064 sp->cmn.fcphLow = FC_PH_4_3;
2066 if (sp->cmn.fcphHigh < FC_PH3)
2067 sp->cmn.fcphHigh = FC_PH3;
2069 sp->cmn.valid_vendor_ver_level = 0;
2070 memset(sp->un.vendorVersion, 0, sizeof(sp->un.vendorVersion));
2071 sp->cmn.bbRcvSizeMsb &= 0xF;
2073 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2074 "Issue PLOGI: did:x%x",
2077 /* If our firmware supports this feature, convey that
2078 * information to the target using the vendor specific field.
2080 if (phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) {
2081 sp->cmn.valid_vendor_ver_level = 1;
2082 sp->un.vv.vid = cpu_to_be32(LPFC_VV_EMLX_ID);
2083 sp->un.vv.flags = cpu_to_be32(LPFC_VV_SUPPRESS_RSP);
2086 phba->fc_stat.elsXmitPLOGI++;
2087 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
2088 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
2090 if (ret == IOCB_ERROR) {
2091 lpfc_els_free_iocb(phba, elsiocb);
2098 * lpfc_cmpl_els_prli - Completion callback function for prli
2099 * @phba: pointer to lpfc hba data structure.
2100 * @cmdiocb: pointer to lpfc command iocb data structure.
2101 * @rspiocb: pointer to lpfc response iocb data structure.
2103 * This routine is the completion callback function for a Process Login
2104 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
2105 * status. If there is error status reported, PRLI retry shall be attempted
2106 * by invoking the lpfc_els_retry() routine. Otherwise, the state
2107 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
2108 * ndlp to mark the PRLI completion.
2111 lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2112 struct lpfc_iocbq *rspiocb)
2114 struct lpfc_vport *vport = cmdiocb->vport;
2115 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2117 struct lpfc_nodelist *ndlp;
2119 /* we pass cmdiocb to state machine which needs rspiocb as well */
2120 cmdiocb->context_un.rsp_iocb = rspiocb;
2122 irsp = &(rspiocb->iocb);
2123 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2124 spin_lock_irq(shost->host_lock);
2125 ndlp->nlp_flag &= ~NLP_PRLI_SND;
2127 /* Driver supports multiple FC4 types. Counters matter. */
2128 vport->fc_prli_sent--;
2129 ndlp->fc4_prli_sent--;
2130 spin_unlock_irq(shost->host_lock);
2132 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2133 "PRLI cmpl: status:x%x/x%x did:x%x",
2134 irsp->ulpStatus, irsp->un.ulpWord[4],
2137 /* PRLI completes to NPort <nlp_DID> */
2138 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2139 "0103 PRLI completes to NPort x%06x "
2140 "Data: x%x x%x x%x x%x\n",
2141 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2142 vport->num_disc_nodes, ndlp->fc4_prli_sent);
2144 /* Check to see if link went down during discovery */
2145 if (lpfc_els_chk_latt(vport))
2148 if (irsp->ulpStatus) {
2149 /* Check for retry */
2150 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2151 /* ELS command is being retried */
2156 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2157 "2754 PRLI failure DID:%06X Status:x%x/x%x, "
2159 ndlp->nlp_DID, irsp->ulpStatus,
2160 irsp->un.ulpWord[4], ndlp->fc4_prli_sent);
2162 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2163 if (lpfc_error_lost_link(irsp))
2166 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2169 /* Good status, call state machine. However, if another
2170 * PRLI is outstanding, don't call the state machine
2171 * because final disposition to Mapped or Unmapped is
2174 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2178 lpfc_els_free_iocb(phba, cmdiocb);
2183 * lpfc_issue_els_prli - Issue a prli iocb command for a vport
2184 * @vport: pointer to a host virtual N_Port data structure.
2185 * @ndlp: pointer to a node-list data structure.
2186 * @retry: number of retries to the command IOCB.
2188 * This routine issues a Process Login (PRLI) ELS command for the
2189 * @vport. The PRLI service parameters are set up in the payload of the
2190 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
2191 * is put to the IOCB completion callback func field before invoking the
2192 * routine lpfc_sli_issue_iocb() to send out PRLI command.
2194 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2195 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2196 * will be stored into the context1 field of the IOCB for the completion
2197 * callback function to the PRLI ELS command.
2200 * 0 - successfully issued prli iocb command for @vport
2201 * 1 - failed to issue prli iocb command for @vport
2204 lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2207 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2208 struct lpfc_hba *phba = vport->phba;
2210 struct lpfc_nvme_prli *npr_nvme;
2211 struct lpfc_iocbq *elsiocb;
2214 u32 local_nlp_type, elscmd;
2217 * If we are in RSCN mode, the FC4 types supported from a
2218 * previous GFT_ID command may not be accurate. So, if we
2219 * are a NVME Initiator, always look for the possibility of
2220 * the remote NPort beng a NVME Target.
2222 if (phba->sli_rev == LPFC_SLI_REV4 &&
2223 vport->fc_flag & FC_RSCN_MODE &&
2224 vport->nvmei_support)
2225 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
2226 local_nlp_type = ndlp->nlp_fc4_type;
2228 /* This routine will issue 1 or 2 PRLIs, so zero all the ndlp
2229 * fields here before any of them can complete.
2231 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
2232 ndlp->nlp_type &= ~(NLP_NVME_TARGET | NLP_NVME_INITIATOR);
2233 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
2234 ndlp->nlp_flag &= ~NLP_FIRSTBURST;
2235 ndlp->nvme_fb_size = 0;
2238 if (local_nlp_type & NLP_FC4_FCP) {
2239 /* Payload is 4 + 16 = 20 x14 bytes. */
2240 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
2241 elscmd = ELS_CMD_PRLI;
2242 } else if (local_nlp_type & NLP_FC4_NVME) {
2243 /* Payload is 4 + 20 = 24 x18 bytes. */
2244 cmdsize = (sizeof(uint32_t) + sizeof(struct lpfc_nvme_prli));
2245 elscmd = ELS_CMD_NVMEPRLI;
2247 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2248 "3083 Unknown FC_TYPE x%x ndlp x%06x\n",
2249 ndlp->nlp_fc4_type, ndlp->nlp_DID);
2253 /* SLI3 ports don't support NVME. If this rport is a strict NVME
2254 * FC4 type, implicitly LOGO.
2256 if (phba->sli_rev == LPFC_SLI_REV3 &&
2257 ndlp->nlp_fc4_type == NLP_FC4_NVME) {
2258 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2259 "3088 Rport fc4 type 0x%x not supported by SLI3 adapter\n",
2261 lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM);
2265 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2266 ndlp->nlp_DID, elscmd);
2270 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2272 /* For PRLI request, remainder of payload is service parameters */
2273 memset(pcmd, 0, cmdsize);
2275 if (local_nlp_type & NLP_FC4_FCP) {
2276 /* Remainder of payload is FCP PRLI parameter page.
2277 * Note: this data structure is defined as
2278 * BE/LE in the structure definition so no
2279 * byte swap call is made.
2281 *((uint32_t *)(pcmd)) = ELS_CMD_PRLI;
2282 pcmd += sizeof(uint32_t);
2286 * If our firmware version is 3.20 or later,
2287 * set the following bits for FC-TAPE support.
2289 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
2290 npr->ConfmComplAllowed = 1;
2292 npr->TaskRetryIdReq = 1;
2294 npr->estabImagePair = 1;
2295 npr->readXferRdyDis = 1;
2296 if (vport->cfg_first_burst_size)
2297 npr->writeXferRdyDis = 1;
2299 /* For FCP support */
2300 npr->prliType = PRLI_FCP_TYPE;
2301 npr->initiatorFunc = 1;
2302 elsiocb->iocb_flag |= LPFC_PRLI_FCP_REQ;
2304 /* Remove FCP type - processed. */
2305 local_nlp_type &= ~NLP_FC4_FCP;
2306 } else if (local_nlp_type & NLP_FC4_NVME) {
2307 /* Remainder of payload is NVME PRLI parameter page.
2308 * This data structure is the newer definition that
2309 * uses bf macros so a byte swap is required.
2311 *((uint32_t *)(pcmd)) = ELS_CMD_NVMEPRLI;
2312 pcmd += sizeof(uint32_t);
2313 npr_nvme = (struct lpfc_nvme_prli *)pcmd;
2314 bf_set(prli_type_code, npr_nvme, PRLI_NVME_TYPE);
2315 bf_set(prli_estabImagePair, npr_nvme, 0); /* Should be 0 */
2317 /* Only initiators request first burst. */
2318 if ((phba->cfg_nvme_enable_fb) &&
2319 !phba->nvmet_support)
2320 bf_set(prli_fba, npr_nvme, 1);
2322 if (phba->nvmet_support) {
2323 bf_set(prli_tgt, npr_nvme, 1);
2324 bf_set(prli_disc, npr_nvme, 1);
2327 bf_set(prli_init, npr_nvme, 1);
2329 npr_nvme->word1 = cpu_to_be32(npr_nvme->word1);
2330 npr_nvme->word4 = cpu_to_be32(npr_nvme->word4);
2331 elsiocb->iocb_flag |= LPFC_PRLI_NVME_REQ;
2333 /* Remove NVME type - processed. */
2334 local_nlp_type &= ~NLP_FC4_NVME;
2337 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2338 "Issue PRLI: did:x%x",
2339 ndlp->nlp_DID, 0, 0);
2341 phba->fc_stat.elsXmitPRLI++;
2342 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
2343 spin_lock_irq(shost->host_lock);
2344 ndlp->nlp_flag |= NLP_PRLI_SND;
2346 /* The vport counters are used for lpfc_scan_finished, but
2347 * the ndlp is used to track outstanding PRLIs for different
2350 vport->fc_prli_sent++;
2351 ndlp->fc4_prli_sent++;
2352 spin_unlock_irq(shost->host_lock);
2353 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2355 spin_lock_irq(shost->host_lock);
2356 ndlp->nlp_flag &= ~NLP_PRLI_SND;
2357 spin_unlock_irq(shost->host_lock);
2358 lpfc_els_free_iocb(phba, elsiocb);
2363 /* The driver supports 2 FC4 types. Make sure
2364 * a PRLI is issued for all types before exiting.
2366 if (phba->sli_rev == LPFC_SLI_REV4 &&
2367 local_nlp_type & (NLP_FC4_FCP | NLP_FC4_NVME))
2368 goto send_next_prli;
2374 * lpfc_rscn_disc - Perform rscn discovery for a vport
2375 * @vport: pointer to a host virtual N_Port data structure.
2377 * This routine performs Registration State Change Notification (RSCN)
2378 * discovery for a @vport. If the @vport's node port recovery count is not
2379 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
2380 * the nodes that need recovery. If none of the PLOGI were needed through
2381 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
2382 * invoked to check and handle possible more RSCN came in during the period
2383 * of processing the current ones.
2386 lpfc_rscn_disc(struct lpfc_vport *vport)
2388 lpfc_can_disctmo(vport);
2390 /* RSCN discovery */
2391 /* go thru NPR nodes and issue ELS PLOGIs */
2392 if (vport->fc_npr_cnt)
2393 if (lpfc_els_disc_plogi(vport))
2396 lpfc_end_rscn(vport);
2400 * lpfc_adisc_done - Complete the adisc phase of discovery
2401 * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
2403 * This function is called when the final ADISC is completed during discovery.
2404 * This function handles clearing link attention or issuing reg_vpi depending
2405 * on whether npiv is enabled. This function also kicks off the PLOGI phase of
2407 * This function is called with no locks held.
2410 lpfc_adisc_done(struct lpfc_vport *vport)
2412 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2413 struct lpfc_hba *phba = vport->phba;
2416 * For NPIV, cmpl_reg_vpi will set port_state to READY,
2417 * and continue discovery.
2419 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2420 !(vport->fc_flag & FC_RSCN_MODE) &&
2421 (phba->sli_rev < LPFC_SLI_REV4)) {
2422 /* The ADISCs are complete. Doesn't matter if they
2423 * succeeded or failed because the ADISC completion
2424 * routine guarantees to call the state machine and
2425 * the RPI is either unregistered (failed ADISC response)
2426 * or the RPI is still valid and the node is marked
2427 * mapped for a target. The exchanges should be in the
2428 * correct state. This code is specific to SLI3.
2430 lpfc_issue_clear_la(phba, vport);
2431 lpfc_issue_reg_vpi(phba, vport);
2435 * For SLI2, we need to set port_state to READY
2436 * and continue discovery.
2438 if (vport->port_state < LPFC_VPORT_READY) {
2439 /* If we get here, there is nothing to ADISC */
2440 lpfc_issue_clear_la(phba, vport);
2441 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
2442 vport->num_disc_nodes = 0;
2443 /* go thru NPR list, issue ELS PLOGIs */
2444 if (vport->fc_npr_cnt)
2445 lpfc_els_disc_plogi(vport);
2446 if (!vport->num_disc_nodes) {
2447 spin_lock_irq(shost->host_lock);
2448 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2449 spin_unlock_irq(shost->host_lock);
2450 lpfc_can_disctmo(vport);
2451 lpfc_end_rscn(vport);
2454 vport->port_state = LPFC_VPORT_READY;
2456 lpfc_rscn_disc(vport);
2460 * lpfc_more_adisc - Issue more adisc as needed
2461 * @vport: pointer to a host virtual N_Port data structure.
2463 * This routine determines whether there are more ndlps on a @vport
2464 * node list need to have Address Discover (ADISC) issued. If so, it will
2465 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
2466 * remaining nodes which need to have ADISC sent.
2469 lpfc_more_adisc(struct lpfc_vport *vport)
2471 if (vport->num_disc_nodes)
2472 vport->num_disc_nodes--;
2473 /* Continue discovery with <num_disc_nodes> ADISCs to go */
2474 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2475 "0210 Continue discovery with %d ADISCs to go "
2476 "Data: x%x x%x x%x\n",
2477 vport->num_disc_nodes, vport->fc_adisc_cnt,
2478 vport->fc_flag, vport->port_state);
2479 /* Check to see if there are more ADISCs to be sent */
2480 if (vport->fc_flag & FC_NLP_MORE) {
2481 lpfc_set_disctmo(vport);
2482 /* go thru NPR nodes and issue any remaining ELS ADISCs */
2483 lpfc_els_disc_adisc(vport);
2485 if (!vport->num_disc_nodes)
2486 lpfc_adisc_done(vport);
2491 * lpfc_cmpl_els_adisc - Completion callback function for adisc
2492 * @phba: pointer to lpfc hba data structure.
2493 * @cmdiocb: pointer to lpfc command iocb data structure.
2494 * @rspiocb: pointer to lpfc response iocb data structure.
2496 * This routine is the completion function for issuing the Address Discover
2497 * (ADISC) command. It first checks to see whether link went down during
2498 * the discovery process. If so, the node will be marked as node port
2499 * recovery for issuing discover IOCB by the link attention handler and
2500 * exit. Otherwise, the response status is checked. If error was reported
2501 * in the response status, the ADISC command shall be retried by invoking
2502 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
2503 * the response status, the state machine is invoked to set transition
2504 * with respect to NLP_EVT_CMPL_ADISC event.
2507 lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2508 struct lpfc_iocbq *rspiocb)
2510 struct lpfc_vport *vport = cmdiocb->vport;
2511 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2513 struct lpfc_nodelist *ndlp;
2516 /* we pass cmdiocb to state machine which needs rspiocb as well */
2517 cmdiocb->context_un.rsp_iocb = rspiocb;
2519 irsp = &(rspiocb->iocb);
2520 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2522 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2523 "ADISC cmpl: status:x%x/x%x did:x%x",
2524 irsp->ulpStatus, irsp->un.ulpWord[4],
2527 /* Since ndlp can be freed in the disc state machine, note if this node
2528 * is being used during discovery.
2530 spin_lock_irq(shost->host_lock);
2531 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
2532 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
2533 spin_unlock_irq(shost->host_lock);
2534 /* ADISC completes to NPort <nlp_DID> */
2535 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2536 "0104 ADISC completes to NPort x%x "
2537 "Data: x%x x%x x%x x%x x%x\n",
2538 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2539 irsp->ulpTimeout, disc, vport->num_disc_nodes);
2540 /* Check to see if link went down during discovery */
2541 if (lpfc_els_chk_latt(vport)) {
2542 spin_lock_irq(shost->host_lock);
2543 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2544 spin_unlock_irq(shost->host_lock);
2548 if (irsp->ulpStatus) {
2549 /* Check for retry */
2550 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2551 /* ELS command is being retried */
2553 spin_lock_irq(shost->host_lock);
2554 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2555 spin_unlock_irq(shost->host_lock);
2556 lpfc_set_disctmo(vport);
2561 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2562 "2755 ADISC failure DID:%06X Status:x%x/x%x\n",
2563 ndlp->nlp_DID, irsp->ulpStatus,
2564 irsp->un.ulpWord[4]);
2565 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2566 if (!lpfc_error_lost_link(irsp))
2567 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2568 NLP_EVT_CMPL_ADISC);
2570 /* Good status, call state machine */
2571 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2572 NLP_EVT_CMPL_ADISC);
2574 /* Check to see if there are more ADISCs to be sent */
2575 if (disc && vport->num_disc_nodes)
2576 lpfc_more_adisc(vport);
2578 lpfc_els_free_iocb(phba, cmdiocb);
2583 * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
2584 * @vport: pointer to a virtual N_Port data structure.
2585 * @ndlp: pointer to a node-list data structure.
2586 * @retry: number of retries to the command IOCB.
2588 * This routine issues an Address Discover (ADISC) for an @ndlp on a
2589 * @vport. It prepares the payload of the ADISC ELS command, updates the
2590 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
2591 * to issue the ADISC ELS command.
2593 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2594 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2595 * will be stored into the context1 field of the IOCB for the completion
2596 * callback function to the ADISC ELS command.
2599 * 0 - successfully issued adisc
2600 * 1 - failed to issue adisc
2603 lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2606 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2607 struct lpfc_hba *phba = vport->phba;
2609 struct lpfc_iocbq *elsiocb;
2613 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
2614 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2615 ndlp->nlp_DID, ELS_CMD_ADISC);
2619 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2621 /* For ADISC request, remainder of payload is service parameters */
2622 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
2623 pcmd += sizeof(uint32_t);
2625 /* Fill in ADISC payload */
2626 ap = (ADISC *) pcmd;
2627 ap->hardAL_PA = phba->fc_pref_ALPA;
2628 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2629 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
2630 ap->DID = be32_to_cpu(vport->fc_myDID);
2632 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2633 "Issue ADISC: did:x%x",
2634 ndlp->nlp_DID, 0, 0);
2636 phba->fc_stat.elsXmitADISC++;
2637 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
2638 spin_lock_irq(shost->host_lock);
2639 ndlp->nlp_flag |= NLP_ADISC_SND;
2640 spin_unlock_irq(shost->host_lock);
2641 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2643 spin_lock_irq(shost->host_lock);
2644 ndlp->nlp_flag &= ~NLP_ADISC_SND;
2645 spin_unlock_irq(shost->host_lock);
2646 lpfc_els_free_iocb(phba, elsiocb);
2653 * lpfc_cmpl_els_logo - Completion callback function for logo
2654 * @phba: pointer to lpfc hba data structure.
2655 * @cmdiocb: pointer to lpfc command iocb data structure.
2656 * @rspiocb: pointer to lpfc response iocb data structure.
2658 * This routine is the completion function for issuing the ELS Logout (LOGO)
2659 * command. If no error status was reported from the LOGO response, the
2660 * state machine of the associated ndlp shall be invoked for transition with
2661 * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
2662 * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
2665 lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2666 struct lpfc_iocbq *rspiocb)
2668 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2669 struct lpfc_vport *vport = ndlp->vport;
2670 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2672 struct lpfcMboxq *mbox;
2673 unsigned long flags;
2674 uint32_t skip_recovery = 0;
2676 /* we pass cmdiocb to state machine which needs rspiocb as well */
2677 cmdiocb->context_un.rsp_iocb = rspiocb;
2679 irsp = &(rspiocb->iocb);
2680 spin_lock_irq(shost->host_lock);
2681 ndlp->nlp_flag &= ~NLP_LOGO_SND;
2682 spin_unlock_irq(shost->host_lock);
2684 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2685 "LOGO cmpl: status:x%x/x%x did:x%x",
2686 irsp->ulpStatus, irsp->un.ulpWord[4],
2689 /* LOGO completes to NPort <nlp_DID> */
2690 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2691 "0105 LOGO completes to NPort x%x "
2692 "Data: x%x x%x x%x x%x\n",
2693 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2694 irsp->ulpTimeout, vport->num_disc_nodes);
2696 if (lpfc_els_chk_latt(vport)) {
2701 /* Check to see if link went down during discovery */
2702 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
2703 /* NLP_EVT_DEVICE_RM should unregister the RPI
2704 * which should abort all outstanding IOs.
2706 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2712 /* The LOGO will not be retried on failure. A LOGO was
2713 * issued to the remote rport and a ACC or RJT or no Answer are
2714 * all acceptable. Note the failure and move forward with
2715 * discovery. The PLOGI will retry.
2717 if (irsp->ulpStatus) {
2719 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2720 "2756 LOGO failure, No Retry DID:%06X Status:x%x/x%x\n",
2721 ndlp->nlp_DID, irsp->ulpStatus,
2722 irsp->un.ulpWord[4]);
2723 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2724 if (lpfc_error_lost_link(irsp)) {
2730 /* Call state machine. This will unregister the rpi if needed. */
2731 lpfc_disc_state_machine(vport, ndlp, cmdiocb, NLP_EVT_CMPL_LOGO);
2734 lpfc_els_free_iocb(phba, cmdiocb);
2735 /* If we are in pt2pt mode, we could rcv new S_ID on PLOGI */
2736 if ((vport->fc_flag & FC_PT2PT) &&
2737 !(vport->fc_flag & FC_PT2PT_PLOGI)) {
2738 phba->pport->fc_myDID = 0;
2740 if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
2741 (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
2742 if (phba->nvmet_support)
2743 lpfc_nvmet_update_targetport(phba);
2745 lpfc_nvme_update_localport(phba->pport);
2748 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2750 lpfc_config_link(phba, mbox);
2751 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
2752 mbox->vport = vport;
2753 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) ==
2755 mempool_free(mbox, phba->mbox_mem_pool);
2762 * If the node is a target, the handling attempts to recover the port.
2763 * For any other port type, the rpi is unregistered as an implicit
2766 if (ndlp->nlp_type & (NLP_FCP_TARGET | NLP_NVME_TARGET) &&
2767 skip_recovery == 0) {
2768 lpfc_cancel_retry_delay_tmo(vport, ndlp);
2769 spin_lock_irqsave(shost->host_lock, flags);
2770 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2771 spin_unlock_irqrestore(shost->host_lock, flags);
2773 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2774 "3187 LOGO completes to NPort x%x: Start "
2775 "Recovery Data: x%x x%x x%x x%x\n",
2776 ndlp->nlp_DID, irsp->ulpStatus,
2777 irsp->un.ulpWord[4], irsp->ulpTimeout,
2778 vport->num_disc_nodes);
2779 lpfc_disc_start(vport);
2785 * lpfc_issue_els_logo - Issue a logo to an node on a vport
2786 * @vport: pointer to a virtual N_Port data structure.
2787 * @ndlp: pointer to a node-list data structure.
2788 * @retry: number of retries to the command IOCB.
2790 * This routine constructs and issues an ELS Logout (LOGO) iocb command
2791 * to a remote node, referred by an @ndlp on a @vport. It constructs the
2792 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
2793 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
2795 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2796 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2797 * will be stored into the context1 field of the IOCB for the completion
2798 * callback function to the LOGO ELS command.
2800 * Callers of this routine are expected to unregister the RPI first
2803 * 0 - successfully issued logo
2804 * 1 - failed to issue logo
2807 lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2810 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2811 struct lpfc_hba *phba = vport->phba;
2812 struct lpfc_iocbq *elsiocb;
2817 spin_lock_irq(shost->host_lock);
2818 if (ndlp->nlp_flag & NLP_LOGO_SND) {
2819 spin_unlock_irq(shost->host_lock);
2822 spin_unlock_irq(shost->host_lock);
2824 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
2825 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2826 ndlp->nlp_DID, ELS_CMD_LOGO);
2830 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2831 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
2832 pcmd += sizeof(uint32_t);
2834 /* Fill in LOGO payload */
2835 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
2836 pcmd += sizeof(uint32_t);
2837 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
2839 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2840 "Issue LOGO: did:x%x",
2841 ndlp->nlp_DID, 0, 0);
2843 phba->fc_stat.elsXmitLOGO++;
2844 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
2845 spin_lock_irq(shost->host_lock);
2846 ndlp->nlp_flag |= NLP_LOGO_SND;
2847 ndlp->nlp_flag &= ~NLP_ISSUE_LOGO;
2848 spin_unlock_irq(shost->host_lock);
2849 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
2850 if (rc == IOCB_ERROR) {
2851 spin_lock_irq(shost->host_lock);
2852 ndlp->nlp_flag &= ~NLP_LOGO_SND;
2853 spin_unlock_irq(shost->host_lock);
2854 lpfc_els_free_iocb(phba, elsiocb);
2858 spin_lock_irq(shost->host_lock);
2859 ndlp->nlp_prev_state = ndlp->nlp_state;
2860 spin_unlock_irq(shost->host_lock);
2861 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
2866 * lpfc_cmpl_els_cmd - Completion callback function for generic els command
2867 * @phba: pointer to lpfc hba data structure.
2868 * @cmdiocb: pointer to lpfc command iocb data structure.
2869 * @rspiocb: pointer to lpfc response iocb data structure.
2871 * This routine is a generic completion callback function for ELS commands.
2872 * Specifically, it is the callback function which does not need to perform
2873 * any command specific operations. It is currently used by the ELS command
2874 * issuing routines for the ELS State Change Request (SCR),
2875 * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution
2876 * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than
2877 * certain debug loggings, this callback function simply invokes the
2878 * lpfc_els_chk_latt() routine to check whether link went down during the
2879 * discovery process.
2882 lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2883 struct lpfc_iocbq *rspiocb)
2885 struct lpfc_vport *vport = cmdiocb->vport;
2888 irsp = &rspiocb->iocb;
2890 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2891 "ELS cmd cmpl: status:x%x/x%x did:x%x",
2892 irsp->ulpStatus, irsp->un.ulpWord[4],
2893 irsp->un.elsreq64.remoteID);
2894 /* ELS cmd tag <ulpIoTag> completes */
2895 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2896 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
2897 irsp->ulpIoTag, irsp->ulpStatus,
2898 irsp->un.ulpWord[4], irsp->ulpTimeout);
2899 /* Check to see if link went down during discovery */
2900 lpfc_els_chk_latt(vport);
2901 lpfc_els_free_iocb(phba, cmdiocb);
2906 * lpfc_issue_els_scr - Issue a scr to an node on a vport
2907 * @vport: pointer to a host virtual N_Port data structure.
2908 * @nportid: N_Port identifier to the remote node.
2909 * @retry: number of retries to the command IOCB.
2911 * This routine issues a State Change Request (SCR) to a fabric node
2912 * on a @vport. The remote node @nportid is passed into the function. It
2913 * first search the @vport node list to find the matching ndlp. If no such
2914 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
2915 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
2916 * routine is invoked to send the SCR IOCB.
2918 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2919 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2920 * will be stored into the context1 field of the IOCB for the completion
2921 * callback function to the SCR ELS command.
2924 * 0 - Successfully issued scr command
2925 * 1 - Failed to issue scr command
2928 lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
2930 struct lpfc_hba *phba = vport->phba;
2931 struct lpfc_iocbq *elsiocb;
2934 struct lpfc_nodelist *ndlp;
2936 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
2938 ndlp = lpfc_findnode_did(vport, nportid);
2940 ndlp = lpfc_nlp_init(vport, nportid);
2943 lpfc_enqueue_node(vport, ndlp);
2944 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2945 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2950 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2951 ndlp->nlp_DID, ELS_CMD_SCR);
2954 /* This will trigger the release of the node just
2961 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2963 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
2964 pcmd += sizeof(uint32_t);
2966 /* For SCR, remainder of payload is SCR parameter page */
2967 memset(pcmd, 0, sizeof(SCR));
2968 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
2970 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2971 "Issue SCR: did:x%x",
2972 ndlp->nlp_DID, 0, 0);
2974 phba->fc_stat.elsXmitSCR++;
2975 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
2976 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2978 /* The additional lpfc_nlp_put will cause the following
2979 * lpfc_els_free_iocb routine to trigger the rlease of
2983 lpfc_els_free_iocb(phba, elsiocb);
2986 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2987 * trigger the release of node.
2995 * lpfc_issue_els_farpr - Issue a farp to an node on a vport
2996 * @vport: pointer to a host virtual N_Port data structure.
2997 * @nportid: N_Port identifier to the remote node.
2998 * @retry: number of retries to the command IOCB.
3000 * This routine issues a Fibre Channel Address Resolution Response
3001 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
3002 * is passed into the function. It first search the @vport node list to find
3003 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
3004 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
3005 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
3007 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3008 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3009 * will be stored into the context1 field of the IOCB for the completion
3010 * callback function to the PARPR ELS command.
3013 * 0 - Successfully issued farpr command
3014 * 1 - Failed to issue farpr command
3017 lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
3019 struct lpfc_hba *phba = vport->phba;
3020 struct lpfc_iocbq *elsiocb;
3025 struct lpfc_nodelist *ondlp;
3026 struct lpfc_nodelist *ndlp;
3028 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
3030 ndlp = lpfc_findnode_did(vport, nportid);
3032 ndlp = lpfc_nlp_init(vport, nportid);
3035 lpfc_enqueue_node(vport, ndlp);
3036 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
3037 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
3042 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
3043 ndlp->nlp_DID, ELS_CMD_RNID);
3045 /* This will trigger the release of the node just
3052 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3054 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
3055 pcmd += sizeof(uint32_t);
3057 /* Fill in FARPR payload */
3058 fp = (FARP *) (pcmd);
3059 memset(fp, 0, sizeof(FARP));
3060 lp = (uint32_t *) pcmd;
3061 *lp++ = be32_to_cpu(nportid);
3062 *lp++ = be32_to_cpu(vport->fc_myDID);
3064 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
3066 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
3067 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
3068 ondlp = lpfc_findnode_did(vport, nportid);
3069 if (ondlp && NLP_CHK_NODE_ACT(ondlp)) {
3070 memcpy(&fp->OportName, &ondlp->nlp_portname,
3071 sizeof(struct lpfc_name));
3072 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
3073 sizeof(struct lpfc_name));
3076 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3077 "Issue FARPR: did:x%x",
3078 ndlp->nlp_DID, 0, 0);
3080 phba->fc_stat.elsXmitFARPR++;
3081 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
3082 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
3084 /* The additional lpfc_nlp_put will cause the following
3085 * lpfc_els_free_iocb routine to trigger the release of
3089 lpfc_els_free_iocb(phba, elsiocb);
3092 /* This will cause the callback-function lpfc_cmpl_els_cmd to
3093 * trigger the release of the node.
3100 * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
3101 * @vport: pointer to a host virtual N_Port data structure.
3102 * @nlp: pointer to a node-list data structure.
3104 * This routine cancels the timer with a delayed IOCB-command retry for
3105 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
3106 * removes the ELS retry event if it presents. In addition, if the
3107 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
3108 * commands are sent for the @vport's nodes that require issuing discovery
3112 lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
3114 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3115 struct lpfc_work_evt *evtp;
3117 if (!(nlp->nlp_flag & NLP_DELAY_TMO))
3119 spin_lock_irq(shost->host_lock);
3120 nlp->nlp_flag &= ~NLP_DELAY_TMO;
3121 spin_unlock_irq(shost->host_lock);
3122 del_timer_sync(&nlp->nlp_delayfunc);
3123 nlp->nlp_last_elscmd = 0;
3124 if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
3125 list_del_init(&nlp->els_retry_evt.evt_listp);
3126 /* Decrement nlp reference count held for the delayed retry */
3127 evtp = &nlp->els_retry_evt;
3128 lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
3130 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
3131 spin_lock_irq(shost->host_lock);
3132 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
3133 spin_unlock_irq(shost->host_lock);
3134 if (vport->num_disc_nodes) {
3135 if (vport->port_state < LPFC_VPORT_READY) {
3136 /* Check if there are more ADISCs to be sent */
3137 lpfc_more_adisc(vport);
3139 /* Check if there are more PLOGIs to be sent */
3140 lpfc_more_plogi(vport);
3141 if (vport->num_disc_nodes == 0) {
3142 spin_lock_irq(shost->host_lock);
3143 vport->fc_flag &= ~FC_NDISC_ACTIVE;
3144 spin_unlock_irq(shost->host_lock);
3145 lpfc_can_disctmo(vport);
3146 lpfc_end_rscn(vport);
3155 * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
3156 * @ptr: holder for the pointer to the timer function associated data (ndlp).
3158 * This routine is invoked by the ndlp delayed-function timer to check
3159 * whether there is any pending ELS retry event(s) with the node. If not, it
3160 * simply returns. Otherwise, if there is at least one ELS delayed event, it
3161 * adds the delayed events to the HBA work list and invokes the
3162 * lpfc_worker_wake_up() routine to wake up worker thread to process the
3163 * event. Note that lpfc_nlp_get() is called before posting the event to
3164 * the work list to hold reference count of ndlp so that it guarantees the
3165 * reference to ndlp will still be available when the worker thread gets
3166 * to the event associated with the ndlp.
3169 lpfc_els_retry_delay(unsigned long ptr)
3171 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr;
3172 struct lpfc_vport *vport = ndlp->vport;
3173 struct lpfc_hba *phba = vport->phba;
3174 unsigned long flags;
3175 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
3177 spin_lock_irqsave(&phba->hbalock, flags);
3178 if (!list_empty(&evtp->evt_listp)) {
3179 spin_unlock_irqrestore(&phba->hbalock, flags);
3183 /* We need to hold the node by incrementing the reference
3184 * count until the queued work is done
3186 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
3187 if (evtp->evt_arg1) {
3188 evtp->evt = LPFC_EVT_ELS_RETRY;
3189 list_add_tail(&evtp->evt_listp, &phba->work_list);
3190 lpfc_worker_wake_up(phba);
3192 spin_unlock_irqrestore(&phba->hbalock, flags);
3197 * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
3198 * @ndlp: pointer to a node-list data structure.
3200 * This routine is the worker-thread handler for processing the @ndlp delayed
3201 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
3202 * the last ELS command from the associated ndlp and invokes the proper ELS
3203 * function according to the delayed ELS command to retry the command.
3206 lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
3208 struct lpfc_vport *vport = ndlp->vport;
3209 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3210 uint32_t cmd, retry;
3212 spin_lock_irq(shost->host_lock);
3213 cmd = ndlp->nlp_last_elscmd;
3214 ndlp->nlp_last_elscmd = 0;
3216 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
3217 spin_unlock_irq(shost->host_lock);
3221 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
3222 spin_unlock_irq(shost->host_lock);
3224 * If a discovery event readded nlp_delayfunc after timer
3225 * firing and before processing the timer, cancel the
3228 del_timer_sync(&ndlp->nlp_delayfunc);
3229 retry = ndlp->nlp_retry;
3230 ndlp->nlp_retry = 0;
3234 lpfc_issue_els_flogi(vport, ndlp, retry);
3237 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
3238 ndlp->nlp_prev_state = ndlp->nlp_state;
3239 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
3243 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
3244 ndlp->nlp_prev_state = ndlp->nlp_state;
3245 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
3249 case ELS_CMD_NVMEPRLI:
3250 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
3251 ndlp->nlp_prev_state = ndlp->nlp_state;
3252 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
3256 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
3257 ndlp->nlp_prev_state = ndlp->nlp_state;
3258 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
3262 if (!(vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI))
3263 lpfc_issue_els_fdisc(vport, ndlp, retry);
3270 * lpfc_els_retry - Make retry decision on an els command iocb
3271 * @phba: pointer to lpfc hba data structure.
3272 * @cmdiocb: pointer to lpfc command iocb data structure.
3273 * @rspiocb: pointer to lpfc response iocb data structure.
3275 * This routine makes a retry decision on an ELS command IOCB, which has
3276 * failed. The following ELS IOCBs use this function for retrying the command
3277 * when previously issued command responsed with error status: FLOGI, PLOGI,
3278 * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
3279 * returned error status, it makes the decision whether a retry shall be
3280 * issued for the command, and whether a retry shall be made immediately or
3281 * delayed. In the former case, the corresponding ELS command issuing-function
3282 * is called to retry the command. In the later case, the ELS command shall
3283 * be posted to the ndlp delayed event and delayed function timer set to the
3284 * ndlp for the delayed command issusing.
3287 * 0 - No retry of els command is made
3288 * 1 - Immediate or delayed retry of els command is made
3291 lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3292 struct lpfc_iocbq *rspiocb)
3294 struct lpfc_vport *vport = cmdiocb->vport;
3295 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3296 IOCB_t *irsp = &rspiocb->iocb;
3297 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3298 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3301 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
3307 /* Note: context2 may be 0 for internal driver abort
3308 * of delays ELS command.
3311 if (pcmd && pcmd->virt) {
3312 elscmd = (uint32_t *) (pcmd->virt);
3316 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
3317 did = ndlp->nlp_DID;
3319 /* We should only hit this case for retrying PLOGI */
3320 did = irsp->un.elsreq64.remoteID;
3321 ndlp = lpfc_findnode_did(vport, did);
3322 if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp))
3323 && (cmd != ELS_CMD_PLOGI))
3327 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3328 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
3329 *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
3331 switch (irsp->ulpStatus) {
3332 case IOSTAT_FCP_RSP_ERROR:
3334 case IOSTAT_REMOTE_STOP:
3335 if (phba->sli_rev == LPFC_SLI_REV4) {
3336 /* This IO was aborted by the target, we don't
3337 * know the rxid and because we did not send the
3338 * ABTS we cannot generate and RRQ.
3340 lpfc_set_rrq_active(phba, ndlp,
3341 cmdiocb->sli4_lxritag, 0, 0);
3344 case IOSTAT_LOCAL_REJECT:
3345 switch ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK)) {
3346 case IOERR_LOOP_OPEN_FAILURE:
3347 if (cmd == ELS_CMD_FLOGI) {
3348 if (PCI_DEVICE_ID_HORNET ==
3349 phba->pcidev->device) {
3350 phba->fc_topology = LPFC_TOPOLOGY_LOOP;
3351 phba->pport->fc_myDID = 0;
3352 phba->alpa_map[0] = 0;
3353 phba->alpa_map[1] = 0;
3356 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
3361 case IOERR_ILLEGAL_COMMAND:
3362 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3363 "0124 Retry illegal cmd x%x "
3364 "retry:x%x delay:x%x\n",
3365 cmd, cmdiocb->retry, delay);
3367 /* All command's retry policy */
3369 if (cmdiocb->retry > 2)
3373 case IOERR_NO_RESOURCES:
3374 logerr = 1; /* HBA out of resources */
3376 if (cmdiocb->retry > 100)
3381 case IOERR_ILLEGAL_FRAME:
3386 case IOERR_SEQUENCE_TIMEOUT:
3387 case IOERR_INVALID_RPI:
3388 if (cmd == ELS_CMD_PLOGI &&
3389 did == NameServer_DID) {
3390 /* Continue forever if plogi to */
3391 /* the nameserver fails */
3400 case IOSTAT_NPORT_RJT:
3401 case IOSTAT_FABRIC_RJT:
3402 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
3408 case IOSTAT_NPORT_BSY:
3409 case IOSTAT_FABRIC_BSY:
3410 logerr = 1; /* Fabric / Remote NPort out of resources */
3415 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
3416 /* Added for Vendor specifc support
3417 * Just keep retrying for these Rsn / Exp codes
3419 switch (stat.un.b.lsRjtRsnCode) {
3420 case LSRJT_UNABLE_TPC:
3421 /* The driver has a VALID PLOGI but the rport has
3422 * rejected the PRLI - can't do it now. Delay
3423 * for 1 second and try again - don't care about
3426 if (cmd == ELS_CMD_PRLI || cmd == ELS_CMD_NVMEPRLI) {
3428 maxretry = lpfc_max_els_tries + 1;
3433 /* Legacy bug fix code for targets with PLOGI delays. */
3434 if (stat.un.b.lsRjtRsnCodeExp ==
3435 LSEXP_CMD_IN_PROGRESS) {
3436 if (cmd == ELS_CMD_PLOGI) {
3443 if (stat.un.b.lsRjtRsnCodeExp ==
3444 LSEXP_CANT_GIVE_DATA) {
3445 if (cmd == ELS_CMD_PLOGI) {
3452 if (cmd == ELS_CMD_PLOGI) {
3454 maxretry = lpfc_max_els_tries + 1;
3458 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
3459 (cmd == ELS_CMD_FDISC) &&
3460 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
3461 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3462 "0125 FDISC Failed (x%x). "
3463 "Fabric out of resources\n",
3464 stat.un.lsRjtError);
3465 lpfc_vport_set_state(vport,
3466 FC_VPORT_NO_FABRIC_RSCS);
3470 case LSRJT_LOGICAL_BSY:
3471 if ((cmd == ELS_CMD_PLOGI) ||
3472 (cmd == ELS_CMD_PRLI) ||
3473 (cmd == ELS_CMD_NVMEPRLI)) {
3476 } else if (cmd == ELS_CMD_FDISC) {
3477 /* FDISC retry policy */
3479 if (cmdiocb->retry >= 32)
3485 case LSRJT_LOGICAL_ERR:
3486 /* There are some cases where switches return this
3487 * error when they are not ready and should be returning
3488 * Logical Busy. We should delay every time.
3490 if (cmd == ELS_CMD_FDISC &&
3491 stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
3495 } else if (cmd == ELS_CMD_FLOGI &&
3496 stat.un.b.lsRjtRsnCodeExp ==
3497 LSEXP_NOTHING_MORE) {
3498 vport->fc_sparam.cmn.bbRcvSizeMsb &= 0xf;
3500 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3501 "0820 FLOGI Failed (x%x). "
3502 "BBCredit Not Supported\n",
3503 stat.un.lsRjtError);
3507 case LSRJT_PROTOCOL_ERR:
3508 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
3509 (cmd == ELS_CMD_FDISC) &&
3510 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
3511 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
3513 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3514 "0122 FDISC Failed (x%x). "
3515 "Fabric Detected Bad WWN\n",
3516 stat.un.lsRjtError);
3517 lpfc_vport_set_state(vport,
3518 FC_VPORT_FABRIC_REJ_WWN);
3521 case LSRJT_VENDOR_UNIQUE:
3522 if ((stat.un.b.vendorUnique == 0x45) &&
3523 (cmd == ELS_CMD_FLOGI)) {
3527 case LSRJT_CMD_UNSUPPORTED:
3528 /* lpfc nvmet returns this type of LS_RJT when it
3529 * receives an FCP PRLI because lpfc nvmet only
3530 * support NVME. ELS request is terminated for FCP4
3533 if (stat.un.b.lsRjtRsnCodeExp ==
3534 LSEXP_REQ_UNSUPPORTED && cmd == ELS_CMD_PRLI) {
3535 spin_lock_irq(shost->host_lock);
3536 ndlp->nlp_flag |= NLP_FCP_PRLI_RJT;
3537 spin_unlock_irq(shost->host_lock);
3545 case IOSTAT_INTERMED_RSP:
3553 if (did == FDMI_DID)
3556 if ((cmd == ELS_CMD_FLOGI) &&
3557 (phba->fc_topology != LPFC_TOPOLOGY_LOOP) &&
3558 !lpfc_error_lost_link(irsp)) {
3559 /* FLOGI retry policy */
3561 /* retry FLOGI forever */
3562 if (phba->link_flag != LS_LOOPBACK_MODE)
3567 if (cmdiocb->retry >= 100)
3569 else if (cmdiocb->retry >= 32)
3571 } else if ((cmd == ELS_CMD_FDISC) && !lpfc_error_lost_link(irsp)) {
3572 /* retry FDISCs every second up to devloss */
3574 maxretry = vport->cfg_devloss_tmo;
3579 if (maxretry && (cmdiocb->retry >= maxretry)) {
3580 phba->fc_stat.elsRetryExceeded++;
3584 if ((vport->load_flag & FC_UNLOADING) != 0)
3589 if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) {
3590 /* Stop retrying PLOGI and FDISC if in FCF discovery */
3591 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
3592 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3593 "2849 Stop retry ELS command "
3594 "x%x to remote NPORT x%x, "
3595 "Data: x%x x%x\n", cmd, did,
3596 cmdiocb->retry, delay);
3601 /* Retry ELS command <elsCmd> to remote NPORT <did> */
3602 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3603 "0107 Retry ELS command x%x to remote "
3604 "NPORT x%x Data: x%x x%x\n",
3605 cmd, did, cmdiocb->retry, delay);
3607 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
3608 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
3609 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
3610 IOERR_NO_RESOURCES))) {
3611 /* Don't reset timer for no resources */
3613 /* If discovery / RSCN timer is running, reset it */
3614 if (timer_pending(&vport->fc_disctmo) ||
3615 (vport->fc_flag & FC_RSCN_MODE))
3616 lpfc_set_disctmo(vport);
3619 phba->fc_stat.elsXmitRetry++;
3620 if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) {
3621 phba->fc_stat.elsDelayRetry++;
3622 ndlp->nlp_retry = cmdiocb->retry;
3624 /* delay is specified in milliseconds */
3625 mod_timer(&ndlp->nlp_delayfunc,
3626 jiffies + msecs_to_jiffies(delay));
3627 spin_lock_irq(shost->host_lock);
3628 ndlp->nlp_flag |= NLP_DELAY_TMO;
3629 spin_unlock_irq(shost->host_lock);
3631 ndlp->nlp_prev_state = ndlp->nlp_state;
3632 if ((cmd == ELS_CMD_PRLI) ||
3633 (cmd == ELS_CMD_NVMEPRLI))
3634 lpfc_nlp_set_state(vport, ndlp,
3635 NLP_STE_PRLI_ISSUE);
3637 lpfc_nlp_set_state(vport, ndlp,
3639 ndlp->nlp_last_elscmd = cmd;
3645 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
3648 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
3651 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
3652 ndlp->nlp_prev_state = ndlp->nlp_state;
3653 lpfc_nlp_set_state(vport, ndlp,
3654 NLP_STE_PLOGI_ISSUE);
3656 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
3659 ndlp->nlp_prev_state = ndlp->nlp_state;
3660 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
3661 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
3664 case ELS_CMD_NVMEPRLI:
3665 ndlp->nlp_prev_state = ndlp->nlp_state;
3666 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
3667 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
3670 ndlp->nlp_prev_state = ndlp->nlp_state;
3671 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
3672 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
3676 /* No retry ELS command <elsCmd> to remote NPORT <did> */
3678 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3679 "0137 No retry ELS command x%x to remote "
3680 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
3681 cmd, did, irsp->ulpStatus,
3682 irsp->un.ulpWord[4]);
3685 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3686 "0108 No retry ELS command x%x to remote "
3687 "NPORT x%x Retried:%d Error:x%x/%x\n",
3688 cmd, did, cmdiocb->retry, irsp->ulpStatus,
3689 irsp->un.ulpWord[4]);
3695 * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
3696 * @phba: pointer to lpfc hba data structure.
3697 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
3699 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
3700 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
3701 * checks to see whether there is a lpfc DMA buffer associated with the
3702 * response of the command IOCB. If so, it will be released before releasing
3703 * the lpfc DMA buffer associated with the IOCB itself.
3706 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3709 lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
3711 struct lpfc_dmabuf *buf_ptr;
3713 /* Free the response before processing the command. */
3714 if (!list_empty(&buf_ptr1->list)) {
3715 list_remove_head(&buf_ptr1->list, buf_ptr,
3718 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3721 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
3727 * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
3728 * @phba: pointer to lpfc hba data structure.
3729 * @buf_ptr: pointer to the lpfc dma buffer data structure.
3731 * This routine releases the lpfc Direct Memory Access (DMA) buffer
3732 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
3736 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3739 lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
3741 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3747 * lpfc_els_free_iocb - Free a command iocb and its associated resources
3748 * @phba: pointer to lpfc hba data structure.
3749 * @elsiocb: pointer to lpfc els command iocb data structure.
3751 * This routine frees a command IOCB and its associated resources. The
3752 * command IOCB data structure contains the reference to various associated
3753 * resources, these fields must be set to NULL if the associated reference
3755 * context1 - reference to ndlp
3756 * context2 - reference to cmd
3757 * context2->next - reference to rsp
3758 * context3 - reference to bpl
3760 * It first properly decrements the reference count held on ndlp for the
3761 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
3762 * set, it invokes the lpfc_els_free_data() routine to release the Direct
3763 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
3764 * adds the DMA buffer the @phba data structure for the delayed release.
3765 * If reference to the Buffer Pointer List (BPL) is present, the
3766 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
3767 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
3768 * invoked to release the IOCB data structure back to @phba IOCBQ list.
3771 * 0 - Success (currently, always return 0)
3774 lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
3776 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
3777 struct lpfc_nodelist *ndlp;
3779 ndlp = (struct lpfc_nodelist *)elsiocb->context1;
3781 if (ndlp->nlp_flag & NLP_DEFER_RM) {
3784 /* If the ndlp is not being used by another discovery
3787 if (!lpfc_nlp_not_used(ndlp)) {
3788 /* If ndlp is being used by another discovery
3789 * thread, just clear NLP_DEFER_RM
3791 ndlp->nlp_flag &= ~NLP_DEFER_RM;
3796 elsiocb->context1 = NULL;
3798 /* context2 = cmd, context2->next = rsp, context3 = bpl */
3799 if (elsiocb->context2) {
3800 if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
3801 /* Firmware could still be in progress of DMAing
3802 * payload, so don't free data buffer till after
3805 elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
3806 buf_ptr = elsiocb->context2;
3807 elsiocb->context2 = NULL;
3810 spin_lock_irq(&phba->hbalock);
3811 if (!list_empty(&buf_ptr->list)) {
3812 list_remove_head(&buf_ptr->list,
3813 buf_ptr1, struct lpfc_dmabuf,
3815 INIT_LIST_HEAD(&buf_ptr1->list);
3816 list_add_tail(&buf_ptr1->list,
3820 INIT_LIST_HEAD(&buf_ptr->list);
3821 list_add_tail(&buf_ptr->list, &phba->elsbuf);
3823 spin_unlock_irq(&phba->hbalock);
3826 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
3827 lpfc_els_free_data(phba, buf_ptr1);
3828 elsiocb->context2 = NULL;
3832 if (elsiocb->context3) {
3833 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
3834 lpfc_els_free_bpl(phba, buf_ptr);
3835 elsiocb->context3 = NULL;
3837 lpfc_sli_release_iocbq(phba, elsiocb);
3842 * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
3843 * @phba: pointer to lpfc hba data structure.
3844 * @cmdiocb: pointer to lpfc command iocb data structure.
3845 * @rspiocb: pointer to lpfc response iocb data structure.
3847 * This routine is the completion callback function to the Logout (LOGO)
3848 * Accept (ACC) Response ELS command. This routine is invoked to indicate
3849 * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
3850 * release the ndlp if it has the last reference remaining (reference count
3851 * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
3852 * field to NULL to inform the following lpfc_els_free_iocb() routine no
3853 * ndlp reference count needs to be decremented. Otherwise, the ndlp
3854 * reference use-count shall be decremented by the lpfc_els_free_iocb()
3855 * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
3856 * IOCB data structure.
3859 lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3860 struct lpfc_iocbq *rspiocb)
3862 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3863 struct lpfc_vport *vport = cmdiocb->vport;
3866 irsp = &rspiocb->iocb;
3867 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3868 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
3869 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
3870 /* ACC to LOGO completes to NPort <nlp_DID> */
3871 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3872 "0109 ACC to LOGO completes to NPort x%x "
3873 "Data: x%x x%x x%x\n",
3874 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3877 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
3878 /* NPort Recovery mode or node is just allocated */
3879 if (!lpfc_nlp_not_used(ndlp)) {
3880 /* If the ndlp is being used by another discovery
3881 * thread, just unregister the RPI.
3883 lpfc_unreg_rpi(vport, ndlp);
3885 /* Indicate the node has already released, should
3886 * not reference to it from within lpfc_els_free_iocb.
3888 cmdiocb->context1 = NULL;
3893 * The driver received a LOGO from the rport and has ACK'd it.
3894 * At this point, the driver is done so release the IOCB
3896 lpfc_els_free_iocb(phba, cmdiocb);
3900 * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
3901 * @phba: pointer to lpfc hba data structure.
3902 * @pmb: pointer to the driver internal queue element for mailbox command.
3904 * This routine is the completion callback function for unregister default
3905 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
3906 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
3907 * decrements the ndlp reference count held for this completion callback
3908 * function. After that, it invokes the lpfc_nlp_not_used() to check
3909 * whether there is only one reference left on the ndlp. If so, it will
3910 * perform one more decrement and trigger the release of the ndlp.
3913 lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3915 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
3916 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
3918 pmb->context1 = NULL;
3919 pmb->context2 = NULL;
3921 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3923 mempool_free(pmb, phba->mbox_mem_pool);
3925 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
3926 "0006 rpi%x DID:%x flg:%x %d map:%x %p\n",
3927 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
3928 kref_read(&ndlp->kref),
3929 ndlp->nlp_usg_map, ndlp);
3930 if (NLP_CHK_NODE_ACT(ndlp)) {
3932 /* This is the end of the default RPI cleanup logic for
3933 * this ndlp. If no other discovery threads are using
3934 * this ndlp, free all resources associated with it.
3936 lpfc_nlp_not_used(ndlp);
3938 lpfc_drop_node(ndlp->vport, ndlp);
3946 * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
3947 * @phba: pointer to lpfc hba data structure.
3948 * @cmdiocb: pointer to lpfc command iocb data structure.
3949 * @rspiocb: pointer to lpfc response iocb data structure.
3951 * This routine is the completion callback function for ELS Response IOCB
3952 * command. In normal case, this callback function just properly sets the
3953 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
3954 * field in the command IOCB is not NULL, the referred mailbox command will
3955 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
3956 * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
3957 * link down event occurred during the discovery, the lpfc_nlp_not_used()
3958 * routine shall be invoked trying to release the ndlp if no other threads
3959 * are currently referring it.
3962 lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3963 struct lpfc_iocbq *rspiocb)
3965 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3966 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
3967 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
3970 LPFC_MBOXQ_t *mbox = NULL;
3971 struct lpfc_dmabuf *mp = NULL;
3972 uint32_t ls_rjt = 0;
3974 irsp = &rspiocb->iocb;
3976 if (cmdiocb->context_un.mbox)
3977 mbox = cmdiocb->context_un.mbox;
3979 /* First determine if this is a LS_RJT cmpl. Note, this callback
3980 * function can have cmdiocb->contest1 (ndlp) field set to NULL.
3982 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
3983 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3984 (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) {
3985 /* A LS_RJT associated with Default RPI cleanup has its own
3986 * separate code path.
3988 if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
3992 /* Check to see if link went down during discovery */
3993 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) {
3995 mp = (struct lpfc_dmabuf *) mbox->context1;
3997 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4000 mempool_free(mbox, phba->mbox_mem_pool);
4002 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
4003 (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
4004 if (lpfc_nlp_not_used(ndlp)) {
4006 /* Indicate the node has already released,
4007 * should not reference to it from within
4008 * the routine lpfc_els_free_iocb.
4010 cmdiocb->context1 = NULL;
4015 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4016 "ELS rsp cmpl: status:x%x/x%x did:x%x",
4017 irsp->ulpStatus, irsp->un.ulpWord[4],
4018 cmdiocb->iocb.un.elsreq64.remoteID);
4019 /* ELS response tag <ulpIoTag> completes */
4020 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4021 "0110 ELS response tag x%x completes "
4022 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
4023 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
4024 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
4025 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4028 if ((rspiocb->iocb.ulpStatus == 0)
4029 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
4030 if (!lpfc_unreg_rpi(vport, ndlp) &&
4031 (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
4032 ndlp->nlp_state == NLP_STE_REG_LOGIN_ISSUE)) {
4033 lpfc_printf_vlog(vport, KERN_INFO,
4035 "0314 PLOGI recov DID x%x "
4036 "Data: x%x x%x x%x\n",
4037 ndlp->nlp_DID, ndlp->nlp_state,
4038 ndlp->nlp_rpi, ndlp->nlp_flag);
4039 mp = mbox->context1;
4041 lpfc_mbuf_free(phba, mp->virt,
4045 mempool_free(mbox, phba->mbox_mem_pool);
4049 /* Increment reference count to ndlp to hold the
4050 * reference to ndlp for the callback function.
4052 mbox->context2 = lpfc_nlp_get(ndlp);
4053 mbox->vport = vport;
4054 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
4055 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
4056 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
4059 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
4060 ndlp->nlp_prev_state = ndlp->nlp_state;
4061 lpfc_nlp_set_state(vport, ndlp,
4062 NLP_STE_REG_LOGIN_ISSUE);
4065 ndlp->nlp_flag |= NLP_REG_LOGIN_SEND;
4066 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
4067 != MBX_NOT_FINISHED)
4070 /* Decrement the ndlp reference count we
4071 * set for this failed mailbox command.
4074 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
4076 /* ELS rsp: Cannot issue reg_login for <NPortid> */
4077 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4078 "0138 ELS rsp: Cannot issue reg_login for x%x "
4079 "Data: x%x x%x x%x\n",
4080 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4083 if (lpfc_nlp_not_used(ndlp)) {
4085 /* Indicate node has already been released,
4086 * should not reference to it from within
4087 * the routine lpfc_els_free_iocb.
4089 cmdiocb->context1 = NULL;
4092 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
4093 if (!lpfc_error_lost_link(irsp) &&
4094 ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
4095 if (lpfc_nlp_not_used(ndlp)) {
4097 /* Indicate node has already been
4098 * released, should not reference
4099 * to it from within the routine
4100 * lpfc_els_free_iocb.
4102 cmdiocb->context1 = NULL;
4106 mp = (struct lpfc_dmabuf *) mbox->context1;
4108 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4111 mempool_free(mbox, phba->mbox_mem_pool);
4114 if (ndlp && NLP_CHK_NODE_ACT(ndlp) && shost) {
4115 spin_lock_irq(shost->host_lock);
4117 ndlp->nlp_flag &= ~NLP_ACC_REGLOGIN;
4118 ndlp->nlp_flag &= ~NLP_RM_DFLT_RPI;
4119 spin_unlock_irq(shost->host_lock);
4121 /* If the node is not being used by another discovery thread,
4122 * and we are sending a reject, we are done with it.
4123 * Release driver reference count here and free associated
4127 if (lpfc_nlp_not_used(ndlp))
4128 /* Indicate node has already been released,
4129 * should not reference to it from within
4130 * the routine lpfc_els_free_iocb.
4132 cmdiocb->context1 = NULL;
4136 lpfc_els_free_iocb(phba, cmdiocb);
4141 * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
4142 * @vport: pointer to a host virtual N_Port data structure.
4143 * @flag: the els command code to be accepted.
4144 * @oldiocb: pointer to the original lpfc command iocb data structure.
4145 * @ndlp: pointer to a node-list data structure.
4146 * @mbox: pointer to the driver internal queue element for mailbox command.
4148 * This routine prepares and issues an Accept (ACC) response IOCB
4149 * command. It uses the @flag to properly set up the IOCB field for the
4150 * specific ACC response command to be issued and invokes the
4151 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
4152 * @mbox pointer is passed in, it will be put into the context_un.mbox
4153 * field of the IOCB for the completion callback function to issue the
4154 * mailbox command to the HBA later when callback is invoked.
4156 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4157 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4158 * will be stored into the context1 field of the IOCB for the completion
4159 * callback function to the corresponding response ELS IOCB command.
4162 * 0 - Successfully issued acc response
4163 * 1 - Failed to issue acc response
4166 lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
4167 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
4170 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4171 struct lpfc_hba *phba = vport->phba;
4174 struct lpfc_iocbq *elsiocb;
4176 struct serv_parm *sp;
4179 ELS_PKT *els_pkt_ptr;
4181 oldcmd = &oldiocb->iocb;
4185 cmdsize = sizeof(uint32_t);
4186 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
4187 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
4189 spin_lock_irq(shost->host_lock);
4190 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
4191 spin_unlock_irq(shost->host_lock);
4195 icmd = &elsiocb->iocb;
4196 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4197 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4198 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4199 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4200 pcmd += sizeof(uint32_t);
4202 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4203 "Issue ACC: did:x%x flg:x%x",
4204 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4208 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
4209 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
4210 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
4214 icmd = &elsiocb->iocb;
4215 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4216 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4217 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4220 elsiocb->context_un.mbox = mbox;
4222 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4223 pcmd += sizeof(uint32_t);
4224 sp = (struct serv_parm *)pcmd;
4226 if (flag == ELS_CMD_FLOGI) {
4227 /* Copy the received service parameters back */
4228 memcpy(sp, &phba->fc_fabparam,
4229 sizeof(struct serv_parm));
4231 /* Clear the F_Port bit */
4234 /* Mark all class service parameters as invalid */
4235 sp->cls1.classValid = 0;
4236 sp->cls2.classValid = 0;
4237 sp->cls3.classValid = 0;
4238 sp->cls4.classValid = 0;
4240 /* Copy our worldwide names */
4241 memcpy(&sp->portName, &vport->fc_sparam.portName,
4242 sizeof(struct lpfc_name));
4243 memcpy(&sp->nodeName, &vport->fc_sparam.nodeName,
4244 sizeof(struct lpfc_name));
4246 memcpy(pcmd, &vport->fc_sparam,
4247 sizeof(struct serv_parm));
4249 sp->cmn.valid_vendor_ver_level = 0;
4250 memset(sp->un.vendorVersion, 0,
4251 sizeof(sp->un.vendorVersion));
4252 sp->cmn.bbRcvSizeMsb &= 0xF;
4254 /* If our firmware supports this feature, convey that
4255 * info to the target using the vendor specific field.
4257 if (phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) {
4258 sp->cmn.valid_vendor_ver_level = 1;
4259 sp->un.vv.vid = cpu_to_be32(LPFC_VV_EMLX_ID);
4261 cpu_to_be32(LPFC_VV_SUPPRESS_RSP);
4265 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4266 "Issue ACC FLOGI/PLOGI: did:x%x flg:x%x",
4267 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4270 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
4271 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
4272 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
4276 icmd = &elsiocb->iocb;
4277 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4278 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4279 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4281 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
4282 sizeof(uint32_t) + sizeof(PRLO));
4283 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
4284 els_pkt_ptr = (ELS_PKT *) pcmd;
4285 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
4287 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4288 "Issue ACC PRLO: did:x%x flg:x%x",
4289 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4294 /* Xmit ELS ACC response tag <ulpIoTag> */
4295 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4296 "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
4297 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x "
4299 elsiocb->iotag, elsiocb->iocb.ulpContext,
4300 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4301 ndlp->nlp_rpi, vport->fc_flag);
4302 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
4303 spin_lock_irq(shost->host_lock);
4304 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED ||
4305 ndlp->nlp_flag & NLP_REG_LOGIN_SEND))
4306 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
4307 spin_unlock_irq(shost->host_lock);
4308 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
4310 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4313 phba->fc_stat.elsXmitACC++;
4314 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4315 if (rc == IOCB_ERROR) {
4316 lpfc_els_free_iocb(phba, elsiocb);
4323 * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command
4324 * @vport: pointer to a virtual N_Port data structure.
4326 * @oldiocb: pointer to the original lpfc command iocb data structure.
4327 * @ndlp: pointer to a node-list data structure.
4328 * @mbox: pointer to the driver internal queue element for mailbox command.
4330 * This routine prepares and issue an Reject (RJT) response IOCB
4331 * command. If a @mbox pointer is passed in, it will be put into the
4332 * context_un.mbox field of the IOCB for the completion callback function
4333 * to issue to the HBA later.
4335 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4336 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4337 * will be stored into the context1 field of the IOCB for the completion
4338 * callback function to the reject response ELS IOCB command.
4341 * 0 - Successfully issued reject response
4342 * 1 - Failed to issue reject response
4345 lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
4346 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
4349 struct lpfc_hba *phba = vport->phba;
4352 struct lpfc_iocbq *elsiocb;
4357 cmdsize = 2 * sizeof(uint32_t);
4358 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4359 ndlp->nlp_DID, ELS_CMD_LS_RJT);
4363 icmd = &elsiocb->iocb;
4364 oldcmd = &oldiocb->iocb;
4365 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4366 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4367 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4369 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
4370 pcmd += sizeof(uint32_t);
4371 *((uint32_t *) (pcmd)) = rejectError;
4374 elsiocb->context_un.mbox = mbox;
4376 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
4377 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4378 "0129 Xmit ELS RJT x%x response tag x%x "
4379 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
4381 rejectError, elsiocb->iotag,
4382 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
4383 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
4384 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4385 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
4386 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
4388 phba->fc_stat.elsXmitLSRJT++;
4389 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4390 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4392 if (rc == IOCB_ERROR) {
4393 lpfc_els_free_iocb(phba, elsiocb);
4400 * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
4401 * @vport: pointer to a virtual N_Port data structure.
4402 * @oldiocb: pointer to the original lpfc command iocb data structure.
4403 * @ndlp: pointer to a node-list data structure.
4405 * This routine prepares and issues an Accept (ACC) response to Address
4406 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
4407 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
4409 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4410 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4411 * will be stored into the context1 field of the IOCB for the completion
4412 * callback function to the ADISC Accept response ELS IOCB command.
4415 * 0 - Successfully issued acc adisc response
4416 * 1 - Failed to issue adisc acc response
4419 lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
4420 struct lpfc_nodelist *ndlp)
4422 struct lpfc_hba *phba = vport->phba;
4424 IOCB_t *icmd, *oldcmd;
4425 struct lpfc_iocbq *elsiocb;
4430 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
4431 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4432 ndlp->nlp_DID, ELS_CMD_ACC);
4436 icmd = &elsiocb->iocb;
4437 oldcmd = &oldiocb->iocb;
4438 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4439 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4441 /* Xmit ADISC ACC response tag <ulpIoTag> */
4442 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4443 "0130 Xmit ADISC ACC response iotag x%x xri: "
4444 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
4445 elsiocb->iotag, elsiocb->iocb.ulpContext,
4446 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4448 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4450 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4451 pcmd += sizeof(uint32_t);
4453 ap = (ADISC *) (pcmd);
4454 ap->hardAL_PA = phba->fc_pref_ALPA;
4455 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
4456 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
4457 ap->DID = be32_to_cpu(vport->fc_myDID);
4459 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4460 "Issue ACC ADISC: did:x%x flg:x%x",
4461 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4463 phba->fc_stat.elsXmitACC++;
4464 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4465 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4466 if (rc == IOCB_ERROR) {
4467 lpfc_els_free_iocb(phba, elsiocb);
4474 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
4475 * @vport: pointer to a virtual N_Port data structure.
4476 * @oldiocb: pointer to the original lpfc command iocb data structure.
4477 * @ndlp: pointer to a node-list data structure.
4479 * This routine prepares and issues an Accept (ACC) response to Process
4480 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
4481 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
4483 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4484 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4485 * will be stored into the context1 field of the IOCB for the completion
4486 * callback function to the PRLI Accept response ELS IOCB command.
4489 * 0 - Successfully issued acc prli response
4490 * 1 - Failed to issue acc prli response
4493 lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
4494 struct lpfc_nodelist *ndlp)
4496 struct lpfc_hba *phba = vport->phba;
4498 struct lpfc_nvme_prli *npr_nvme;
4502 struct lpfc_iocbq *elsiocb;
4505 uint32_t prli_fc4_req, *req_payload;
4506 struct lpfc_dmabuf *req_buf;
4510 /* Need the incoming PRLI payload to determine if the ACC is for an
4511 * FC4 or NVME PRLI type. The PRLI type is at word 1.
4513 req_buf = (struct lpfc_dmabuf *)oldiocb->context2;
4514 req_payload = (((uint32_t *)req_buf->virt) + 1);
4516 /* PRLI type payload is at byte 3 for FCP or NVME. */
4517 prli_fc4_req = be32_to_cpu(*req_payload);
4518 prli_fc4_req = (prli_fc4_req >> 24) & 0xff;
4519 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4520 "6127 PRLI_ACC: Req Type x%x, Word1 x%08x\n",
4521 prli_fc4_req, *((uint32_t *)req_payload));
4523 if (prli_fc4_req == PRLI_FCP_TYPE) {
4524 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
4525 elsrspcmd = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
4526 } else if (prli_fc4_req & PRLI_NVME_TYPE) {
4527 cmdsize = sizeof(uint32_t) + sizeof(struct lpfc_nvme_prli);
4528 elsrspcmd = (ELS_CMD_ACC | (ELS_CMD_NVMEPRLI & ~ELS_RSP_MASK));
4533 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4534 ndlp->nlp_DID, elsrspcmd);
4538 icmd = &elsiocb->iocb;
4539 oldcmd = &oldiocb->iocb;
4540 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4541 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4543 /* Xmit PRLI ACC response tag <ulpIoTag> */
4544 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4545 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
4546 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
4547 elsiocb->iotag, elsiocb->iocb.ulpContext,
4548 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4550 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4551 memset(pcmd, 0, cmdsize);
4553 *((uint32_t *)(pcmd)) = elsrspcmd;
4554 pcmd += sizeof(uint32_t);
4556 /* For PRLI, remainder of payload is PRLI parameter page */
4559 if (prli_fc4_req == PRLI_FCP_TYPE) {
4561 * If the remote port is a target and our firmware version
4562 * is 3.20 or later, set the following bits for FC-TAPE
4565 npr = (PRLI *) pcmd;
4566 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
4567 (vpd->rev.feaLevelHigh >= 0x02)) {
4568 npr->ConfmComplAllowed = 1;
4570 npr->TaskRetryIdReq = 1;
4572 npr->acceptRspCode = PRLI_REQ_EXECUTED;
4573 npr->estabImagePair = 1;
4574 npr->readXferRdyDis = 1;
4575 npr->ConfmComplAllowed = 1;
4576 npr->prliType = PRLI_FCP_TYPE;
4577 npr->initiatorFunc = 1;
4578 } else if (prli_fc4_req & PRLI_NVME_TYPE) {
4579 /* Respond with an NVME PRLI Type */
4580 npr_nvme = (struct lpfc_nvme_prli *) pcmd;
4581 bf_set(prli_type_code, npr_nvme, PRLI_NVME_TYPE);
4582 bf_set(prli_estabImagePair, npr_nvme, 0); /* Should be 0 */
4583 bf_set(prli_acc_rsp_code, npr_nvme, PRLI_REQ_EXECUTED);
4584 if (phba->nvmet_support) {
4585 bf_set(prli_tgt, npr_nvme, 1);
4586 bf_set(prli_disc, npr_nvme, 1);
4587 if (phba->cfg_nvme_enable_fb) {
4588 bf_set(prli_fba, npr_nvme, 1);
4590 /* TBD. Target mode needs to post buffers
4591 * that support the configured first burst
4594 bf_set(prli_fb_sz, npr_nvme,
4595 phba->cfg_nvmet_fb_size);
4598 bf_set(prli_init, npr_nvme, 1);
4601 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
4602 "6015 NVME issue PRLI ACC word1 x%08x "
4603 "word4 x%08x word5 x%08x flag x%x, "
4604 "fcp_info x%x nlp_type x%x\n",
4605 npr_nvme->word1, npr_nvme->word4,
4606 npr_nvme->word5, ndlp->nlp_flag,
4607 ndlp->nlp_fcp_info, ndlp->nlp_type);
4608 npr_nvme->word1 = cpu_to_be32(npr_nvme->word1);
4609 npr_nvme->word4 = cpu_to_be32(npr_nvme->word4);
4610 npr_nvme->word5 = cpu_to_be32(npr_nvme->word5);
4612 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4613 "6128 Unknown FC_TYPE x%x x%x ndlp x%06x\n",
4614 prli_fc4_req, ndlp->nlp_fc4_type,
4617 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4618 "Issue ACC PRLI: did:x%x flg:x%x",
4619 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4621 phba->fc_stat.elsXmitACC++;
4622 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4624 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4625 if (rc == IOCB_ERROR) {
4626 lpfc_els_free_iocb(phba, elsiocb);
4633 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
4634 * @vport: pointer to a virtual N_Port data structure.
4635 * @format: rnid command format.
4636 * @oldiocb: pointer to the original lpfc command iocb data structure.
4637 * @ndlp: pointer to a node-list data structure.
4639 * This routine issues a Request Node Identification Data (RNID) Accept
4640 * (ACC) response. It constructs the RNID ACC response command according to
4641 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
4642 * issue the response. Note that this command does not need to hold the ndlp
4643 * reference count for the callback. So, the ndlp reference count taken by
4644 * the lpfc_prep_els_iocb() routine is put back and the context1 field of
4645 * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
4646 * there is no ndlp reference available.
4648 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4649 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4650 * will be stored into the context1 field of the IOCB for the completion
4651 * callback function. However, for the RNID Accept Response ELS command,
4652 * this is undone later by this routine after the IOCB is allocated.
4655 * 0 - Successfully issued acc rnid response
4656 * 1 - Failed to issue acc rnid response
4659 lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
4660 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
4662 struct lpfc_hba *phba = vport->phba;
4664 IOCB_t *icmd, *oldcmd;
4665 struct lpfc_iocbq *elsiocb;
4670 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
4671 + (2 * sizeof(struct lpfc_name));
4673 cmdsize += sizeof(RNID_TOP_DISC);
4675 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4676 ndlp->nlp_DID, ELS_CMD_ACC);
4680 icmd = &elsiocb->iocb;
4681 oldcmd = &oldiocb->iocb;
4682 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4683 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4685 /* Xmit RNID ACC response tag <ulpIoTag> */
4686 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4687 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
4688 elsiocb->iotag, elsiocb->iocb.ulpContext);
4689 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4690 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4691 pcmd += sizeof(uint32_t);
4693 memset(pcmd, 0, sizeof(RNID));
4694 rn = (RNID *) (pcmd);
4695 rn->Format = format;
4696 rn->CommonLen = (2 * sizeof(struct lpfc_name));
4697 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
4698 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
4701 rn->SpecificLen = 0;
4703 case RNID_TOPOLOGY_DISC:
4704 rn->SpecificLen = sizeof(RNID_TOP_DISC);
4705 memcpy(&rn->un.topologyDisc.portName,
4706 &vport->fc_portname, sizeof(struct lpfc_name));
4707 rn->un.topologyDisc.unitType = RNID_HBA;
4708 rn->un.topologyDisc.physPort = 0;
4709 rn->un.topologyDisc.attachedNodes = 0;
4713 rn->SpecificLen = 0;
4717 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4718 "Issue ACC RNID: did:x%x flg:x%x",
4719 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4721 phba->fc_stat.elsXmitACC++;
4722 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4724 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4725 if (rc == IOCB_ERROR) {
4726 lpfc_els_free_iocb(phba, elsiocb);
4733 * lpfc_els_clear_rrq - Clear the rq that this rrq describes.
4734 * @vport: pointer to a virtual N_Port data structure.
4735 * @iocb: pointer to the lpfc command iocb data structure.
4736 * @ndlp: pointer to a node-list data structure.
4741 lpfc_els_clear_rrq(struct lpfc_vport *vport,
4742 struct lpfc_iocbq *iocb, struct lpfc_nodelist *ndlp)
4744 struct lpfc_hba *phba = vport->phba;
4749 struct lpfc_node_rrq *prrq;
4752 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) iocb->context2)->virt);
4753 pcmd += sizeof(uint32_t);
4754 rrq = (struct RRQ *)pcmd;
4755 rrq->rrq_exchg = be32_to_cpu(rrq->rrq_exchg);
4756 rxid = bf_get(rrq_rxid, rrq);
4758 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4759 "2883 Clear RRQ for SID:x%x OXID:x%x RXID:x%x"
4761 be32_to_cpu(bf_get(rrq_did, rrq)),
4762 bf_get(rrq_oxid, rrq),
4764 iocb->iotag, iocb->iocb.ulpContext);
4766 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4767 "Clear RRQ: did:x%x flg:x%x exchg:x%.08x",
4768 ndlp->nlp_DID, ndlp->nlp_flag, rrq->rrq_exchg);
4769 if (vport->fc_myDID == be32_to_cpu(bf_get(rrq_did, rrq)))
4770 xri = bf_get(rrq_oxid, rrq);
4773 prrq = lpfc_get_active_rrq(vport, xri, ndlp->nlp_DID);
4775 lpfc_clr_rrq_active(phba, xri, prrq);
4780 * lpfc_els_rsp_echo_acc - Issue echo acc response
4781 * @vport: pointer to a virtual N_Port data structure.
4782 * @data: pointer to echo data to return in the accept.
4783 * @oldiocb: pointer to the original lpfc command iocb data structure.
4784 * @ndlp: pointer to a node-list data structure.
4787 * 0 - Successfully issued acc echo response
4788 * 1 - Failed to issue acc echo response
4791 lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data,
4792 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
4794 struct lpfc_hba *phba = vport->phba;
4795 struct lpfc_iocbq *elsiocb;
4800 cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len;
4802 /* The accumulated length can exceed the BPL_SIZE. For
4803 * now, use this as the limit
4805 if (cmdsize > LPFC_BPL_SIZE)
4806 cmdsize = LPFC_BPL_SIZE;
4807 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4808 ndlp->nlp_DID, ELS_CMD_ACC);
4812 elsiocb->iocb.ulpContext = oldiocb->iocb.ulpContext; /* Xri / rx_id */
4813 elsiocb->iocb.unsli3.rcvsli3.ox_id = oldiocb->iocb.unsli3.rcvsli3.ox_id;
4815 /* Xmit ECHO ACC response tag <ulpIoTag> */
4816 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4817 "2876 Xmit ECHO ACC response tag x%x xri x%x\n",
4818 elsiocb->iotag, elsiocb->iocb.ulpContext);
4819 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4820 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4821 pcmd += sizeof(uint32_t);
4822 memcpy(pcmd, data, cmdsize - sizeof(uint32_t));
4824 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4825 "Issue ACC ECHO: did:x%x flg:x%x",
4826 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4828 phba->fc_stat.elsXmitACC++;
4829 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4831 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4832 if (rc == IOCB_ERROR) {
4833 lpfc_els_free_iocb(phba, elsiocb);
4840 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
4841 * @vport: pointer to a host virtual N_Port data structure.
4843 * This routine issues Address Discover (ADISC) ELS commands to those
4844 * N_Ports which are in node port recovery state and ADISC has not been issued
4845 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
4846 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
4847 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
4848 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
4849 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
4850 * IOCBs quit for later pick up. On the other hand, after walking through
4851 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
4852 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
4853 * no more ADISC need to be sent.
4856 * The number of N_Ports with adisc issued.
4859 lpfc_els_disc_adisc(struct lpfc_vport *vport)
4861 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4862 struct lpfc_nodelist *ndlp, *next_ndlp;
4865 /* go thru NPR nodes and issue any remaining ELS ADISCs */
4866 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
4867 if (!NLP_CHK_NODE_ACT(ndlp))
4869 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
4870 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
4871 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
4872 spin_lock_irq(shost->host_lock);
4873 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
4874 spin_unlock_irq(shost->host_lock);
4875 ndlp->nlp_prev_state = ndlp->nlp_state;
4876 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
4877 lpfc_issue_els_adisc(vport, ndlp, 0);
4879 vport->num_disc_nodes++;
4880 if (vport->num_disc_nodes >=
4881 vport->cfg_discovery_threads) {
4882 spin_lock_irq(shost->host_lock);
4883 vport->fc_flag |= FC_NLP_MORE;
4884 spin_unlock_irq(shost->host_lock);
4889 if (sentadisc == 0) {
4890 spin_lock_irq(shost->host_lock);
4891 vport->fc_flag &= ~FC_NLP_MORE;
4892 spin_unlock_irq(shost->host_lock);
4898 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
4899 * @vport: pointer to a host virtual N_Port data structure.
4901 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
4902 * which are in node port recovery state, with a @vport. Each time an ELS
4903 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
4904 * the per @vport number of discover count (num_disc_nodes) shall be
4905 * incremented. If the num_disc_nodes reaches a pre-configured threshold
4906 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
4907 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
4908 * later pick up. On the other hand, after walking through all the ndlps with
4909 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
4910 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
4911 * PLOGI need to be sent.
4914 * The number of N_Ports with plogi issued.
4917 lpfc_els_disc_plogi(struct lpfc_vport *vport)
4919 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4920 struct lpfc_nodelist *ndlp, *next_ndlp;
4923 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
4924 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
4925 if (!NLP_CHK_NODE_ACT(ndlp))
4927 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
4928 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
4929 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
4930 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
4931 ndlp->nlp_prev_state = ndlp->nlp_state;
4932 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
4933 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
4935 vport->num_disc_nodes++;
4936 if (vport->num_disc_nodes >=
4937 vport->cfg_discovery_threads) {
4938 spin_lock_irq(shost->host_lock);
4939 vport->fc_flag |= FC_NLP_MORE;
4940 spin_unlock_irq(shost->host_lock);
4946 lpfc_set_disctmo(vport);
4949 spin_lock_irq(shost->host_lock);
4950 vport->fc_flag &= ~FC_NLP_MORE;
4951 spin_unlock_irq(shost->host_lock);
4957 lpfc_rdp_res_link_service(struct fc_rdp_link_service_desc *desc,
4961 desc->tag = cpu_to_be32(RDP_LINK_SERVICE_DESC_TAG);
4962 desc->payload.els_req = word0;
4963 desc->length = cpu_to_be32(sizeof(desc->payload));
4965 return sizeof(struct fc_rdp_link_service_desc);
4969 lpfc_rdp_res_sfp_desc(struct fc_rdp_sfp_desc *desc,
4970 uint8_t *page_a0, uint8_t *page_a2)
4972 uint16_t wavelength;
4973 uint16_t temperature;
4979 struct sff_trasnceiver_codes_byte4 *trasn_code_byte4;
4980 struct sff_trasnceiver_codes_byte5 *trasn_code_byte5;
4982 desc->tag = cpu_to_be32(RDP_SFP_DESC_TAG);
4984 trasn_code_byte4 = (struct sff_trasnceiver_codes_byte4 *)
4985 &page_a0[SSF_TRANSCEIVER_CODE_B4];
4986 trasn_code_byte5 = (struct sff_trasnceiver_codes_byte5 *)
4987 &page_a0[SSF_TRANSCEIVER_CODE_B5];
4989 if ((trasn_code_byte4->fc_sw_laser) ||
4990 (trasn_code_byte5->fc_sw_laser_sl) ||
4991 (trasn_code_byte5->fc_sw_laser_sn)) { /* check if its short WL */
4992 flag |= (SFP_FLAG_PT_SWLASER << SFP_FLAG_PT_SHIFT);
4993 } else if (trasn_code_byte4->fc_lw_laser) {
4994 wavelength = (page_a0[SSF_WAVELENGTH_B1] << 8) |
4995 page_a0[SSF_WAVELENGTH_B0];
4996 if (wavelength == SFP_WAVELENGTH_LC1310)
4997 flag |= SFP_FLAG_PT_LWLASER_LC1310 << SFP_FLAG_PT_SHIFT;
4998 if (wavelength == SFP_WAVELENGTH_LL1550)
4999 flag |= SFP_FLAG_PT_LWLASER_LL1550 << SFP_FLAG_PT_SHIFT;
5001 /* check if its SFP+ */
5002 flag |= ((page_a0[SSF_IDENTIFIER] == SFF_PG0_IDENT_SFP) ?
5003 SFP_FLAG_CT_SFP_PLUS : SFP_FLAG_CT_UNKNOWN)
5004 << SFP_FLAG_CT_SHIFT;
5006 /* check if its OPTICAL */
5007 flag |= ((page_a0[SSF_CONNECTOR] == SFF_PG0_CONNECTOR_LC) ?
5008 SFP_FLAG_IS_OPTICAL_PORT : 0)
5009 << SFP_FLAG_IS_OPTICAL_SHIFT;
5011 temperature = (page_a2[SFF_TEMPERATURE_B1] << 8 |
5012 page_a2[SFF_TEMPERATURE_B0]);
5013 vcc = (page_a2[SFF_VCC_B1] << 8 |
5014 page_a2[SFF_VCC_B0]);
5015 tx_power = (page_a2[SFF_TXPOWER_B1] << 8 |
5016 page_a2[SFF_TXPOWER_B0]);
5017 tx_bias = (page_a2[SFF_TX_BIAS_CURRENT_B1] << 8 |
5018 page_a2[SFF_TX_BIAS_CURRENT_B0]);
5019 rx_power = (page_a2[SFF_RXPOWER_B1] << 8 |
5020 page_a2[SFF_RXPOWER_B0]);
5021 desc->sfp_info.temperature = cpu_to_be16(temperature);
5022 desc->sfp_info.rx_power = cpu_to_be16(rx_power);
5023 desc->sfp_info.tx_bias = cpu_to_be16(tx_bias);
5024 desc->sfp_info.tx_power = cpu_to_be16(tx_power);
5025 desc->sfp_info.vcc = cpu_to_be16(vcc);
5027 desc->sfp_info.flags = cpu_to_be16(flag);
5028 desc->length = cpu_to_be32(sizeof(desc->sfp_info));
5030 return sizeof(struct fc_rdp_sfp_desc);
5034 lpfc_rdp_res_link_error(struct fc_rdp_link_error_status_desc *desc,
5039 desc->tag = cpu_to_be32(RDP_LINK_ERROR_STATUS_DESC_TAG);
5041 type = VN_PT_PHY_PF_PORT << VN_PT_PHY_SHIFT;
5043 desc->info.port_type = cpu_to_be32(type);
5045 desc->info.link_status.link_failure_cnt =
5046 cpu_to_be32(stat->linkFailureCnt);
5047 desc->info.link_status.loss_of_synch_cnt =
5048 cpu_to_be32(stat->lossSyncCnt);
5049 desc->info.link_status.loss_of_signal_cnt =
5050 cpu_to_be32(stat->lossSignalCnt);
5051 desc->info.link_status.primitive_seq_proto_err =
5052 cpu_to_be32(stat->primSeqErrCnt);
5053 desc->info.link_status.invalid_trans_word =
5054 cpu_to_be32(stat->invalidXmitWord);
5055 desc->info.link_status.invalid_crc_cnt = cpu_to_be32(stat->crcCnt);
5057 desc->length = cpu_to_be32(sizeof(desc->info));
5059 return sizeof(struct fc_rdp_link_error_status_desc);
5063 lpfc_rdp_res_bbc_desc(struct fc_rdp_bbc_desc *desc, READ_LNK_VAR *stat,
5064 struct lpfc_vport *vport)
5068 desc->tag = cpu_to_be32(RDP_BBC_DESC_TAG);
5070 bbCredit = vport->fc_sparam.cmn.bbCreditLsb |
5071 (vport->fc_sparam.cmn.bbCreditMsb << 8);
5072 desc->bbc_info.port_bbc = cpu_to_be32(bbCredit);
5073 if (vport->phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
5074 bbCredit = vport->phba->fc_fabparam.cmn.bbCreditLsb |
5075 (vport->phba->fc_fabparam.cmn.bbCreditMsb << 8);
5076 desc->bbc_info.attached_port_bbc = cpu_to_be32(bbCredit);
5078 desc->bbc_info.attached_port_bbc = 0;
5081 desc->bbc_info.rtt = 0;
5082 desc->length = cpu_to_be32(sizeof(desc->bbc_info));
5084 return sizeof(struct fc_rdp_bbc_desc);
5088 lpfc_rdp_res_oed_temp_desc(struct lpfc_hba *phba,
5089 struct fc_rdp_oed_sfp_desc *desc, uint8_t *page_a2)
5093 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5095 desc->oed_info.hi_alarm = page_a2[SSF_TEMP_HIGH_ALARM];
5096 desc->oed_info.lo_alarm = page_a2[SSF_TEMP_LOW_ALARM];
5097 desc->oed_info.hi_warning = page_a2[SSF_TEMP_HIGH_WARNING];
5098 desc->oed_info.lo_warning = page_a2[SSF_TEMP_LOW_WARNING];
5100 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TEMPERATURE)
5101 flags |= RDP_OET_HIGH_ALARM;
5102 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TEMPERATURE)
5103 flags |= RDP_OET_LOW_ALARM;
5104 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TEMPERATURE)
5105 flags |= RDP_OET_HIGH_WARNING;
5106 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TEMPERATURE)
5107 flags |= RDP_OET_LOW_WARNING;
5109 flags |= ((0xf & RDP_OED_TEMPERATURE) << RDP_OED_TYPE_SHIFT);
5110 desc->oed_info.function_flags = cpu_to_be32(flags);
5111 desc->length = cpu_to_be32(sizeof(desc->oed_info));
5112 return sizeof(struct fc_rdp_oed_sfp_desc);
5116 lpfc_rdp_res_oed_voltage_desc(struct lpfc_hba *phba,
5117 struct fc_rdp_oed_sfp_desc *desc,
5122 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5124 desc->oed_info.hi_alarm = page_a2[SSF_VOLTAGE_HIGH_ALARM];
5125 desc->oed_info.lo_alarm = page_a2[SSF_VOLTAGE_LOW_ALARM];
5126 desc->oed_info.hi_warning = page_a2[SSF_VOLTAGE_HIGH_WARNING];
5127 desc->oed_info.lo_warning = page_a2[SSF_VOLTAGE_LOW_WARNING];
5129 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_VOLTAGE)
5130 flags |= RDP_OET_HIGH_ALARM;
5131 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_VOLTAGE)
5132 flags |= RDP_OET_LOW_ALARM;
5133 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_VOLTAGE)
5134 flags |= RDP_OET_HIGH_WARNING;
5135 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_VOLTAGE)
5136 flags |= RDP_OET_LOW_WARNING;
5138 flags |= ((0xf & RDP_OED_VOLTAGE) << RDP_OED_TYPE_SHIFT);
5139 desc->oed_info.function_flags = cpu_to_be32(flags);
5140 desc->length = cpu_to_be32(sizeof(desc->oed_info));
5141 return sizeof(struct fc_rdp_oed_sfp_desc);
5145 lpfc_rdp_res_oed_txbias_desc(struct lpfc_hba *phba,
5146 struct fc_rdp_oed_sfp_desc *desc,
5151 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5153 desc->oed_info.hi_alarm = page_a2[SSF_BIAS_HIGH_ALARM];
5154 desc->oed_info.lo_alarm = page_a2[SSF_BIAS_LOW_ALARM];
5155 desc->oed_info.hi_warning = page_a2[SSF_BIAS_HIGH_WARNING];
5156 desc->oed_info.lo_warning = page_a2[SSF_BIAS_LOW_WARNING];
5158 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TXBIAS)
5159 flags |= RDP_OET_HIGH_ALARM;
5160 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TXBIAS)
5161 flags |= RDP_OET_LOW_ALARM;
5162 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TXBIAS)
5163 flags |= RDP_OET_HIGH_WARNING;
5164 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TXBIAS)
5165 flags |= RDP_OET_LOW_WARNING;
5167 flags |= ((0xf & RDP_OED_TXBIAS) << RDP_OED_TYPE_SHIFT);
5168 desc->oed_info.function_flags = cpu_to_be32(flags);
5169 desc->length = cpu_to_be32(sizeof(desc->oed_info));
5170 return sizeof(struct fc_rdp_oed_sfp_desc);
5174 lpfc_rdp_res_oed_txpower_desc(struct lpfc_hba *phba,
5175 struct fc_rdp_oed_sfp_desc *desc,
5180 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5182 desc->oed_info.hi_alarm = page_a2[SSF_TXPOWER_HIGH_ALARM];
5183 desc->oed_info.lo_alarm = page_a2[SSF_TXPOWER_LOW_ALARM];
5184 desc->oed_info.hi_warning = page_a2[SSF_TXPOWER_HIGH_WARNING];
5185 desc->oed_info.lo_warning = page_a2[SSF_TXPOWER_LOW_WARNING];
5187 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TXPOWER)
5188 flags |= RDP_OET_HIGH_ALARM;
5189 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TXPOWER)
5190 flags |= RDP_OET_LOW_ALARM;
5191 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TXPOWER)
5192 flags |= RDP_OET_HIGH_WARNING;
5193 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TXPOWER)
5194 flags |= RDP_OET_LOW_WARNING;
5196 flags |= ((0xf & RDP_OED_TXPOWER) << RDP_OED_TYPE_SHIFT);
5197 desc->oed_info.function_flags = cpu_to_be32(flags);
5198 desc->length = cpu_to_be32(sizeof(desc->oed_info));
5199 return sizeof(struct fc_rdp_oed_sfp_desc);
5204 lpfc_rdp_res_oed_rxpower_desc(struct lpfc_hba *phba,
5205 struct fc_rdp_oed_sfp_desc *desc,
5210 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5212 desc->oed_info.hi_alarm = page_a2[SSF_RXPOWER_HIGH_ALARM];
5213 desc->oed_info.lo_alarm = page_a2[SSF_RXPOWER_LOW_ALARM];
5214 desc->oed_info.hi_warning = page_a2[SSF_RXPOWER_HIGH_WARNING];
5215 desc->oed_info.lo_warning = page_a2[SSF_RXPOWER_LOW_WARNING];
5217 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_RXPOWER)
5218 flags |= RDP_OET_HIGH_ALARM;
5219 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_RXPOWER)
5220 flags |= RDP_OET_LOW_ALARM;
5221 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_RXPOWER)
5222 flags |= RDP_OET_HIGH_WARNING;
5223 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_RXPOWER)
5224 flags |= RDP_OET_LOW_WARNING;
5226 flags |= ((0xf & RDP_OED_RXPOWER) << RDP_OED_TYPE_SHIFT);
5227 desc->oed_info.function_flags = cpu_to_be32(flags);
5228 desc->length = cpu_to_be32(sizeof(desc->oed_info));
5229 return sizeof(struct fc_rdp_oed_sfp_desc);
5233 lpfc_rdp_res_opd_desc(struct fc_rdp_opd_sfp_desc *desc,
5234 uint8_t *page_a0, struct lpfc_vport *vport)
5236 desc->tag = cpu_to_be32(RDP_OPD_DESC_TAG);
5237 memcpy(desc->opd_info.vendor_name, &page_a0[SSF_VENDOR_NAME], 16);
5238 memcpy(desc->opd_info.model_number, &page_a0[SSF_VENDOR_PN], 16);
5239 memcpy(desc->opd_info.serial_number, &page_a0[SSF_VENDOR_SN], 16);
5240 memcpy(desc->opd_info.revision, &page_a0[SSF_VENDOR_REV], 4);
5241 memcpy(desc->opd_info.date, &page_a0[SSF_DATE_CODE], 8);
5242 desc->length = cpu_to_be32(sizeof(desc->opd_info));
5243 return sizeof(struct fc_rdp_opd_sfp_desc);
5247 lpfc_rdp_res_fec_desc(struct fc_fec_rdp_desc *desc, READ_LNK_VAR *stat)
5249 if (bf_get(lpfc_read_link_stat_gec2, stat) == 0)
5251 desc->tag = cpu_to_be32(RDP_FEC_DESC_TAG);
5253 desc->info.CorrectedBlocks =
5254 cpu_to_be32(stat->fecCorrBlkCount);
5255 desc->info.UncorrectableBlocks =
5256 cpu_to_be32(stat->fecUncorrBlkCount);
5258 desc->length = cpu_to_be32(sizeof(desc->info));
5260 return sizeof(struct fc_fec_rdp_desc);
5264 lpfc_rdp_res_speed(struct fc_rdp_port_speed_desc *desc, struct lpfc_hba *phba)
5266 uint16_t rdp_cap = 0;
5269 desc->tag = cpu_to_be32(RDP_PORT_SPEED_DESC_TAG);
5271 switch (phba->fc_linkspeed) {
5272 case LPFC_LINK_SPEED_1GHZ:
5273 rdp_speed = RDP_PS_1GB;
5275 case LPFC_LINK_SPEED_2GHZ:
5276 rdp_speed = RDP_PS_2GB;
5278 case LPFC_LINK_SPEED_4GHZ:
5279 rdp_speed = RDP_PS_4GB;
5281 case LPFC_LINK_SPEED_8GHZ:
5282 rdp_speed = RDP_PS_8GB;
5284 case LPFC_LINK_SPEED_10GHZ:
5285 rdp_speed = RDP_PS_10GB;
5287 case LPFC_LINK_SPEED_16GHZ:
5288 rdp_speed = RDP_PS_16GB;
5290 case LPFC_LINK_SPEED_32GHZ:
5291 rdp_speed = RDP_PS_32GB;
5294 rdp_speed = RDP_PS_UNKNOWN;
5298 desc->info.port_speed.speed = cpu_to_be16(rdp_speed);
5300 if (phba->lmt & LMT_32Gb)
5301 rdp_cap |= RDP_PS_32GB;
5302 if (phba->lmt & LMT_16Gb)
5303 rdp_cap |= RDP_PS_16GB;
5304 if (phba->lmt & LMT_10Gb)
5305 rdp_cap |= RDP_PS_10GB;
5306 if (phba->lmt & LMT_8Gb)
5307 rdp_cap |= RDP_PS_8GB;
5308 if (phba->lmt & LMT_4Gb)
5309 rdp_cap |= RDP_PS_4GB;
5310 if (phba->lmt & LMT_2Gb)
5311 rdp_cap |= RDP_PS_2GB;
5312 if (phba->lmt & LMT_1Gb)
5313 rdp_cap |= RDP_PS_1GB;
5316 rdp_cap = RDP_CAP_UNKNOWN;
5317 if (phba->cfg_link_speed != LPFC_USER_LINK_SPEED_AUTO)
5318 rdp_cap |= RDP_CAP_USER_CONFIGURED;
5320 desc->info.port_speed.capabilities = cpu_to_be16(rdp_cap);
5321 desc->length = cpu_to_be32(sizeof(desc->info));
5322 return sizeof(struct fc_rdp_port_speed_desc);
5326 lpfc_rdp_res_diag_port_names(struct fc_rdp_port_name_desc *desc,
5327 struct lpfc_vport *vport)
5330 desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG);
5332 memcpy(desc->port_names.wwnn, &vport->fc_nodename,
5333 sizeof(desc->port_names.wwnn));
5335 memcpy(desc->port_names.wwpn, &vport->fc_portname,
5336 sizeof(desc->port_names.wwpn));
5338 desc->length = cpu_to_be32(sizeof(desc->port_names));
5339 return sizeof(struct fc_rdp_port_name_desc);
5343 lpfc_rdp_res_attach_port_names(struct fc_rdp_port_name_desc *desc,
5344 struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
5347 desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG);
5348 if (vport->fc_flag & FC_FABRIC) {
5349 memcpy(desc->port_names.wwnn, &vport->fabric_nodename,
5350 sizeof(desc->port_names.wwnn));
5352 memcpy(desc->port_names.wwpn, &vport->fabric_portname,
5353 sizeof(desc->port_names.wwpn));
5354 } else { /* Point to Point */
5355 memcpy(desc->port_names.wwnn, &ndlp->nlp_nodename,
5356 sizeof(desc->port_names.wwnn));
5358 memcpy(desc->port_names.wwnn, &ndlp->nlp_portname,
5359 sizeof(desc->port_names.wwpn));
5362 desc->length = cpu_to_be32(sizeof(desc->port_names));
5363 return sizeof(struct fc_rdp_port_name_desc);
5367 lpfc_els_rdp_cmpl(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context,
5370 struct lpfc_nodelist *ndlp = rdp_context->ndlp;
5371 struct lpfc_vport *vport = ndlp->vport;
5372 struct lpfc_iocbq *elsiocb;
5373 struct ulp_bde64 *bpl;
5376 struct ls_rjt *stat;
5377 struct fc_rdp_res_frame *rdp_res;
5378 uint32_t cmdsize, len;
5382 if (status != SUCCESS)
5385 /* This will change once we know the true size of the RDP payload */
5386 cmdsize = sizeof(struct fc_rdp_res_frame);
5388 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize,
5389 lpfc_max_els_tries, rdp_context->ndlp,
5390 rdp_context->ndlp->nlp_DID, ELS_CMD_ACC);
5393 goto free_rdp_context;
5395 icmd = &elsiocb->iocb;
5396 icmd->ulpContext = rdp_context->rx_id;
5397 icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id;
5399 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5400 "2171 Xmit RDP response tag x%x xri x%x, "
5401 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x",
5402 elsiocb->iotag, elsiocb->iocb.ulpContext,
5403 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5405 rdp_res = (struct fc_rdp_res_frame *)
5406 (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5407 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5408 memset(pcmd, 0, sizeof(struct fc_rdp_res_frame));
5409 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5411 /* Update Alarm and Warning */
5412 flag_ptr = (uint16_t *)(rdp_context->page_a2 + SSF_ALARM_FLAGS);
5413 phba->sfp_alarm |= *flag_ptr;
5414 flag_ptr = (uint16_t *)(rdp_context->page_a2 + SSF_WARNING_FLAGS);
5415 phba->sfp_warning |= *flag_ptr;
5417 /* For RDP payload */
5419 len += lpfc_rdp_res_link_service((struct fc_rdp_link_service_desc *)
5420 (len + pcmd), ELS_CMD_RDP);
5422 len += lpfc_rdp_res_sfp_desc((struct fc_rdp_sfp_desc *)(len + pcmd),
5423 rdp_context->page_a0, rdp_context->page_a2);
5424 len += lpfc_rdp_res_speed((struct fc_rdp_port_speed_desc *)(len + pcmd),
5426 len += lpfc_rdp_res_link_error((struct fc_rdp_link_error_status_desc *)
5427 (len + pcmd), &rdp_context->link_stat);
5428 len += lpfc_rdp_res_diag_port_names((struct fc_rdp_port_name_desc *)
5429 (len + pcmd), vport);
5430 len += lpfc_rdp_res_attach_port_names((struct fc_rdp_port_name_desc *)
5431 (len + pcmd), vport, ndlp);
5432 len += lpfc_rdp_res_fec_desc((struct fc_fec_rdp_desc *)(len + pcmd),
5433 &rdp_context->link_stat);
5434 /* Check if nport is logged, BZ190632 */
5435 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED))
5436 goto lpfc_skip_descriptor;
5438 len += lpfc_rdp_res_bbc_desc((struct fc_rdp_bbc_desc *)(len + pcmd),
5439 &rdp_context->link_stat, vport);
5440 len += lpfc_rdp_res_oed_temp_desc(phba,
5441 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5442 rdp_context->page_a2);
5443 len += lpfc_rdp_res_oed_voltage_desc(phba,
5444 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5445 rdp_context->page_a2);
5446 len += lpfc_rdp_res_oed_txbias_desc(phba,
5447 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5448 rdp_context->page_a2);
5449 len += lpfc_rdp_res_oed_txpower_desc(phba,
5450 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5451 rdp_context->page_a2);
5452 len += lpfc_rdp_res_oed_rxpower_desc(phba,
5453 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5454 rdp_context->page_a2);
5455 len += lpfc_rdp_res_opd_desc((struct fc_rdp_opd_sfp_desc *)(len + pcmd),
5456 rdp_context->page_a0, vport);
5458 lpfc_skip_descriptor:
5459 rdp_res->length = cpu_to_be32(len - 8);
5460 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5462 /* Now that we know the true size of the payload, update the BPL */
5463 bpl = (struct ulp_bde64 *)
5464 (((struct lpfc_dmabuf *)(elsiocb->context3))->virt);
5465 bpl->tus.f.bdeSize = len;
5466 bpl->tus.f.bdeFlags = 0;
5467 bpl->tus.w = le32_to_cpu(bpl->tus.w);
5469 phba->fc_stat.elsXmitACC++;
5470 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5471 if (rc == IOCB_ERROR)
5472 lpfc_els_free_iocb(phba, elsiocb);
5478 cmdsize = 2 * sizeof(uint32_t);
5479 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, lpfc_max_els_tries,
5480 ndlp, ndlp->nlp_DID, ELS_CMD_LS_RJT);
5483 goto free_rdp_context;
5485 icmd = &elsiocb->iocb;
5486 icmd->ulpContext = rdp_context->rx_id;
5487 icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id;
5488 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5490 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
5491 stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t));
5492 stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5494 phba->fc_stat.elsXmitLSRJT++;
5495 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5496 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5498 if (rc == IOCB_ERROR)
5499 lpfc_els_free_iocb(phba, elsiocb);
5505 lpfc_get_rdp_info(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context)
5507 LPFC_MBOXQ_t *mbox = NULL;
5510 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5512 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_ELS,
5513 "7105 failed to allocate mailbox memory");
5517 if (lpfc_sli4_dump_page_a0(phba, mbox))
5518 goto prep_mbox_fail;
5519 mbox->vport = rdp_context->ndlp->vport;
5520 mbox->mbox_cmpl = lpfc_mbx_cmpl_rdp_page_a0;
5521 mbox->context2 = (struct lpfc_rdp_context *) rdp_context;
5522 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
5523 if (rc == MBX_NOT_FINISHED)
5524 goto issue_mbox_fail;
5530 mempool_free(mbox, phba->mbox_mem_pool);
5535 * lpfc_els_rcv_rdp - Process an unsolicited RDP ELS.
5536 * @vport: pointer to a host virtual N_Port data structure.
5537 * @cmdiocb: pointer to lpfc command iocb data structure.
5538 * @ndlp: pointer to a node-list data structure.
5540 * This routine processes an unsolicited RDP(Read Diagnostic Parameters)
5541 * IOCB. First, the payload of the unsolicited RDP is checked.
5542 * Then it will (1) send MBX_DUMP_MEMORY, Embedded DMP_LMSD sub command TYPE-3
5543 * for Page A0, (2) send MBX_DUMP_MEMORY, DMP_LMSD for Page A2,
5544 * (3) send MBX_READ_LNK_STAT to get link stat, (4) Call lpfc_els_rdp_cmpl
5545 * gather all data and send RDP response.
5548 * 0 - Sent the acc response
5549 * 1 - Sent the reject response.
5552 lpfc_els_rcv_rdp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5553 struct lpfc_nodelist *ndlp)
5555 struct lpfc_hba *phba = vport->phba;
5556 struct lpfc_dmabuf *pcmd;
5557 uint8_t rjt_err, rjt_expl = LSEXP_NOTHING_MORE;
5558 struct fc_rdp_req_frame *rdp_req;
5559 struct lpfc_rdp_context *rdp_context;
5563 if (phba->sli_rev < LPFC_SLI_REV4 ||
5564 bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
5565 LPFC_SLI_INTF_IF_TYPE_2) {
5566 rjt_err = LSRJT_UNABLE_TPC;
5567 rjt_expl = LSEXP_REQ_UNSUPPORTED;
5571 if (phba->sli_rev < LPFC_SLI_REV4 || (phba->hba_flag & HBA_FCOE_MODE)) {
5572 rjt_err = LSRJT_UNABLE_TPC;
5573 rjt_expl = LSEXP_REQ_UNSUPPORTED;
5577 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5578 rdp_req = (struct fc_rdp_req_frame *) pcmd->virt;
5581 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5582 "2422 ELS RDP Request "
5583 "dec len %d tag x%x port_id %d len %d\n",
5584 be32_to_cpu(rdp_req->rdp_des_length),
5585 be32_to_cpu(rdp_req->nport_id_desc.tag),
5586 be32_to_cpu(rdp_req->nport_id_desc.nport_id),
5587 be32_to_cpu(rdp_req->nport_id_desc.length));
5589 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED) &&
5590 !phba->cfg_enable_SmartSAN) {
5591 rjt_err = LSRJT_UNABLE_TPC;
5592 rjt_expl = LSEXP_PORT_LOGIN_REQ;
5595 if (sizeof(struct fc_rdp_nport_desc) !=
5596 be32_to_cpu(rdp_req->rdp_des_length))
5598 if (RDP_N_PORT_DESC_TAG != be32_to_cpu(rdp_req->nport_id_desc.tag))
5600 if (RDP_NPORT_ID_SIZE !=
5601 be32_to_cpu(rdp_req->nport_id_desc.length))
5603 rdp_context = kzalloc(sizeof(struct lpfc_rdp_context), GFP_KERNEL);
5605 rjt_err = LSRJT_UNABLE_TPC;
5609 cmd = &cmdiocb->iocb;
5610 rdp_context->ndlp = lpfc_nlp_get(ndlp);
5611 rdp_context->ox_id = cmd->unsli3.rcvsli3.ox_id;
5612 rdp_context->rx_id = cmd->ulpContext;
5613 rdp_context->cmpl = lpfc_els_rdp_cmpl;
5614 if (lpfc_get_rdp_info(phba, rdp_context)) {
5615 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_ELS,
5616 "2423 Unable to send mailbox");
5618 rjt_err = LSRJT_UNABLE_TPC;
5626 rjt_err = LSRJT_LOGICAL_ERR;
5629 memset(&stat, 0, sizeof(stat));
5630 stat.un.b.lsRjtRsnCode = rjt_err;
5631 stat.un.b.lsRjtRsnCodeExp = rjt_expl;
5632 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5638 lpfc_els_lcb_rsp(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
5643 struct lpfc_iocbq *elsiocb;
5644 struct lpfc_nodelist *ndlp;
5645 struct ls_rjt *stat;
5646 union lpfc_sli4_cfg_shdr *shdr;
5647 struct lpfc_lcb_context *lcb_context;
5648 struct fc_lcb_res_frame *lcb_res;
5649 uint32_t cmdsize, shdr_status, shdr_add_status;
5653 lcb_context = (struct lpfc_lcb_context *)pmb->context1;
5654 ndlp = lcb_context->ndlp;
5655 pmb->context1 = NULL;
5656 pmb->context2 = NULL;
5658 shdr = (union lpfc_sli4_cfg_shdr *)
5659 &pmb->u.mqe.un.beacon_config.header.cfg_shdr;
5660 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
5661 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
5663 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX,
5664 "0194 SET_BEACON_CONFIG mailbox "
5665 "completed with status x%x add_status x%x,"
5666 " mbx status x%x\n",
5667 shdr_status, shdr_add_status, mb->mbxStatus);
5669 if (mb->mbxStatus && !(shdr_status &&
5670 shdr_add_status == ADD_STATUS_OPERATION_ALREADY_ACTIVE)) {
5671 mempool_free(pmb, phba->mbox_mem_pool);
5675 mempool_free(pmb, phba->mbox_mem_pool);
5676 cmdsize = sizeof(struct fc_lcb_res_frame);
5677 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5678 lpfc_max_els_tries, ndlp,
5679 ndlp->nlp_DID, ELS_CMD_ACC);
5681 /* Decrement the ndlp reference count from previous mbox command */
5685 goto free_lcb_context;
5687 lcb_res = (struct fc_lcb_res_frame *)
5688 (((struct lpfc_dmabuf *)elsiocb->context2)->virt);
5690 icmd = &elsiocb->iocb;
5691 icmd->ulpContext = lcb_context->rx_id;
5692 icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id;
5694 pcmd = (uint8_t *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt);
5695 *((uint32_t *)(pcmd)) = ELS_CMD_ACC;
5696 lcb_res->lcb_sub_command = lcb_context->sub_command;
5697 lcb_res->lcb_type = lcb_context->type;
5698 lcb_res->lcb_frequency = lcb_context->frequency;
5699 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5700 phba->fc_stat.elsXmitACC++;
5701 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5702 if (rc == IOCB_ERROR)
5703 lpfc_els_free_iocb(phba, elsiocb);
5709 cmdsize = sizeof(struct fc_lcb_res_frame);
5710 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5711 lpfc_max_els_tries, ndlp,
5712 ndlp->nlp_DID, ELS_CMD_LS_RJT);
5715 goto free_lcb_context;
5717 icmd = &elsiocb->iocb;
5718 icmd->ulpContext = lcb_context->rx_id;
5719 icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id;
5720 pcmd = (uint8_t *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt);
5722 *((uint32_t *)(pcmd)) = ELS_CMD_LS_RJT;
5723 stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t));
5724 stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5726 if (shdr_add_status == ADD_STATUS_OPERATION_ALREADY_ACTIVE)
5727 stat->un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS;
5729 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5730 phba->fc_stat.elsXmitLSRJT++;
5731 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5732 if (rc == IOCB_ERROR)
5733 lpfc_els_free_iocb(phba, elsiocb);
5739 lpfc_sli4_set_beacon(struct lpfc_vport *vport,
5740 struct lpfc_lcb_context *lcb_context,
5741 uint32_t beacon_state)
5743 struct lpfc_hba *phba = vport->phba;
5744 LPFC_MBOXQ_t *mbox = NULL;
5748 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5752 len = sizeof(struct lpfc_mbx_set_beacon_config) -
5753 sizeof(struct lpfc_sli4_cfg_mhdr);
5754 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
5755 LPFC_MBOX_OPCODE_SET_BEACON_CONFIG, len,
5756 LPFC_SLI4_MBX_EMBED);
5757 mbox->context1 = (void *)lcb_context;
5758 mbox->vport = phba->pport;
5759 mbox->mbox_cmpl = lpfc_els_lcb_rsp;
5760 bf_set(lpfc_mbx_set_beacon_port_num, &mbox->u.mqe.un.beacon_config,
5761 phba->sli4_hba.physical_port);
5762 bf_set(lpfc_mbx_set_beacon_state, &mbox->u.mqe.un.beacon_config,
5764 bf_set(lpfc_mbx_set_beacon_port_type, &mbox->u.mqe.un.beacon_config, 1);
5765 bf_set(lpfc_mbx_set_beacon_duration, &mbox->u.mqe.un.beacon_config, 0);
5766 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
5767 if (rc == MBX_NOT_FINISHED) {
5768 mempool_free(mbox, phba->mbox_mem_pool);
5777 * lpfc_els_rcv_lcb - Process an unsolicited LCB
5778 * @vport: pointer to a host virtual N_Port data structure.
5779 * @cmdiocb: pointer to lpfc command iocb data structure.
5780 * @ndlp: pointer to a node-list data structure.
5782 * This routine processes an unsolicited LCB(LINK CABLE BEACON) IOCB.
5783 * First, the payload of the unsolicited LCB is checked.
5784 * Then based on Subcommand beacon will either turn on or off.
5787 * 0 - Sent the acc response
5788 * 1 - Sent the reject response.
5791 lpfc_els_rcv_lcb(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5792 struct lpfc_nodelist *ndlp)
5794 struct lpfc_hba *phba = vport->phba;
5795 struct lpfc_dmabuf *pcmd;
5797 struct fc_lcb_request_frame *beacon;
5798 struct lpfc_lcb_context *lcb_context;
5799 uint8_t state, rjt_err;
5802 pcmd = (struct lpfc_dmabuf *)cmdiocb->context2;
5803 lp = (uint8_t *)pcmd->virt;
5804 beacon = (struct fc_lcb_request_frame *)pcmd->virt;
5806 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5807 "0192 ELS LCB Data x%x x%x x%x x%x sub x%x "
5808 "type x%x frequency %x duration x%x\n",
5809 lp[0], lp[1], lp[2],
5810 beacon->lcb_command,
5811 beacon->lcb_sub_command,
5813 beacon->lcb_frequency,
5814 be16_to_cpu(beacon->lcb_duration));
5816 if (phba->sli_rev < LPFC_SLI_REV4 ||
5817 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
5818 LPFC_SLI_INTF_IF_TYPE_2)) {
5819 rjt_err = LSRJT_CMD_UNSUPPORTED;
5823 if (phba->hba_flag & HBA_FCOE_MODE) {
5824 rjt_err = LSRJT_CMD_UNSUPPORTED;
5827 if (beacon->lcb_sub_command != LPFC_LCB_ON &&
5828 beacon->lcb_sub_command != LPFC_LCB_OFF) {
5829 rjt_err = LSRJT_CMD_UNSUPPORTED;
5832 if (beacon->lcb_sub_command == LPFC_LCB_ON &&
5833 be16_to_cpu(beacon->lcb_duration) != 0) {
5834 rjt_err = LSRJT_CMD_UNSUPPORTED;
5838 lcb_context = kmalloc(sizeof(*lcb_context), GFP_KERNEL);
5840 rjt_err = LSRJT_UNABLE_TPC;
5844 state = (beacon->lcb_sub_command == LPFC_LCB_ON) ? 1 : 0;
5845 lcb_context->sub_command = beacon->lcb_sub_command;
5846 lcb_context->type = beacon->lcb_type;
5847 lcb_context->frequency = beacon->lcb_frequency;
5848 lcb_context->ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id;
5849 lcb_context->rx_id = cmdiocb->iocb.ulpContext;
5850 lcb_context->ndlp = lpfc_nlp_get(ndlp);
5851 if (lpfc_sli4_set_beacon(vport, lcb_context, state)) {
5852 lpfc_printf_vlog(ndlp->vport, KERN_ERR,
5853 LOG_ELS, "0193 failed to send mail box");
5856 rjt_err = LSRJT_UNABLE_TPC;
5861 memset(&stat, 0, sizeof(stat));
5862 stat.un.b.lsRjtRsnCode = rjt_err;
5863 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5869 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
5870 * @vport: pointer to a host virtual N_Port data structure.
5872 * This routine cleans up any Registration State Change Notification
5873 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
5874 * @vport together with the host_lock is used to prevent multiple thread
5875 * trying to access the RSCN array on a same @vport at the same time.
5878 lpfc_els_flush_rscn(struct lpfc_vport *vport)
5880 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5881 struct lpfc_hba *phba = vport->phba;
5884 spin_lock_irq(shost->host_lock);
5885 if (vport->fc_rscn_flush) {
5886 /* Another thread is walking fc_rscn_id_list on this vport */
5887 spin_unlock_irq(shost->host_lock);
5890 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
5891 vport->fc_rscn_flush = 1;
5892 spin_unlock_irq(shost->host_lock);
5894 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
5895 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
5896 vport->fc_rscn_id_list[i] = NULL;
5898 spin_lock_irq(shost->host_lock);
5899 vport->fc_rscn_id_cnt = 0;
5900 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
5901 spin_unlock_irq(shost->host_lock);
5902 lpfc_can_disctmo(vport);
5903 /* Indicate we are done walking this fc_rscn_id_list */
5904 vport->fc_rscn_flush = 0;
5908 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
5909 * @vport: pointer to a host virtual N_Port data structure.
5910 * @did: remote destination port identifier.
5912 * This routine checks whether there is any pending Registration State
5913 * Configuration Notification (RSCN) to a @did on @vport.
5916 * None zero - The @did matched with a pending rscn
5917 * 0 - not able to match @did with a pending rscn
5920 lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
5925 uint32_t payload_len, i;
5926 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5928 ns_did.un.word = did;
5930 /* Never match fabric nodes for RSCNs */
5931 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
5934 /* If we are doing a FULL RSCN rediscovery, match everything */
5935 if (vport->fc_flag & FC_RSCN_DISCOVERY)
5938 spin_lock_irq(shost->host_lock);
5939 if (vport->fc_rscn_flush) {
5940 /* Another thread is walking fc_rscn_id_list on this vport */
5941 spin_unlock_irq(shost->host_lock);
5944 /* Indicate we are walking fc_rscn_id_list on this vport */
5945 vport->fc_rscn_flush = 1;
5946 spin_unlock_irq(shost->host_lock);
5947 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
5948 lp = vport->fc_rscn_id_list[i]->virt;
5949 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
5950 payload_len -= sizeof(uint32_t); /* take off word 0 */
5951 while (payload_len) {
5952 rscn_did.un.word = be32_to_cpu(*lp++);
5953 payload_len -= sizeof(uint32_t);
5954 switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) {
5955 case RSCN_ADDRESS_FORMAT_PORT:
5956 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
5957 && (ns_did.un.b.area == rscn_did.un.b.area)
5958 && (ns_did.un.b.id == rscn_did.un.b.id))
5959 goto return_did_out;
5961 case RSCN_ADDRESS_FORMAT_AREA:
5962 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
5963 && (ns_did.un.b.area == rscn_did.un.b.area))
5964 goto return_did_out;
5966 case RSCN_ADDRESS_FORMAT_DOMAIN:
5967 if (ns_did.un.b.domain == rscn_did.un.b.domain)
5968 goto return_did_out;
5970 case RSCN_ADDRESS_FORMAT_FABRIC:
5971 goto return_did_out;
5975 /* Indicate we are done with walking fc_rscn_id_list on this vport */
5976 vport->fc_rscn_flush = 0;
5979 /* Indicate we are done with walking fc_rscn_id_list on this vport */
5980 vport->fc_rscn_flush = 0;
5985 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
5986 * @vport: pointer to a host virtual N_Port data structure.
5988 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
5989 * state machine for a @vport's nodes that are with pending RSCN (Registration
5990 * State Change Notification).
5993 * 0 - Successful (currently alway return 0)
5996 lpfc_rscn_recovery_check(struct lpfc_vport *vport)
5998 struct lpfc_nodelist *ndlp = NULL;
6000 /* Move all affected nodes by pending RSCNs to NPR state. */
6001 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
6002 if (!NLP_CHK_NODE_ACT(ndlp) ||
6003 (ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
6004 !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
6007 /* NVME Target mode does not do RSCN Recovery. */
6008 if (vport->phba->nvmet_support)
6011 lpfc_disc_state_machine(vport, ndlp, NULL,
6012 NLP_EVT_DEVICE_RECOVERY);
6013 lpfc_cancel_retry_delay_tmo(vport, ndlp);
6019 * lpfc_send_rscn_event - Send an RSCN event to management application
6020 * @vport: pointer to a host virtual N_Port data structure.
6021 * @cmdiocb: pointer to lpfc command iocb data structure.
6023 * lpfc_send_rscn_event sends an RSCN netlink event to management
6027 lpfc_send_rscn_event(struct lpfc_vport *vport,
6028 struct lpfc_iocbq *cmdiocb)
6030 struct lpfc_dmabuf *pcmd;
6031 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6032 uint32_t *payload_ptr;
6033 uint32_t payload_len;
6034 struct lpfc_rscn_event_header *rscn_event_data;
6036 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6037 payload_ptr = (uint32_t *) pcmd->virt;
6038 payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK);
6040 rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) +
6041 payload_len, GFP_KERNEL);
6042 if (!rscn_event_data) {
6043 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6044 "0147 Failed to allocate memory for RSCN event\n");
6047 rscn_event_data->event_type = FC_REG_RSCN_EVENT;
6048 rscn_event_data->payload_length = payload_len;
6049 memcpy(rscn_event_data->rscn_payload, payload_ptr,
6052 fc_host_post_vendor_event(shost,
6053 fc_get_event_number(),
6054 sizeof(struct lpfc_rscn_event_header) + payload_len,
6055 (char *)rscn_event_data,
6058 kfree(rscn_event_data);
6062 * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
6063 * @vport: pointer to a host virtual N_Port data structure.
6064 * @cmdiocb: pointer to lpfc command iocb data structure.
6065 * @ndlp: pointer to a node-list data structure.
6067 * This routine processes an unsolicited RSCN (Registration State Change
6068 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
6069 * to invoke fc_host_post_event() routine to the FC transport layer. If the
6070 * discover state machine is about to begin discovery, it just accepts the
6071 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
6072 * contains N_Port IDs for other vports on this HBA, it just accepts the
6073 * RSCN and ignore processing it. If the state machine is in the recovery
6074 * state, the fc_rscn_id_list of this @vport is walked and the
6075 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
6076 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
6077 * routine is invoked to handle the RSCN event.
6080 * 0 - Just sent the acc response
6081 * 1 - Sent the acc response and waited for name server completion
6084 lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6085 struct lpfc_nodelist *ndlp)
6087 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6088 struct lpfc_hba *phba = vport->phba;
6089 struct lpfc_dmabuf *pcmd;
6090 uint32_t *lp, *datap;
6091 uint32_t payload_len, length, nportid, *cmd;
6093 int rscn_id = 0, hba_id = 0;
6096 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6097 lp = (uint32_t *) pcmd->virt;
6099 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
6100 payload_len -= sizeof(uint32_t); /* take off word 0 */
6102 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6103 "0214 RSCN received Data: x%x x%x x%x x%x\n",
6104 vport->fc_flag, payload_len, *lp,
6105 vport->fc_rscn_id_cnt);
6107 /* Send an RSCN event to the management application */
6108 lpfc_send_rscn_event(vport, cmdiocb);
6110 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
6111 fc_host_post_event(shost, fc_get_event_number(),
6112 FCH_EVT_RSCN, lp[i]);
6114 /* If we are about to begin discovery, just ACC the RSCN.
6115 * Discovery processing will satisfy it.
6117 if (vport->port_state <= LPFC_NS_QRY) {
6118 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6119 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
6120 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
6122 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
6126 /* If this RSCN just contains NPortIDs for other vports on this HBA,
6127 * just ACC and ignore it.
6129 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
6130 !(vport->cfg_peer_port_login)) {
6135 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
6136 i -= sizeof(uint32_t);
6138 if (lpfc_find_vport_by_did(phba, nportid))
6141 if (rscn_id == hba_id) {
6142 /* ALL NPortIDs in RSCN are on HBA */
6143 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6145 "Data: x%x x%x x%x x%x\n",
6146 vport->fc_flag, payload_len,
6147 *lp, vport->fc_rscn_id_cnt);
6148 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6149 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
6150 ndlp->nlp_DID, vport->port_state,
6153 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
6159 spin_lock_irq(shost->host_lock);
6160 if (vport->fc_rscn_flush) {
6161 /* Another thread is walking fc_rscn_id_list on this vport */
6162 vport->fc_flag |= FC_RSCN_DISCOVERY;
6163 spin_unlock_irq(shost->host_lock);
6165 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
6168 /* Indicate we are walking fc_rscn_id_list on this vport */
6169 vport->fc_rscn_flush = 1;
6170 spin_unlock_irq(shost->host_lock);
6171 /* Get the array count after successfully have the token */
6172 rscn_cnt = vport->fc_rscn_id_cnt;
6173 /* If we are already processing an RSCN, save the received
6174 * RSCN payload buffer, cmdiocb->context2 to process later.
6176 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
6177 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6178 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
6179 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
6181 spin_lock_irq(shost->host_lock);
6182 vport->fc_flag |= FC_RSCN_DEFERRED;
6183 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
6184 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
6185 vport->fc_flag |= FC_RSCN_MODE;
6186 spin_unlock_irq(shost->host_lock);
6188 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
6189 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
6192 (payload_len + length <= LPFC_BPL_SIZE)) {
6193 *cmd &= ELS_CMD_MASK;
6194 *cmd |= cpu_to_be32(payload_len + length);
6195 memcpy(((uint8_t *)cmd) + length, lp,
6198 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
6199 vport->fc_rscn_id_cnt++;
6200 /* If we zero, cmdiocb->context2, the calling
6201 * routine will not try to free it.
6203 cmdiocb->context2 = NULL;
6206 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6207 "0235 Deferred RSCN "
6208 "Data: x%x x%x x%x\n",
6209 vport->fc_rscn_id_cnt, vport->fc_flag,
6212 vport->fc_flag |= FC_RSCN_DISCOVERY;
6213 spin_unlock_irq(shost->host_lock);
6214 /* ReDiscovery RSCN */
6215 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6216 "0234 ReDiscovery RSCN "
6217 "Data: x%x x%x x%x\n",
6218 vport->fc_rscn_id_cnt, vport->fc_flag,
6221 /* Indicate we are done walking fc_rscn_id_list on this vport */
6222 vport->fc_rscn_flush = 0;
6224 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
6225 /* send RECOVERY event for ALL nodes that match RSCN payload */
6226 lpfc_rscn_recovery_check(vport);
6227 spin_lock_irq(shost->host_lock);
6228 vport->fc_flag &= ~FC_RSCN_DEFERRED;
6229 spin_unlock_irq(shost->host_lock);
6232 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6233 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
6234 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
6236 spin_lock_irq(shost->host_lock);
6237 vport->fc_flag |= FC_RSCN_MODE;
6238 spin_unlock_irq(shost->host_lock);
6239 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
6240 /* Indicate we are done walking fc_rscn_id_list on this vport */
6241 vport->fc_rscn_flush = 0;
6243 * If we zero, cmdiocb->context2, the calling routine will
6244 * not try to free it.
6246 cmdiocb->context2 = NULL;
6247 lpfc_set_disctmo(vport);
6249 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
6250 /* send RECOVERY event for ALL nodes that match RSCN payload */
6251 lpfc_rscn_recovery_check(vport);
6252 return lpfc_els_handle_rscn(vport);
6256 * lpfc_els_handle_rscn - Handle rscn for a vport
6257 * @vport: pointer to a host virtual N_Port data structure.
6259 * This routine handles the Registration State Configuration Notification
6260 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
6261 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
6262 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
6263 * NameServer shall be issued. If CT command to the NameServer fails to be
6264 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
6265 * RSCN activities with the @vport.
6268 * 0 - Cleaned up rscn on the @vport
6269 * 1 - Wait for plogi to name server before proceed
6272 lpfc_els_handle_rscn(struct lpfc_vport *vport)
6274 struct lpfc_nodelist *ndlp;
6276 /* Ignore RSCN if the port is being torn down. */
6277 if (vport->load_flag & FC_UNLOADING) {
6278 lpfc_els_flush_rscn(vport);
6282 /* Start timer for RSCN processing */
6283 lpfc_set_disctmo(vport);
6285 /* RSCN processed */
6286 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6287 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
6288 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
6291 /* To process RSCN, first compare RSCN data with NameServer */
6292 vport->fc_ns_retry = 0;
6293 vport->num_disc_nodes = 0;
6295 ndlp = lpfc_findnode_did(vport, NameServer_DID);
6296 if (ndlp && NLP_CHK_NODE_ACT(ndlp)
6297 && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
6298 /* Good ndlp, issue CT Request to NameServer. Need to
6299 * know how many gidfts were issued. If none, then just
6300 * flush the RSCN. Otherwise, the outstanding requests
6303 vport->gidft_inp = 0;
6304 if (lpfc_issue_gidft(vport) > 0)
6307 /* Nameserver login in question. Revalidate. */
6309 ndlp = lpfc_enable_node(vport, ndlp,
6310 NLP_STE_PLOGI_ISSUE);
6312 lpfc_els_flush_rscn(vport);
6315 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
6317 ndlp = lpfc_nlp_init(vport, NameServer_DID);
6319 lpfc_els_flush_rscn(vport);
6322 ndlp->nlp_prev_state = ndlp->nlp_state;
6323 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
6325 ndlp->nlp_type |= NLP_FABRIC;
6326 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
6327 /* Wait for NameServer login cmpl before we can
6333 lpfc_els_flush_rscn(vport);
6338 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
6339 * @vport: pointer to a host virtual N_Port data structure.
6340 * @cmdiocb: pointer to lpfc command iocb data structure.
6341 * @ndlp: pointer to a node-list data structure.
6343 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
6344 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
6345 * point topology. As an unsolicited FLOGI should not be received in a loop
6346 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
6347 * lpfc_check_sparm() routine is invoked to check the parameters in the
6348 * unsolicited FLOGI. If parameters validation failed, the routine
6349 * lpfc_els_rsp_reject() shall be called with reject reason code set to
6350 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
6351 * FLOGI shall be compared with the Port WWN of the @vport to determine who
6352 * will initiate PLOGI. The higher lexicographical value party shall has
6353 * higher priority (as the winning port) and will initiate PLOGI and
6354 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
6355 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
6356 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
6359 * 0 - Successfully processed the unsolicited flogi
6360 * 1 - Failed to process the unsolicited flogi
6363 lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6364 struct lpfc_nodelist *ndlp)
6366 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6367 struct lpfc_hba *phba = vport->phba;
6368 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6369 uint32_t *lp = (uint32_t *) pcmd->virt;
6370 IOCB_t *icmd = &cmdiocb->iocb;
6371 struct serv_parm *sp;
6375 uint32_t fc_flag = 0;
6376 uint32_t port_state = 0;
6379 sp = (struct serv_parm *) lp;
6381 /* FLOGI received */
6383 lpfc_set_disctmo(vport);
6385 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
6386 /* We should never receive a FLOGI in loop mode, ignore it */
6387 did = icmd->un.elsreq64.remoteID;
6389 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
6391 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6392 "0113 An FLOGI ELS command x%x was "
6393 "received from DID x%x in Loop Mode\n",
6398 (void) lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1);
6401 * If our portname is greater than the remote portname,
6402 * then we initiate Nport login.
6405 rc = memcmp(&vport->fc_portname, &sp->portName,
6406 sizeof(struct lpfc_name));
6409 if (phba->sli_rev < LPFC_SLI_REV4) {
6410 mbox = mempool_alloc(phba->mbox_mem_pool,
6414 lpfc_linkdown(phba);
6415 lpfc_init_link(phba, mbox,
6417 phba->cfg_link_speed);
6418 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
6419 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
6420 mbox->vport = vport;
6421 rc = lpfc_sli_issue_mbox(phba, mbox,
6423 lpfc_set_loopback_flag(phba);
6424 if (rc == MBX_NOT_FINISHED)
6425 mempool_free(mbox, phba->mbox_mem_pool);
6429 /* abort the flogi coming back to ourselves
6430 * due to external loopback on the port.
6432 lpfc_els_abort_flogi(phba);
6435 } else if (rc > 0) { /* greater than */
6436 spin_lock_irq(shost->host_lock);
6437 vport->fc_flag |= FC_PT2PT_PLOGI;
6438 spin_unlock_irq(shost->host_lock);
6440 /* If we have the high WWPN we can assign our own
6441 * myDID; otherwise, we have to WAIT for a PLOGI
6442 * from the remote NPort to find out what it
6445 vport->fc_myDID = PT2PT_LocalID;
6447 vport->fc_myDID = PT2PT_RemoteID;
6451 * The vport state should go to LPFC_FLOGI only
6452 * AFTER we issue a FLOGI, not receive one.
6454 spin_lock_irq(shost->host_lock);
6455 fc_flag = vport->fc_flag;
6456 port_state = vport->port_state;
6457 vport->fc_flag |= FC_PT2PT;
6458 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
6459 spin_unlock_irq(shost->host_lock);
6460 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6461 "3311 Rcv Flogi PS x%x new PS x%x "
6462 "fc_flag x%x new fc_flag x%x\n",
6463 port_state, vport->port_state,
6464 fc_flag, vport->fc_flag);
6467 * We temporarily set fc_myDID to make it look like we are
6468 * a Fabric. This is done just so we end up with the right
6469 * did / sid on the FLOGI ACC rsp.
6471 did = vport->fc_myDID;
6472 vport->fc_myDID = Fabric_DID;
6474 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
6477 lpfc_els_rsp_acc(vport, ELS_CMD_FLOGI, cmdiocb, ndlp, NULL);
6479 /* Now lets put fc_myDID back to what its supposed to be */
6480 vport->fc_myDID = did;
6486 * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
6487 * @vport: pointer to a host virtual N_Port data structure.
6488 * @cmdiocb: pointer to lpfc command iocb data structure.
6489 * @ndlp: pointer to a node-list data structure.
6491 * This routine processes Request Node Identification Data (RNID) IOCB
6492 * received as an ELS unsolicited event. Only when the RNID specified format
6493 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
6494 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
6495 * Accept (ACC) the RNID ELS command. All the other RNID formats are
6496 * rejected by invoking the lpfc_els_rsp_reject() routine.
6499 * 0 - Successfully processed rnid iocb (currently always return 0)
6502 lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6503 struct lpfc_nodelist *ndlp)
6505 struct lpfc_dmabuf *pcmd;
6511 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6512 lp = (uint32_t *) pcmd->virt;
6519 switch (rn->Format) {
6521 case RNID_TOPOLOGY_DISC:
6523 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
6526 /* Reject this request because format not supported */
6527 stat.un.b.lsRjtRsvd0 = 0;
6528 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6529 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
6530 stat.un.b.vendorUnique = 0;
6531 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
6538 * lpfc_els_rcv_echo - Process an unsolicited echo iocb
6539 * @vport: pointer to a host virtual N_Port data structure.
6540 * @cmdiocb: pointer to lpfc command iocb data structure.
6541 * @ndlp: pointer to a node-list data structure.
6544 * 0 - Successfully processed echo iocb (currently always return 0)
6547 lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6548 struct lpfc_nodelist *ndlp)
6552 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
6554 /* skip over first word of echo command to find echo data */
6555 pcmd += sizeof(uint32_t);
6557 lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp);
6562 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
6563 * @vport: pointer to a host virtual N_Port data structure.
6564 * @cmdiocb: pointer to lpfc command iocb data structure.
6565 * @ndlp: pointer to a node-list data structure.
6567 * This routine processes a Link Incident Report Registration(LIRR) IOCB
6568 * received as an ELS unsolicited event. Currently, this function just invokes
6569 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
6572 * 0 - Successfully processed lirr iocb (currently always return 0)
6575 lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6576 struct lpfc_nodelist *ndlp)
6580 /* For now, unconditionally reject this command */
6581 stat.un.b.lsRjtRsvd0 = 0;
6582 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6583 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
6584 stat.un.b.vendorUnique = 0;
6585 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
6590 * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb
6591 * @vport: pointer to a host virtual N_Port data structure.
6592 * @cmdiocb: pointer to lpfc command iocb data structure.
6593 * @ndlp: pointer to a node-list data structure.
6595 * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB
6596 * received as an ELS unsolicited event. A request to RRQ shall only
6597 * be accepted if the Originator Nx_Port N_Port_ID or the Responder
6598 * Nx_Port N_Port_ID of the target Exchange is the same as the
6599 * N_Port_ID of the Nx_Port that makes the request. If the RRQ is
6600 * not accepted, an LS_RJT with reason code "Unable to perform
6601 * command request" and reason code explanation "Invalid Originator
6602 * S_ID" shall be returned. For now, we just unconditionally accept
6603 * RRQ from the target.
6606 lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6607 struct lpfc_nodelist *ndlp)
6609 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
6610 if (vport->phba->sli_rev == LPFC_SLI_REV4)
6611 lpfc_els_clear_rrq(vport, cmdiocb, ndlp);
6615 * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
6616 * @phba: pointer to lpfc hba data structure.
6617 * @pmb: pointer to the driver internal queue element for mailbox command.
6619 * This routine is the completion callback function for the MBX_READ_LNK_STAT
6620 * mailbox command. This callback function is to actually send the Accept
6621 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
6622 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
6623 * mailbox command, constructs the RPS response with the link statistics
6624 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
6625 * response to the RPS.
6627 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6628 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6629 * will be stored into the context1 field of the IOCB for the completion
6630 * callback function to the RPS Accept Response ELS IOCB command.
6634 lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
6638 struct RLS_RSP *rls_rsp;
6640 struct lpfc_iocbq *elsiocb;
6641 struct lpfc_nodelist *ndlp;
6648 ndlp = (struct lpfc_nodelist *) pmb->context2;
6649 rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff);
6650 oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff);
6651 pmb->context1 = NULL;
6652 pmb->context2 = NULL;
6654 if (mb->mbxStatus) {
6655 mempool_free(pmb, phba->mbox_mem_pool);
6659 cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t);
6660 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
6661 lpfc_max_els_tries, ndlp,
6662 ndlp->nlp_DID, ELS_CMD_ACC);
6664 /* Decrement the ndlp reference count from previous mbox command */
6668 mempool_free(pmb, phba->mbox_mem_pool);
6672 icmd = &elsiocb->iocb;
6673 icmd->ulpContext = rxid;
6674 icmd->unsli3.rcvsli3.ox_id = oxid;
6676 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6677 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
6678 pcmd += sizeof(uint32_t); /* Skip past command */
6679 rls_rsp = (struct RLS_RSP *)pcmd;
6681 rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
6682 rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
6683 rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
6684 rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
6685 rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
6686 rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
6687 mempool_free(pmb, phba->mbox_mem_pool);
6688 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
6689 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
6690 "2874 Xmit ELS RLS ACC response tag x%x xri x%x, "
6691 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
6692 elsiocb->iotag, elsiocb->iocb.ulpContext,
6693 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
6695 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
6696 phba->fc_stat.elsXmitACC++;
6697 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
6698 lpfc_els_free_iocb(phba, elsiocb);
6702 * lpfc_els_rsp_rps_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
6703 * @phba: pointer to lpfc hba data structure.
6704 * @pmb: pointer to the driver internal queue element for mailbox command.
6706 * This routine is the completion callback function for the MBX_READ_LNK_STAT
6707 * mailbox command. This callback function is to actually send the Accept
6708 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
6709 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
6710 * mailbox command, constructs the RPS response with the link statistics
6711 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
6712 * response to the RPS.
6714 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6715 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6716 * will be stored into the context1 field of the IOCB for the completion
6717 * callback function to the RPS Accept Response ELS IOCB command.
6721 lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
6727 struct lpfc_iocbq *elsiocb;
6728 struct lpfc_nodelist *ndlp;
6736 ndlp = (struct lpfc_nodelist *) pmb->context2;
6737 rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff);
6738 oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff);
6739 pmb->context1 = NULL;
6740 pmb->context2 = NULL;
6742 if (mb->mbxStatus) {
6743 mempool_free(pmb, phba->mbox_mem_pool);
6747 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
6748 mempool_free(pmb, phba->mbox_mem_pool);
6749 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
6750 lpfc_max_els_tries, ndlp,
6751 ndlp->nlp_DID, ELS_CMD_ACC);
6753 /* Decrement the ndlp reference count from previous mbox command */
6759 icmd = &elsiocb->iocb;
6760 icmd->ulpContext = rxid;
6761 icmd->unsli3.rcvsli3.ox_id = oxid;
6763 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6764 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
6765 pcmd += sizeof(uint32_t); /* Skip past command */
6766 rps_rsp = (RPS_RSP *)pcmd;
6768 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP)
6772 if (phba->pport->fc_flag & FC_FABRIC)
6776 rps_rsp->portStatus = cpu_to_be16(status);
6777 rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
6778 rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
6779 rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
6780 rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
6781 rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
6782 rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
6783 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
6784 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
6785 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
6786 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
6787 elsiocb->iotag, elsiocb->iocb.ulpContext,
6788 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
6790 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
6791 phba->fc_stat.elsXmitACC++;
6792 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
6793 lpfc_els_free_iocb(phba, elsiocb);
6798 * lpfc_els_rcv_rls - Process an unsolicited rls iocb
6799 * @vport: pointer to a host virtual N_Port data structure.
6800 * @cmdiocb: pointer to lpfc command iocb data structure.
6801 * @ndlp: pointer to a node-list data structure.
6803 * This routine processes Read Port Status (RPL) IOCB received as an
6804 * ELS unsolicited event. It first checks the remote port state. If the
6805 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
6806 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
6807 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
6808 * for reading the HBA link statistics. It is for the callback function,
6809 * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command
6810 * to actually sending out RPL Accept (ACC) response.
6813 * 0 - Successfully processed rls iocb (currently always return 0)
6816 lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6817 struct lpfc_nodelist *ndlp)
6819 struct lpfc_hba *phba = vport->phba;
6823 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
6824 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
6825 /* reject the unsolicited RPS request and done with it */
6828 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
6830 lpfc_read_lnk_stat(phba, mbox);
6831 mbox->context1 = (void *)((unsigned long)
6832 ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) |
6833 cmdiocb->iocb.ulpContext)); /* rx_id */
6834 mbox->context2 = lpfc_nlp_get(ndlp);
6835 mbox->vport = vport;
6836 mbox->mbox_cmpl = lpfc_els_rsp_rls_acc;
6837 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
6838 != MBX_NOT_FINISHED)
6839 /* Mbox completion will send ELS Response */
6841 /* Decrement reference count used for the failed mbox
6845 mempool_free(mbox, phba->mbox_mem_pool);
6848 /* issue rejection response */
6849 stat.un.b.lsRjtRsvd0 = 0;
6850 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6851 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
6852 stat.un.b.vendorUnique = 0;
6853 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
6858 * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb
6859 * @vport: pointer to a host virtual N_Port data structure.
6860 * @cmdiocb: pointer to lpfc command iocb data structure.
6861 * @ndlp: pointer to a node-list data structure.
6863 * This routine processes Read Timout Value (RTV) IOCB received as an
6864 * ELS unsolicited event. It first checks the remote port state. If the
6865 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
6866 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
6867 * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout
6868 * Value (RTV) unsolicited IOCB event.
6870 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6871 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6872 * will be stored into the context1 field of the IOCB for the completion
6873 * callback function to the RPS Accept Response ELS IOCB command.
6876 * 0 - Successfully processed rtv iocb (currently always return 0)
6879 lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6880 struct lpfc_nodelist *ndlp)
6882 struct lpfc_hba *phba = vport->phba;
6884 struct RTV_RSP *rtv_rsp;
6886 struct lpfc_iocbq *elsiocb;
6890 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
6891 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
6892 /* reject the unsolicited RPS request and done with it */
6895 cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t);
6896 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
6897 lpfc_max_els_tries, ndlp,
6898 ndlp->nlp_DID, ELS_CMD_ACC);
6903 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6904 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
6905 pcmd += sizeof(uint32_t); /* Skip past command */
6907 /* use the command's xri in the response */
6908 elsiocb->iocb.ulpContext = cmdiocb->iocb.ulpContext; /* Xri / rx_id */
6909 elsiocb->iocb.unsli3.rcvsli3.ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id;
6911 rtv_rsp = (struct RTV_RSP *)pcmd;
6913 /* populate RTV payload */
6914 rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000); /* report msecs */
6915 rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov);
6916 bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0);
6917 bf_set(qtov_rttov, rtv_rsp, 0); /* Field is for FC ONLY */
6918 rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov);
6920 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
6921 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
6922 "2875 Xmit ELS RTV ACC response tag x%x xri x%x, "
6923 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, "
6924 "Data: x%x x%x x%x\n",
6925 elsiocb->iotag, elsiocb->iocb.ulpContext,
6926 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
6928 rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov);
6929 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
6930 phba->fc_stat.elsXmitACC++;
6931 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
6932 lpfc_els_free_iocb(phba, elsiocb);
6936 /* issue rejection response */
6937 stat.un.b.lsRjtRsvd0 = 0;
6938 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6939 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
6940 stat.un.b.vendorUnique = 0;
6941 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
6945 /* lpfc_els_rcv_rps - Process an unsolicited rps iocb
6946 * @vport: pointer to a host virtual N_Port data structure.
6947 * @cmdiocb: pointer to lpfc command iocb data structure.
6948 * @ndlp: pointer to a node-list data structure.
6950 * This routine processes Read Port Status (RPS) IOCB received as an
6951 * ELS unsolicited event. It first checks the remote port state. If the
6952 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
6953 * state, it invokes the lpfc_els_rsp_reject() routine to send the reject
6954 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
6955 * for reading the HBA link statistics. It is for the callback function,
6956 * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command
6957 * to actually sending out RPS Accept (ACC) response.
6960 * 0 - Successfully processed rps iocb (currently always return 0)
6963 lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6964 struct lpfc_nodelist *ndlp)
6966 struct lpfc_hba *phba = vport->phba;
6970 struct lpfc_dmabuf *pcmd;
6974 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
6975 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
6976 /* reject the unsolicited RPS request and done with it */
6979 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6980 lp = (uint32_t *) pcmd->virt;
6981 flag = (be32_to_cpu(*lp++) & 0xf);
6985 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
6986 ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
6987 sizeof(struct lpfc_name)) == 0))) {
6989 printk("Fix me....\n");
6991 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
6993 lpfc_read_lnk_stat(phba, mbox);
6994 mbox->context1 = (void *)((unsigned long)
6995 ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) |
6996 cmdiocb->iocb.ulpContext)); /* rx_id */
6997 mbox->context2 = lpfc_nlp_get(ndlp);
6998 mbox->vport = vport;
6999 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
7000 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
7001 != MBX_NOT_FINISHED)
7002 /* Mbox completion will send ELS Response */
7004 /* Decrement reference count used for the failed mbox
7008 mempool_free(mbox, phba->mbox_mem_pool);
7013 /* issue rejection response */
7014 stat.un.b.lsRjtRsvd0 = 0;
7015 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
7016 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
7017 stat.un.b.vendorUnique = 0;
7018 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
7022 /* lpfc_issue_els_rrq - Process an unsolicited rps iocb
7023 * @vport: pointer to a host virtual N_Port data structure.
7024 * @ndlp: pointer to a node-list data structure.
7025 * @did: DID of the target.
7026 * @rrq: Pointer to the rrq struct.
7028 * Build a ELS RRQ command and send it to the target. If the issue_iocb is
7029 * Successful the the completion handler will clear the RRQ.
7032 * 0 - Successfully sent rrq els iocb.
7033 * 1 - Failed to send rrq els iocb.
7036 lpfc_issue_els_rrq(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
7037 uint32_t did, struct lpfc_node_rrq *rrq)
7039 struct lpfc_hba *phba = vport->phba;
7040 struct RRQ *els_rrq;
7041 struct lpfc_iocbq *elsiocb;
7047 if (ndlp != rrq->ndlp)
7049 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
7052 /* If ndlp is not NULL, we will bump the reference count on it */
7053 cmdsize = (sizeof(uint32_t) + sizeof(struct RRQ));
7054 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, did,
7059 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7061 /* For RRQ request, remainder of payload is Exchange IDs */
7062 *((uint32_t *) (pcmd)) = ELS_CMD_RRQ;
7063 pcmd += sizeof(uint32_t);
7064 els_rrq = (struct RRQ *) pcmd;
7066 bf_set(rrq_oxid, els_rrq, phba->sli4_hba.xri_ids[rrq->xritag]);
7067 bf_set(rrq_rxid, els_rrq, rrq->rxid);
7068 bf_set(rrq_did, els_rrq, vport->fc_myDID);
7069 els_rrq->rrq = cpu_to_be32(els_rrq->rrq);
7070 els_rrq->rrq_exchg = cpu_to_be32(els_rrq->rrq_exchg);
7073 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7074 "Issue RRQ: did:x%x",
7075 did, rrq->xritag, rrq->rxid);
7076 elsiocb->context_un.rrq = rrq;
7077 elsiocb->iocb_cmpl = lpfc_cmpl_els_rrq;
7078 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
7080 if (ret == IOCB_ERROR) {
7081 lpfc_els_free_iocb(phba, elsiocb);
7088 * lpfc_send_rrq - Sends ELS RRQ if needed.
7089 * @phba: pointer to lpfc hba data structure.
7090 * @rrq: pointer to the active rrq.
7092 * This routine will call the lpfc_issue_els_rrq if the rrq is
7093 * still active for the xri. If this function returns a failure then
7094 * the caller needs to clean up the RRQ by calling lpfc_clr_active_rrq.
7096 * Returns 0 Success.
7100 lpfc_send_rrq(struct lpfc_hba *phba, struct lpfc_node_rrq *rrq)
7102 struct lpfc_nodelist *ndlp = lpfc_findnode_did(rrq->vport,
7107 if (lpfc_test_rrq_active(phba, ndlp, rrq->xritag))
7108 return lpfc_issue_els_rrq(rrq->vport, ndlp,
7115 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
7116 * @vport: pointer to a host virtual N_Port data structure.
7117 * @cmdsize: size of the ELS command.
7118 * @oldiocb: pointer to the original lpfc command iocb data structure.
7119 * @ndlp: pointer to a node-list data structure.
7121 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
7122 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
7124 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7125 * will be incremented by 1 for holding the ndlp and the reference to ndlp
7126 * will be stored into the context1 field of the IOCB for the completion
7127 * callback function to the RPL Accept Response ELS command.
7130 * 0 - Successfully issued ACC RPL ELS command
7131 * 1 - Failed to issue ACC RPL ELS command
7134 lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
7135 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
7137 struct lpfc_hba *phba = vport->phba;
7138 IOCB_t *icmd, *oldcmd;
7140 struct lpfc_iocbq *elsiocb;
7143 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
7144 ndlp->nlp_DID, ELS_CMD_ACC);
7149 icmd = &elsiocb->iocb;
7150 oldcmd = &oldiocb->iocb;
7151 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
7152 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
7154 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7155 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
7156 pcmd += sizeof(uint16_t);
7157 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
7158 pcmd += sizeof(uint16_t);
7160 /* Setup the RPL ACC payload */
7161 rpl_rsp.listLen = be32_to_cpu(1);
7163 rpl_rsp.port_num_blk.portNum = 0;
7164 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
7165 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
7166 sizeof(struct lpfc_name));
7167 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
7168 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
7169 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7170 "0120 Xmit ELS RPL ACC response tag x%x "
7171 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
7173 elsiocb->iotag, elsiocb->iocb.ulpContext,
7174 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
7176 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
7177 phba->fc_stat.elsXmitACC++;
7178 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
7180 lpfc_els_free_iocb(phba, elsiocb);
7187 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
7188 * @vport: pointer to a host virtual N_Port data structure.
7189 * @cmdiocb: pointer to lpfc command iocb data structure.
7190 * @ndlp: pointer to a node-list data structure.
7192 * This routine processes Read Port List (RPL) IOCB received as an ELS
7193 * unsolicited event. It first checks the remote port state. If the remote
7194 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
7195 * invokes the lpfc_els_rsp_reject() routine to send reject response.
7196 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
7197 * to accept the RPL.
7200 * 0 - Successfully processed rpl iocb (currently always return 0)
7203 lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7204 struct lpfc_nodelist *ndlp)
7206 struct lpfc_dmabuf *pcmd;
7213 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
7214 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
7215 /* issue rejection response */
7216 stat.un.b.lsRjtRsvd0 = 0;
7217 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
7218 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
7219 stat.un.b.vendorUnique = 0;
7220 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
7222 /* rejected the unsolicited RPL request and done with it */
7226 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7227 lp = (uint32_t *) pcmd->virt;
7228 rpl = (RPL *) (lp + 1);
7229 maxsize = be32_to_cpu(rpl->maxsize);
7231 /* We support only one port */
7232 if ((rpl->index == 0) &&
7234 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
7235 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
7237 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
7239 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
7245 * lpfc_els_rcv_farp - Process an unsolicited farp request els command
7246 * @vport: pointer to a virtual N_Port data structure.
7247 * @cmdiocb: pointer to lpfc command iocb data structure.
7248 * @ndlp: pointer to a node-list data structure.
7250 * This routine processes Fibre Channel Address Resolution Protocol
7251 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
7252 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
7253 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
7254 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
7255 * remote PortName is compared against the FC PortName stored in the @vport
7256 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
7257 * compared against the FC NodeName stored in the @vport data structure.
7258 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
7259 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
7260 * invoked to send out FARP Response to the remote node. Before sending the
7261 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
7262 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
7263 * routine is invoked to log into the remote port first.
7266 * 0 - Either the FARP Match Mode not supported or successfully processed
7269 lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7270 struct lpfc_nodelist *ndlp)
7272 struct lpfc_dmabuf *pcmd;
7276 uint32_t cmd, cnt, did;
7278 icmd = &cmdiocb->iocb;
7279 did = icmd->un.elsreq64.remoteID;
7280 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7281 lp = (uint32_t *) pcmd->virt;
7285 /* FARP-REQ received from DID <did> */
7286 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7287 "0601 FARP-REQ received from DID x%x\n", did);
7288 /* We will only support match on WWPN or WWNN */
7289 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
7294 /* If this FARP command is searching for my portname */
7295 if (fp->Mflags & FARP_MATCH_PORT) {
7296 if (memcmp(&fp->RportName, &vport->fc_portname,
7297 sizeof(struct lpfc_name)) == 0)
7301 /* If this FARP command is searching for my nodename */
7302 if (fp->Mflags & FARP_MATCH_NODE) {
7303 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
7304 sizeof(struct lpfc_name)) == 0)
7309 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
7310 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
7311 /* Log back into the node before sending the FARP. */
7312 if (fp->Rflags & FARP_REQUEST_PLOGI) {
7313 ndlp->nlp_prev_state = ndlp->nlp_state;
7314 lpfc_nlp_set_state(vport, ndlp,
7315 NLP_STE_PLOGI_ISSUE);
7316 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
7319 /* Send a FARP response to that node */
7320 if (fp->Rflags & FARP_REQUEST_FARPR)
7321 lpfc_issue_els_farpr(vport, did, 0);
7328 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
7329 * @vport: pointer to a host virtual N_Port data structure.
7330 * @cmdiocb: pointer to lpfc command iocb data structure.
7331 * @ndlp: pointer to a node-list data structure.
7333 * This routine processes Fibre Channel Address Resolution Protocol
7334 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
7335 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
7336 * the FARP response request.
7339 * 0 - Successfully processed FARPR IOCB (currently always return 0)
7342 lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7343 struct lpfc_nodelist *ndlp)
7345 struct lpfc_dmabuf *pcmd;
7350 icmd = &cmdiocb->iocb;
7351 did = icmd->un.elsreq64.remoteID;
7352 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7353 lp = (uint32_t *) pcmd->virt;
7356 /* FARP-RSP received from DID <did> */
7357 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7358 "0600 FARP-RSP received from DID x%x\n", did);
7359 /* ACCEPT the Farp resp request */
7360 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
7366 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
7367 * @vport: pointer to a host virtual N_Port data structure.
7368 * @cmdiocb: pointer to lpfc command iocb data structure.
7369 * @fan_ndlp: pointer to a node-list data structure.
7371 * This routine processes a Fabric Address Notification (FAN) IOCB
7372 * command received as an ELS unsolicited event. The FAN ELS command will
7373 * only be processed on a physical port (i.e., the @vport represents the
7374 * physical port). The fabric NodeName and PortName from the FAN IOCB are
7375 * compared against those in the phba data structure. If any of those is
7376 * different, the lpfc_initial_flogi() routine is invoked to initialize
7377 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
7378 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
7379 * is invoked to register login to the fabric.
7382 * 0 - Successfully processed fan iocb (currently always return 0).
7385 lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7386 struct lpfc_nodelist *fan_ndlp)
7388 struct lpfc_hba *phba = vport->phba;
7392 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
7393 lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
7395 /* FAN received; Fan does not have a reply sequence */
7396 if ((vport == phba->pport) &&
7397 (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
7398 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
7399 sizeof(struct lpfc_name))) ||
7400 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
7401 sizeof(struct lpfc_name)))) {
7402 /* This port has switched fabrics. FLOGI is required */
7403 lpfc_issue_init_vfi(vport);
7405 /* FAN verified - skip FLOGI */
7406 vport->fc_myDID = vport->fc_prevDID;
7407 if (phba->sli_rev < LPFC_SLI_REV4)
7408 lpfc_issue_fabric_reglogin(vport);
7410 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7411 "3138 Need register VFI: (x%x/%x)\n",
7412 vport->fc_prevDID, vport->fc_myDID);
7413 lpfc_issue_reg_vfi(vport);
7421 * lpfc_els_timeout - Handler funciton to the els timer
7422 * @ptr: holder for the timer function associated data.
7424 * This routine is invoked by the ELS timer after timeout. It posts the ELS
7425 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
7426 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
7427 * up the worker thread. It is for the worker thread to invoke the routine
7428 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
7431 lpfc_els_timeout(unsigned long ptr)
7433 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
7434 struct lpfc_hba *phba = vport->phba;
7435 uint32_t tmo_posted;
7436 unsigned long iflag;
7438 spin_lock_irqsave(&vport->work_port_lock, iflag);
7439 tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
7440 if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING)))
7441 vport->work_port_events |= WORKER_ELS_TMO;
7442 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
7444 if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING)))
7445 lpfc_worker_wake_up(phba);
7451 * lpfc_els_timeout_handler - Process an els timeout event
7452 * @vport: pointer to a virtual N_Port data structure.
7454 * This routine is the actual handler function that processes an ELS timeout
7455 * event. It walks the ELS ring to get and abort all the IOCBs (except the
7456 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
7457 * invoking the lpfc_sli_issue_abort_iotag() routine.
7460 lpfc_els_timeout_handler(struct lpfc_vport *vport)
7462 struct lpfc_hba *phba = vport->phba;
7463 struct lpfc_sli_ring *pring;
7464 struct lpfc_iocbq *tmp_iocb, *piocb;
7466 struct lpfc_dmabuf *pcmd;
7467 uint32_t els_command = 0;
7469 uint32_t remote_ID = 0xffffffff;
7470 LIST_HEAD(abort_list);
7473 timeout = (uint32_t)(phba->fc_ratov << 1);
7475 pring = lpfc_phba_elsring(phba);
7476 if (unlikely(!pring))
7479 if ((phba->pport->load_flag & FC_UNLOADING))
7481 spin_lock_irq(&phba->hbalock);
7482 if (phba->sli_rev == LPFC_SLI_REV4)
7483 spin_lock(&pring->ring_lock);
7485 if ((phba->pport->load_flag & FC_UNLOADING)) {
7486 if (phba->sli_rev == LPFC_SLI_REV4)
7487 spin_unlock(&pring->ring_lock);
7488 spin_unlock_irq(&phba->hbalock);
7492 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
7495 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
7496 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
7497 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
7500 if (piocb->vport != vport)
7503 pcmd = (struct lpfc_dmabuf *) piocb->context2;
7505 els_command = *(uint32_t *) (pcmd->virt);
7507 if (els_command == ELS_CMD_FARP ||
7508 els_command == ELS_CMD_FARPR ||
7509 els_command == ELS_CMD_FDISC)
7512 if (piocb->drvrTimeout > 0) {
7513 if (piocb->drvrTimeout >= timeout)
7514 piocb->drvrTimeout -= timeout;
7516 piocb->drvrTimeout = 0;
7520 remote_ID = 0xffffffff;
7521 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
7522 remote_ID = cmd->un.elsreq64.remoteID;
7524 struct lpfc_nodelist *ndlp;
7525 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
7526 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
7527 remote_ID = ndlp->nlp_DID;
7529 list_add_tail(&piocb->dlist, &abort_list);
7531 if (phba->sli_rev == LPFC_SLI_REV4)
7532 spin_unlock(&pring->ring_lock);
7533 spin_unlock_irq(&phba->hbalock);
7535 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
7537 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7538 "0127 ELS timeout Data: x%x x%x x%x "
7539 "x%x\n", els_command,
7540 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
7541 spin_lock_irq(&phba->hbalock);
7542 list_del_init(&piocb->dlist);
7543 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
7544 spin_unlock_irq(&phba->hbalock);
7547 if (!list_empty(&pring->txcmplq))
7548 if (!(phba->pport->load_flag & FC_UNLOADING))
7549 mod_timer(&vport->els_tmofunc,
7550 jiffies + msecs_to_jiffies(1000 * timeout));
7554 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
7555 * @vport: pointer to a host virtual N_Port data structure.
7557 * This routine is used to clean up all the outstanding ELS commands on a
7558 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
7559 * routine. After that, it walks the ELS transmit queue to remove all the
7560 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
7561 * the IOCBs with a non-NULL completion callback function, the callback
7562 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
7563 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
7564 * callback function, the IOCB will simply be released. Finally, it walks
7565 * the ELS transmit completion queue to issue an abort IOCB to any transmit
7566 * completion queue IOCB that is associated with the @vport and is not
7567 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
7568 * part of the discovery state machine) out to HBA by invoking the
7569 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
7570 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
7571 * the IOCBs are aborted when this function returns.
7574 lpfc_els_flush_cmd(struct lpfc_vport *vport)
7576 LIST_HEAD(abort_list);
7577 struct lpfc_hba *phba = vport->phba;
7578 struct lpfc_sli_ring *pring;
7579 struct lpfc_iocbq *tmp_iocb, *piocb;
7582 lpfc_fabric_abort_vport(vport);
7584 * For SLI3, only the hbalock is required. But SLI4 needs to coordinate
7585 * with the ring insert operation. Because lpfc_sli_issue_abort_iotag
7586 * ultimately grabs the ring_lock, the driver must splice the list into
7587 * a working list and release the locks before calling the abort.
7589 spin_lock_irq(&phba->hbalock);
7590 pring = lpfc_phba_elsring(phba);
7592 /* Bail out if we've no ELS wq, like in PCI error recovery case. */
7593 if (unlikely(!pring)) {
7594 spin_unlock_irq(&phba->hbalock);
7598 if (phba->sli_rev == LPFC_SLI_REV4)
7599 spin_lock(&pring->ring_lock);
7601 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
7602 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
7605 if (piocb->vport != vport)
7607 list_add_tail(&piocb->dlist, &abort_list);
7609 if (phba->sli_rev == LPFC_SLI_REV4)
7610 spin_unlock(&pring->ring_lock);
7611 spin_unlock_irq(&phba->hbalock);
7612 /* Abort each iocb on the aborted list and remove the dlist links. */
7613 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
7614 spin_lock_irq(&phba->hbalock);
7615 list_del_init(&piocb->dlist);
7616 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
7617 spin_unlock_irq(&phba->hbalock);
7619 if (!list_empty(&abort_list))
7620 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7621 "3387 abort list for txq not empty\n");
7622 INIT_LIST_HEAD(&abort_list);
7624 spin_lock_irq(&phba->hbalock);
7625 if (phba->sli_rev == LPFC_SLI_REV4)
7626 spin_lock(&pring->ring_lock);
7628 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
7631 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
7635 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
7636 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
7637 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
7638 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
7639 cmd->ulpCommand == CMD_ABORT_XRI_CN)
7642 if (piocb->vport != vport)
7645 list_del_init(&piocb->list);
7646 list_add_tail(&piocb->list, &abort_list);
7648 if (phba->sli_rev == LPFC_SLI_REV4)
7649 spin_unlock(&pring->ring_lock);
7650 spin_unlock_irq(&phba->hbalock);
7652 /* Cancell all the IOCBs from the completions list */
7653 lpfc_sli_cancel_iocbs(phba, &abort_list,
7654 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
7660 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
7661 * @phba: pointer to lpfc hba data structure.
7663 * This routine is used to clean up all the outstanding ELS commands on a
7664 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
7665 * routine. After that, it walks the ELS transmit queue to remove all the
7666 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
7667 * the IOCBs with the completion callback function associated, the callback
7668 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
7669 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
7670 * callback function associated, the IOCB will simply be released. Finally,
7671 * it walks the ELS transmit completion queue to issue an abort IOCB to any
7672 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
7673 * management plane IOCBs that are not part of the discovery state machine)
7674 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
7677 lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
7679 struct lpfc_vport *vport;
7680 list_for_each_entry(vport, &phba->port_list, listentry)
7681 lpfc_els_flush_cmd(vport);
7687 * lpfc_send_els_failure_event - Posts an ELS command failure event
7688 * @phba: Pointer to hba context object.
7689 * @cmdiocbp: Pointer to command iocb which reported error.
7690 * @rspiocbp: Pointer to response iocb which reported error.
7692 * This function sends an event when there is an ELS command
7696 lpfc_send_els_failure_event(struct lpfc_hba *phba,
7697 struct lpfc_iocbq *cmdiocbp,
7698 struct lpfc_iocbq *rspiocbp)
7700 struct lpfc_vport *vport = cmdiocbp->vport;
7701 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7702 struct lpfc_lsrjt_event lsrjt_event;
7703 struct lpfc_fabric_event_header fabric_event;
7705 struct lpfc_nodelist *ndlp;
7708 ndlp = cmdiocbp->context1;
7709 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
7712 if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) {
7713 lsrjt_event.header.event_type = FC_REG_ELS_EVENT;
7714 lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV;
7715 memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname,
7716 sizeof(struct lpfc_name));
7717 memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename,
7718 sizeof(struct lpfc_name));
7719 pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
7720 cmdiocbp->context2)->virt);
7721 lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0;
7722 stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]);
7723 lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode;
7724 lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp;
7725 fc_host_post_vendor_event(shost,
7726 fc_get_event_number(),
7727 sizeof(lsrjt_event),
7728 (char *)&lsrjt_event,
7732 if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) ||
7733 (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) {
7734 fabric_event.event_type = FC_REG_FABRIC_EVENT;
7735 if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY)
7736 fabric_event.subcategory = LPFC_EVENT_PORT_BUSY;
7738 fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY;
7739 memcpy(fabric_event.wwpn, &ndlp->nlp_portname,
7740 sizeof(struct lpfc_name));
7741 memcpy(fabric_event.wwnn, &ndlp->nlp_nodename,
7742 sizeof(struct lpfc_name));
7743 fc_host_post_vendor_event(shost,
7744 fc_get_event_number(),
7745 sizeof(fabric_event),
7746 (char *)&fabric_event,
7754 * lpfc_send_els_event - Posts unsolicited els event
7755 * @vport: Pointer to vport object.
7756 * @ndlp: Pointer FC node object.
7757 * @cmd: ELS command code.
7759 * This function posts an event when there is an incoming
7760 * unsolicited ELS command.
7763 lpfc_send_els_event(struct lpfc_vport *vport,
7764 struct lpfc_nodelist *ndlp,
7767 struct lpfc_els_event_header *els_data = NULL;
7768 struct lpfc_logo_event *logo_data = NULL;
7769 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7771 if (*payload == ELS_CMD_LOGO) {
7772 logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL);
7774 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7775 "0148 Failed to allocate memory "
7776 "for LOGO event\n");
7779 els_data = &logo_data->header;
7781 els_data = kmalloc(sizeof(struct lpfc_els_event_header),
7784 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7785 "0149 Failed to allocate memory "
7790 els_data->event_type = FC_REG_ELS_EVENT;
7793 els_data->subcategory = LPFC_EVENT_PLOGI_RCV;
7796 els_data->subcategory = LPFC_EVENT_PRLO_RCV;
7799 els_data->subcategory = LPFC_EVENT_ADISC_RCV;
7802 els_data->subcategory = LPFC_EVENT_LOGO_RCV;
7803 /* Copy the WWPN in the LOGO payload */
7804 memcpy(logo_data->logo_wwpn, &payload[2],
7805 sizeof(struct lpfc_name));
7811 memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name));
7812 memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name));
7813 if (*payload == ELS_CMD_LOGO) {
7814 fc_host_post_vendor_event(shost,
7815 fc_get_event_number(),
7816 sizeof(struct lpfc_logo_event),
7821 fc_host_post_vendor_event(shost,
7822 fc_get_event_number(),
7823 sizeof(struct lpfc_els_event_header),
7834 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
7835 * @phba: pointer to lpfc hba data structure.
7836 * @pring: pointer to a SLI ring.
7837 * @vport: pointer to a host virtual N_Port data structure.
7838 * @elsiocb: pointer to lpfc els command iocb data structure.
7840 * This routine is used for processing the IOCB associated with a unsolicited
7841 * event. It first determines whether there is an existing ndlp that matches
7842 * the DID from the unsolicited IOCB. If not, it will create a new one with
7843 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
7844 * IOCB is then used to invoke the proper routine and to set up proper state
7845 * of the discovery state machine.
7848 lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
7849 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
7851 struct Scsi_Host *shost;
7852 struct lpfc_nodelist *ndlp;
7855 uint32_t cmd, did, newnode;
7856 uint8_t rjt_exp, rjt_err = 0;
7857 IOCB_t *icmd = &elsiocb->iocb;
7859 if (!vport || !(elsiocb->context2))
7863 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
7865 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
7866 lpfc_post_buffer(phba, pring, 1);
7868 did = icmd->un.rcvels.remoteID;
7869 if (icmd->ulpStatus) {
7870 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7871 "RCV Unsol ELS: status:x%x/x%x did:x%x",
7872 icmd->ulpStatus, icmd->un.ulpWord[4], did);
7876 /* Check to see if link went down during discovery */
7877 if (lpfc_els_chk_latt(vport))
7880 /* Ignore traffic received during vport shutdown. */
7881 if (vport->load_flag & FC_UNLOADING)
7884 /* If NPort discovery is delayed drop incoming ELS */
7885 if ((vport->fc_flag & FC_DISC_DELAYED) &&
7886 (cmd != ELS_CMD_PLOGI))
7889 ndlp = lpfc_findnode_did(vport, did);
7891 /* Cannot find existing Fabric ndlp, so allocate a new one */
7892 ndlp = lpfc_nlp_init(vport, did);
7895 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
7897 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
7898 ndlp->nlp_type |= NLP_FABRIC;
7899 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
7900 ndlp = lpfc_enable_node(vport, ndlp,
7901 NLP_STE_UNUSED_NODE);
7904 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
7906 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
7907 ndlp->nlp_type |= NLP_FABRIC;
7908 } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
7909 /* This is similar to the new node path */
7910 ndlp = lpfc_nlp_get(ndlp);
7913 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
7917 phba->fc_stat.elsRcvFrame++;
7920 * Do not process any unsolicited ELS commands
7921 * if the ndlp is in DEV_LOSS
7923 shost = lpfc_shost_from_vport(vport);
7924 spin_lock_irq(shost->host_lock);
7925 if (ndlp->nlp_flag & NLP_IN_DEV_LOSS) {
7926 spin_unlock_irq(shost->host_lock);
7931 spin_unlock_irq(shost->host_lock);
7933 elsiocb->context1 = lpfc_nlp_get(ndlp);
7934 elsiocb->vport = vport;
7936 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
7937 cmd &= ELS_CMD_MASK;
7939 /* ELS command <elsCmd> received from NPORT <did> */
7940 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7941 "0112 ELS command x%x received from NPORT x%x "
7942 "Data: x%x x%x x%x x%x\n",
7943 cmd, did, vport->port_state, vport->fc_flag,
7944 vport->fc_myDID, vport->fc_prevDID);
7946 /* reject till our FLOGI completes */
7947 if ((vport->port_state < LPFC_FABRIC_CFG_LINK) &&
7948 (cmd != ELS_CMD_FLOGI)) {
7949 rjt_err = LSRJT_LOGICAL_BSY;
7950 rjt_exp = LSEXP_NOTHING_MORE;
7956 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7957 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
7958 did, vport->port_state, ndlp->nlp_flag);
7960 phba->fc_stat.elsRcvPLOGI++;
7961 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
7962 if (phba->sli_rev == LPFC_SLI_REV4 &&
7963 (phba->pport->fc_flag & FC_PT2PT)) {
7964 vport->fc_prevDID = vport->fc_myDID;
7965 /* Our DID needs to be updated before registering
7966 * the vfi. This is done in lpfc_rcv_plogi but
7967 * that is called after the reg_vfi.
7969 vport->fc_myDID = elsiocb->iocb.un.rcvels.parmRo;
7970 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7971 "3312 Remote port assigned DID x%x "
7972 "%x\n", vport->fc_myDID,
7976 lpfc_send_els_event(vport, ndlp, payload);
7978 /* If Nport discovery is delayed, reject PLOGIs */
7979 if (vport->fc_flag & FC_DISC_DELAYED) {
7980 rjt_err = LSRJT_UNABLE_TPC;
7981 rjt_exp = LSEXP_NOTHING_MORE;
7985 if (vport->port_state < LPFC_DISC_AUTH) {
7986 if (!(phba->pport->fc_flag & FC_PT2PT) ||
7987 (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
7988 rjt_err = LSRJT_UNABLE_TPC;
7989 rjt_exp = LSEXP_NOTHING_MORE;
7994 spin_lock_irq(shost->host_lock);
7995 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
7996 spin_unlock_irq(shost->host_lock);
7998 lpfc_disc_state_machine(vport, ndlp, elsiocb,
8003 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8004 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
8005 did, vport->port_state, ndlp->nlp_flag);
8007 phba->fc_stat.elsRcvFLOGI++;
8008 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
8013 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8014 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
8015 did, vport->port_state, ndlp->nlp_flag);
8017 phba->fc_stat.elsRcvLOGO++;
8018 lpfc_send_els_event(vport, ndlp, payload);
8019 if (vport->port_state < LPFC_DISC_AUTH) {
8020 rjt_err = LSRJT_UNABLE_TPC;
8021 rjt_exp = LSEXP_NOTHING_MORE;
8024 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
8027 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8028 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
8029 did, vport->port_state, ndlp->nlp_flag);
8031 phba->fc_stat.elsRcvPRLO++;
8032 lpfc_send_els_event(vport, ndlp, payload);
8033 if (vport->port_state < LPFC_DISC_AUTH) {
8034 rjt_err = LSRJT_UNABLE_TPC;
8035 rjt_exp = LSEXP_NOTHING_MORE;
8038 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
8041 phba->fc_stat.elsRcvLCB++;
8042 lpfc_els_rcv_lcb(vport, elsiocb, ndlp);
8045 phba->fc_stat.elsRcvRDP++;
8046 lpfc_els_rcv_rdp(vport, elsiocb, ndlp);
8049 phba->fc_stat.elsRcvRSCN++;
8050 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
8055 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8056 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
8057 did, vport->port_state, ndlp->nlp_flag);
8059 lpfc_send_els_event(vport, ndlp, payload);
8060 phba->fc_stat.elsRcvADISC++;
8061 if (vport->port_state < LPFC_DISC_AUTH) {
8062 rjt_err = LSRJT_UNABLE_TPC;
8063 rjt_exp = LSEXP_NOTHING_MORE;
8066 lpfc_disc_state_machine(vport, ndlp, elsiocb,
8070 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8071 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
8072 did, vport->port_state, ndlp->nlp_flag);
8074 phba->fc_stat.elsRcvPDISC++;
8075 if (vport->port_state < LPFC_DISC_AUTH) {
8076 rjt_err = LSRJT_UNABLE_TPC;
8077 rjt_exp = LSEXP_NOTHING_MORE;
8080 lpfc_disc_state_machine(vport, ndlp, elsiocb,
8084 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8085 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
8086 did, vport->port_state, ndlp->nlp_flag);
8088 phba->fc_stat.elsRcvFARPR++;
8089 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
8092 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8093 "RCV FARP: did:x%x/ste:x%x flg:x%x",
8094 did, vport->port_state, ndlp->nlp_flag);
8096 phba->fc_stat.elsRcvFARP++;
8097 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
8100 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8101 "RCV FAN: did:x%x/ste:x%x flg:x%x",
8102 did, vport->port_state, ndlp->nlp_flag);
8104 phba->fc_stat.elsRcvFAN++;
8105 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
8108 case ELS_CMD_NVMEPRLI:
8109 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8110 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
8111 did, vport->port_state, ndlp->nlp_flag);
8113 phba->fc_stat.elsRcvPRLI++;
8114 if ((vport->port_state < LPFC_DISC_AUTH) &&
8115 (vport->fc_flag & FC_FABRIC)) {
8116 rjt_err = LSRJT_UNABLE_TPC;
8117 rjt_exp = LSEXP_NOTHING_MORE;
8121 /* NVMET accepts NVME PRLI only. Reject FCP PRLI */
8122 if (cmd == ELS_CMD_PRLI && phba->nvmet_support) {
8123 rjt_err = LSRJT_CMD_UNSUPPORTED;
8124 rjt_exp = LSEXP_REQ_UNSUPPORTED;
8127 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
8130 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8131 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
8132 did, vport->port_state, ndlp->nlp_flag);
8134 phba->fc_stat.elsRcvLIRR++;
8135 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
8140 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8141 "RCV RLS: did:x%x/ste:x%x flg:x%x",
8142 did, vport->port_state, ndlp->nlp_flag);
8144 phba->fc_stat.elsRcvRLS++;
8145 lpfc_els_rcv_rls(vport, elsiocb, ndlp);
8150 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8151 "RCV RPS: did:x%x/ste:x%x flg:x%x",
8152 did, vport->port_state, ndlp->nlp_flag);
8154 phba->fc_stat.elsRcvRPS++;
8155 lpfc_els_rcv_rps(vport, elsiocb, ndlp);
8160 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8161 "RCV RPL: did:x%x/ste:x%x flg:x%x",
8162 did, vport->port_state, ndlp->nlp_flag);
8164 phba->fc_stat.elsRcvRPL++;
8165 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
8170 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8171 "RCV RNID: did:x%x/ste:x%x flg:x%x",
8172 did, vport->port_state, ndlp->nlp_flag);
8174 phba->fc_stat.elsRcvRNID++;
8175 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
8180 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8181 "RCV RTV: did:x%x/ste:x%x flg:x%x",
8182 did, vport->port_state, ndlp->nlp_flag);
8183 phba->fc_stat.elsRcvRTV++;
8184 lpfc_els_rcv_rtv(vport, elsiocb, ndlp);
8189 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8190 "RCV RRQ: did:x%x/ste:x%x flg:x%x",
8191 did, vport->port_state, ndlp->nlp_flag);
8193 phba->fc_stat.elsRcvRRQ++;
8194 lpfc_els_rcv_rrq(vport, elsiocb, ndlp);
8199 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8200 "RCV ECHO: did:x%x/ste:x%x flg:x%x",
8201 did, vport->port_state, ndlp->nlp_flag);
8203 phba->fc_stat.elsRcvECHO++;
8204 lpfc_els_rcv_echo(vport, elsiocb, ndlp);
8209 /* receive this due to exchange closed */
8210 rjt_err = LSRJT_UNABLE_TPC;
8211 rjt_exp = LSEXP_INVALID_OX_RX;
8214 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8215 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
8216 cmd, did, vport->port_state);
8218 /* Unsupported ELS command, reject */
8219 rjt_err = LSRJT_CMD_UNSUPPORTED;
8220 rjt_exp = LSEXP_NOTHING_MORE;
8222 /* Unknown ELS command <elsCmd> received from NPORT <did> */
8223 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8224 "0115 Unknown ELS command x%x "
8225 "received from NPORT x%x\n", cmd, did);
8232 /* check if need to LS_RJT received ELS cmd */
8234 memset(&stat, 0, sizeof(stat));
8235 stat.un.b.lsRjtRsnCode = rjt_err;
8236 stat.un.b.lsRjtRsnCodeExp = rjt_exp;
8237 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
8241 lpfc_nlp_put(elsiocb->context1);
8242 elsiocb->context1 = NULL;
8246 if (vport && !(vport->load_flag & FC_UNLOADING))
8247 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8248 "0111 Dropping received ELS cmd "
8249 "Data: x%x x%x x%x\n",
8250 icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout);
8251 phba->fc_stat.elsRcvDrop++;
8255 * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
8256 * @phba: pointer to lpfc hba data structure.
8257 * @pring: pointer to a SLI ring.
8258 * @elsiocb: pointer to lpfc els iocb data structure.
8260 * This routine is used to process an unsolicited event received from a SLI
8261 * (Service Level Interface) ring. The actual processing of the data buffer
8262 * associated with the unsolicited event is done by invoking the routine
8263 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
8264 * SLI ring on which the unsolicited event was received.
8267 lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
8268 struct lpfc_iocbq *elsiocb)
8270 struct lpfc_vport *vport = phba->pport;
8271 IOCB_t *icmd = &elsiocb->iocb;
8273 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
8274 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
8276 elsiocb->context1 = NULL;
8277 elsiocb->context2 = NULL;
8278 elsiocb->context3 = NULL;
8280 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
8281 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
8282 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
8283 (icmd->un.ulpWord[4] & IOERR_PARAM_MASK) ==
8284 IOERR_RCV_BUFFER_WAITING) {
8285 phba->fc_stat.NoRcvBuf++;
8286 /* Not enough posted buffers; Try posting more buffers */
8287 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
8288 lpfc_post_buffer(phba, pring, 0);
8292 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
8293 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
8294 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
8295 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
8296 vport = phba->pport;
8298 vport = lpfc_find_vport_by_vpid(phba,
8299 icmd->unsli3.rcvsli3.vpi);
8302 /* If there are no BDEs associated
8303 * with this IOCB, there is nothing to do.
8305 if (icmd->ulpBdeCount == 0)
8308 /* type of ELS cmd is first 32bit word
8311 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
8312 elsiocb->context2 = bdeBuf1;
8314 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
8315 icmd->un.cont64[0].addrLow);
8316 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
8320 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
8322 * The different unsolicited event handlers would tell us
8323 * if they are done with "mp" by setting context2 to NULL.
8325 if (elsiocb->context2) {
8326 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
8327 elsiocb->context2 = NULL;
8330 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
8331 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
8332 icmd->ulpBdeCount == 2) {
8333 elsiocb->context2 = bdeBuf2;
8334 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
8335 /* free mp if we are done with it */
8336 if (elsiocb->context2) {
8337 lpfc_in_buf_free(phba, elsiocb->context2);
8338 elsiocb->context2 = NULL;
8344 lpfc_start_fdmi(struct lpfc_vport *vport)
8346 struct lpfc_nodelist *ndlp;
8348 /* If this is the first time, allocate an ndlp and initialize
8349 * it. Otherwise, make sure the node is enabled and then do the
8352 ndlp = lpfc_findnode_did(vport, FDMI_DID);
8354 ndlp = lpfc_nlp_init(vport, FDMI_DID);
8356 ndlp->nlp_type |= NLP_FABRIC;
8361 if (!NLP_CHK_NODE_ACT(ndlp))
8362 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_NPR_NODE);
8365 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
8366 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
8371 * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
8372 * @phba: pointer to lpfc hba data structure.
8373 * @vport: pointer to a virtual N_Port data structure.
8375 * This routine issues a Port Login (PLOGI) to the Name Server with
8376 * State Change Request (SCR) for a @vport. This routine will create an
8377 * ndlp for the Name Server associated to the @vport if such node does
8378 * not already exist. The PLOGI to Name Server is issued by invoking the
8379 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
8380 * (FDMI) is configured to the @vport, a FDMI node will be created and
8381 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
8384 lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
8386 struct lpfc_nodelist *ndlp;
8387 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8390 * If lpfc_delay_discovery parameter is set and the clean address
8391 * bit is cleared and fc fabric parameters chenged, delay FC NPort
8394 spin_lock_irq(shost->host_lock);
8395 if (vport->fc_flag & FC_DISC_DELAYED) {
8396 spin_unlock_irq(shost->host_lock);
8397 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
8398 "3334 Delay fc port discovery for %d seconds\n",
8400 mod_timer(&vport->delayed_disc_tmo,
8401 jiffies + msecs_to_jiffies(1000 * phba->fc_ratov));
8404 spin_unlock_irq(shost->host_lock);
8406 ndlp = lpfc_findnode_did(vport, NameServer_DID);
8408 ndlp = lpfc_nlp_init(vport, NameServer_DID);
8410 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
8411 lpfc_disc_start(vport);
8414 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
8415 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8416 "0251 NameServer login: no memory\n");
8419 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
8420 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
8422 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
8423 lpfc_disc_start(vport);
8426 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
8427 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8428 "0348 NameServer login: node freed\n");
8432 ndlp->nlp_type |= NLP_FABRIC;
8434 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
8436 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
8437 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
8438 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8439 "0252 Cannot issue NameServer login\n");
8443 if ((phba->cfg_enable_SmartSAN ||
8444 (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) &&
8445 (vport->load_flag & FC_ALLOW_FDMI))
8446 lpfc_start_fdmi(vport);
8450 * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
8451 * @phba: pointer to lpfc hba data structure.
8452 * @pmb: pointer to the driver internal queue element for mailbox command.
8454 * This routine is the completion callback function to register new vport
8455 * mailbox command. If the new vport mailbox command completes successfully,
8456 * the fabric registration login shall be performed on physical port (the
8457 * new vport created is actually a physical port, with VPI 0) or the port
8458 * login to Name Server for State Change Request (SCR) will be performed
8459 * on virtual port (real virtual port, with VPI greater than 0).
8462 lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
8464 struct lpfc_vport *vport = pmb->vport;
8465 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8466 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
8467 MAILBOX_t *mb = &pmb->u.mb;
8470 spin_lock_irq(shost->host_lock);
8471 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
8472 spin_unlock_irq(shost->host_lock);
8474 if (mb->mbxStatus) {
8475 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
8476 "0915 Register VPI failed : Status: x%x"
8477 " upd bit: x%x \n", mb->mbxStatus,
8478 mb->un.varRegVpi.upd);
8479 if (phba->sli_rev == LPFC_SLI_REV4 &&
8480 mb->un.varRegVpi.upd)
8481 goto mbox_err_exit ;
8483 switch (mb->mbxStatus) {
8484 case 0x11: /* unsupported feature */
8485 case 0x9603: /* max_vpi exceeded */
8486 case 0x9602: /* Link event since CLEAR_LA */
8487 /* giving up on vport registration */
8488 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
8489 spin_lock_irq(shost->host_lock);
8490 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
8491 spin_unlock_irq(shost->host_lock);
8492 lpfc_can_disctmo(vport);
8494 /* If reg_vpi fail with invalid VPI status, re-init VPI */
8496 spin_lock_irq(shost->host_lock);
8497 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
8498 spin_unlock_irq(shost->host_lock);
8499 lpfc_init_vpi(phba, pmb, vport->vpi);
8501 pmb->mbox_cmpl = lpfc_init_vpi_cmpl;
8502 rc = lpfc_sli_issue_mbox(phba, pmb,
8504 if (rc == MBX_NOT_FINISHED) {
8505 lpfc_printf_vlog(vport,
8507 "2732 Failed to issue INIT_VPI"
8508 " mailbox command\n");
8515 /* Try to recover from this error */
8516 if (phba->sli_rev == LPFC_SLI_REV4)
8517 lpfc_sli4_unreg_all_rpis(vport);
8518 lpfc_mbx_unreg_vpi(vport);
8519 spin_lock_irq(shost->host_lock);
8520 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
8521 spin_unlock_irq(shost->host_lock);
8522 if (mb->mbxStatus == MBX_NOT_FINISHED)
8524 if ((vport->port_type == LPFC_PHYSICAL_PORT) &&
8525 !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG)) {
8526 if (phba->sli_rev == LPFC_SLI_REV4)
8527 lpfc_issue_init_vfi(vport);
8529 lpfc_initial_flogi(vport);
8531 lpfc_initial_fdisc(vport);
8536 spin_lock_irq(shost->host_lock);
8537 vport->vpi_state |= LPFC_VPI_REGISTERED;
8538 spin_unlock_irq(shost->host_lock);
8539 if (vport == phba->pport) {
8540 if (phba->sli_rev < LPFC_SLI_REV4)
8541 lpfc_issue_fabric_reglogin(vport);
8544 * If the physical port is instantiated using
8545 * FDISC, do not start vport discovery.
8547 if (vport->port_state != LPFC_FDISC)
8548 lpfc_start_fdiscs(phba);
8549 lpfc_do_scr_ns_plogi(phba, vport);
8552 lpfc_do_scr_ns_plogi(phba, vport);
8555 /* Now, we decrement the ndlp reference count held for this
8560 mempool_free(pmb, phba->mbox_mem_pool);
8565 * lpfc_register_new_vport - Register a new vport with a HBA
8566 * @phba: pointer to lpfc hba data structure.
8567 * @vport: pointer to a host virtual N_Port data structure.
8568 * @ndlp: pointer to a node-list data structure.
8570 * This routine registers the @vport as a new virtual port with a HBA.
8571 * It is done through a registering vpi mailbox command.
8574 lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
8575 struct lpfc_nodelist *ndlp)
8577 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8580 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
8582 lpfc_reg_vpi(vport, mbox);
8583 mbox->vport = vport;
8584 mbox->context2 = lpfc_nlp_get(ndlp);
8585 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
8586 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
8587 == MBX_NOT_FINISHED) {
8588 /* mailbox command not success, decrement ndlp
8589 * reference count for this command
8592 mempool_free(mbox, phba->mbox_mem_pool);
8594 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
8595 "0253 Register VPI: Can't send mbox\n");
8599 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
8600 "0254 Register VPI: no memory\n");
8606 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
8607 spin_lock_irq(shost->host_lock);
8608 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
8609 spin_unlock_irq(shost->host_lock);
8614 * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer
8615 * @phba: pointer to lpfc hba data structure.
8617 * This routine cancels the retry delay timers to all the vports.
8620 lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba)
8622 struct lpfc_vport **vports;
8623 struct lpfc_nodelist *ndlp;
8624 uint32_t link_state;
8627 /* Treat this failure as linkdown for all vports */
8628 link_state = phba->link_state;
8629 lpfc_linkdown(phba);
8630 phba->link_state = link_state;
8632 vports = lpfc_create_vport_work_array(phba);
8635 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
8636 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
8638 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
8639 lpfc_els_flush_cmd(vports[i]);
8641 lpfc_destroy_vport_work_array(phba, vports);
8646 * lpfc_retry_pport_discovery - Start timer to retry FLOGI.
8647 * @phba: pointer to lpfc hba data structure.
8649 * This routine abort all pending discovery commands and
8650 * start a timer to retry FLOGI for the physical port
8654 lpfc_retry_pport_discovery(struct lpfc_hba *phba)
8656 struct lpfc_nodelist *ndlp;
8657 struct Scsi_Host *shost;
8659 /* Cancel the all vports retry delay retry timers */
8660 lpfc_cancel_all_vport_retry_delay_timer(phba);
8662 /* If fabric require FLOGI, then re-instantiate physical login */
8663 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
8667 shost = lpfc_shost_from_vport(phba->pport);
8668 mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000));
8669 spin_lock_irq(shost->host_lock);
8670 ndlp->nlp_flag |= NLP_DELAY_TMO;
8671 spin_unlock_irq(shost->host_lock);
8672 ndlp->nlp_last_elscmd = ELS_CMD_FLOGI;
8673 phba->pport->port_state = LPFC_FLOGI;
8678 * lpfc_fabric_login_reqd - Check if FLOGI required.
8679 * @phba: pointer to lpfc hba data structure.
8680 * @cmdiocb: pointer to FDISC command iocb.
8681 * @rspiocb: pointer to FDISC response iocb.
8683 * This routine checks if a FLOGI is reguired for FDISC
8687 lpfc_fabric_login_reqd(struct lpfc_hba *phba,
8688 struct lpfc_iocbq *cmdiocb,
8689 struct lpfc_iocbq *rspiocb)
8692 if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) ||
8693 (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED))
8700 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
8701 * @phba: pointer to lpfc hba data structure.
8702 * @cmdiocb: pointer to lpfc command iocb data structure.
8703 * @rspiocb: pointer to lpfc response iocb data structure.
8705 * This routine is the completion callback function to a Fabric Discover
8706 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
8707 * single threaded, each FDISC completion callback function will reset
8708 * the discovery timer for all vports such that the timers will not get
8709 * unnecessary timeout. The function checks the FDISC IOCB status. If error
8710 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
8711 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
8712 * assigned to the vport has been changed with the completion of the FDISC
8713 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
8714 * are unregistered from the HBA, and then the lpfc_register_new_vport()
8715 * routine is invoked to register new vport with the HBA. Otherwise, the
8716 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
8717 * Server for State Change Request (SCR).
8720 lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
8721 struct lpfc_iocbq *rspiocb)
8723 struct lpfc_vport *vport = cmdiocb->vport;
8724 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8725 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
8726 struct lpfc_nodelist *np;
8727 struct lpfc_nodelist *next_np;
8728 IOCB_t *irsp = &rspiocb->iocb;
8729 struct lpfc_iocbq *piocb;
8730 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
8731 struct serv_parm *sp;
8732 uint8_t fabric_param_changed;
8734 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
8735 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
8736 irsp->ulpStatus, irsp->un.ulpWord[4],
8738 /* Since all FDISCs are being single threaded, we
8739 * must reset the discovery timer for ALL vports
8740 * waiting to send FDISC when one completes.
8742 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
8743 lpfc_set_disctmo(piocb->vport);
8746 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
8747 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
8748 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
8750 if (irsp->ulpStatus) {
8752 if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) {
8753 lpfc_retry_pport_discovery(phba);
8757 /* Check for retry */
8758 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
8761 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8762 "0126 FDISC failed. (x%x/x%x)\n",
8763 irsp->ulpStatus, irsp->un.ulpWord[4]);
8766 spin_lock_irq(shost->host_lock);
8767 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
8768 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
8769 vport->fc_flag |= FC_FABRIC;
8770 if (vport->phba->fc_topology == LPFC_TOPOLOGY_LOOP)
8771 vport->fc_flag |= FC_PUBLIC_LOOP;
8772 spin_unlock_irq(shost->host_lock);
8774 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
8775 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
8776 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
8779 sp = prsp->virt + sizeof(uint32_t);
8780 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
8781 memcpy(&vport->fabric_portname, &sp->portName,
8782 sizeof(struct lpfc_name));
8783 memcpy(&vport->fabric_nodename, &sp->nodeName,
8784 sizeof(struct lpfc_name));
8785 if (fabric_param_changed &&
8786 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
8787 /* If our NportID changed, we need to ensure all
8788 * remaining NPORTs get unreg_login'ed so we can
8791 list_for_each_entry_safe(np, next_np,
8792 &vport->fc_nodes, nlp_listp) {
8793 if (!NLP_CHK_NODE_ACT(ndlp) ||
8794 (np->nlp_state != NLP_STE_NPR_NODE) ||
8795 !(np->nlp_flag & NLP_NPR_ADISC))
8797 spin_lock_irq(shost->host_lock);
8798 np->nlp_flag &= ~NLP_NPR_ADISC;
8799 spin_unlock_irq(shost->host_lock);
8800 lpfc_unreg_rpi(vport, np);
8802 lpfc_cleanup_pending_mbox(vport);
8804 if (phba->sli_rev == LPFC_SLI_REV4)
8805 lpfc_sli4_unreg_all_rpis(vport);
8807 lpfc_mbx_unreg_vpi(vport);
8808 spin_lock_irq(shost->host_lock);
8809 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
8810 if (phba->sli_rev == LPFC_SLI_REV4)
8811 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
8813 vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG;
8814 spin_unlock_irq(shost->host_lock);
8815 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
8816 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
8818 * Driver needs to re-reg VPI in order for f/w
8819 * to update the MAC address.
8821 lpfc_register_new_vport(phba, vport, ndlp);
8825 if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)
8826 lpfc_issue_init_vpi(vport);
8827 else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
8828 lpfc_register_new_vport(phba, vport, ndlp);
8830 lpfc_do_scr_ns_plogi(phba, vport);
8833 if (vport->fc_vport &&
8834 (vport->fc_vport->vport_state != FC_VPORT_NO_FABRIC_RSCS))
8835 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
8836 /* Cancel discovery timer */
8837 lpfc_can_disctmo(vport);
8840 lpfc_els_free_iocb(phba, cmdiocb);
8844 * lpfc_issue_els_fdisc - Issue a fdisc iocb command
8845 * @vport: pointer to a virtual N_Port data structure.
8846 * @ndlp: pointer to a node-list data structure.
8847 * @retry: number of retries to the command IOCB.
8849 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
8850 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
8851 * routine to issue the IOCB, which makes sure only one outstanding fabric
8852 * IOCB will be sent off HBA at any given time.
8854 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
8855 * will be incremented by 1 for holding the ndlp and the reference to ndlp
8856 * will be stored into the context1 field of the IOCB for the completion
8857 * callback function to the FDISC ELS command.
8860 * 0 - Successfully issued fdisc iocb command
8861 * 1 - Failed to issue fdisc iocb command
8864 lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
8867 struct lpfc_hba *phba = vport->phba;
8869 struct lpfc_iocbq *elsiocb;
8870 struct serv_parm *sp;
8873 int did = ndlp->nlp_DID;
8876 vport->port_state = LPFC_FDISC;
8877 vport->fc_myDID = 0;
8878 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
8879 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
8882 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
8883 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8884 "0255 Issue FDISC: no IOCB\n");
8888 icmd = &elsiocb->iocb;
8889 icmd->un.elsreq64.myID = 0;
8890 icmd->un.elsreq64.fl = 1;
8893 * SLI3 ports require a different context type value than SLI4.
8894 * Catch SLI3 ports here and override the prep.
8896 if (phba->sli_rev == LPFC_SLI_REV3) {
8901 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
8902 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
8903 pcmd += sizeof(uint32_t); /* CSP Word 1 */
8904 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
8905 sp = (struct serv_parm *) pcmd;
8906 /* Setup CSPs accordingly for Fabric */
8907 sp->cmn.e_d_tov = 0;
8908 sp->cmn.w2.r_a_tov = 0;
8909 sp->cmn.virtual_fabric_support = 0;
8910 sp->cls1.classValid = 0;
8911 sp->cls2.seqDelivery = 1;
8912 sp->cls3.seqDelivery = 1;
8914 pcmd += sizeof(uint32_t); /* CSP Word 2 */
8915 pcmd += sizeof(uint32_t); /* CSP Word 3 */
8916 pcmd += sizeof(uint32_t); /* CSP Word 4 */
8917 pcmd += sizeof(uint32_t); /* Port Name */
8918 memcpy(pcmd, &vport->fc_portname, 8);
8919 pcmd += sizeof(uint32_t); /* Node Name */
8920 pcmd += sizeof(uint32_t); /* Node Name */
8921 memcpy(pcmd, &vport->fc_nodename, 8);
8922 sp->cmn.valid_vendor_ver_level = 0;
8923 memset(sp->un.vendorVersion, 0, sizeof(sp->un.vendorVersion));
8924 lpfc_set_disctmo(vport);
8926 phba->fc_stat.elsXmitFDISC++;
8927 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
8929 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
8930 "Issue FDISC: did:x%x",
8933 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
8934 if (rc == IOCB_ERROR) {
8935 lpfc_els_free_iocb(phba, elsiocb);
8936 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
8937 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8938 "0256 Issue FDISC: Cannot send IOCB\n");
8941 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
8946 * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
8947 * @phba: pointer to lpfc hba data structure.
8948 * @cmdiocb: pointer to lpfc command iocb data structure.
8949 * @rspiocb: pointer to lpfc response iocb data structure.
8951 * This routine is the completion callback function to the issuing of a LOGO
8952 * ELS command off a vport. It frees the command IOCB and then decrement the
8953 * reference count held on ndlp for this completion function, indicating that
8954 * the reference to the ndlp is no long needed. Note that the
8955 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
8956 * callback function and an additional explicit ndlp reference decrementation
8957 * will trigger the actual release of the ndlp.
8960 lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
8961 struct lpfc_iocbq *rspiocb)
8963 struct lpfc_vport *vport = cmdiocb->vport;
8965 struct lpfc_nodelist *ndlp;
8966 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8968 ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
8969 irsp = &rspiocb->iocb;
8970 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
8971 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
8972 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
8974 lpfc_els_free_iocb(phba, cmdiocb);
8975 vport->unreg_vpi_cmpl = VPORT_ERROR;
8977 /* Trigger the release of the ndlp after logo */
8980 /* NPIV LOGO completes to NPort <nlp_DID> */
8981 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
8982 "2928 NPIV LOGO completes to NPort x%x "
8983 "Data: x%x x%x x%x x%x\n",
8984 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
8985 irsp->ulpTimeout, vport->num_disc_nodes);
8987 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
8988 spin_lock_irq(shost->host_lock);
8989 vport->fc_flag &= ~FC_NDISC_ACTIVE;
8990 vport->fc_flag &= ~FC_FABRIC;
8991 spin_unlock_irq(shost->host_lock);
8992 lpfc_can_disctmo(vport);
8997 * lpfc_issue_els_npiv_logo - Issue a logo off a vport
8998 * @vport: pointer to a virtual N_Port data structure.
8999 * @ndlp: pointer to a node-list data structure.
9001 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
9003 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
9004 * will be incremented by 1 for holding the ndlp and the reference to ndlp
9005 * will be stored into the context1 field of the IOCB for the completion
9006 * callback function to the LOGO ELS command.
9009 * 0 - Successfully issued logo off the @vport
9010 * 1 - Failed to issue logo off the @vport
9013 lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
9015 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
9016 struct lpfc_hba *phba = vport->phba;
9017 struct lpfc_iocbq *elsiocb;
9021 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
9022 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
9027 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
9028 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
9029 pcmd += sizeof(uint32_t);
9031 /* Fill in LOGO payload */
9032 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
9033 pcmd += sizeof(uint32_t);
9034 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
9036 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
9037 "Issue LOGO npiv did:x%x flg:x%x",
9038 ndlp->nlp_DID, ndlp->nlp_flag, 0);
9040 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
9041 spin_lock_irq(shost->host_lock);
9042 ndlp->nlp_flag |= NLP_LOGO_SND;
9043 spin_unlock_irq(shost->host_lock);
9044 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
9046 spin_lock_irq(shost->host_lock);
9047 ndlp->nlp_flag &= ~NLP_LOGO_SND;
9048 spin_unlock_irq(shost->host_lock);
9049 lpfc_els_free_iocb(phba, elsiocb);
9056 * lpfc_fabric_block_timeout - Handler function to the fabric block timer
9057 * @ptr: holder for the timer function associated data.
9059 * This routine is invoked by the fabric iocb block timer after
9060 * timeout. It posts the fabric iocb block timeout event by setting the
9061 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
9062 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
9063 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
9064 * posted event WORKER_FABRIC_BLOCK_TMO.
9067 lpfc_fabric_block_timeout(unsigned long ptr)
9069 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
9070 unsigned long iflags;
9071 uint32_t tmo_posted;
9073 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
9074 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
9076 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
9077 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
9080 lpfc_worker_wake_up(phba);
9085 * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
9086 * @phba: pointer to lpfc hba data structure.
9088 * This routine issues one fabric iocb from the driver internal list to
9089 * the HBA. It first checks whether it's ready to issue one fabric iocb to
9090 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
9091 * remove one pending fabric iocb from the driver internal list and invokes
9092 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
9095 lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
9097 struct lpfc_iocbq *iocb;
9098 unsigned long iflags;
9104 spin_lock_irqsave(&phba->hbalock, iflags);
9105 /* Post any pending iocb to the SLI layer */
9106 if (atomic_read(&phba->fabric_iocb_count) == 0) {
9107 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
9110 /* Increment fabric iocb count to hold the position */
9111 atomic_inc(&phba->fabric_iocb_count);
9113 spin_unlock_irqrestore(&phba->hbalock, iflags);
9115 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
9116 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
9117 iocb->iocb_flag |= LPFC_IO_FABRIC;
9119 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
9120 "Fabric sched1: ste:x%x",
9121 iocb->vport->port_state, 0, 0);
9123 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
9125 if (ret == IOCB_ERROR) {
9126 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
9127 iocb->fabric_iocb_cmpl = NULL;
9128 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
9130 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
9131 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
9132 iocb->iocb_cmpl(phba, iocb, iocb);
9134 atomic_dec(&phba->fabric_iocb_count);
9143 * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
9144 * @phba: pointer to lpfc hba data structure.
9146 * This routine unblocks the issuing fabric iocb command. The function
9147 * will clear the fabric iocb block bit and then invoke the routine
9148 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
9149 * from the driver internal fabric iocb list.
9152 lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
9154 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
9156 lpfc_resume_fabric_iocbs(phba);
9161 * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
9162 * @phba: pointer to lpfc hba data structure.
9164 * This routine blocks the issuing fabric iocb for a specified amount of
9165 * time (currently 100 ms). This is done by set the fabric iocb block bit
9166 * and set up a timeout timer for 100ms. When the block bit is set, no more
9167 * fabric iocb will be issued out of the HBA.
9170 lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
9174 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
9175 /* Start a timer to unblock fabric iocbs after 100ms */
9177 mod_timer(&phba->fabric_block_timer,
9178 jiffies + msecs_to_jiffies(100));
9184 * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
9185 * @phba: pointer to lpfc hba data structure.
9186 * @cmdiocb: pointer to lpfc command iocb data structure.
9187 * @rspiocb: pointer to lpfc response iocb data structure.
9189 * This routine is the callback function that is put to the fabric iocb's
9190 * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
9191 * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
9192 * function first restores and invokes the original iocb's callback function
9193 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
9194 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
9197 lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
9198 struct lpfc_iocbq *rspiocb)
9202 BUG_ON((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC);
9204 switch (rspiocb->iocb.ulpStatus) {
9205 case IOSTAT_NPORT_RJT:
9206 case IOSTAT_FABRIC_RJT:
9207 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
9208 lpfc_block_fabric_iocbs(phba);
9212 case IOSTAT_NPORT_BSY:
9213 case IOSTAT_FABRIC_BSY:
9214 lpfc_block_fabric_iocbs(phba);
9218 stat.un.lsRjtError =
9219 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
9220 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
9221 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
9222 lpfc_block_fabric_iocbs(phba);
9226 BUG_ON(atomic_read(&phba->fabric_iocb_count) == 0);
9228 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
9229 cmdiocb->fabric_iocb_cmpl = NULL;
9230 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
9231 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
9233 atomic_dec(&phba->fabric_iocb_count);
9234 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
9235 /* Post any pending iocbs to HBA */
9236 lpfc_resume_fabric_iocbs(phba);
9241 * lpfc_issue_fabric_iocb - Issue a fabric iocb command
9242 * @phba: pointer to lpfc hba data structure.
9243 * @iocb: pointer to lpfc command iocb data structure.
9245 * This routine is used as the top-level API for issuing a fabric iocb command
9246 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
9247 * function makes sure that only one fabric bound iocb will be outstanding at
9248 * any given time. As such, this function will first check to see whether there
9249 * is already an outstanding fabric iocb on the wire. If so, it will put the
9250 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
9251 * issued later. Otherwise, it will issue the iocb on the wire and update the
9252 * fabric iocb count it indicate that there is one fabric iocb on the wire.
9254 * Note, this implementation has a potential sending out fabric IOCBs out of
9255 * order. The problem is caused by the construction of the "ready" boolen does
9256 * not include the condition that the internal fabric IOCB list is empty. As
9257 * such, it is possible a fabric IOCB issued by this routine might be "jump"
9258 * ahead of the fabric IOCBs in the internal list.
9261 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
9262 * IOCB_ERROR - failed to issue fabric iocb
9265 lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
9267 unsigned long iflags;
9271 BUG_ON(atomic_read(&phba->fabric_iocb_count) > 1);
9273 spin_lock_irqsave(&phba->hbalock, iflags);
9274 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
9275 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
9278 /* Increment fabric iocb count to hold the position */
9279 atomic_inc(&phba->fabric_iocb_count);
9280 spin_unlock_irqrestore(&phba->hbalock, iflags);
9282 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
9283 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
9284 iocb->iocb_flag |= LPFC_IO_FABRIC;
9286 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
9287 "Fabric sched2: ste:x%x",
9288 iocb->vport->port_state, 0, 0);
9290 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
9292 if (ret == IOCB_ERROR) {
9293 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
9294 iocb->fabric_iocb_cmpl = NULL;
9295 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
9296 atomic_dec(&phba->fabric_iocb_count);
9299 spin_lock_irqsave(&phba->hbalock, iflags);
9300 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
9301 spin_unlock_irqrestore(&phba->hbalock, iflags);
9308 * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
9309 * @vport: pointer to a virtual N_Port data structure.
9311 * This routine aborts all the IOCBs associated with a @vport from the
9312 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
9313 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
9314 * list, removes each IOCB associated with the @vport off the list, set the
9315 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
9316 * associated with the IOCB.
9318 static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
9320 LIST_HEAD(completions);
9321 struct lpfc_hba *phba = vport->phba;
9322 struct lpfc_iocbq *tmp_iocb, *piocb;
9324 spin_lock_irq(&phba->hbalock);
9325 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
9328 if (piocb->vport != vport)
9331 list_move_tail(&piocb->list, &completions);
9333 spin_unlock_irq(&phba->hbalock);
9335 /* Cancel all the IOCBs from the completions list */
9336 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
9341 * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
9342 * @ndlp: pointer to a node-list data structure.
9344 * This routine aborts all the IOCBs associated with an @ndlp from the
9345 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
9346 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
9347 * list, removes each IOCB associated with the @ndlp off the list, set the
9348 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
9349 * associated with the IOCB.
9351 void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
9353 LIST_HEAD(completions);
9354 struct lpfc_hba *phba = ndlp->phba;
9355 struct lpfc_iocbq *tmp_iocb, *piocb;
9356 struct lpfc_sli_ring *pring;
9358 pring = lpfc_phba_elsring(phba);
9360 if (unlikely(!pring))
9363 spin_lock_irq(&phba->hbalock);
9364 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
9366 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
9368 list_move_tail(&piocb->list, &completions);
9371 spin_unlock_irq(&phba->hbalock);
9373 /* Cancel all the IOCBs from the completions list */
9374 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
9379 * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
9380 * @phba: pointer to lpfc hba data structure.
9382 * This routine aborts all the IOCBs currently on the driver internal
9383 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
9384 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
9385 * list, removes IOCBs off the list, set the status feild to
9386 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
9389 void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
9391 LIST_HEAD(completions);
9393 spin_lock_irq(&phba->hbalock);
9394 list_splice_init(&phba->fabric_iocb_list, &completions);
9395 spin_unlock_irq(&phba->hbalock);
9397 /* Cancel all the IOCBs from the completions list */
9398 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
9403 * lpfc_sli4_vport_delete_els_xri_aborted -Remove all ndlp references for vport
9404 * @vport: pointer to lpfc vport data structure.
9406 * This routine is invoked by the vport cleanup for deletions and the cleanup
9407 * for an ndlp on removal.
9410 lpfc_sli4_vport_delete_els_xri_aborted(struct lpfc_vport *vport)
9412 struct lpfc_hba *phba = vport->phba;
9413 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
9414 unsigned long iflag = 0;
9416 spin_lock_irqsave(&phba->hbalock, iflag);
9417 spin_lock(&phba->sli4_hba.sgl_list_lock);
9418 list_for_each_entry_safe(sglq_entry, sglq_next,
9419 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
9420 if (sglq_entry->ndlp && sglq_entry->ndlp->vport == vport)
9421 sglq_entry->ndlp = NULL;
9423 spin_unlock(&phba->sli4_hba.sgl_list_lock);
9424 spin_unlock_irqrestore(&phba->hbalock, iflag);
9429 * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
9430 * @phba: pointer to lpfc hba data structure.
9431 * @axri: pointer to the els xri abort wcqe structure.
9433 * This routine is invoked by the worker thread to process a SLI4 slow-path
9437 lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba,
9438 struct sli4_wcqe_xri_aborted *axri)
9440 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
9441 uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri);
9444 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
9445 unsigned long iflag = 0;
9446 struct lpfc_nodelist *ndlp;
9447 struct lpfc_sli_ring *pring;
9449 pring = lpfc_phba_elsring(phba);
9451 spin_lock_irqsave(&phba->hbalock, iflag);
9452 spin_lock(&phba->sli4_hba.sgl_list_lock);
9453 list_for_each_entry_safe(sglq_entry, sglq_next,
9454 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
9455 if (sglq_entry->sli4_xritag == xri) {
9456 list_del(&sglq_entry->list);
9457 ndlp = sglq_entry->ndlp;
9458 sglq_entry->ndlp = NULL;
9459 list_add_tail(&sglq_entry->list,
9460 &phba->sli4_hba.lpfc_els_sgl_list);
9461 sglq_entry->state = SGL_FREED;
9462 spin_unlock(&phba->sli4_hba.sgl_list_lock);
9463 spin_unlock_irqrestore(&phba->hbalock, iflag);
9464 lpfc_set_rrq_active(phba, ndlp,
9465 sglq_entry->sli4_lxritag,
9468 /* Check if TXQ queue needs to be serviced */
9469 if (pring && !list_empty(&pring->txq))
9470 lpfc_worker_wake_up(phba);
9474 spin_unlock(&phba->sli4_hba.sgl_list_lock);
9475 lxri = lpfc_sli4_xri_inrange(phba, xri);
9476 if (lxri == NO_XRI) {
9477 spin_unlock_irqrestore(&phba->hbalock, iflag);
9480 spin_lock(&phba->sli4_hba.sgl_list_lock);
9481 sglq_entry = __lpfc_get_active_sglq(phba, lxri);
9482 if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) {
9483 spin_unlock(&phba->sli4_hba.sgl_list_lock);
9484 spin_unlock_irqrestore(&phba->hbalock, iflag);
9487 sglq_entry->state = SGL_XRI_ABORTED;
9488 spin_unlock(&phba->sli4_hba.sgl_list_lock);
9489 spin_unlock_irqrestore(&phba->hbalock, iflag);
9493 /* lpfc_sli_abts_recover_port - Recover a port that failed a BLS_ABORT req.
9494 * @vport: pointer to virtual port object.
9495 * @ndlp: nodelist pointer for the impacted node.
9497 * The driver calls this routine in response to an SLI4 XRI ABORT CQE
9498 * or an SLI3 ASYNC_STATUS_CN event from the port. For either event,
9499 * the driver is required to send a LOGO to the remote node before it
9500 * attempts to recover its login to the remote node.
9503 lpfc_sli_abts_recover_port(struct lpfc_vport *vport,
9504 struct lpfc_nodelist *ndlp)
9506 struct Scsi_Host *shost;
9507 struct lpfc_hba *phba;
9508 unsigned long flags = 0;
9510 shost = lpfc_shost_from_vport(vport);
9512 if (ndlp->nlp_state != NLP_STE_MAPPED_NODE) {
9513 lpfc_printf_log(phba, KERN_INFO,
9514 LOG_SLI, "3093 No rport recovery needed. "
9515 "rport in state 0x%x\n", ndlp->nlp_state);
9518 lpfc_printf_log(phba, KERN_ERR,
9519 LOG_ELS | LOG_FCP_ERROR | LOG_NVME_IOERR,
9520 "3094 Start rport recovery on shost id 0x%x "
9521 "fc_id 0x%06x vpi 0x%x rpi 0x%x state 0x%x "
9523 shost->host_no, ndlp->nlp_DID,
9524 vport->vpi, ndlp->nlp_rpi, ndlp->nlp_state,
9527 * The rport is not responding. Remove the FCP-2 flag to prevent
9528 * an ADISC in the follow-up recovery code.
9530 spin_lock_irqsave(shost->host_lock, flags);
9531 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
9532 ndlp->nlp_flag |= NLP_ISSUE_LOGO;
9533 spin_unlock_irqrestore(shost->host_lock, flags);
9534 lpfc_unreg_rpi(vport, ndlp);