1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2017-2018 Broadcom. All Rights Reserved. The term *
5 * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. *
6 * Copyright (C) 2004-2016 Emulex. All rights reserved. *
7 * EMULEX and SLI are trademarks of Emulex. *
9 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
11 * This program is free software; you can redistribute it and/or *
12 * modify it under the terms of version 2 of the GNU General *
13 * Public License as published by the Free Software Foundation. *
14 * This program is distributed in the hope that it will be useful. *
15 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
16 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
17 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
18 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
19 * TO BE LEGALLY INVALID. See the GNU General Public License for *
20 * more details, a copy of which can be found in the file COPYING *
21 * included with this package. *
22 *******************************************************************/
23 /* See Fibre Channel protocol T11 FC-LS for details */
24 #include <linux/blkdev.h>
25 #include <linux/pci.h>
26 #include <linux/slab.h>
27 #include <linux/interrupt.h>
29 #include <scsi/scsi.h>
30 #include <scsi/scsi_device.h>
31 #include <scsi/scsi_host.h>
32 #include <scsi/scsi_transport_fc.h>
37 #include "lpfc_sli4.h"
39 #include "lpfc_disc.h"
40 #include "lpfc_scsi.h"
42 #include "lpfc_logmsg.h"
43 #include "lpfc_crtn.h"
44 #include "lpfc_vport.h"
45 #include "lpfc_debugfs.h"
47 static int lpfc_els_retry(struct lpfc_hba *, struct lpfc_iocbq *,
49 static void lpfc_cmpl_fabric_iocb(struct lpfc_hba *, struct lpfc_iocbq *,
51 static void lpfc_fabric_abort_vport(struct lpfc_vport *vport);
52 static int lpfc_issue_els_fdisc(struct lpfc_vport *vport,
53 struct lpfc_nodelist *ndlp, uint8_t retry);
54 static int lpfc_issue_fabric_iocb(struct lpfc_hba *phba,
55 struct lpfc_iocbq *iocb);
57 static int lpfc_max_els_tries = 3;
60 * lpfc_els_chk_latt - Check host link attention event for a vport
61 * @vport: pointer to a host virtual N_Port data structure.
63 * This routine checks whether there is an outstanding host link
64 * attention event during the discovery process with the @vport. It is done
65 * by reading the HBA's Host Attention (HA) register. If there is any host
66 * link attention events during this @vport's discovery process, the @vport
67 * shall be marked as FC_ABORT_DISCOVERY, a host link attention clear shall
68 * be issued if the link state is not already in host link cleared state,
69 * and a return code shall indicate whether the host link attention event
72 * Note that, if either the host link is in state LPFC_LINK_DOWN or @vport
73 * state in LPFC_VPORT_READY, the request for checking host link attention
74 * event will be ignored and a return code shall indicate no host link
75 * attention event had happened.
78 * 0 - no host link attention event happened
79 * 1 - host link attention event happened
82 lpfc_els_chk_latt(struct lpfc_vport *vport)
84 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
85 struct lpfc_hba *phba = vport->phba;
88 if (vport->port_state >= LPFC_VPORT_READY ||
89 phba->link_state == LPFC_LINK_DOWN ||
90 phba->sli_rev > LPFC_SLI_REV3)
93 /* Read the HBA Host Attention Register */
94 if (lpfc_readl(phba->HAregaddr, &ha_copy))
97 if (!(ha_copy & HA_LATT))
100 /* Pending Link Event during Discovery */
101 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
102 "0237 Pending Link Event during "
103 "Discovery: State x%x\n",
104 phba->pport->port_state);
106 /* CLEAR_LA should re-enable link attention events and
107 * we should then immediately take a LATT event. The
108 * LATT processing should call lpfc_linkdown() which
109 * will cleanup any left over in-progress discovery
112 spin_lock_irq(shost->host_lock);
113 vport->fc_flag |= FC_ABORT_DISCOVERY;
114 spin_unlock_irq(shost->host_lock);
116 if (phba->link_state != LPFC_CLEAR_LA)
117 lpfc_issue_clear_la(phba, vport);
123 * lpfc_prep_els_iocb - Allocate and prepare a lpfc iocb data structure
124 * @vport: pointer to a host virtual N_Port data structure.
125 * @expectRsp: flag indicating whether response is expected.
126 * @cmdSize: size of the ELS command.
127 * @retry: number of retries to the command IOCB when it fails.
128 * @ndlp: pointer to a node-list data structure.
129 * @did: destination identifier.
130 * @elscmd: the ELS command code.
132 * This routine is used for allocating a lpfc-IOCB data structure from
133 * the driver lpfc-IOCB free-list and prepare the IOCB with the parameters
134 * passed into the routine for discovery state machine to issue an Extended
135 * Link Service (ELS) commands. It is a generic lpfc-IOCB allocation
136 * and preparation routine that is used by all the discovery state machine
137 * routines and the ELS command-specific fields will be later set up by
138 * the individual discovery machine routines after calling this routine
139 * allocating and preparing a generic IOCB data structure. It fills in the
140 * Buffer Descriptor Entries (BDEs), allocates buffers for both command
141 * payload and response payload (if expected). The reference count on the
142 * ndlp is incremented by 1 and the reference to the ndlp is put into
143 * context1 of the IOCB data structure for this IOCB to hold the ndlp
144 * reference for the command's callback function to access later.
147 * Pointer to the newly allocated/prepared els iocb data structure
148 * NULL - when els iocb data structure allocation/preparation failed
151 lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp,
152 uint16_t cmdSize, uint8_t retry,
153 struct lpfc_nodelist *ndlp, uint32_t did,
156 struct lpfc_hba *phba = vport->phba;
157 struct lpfc_iocbq *elsiocb;
158 struct lpfc_dmabuf *pcmd, *prsp, *pbuflist;
159 struct ulp_bde64 *bpl;
163 if (!lpfc_is_link_up(phba))
166 /* Allocate buffer for command iocb */
167 elsiocb = lpfc_sli_get_iocbq(phba);
173 * If this command is for fabric controller and HBA running
174 * in FIP mode send FLOGI, FDISC and LOGO as FIP frames.
176 if ((did == Fabric_DID) &&
177 (phba->hba_flag & HBA_FIP_SUPPORT) &&
178 ((elscmd == ELS_CMD_FLOGI) ||
179 (elscmd == ELS_CMD_FDISC) ||
180 (elscmd == ELS_CMD_LOGO)))
183 elsiocb->iocb_flag |=
184 ((LPFC_ELS_ID_FLOGI << LPFC_FIP_ELS_ID_SHIFT)
185 & LPFC_FIP_ELS_ID_MASK);
188 elsiocb->iocb_flag |=
189 ((LPFC_ELS_ID_FDISC << LPFC_FIP_ELS_ID_SHIFT)
190 & LPFC_FIP_ELS_ID_MASK);
193 elsiocb->iocb_flag |=
194 ((LPFC_ELS_ID_LOGO << LPFC_FIP_ELS_ID_SHIFT)
195 & LPFC_FIP_ELS_ID_MASK);
199 elsiocb->iocb_flag &= ~LPFC_FIP_ELS_ID_MASK;
201 icmd = &elsiocb->iocb;
203 /* fill in BDEs for command */
204 /* Allocate buffer for command payload */
205 pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
207 pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys);
208 if (!pcmd || !pcmd->virt)
209 goto els_iocb_free_pcmb_exit;
211 INIT_LIST_HEAD(&pcmd->list);
213 /* Allocate buffer for response payload */
215 prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
217 prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
219 if (!prsp || !prsp->virt)
220 goto els_iocb_free_prsp_exit;
221 INIT_LIST_HEAD(&prsp->list);
225 /* Allocate buffer for Buffer ptr list */
226 pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
228 pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
230 if (!pbuflist || !pbuflist->virt)
231 goto els_iocb_free_pbuf_exit;
233 INIT_LIST_HEAD(&pbuflist->list);
236 icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
237 icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
238 icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
239 icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64));
241 icmd->un.elsreq64.remoteID = did; /* DID */
242 icmd->ulpCommand = CMD_ELS_REQUEST64_CR;
243 if (elscmd == ELS_CMD_FLOGI)
244 icmd->ulpTimeout = FF_DEF_RATOV * 2;
245 else if (elscmd == ELS_CMD_LOGO)
246 icmd->ulpTimeout = phba->fc_ratov;
248 icmd->ulpTimeout = phba->fc_ratov * 2;
250 icmd->un.xseq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
251 icmd->un.xseq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
252 icmd->un.xseq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
253 icmd->un.xseq64.bdl.bdeSize = sizeof(struct ulp_bde64);
254 icmd->un.xseq64.xmit_els_remoteID = did; /* DID */
255 icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX;
257 icmd->ulpBdeCount = 1;
259 icmd->ulpClass = CLASS3;
262 * If we have NPIV enabled, we want to send ELS traffic by VPI.
263 * For SLI4, since the driver controls VPIs we also want to include
264 * all ELS pt2pt protocol traffic as well.
266 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) ||
267 ((phba->sli_rev == LPFC_SLI_REV4) &&
268 (vport->fc_flag & FC_PT2PT))) {
271 icmd->un.elsreq64.myID = vport->fc_myDID;
273 /* For ELS_REQUEST64_CR, use the VPI by default */
274 icmd->ulpContext = phba->vpi_ids[vport->vpi];
278 /* The CT field must be 0=INVALID_RPI for the ECHO cmd */
279 if (elscmd == ELS_CMD_ECHO)
280 icmd->ulpCt_l = 0; /* context = invalid RPI */
282 icmd->ulpCt_l = 1; /* context = VPI */
285 bpl = (struct ulp_bde64 *) pbuflist->virt;
286 bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys));
287 bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys));
288 bpl->tus.f.bdeSize = cmdSize;
289 bpl->tus.f.bdeFlags = 0;
290 bpl->tus.w = le32_to_cpu(bpl->tus.w);
294 bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys));
295 bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys));
296 bpl->tus.f.bdeSize = FCELSSIZE;
297 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
298 bpl->tus.w = le32_to_cpu(bpl->tus.w);
301 /* prevent preparing iocb with NULL ndlp reference */
302 elsiocb->context1 = lpfc_nlp_get(ndlp);
303 if (!elsiocb->context1)
304 goto els_iocb_free_pbuf_exit;
305 elsiocb->context2 = pcmd;
306 elsiocb->context3 = pbuflist;
307 elsiocb->retry = retry;
308 elsiocb->vport = vport;
309 elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT;
312 list_add(&prsp->list, &pcmd->list);
315 /* Xmit ELS command <elsCmd> to remote NPORT <did> */
316 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
317 "0116 Xmit ELS command x%x to remote "
318 "NPORT x%x I/O tag: x%x, port state:x%x"
320 elscmd, did, elsiocb->iotag,
324 /* Xmit ELS response <elsCmd> to remote NPORT <did> */
325 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
326 "0117 Xmit ELS response x%x to remote "
327 "NPORT x%x I/O tag: x%x, size: x%x "
328 "port_state x%x fc_flag x%x\n",
329 elscmd, ndlp->nlp_DID, elsiocb->iotag,
330 cmdSize, vport->port_state,
335 els_iocb_free_pbuf_exit:
337 lpfc_mbuf_free(phba, prsp->virt, prsp->phys);
340 els_iocb_free_prsp_exit:
341 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
344 els_iocb_free_pcmb_exit:
346 lpfc_sli_release_iocbq(phba, elsiocb);
351 * lpfc_issue_fabric_reglogin - Issue fabric registration login for a vport
352 * @vport: pointer to a host virtual N_Port data structure.
354 * This routine issues a fabric registration login for a @vport. An
355 * active ndlp node with Fabric_DID must already exist for this @vport.
356 * The routine invokes two mailbox commands to carry out fabric registration
357 * login through the HBA firmware: the first mailbox command requests the
358 * HBA to perform link configuration for the @vport; and the second mailbox
359 * command requests the HBA to perform the actual fabric registration login
363 * 0 - successfully issued fabric registration login for @vport
364 * -ENXIO -- failed to issue fabric registration login for @vport
367 lpfc_issue_fabric_reglogin(struct lpfc_vport *vport)
369 struct lpfc_hba *phba = vport->phba;
371 struct lpfc_dmabuf *mp;
372 struct lpfc_nodelist *ndlp;
373 struct serv_parm *sp;
377 sp = &phba->fc_fabparam;
378 ndlp = lpfc_findnode_did(vport, Fabric_DID);
379 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
384 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
390 vport->port_state = LPFC_FABRIC_CFG_LINK;
391 lpfc_config_link(phba, mbox);
392 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
395 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
396 if (rc == MBX_NOT_FINISHED) {
401 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
406 rc = lpfc_reg_rpi(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox,
413 mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login;
415 /* increment the reference count on ndlp to hold reference
416 * for the callback routine.
418 mbox->context2 = lpfc_nlp_get(ndlp);
420 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
421 if (rc == MBX_NOT_FINISHED) {
423 goto fail_issue_reg_login;
428 fail_issue_reg_login:
429 /* decrement the reference count on ndlp just incremented
430 * for the failed mbox command.
433 mp = (struct lpfc_dmabuf *) mbox->context1;
434 lpfc_mbuf_free(phba, mp->virt, mp->phys);
437 mempool_free(mbox, phba->mbox_mem_pool);
440 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
441 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
442 "0249 Cannot issue Register Fabric login: Err %d\n", err);
447 * lpfc_issue_reg_vfi - Register VFI for this vport's fabric login
448 * @vport: pointer to a host virtual N_Port data structure.
450 * This routine issues a REG_VFI mailbox for the vfi, vpi, fcfi triplet for
451 * the @vport. This mailbox command is necessary for SLI4 port only.
454 * 0 - successfully issued REG_VFI for @vport
455 * A failure code otherwise.
458 lpfc_issue_reg_vfi(struct lpfc_vport *vport)
460 struct lpfc_hba *phba = vport->phba;
461 LPFC_MBOXQ_t *mboxq = NULL;
462 struct lpfc_nodelist *ndlp;
463 struct lpfc_dmabuf *dmabuf = NULL;
466 /* move forward in case of SLI4 FC port loopback test and pt2pt mode */
467 if ((phba->sli_rev == LPFC_SLI_REV4) &&
468 !(phba->link_flag & LS_LOOPBACK_MODE) &&
469 !(vport->fc_flag & FC_PT2PT)) {
470 ndlp = lpfc_findnode_did(vport, Fabric_DID);
471 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
477 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
483 /* Supply CSP's only if we are fabric connect or pt-to-pt connect */
484 if ((vport->fc_flag & FC_FABRIC) || (vport->fc_flag & FC_PT2PT)) {
485 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
490 dmabuf->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &dmabuf->phys);
495 memcpy(dmabuf->virt, &phba->fc_fabparam,
496 sizeof(struct serv_parm));
499 vport->port_state = LPFC_FABRIC_CFG_LINK;
501 lpfc_reg_vfi(mboxq, vport, dmabuf->phys);
503 lpfc_reg_vfi(mboxq, vport, 0);
505 mboxq->mbox_cmpl = lpfc_mbx_cmpl_reg_vfi;
506 mboxq->vport = vport;
507 mboxq->context1 = dmabuf;
508 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
509 if (rc == MBX_NOT_FINISHED) {
517 mempool_free(mboxq, phba->mbox_mem_pool);
520 lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys);
524 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
525 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
526 "0289 Issue Register VFI failed: Err %d\n", rc);
531 * lpfc_issue_unreg_vfi - Unregister VFI for this vport's fabric login
532 * @vport: pointer to a host virtual N_Port data structure.
534 * This routine issues a UNREG_VFI mailbox with the vfi, vpi, fcfi triplet for
535 * the @vport. This mailbox command is necessary for SLI4 port only.
538 * 0 - successfully issued REG_VFI for @vport
539 * A failure code otherwise.
542 lpfc_issue_unreg_vfi(struct lpfc_vport *vport)
544 struct lpfc_hba *phba = vport->phba;
545 struct Scsi_Host *shost;
549 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
551 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
552 "2556 UNREG_VFI mbox allocation failed"
553 "HBA state x%x\n", phba->pport->port_state);
557 lpfc_unreg_vfi(mboxq, vport);
558 mboxq->vport = vport;
559 mboxq->mbox_cmpl = lpfc_unregister_vfi_cmpl;
561 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
562 if (rc == MBX_NOT_FINISHED) {
563 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
564 "2557 UNREG_VFI issue mbox failed rc x%x "
566 rc, phba->pport->port_state);
567 mempool_free(mboxq, phba->mbox_mem_pool);
571 shost = lpfc_shost_from_vport(vport);
572 spin_lock_irq(shost->host_lock);
573 vport->fc_flag &= ~FC_VFI_REGISTERED;
574 spin_unlock_irq(shost->host_lock);
579 * lpfc_check_clean_addr_bit - Check whether assigned FCID is clean.
580 * @vport: pointer to a host virtual N_Port data structure.
581 * @sp: pointer to service parameter data structure.
583 * This routine is called from FLOGI/FDISC completion handler functions.
584 * lpfc_check_clean_addr_bit return 1 when FCID/Fabric portname/ Fabric
585 * node nodename is changed in the completion service parameter else return
586 * 0. This function also set flag in the vport data structure to delay
587 * NP_Port discovery after the FLOGI/FDISC completion if Clean address bit
588 * in FLOGI/FDISC response is cleared and FCID/Fabric portname/ Fabric
589 * node nodename is changed in the completion service parameter.
592 * 0 - FCID and Fabric Nodename and Fabric portname is not changed.
593 * 1 - FCID or Fabric Nodename or Fabric portname is changed.
597 lpfc_check_clean_addr_bit(struct lpfc_vport *vport,
598 struct serv_parm *sp)
600 struct lpfc_hba *phba = vport->phba;
601 uint8_t fabric_param_changed = 0;
602 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
604 if ((vport->fc_prevDID != vport->fc_myDID) ||
605 memcmp(&vport->fabric_portname, &sp->portName,
606 sizeof(struct lpfc_name)) ||
607 memcmp(&vport->fabric_nodename, &sp->nodeName,
608 sizeof(struct lpfc_name)) ||
609 (vport->vport_flag & FAWWPN_PARAM_CHG)) {
610 fabric_param_changed = 1;
611 vport->vport_flag &= ~FAWWPN_PARAM_CHG;
614 * Word 1 Bit 31 in common service parameter is overloaded.
615 * Word 1 Bit 31 in FLOGI request is multiple NPort request
616 * Word 1 Bit 31 in FLOGI response is clean address bit
618 * If fabric parameter is changed and clean address bit is
619 * cleared delay nport discovery if
620 * - vport->fc_prevDID != 0 (not initial discovery) OR
621 * - lpfc_delay_discovery module parameter is set.
623 if (fabric_param_changed && !sp->cmn.clean_address_bit &&
624 (vport->fc_prevDID || phba->cfg_delay_discovery)) {
625 spin_lock_irq(shost->host_lock);
626 vport->fc_flag |= FC_DISC_DELAYED;
627 spin_unlock_irq(shost->host_lock);
630 return fabric_param_changed;
635 * lpfc_cmpl_els_flogi_fabric - Completion function for flogi to a fabric port
636 * @vport: pointer to a host virtual N_Port data structure.
637 * @ndlp: pointer to a node-list data structure.
638 * @sp: pointer to service parameter data structure.
639 * @irsp: pointer to the IOCB within the lpfc response IOCB.
641 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
642 * function to handle the completion of a Fabric Login (FLOGI) into a fabric
643 * port in a fabric topology. It properly sets up the parameters to the @ndlp
644 * from the IOCB response. It also check the newly assigned N_Port ID to the
645 * @vport against the previously assigned N_Port ID. If it is different from
646 * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine
647 * is invoked on all the remaining nodes with the @vport to unregister the
648 * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin()
649 * is invoked to register login to the fabric.
652 * 0 - Success (currently, always return 0)
655 lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
656 struct serv_parm *sp, IOCB_t *irsp)
658 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
659 struct lpfc_hba *phba = vport->phba;
660 struct lpfc_nodelist *np;
661 struct lpfc_nodelist *next_np;
662 uint8_t fabric_param_changed;
664 spin_lock_irq(shost->host_lock);
665 vport->fc_flag |= FC_FABRIC;
666 spin_unlock_irq(shost->host_lock);
668 phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
669 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
670 phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
672 phba->fc_edtovResol = sp->cmn.edtovResolution;
673 phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
675 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
676 spin_lock_irq(shost->host_lock);
677 vport->fc_flag |= FC_PUBLIC_LOOP;
678 spin_unlock_irq(shost->host_lock);
681 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
682 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
683 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name));
684 ndlp->nlp_class_sup = 0;
685 if (sp->cls1.classValid)
686 ndlp->nlp_class_sup |= FC_COS_CLASS1;
687 if (sp->cls2.classValid)
688 ndlp->nlp_class_sup |= FC_COS_CLASS2;
689 if (sp->cls3.classValid)
690 ndlp->nlp_class_sup |= FC_COS_CLASS3;
691 if (sp->cls4.classValid)
692 ndlp->nlp_class_sup |= FC_COS_CLASS4;
693 ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
694 sp->cmn.bbRcvSizeLsb;
696 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
697 if (fabric_param_changed) {
698 /* Reset FDMI attribute masks based on config parameter */
699 if (phba->cfg_enable_SmartSAN ||
700 (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) {
701 /* Setup appropriate attribute masks */
702 vport->fdmi_hba_mask = LPFC_FDMI2_HBA_ATTR;
703 if (phba->cfg_enable_SmartSAN)
704 vport->fdmi_port_mask = LPFC_FDMI2_SMART_ATTR;
706 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
708 vport->fdmi_hba_mask = 0;
709 vport->fdmi_port_mask = 0;
713 memcpy(&vport->fabric_portname, &sp->portName,
714 sizeof(struct lpfc_name));
715 memcpy(&vport->fabric_nodename, &sp->nodeName,
716 sizeof(struct lpfc_name));
717 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
719 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
720 if (sp->cmn.response_multiple_NPort) {
721 lpfc_printf_vlog(vport, KERN_WARNING,
723 "1816 FLOGI NPIV supported, "
724 "response data 0x%x\n",
725 sp->cmn.response_multiple_NPort);
726 spin_lock_irq(&phba->hbalock);
727 phba->link_flag |= LS_NPIV_FAB_SUPPORTED;
728 spin_unlock_irq(&phba->hbalock);
730 /* Because we asked f/w for NPIV it still expects us
731 to call reg_vnpid atleast for the physcial host */
732 lpfc_printf_vlog(vport, KERN_WARNING,
734 "1817 Fabric does not support NPIV "
735 "- configuring single port mode.\n");
736 spin_lock_irq(&phba->hbalock);
737 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
738 spin_unlock_irq(&phba->hbalock);
743 * For FC we need to do some special processing because of the SLI
744 * Port's default settings of the Common Service Parameters.
746 if ((phba->sli_rev == LPFC_SLI_REV4) &&
747 (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC)) {
748 /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */
749 if (fabric_param_changed)
750 lpfc_unregister_fcf_prep(phba);
752 /* This should just update the VFI CSPs*/
753 if (vport->fc_flag & FC_VFI_REGISTERED)
754 lpfc_issue_reg_vfi(vport);
757 if (fabric_param_changed &&
758 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
760 /* If our NportID changed, we need to ensure all
761 * remaining NPORTs get unreg_login'ed.
763 list_for_each_entry_safe(np, next_np,
764 &vport->fc_nodes, nlp_listp) {
765 if (!NLP_CHK_NODE_ACT(np))
767 if ((np->nlp_state != NLP_STE_NPR_NODE) ||
768 !(np->nlp_flag & NLP_NPR_ADISC))
770 spin_lock_irq(shost->host_lock);
771 np->nlp_flag &= ~NLP_NPR_ADISC;
772 spin_unlock_irq(shost->host_lock);
773 lpfc_unreg_rpi(vport, np);
775 lpfc_cleanup_pending_mbox(vport);
777 if (phba->sli_rev == LPFC_SLI_REV4) {
778 lpfc_sli4_unreg_all_rpis(vport);
779 lpfc_mbx_unreg_vpi(vport);
780 spin_lock_irq(shost->host_lock);
781 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
782 spin_unlock_irq(shost->host_lock);
786 * For SLI3 and SLI4, the VPI needs to be reregistered in
787 * response to this fabric parameter change event.
789 spin_lock_irq(shost->host_lock);
790 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
791 spin_unlock_irq(shost->host_lock);
792 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
793 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
795 * Driver needs to re-reg VPI in order for f/w
796 * to update the MAC address.
798 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
799 lpfc_register_new_vport(phba, vport, ndlp);
803 if (phba->sli_rev < LPFC_SLI_REV4) {
804 lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
805 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED &&
806 vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
807 lpfc_register_new_vport(phba, vport, ndlp);
809 lpfc_issue_fabric_reglogin(vport);
811 ndlp->nlp_type |= NLP_FABRIC;
812 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
813 if ((!(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) &&
814 (vport->vpi_state & LPFC_VPI_REGISTERED)) {
815 lpfc_start_fdiscs(phba);
816 lpfc_do_scr_ns_plogi(phba, vport);
817 } else if (vport->fc_flag & FC_VFI_REGISTERED)
818 lpfc_issue_init_vpi(vport);
820 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
821 "3135 Need register VFI: (x%x/%x)\n",
822 vport->fc_prevDID, vport->fc_myDID);
823 lpfc_issue_reg_vfi(vport);
830 * lpfc_cmpl_els_flogi_nport - Completion function for flogi to an N_Port
831 * @vport: pointer to a host virtual N_Port data structure.
832 * @ndlp: pointer to a node-list data structure.
833 * @sp: pointer to service parameter data structure.
835 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
836 * function to handle the completion of a Fabric Login (FLOGI) into an N_Port
837 * in a point-to-point topology. First, the @vport's N_Port Name is compared
838 * with the received N_Port Name: if the @vport's N_Port Name is greater than
839 * the received N_Port Name lexicographically, this node shall assign local
840 * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and
841 * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise,
842 * this node shall just wait for the remote node to issue PLOGI and assign
850 lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
851 struct serv_parm *sp)
853 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
854 struct lpfc_hba *phba = vport->phba;
858 spin_lock_irq(shost->host_lock);
859 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
860 vport->fc_flag |= FC_PT2PT;
861 spin_unlock_irq(shost->host_lock);
863 /* If we are pt2pt with another NPort, force NPIV off! */
864 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
866 /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */
867 if ((phba->sli_rev == LPFC_SLI_REV4) && phba->fc_topology_changed) {
868 lpfc_unregister_fcf_prep(phba);
870 spin_lock_irq(shost->host_lock);
871 vport->fc_flag &= ~FC_VFI_REGISTERED;
872 spin_unlock_irq(shost->host_lock);
873 phba->fc_topology_changed = 0;
876 rc = memcmp(&vport->fc_portname, &sp->portName,
877 sizeof(vport->fc_portname));
880 /* This side will initiate the PLOGI */
881 spin_lock_irq(shost->host_lock);
882 vport->fc_flag |= FC_PT2PT_PLOGI;
883 spin_unlock_irq(shost->host_lock);
886 * N_Port ID cannot be 0, set our Id to LocalID
887 * the other side will be RemoteID.
892 vport->fc_myDID = PT2PT_LocalID;
894 /* Decrement ndlp reference count indicating that ndlp can be
895 * safely released when other references to it are done.
899 ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
902 * Cannot find existing Fabric ndlp, so allocate a
905 ndlp = lpfc_nlp_init(vport, PT2PT_RemoteID);
908 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
909 ndlp = lpfc_enable_node(vport, ndlp,
910 NLP_STE_UNUSED_NODE);
915 memcpy(&ndlp->nlp_portname, &sp->portName,
916 sizeof(struct lpfc_name));
917 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
918 sizeof(struct lpfc_name));
919 /* Set state will put ndlp onto node list if not already done */
920 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
921 spin_lock_irq(shost->host_lock);
922 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
923 spin_unlock_irq(shost->host_lock);
925 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
929 lpfc_config_link(phba, mbox);
931 mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link;
933 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
934 if (rc == MBX_NOT_FINISHED) {
935 mempool_free(mbox, phba->mbox_mem_pool);
939 /* This side will wait for the PLOGI, decrement ndlp reference
940 * count indicating that ndlp can be released when other
941 * references to it are done.
945 /* Start discovery - this should just do CLEAR_LA */
946 lpfc_disc_start(vport);
955 * lpfc_cmpl_els_flogi - Completion callback function for flogi
956 * @phba: pointer to lpfc hba data structure.
957 * @cmdiocb: pointer to lpfc command iocb data structure.
958 * @rspiocb: pointer to lpfc response iocb data structure.
960 * This routine is the top-level completion callback function for issuing
961 * a Fabric Login (FLOGI) command. If the response IOCB reported error,
962 * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If
963 * retry has been made (either immediately or delayed with lpfc_els_retry()
964 * returning 1), the command IOCB will be released and function returned.
965 * If the retry attempt has been given up (possibly reach the maximum
966 * number of retries), one additional decrement of ndlp reference shall be
967 * invoked before going out after releasing the command IOCB. This will
968 * actually release the remote node (Note, lpfc_els_free_iocb() will also
969 * invoke one decrement of ndlp reference count). If no error reported in
970 * the IOCB status, the command Port ID field is used to determine whether
971 * this is a point-to-point topology or a fabric topology: if the Port ID
972 * field is assigned, it is a fabric topology; otherwise, it is a
973 * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or
974 * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the
975 * specific topology completion conditions.
978 lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
979 struct lpfc_iocbq *rspiocb)
981 struct lpfc_vport *vport = cmdiocb->vport;
982 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
983 IOCB_t *irsp = &rspiocb->iocb;
984 struct lpfc_nodelist *ndlp = cmdiocb->context1;
985 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
986 struct serv_parm *sp;
990 /* Check to see if link went down during discovery */
991 if (lpfc_els_chk_latt(vport)) {
992 /* One additional decrement on node reference count to
993 * trigger the release of the node
999 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1000 "FLOGI cmpl: status:x%x/x%x state:x%x",
1001 irsp->ulpStatus, irsp->un.ulpWord[4],
1004 if (irsp->ulpStatus) {
1006 * In case of FIP mode, perform roundrobin FCF failover
1007 * due to new FCF discovery
1009 if ((phba->hba_flag & HBA_FIP_SUPPORT) &&
1010 (phba->fcf.fcf_flag & FCF_DISCOVERY)) {
1011 if (phba->link_state < LPFC_LINK_UP)
1012 goto stop_rr_fcf_flogi;
1013 if ((phba->fcoe_cvl_eventtag_attn ==
1014 phba->fcoe_cvl_eventtag) &&
1015 (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
1016 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1018 goto stop_rr_fcf_flogi;
1020 phba->fcoe_cvl_eventtag_attn =
1021 phba->fcoe_cvl_eventtag;
1022 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
1023 "2611 FLOGI failed on FCF (x%x), "
1024 "status:x%x/x%x, tmo:x%x, perform "
1025 "roundrobin FCF failover\n",
1026 phba->fcf.current_rec.fcf_indx,
1027 irsp->ulpStatus, irsp->un.ulpWord[4],
1029 lpfc_sli4_set_fcf_flogi_fail(phba,
1030 phba->fcf.current_rec.fcf_indx);
1031 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
1032 rc = lpfc_sli4_fcf_rr_next_proc(vport, fcf_index);
1039 if (!(irsp->ulpStatus == IOSTAT_LOCAL_REJECT &&
1040 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1041 IOERR_LOOP_OPEN_FAILURE)))
1042 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1043 "2858 FLOGI failure Status:x%x/x%x "
1044 "TMO:x%x Data x%x x%x\n",
1045 irsp->ulpStatus, irsp->un.ulpWord[4],
1046 irsp->ulpTimeout, phba->hba_flag,
1047 phba->fcf.fcf_flag);
1049 /* Check for retry */
1050 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
1053 /* If this is not a loop open failure, bail out */
1054 if (!(irsp->ulpStatus == IOSTAT_LOCAL_REJECT &&
1055 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1056 IOERR_LOOP_OPEN_FAILURE)))
1059 lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS,
1060 "0150 FLOGI failure Status:x%x/x%x xri x%x TMO:x%x\n",
1061 irsp->ulpStatus, irsp->un.ulpWord[4],
1062 cmdiocb->sli4_xritag, irsp->ulpTimeout);
1064 /* FLOGI failed, so there is no fabric */
1065 spin_lock_irq(shost->host_lock);
1066 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
1067 spin_unlock_irq(shost->host_lock);
1069 /* If private loop, then allow max outstanding els to be
1070 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
1071 * alpa map would take too long otherwise.
1073 if (phba->alpa_map[0] == 0)
1074 vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
1075 if ((phba->sli_rev == LPFC_SLI_REV4) &&
1076 (!(vport->fc_flag & FC_VFI_REGISTERED) ||
1077 (vport->fc_prevDID != vport->fc_myDID) ||
1078 phba->fc_topology_changed)) {
1079 if (vport->fc_flag & FC_VFI_REGISTERED) {
1080 if (phba->fc_topology_changed) {
1081 lpfc_unregister_fcf_prep(phba);
1082 spin_lock_irq(shost->host_lock);
1083 vport->fc_flag &= ~FC_VFI_REGISTERED;
1084 spin_unlock_irq(shost->host_lock);
1085 phba->fc_topology_changed = 0;
1087 lpfc_sli4_unreg_all_rpis(vport);
1091 /* Do not register VFI if the driver aborted FLOGI */
1092 if (!lpfc_error_lost_link(irsp))
1093 lpfc_issue_reg_vfi(vport);
1099 spin_lock_irq(shost->host_lock);
1100 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
1101 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
1102 spin_unlock_irq(shost->host_lock);
1105 * The FLogI succeeded. Sync the data for the CPU before
1108 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
1111 sp = prsp->virt + sizeof(uint32_t);
1113 /* FLOGI completes successfully */
1114 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1115 "0101 FLOGI completes successfully, I/O tag:x%x, "
1116 "xri x%x Data: x%x x%x x%x x%x x%x %x\n",
1117 cmdiocb->iotag, cmdiocb->sli4_xritag,
1118 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
1119 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution,
1120 vport->port_state, vport->fc_flag);
1122 if (vport->port_state == LPFC_FLOGI) {
1124 * If Common Service Parameters indicate Nport
1125 * we are point to point, if Fport we are Fabric.
1128 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
1129 else if (!(phba->hba_flag & HBA_FCOE_MODE))
1130 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
1132 lpfc_printf_vlog(vport, KERN_ERR,
1134 "2831 FLOGI response with cleared Fabric "
1135 "bit fcf_index 0x%x "
1136 "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x "
1138 "%02x%02x%02x%02x%02x%02x%02x%02x\n",
1139 phba->fcf.current_rec.fcf_indx,
1140 phba->fcf.current_rec.switch_name[0],
1141 phba->fcf.current_rec.switch_name[1],
1142 phba->fcf.current_rec.switch_name[2],
1143 phba->fcf.current_rec.switch_name[3],
1144 phba->fcf.current_rec.switch_name[4],
1145 phba->fcf.current_rec.switch_name[5],
1146 phba->fcf.current_rec.switch_name[6],
1147 phba->fcf.current_rec.switch_name[7],
1148 phba->fcf.current_rec.fabric_name[0],
1149 phba->fcf.current_rec.fabric_name[1],
1150 phba->fcf.current_rec.fabric_name[2],
1151 phba->fcf.current_rec.fabric_name[3],
1152 phba->fcf.current_rec.fabric_name[4],
1153 phba->fcf.current_rec.fabric_name[5],
1154 phba->fcf.current_rec.fabric_name[6],
1155 phba->fcf.current_rec.fabric_name[7]);
1157 spin_lock_irq(&phba->hbalock);
1158 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
1159 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
1160 spin_unlock_irq(&phba->hbalock);
1161 phba->fcf.fcf_redisc_attempted = 0; /* reset */
1165 /* Mark the FCF discovery process done */
1166 if (phba->hba_flag & HBA_FIP_SUPPORT)
1167 lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP |
1169 "2769 FLOGI to FCF (x%x) "
1170 "completed successfully\n",
1171 phba->fcf.current_rec.fcf_indx);
1172 spin_lock_irq(&phba->hbalock);
1173 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
1174 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
1175 spin_unlock_irq(&phba->hbalock);
1176 phba->fcf.fcf_redisc_attempted = 0; /* reset */
1182 spin_lock_irq(&phba->hbalock);
1183 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
1184 spin_unlock_irq(&phba->hbalock);
1188 if (!lpfc_error_lost_link(irsp)) {
1189 /* FLOGI failed, so just use loop map to make discovery list */
1190 lpfc_disc_list_loopmap(vport);
1192 /* Start discovery */
1193 lpfc_disc_start(vport);
1194 } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
1195 (((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
1196 IOERR_SLI_ABORTED) &&
1197 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
1198 IOERR_SLI_DOWN))) &&
1199 (phba->link_state != LPFC_CLEAR_LA)) {
1200 /* If FLOGI failed enable link interrupt. */
1201 lpfc_issue_clear_la(phba, vport);
1204 lpfc_els_free_iocb(phba, cmdiocb);
1208 * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport
1209 * @vport: pointer to a host virtual N_Port data structure.
1210 * @ndlp: pointer to a node-list data structure.
1211 * @retry: number of retries to the command IOCB.
1213 * This routine issues a Fabric Login (FLOGI) Request ELS command
1214 * for a @vport. The initiator service parameters are put into the payload
1215 * of the FLOGI Request IOCB and the top-level callback function pointer
1216 * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
1217 * function field. The lpfc_issue_fabric_iocb routine is invoked to send
1218 * out FLOGI ELS command with one outstanding fabric IOCB at a time.
1220 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1221 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1222 * will be stored into the context1 field of the IOCB for the completion
1223 * callback function to the FLOGI ELS command.
1226 * 0 - successfully issued flogi iocb for @vport
1227 * 1 - failed to issue flogi iocb for @vport
1230 lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1233 struct lpfc_hba *phba = vport->phba;
1234 struct serv_parm *sp;
1236 struct lpfc_iocbq *elsiocb;
1242 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
1243 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1244 ndlp->nlp_DID, ELS_CMD_FLOGI);
1249 icmd = &elsiocb->iocb;
1250 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1252 /* For FLOGI request, remainder of payload is service parameters */
1253 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
1254 pcmd += sizeof(uint32_t);
1255 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
1256 sp = (struct serv_parm *) pcmd;
1258 /* Setup CSPs accordingly for Fabric */
1259 sp->cmn.e_d_tov = 0;
1260 sp->cmn.w2.r_a_tov = 0;
1261 sp->cmn.virtual_fabric_support = 0;
1262 sp->cls1.classValid = 0;
1263 if (sp->cmn.fcphLow < FC_PH3)
1264 sp->cmn.fcphLow = FC_PH3;
1265 if (sp->cmn.fcphHigh < FC_PH3)
1266 sp->cmn.fcphHigh = FC_PH3;
1268 if (phba->sli_rev == LPFC_SLI_REV4) {
1269 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
1270 LPFC_SLI_INTF_IF_TYPE_0) {
1271 elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1);
1272 elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1);
1273 /* FLOGI needs to be 3 for WQE FCFI */
1274 /* Set the fcfi to the fcfi we registered with */
1275 elsiocb->iocb.ulpContext = phba->fcf.fcfi;
1277 /* Can't do SLI4 class2 without support sequence coalescing */
1278 sp->cls2.classValid = 0;
1279 sp->cls2.seqDelivery = 0;
1281 /* Historical, setting sequential-delivery bit for SLI3 */
1282 sp->cls2.seqDelivery = (sp->cls2.classValid) ? 1 : 0;
1283 sp->cls3.seqDelivery = (sp->cls3.classValid) ? 1 : 0;
1284 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
1285 sp->cmn.request_multiple_Nport = 1;
1286 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
1290 sp->cmn.request_multiple_Nport = 0;
1293 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
1294 icmd->un.elsreq64.myID = 0;
1295 icmd->un.elsreq64.fl = 1;
1298 tmo = phba->fc_ratov;
1299 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
1300 lpfc_set_disctmo(vport);
1301 phba->fc_ratov = tmo;
1303 phba->fc_stat.elsXmitFLOGI++;
1304 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
1306 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1307 "Issue FLOGI: opt:x%x",
1308 phba->sli3_options, 0, 0);
1310 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
1311 if (rc == IOCB_ERROR) {
1312 lpfc_els_free_iocb(phba, elsiocb);
1319 * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs
1320 * @phba: pointer to lpfc hba data structure.
1322 * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
1323 * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
1324 * list and issues an abort IOCB commond on each outstanding IOCB that
1325 * contains a active Fabric_DID ndlp. Note that this function is to issue
1326 * the abort IOCB command on all the outstanding IOCBs, thus when this
1327 * function returns, it does not guarantee all the IOCBs are actually aborted.
1330 * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0)
1333 lpfc_els_abort_flogi(struct lpfc_hba *phba)
1335 struct lpfc_sli_ring *pring;
1336 struct lpfc_iocbq *iocb, *next_iocb;
1337 struct lpfc_nodelist *ndlp;
1340 /* Abort outstanding I/O on NPort <nlp_DID> */
1341 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
1342 "0201 Abort outstanding I/O on NPort x%x\n",
1345 pring = lpfc_phba_elsring(phba);
1346 if (unlikely(!pring))
1350 * Check the txcmplq for an iocb that matches the nport the driver is
1353 spin_lock_irq(&phba->hbalock);
1354 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
1356 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR) {
1357 ndlp = (struct lpfc_nodelist *)(iocb->context1);
1358 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
1359 (ndlp->nlp_DID == Fabric_DID))
1360 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
1363 spin_unlock_irq(&phba->hbalock);
1369 * lpfc_initial_flogi - Issue an initial fabric login for a vport
1370 * @vport: pointer to a host virtual N_Port data structure.
1372 * This routine issues an initial Fabric Login (FLOGI) for the @vport
1373 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1374 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1375 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1376 * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
1377 * is then invoked with the @vport and the ndlp to perform the FLOGI for the
1381 * 0 - failed to issue initial flogi for @vport
1382 * 1 - successfully issued initial flogi for @vport
1385 lpfc_initial_flogi(struct lpfc_vport *vport)
1387 struct lpfc_nodelist *ndlp;
1389 vport->port_state = LPFC_FLOGI;
1390 lpfc_set_disctmo(vport);
1392 /* First look for the Fabric ndlp */
1393 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1395 /* Cannot find existing Fabric ndlp, so allocate a new one */
1396 ndlp = lpfc_nlp_init(vport, Fabric_DID);
1399 /* Set the node type */
1400 ndlp->nlp_type |= NLP_FABRIC;
1401 /* Put ndlp onto node list */
1402 lpfc_enqueue_node(vport, ndlp);
1403 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1404 /* re-setup ndlp without removing from node list */
1405 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1410 if (lpfc_issue_els_flogi(vport, ndlp, 0)) {
1411 /* This decrement of reference count to node shall kick off
1412 * the release of the node.
1421 * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport
1422 * @vport: pointer to a host virtual N_Port data structure.
1424 * This routine issues an initial Fabric Discover (FDISC) for the @vport
1425 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1426 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1427 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1428 * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
1429 * is then invoked with the @vport and the ndlp to perform the FDISC for the
1433 * 0 - failed to issue initial fdisc for @vport
1434 * 1 - successfully issued initial fdisc for @vport
1437 lpfc_initial_fdisc(struct lpfc_vport *vport)
1439 struct lpfc_nodelist *ndlp;
1441 /* First look for the Fabric ndlp */
1442 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1444 /* Cannot find existing Fabric ndlp, so allocate a new one */
1445 ndlp = lpfc_nlp_init(vport, Fabric_DID);
1448 /* Put ndlp onto node list */
1449 lpfc_enqueue_node(vport, ndlp);
1450 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1451 /* re-setup ndlp without removing from node list */
1452 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1457 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
1458 /* decrement node reference count to trigger the release of
1468 * lpfc_more_plogi - Check and issue remaining plogis for a vport
1469 * @vport: pointer to a host virtual N_Port data structure.
1471 * This routine checks whether there are more remaining Port Logins
1472 * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
1473 * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
1474 * to issue ELS PLOGIs up to the configured discover threads with the
1475 * @vport (@vport->cfg_discovery_threads). The function also decrement
1476 * the @vport's num_disc_node by 1 if it is not already 0.
1479 lpfc_more_plogi(struct lpfc_vport *vport)
1481 if (vport->num_disc_nodes)
1482 vport->num_disc_nodes--;
1484 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
1485 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1486 "0232 Continue discovery with %d PLOGIs to go "
1487 "Data: x%x x%x x%x\n",
1488 vport->num_disc_nodes, vport->fc_plogi_cnt,
1489 vport->fc_flag, vport->port_state);
1490 /* Check to see if there are more PLOGIs to be sent */
1491 if (vport->fc_flag & FC_NLP_MORE)
1492 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
1493 lpfc_els_disc_plogi(vport);
1499 * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp
1500 * @phba: pointer to lpfc hba data structure.
1501 * @prsp: pointer to response IOCB payload.
1502 * @ndlp: pointer to a node-list data structure.
1504 * This routine checks and indicates whether the WWPN of an N_Port, retrieved
1505 * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
1506 * The following cases are considered N_Port confirmed:
1507 * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
1508 * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
1509 * it does not have WWPN assigned either. If the WWPN is confirmed, the
1510 * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
1511 * 1) if there is a node on vport list other than the @ndlp with the same
1512 * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
1513 * on that node to release the RPI associated with the node; 2) if there is
1514 * no node found on vport list with the same WWPN of the N_Port PLOGI logged
1515 * into, a new node shall be allocated (or activated). In either case, the
1516 * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
1517 * be released and the new_ndlp shall be put on to the vport node list and
1518 * its pointer returned as the confirmed node.
1520 * Note that before the @ndlp got "released", the keepDID from not-matching
1521 * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
1522 * of the @ndlp. This is because the release of @ndlp is actually to put it
1523 * into an inactive state on the vport node list and the vport node list
1524 * management algorithm does not allow two node with a same DID.
1527 * pointer to the PLOGI N_Port @ndlp
1529 static struct lpfc_nodelist *
1530 lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
1531 struct lpfc_nodelist *ndlp)
1533 struct lpfc_vport *vport = ndlp->vport;
1534 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1535 struct lpfc_nodelist *new_ndlp;
1536 struct lpfc_rport_data *rdata;
1537 struct fc_rport *rport;
1538 struct serv_parm *sp;
1539 uint8_t name[sizeof(struct lpfc_name)];
1540 uint32_t rc, keepDID = 0, keep_nlp_flag = 0;
1541 uint16_t keep_nlp_state;
1542 struct lpfc_nvme_rport *keep_nrport = NULL;
1545 unsigned long *active_rrqs_xri_bitmap = NULL;
1547 /* Fabric nodes can have the same WWPN so we don't bother searching
1548 * by WWPN. Just return the ndlp that was given to us.
1550 if (ndlp->nlp_type & NLP_FABRIC)
1553 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
1554 memset(name, 0, sizeof(struct lpfc_name));
1556 /* Now we find out if the NPort we are logging into, matches the WWPN
1557 * we have for that ndlp. If not, we have some work to do.
1559 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
1561 /* return immediately if the WWPN matches ndlp */
1562 if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp))
1565 if (phba->sli_rev == LPFC_SLI_REV4) {
1566 active_rrqs_xri_bitmap = mempool_alloc(phba->active_rrq_pool,
1568 if (active_rrqs_xri_bitmap)
1569 memset(active_rrqs_xri_bitmap, 0,
1570 phba->cfg_rrq_xri_bitmap_sz);
1573 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_NODE,
1574 "3178 PLOGI confirm: ndlp x%x x%x x%x: "
1575 "new_ndlp x%x x%x x%x\n",
1576 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_fc4_type,
1577 (new_ndlp ? new_ndlp->nlp_DID : 0),
1578 (new_ndlp ? new_ndlp->nlp_flag : 0),
1579 (new_ndlp ? new_ndlp->nlp_fc4_type : 0));
1582 rc = memcmp(&ndlp->nlp_portname, name,
1583 sizeof(struct lpfc_name));
1585 if (active_rrqs_xri_bitmap)
1586 mempool_free(active_rrqs_xri_bitmap,
1587 phba->active_rrq_pool);
1590 new_ndlp = lpfc_nlp_init(vport, ndlp->nlp_DID);
1592 if (active_rrqs_xri_bitmap)
1593 mempool_free(active_rrqs_xri_bitmap,
1594 phba->active_rrq_pool);
1597 } else if (!NLP_CHK_NODE_ACT(new_ndlp)) {
1598 rc = memcmp(&ndlp->nlp_portname, name,
1599 sizeof(struct lpfc_name));
1601 if (active_rrqs_xri_bitmap)
1602 mempool_free(active_rrqs_xri_bitmap,
1603 phba->active_rrq_pool);
1606 new_ndlp = lpfc_enable_node(vport, new_ndlp,
1607 NLP_STE_UNUSED_NODE);
1609 if (active_rrqs_xri_bitmap)
1610 mempool_free(active_rrqs_xri_bitmap,
1611 phba->active_rrq_pool);
1614 keepDID = new_ndlp->nlp_DID;
1615 if ((phba->sli_rev == LPFC_SLI_REV4) && active_rrqs_xri_bitmap)
1616 memcpy(active_rrqs_xri_bitmap,
1617 new_ndlp->active_rrqs_xri_bitmap,
1618 phba->cfg_rrq_xri_bitmap_sz);
1620 keepDID = new_ndlp->nlp_DID;
1621 if (phba->sli_rev == LPFC_SLI_REV4 &&
1622 active_rrqs_xri_bitmap)
1623 memcpy(active_rrqs_xri_bitmap,
1624 new_ndlp->active_rrqs_xri_bitmap,
1625 phba->cfg_rrq_xri_bitmap_sz);
1628 /* At this point in this routine, we know new_ndlp will be
1629 * returned. however, any previous GID_FTs that were done
1630 * would have updated nlp_fc4_type in ndlp, so we must ensure
1631 * new_ndlp has the right value.
1633 if (vport->fc_flag & FC_FABRIC)
1634 new_ndlp->nlp_fc4_type = ndlp->nlp_fc4_type;
1636 lpfc_unreg_rpi(vport, new_ndlp);
1637 new_ndlp->nlp_DID = ndlp->nlp_DID;
1638 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
1639 if (phba->sli_rev == LPFC_SLI_REV4)
1640 memcpy(new_ndlp->active_rrqs_xri_bitmap,
1641 ndlp->active_rrqs_xri_bitmap,
1642 phba->cfg_rrq_xri_bitmap_sz);
1644 spin_lock_irq(shost->host_lock);
1645 keep_nlp_flag = new_ndlp->nlp_flag;
1646 new_ndlp->nlp_flag = ndlp->nlp_flag;
1647 ndlp->nlp_flag = keep_nlp_flag;
1648 spin_unlock_irq(shost->host_lock);
1650 /* Set nlp_states accordingly */
1651 keep_nlp_state = new_ndlp->nlp_state;
1652 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
1654 /* interchange the nvme remoteport structs */
1655 keep_nrport = new_ndlp->nrport;
1656 new_ndlp->nrport = ndlp->nrport;
1658 /* Move this back to NPR state */
1659 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
1660 /* The new_ndlp is replacing ndlp totally, so we need
1661 * to put ndlp on UNUSED list and try to free it.
1663 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1664 "3179 PLOGI confirm NEW: %x %x\n",
1665 new_ndlp->nlp_DID, keepDID);
1667 /* Fix up the rport accordingly */
1668 rport = ndlp->rport;
1670 rdata = rport->dd_data;
1671 if (rdata->pnode == ndlp) {
1672 /* break the link before dropping the ref */
1675 rdata->pnode = lpfc_nlp_get(new_ndlp);
1676 new_ndlp->rport = rport;
1678 new_ndlp->nlp_type = ndlp->nlp_type;
1681 /* Fix up the nvme rport */
1683 ndlp->nrport = NULL;
1687 /* We shall actually free the ndlp with both nlp_DID and
1688 * nlp_portname fields equals 0 to avoid any ndlp on the
1689 * nodelist never to be used.
1691 if (ndlp->nlp_DID == 0) {
1692 spin_lock_irq(&phba->ndlp_lock);
1693 NLP_SET_FREE_REQ(ndlp);
1694 spin_unlock_irq(&phba->ndlp_lock);
1697 /* Two ndlps cannot have the same did on the nodelist */
1698 ndlp->nlp_DID = keepDID;
1699 lpfc_nlp_set_state(vport, ndlp, keep_nlp_state);
1700 if (phba->sli_rev == LPFC_SLI_REV4 &&
1701 active_rrqs_xri_bitmap)
1702 memcpy(ndlp->active_rrqs_xri_bitmap,
1703 active_rrqs_xri_bitmap,
1704 phba->cfg_rrq_xri_bitmap_sz);
1706 if (!NLP_CHK_NODE_ACT(ndlp))
1707 lpfc_drop_node(vport, ndlp);
1710 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1711 "3180 PLOGI confirm SWAP: %x %x\n",
1712 new_ndlp->nlp_DID, keepDID);
1714 lpfc_unreg_rpi(vport, ndlp);
1716 /* Two ndlps cannot have the same did */
1717 ndlp->nlp_DID = keepDID;
1718 if (phba->sli_rev == LPFC_SLI_REV4 &&
1719 active_rrqs_xri_bitmap)
1720 memcpy(ndlp->active_rrqs_xri_bitmap,
1721 active_rrqs_xri_bitmap,
1722 phba->cfg_rrq_xri_bitmap_sz);
1724 /* Since we are switching over to the new_ndlp,
1725 * reset the old ndlp state
1727 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
1728 (ndlp->nlp_state == NLP_STE_MAPPED_NODE))
1729 keep_nlp_state = NLP_STE_NPR_NODE;
1730 lpfc_nlp_set_state(vport, ndlp, keep_nlp_state);
1732 /* Previous ndlp no longer active with nvme host transport.
1733 * Remove reference from earlier registration unless the
1734 * nvme host took care of it.
1738 ndlp->nrport = keep_nrport;
1740 /* Fix up the rport accordingly */
1741 rport = ndlp->rport;
1743 rdata = rport->dd_data;
1744 put_node = rdata->pnode != NULL;
1745 put_rport = ndlp->rport != NULL;
1746 rdata->pnode = NULL;
1751 put_device(&rport->dev);
1754 if (phba->sli_rev == LPFC_SLI_REV4 &&
1755 active_rrqs_xri_bitmap)
1756 mempool_free(active_rrqs_xri_bitmap,
1757 phba->active_rrq_pool);
1759 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_NODE,
1760 "3173 PLOGI confirm exit: new_ndlp x%x x%x x%x\n",
1761 new_ndlp->nlp_DID, new_ndlp->nlp_flag,
1762 new_ndlp->nlp_fc4_type);
1768 * lpfc_end_rscn - Check and handle more rscn for a vport
1769 * @vport: pointer to a host virtual N_Port data structure.
1771 * This routine checks whether more Registration State Change
1772 * Notifications (RSCNs) came in while the discovery state machine was in
1773 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1774 * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1775 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1776 * handling the RSCNs.
1779 lpfc_end_rscn(struct lpfc_vport *vport)
1781 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1783 if (vport->fc_flag & FC_RSCN_MODE) {
1785 * Check to see if more RSCNs came in while we were
1786 * processing this one.
1788 if (vport->fc_rscn_id_cnt ||
1789 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
1790 lpfc_els_handle_rscn(vport);
1792 spin_lock_irq(shost->host_lock);
1793 vport->fc_flag &= ~FC_RSCN_MODE;
1794 spin_unlock_irq(shost->host_lock);
1800 * lpfc_cmpl_els_rrq - Completion handled for els RRQs.
1801 * @phba: pointer to lpfc hba data structure.
1802 * @cmdiocb: pointer to lpfc command iocb data structure.
1803 * @rspiocb: pointer to lpfc response iocb data structure.
1805 * This routine will call the clear rrq function to free the rrq and
1806 * clear the xri's bit in the ndlp's xri_bitmap. If the ndlp does not
1807 * exist then the clear_rrq is still called because the rrq needs to
1812 lpfc_cmpl_els_rrq(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1813 struct lpfc_iocbq *rspiocb)
1815 struct lpfc_vport *vport = cmdiocb->vport;
1817 struct lpfc_nodelist *ndlp;
1818 struct lpfc_node_rrq *rrq;
1820 /* we pass cmdiocb to state machine which needs rspiocb as well */
1821 rrq = cmdiocb->context_un.rrq;
1822 cmdiocb->context_un.rsp_iocb = rspiocb;
1824 irsp = &rspiocb->iocb;
1825 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1826 "RRQ cmpl: status:x%x/x%x did:x%x",
1827 irsp->ulpStatus, irsp->un.ulpWord[4],
1828 irsp->un.elsreq64.remoteID);
1830 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
1831 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || ndlp != rrq->ndlp) {
1832 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1833 "2882 RRQ completes to NPort x%x "
1834 "with no ndlp. Data: x%x x%x x%x\n",
1835 irsp->un.elsreq64.remoteID,
1836 irsp->ulpStatus, irsp->un.ulpWord[4],
1841 /* rrq completes to NPort <nlp_DID> */
1842 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1843 "2880 RRQ completes to NPort x%x "
1844 "Data: x%x x%x x%x x%x x%x\n",
1845 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1846 irsp->ulpTimeout, rrq->xritag, rrq->rxid);
1848 if (irsp->ulpStatus) {
1849 /* Check for retry */
1850 /* RRQ failed Don't print the vport to vport rjts */
1851 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1852 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1853 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1854 (phba)->pport->cfg_log_verbose & LOG_ELS)
1855 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1856 "2881 RRQ failure DID:%06X Status:x%x/x%x\n",
1857 ndlp->nlp_DID, irsp->ulpStatus,
1858 irsp->un.ulpWord[4]);
1862 lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
1863 lpfc_els_free_iocb(phba, cmdiocb);
1867 * lpfc_cmpl_els_plogi - Completion callback function for plogi
1868 * @phba: pointer to lpfc hba data structure.
1869 * @cmdiocb: pointer to lpfc command iocb data structure.
1870 * @rspiocb: pointer to lpfc response iocb data structure.
1872 * This routine is the completion callback function for issuing the Port
1873 * Login (PLOGI) command. For PLOGI completion, there must be an active
1874 * ndlp on the vport node list that matches the remote node ID from the
1875 * PLOGI response IOCB. If such ndlp does not exist, the PLOGI is simply
1876 * ignored and command IOCB released. The PLOGI response IOCB status is
1877 * checked for error conditons. If there is error status reported, PLOGI
1878 * retry shall be attempted by invoking the lpfc_els_retry() routine.
1879 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1880 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1881 * (DSM) is set for this PLOGI completion. Finally, it checks whether
1882 * there are additional N_Port nodes with the vport that need to perform
1883 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
1887 lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1888 struct lpfc_iocbq *rspiocb)
1890 struct lpfc_vport *vport = cmdiocb->vport;
1891 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1893 struct lpfc_nodelist *ndlp;
1894 struct lpfc_dmabuf *prsp;
1897 /* we pass cmdiocb to state machine which needs rspiocb as well */
1898 cmdiocb->context_un.rsp_iocb = rspiocb;
1900 irsp = &rspiocb->iocb;
1901 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1902 "PLOGI cmpl: status:x%x/x%x did:x%x",
1903 irsp->ulpStatus, irsp->un.ulpWord[4],
1904 irsp->un.elsreq64.remoteID);
1906 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
1907 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
1908 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1909 "0136 PLOGI completes to NPort x%x "
1910 "with no ndlp. Data: x%x x%x x%x\n",
1911 irsp->un.elsreq64.remoteID,
1912 irsp->ulpStatus, irsp->un.ulpWord[4],
1917 /* Since ndlp can be freed in the disc state machine, note if this node
1918 * is being used during discovery.
1920 spin_lock_irq(shost->host_lock);
1921 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
1922 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1923 spin_unlock_irq(shost->host_lock);
1926 /* PLOGI completes to NPort <nlp_DID> */
1927 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1928 "0102 PLOGI completes to NPort x%06x "
1929 "Data: x%x x%x x%x x%x x%x\n",
1930 ndlp->nlp_DID, ndlp->nlp_fc4_type,
1931 irsp->ulpStatus, irsp->un.ulpWord[4],
1932 disc, vport->num_disc_nodes);
1934 /* Check to see if link went down during discovery */
1935 if (lpfc_els_chk_latt(vport)) {
1936 spin_lock_irq(shost->host_lock);
1937 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1938 spin_unlock_irq(shost->host_lock);
1942 if (irsp->ulpStatus) {
1943 /* Check for retry */
1944 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1945 /* ELS command is being retried */
1947 spin_lock_irq(shost->host_lock);
1948 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1949 spin_unlock_irq(shost->host_lock);
1953 /* PLOGI failed Don't print the vport to vport rjts */
1954 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1955 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1956 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1957 (phba)->pport->cfg_log_verbose & LOG_ELS)
1958 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1959 "2753 PLOGI failure DID:%06X Status:x%x/x%x\n",
1960 ndlp->nlp_DID, irsp->ulpStatus,
1961 irsp->un.ulpWord[4]);
1962 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1963 if (lpfc_error_lost_link(irsp))
1964 rc = NLP_STE_FREED_NODE;
1966 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1967 NLP_EVT_CMPL_PLOGI);
1969 /* Good status, call state machine */
1970 prsp = list_entry(((struct lpfc_dmabuf *)
1971 cmdiocb->context2)->list.next,
1972 struct lpfc_dmabuf, list);
1973 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
1974 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1975 NLP_EVT_CMPL_PLOGI);
1978 if (disc && vport->num_disc_nodes) {
1979 /* Check to see if there are more PLOGIs to be sent */
1980 lpfc_more_plogi(vport);
1982 if (vport->num_disc_nodes == 0) {
1983 spin_lock_irq(shost->host_lock);
1984 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1985 spin_unlock_irq(shost->host_lock);
1987 lpfc_can_disctmo(vport);
1988 lpfc_end_rscn(vport);
1993 lpfc_els_free_iocb(phba, cmdiocb);
1998 * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
1999 * @vport: pointer to a host virtual N_Port data structure.
2000 * @did: destination port identifier.
2001 * @retry: number of retries to the command IOCB.
2003 * This routine issues a Port Login (PLOGI) command to a remote N_Port
2004 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
2005 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
2006 * This routine constructs the proper feilds of the PLOGI IOCB and invokes
2007 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
2009 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2010 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2011 * will be stored into the context1 field of the IOCB for the completion
2012 * callback function to the PLOGI ELS command.
2015 * 0 - Successfully issued a plogi for @vport
2016 * 1 - failed to issue a plogi for @vport
2019 lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
2021 struct lpfc_hba *phba = vport->phba;
2022 struct Scsi_Host *shost;
2023 struct serv_parm *sp;
2024 struct lpfc_nodelist *ndlp;
2025 struct lpfc_iocbq *elsiocb;
2030 ndlp = lpfc_findnode_did(vport, did);
2031 if (ndlp && !NLP_CHK_NODE_ACT(ndlp))
2034 /* If ndlp is not NULL, we will bump the reference count on it */
2035 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
2036 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
2041 shost = lpfc_shost_from_vport(vport);
2042 spin_lock_irq(shost->host_lock);
2043 ndlp->nlp_flag &= ~NLP_FCP_PRLI_RJT;
2044 spin_unlock_irq(shost->host_lock);
2046 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2048 /* For PLOGI request, remainder of payload is service parameters */
2049 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
2050 pcmd += sizeof(uint32_t);
2051 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
2052 sp = (struct serv_parm *) pcmd;
2055 * If we are a N-port connected to a Fabric, fix-up paramm's so logins
2056 * to device on remote loops work.
2058 if ((vport->fc_flag & FC_FABRIC) && !(vport->fc_flag & FC_PUBLIC_LOOP))
2059 sp->cmn.altBbCredit = 1;
2061 if (sp->cmn.fcphLow < FC_PH_4_3)
2062 sp->cmn.fcphLow = FC_PH_4_3;
2064 if (sp->cmn.fcphHigh < FC_PH3)
2065 sp->cmn.fcphHigh = FC_PH3;
2067 sp->cmn.valid_vendor_ver_level = 0;
2068 memset(sp->un.vendorVersion, 0, sizeof(sp->un.vendorVersion));
2069 sp->cmn.bbRcvSizeMsb &= 0xF;
2071 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2072 "Issue PLOGI: did:x%x",
2075 /* If our firmware supports this feature, convey that
2076 * information to the target using the vendor specific field.
2078 if (phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) {
2079 sp->cmn.valid_vendor_ver_level = 1;
2080 sp->un.vv.vid = cpu_to_be32(LPFC_VV_EMLX_ID);
2081 sp->un.vv.flags = cpu_to_be32(LPFC_VV_SUPPRESS_RSP);
2084 phba->fc_stat.elsXmitPLOGI++;
2085 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
2086 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
2088 if (ret == IOCB_ERROR) {
2089 lpfc_els_free_iocb(phba, elsiocb);
2096 * lpfc_cmpl_els_prli - Completion callback function for prli
2097 * @phba: pointer to lpfc hba data structure.
2098 * @cmdiocb: pointer to lpfc command iocb data structure.
2099 * @rspiocb: pointer to lpfc response iocb data structure.
2101 * This routine is the completion callback function for a Process Login
2102 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
2103 * status. If there is error status reported, PRLI retry shall be attempted
2104 * by invoking the lpfc_els_retry() routine. Otherwise, the state
2105 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
2106 * ndlp to mark the PRLI completion.
2109 lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2110 struct lpfc_iocbq *rspiocb)
2112 struct lpfc_vport *vport = cmdiocb->vport;
2113 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2115 struct lpfc_nodelist *ndlp;
2117 /* we pass cmdiocb to state machine which needs rspiocb as well */
2118 cmdiocb->context_un.rsp_iocb = rspiocb;
2120 irsp = &(rspiocb->iocb);
2121 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2122 spin_lock_irq(shost->host_lock);
2123 ndlp->nlp_flag &= ~NLP_PRLI_SND;
2125 /* Driver supports multiple FC4 types. Counters matter. */
2126 vport->fc_prli_sent--;
2127 ndlp->fc4_prli_sent--;
2128 spin_unlock_irq(shost->host_lock);
2130 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2131 "PRLI cmpl: status:x%x/x%x did:x%x",
2132 irsp->ulpStatus, irsp->un.ulpWord[4],
2135 /* PRLI completes to NPort <nlp_DID> */
2136 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2137 "0103 PRLI completes to NPort x%06x "
2138 "Data: x%x x%x x%x x%x\n",
2139 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2140 vport->num_disc_nodes, ndlp->fc4_prli_sent);
2142 /* Check to see if link went down during discovery */
2143 if (lpfc_els_chk_latt(vport))
2146 if (irsp->ulpStatus) {
2147 /* Check for retry */
2148 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2149 /* ELS command is being retried */
2154 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2155 "2754 PRLI failure DID:%06X Status:x%x/x%x, "
2157 ndlp->nlp_DID, irsp->ulpStatus,
2158 irsp->un.ulpWord[4], ndlp->fc4_prli_sent);
2160 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2161 if (lpfc_error_lost_link(irsp))
2164 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2167 /* Good status, call state machine. However, if another
2168 * PRLI is outstanding, don't call the state machine
2169 * because final disposition to Mapped or Unmapped is
2172 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2176 lpfc_els_free_iocb(phba, cmdiocb);
2181 * lpfc_issue_els_prli - Issue a prli iocb command for a vport
2182 * @vport: pointer to a host virtual N_Port data structure.
2183 * @ndlp: pointer to a node-list data structure.
2184 * @retry: number of retries to the command IOCB.
2186 * This routine issues a Process Login (PRLI) ELS command for the
2187 * @vport. The PRLI service parameters are set up in the payload of the
2188 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
2189 * is put to the IOCB completion callback func field before invoking the
2190 * routine lpfc_sli_issue_iocb() to send out PRLI command.
2192 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2193 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2194 * will be stored into the context1 field of the IOCB for the completion
2195 * callback function to the PRLI ELS command.
2198 * 0 - successfully issued prli iocb command for @vport
2199 * 1 - failed to issue prli iocb command for @vport
2202 lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2205 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2206 struct lpfc_hba *phba = vport->phba;
2208 struct lpfc_nvme_prli *npr_nvme;
2209 struct lpfc_iocbq *elsiocb;
2212 u32 local_nlp_type, elscmd;
2215 * If we are in RSCN mode, the FC4 types supported from a
2216 * previous GFT_ID command may not be accurate. So, if we
2217 * are a NVME Initiator, always look for the possibility of
2218 * the remote NPort beng a NVME Target.
2220 if (phba->sli_rev == LPFC_SLI_REV4 &&
2221 vport->fc_flag & FC_RSCN_MODE &&
2222 vport->nvmei_support)
2223 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
2224 local_nlp_type = ndlp->nlp_fc4_type;
2226 /* This routine will issue 1 or 2 PRLIs, so zero all the ndlp
2227 * fields here before any of them can complete.
2229 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
2230 ndlp->nlp_type &= ~(NLP_NVME_TARGET | NLP_NVME_INITIATOR);
2231 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
2232 ndlp->nlp_flag &= ~NLP_FIRSTBURST;
2233 ndlp->nvme_fb_size = 0;
2236 if (local_nlp_type & NLP_FC4_FCP) {
2237 /* Payload is 4 + 16 = 20 x14 bytes. */
2238 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
2239 elscmd = ELS_CMD_PRLI;
2240 } else if (local_nlp_type & NLP_FC4_NVME) {
2241 /* Payload is 4 + 20 = 24 x18 bytes. */
2242 cmdsize = (sizeof(uint32_t) + sizeof(struct lpfc_nvme_prli));
2243 elscmd = ELS_CMD_NVMEPRLI;
2245 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2246 "3083 Unknown FC_TYPE x%x ndlp x%06x\n",
2247 ndlp->nlp_fc4_type, ndlp->nlp_DID);
2251 /* SLI3 ports don't support NVME. If this rport is a strict NVME
2252 * FC4 type, implicitly LOGO.
2254 if (phba->sli_rev == LPFC_SLI_REV3 &&
2255 ndlp->nlp_fc4_type == NLP_FC4_NVME) {
2256 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2257 "3088 Rport fc4 type 0x%x not supported by SLI3 adapter\n",
2259 lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM);
2263 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2264 ndlp->nlp_DID, elscmd);
2268 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2270 /* For PRLI request, remainder of payload is service parameters */
2271 memset(pcmd, 0, cmdsize);
2273 if (local_nlp_type & NLP_FC4_FCP) {
2274 /* Remainder of payload is FCP PRLI parameter page.
2275 * Note: this data structure is defined as
2276 * BE/LE in the structure definition so no
2277 * byte swap call is made.
2279 *((uint32_t *)(pcmd)) = ELS_CMD_PRLI;
2280 pcmd += sizeof(uint32_t);
2284 * If our firmware version is 3.20 or later,
2285 * set the following bits for FC-TAPE support.
2287 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
2288 npr->ConfmComplAllowed = 1;
2290 npr->TaskRetryIdReq = 1;
2292 npr->estabImagePair = 1;
2293 npr->readXferRdyDis = 1;
2294 if (vport->cfg_first_burst_size)
2295 npr->writeXferRdyDis = 1;
2297 /* For FCP support */
2298 npr->prliType = PRLI_FCP_TYPE;
2299 npr->initiatorFunc = 1;
2300 elsiocb->iocb_flag |= LPFC_PRLI_FCP_REQ;
2302 /* Remove FCP type - processed. */
2303 local_nlp_type &= ~NLP_FC4_FCP;
2304 } else if (local_nlp_type & NLP_FC4_NVME) {
2305 /* Remainder of payload is NVME PRLI parameter page.
2306 * This data structure is the newer definition that
2307 * uses bf macros so a byte swap is required.
2309 *((uint32_t *)(pcmd)) = ELS_CMD_NVMEPRLI;
2310 pcmd += sizeof(uint32_t);
2311 npr_nvme = (struct lpfc_nvme_prli *)pcmd;
2312 bf_set(prli_type_code, npr_nvme, PRLI_NVME_TYPE);
2313 bf_set(prli_estabImagePair, npr_nvme, 0); /* Should be 0 */
2315 /* Only initiators request first burst. */
2316 if ((phba->cfg_nvme_enable_fb) &&
2317 !phba->nvmet_support)
2318 bf_set(prli_fba, npr_nvme, 1);
2320 if (phba->nvmet_support) {
2321 bf_set(prli_tgt, npr_nvme, 1);
2322 bf_set(prli_disc, npr_nvme, 1);
2324 bf_set(prli_init, npr_nvme, 1);
2325 bf_set(prli_conf, npr_nvme, 1);
2328 npr_nvme->word1 = cpu_to_be32(npr_nvme->word1);
2329 npr_nvme->word4 = cpu_to_be32(npr_nvme->word4);
2330 elsiocb->iocb_flag |= LPFC_PRLI_NVME_REQ;
2332 /* Remove NVME type - processed. */
2333 local_nlp_type &= ~NLP_FC4_NVME;
2336 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2337 "Issue PRLI: did:x%x",
2338 ndlp->nlp_DID, 0, 0);
2340 phba->fc_stat.elsXmitPRLI++;
2341 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
2342 spin_lock_irq(shost->host_lock);
2343 ndlp->nlp_flag |= NLP_PRLI_SND;
2345 /* The vport counters are used for lpfc_scan_finished, but
2346 * the ndlp is used to track outstanding PRLIs for different
2349 vport->fc_prli_sent++;
2350 ndlp->fc4_prli_sent++;
2351 spin_unlock_irq(shost->host_lock);
2352 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2354 spin_lock_irq(shost->host_lock);
2355 ndlp->nlp_flag &= ~NLP_PRLI_SND;
2356 spin_unlock_irq(shost->host_lock);
2357 lpfc_els_free_iocb(phba, elsiocb);
2362 /* The driver supports 2 FC4 types. Make sure
2363 * a PRLI is issued for all types before exiting.
2365 if (phba->sli_rev == LPFC_SLI_REV4 &&
2366 local_nlp_type & (NLP_FC4_FCP | NLP_FC4_NVME))
2367 goto send_next_prli;
2373 * lpfc_rscn_disc - Perform rscn discovery for a vport
2374 * @vport: pointer to a host virtual N_Port data structure.
2376 * This routine performs Registration State Change Notification (RSCN)
2377 * discovery for a @vport. If the @vport's node port recovery count is not
2378 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
2379 * the nodes that need recovery. If none of the PLOGI were needed through
2380 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
2381 * invoked to check and handle possible more RSCN came in during the period
2382 * of processing the current ones.
2385 lpfc_rscn_disc(struct lpfc_vport *vport)
2387 lpfc_can_disctmo(vport);
2389 /* RSCN discovery */
2390 /* go thru NPR nodes and issue ELS PLOGIs */
2391 if (vport->fc_npr_cnt)
2392 if (lpfc_els_disc_plogi(vport))
2395 lpfc_end_rscn(vport);
2399 * lpfc_adisc_done - Complete the adisc phase of discovery
2400 * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
2402 * This function is called when the final ADISC is completed during discovery.
2403 * This function handles clearing link attention or issuing reg_vpi depending
2404 * on whether npiv is enabled. This function also kicks off the PLOGI phase of
2406 * This function is called with no locks held.
2409 lpfc_adisc_done(struct lpfc_vport *vport)
2411 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2412 struct lpfc_hba *phba = vport->phba;
2415 * For NPIV, cmpl_reg_vpi will set port_state to READY,
2416 * and continue discovery.
2418 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2419 !(vport->fc_flag & FC_RSCN_MODE) &&
2420 (phba->sli_rev < LPFC_SLI_REV4)) {
2421 /* The ADISCs are complete. Doesn't matter if they
2422 * succeeded or failed because the ADISC completion
2423 * routine guarantees to call the state machine and
2424 * the RPI is either unregistered (failed ADISC response)
2425 * or the RPI is still valid and the node is marked
2426 * mapped for a target. The exchanges should be in the
2427 * correct state. This code is specific to SLI3.
2429 lpfc_issue_clear_la(phba, vport);
2430 lpfc_issue_reg_vpi(phba, vport);
2434 * For SLI2, we need to set port_state to READY
2435 * and continue discovery.
2437 if (vport->port_state < LPFC_VPORT_READY) {
2438 /* If we get here, there is nothing to ADISC */
2439 lpfc_issue_clear_la(phba, vport);
2440 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
2441 vport->num_disc_nodes = 0;
2442 /* go thru NPR list, issue ELS PLOGIs */
2443 if (vport->fc_npr_cnt)
2444 lpfc_els_disc_plogi(vport);
2445 if (!vport->num_disc_nodes) {
2446 spin_lock_irq(shost->host_lock);
2447 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2448 spin_unlock_irq(shost->host_lock);
2449 lpfc_can_disctmo(vport);
2450 lpfc_end_rscn(vport);
2453 vport->port_state = LPFC_VPORT_READY;
2455 lpfc_rscn_disc(vport);
2459 * lpfc_more_adisc - Issue more adisc as needed
2460 * @vport: pointer to a host virtual N_Port data structure.
2462 * This routine determines whether there are more ndlps on a @vport
2463 * node list need to have Address Discover (ADISC) issued. If so, it will
2464 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
2465 * remaining nodes which need to have ADISC sent.
2468 lpfc_more_adisc(struct lpfc_vport *vport)
2470 if (vport->num_disc_nodes)
2471 vport->num_disc_nodes--;
2472 /* Continue discovery with <num_disc_nodes> ADISCs to go */
2473 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2474 "0210 Continue discovery with %d ADISCs to go "
2475 "Data: x%x x%x x%x\n",
2476 vport->num_disc_nodes, vport->fc_adisc_cnt,
2477 vport->fc_flag, vport->port_state);
2478 /* Check to see if there are more ADISCs to be sent */
2479 if (vport->fc_flag & FC_NLP_MORE) {
2480 lpfc_set_disctmo(vport);
2481 /* go thru NPR nodes and issue any remaining ELS ADISCs */
2482 lpfc_els_disc_adisc(vport);
2484 if (!vport->num_disc_nodes)
2485 lpfc_adisc_done(vport);
2490 * lpfc_cmpl_els_adisc - Completion callback function for adisc
2491 * @phba: pointer to lpfc hba data structure.
2492 * @cmdiocb: pointer to lpfc command iocb data structure.
2493 * @rspiocb: pointer to lpfc response iocb data structure.
2495 * This routine is the completion function for issuing the Address Discover
2496 * (ADISC) command. It first checks to see whether link went down during
2497 * the discovery process. If so, the node will be marked as node port
2498 * recovery for issuing discover IOCB by the link attention handler and
2499 * exit. Otherwise, the response status is checked. If error was reported
2500 * in the response status, the ADISC command shall be retried by invoking
2501 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
2502 * the response status, the state machine is invoked to set transition
2503 * with respect to NLP_EVT_CMPL_ADISC event.
2506 lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2507 struct lpfc_iocbq *rspiocb)
2509 struct lpfc_vport *vport = cmdiocb->vport;
2510 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2512 struct lpfc_nodelist *ndlp;
2515 /* we pass cmdiocb to state machine which needs rspiocb as well */
2516 cmdiocb->context_un.rsp_iocb = rspiocb;
2518 irsp = &(rspiocb->iocb);
2519 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2521 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2522 "ADISC cmpl: status:x%x/x%x did:x%x",
2523 irsp->ulpStatus, irsp->un.ulpWord[4],
2526 /* Since ndlp can be freed in the disc state machine, note if this node
2527 * is being used during discovery.
2529 spin_lock_irq(shost->host_lock);
2530 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
2531 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
2532 spin_unlock_irq(shost->host_lock);
2533 /* ADISC completes to NPort <nlp_DID> */
2534 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2535 "0104 ADISC completes to NPort x%x "
2536 "Data: x%x x%x x%x x%x x%x\n",
2537 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2538 irsp->ulpTimeout, disc, vport->num_disc_nodes);
2539 /* Check to see if link went down during discovery */
2540 if (lpfc_els_chk_latt(vport)) {
2541 spin_lock_irq(shost->host_lock);
2542 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2543 spin_unlock_irq(shost->host_lock);
2547 if (irsp->ulpStatus) {
2548 /* Check for retry */
2549 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2550 /* ELS command is being retried */
2552 spin_lock_irq(shost->host_lock);
2553 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2554 spin_unlock_irq(shost->host_lock);
2555 lpfc_set_disctmo(vport);
2560 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2561 "2755 ADISC failure DID:%06X Status:x%x/x%x\n",
2562 ndlp->nlp_DID, irsp->ulpStatus,
2563 irsp->un.ulpWord[4]);
2564 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2565 if (!lpfc_error_lost_link(irsp))
2566 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2567 NLP_EVT_CMPL_ADISC);
2569 /* Good status, call state machine */
2570 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2571 NLP_EVT_CMPL_ADISC);
2573 /* Check to see if there are more ADISCs to be sent */
2574 if (disc && vport->num_disc_nodes)
2575 lpfc_more_adisc(vport);
2577 lpfc_els_free_iocb(phba, cmdiocb);
2582 * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
2583 * @vport: pointer to a virtual N_Port data structure.
2584 * @ndlp: pointer to a node-list data structure.
2585 * @retry: number of retries to the command IOCB.
2587 * This routine issues an Address Discover (ADISC) for an @ndlp on a
2588 * @vport. It prepares the payload of the ADISC ELS command, updates the
2589 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
2590 * to issue the ADISC ELS command.
2592 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2593 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2594 * will be stored into the context1 field of the IOCB for the completion
2595 * callback function to the ADISC ELS command.
2598 * 0 - successfully issued adisc
2599 * 1 - failed to issue adisc
2602 lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2605 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2606 struct lpfc_hba *phba = vport->phba;
2608 struct lpfc_iocbq *elsiocb;
2612 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
2613 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2614 ndlp->nlp_DID, ELS_CMD_ADISC);
2618 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2620 /* For ADISC request, remainder of payload is service parameters */
2621 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
2622 pcmd += sizeof(uint32_t);
2624 /* Fill in ADISC payload */
2625 ap = (ADISC *) pcmd;
2626 ap->hardAL_PA = phba->fc_pref_ALPA;
2627 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2628 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
2629 ap->DID = be32_to_cpu(vport->fc_myDID);
2631 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2632 "Issue ADISC: did:x%x",
2633 ndlp->nlp_DID, 0, 0);
2635 phba->fc_stat.elsXmitADISC++;
2636 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
2637 spin_lock_irq(shost->host_lock);
2638 ndlp->nlp_flag |= NLP_ADISC_SND;
2639 spin_unlock_irq(shost->host_lock);
2640 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2642 spin_lock_irq(shost->host_lock);
2643 ndlp->nlp_flag &= ~NLP_ADISC_SND;
2644 spin_unlock_irq(shost->host_lock);
2645 lpfc_els_free_iocb(phba, elsiocb);
2652 * lpfc_cmpl_els_logo - Completion callback function for logo
2653 * @phba: pointer to lpfc hba data structure.
2654 * @cmdiocb: pointer to lpfc command iocb data structure.
2655 * @rspiocb: pointer to lpfc response iocb data structure.
2657 * This routine is the completion function for issuing the ELS Logout (LOGO)
2658 * command. If no error status was reported from the LOGO response, the
2659 * state machine of the associated ndlp shall be invoked for transition with
2660 * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
2661 * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
2664 lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2665 struct lpfc_iocbq *rspiocb)
2667 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2668 struct lpfc_vport *vport = ndlp->vport;
2669 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2671 struct lpfcMboxq *mbox;
2672 unsigned long flags;
2673 uint32_t skip_recovery = 0;
2675 /* we pass cmdiocb to state machine which needs rspiocb as well */
2676 cmdiocb->context_un.rsp_iocb = rspiocb;
2678 irsp = &(rspiocb->iocb);
2679 spin_lock_irq(shost->host_lock);
2680 ndlp->nlp_flag &= ~NLP_LOGO_SND;
2681 spin_unlock_irq(shost->host_lock);
2683 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2684 "LOGO cmpl: status:x%x/x%x did:x%x",
2685 irsp->ulpStatus, irsp->un.ulpWord[4],
2688 /* LOGO completes to NPort <nlp_DID> */
2689 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2690 "0105 LOGO completes to NPort x%x "
2691 "Data: x%x x%x x%x x%x\n",
2692 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2693 irsp->ulpTimeout, vport->num_disc_nodes);
2695 if (lpfc_els_chk_latt(vport)) {
2700 /* Check to see if link went down during discovery */
2701 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
2702 /* NLP_EVT_DEVICE_RM should unregister the RPI
2703 * which should abort all outstanding IOs.
2705 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2711 /* The LOGO will not be retried on failure. A LOGO was
2712 * issued to the remote rport and a ACC or RJT or no Answer are
2713 * all acceptable. Note the failure and move forward with
2714 * discovery. The PLOGI will retry.
2716 if (irsp->ulpStatus) {
2718 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2719 "2756 LOGO failure, No Retry DID:%06X Status:x%x/x%x\n",
2720 ndlp->nlp_DID, irsp->ulpStatus,
2721 irsp->un.ulpWord[4]);
2722 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2723 if (lpfc_error_lost_link(irsp)) {
2729 /* Call state machine. This will unregister the rpi if needed. */
2730 lpfc_disc_state_machine(vport, ndlp, cmdiocb, NLP_EVT_CMPL_LOGO);
2733 lpfc_els_free_iocb(phba, cmdiocb);
2734 /* If we are in pt2pt mode, we could rcv new S_ID on PLOGI */
2735 if ((vport->fc_flag & FC_PT2PT) &&
2736 !(vport->fc_flag & FC_PT2PT_PLOGI)) {
2737 phba->pport->fc_myDID = 0;
2739 if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
2740 (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
2741 if (phba->nvmet_support)
2742 lpfc_nvmet_update_targetport(phba);
2744 lpfc_nvme_update_localport(phba->pport);
2747 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2749 lpfc_config_link(phba, mbox);
2750 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
2751 mbox->vport = vport;
2752 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) ==
2754 mempool_free(mbox, phba->mbox_mem_pool);
2761 * If the node is a target, the handling attempts to recover the port.
2762 * For any other port type, the rpi is unregistered as an implicit
2765 if (ndlp->nlp_type & (NLP_FCP_TARGET | NLP_NVME_TARGET) &&
2766 skip_recovery == 0) {
2767 lpfc_cancel_retry_delay_tmo(vport, ndlp);
2768 spin_lock_irqsave(shost->host_lock, flags);
2769 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2770 spin_unlock_irqrestore(shost->host_lock, flags);
2772 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2773 "3187 LOGO completes to NPort x%x: Start "
2774 "Recovery Data: x%x x%x x%x x%x\n",
2775 ndlp->nlp_DID, irsp->ulpStatus,
2776 irsp->un.ulpWord[4], irsp->ulpTimeout,
2777 vport->num_disc_nodes);
2778 lpfc_disc_start(vport);
2784 * lpfc_issue_els_logo - Issue a logo to an node on a vport
2785 * @vport: pointer to a virtual N_Port data structure.
2786 * @ndlp: pointer to a node-list data structure.
2787 * @retry: number of retries to the command IOCB.
2789 * This routine constructs and issues an ELS Logout (LOGO) iocb command
2790 * to a remote node, referred by an @ndlp on a @vport. It constructs the
2791 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
2792 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
2794 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2795 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2796 * will be stored into the context1 field of the IOCB for the completion
2797 * callback function to the LOGO ELS command.
2799 * Callers of this routine are expected to unregister the RPI first
2802 * 0 - successfully issued logo
2803 * 1 - failed to issue logo
2806 lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2809 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2810 struct lpfc_hba *phba = vport->phba;
2811 struct lpfc_iocbq *elsiocb;
2816 spin_lock_irq(shost->host_lock);
2817 if (ndlp->nlp_flag & NLP_LOGO_SND) {
2818 spin_unlock_irq(shost->host_lock);
2821 spin_unlock_irq(shost->host_lock);
2823 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
2824 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2825 ndlp->nlp_DID, ELS_CMD_LOGO);
2829 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2830 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
2831 pcmd += sizeof(uint32_t);
2833 /* Fill in LOGO payload */
2834 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
2835 pcmd += sizeof(uint32_t);
2836 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
2838 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2839 "Issue LOGO: did:x%x",
2840 ndlp->nlp_DID, 0, 0);
2842 phba->fc_stat.elsXmitLOGO++;
2843 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
2844 spin_lock_irq(shost->host_lock);
2845 ndlp->nlp_flag |= NLP_LOGO_SND;
2846 ndlp->nlp_flag &= ~NLP_ISSUE_LOGO;
2847 spin_unlock_irq(shost->host_lock);
2848 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
2849 if (rc == IOCB_ERROR) {
2850 spin_lock_irq(shost->host_lock);
2851 ndlp->nlp_flag &= ~NLP_LOGO_SND;
2852 spin_unlock_irq(shost->host_lock);
2853 lpfc_els_free_iocb(phba, elsiocb);
2857 spin_lock_irq(shost->host_lock);
2858 ndlp->nlp_prev_state = ndlp->nlp_state;
2859 spin_unlock_irq(shost->host_lock);
2860 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
2865 * lpfc_cmpl_els_cmd - Completion callback function for generic els command
2866 * @phba: pointer to lpfc hba data structure.
2867 * @cmdiocb: pointer to lpfc command iocb data structure.
2868 * @rspiocb: pointer to lpfc response iocb data structure.
2870 * This routine is a generic completion callback function for ELS commands.
2871 * Specifically, it is the callback function which does not need to perform
2872 * any command specific operations. It is currently used by the ELS command
2873 * issuing routines for the ELS State Change Request (SCR),
2874 * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution
2875 * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than
2876 * certain debug loggings, this callback function simply invokes the
2877 * lpfc_els_chk_latt() routine to check whether link went down during the
2878 * discovery process.
2881 lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2882 struct lpfc_iocbq *rspiocb)
2884 struct lpfc_vport *vport = cmdiocb->vport;
2887 irsp = &rspiocb->iocb;
2889 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2890 "ELS cmd cmpl: status:x%x/x%x did:x%x",
2891 irsp->ulpStatus, irsp->un.ulpWord[4],
2892 irsp->un.elsreq64.remoteID);
2893 /* ELS cmd tag <ulpIoTag> completes */
2894 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2895 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
2896 irsp->ulpIoTag, irsp->ulpStatus,
2897 irsp->un.ulpWord[4], irsp->ulpTimeout);
2898 /* Check to see if link went down during discovery */
2899 lpfc_els_chk_latt(vport);
2900 lpfc_els_free_iocb(phba, cmdiocb);
2905 * lpfc_issue_els_scr - Issue a scr to an node on a vport
2906 * @vport: pointer to a host virtual N_Port data structure.
2907 * @nportid: N_Port identifier to the remote node.
2908 * @retry: number of retries to the command IOCB.
2910 * This routine issues a State Change Request (SCR) to a fabric node
2911 * on a @vport. The remote node @nportid is passed into the function. It
2912 * first search the @vport node list to find the matching ndlp. If no such
2913 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
2914 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
2915 * routine is invoked to send the SCR IOCB.
2917 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2918 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2919 * will be stored into the context1 field of the IOCB for the completion
2920 * callback function to the SCR ELS command.
2923 * 0 - Successfully issued scr command
2924 * 1 - Failed to issue scr command
2927 lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
2929 struct lpfc_hba *phba = vport->phba;
2930 struct lpfc_iocbq *elsiocb;
2933 struct lpfc_nodelist *ndlp;
2935 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
2937 ndlp = lpfc_findnode_did(vport, nportid);
2939 ndlp = lpfc_nlp_init(vport, nportid);
2942 lpfc_enqueue_node(vport, ndlp);
2943 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2944 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2949 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2950 ndlp->nlp_DID, ELS_CMD_SCR);
2953 /* This will trigger the release of the node just
2960 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2962 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
2963 pcmd += sizeof(uint32_t);
2965 /* For SCR, remainder of payload is SCR parameter page */
2966 memset(pcmd, 0, sizeof(SCR));
2967 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
2969 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2970 "Issue SCR: did:x%x",
2971 ndlp->nlp_DID, 0, 0);
2973 phba->fc_stat.elsXmitSCR++;
2974 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
2975 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2977 /* The additional lpfc_nlp_put will cause the following
2978 * lpfc_els_free_iocb routine to trigger the rlease of
2982 lpfc_els_free_iocb(phba, elsiocb);
2985 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2986 * trigger the release of node.
2988 if (!(vport->fc_flag & FC_PT2PT))
2994 * lpfc_issue_els_farpr - Issue a farp to an node on a vport
2995 * @vport: pointer to a host virtual N_Port data structure.
2996 * @nportid: N_Port identifier to the remote node.
2997 * @retry: number of retries to the command IOCB.
2999 * This routine issues a Fibre Channel Address Resolution Response
3000 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
3001 * is passed into the function. It first search the @vport node list to find
3002 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
3003 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
3004 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
3006 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3007 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3008 * will be stored into the context1 field of the IOCB for the completion
3009 * callback function to the PARPR ELS command.
3012 * 0 - Successfully issued farpr command
3013 * 1 - Failed to issue farpr command
3016 lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
3018 struct lpfc_hba *phba = vport->phba;
3019 struct lpfc_iocbq *elsiocb;
3024 struct lpfc_nodelist *ondlp;
3025 struct lpfc_nodelist *ndlp;
3027 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
3029 ndlp = lpfc_findnode_did(vport, nportid);
3031 ndlp = lpfc_nlp_init(vport, nportid);
3034 lpfc_enqueue_node(vport, ndlp);
3035 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
3036 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
3041 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
3042 ndlp->nlp_DID, ELS_CMD_RNID);
3044 /* This will trigger the release of the node just
3051 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3053 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
3054 pcmd += sizeof(uint32_t);
3056 /* Fill in FARPR payload */
3057 fp = (FARP *) (pcmd);
3058 memset(fp, 0, sizeof(FARP));
3059 lp = (uint32_t *) pcmd;
3060 *lp++ = be32_to_cpu(nportid);
3061 *lp++ = be32_to_cpu(vport->fc_myDID);
3063 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
3065 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
3066 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
3067 ondlp = lpfc_findnode_did(vport, nportid);
3068 if (ondlp && NLP_CHK_NODE_ACT(ondlp)) {
3069 memcpy(&fp->OportName, &ondlp->nlp_portname,
3070 sizeof(struct lpfc_name));
3071 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
3072 sizeof(struct lpfc_name));
3075 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3076 "Issue FARPR: did:x%x",
3077 ndlp->nlp_DID, 0, 0);
3079 phba->fc_stat.elsXmitFARPR++;
3080 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
3081 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
3083 /* The additional lpfc_nlp_put will cause the following
3084 * lpfc_els_free_iocb routine to trigger the release of
3088 lpfc_els_free_iocb(phba, elsiocb);
3091 /* This will cause the callback-function lpfc_cmpl_els_cmd to
3092 * trigger the release of the node.
3099 * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
3100 * @vport: pointer to a host virtual N_Port data structure.
3101 * @nlp: pointer to a node-list data structure.
3103 * This routine cancels the timer with a delayed IOCB-command retry for
3104 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
3105 * removes the ELS retry event if it presents. In addition, if the
3106 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
3107 * commands are sent for the @vport's nodes that require issuing discovery
3111 lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
3113 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3114 struct lpfc_work_evt *evtp;
3116 if (!(nlp->nlp_flag & NLP_DELAY_TMO))
3118 spin_lock_irq(shost->host_lock);
3119 nlp->nlp_flag &= ~NLP_DELAY_TMO;
3120 spin_unlock_irq(shost->host_lock);
3121 del_timer_sync(&nlp->nlp_delayfunc);
3122 nlp->nlp_last_elscmd = 0;
3123 if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
3124 list_del_init(&nlp->els_retry_evt.evt_listp);
3125 /* Decrement nlp reference count held for the delayed retry */
3126 evtp = &nlp->els_retry_evt;
3127 lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
3129 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
3130 spin_lock_irq(shost->host_lock);
3131 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
3132 spin_unlock_irq(shost->host_lock);
3133 if (vport->num_disc_nodes) {
3134 if (vport->port_state < LPFC_VPORT_READY) {
3135 /* Check if there are more ADISCs to be sent */
3136 lpfc_more_adisc(vport);
3138 /* Check if there are more PLOGIs to be sent */
3139 lpfc_more_plogi(vport);
3140 if (vport->num_disc_nodes == 0) {
3141 spin_lock_irq(shost->host_lock);
3142 vport->fc_flag &= ~FC_NDISC_ACTIVE;
3143 spin_unlock_irq(shost->host_lock);
3144 lpfc_can_disctmo(vport);
3145 lpfc_end_rscn(vport);
3154 * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
3155 * @ptr: holder for the pointer to the timer function associated data (ndlp).
3157 * This routine is invoked by the ndlp delayed-function timer to check
3158 * whether there is any pending ELS retry event(s) with the node. If not, it
3159 * simply returns. Otherwise, if there is at least one ELS delayed event, it
3160 * adds the delayed events to the HBA work list and invokes the
3161 * lpfc_worker_wake_up() routine to wake up worker thread to process the
3162 * event. Note that lpfc_nlp_get() is called before posting the event to
3163 * the work list to hold reference count of ndlp so that it guarantees the
3164 * reference to ndlp will still be available when the worker thread gets
3165 * to the event associated with the ndlp.
3168 lpfc_els_retry_delay(struct timer_list *t)
3170 struct lpfc_nodelist *ndlp = from_timer(ndlp, t, nlp_delayfunc);
3171 struct lpfc_vport *vport = ndlp->vport;
3172 struct lpfc_hba *phba = vport->phba;
3173 unsigned long flags;
3174 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
3176 spin_lock_irqsave(&phba->hbalock, flags);
3177 if (!list_empty(&evtp->evt_listp)) {
3178 spin_unlock_irqrestore(&phba->hbalock, flags);
3182 /* We need to hold the node by incrementing the reference
3183 * count until the queued work is done
3185 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
3186 if (evtp->evt_arg1) {
3187 evtp->evt = LPFC_EVT_ELS_RETRY;
3188 list_add_tail(&evtp->evt_listp, &phba->work_list);
3189 lpfc_worker_wake_up(phba);
3191 spin_unlock_irqrestore(&phba->hbalock, flags);
3196 * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
3197 * @ndlp: pointer to a node-list data structure.
3199 * This routine is the worker-thread handler for processing the @ndlp delayed
3200 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
3201 * the last ELS command from the associated ndlp and invokes the proper ELS
3202 * function according to the delayed ELS command to retry the command.
3205 lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
3207 struct lpfc_vport *vport = ndlp->vport;
3208 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3209 uint32_t cmd, retry;
3211 spin_lock_irq(shost->host_lock);
3212 cmd = ndlp->nlp_last_elscmd;
3213 ndlp->nlp_last_elscmd = 0;
3215 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
3216 spin_unlock_irq(shost->host_lock);
3220 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
3221 spin_unlock_irq(shost->host_lock);
3223 * If a discovery event readded nlp_delayfunc after timer
3224 * firing and before processing the timer, cancel the
3227 del_timer_sync(&ndlp->nlp_delayfunc);
3228 retry = ndlp->nlp_retry;
3229 ndlp->nlp_retry = 0;
3233 lpfc_issue_els_flogi(vport, ndlp, retry);
3236 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
3237 ndlp->nlp_prev_state = ndlp->nlp_state;
3238 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
3242 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
3243 ndlp->nlp_prev_state = ndlp->nlp_state;
3244 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
3248 case ELS_CMD_NVMEPRLI:
3249 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
3250 ndlp->nlp_prev_state = ndlp->nlp_state;
3251 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
3255 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
3256 ndlp->nlp_prev_state = ndlp->nlp_state;
3257 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
3261 if (!(vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI))
3262 lpfc_issue_els_fdisc(vport, ndlp, retry);
3269 * lpfc_els_retry - Make retry decision on an els command iocb
3270 * @phba: pointer to lpfc hba data structure.
3271 * @cmdiocb: pointer to lpfc command iocb data structure.
3272 * @rspiocb: pointer to lpfc response iocb data structure.
3274 * This routine makes a retry decision on an ELS command IOCB, which has
3275 * failed. The following ELS IOCBs use this function for retrying the command
3276 * when previously issued command responsed with error status: FLOGI, PLOGI,
3277 * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
3278 * returned error status, it makes the decision whether a retry shall be
3279 * issued for the command, and whether a retry shall be made immediately or
3280 * delayed. In the former case, the corresponding ELS command issuing-function
3281 * is called to retry the command. In the later case, the ELS command shall
3282 * be posted to the ndlp delayed event and delayed function timer set to the
3283 * ndlp for the delayed command issusing.
3286 * 0 - No retry of els command is made
3287 * 1 - Immediate or delayed retry of els command is made
3290 lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3291 struct lpfc_iocbq *rspiocb)
3293 struct lpfc_vport *vport = cmdiocb->vport;
3294 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3295 IOCB_t *irsp = &rspiocb->iocb;
3296 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3297 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3300 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
3306 /* Note: context2 may be 0 for internal driver abort
3307 * of delays ELS command.
3310 if (pcmd && pcmd->virt) {
3311 elscmd = (uint32_t *) (pcmd->virt);
3315 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
3316 did = ndlp->nlp_DID;
3318 /* We should only hit this case for retrying PLOGI */
3319 did = irsp->un.elsreq64.remoteID;
3320 ndlp = lpfc_findnode_did(vport, did);
3321 if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp))
3322 && (cmd != ELS_CMD_PLOGI))
3326 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3327 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
3328 *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
3330 switch (irsp->ulpStatus) {
3331 case IOSTAT_FCP_RSP_ERROR:
3333 case IOSTAT_REMOTE_STOP:
3334 if (phba->sli_rev == LPFC_SLI_REV4) {
3335 /* This IO was aborted by the target, we don't
3336 * know the rxid and because we did not send the
3337 * ABTS we cannot generate and RRQ.
3339 lpfc_set_rrq_active(phba, ndlp,
3340 cmdiocb->sli4_lxritag, 0, 0);
3343 case IOSTAT_LOCAL_REJECT:
3344 switch ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK)) {
3345 case IOERR_LOOP_OPEN_FAILURE:
3346 if (cmd == ELS_CMD_FLOGI) {
3347 if (PCI_DEVICE_ID_HORNET ==
3348 phba->pcidev->device) {
3349 phba->fc_topology = LPFC_TOPOLOGY_LOOP;
3350 phba->pport->fc_myDID = 0;
3351 phba->alpa_map[0] = 0;
3352 phba->alpa_map[1] = 0;
3355 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
3360 case IOERR_ILLEGAL_COMMAND:
3361 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3362 "0124 Retry illegal cmd x%x "
3363 "retry:x%x delay:x%x\n",
3364 cmd, cmdiocb->retry, delay);
3366 /* All command's retry policy */
3368 if (cmdiocb->retry > 2)
3372 case IOERR_NO_RESOURCES:
3373 logerr = 1; /* HBA out of resources */
3375 if (cmdiocb->retry > 100)
3380 case IOERR_ILLEGAL_FRAME:
3385 case IOERR_SEQUENCE_TIMEOUT:
3386 case IOERR_INVALID_RPI:
3387 if (cmd == ELS_CMD_PLOGI &&
3388 did == NameServer_DID) {
3389 /* Continue forever if plogi to */
3390 /* the nameserver fails */
3399 case IOSTAT_NPORT_RJT:
3400 case IOSTAT_FABRIC_RJT:
3401 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
3407 case IOSTAT_NPORT_BSY:
3408 case IOSTAT_FABRIC_BSY:
3409 logerr = 1; /* Fabric / Remote NPort out of resources */
3414 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
3415 /* Added for Vendor specifc support
3416 * Just keep retrying for these Rsn / Exp codes
3418 switch (stat.un.b.lsRjtRsnCode) {
3419 case LSRJT_UNABLE_TPC:
3420 /* The driver has a VALID PLOGI but the rport has
3421 * rejected the PRLI - can't do it now. Delay
3422 * for 1 second and try again - don't care about
3425 if (cmd == ELS_CMD_PRLI || cmd == ELS_CMD_NVMEPRLI) {
3427 maxretry = lpfc_max_els_tries + 1;
3432 /* Legacy bug fix code for targets with PLOGI delays. */
3433 if (stat.un.b.lsRjtRsnCodeExp ==
3434 LSEXP_CMD_IN_PROGRESS) {
3435 if (cmd == ELS_CMD_PLOGI) {
3442 if (stat.un.b.lsRjtRsnCodeExp ==
3443 LSEXP_CANT_GIVE_DATA) {
3444 if (cmd == ELS_CMD_PLOGI) {
3451 if (cmd == ELS_CMD_PLOGI) {
3453 maxretry = lpfc_max_els_tries + 1;
3457 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
3458 (cmd == ELS_CMD_FDISC) &&
3459 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
3460 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3461 "0125 FDISC Failed (x%x). "
3462 "Fabric out of resources\n",
3463 stat.un.lsRjtError);
3464 lpfc_vport_set_state(vport,
3465 FC_VPORT_NO_FABRIC_RSCS);
3469 case LSRJT_LOGICAL_BSY:
3470 if ((cmd == ELS_CMD_PLOGI) ||
3471 (cmd == ELS_CMD_PRLI) ||
3472 (cmd == ELS_CMD_NVMEPRLI)) {
3475 } else if (cmd == ELS_CMD_FDISC) {
3476 /* FDISC retry policy */
3478 if (cmdiocb->retry >= 32)
3484 case LSRJT_LOGICAL_ERR:
3485 /* There are some cases where switches return this
3486 * error when they are not ready and should be returning
3487 * Logical Busy. We should delay every time.
3489 if (cmd == ELS_CMD_FDISC &&
3490 stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
3494 } else if (cmd == ELS_CMD_FLOGI &&
3495 stat.un.b.lsRjtRsnCodeExp ==
3496 LSEXP_NOTHING_MORE) {
3497 vport->fc_sparam.cmn.bbRcvSizeMsb &= 0xf;
3499 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3500 "0820 FLOGI Failed (x%x). "
3501 "BBCredit Not Supported\n",
3502 stat.un.lsRjtError);
3506 case LSRJT_PROTOCOL_ERR:
3507 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
3508 (cmd == ELS_CMD_FDISC) &&
3509 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
3510 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
3512 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3513 "0122 FDISC Failed (x%x). "
3514 "Fabric Detected Bad WWN\n",
3515 stat.un.lsRjtError);
3516 lpfc_vport_set_state(vport,
3517 FC_VPORT_FABRIC_REJ_WWN);
3520 case LSRJT_VENDOR_UNIQUE:
3521 if ((stat.un.b.vendorUnique == 0x45) &&
3522 (cmd == ELS_CMD_FLOGI)) {
3526 case LSRJT_CMD_UNSUPPORTED:
3527 /* lpfc nvmet returns this type of LS_RJT when it
3528 * receives an FCP PRLI because lpfc nvmet only
3529 * support NVME. ELS request is terminated for FCP4
3532 if (stat.un.b.lsRjtRsnCodeExp ==
3533 LSEXP_REQ_UNSUPPORTED && cmd == ELS_CMD_PRLI) {
3534 spin_lock_irq(shost->host_lock);
3535 ndlp->nlp_flag |= NLP_FCP_PRLI_RJT;
3536 spin_unlock_irq(shost->host_lock);
3544 case IOSTAT_INTERMED_RSP:
3552 if (did == FDMI_DID)
3555 if ((cmd == ELS_CMD_FLOGI) &&
3556 (phba->fc_topology != LPFC_TOPOLOGY_LOOP) &&
3557 !lpfc_error_lost_link(irsp)) {
3558 /* FLOGI retry policy */
3560 /* retry FLOGI forever */
3561 if (phba->link_flag != LS_LOOPBACK_MODE)
3566 if (cmdiocb->retry >= 100)
3568 else if (cmdiocb->retry >= 32)
3570 } else if ((cmd == ELS_CMD_FDISC) && !lpfc_error_lost_link(irsp)) {
3571 /* retry FDISCs every second up to devloss */
3573 maxretry = vport->cfg_devloss_tmo;
3578 if (maxretry && (cmdiocb->retry >= maxretry)) {
3579 phba->fc_stat.elsRetryExceeded++;
3583 if ((vport->load_flag & FC_UNLOADING) != 0)
3588 if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) {
3589 /* Stop retrying PLOGI and FDISC if in FCF discovery */
3590 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
3591 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3592 "2849 Stop retry ELS command "
3593 "x%x to remote NPORT x%x, "
3594 "Data: x%x x%x\n", cmd, did,
3595 cmdiocb->retry, delay);
3600 /* Retry ELS command <elsCmd> to remote NPORT <did> */
3601 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3602 "0107 Retry ELS command x%x to remote "
3603 "NPORT x%x Data: x%x x%x\n",
3604 cmd, did, cmdiocb->retry, delay);
3606 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
3607 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
3608 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
3609 IOERR_NO_RESOURCES))) {
3610 /* Don't reset timer for no resources */
3612 /* If discovery / RSCN timer is running, reset it */
3613 if (timer_pending(&vport->fc_disctmo) ||
3614 (vport->fc_flag & FC_RSCN_MODE))
3615 lpfc_set_disctmo(vport);
3618 phba->fc_stat.elsXmitRetry++;
3619 if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) {
3620 phba->fc_stat.elsDelayRetry++;
3621 ndlp->nlp_retry = cmdiocb->retry;
3623 /* delay is specified in milliseconds */
3624 mod_timer(&ndlp->nlp_delayfunc,
3625 jiffies + msecs_to_jiffies(delay));
3626 spin_lock_irq(shost->host_lock);
3627 ndlp->nlp_flag |= NLP_DELAY_TMO;
3628 spin_unlock_irq(shost->host_lock);
3630 ndlp->nlp_prev_state = ndlp->nlp_state;
3631 if ((cmd == ELS_CMD_PRLI) ||
3632 (cmd == ELS_CMD_NVMEPRLI))
3633 lpfc_nlp_set_state(vport, ndlp,
3634 NLP_STE_PRLI_ISSUE);
3636 lpfc_nlp_set_state(vport, ndlp,
3638 ndlp->nlp_last_elscmd = cmd;
3644 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
3647 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
3650 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
3651 ndlp->nlp_prev_state = ndlp->nlp_state;
3652 lpfc_nlp_set_state(vport, ndlp,
3653 NLP_STE_PLOGI_ISSUE);
3655 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
3658 ndlp->nlp_prev_state = ndlp->nlp_state;
3659 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
3660 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
3663 case ELS_CMD_NVMEPRLI:
3664 ndlp->nlp_prev_state = ndlp->nlp_state;
3665 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
3666 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
3669 ndlp->nlp_prev_state = ndlp->nlp_state;
3670 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
3671 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
3675 /* No retry ELS command <elsCmd> to remote NPORT <did> */
3677 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3678 "0137 No retry ELS command x%x to remote "
3679 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
3680 cmd, did, irsp->ulpStatus,
3681 irsp->un.ulpWord[4]);
3684 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3685 "0108 No retry ELS command x%x to remote "
3686 "NPORT x%x Retried:%d Error:x%x/%x\n",
3687 cmd, did, cmdiocb->retry, irsp->ulpStatus,
3688 irsp->un.ulpWord[4]);
3694 * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
3695 * @phba: pointer to lpfc hba data structure.
3696 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
3698 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
3699 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
3700 * checks to see whether there is a lpfc DMA buffer associated with the
3701 * response of the command IOCB. If so, it will be released before releasing
3702 * the lpfc DMA buffer associated with the IOCB itself.
3705 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3708 lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
3710 struct lpfc_dmabuf *buf_ptr;
3712 /* Free the response before processing the command. */
3713 if (!list_empty(&buf_ptr1->list)) {
3714 list_remove_head(&buf_ptr1->list, buf_ptr,
3717 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3720 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
3726 * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
3727 * @phba: pointer to lpfc hba data structure.
3728 * @buf_ptr: pointer to the lpfc dma buffer data structure.
3730 * This routine releases the lpfc Direct Memory Access (DMA) buffer
3731 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
3735 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3738 lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
3740 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3746 * lpfc_els_free_iocb - Free a command iocb and its associated resources
3747 * @phba: pointer to lpfc hba data structure.
3748 * @elsiocb: pointer to lpfc els command iocb data structure.
3750 * This routine frees a command IOCB and its associated resources. The
3751 * command IOCB data structure contains the reference to various associated
3752 * resources, these fields must be set to NULL if the associated reference
3754 * context1 - reference to ndlp
3755 * context2 - reference to cmd
3756 * context2->next - reference to rsp
3757 * context3 - reference to bpl
3759 * It first properly decrements the reference count held on ndlp for the
3760 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
3761 * set, it invokes the lpfc_els_free_data() routine to release the Direct
3762 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
3763 * adds the DMA buffer the @phba data structure for the delayed release.
3764 * If reference to the Buffer Pointer List (BPL) is present, the
3765 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
3766 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
3767 * invoked to release the IOCB data structure back to @phba IOCBQ list.
3770 * 0 - Success (currently, always return 0)
3773 lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
3775 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
3776 struct lpfc_nodelist *ndlp;
3778 ndlp = (struct lpfc_nodelist *)elsiocb->context1;
3780 if (ndlp->nlp_flag & NLP_DEFER_RM) {
3783 /* If the ndlp is not being used by another discovery
3786 if (!lpfc_nlp_not_used(ndlp)) {
3787 /* If ndlp is being used by another discovery
3788 * thread, just clear NLP_DEFER_RM
3790 ndlp->nlp_flag &= ~NLP_DEFER_RM;
3795 elsiocb->context1 = NULL;
3797 /* context2 = cmd, context2->next = rsp, context3 = bpl */
3798 if (elsiocb->context2) {
3799 if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
3800 /* Firmware could still be in progress of DMAing
3801 * payload, so don't free data buffer till after
3804 elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
3805 buf_ptr = elsiocb->context2;
3806 elsiocb->context2 = NULL;
3809 spin_lock_irq(&phba->hbalock);
3810 if (!list_empty(&buf_ptr->list)) {
3811 list_remove_head(&buf_ptr->list,
3812 buf_ptr1, struct lpfc_dmabuf,
3814 INIT_LIST_HEAD(&buf_ptr1->list);
3815 list_add_tail(&buf_ptr1->list,
3819 INIT_LIST_HEAD(&buf_ptr->list);
3820 list_add_tail(&buf_ptr->list, &phba->elsbuf);
3822 spin_unlock_irq(&phba->hbalock);
3825 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
3826 lpfc_els_free_data(phba, buf_ptr1);
3827 elsiocb->context2 = NULL;
3831 if (elsiocb->context3) {
3832 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
3833 lpfc_els_free_bpl(phba, buf_ptr);
3834 elsiocb->context3 = NULL;
3836 lpfc_sli_release_iocbq(phba, elsiocb);
3841 * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
3842 * @phba: pointer to lpfc hba data structure.
3843 * @cmdiocb: pointer to lpfc command iocb data structure.
3844 * @rspiocb: pointer to lpfc response iocb data structure.
3846 * This routine is the completion callback function to the Logout (LOGO)
3847 * Accept (ACC) Response ELS command. This routine is invoked to indicate
3848 * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
3849 * release the ndlp if it has the last reference remaining (reference count
3850 * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
3851 * field to NULL to inform the following lpfc_els_free_iocb() routine no
3852 * ndlp reference count needs to be decremented. Otherwise, the ndlp
3853 * reference use-count shall be decremented by the lpfc_els_free_iocb()
3854 * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
3855 * IOCB data structure.
3858 lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3859 struct lpfc_iocbq *rspiocb)
3861 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3862 struct lpfc_vport *vport = cmdiocb->vport;
3865 irsp = &rspiocb->iocb;
3866 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3867 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
3868 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
3869 /* ACC to LOGO completes to NPort <nlp_DID> */
3870 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3871 "0109 ACC to LOGO completes to NPort x%x "
3872 "Data: x%x x%x x%x\n",
3873 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3876 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
3877 /* NPort Recovery mode or node is just allocated */
3878 if (!lpfc_nlp_not_used(ndlp)) {
3879 /* If the ndlp is being used by another discovery
3880 * thread, just unregister the RPI.
3882 lpfc_unreg_rpi(vport, ndlp);
3884 /* Indicate the node has already released, should
3885 * not reference to it from within lpfc_els_free_iocb.
3887 cmdiocb->context1 = NULL;
3892 * The driver received a LOGO from the rport and has ACK'd it.
3893 * At this point, the driver is done so release the IOCB
3895 lpfc_els_free_iocb(phba, cmdiocb);
3899 * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
3900 * @phba: pointer to lpfc hba data structure.
3901 * @pmb: pointer to the driver internal queue element for mailbox command.
3903 * This routine is the completion callback function for unregister default
3904 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
3905 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
3906 * decrements the ndlp reference count held for this completion callback
3907 * function. After that, it invokes the lpfc_nlp_not_used() to check
3908 * whether there is only one reference left on the ndlp. If so, it will
3909 * perform one more decrement and trigger the release of the ndlp.
3912 lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3914 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
3915 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
3917 pmb->context1 = NULL;
3918 pmb->context2 = NULL;
3920 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3922 mempool_free(pmb, phba->mbox_mem_pool);
3924 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
3925 "0006 rpi%x DID:%x flg:%x %d map:%x %p\n",
3926 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
3927 kref_read(&ndlp->kref),
3928 ndlp->nlp_usg_map, ndlp);
3929 if (NLP_CHK_NODE_ACT(ndlp)) {
3931 /* This is the end of the default RPI cleanup logic for
3932 * this ndlp. If no other discovery threads are using
3933 * this ndlp, free all resources associated with it.
3935 lpfc_nlp_not_used(ndlp);
3937 lpfc_drop_node(ndlp->vport, ndlp);
3945 * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
3946 * @phba: pointer to lpfc hba data structure.
3947 * @cmdiocb: pointer to lpfc command iocb data structure.
3948 * @rspiocb: pointer to lpfc response iocb data structure.
3950 * This routine is the completion callback function for ELS Response IOCB
3951 * command. In normal case, this callback function just properly sets the
3952 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
3953 * field in the command IOCB is not NULL, the referred mailbox command will
3954 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
3955 * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
3956 * link down event occurred during the discovery, the lpfc_nlp_not_used()
3957 * routine shall be invoked trying to release the ndlp if no other threads
3958 * are currently referring it.
3961 lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3962 struct lpfc_iocbq *rspiocb)
3964 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3965 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
3966 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
3969 LPFC_MBOXQ_t *mbox = NULL;
3970 struct lpfc_dmabuf *mp = NULL;
3971 uint32_t ls_rjt = 0;
3973 irsp = &rspiocb->iocb;
3975 if (cmdiocb->context_un.mbox)
3976 mbox = cmdiocb->context_un.mbox;
3978 /* First determine if this is a LS_RJT cmpl. Note, this callback
3979 * function can have cmdiocb->contest1 (ndlp) field set to NULL.
3981 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
3982 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3983 (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) {
3984 /* A LS_RJT associated with Default RPI cleanup has its own
3985 * separate code path.
3987 if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
3991 /* Check to see if link went down during discovery */
3992 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) {
3994 mp = (struct lpfc_dmabuf *) mbox->context1;
3996 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3999 mempool_free(mbox, phba->mbox_mem_pool);
4001 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
4002 (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
4003 if (lpfc_nlp_not_used(ndlp)) {
4005 /* Indicate the node has already released,
4006 * should not reference to it from within
4007 * the routine lpfc_els_free_iocb.
4009 cmdiocb->context1 = NULL;
4014 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4015 "ELS rsp cmpl: status:x%x/x%x did:x%x",
4016 irsp->ulpStatus, irsp->un.ulpWord[4],
4017 cmdiocb->iocb.un.elsreq64.remoteID);
4018 /* ELS response tag <ulpIoTag> completes */
4019 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4020 "0110 ELS response tag x%x completes "
4021 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
4022 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
4023 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
4024 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4027 if ((rspiocb->iocb.ulpStatus == 0)
4028 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
4029 if (!lpfc_unreg_rpi(vport, ndlp) &&
4030 (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
4031 ndlp->nlp_state == NLP_STE_REG_LOGIN_ISSUE)) {
4032 lpfc_printf_vlog(vport, KERN_INFO,
4034 "0314 PLOGI recov DID x%x "
4035 "Data: x%x x%x x%x\n",
4036 ndlp->nlp_DID, ndlp->nlp_state,
4037 ndlp->nlp_rpi, ndlp->nlp_flag);
4038 mp = mbox->context1;
4040 lpfc_mbuf_free(phba, mp->virt,
4044 mempool_free(mbox, phba->mbox_mem_pool);
4048 /* Increment reference count to ndlp to hold the
4049 * reference to ndlp for the callback function.
4051 mbox->context2 = lpfc_nlp_get(ndlp);
4052 mbox->vport = vport;
4053 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
4054 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
4055 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
4058 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
4059 ndlp->nlp_prev_state = ndlp->nlp_state;
4060 lpfc_nlp_set_state(vport, ndlp,
4061 NLP_STE_REG_LOGIN_ISSUE);
4064 ndlp->nlp_flag |= NLP_REG_LOGIN_SEND;
4065 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
4066 != MBX_NOT_FINISHED)
4069 /* Decrement the ndlp reference count we
4070 * set for this failed mailbox command.
4073 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
4075 /* ELS rsp: Cannot issue reg_login for <NPortid> */
4076 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4077 "0138 ELS rsp: Cannot issue reg_login for x%x "
4078 "Data: x%x x%x x%x\n",
4079 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4082 if (lpfc_nlp_not_used(ndlp)) {
4084 /* Indicate node has already been released,
4085 * should not reference to it from within
4086 * the routine lpfc_els_free_iocb.
4088 cmdiocb->context1 = NULL;
4091 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
4092 if (!lpfc_error_lost_link(irsp) &&
4093 ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
4094 if (lpfc_nlp_not_used(ndlp)) {
4096 /* Indicate node has already been
4097 * released, should not reference
4098 * to it from within the routine
4099 * lpfc_els_free_iocb.
4101 cmdiocb->context1 = NULL;
4105 mp = (struct lpfc_dmabuf *) mbox->context1;
4107 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4110 mempool_free(mbox, phba->mbox_mem_pool);
4113 if (ndlp && NLP_CHK_NODE_ACT(ndlp) && shost) {
4114 spin_lock_irq(shost->host_lock);
4115 ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI);
4116 spin_unlock_irq(shost->host_lock);
4118 /* If the node is not being used by another discovery thread,
4119 * and we are sending a reject, we are done with it.
4120 * Release driver reference count here and free associated
4124 if (lpfc_nlp_not_used(ndlp))
4125 /* Indicate node has already been released,
4126 * should not reference to it from within
4127 * the routine lpfc_els_free_iocb.
4129 cmdiocb->context1 = NULL;
4133 lpfc_els_free_iocb(phba, cmdiocb);
4138 * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
4139 * @vport: pointer to a host virtual N_Port data structure.
4140 * @flag: the els command code to be accepted.
4141 * @oldiocb: pointer to the original lpfc command iocb data structure.
4142 * @ndlp: pointer to a node-list data structure.
4143 * @mbox: pointer to the driver internal queue element for mailbox command.
4145 * This routine prepares and issues an Accept (ACC) response IOCB
4146 * command. It uses the @flag to properly set up the IOCB field for the
4147 * specific ACC response command to be issued and invokes the
4148 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
4149 * @mbox pointer is passed in, it will be put into the context_un.mbox
4150 * field of the IOCB for the completion callback function to issue the
4151 * mailbox command to the HBA later when callback is invoked.
4153 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4154 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4155 * will be stored into the context1 field of the IOCB for the completion
4156 * callback function to the corresponding response ELS IOCB command.
4159 * 0 - Successfully issued acc response
4160 * 1 - Failed to issue acc response
4163 lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
4164 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
4167 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4168 struct lpfc_hba *phba = vport->phba;
4171 struct lpfc_iocbq *elsiocb;
4173 struct serv_parm *sp;
4176 ELS_PKT *els_pkt_ptr;
4178 oldcmd = &oldiocb->iocb;
4182 cmdsize = sizeof(uint32_t);
4183 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
4184 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
4186 spin_lock_irq(shost->host_lock);
4187 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
4188 spin_unlock_irq(shost->host_lock);
4192 icmd = &elsiocb->iocb;
4193 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4194 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4195 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4196 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4197 pcmd += sizeof(uint32_t);
4199 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4200 "Issue ACC: did:x%x flg:x%x",
4201 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4205 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
4206 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
4207 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
4211 icmd = &elsiocb->iocb;
4212 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4213 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4214 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4217 elsiocb->context_un.mbox = mbox;
4219 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4220 pcmd += sizeof(uint32_t);
4221 sp = (struct serv_parm *)pcmd;
4223 if (flag == ELS_CMD_FLOGI) {
4224 /* Copy the received service parameters back */
4225 memcpy(sp, &phba->fc_fabparam,
4226 sizeof(struct serv_parm));
4228 /* Clear the F_Port bit */
4231 /* Mark all class service parameters as invalid */
4232 sp->cls1.classValid = 0;
4233 sp->cls2.classValid = 0;
4234 sp->cls3.classValid = 0;
4235 sp->cls4.classValid = 0;
4237 /* Copy our worldwide names */
4238 memcpy(&sp->portName, &vport->fc_sparam.portName,
4239 sizeof(struct lpfc_name));
4240 memcpy(&sp->nodeName, &vport->fc_sparam.nodeName,
4241 sizeof(struct lpfc_name));
4243 memcpy(pcmd, &vport->fc_sparam,
4244 sizeof(struct serv_parm));
4246 sp->cmn.valid_vendor_ver_level = 0;
4247 memset(sp->un.vendorVersion, 0,
4248 sizeof(sp->un.vendorVersion));
4249 sp->cmn.bbRcvSizeMsb &= 0xF;
4251 /* If our firmware supports this feature, convey that
4252 * info to the target using the vendor specific field.
4254 if (phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) {
4255 sp->cmn.valid_vendor_ver_level = 1;
4256 sp->un.vv.vid = cpu_to_be32(LPFC_VV_EMLX_ID);
4258 cpu_to_be32(LPFC_VV_SUPPRESS_RSP);
4262 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4263 "Issue ACC FLOGI/PLOGI: did:x%x flg:x%x",
4264 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4267 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
4268 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
4269 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
4273 icmd = &elsiocb->iocb;
4274 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4275 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4276 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4278 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
4279 sizeof(uint32_t) + sizeof(PRLO));
4280 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
4281 els_pkt_ptr = (ELS_PKT *) pcmd;
4282 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
4284 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4285 "Issue ACC PRLO: did:x%x flg:x%x",
4286 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4291 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
4292 spin_lock_irq(shost->host_lock);
4293 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED ||
4294 ndlp->nlp_flag & NLP_REG_LOGIN_SEND))
4295 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
4296 spin_unlock_irq(shost->host_lock);
4297 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
4299 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4302 phba->fc_stat.elsXmitACC++;
4303 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4304 if (rc == IOCB_ERROR) {
4305 lpfc_els_free_iocb(phba, elsiocb);
4312 * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command
4313 * @vport: pointer to a virtual N_Port data structure.
4315 * @oldiocb: pointer to the original lpfc command iocb data structure.
4316 * @ndlp: pointer to a node-list data structure.
4317 * @mbox: pointer to the driver internal queue element for mailbox command.
4319 * This routine prepares and issue an Reject (RJT) response IOCB
4320 * command. If a @mbox pointer is passed in, it will be put into the
4321 * context_un.mbox field of the IOCB for the completion callback function
4322 * to issue to the HBA later.
4324 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4325 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4326 * will be stored into the context1 field of the IOCB for the completion
4327 * callback function to the reject response ELS IOCB command.
4330 * 0 - Successfully issued reject response
4331 * 1 - Failed to issue reject response
4334 lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
4335 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
4338 struct lpfc_hba *phba = vport->phba;
4341 struct lpfc_iocbq *elsiocb;
4346 cmdsize = 2 * sizeof(uint32_t);
4347 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4348 ndlp->nlp_DID, ELS_CMD_LS_RJT);
4352 icmd = &elsiocb->iocb;
4353 oldcmd = &oldiocb->iocb;
4354 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4355 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4356 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4358 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
4359 pcmd += sizeof(uint32_t);
4360 *((uint32_t *) (pcmd)) = rejectError;
4363 elsiocb->context_un.mbox = mbox;
4365 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
4366 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4367 "0129 Xmit ELS RJT x%x response tag x%x "
4368 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
4370 rejectError, elsiocb->iotag,
4371 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
4372 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
4373 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4374 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
4375 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
4377 phba->fc_stat.elsXmitLSRJT++;
4378 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4379 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4381 if (rc == IOCB_ERROR) {
4382 lpfc_els_free_iocb(phba, elsiocb);
4389 * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
4390 * @vport: pointer to a virtual N_Port data structure.
4391 * @oldiocb: pointer to the original lpfc command iocb data structure.
4392 * @ndlp: pointer to a node-list data structure.
4394 * This routine prepares and issues an Accept (ACC) response to Address
4395 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
4396 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
4398 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4399 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4400 * will be stored into the context1 field of the IOCB for the completion
4401 * callback function to the ADISC Accept response ELS IOCB command.
4404 * 0 - Successfully issued acc adisc response
4405 * 1 - Failed to issue adisc acc response
4408 lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
4409 struct lpfc_nodelist *ndlp)
4411 struct lpfc_hba *phba = vport->phba;
4413 IOCB_t *icmd, *oldcmd;
4414 struct lpfc_iocbq *elsiocb;
4419 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
4420 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4421 ndlp->nlp_DID, ELS_CMD_ACC);
4425 icmd = &elsiocb->iocb;
4426 oldcmd = &oldiocb->iocb;
4427 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4428 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4430 /* Xmit ADISC ACC response tag <ulpIoTag> */
4431 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4432 "0130 Xmit ADISC ACC response iotag x%x xri: "
4433 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
4434 elsiocb->iotag, elsiocb->iocb.ulpContext,
4435 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4437 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4439 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4440 pcmd += sizeof(uint32_t);
4442 ap = (ADISC *) (pcmd);
4443 ap->hardAL_PA = phba->fc_pref_ALPA;
4444 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
4445 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
4446 ap->DID = be32_to_cpu(vport->fc_myDID);
4448 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4449 "Issue ACC ADISC: did:x%x flg:x%x",
4450 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4452 phba->fc_stat.elsXmitACC++;
4453 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4454 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4455 if (rc == IOCB_ERROR) {
4456 lpfc_els_free_iocb(phba, elsiocb);
4460 /* Xmit ELS ACC response tag <ulpIoTag> */
4461 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4462 "0128 Xmit ELS ACC response Status: x%x, IoTag: x%x, "
4463 "XRI: x%x, DID: x%x, nlp_flag: x%x nlp_state: x%x "
4464 "RPI: x%x, fc_flag x%x\n",
4465 rc, elsiocb->iotag, elsiocb->sli4_xritag,
4466 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4467 ndlp->nlp_rpi, vport->fc_flag);
4472 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
4473 * @vport: pointer to a virtual N_Port data structure.
4474 * @oldiocb: pointer to the original lpfc command iocb data structure.
4475 * @ndlp: pointer to a node-list data structure.
4477 * This routine prepares and issues an Accept (ACC) response to Process
4478 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
4479 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
4481 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4482 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4483 * will be stored into the context1 field of the IOCB for the completion
4484 * callback function to the PRLI Accept response ELS IOCB command.
4487 * 0 - Successfully issued acc prli response
4488 * 1 - Failed to issue acc prli response
4491 lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
4492 struct lpfc_nodelist *ndlp)
4494 struct lpfc_hba *phba = vport->phba;
4496 struct lpfc_nvme_prli *npr_nvme;
4500 struct lpfc_iocbq *elsiocb;
4503 uint32_t prli_fc4_req, *req_payload;
4504 struct lpfc_dmabuf *req_buf;
4508 /* Need the incoming PRLI payload to determine if the ACC is for an
4509 * FC4 or NVME PRLI type. The PRLI type is at word 1.
4511 req_buf = (struct lpfc_dmabuf *)oldiocb->context2;
4512 req_payload = (((uint32_t *)req_buf->virt) + 1);
4514 /* PRLI type payload is at byte 3 for FCP or NVME. */
4515 prli_fc4_req = be32_to_cpu(*req_payload);
4516 prli_fc4_req = (prli_fc4_req >> 24) & 0xff;
4517 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4518 "6127 PRLI_ACC: Req Type x%x, Word1 x%08x\n",
4519 prli_fc4_req, *((uint32_t *)req_payload));
4521 if (prli_fc4_req == PRLI_FCP_TYPE) {
4522 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
4523 elsrspcmd = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
4524 } else if (prli_fc4_req & PRLI_NVME_TYPE) {
4525 cmdsize = sizeof(uint32_t) + sizeof(struct lpfc_nvme_prli);
4526 elsrspcmd = (ELS_CMD_ACC | (ELS_CMD_NVMEPRLI & ~ELS_RSP_MASK));
4531 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4532 ndlp->nlp_DID, elsrspcmd);
4536 icmd = &elsiocb->iocb;
4537 oldcmd = &oldiocb->iocb;
4538 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4539 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4541 /* Xmit PRLI ACC response tag <ulpIoTag> */
4542 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4543 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
4544 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
4545 elsiocb->iotag, elsiocb->iocb.ulpContext,
4546 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4548 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4549 memset(pcmd, 0, cmdsize);
4551 *((uint32_t *)(pcmd)) = elsrspcmd;
4552 pcmd += sizeof(uint32_t);
4554 /* For PRLI, remainder of payload is PRLI parameter page */
4557 if (prli_fc4_req == PRLI_FCP_TYPE) {
4559 * If the remote port is a target and our firmware version
4560 * is 3.20 or later, set the following bits for FC-TAPE
4563 npr = (PRLI *) pcmd;
4564 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
4565 (vpd->rev.feaLevelHigh >= 0x02)) {
4566 npr->ConfmComplAllowed = 1;
4568 npr->TaskRetryIdReq = 1;
4570 npr->acceptRspCode = PRLI_REQ_EXECUTED;
4571 npr->estabImagePair = 1;
4572 npr->readXferRdyDis = 1;
4573 npr->ConfmComplAllowed = 1;
4574 npr->prliType = PRLI_FCP_TYPE;
4575 npr->initiatorFunc = 1;
4576 } else if (prli_fc4_req & PRLI_NVME_TYPE) {
4577 /* Respond with an NVME PRLI Type */
4578 npr_nvme = (struct lpfc_nvme_prli *) pcmd;
4579 bf_set(prli_type_code, npr_nvme, PRLI_NVME_TYPE);
4580 bf_set(prli_estabImagePair, npr_nvme, 0); /* Should be 0 */
4581 bf_set(prli_acc_rsp_code, npr_nvme, PRLI_REQ_EXECUTED);
4582 if (phba->nvmet_support) {
4583 bf_set(prli_tgt, npr_nvme, 1);
4584 bf_set(prli_disc, npr_nvme, 1);
4585 if (phba->cfg_nvme_enable_fb) {
4586 bf_set(prli_fba, npr_nvme, 1);
4588 /* TBD. Target mode needs to post buffers
4589 * that support the configured first burst
4592 bf_set(prli_fb_sz, npr_nvme,
4593 phba->cfg_nvmet_fb_size);
4596 bf_set(prli_init, npr_nvme, 1);
4599 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
4600 "6015 NVME issue PRLI ACC word1 x%08x "
4601 "word4 x%08x word5 x%08x flag x%x, "
4602 "fcp_info x%x nlp_type x%x\n",
4603 npr_nvme->word1, npr_nvme->word4,
4604 npr_nvme->word5, ndlp->nlp_flag,
4605 ndlp->nlp_fcp_info, ndlp->nlp_type);
4606 npr_nvme->word1 = cpu_to_be32(npr_nvme->word1);
4607 npr_nvme->word4 = cpu_to_be32(npr_nvme->word4);
4608 npr_nvme->word5 = cpu_to_be32(npr_nvme->word5);
4610 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4611 "6128 Unknown FC_TYPE x%x x%x ndlp x%06x\n",
4612 prli_fc4_req, ndlp->nlp_fc4_type,
4615 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4616 "Issue ACC PRLI: did:x%x flg:x%x",
4617 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4619 phba->fc_stat.elsXmitACC++;
4620 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4622 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4623 if (rc == IOCB_ERROR) {
4624 lpfc_els_free_iocb(phba, elsiocb);
4631 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
4632 * @vport: pointer to a virtual N_Port data structure.
4633 * @format: rnid command format.
4634 * @oldiocb: pointer to the original lpfc command iocb data structure.
4635 * @ndlp: pointer to a node-list data structure.
4637 * This routine issues a Request Node Identification Data (RNID) Accept
4638 * (ACC) response. It constructs the RNID ACC response command according to
4639 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
4640 * issue the response. Note that this command does not need to hold the ndlp
4641 * reference count for the callback. So, the ndlp reference count taken by
4642 * the lpfc_prep_els_iocb() routine is put back and the context1 field of
4643 * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
4644 * there is no ndlp reference available.
4646 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4647 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4648 * will be stored into the context1 field of the IOCB for the completion
4649 * callback function. However, for the RNID Accept Response ELS command,
4650 * this is undone later by this routine after the IOCB is allocated.
4653 * 0 - Successfully issued acc rnid response
4654 * 1 - Failed to issue acc rnid response
4657 lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
4658 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
4660 struct lpfc_hba *phba = vport->phba;
4662 IOCB_t *icmd, *oldcmd;
4663 struct lpfc_iocbq *elsiocb;
4668 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
4669 + (2 * sizeof(struct lpfc_name));
4671 cmdsize += sizeof(RNID_TOP_DISC);
4673 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4674 ndlp->nlp_DID, ELS_CMD_ACC);
4678 icmd = &elsiocb->iocb;
4679 oldcmd = &oldiocb->iocb;
4680 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4681 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4683 /* Xmit RNID ACC response tag <ulpIoTag> */
4684 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4685 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
4686 elsiocb->iotag, elsiocb->iocb.ulpContext);
4687 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4688 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4689 pcmd += sizeof(uint32_t);
4691 memset(pcmd, 0, sizeof(RNID));
4692 rn = (RNID *) (pcmd);
4693 rn->Format = format;
4694 rn->CommonLen = (2 * sizeof(struct lpfc_name));
4695 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
4696 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
4699 rn->SpecificLen = 0;
4701 case RNID_TOPOLOGY_DISC:
4702 rn->SpecificLen = sizeof(RNID_TOP_DISC);
4703 memcpy(&rn->un.topologyDisc.portName,
4704 &vport->fc_portname, sizeof(struct lpfc_name));
4705 rn->un.topologyDisc.unitType = RNID_HBA;
4706 rn->un.topologyDisc.physPort = 0;
4707 rn->un.topologyDisc.attachedNodes = 0;
4711 rn->SpecificLen = 0;
4715 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4716 "Issue ACC RNID: did:x%x flg:x%x",
4717 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4719 phba->fc_stat.elsXmitACC++;
4720 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4722 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4723 if (rc == IOCB_ERROR) {
4724 lpfc_els_free_iocb(phba, elsiocb);
4731 * lpfc_els_clear_rrq - Clear the rq that this rrq describes.
4732 * @vport: pointer to a virtual N_Port data structure.
4733 * @iocb: pointer to the lpfc command iocb data structure.
4734 * @ndlp: pointer to a node-list data structure.
4739 lpfc_els_clear_rrq(struct lpfc_vport *vport,
4740 struct lpfc_iocbq *iocb, struct lpfc_nodelist *ndlp)
4742 struct lpfc_hba *phba = vport->phba;
4747 struct lpfc_node_rrq *prrq;
4750 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) iocb->context2)->virt);
4751 pcmd += sizeof(uint32_t);
4752 rrq = (struct RRQ *)pcmd;
4753 rrq->rrq_exchg = be32_to_cpu(rrq->rrq_exchg);
4754 rxid = bf_get(rrq_rxid, rrq);
4756 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4757 "2883 Clear RRQ for SID:x%x OXID:x%x RXID:x%x"
4759 be32_to_cpu(bf_get(rrq_did, rrq)),
4760 bf_get(rrq_oxid, rrq),
4762 iocb->iotag, iocb->iocb.ulpContext);
4764 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4765 "Clear RRQ: did:x%x flg:x%x exchg:x%.08x",
4766 ndlp->nlp_DID, ndlp->nlp_flag, rrq->rrq_exchg);
4767 if (vport->fc_myDID == be32_to_cpu(bf_get(rrq_did, rrq)))
4768 xri = bf_get(rrq_oxid, rrq);
4771 prrq = lpfc_get_active_rrq(vport, xri, ndlp->nlp_DID);
4773 lpfc_clr_rrq_active(phba, xri, prrq);
4778 * lpfc_els_rsp_echo_acc - Issue echo acc response
4779 * @vport: pointer to a virtual N_Port data structure.
4780 * @data: pointer to echo data to return in the accept.
4781 * @oldiocb: pointer to the original lpfc command iocb data structure.
4782 * @ndlp: pointer to a node-list data structure.
4785 * 0 - Successfully issued acc echo response
4786 * 1 - Failed to issue acc echo response
4789 lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data,
4790 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
4792 struct lpfc_hba *phba = vport->phba;
4793 struct lpfc_iocbq *elsiocb;
4798 cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len;
4800 /* The accumulated length can exceed the BPL_SIZE. For
4801 * now, use this as the limit
4803 if (cmdsize > LPFC_BPL_SIZE)
4804 cmdsize = LPFC_BPL_SIZE;
4805 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4806 ndlp->nlp_DID, ELS_CMD_ACC);
4810 elsiocb->iocb.ulpContext = oldiocb->iocb.ulpContext; /* Xri / rx_id */
4811 elsiocb->iocb.unsli3.rcvsli3.ox_id = oldiocb->iocb.unsli3.rcvsli3.ox_id;
4813 /* Xmit ECHO ACC response tag <ulpIoTag> */
4814 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4815 "2876 Xmit ECHO ACC response tag x%x xri x%x\n",
4816 elsiocb->iotag, elsiocb->iocb.ulpContext);
4817 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4818 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4819 pcmd += sizeof(uint32_t);
4820 memcpy(pcmd, data, cmdsize - sizeof(uint32_t));
4822 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4823 "Issue ACC ECHO: did:x%x flg:x%x",
4824 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4826 phba->fc_stat.elsXmitACC++;
4827 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4829 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4830 if (rc == IOCB_ERROR) {
4831 lpfc_els_free_iocb(phba, elsiocb);
4838 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
4839 * @vport: pointer to a host virtual N_Port data structure.
4841 * This routine issues Address Discover (ADISC) ELS commands to those
4842 * N_Ports which are in node port recovery state and ADISC has not been issued
4843 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
4844 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
4845 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
4846 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
4847 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
4848 * IOCBs quit for later pick up. On the other hand, after walking through
4849 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
4850 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
4851 * no more ADISC need to be sent.
4854 * The number of N_Ports with adisc issued.
4857 lpfc_els_disc_adisc(struct lpfc_vport *vport)
4859 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4860 struct lpfc_nodelist *ndlp, *next_ndlp;
4863 /* go thru NPR nodes and issue any remaining ELS ADISCs */
4864 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
4865 if (!NLP_CHK_NODE_ACT(ndlp))
4867 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
4868 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
4869 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
4870 spin_lock_irq(shost->host_lock);
4871 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
4872 spin_unlock_irq(shost->host_lock);
4873 ndlp->nlp_prev_state = ndlp->nlp_state;
4874 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
4875 lpfc_issue_els_adisc(vport, ndlp, 0);
4877 vport->num_disc_nodes++;
4878 if (vport->num_disc_nodes >=
4879 vport->cfg_discovery_threads) {
4880 spin_lock_irq(shost->host_lock);
4881 vport->fc_flag |= FC_NLP_MORE;
4882 spin_unlock_irq(shost->host_lock);
4887 if (sentadisc == 0) {
4888 spin_lock_irq(shost->host_lock);
4889 vport->fc_flag &= ~FC_NLP_MORE;
4890 spin_unlock_irq(shost->host_lock);
4896 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
4897 * @vport: pointer to a host virtual N_Port data structure.
4899 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
4900 * which are in node port recovery state, with a @vport. Each time an ELS
4901 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
4902 * the per @vport number of discover count (num_disc_nodes) shall be
4903 * incremented. If the num_disc_nodes reaches a pre-configured threshold
4904 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
4905 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
4906 * later pick up. On the other hand, after walking through all the ndlps with
4907 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
4908 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
4909 * PLOGI need to be sent.
4912 * The number of N_Ports with plogi issued.
4915 lpfc_els_disc_plogi(struct lpfc_vport *vport)
4917 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4918 struct lpfc_nodelist *ndlp, *next_ndlp;
4921 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
4922 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
4923 if (!NLP_CHK_NODE_ACT(ndlp))
4925 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
4926 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
4927 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
4928 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
4929 ndlp->nlp_prev_state = ndlp->nlp_state;
4930 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
4931 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
4933 vport->num_disc_nodes++;
4934 if (vport->num_disc_nodes >=
4935 vport->cfg_discovery_threads) {
4936 spin_lock_irq(shost->host_lock);
4937 vport->fc_flag |= FC_NLP_MORE;
4938 spin_unlock_irq(shost->host_lock);
4944 lpfc_set_disctmo(vport);
4947 spin_lock_irq(shost->host_lock);
4948 vport->fc_flag &= ~FC_NLP_MORE;
4949 spin_unlock_irq(shost->host_lock);
4955 lpfc_rdp_res_link_service(struct fc_rdp_link_service_desc *desc,
4959 desc->tag = cpu_to_be32(RDP_LINK_SERVICE_DESC_TAG);
4960 desc->payload.els_req = word0;
4961 desc->length = cpu_to_be32(sizeof(desc->payload));
4963 return sizeof(struct fc_rdp_link_service_desc);
4967 lpfc_rdp_res_sfp_desc(struct fc_rdp_sfp_desc *desc,
4968 uint8_t *page_a0, uint8_t *page_a2)
4970 uint16_t wavelength;
4971 uint16_t temperature;
4977 struct sff_trasnceiver_codes_byte4 *trasn_code_byte4;
4978 struct sff_trasnceiver_codes_byte5 *trasn_code_byte5;
4980 desc->tag = cpu_to_be32(RDP_SFP_DESC_TAG);
4982 trasn_code_byte4 = (struct sff_trasnceiver_codes_byte4 *)
4983 &page_a0[SSF_TRANSCEIVER_CODE_B4];
4984 trasn_code_byte5 = (struct sff_trasnceiver_codes_byte5 *)
4985 &page_a0[SSF_TRANSCEIVER_CODE_B5];
4987 if ((trasn_code_byte4->fc_sw_laser) ||
4988 (trasn_code_byte5->fc_sw_laser_sl) ||
4989 (trasn_code_byte5->fc_sw_laser_sn)) { /* check if its short WL */
4990 flag |= (SFP_FLAG_PT_SWLASER << SFP_FLAG_PT_SHIFT);
4991 } else if (trasn_code_byte4->fc_lw_laser) {
4992 wavelength = (page_a0[SSF_WAVELENGTH_B1] << 8) |
4993 page_a0[SSF_WAVELENGTH_B0];
4994 if (wavelength == SFP_WAVELENGTH_LC1310)
4995 flag |= SFP_FLAG_PT_LWLASER_LC1310 << SFP_FLAG_PT_SHIFT;
4996 if (wavelength == SFP_WAVELENGTH_LL1550)
4997 flag |= SFP_FLAG_PT_LWLASER_LL1550 << SFP_FLAG_PT_SHIFT;
4999 /* check if its SFP+ */
5000 flag |= ((page_a0[SSF_IDENTIFIER] == SFF_PG0_IDENT_SFP) ?
5001 SFP_FLAG_CT_SFP_PLUS : SFP_FLAG_CT_UNKNOWN)
5002 << SFP_FLAG_CT_SHIFT;
5004 /* check if its OPTICAL */
5005 flag |= ((page_a0[SSF_CONNECTOR] == SFF_PG0_CONNECTOR_LC) ?
5006 SFP_FLAG_IS_OPTICAL_PORT : 0)
5007 << SFP_FLAG_IS_OPTICAL_SHIFT;
5009 temperature = (page_a2[SFF_TEMPERATURE_B1] << 8 |
5010 page_a2[SFF_TEMPERATURE_B0]);
5011 vcc = (page_a2[SFF_VCC_B1] << 8 |
5012 page_a2[SFF_VCC_B0]);
5013 tx_power = (page_a2[SFF_TXPOWER_B1] << 8 |
5014 page_a2[SFF_TXPOWER_B0]);
5015 tx_bias = (page_a2[SFF_TX_BIAS_CURRENT_B1] << 8 |
5016 page_a2[SFF_TX_BIAS_CURRENT_B0]);
5017 rx_power = (page_a2[SFF_RXPOWER_B1] << 8 |
5018 page_a2[SFF_RXPOWER_B0]);
5019 desc->sfp_info.temperature = cpu_to_be16(temperature);
5020 desc->sfp_info.rx_power = cpu_to_be16(rx_power);
5021 desc->sfp_info.tx_bias = cpu_to_be16(tx_bias);
5022 desc->sfp_info.tx_power = cpu_to_be16(tx_power);
5023 desc->sfp_info.vcc = cpu_to_be16(vcc);
5025 desc->sfp_info.flags = cpu_to_be16(flag);
5026 desc->length = cpu_to_be32(sizeof(desc->sfp_info));
5028 return sizeof(struct fc_rdp_sfp_desc);
5032 lpfc_rdp_res_link_error(struct fc_rdp_link_error_status_desc *desc,
5037 desc->tag = cpu_to_be32(RDP_LINK_ERROR_STATUS_DESC_TAG);
5039 type = VN_PT_PHY_PF_PORT << VN_PT_PHY_SHIFT;
5041 desc->info.port_type = cpu_to_be32(type);
5043 desc->info.link_status.link_failure_cnt =
5044 cpu_to_be32(stat->linkFailureCnt);
5045 desc->info.link_status.loss_of_synch_cnt =
5046 cpu_to_be32(stat->lossSyncCnt);
5047 desc->info.link_status.loss_of_signal_cnt =
5048 cpu_to_be32(stat->lossSignalCnt);
5049 desc->info.link_status.primitive_seq_proto_err =
5050 cpu_to_be32(stat->primSeqErrCnt);
5051 desc->info.link_status.invalid_trans_word =
5052 cpu_to_be32(stat->invalidXmitWord);
5053 desc->info.link_status.invalid_crc_cnt = cpu_to_be32(stat->crcCnt);
5055 desc->length = cpu_to_be32(sizeof(desc->info));
5057 return sizeof(struct fc_rdp_link_error_status_desc);
5061 lpfc_rdp_res_bbc_desc(struct fc_rdp_bbc_desc *desc, READ_LNK_VAR *stat,
5062 struct lpfc_vport *vport)
5066 desc->tag = cpu_to_be32(RDP_BBC_DESC_TAG);
5068 bbCredit = vport->fc_sparam.cmn.bbCreditLsb |
5069 (vport->fc_sparam.cmn.bbCreditMsb << 8);
5070 desc->bbc_info.port_bbc = cpu_to_be32(bbCredit);
5071 if (vport->phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
5072 bbCredit = vport->phba->fc_fabparam.cmn.bbCreditLsb |
5073 (vport->phba->fc_fabparam.cmn.bbCreditMsb << 8);
5074 desc->bbc_info.attached_port_bbc = cpu_to_be32(bbCredit);
5076 desc->bbc_info.attached_port_bbc = 0;
5079 desc->bbc_info.rtt = 0;
5080 desc->length = cpu_to_be32(sizeof(desc->bbc_info));
5082 return sizeof(struct fc_rdp_bbc_desc);
5086 lpfc_rdp_res_oed_temp_desc(struct lpfc_hba *phba,
5087 struct fc_rdp_oed_sfp_desc *desc, uint8_t *page_a2)
5091 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5093 desc->oed_info.hi_alarm = page_a2[SSF_TEMP_HIGH_ALARM];
5094 desc->oed_info.lo_alarm = page_a2[SSF_TEMP_LOW_ALARM];
5095 desc->oed_info.hi_warning = page_a2[SSF_TEMP_HIGH_WARNING];
5096 desc->oed_info.lo_warning = page_a2[SSF_TEMP_LOW_WARNING];
5098 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TEMPERATURE)
5099 flags |= RDP_OET_HIGH_ALARM;
5100 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TEMPERATURE)
5101 flags |= RDP_OET_LOW_ALARM;
5102 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TEMPERATURE)
5103 flags |= RDP_OET_HIGH_WARNING;
5104 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TEMPERATURE)
5105 flags |= RDP_OET_LOW_WARNING;
5107 flags |= ((0xf & RDP_OED_TEMPERATURE) << RDP_OED_TYPE_SHIFT);
5108 desc->oed_info.function_flags = cpu_to_be32(flags);
5109 desc->length = cpu_to_be32(sizeof(desc->oed_info));
5110 return sizeof(struct fc_rdp_oed_sfp_desc);
5114 lpfc_rdp_res_oed_voltage_desc(struct lpfc_hba *phba,
5115 struct fc_rdp_oed_sfp_desc *desc,
5120 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5122 desc->oed_info.hi_alarm = page_a2[SSF_VOLTAGE_HIGH_ALARM];
5123 desc->oed_info.lo_alarm = page_a2[SSF_VOLTAGE_LOW_ALARM];
5124 desc->oed_info.hi_warning = page_a2[SSF_VOLTAGE_HIGH_WARNING];
5125 desc->oed_info.lo_warning = page_a2[SSF_VOLTAGE_LOW_WARNING];
5127 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_VOLTAGE)
5128 flags |= RDP_OET_HIGH_ALARM;
5129 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_VOLTAGE)
5130 flags |= RDP_OET_LOW_ALARM;
5131 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_VOLTAGE)
5132 flags |= RDP_OET_HIGH_WARNING;
5133 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_VOLTAGE)
5134 flags |= RDP_OET_LOW_WARNING;
5136 flags |= ((0xf & RDP_OED_VOLTAGE) << RDP_OED_TYPE_SHIFT);
5137 desc->oed_info.function_flags = cpu_to_be32(flags);
5138 desc->length = cpu_to_be32(sizeof(desc->oed_info));
5139 return sizeof(struct fc_rdp_oed_sfp_desc);
5143 lpfc_rdp_res_oed_txbias_desc(struct lpfc_hba *phba,
5144 struct fc_rdp_oed_sfp_desc *desc,
5149 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5151 desc->oed_info.hi_alarm = page_a2[SSF_BIAS_HIGH_ALARM];
5152 desc->oed_info.lo_alarm = page_a2[SSF_BIAS_LOW_ALARM];
5153 desc->oed_info.hi_warning = page_a2[SSF_BIAS_HIGH_WARNING];
5154 desc->oed_info.lo_warning = page_a2[SSF_BIAS_LOW_WARNING];
5156 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TXBIAS)
5157 flags |= RDP_OET_HIGH_ALARM;
5158 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TXBIAS)
5159 flags |= RDP_OET_LOW_ALARM;
5160 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TXBIAS)
5161 flags |= RDP_OET_HIGH_WARNING;
5162 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TXBIAS)
5163 flags |= RDP_OET_LOW_WARNING;
5165 flags |= ((0xf & RDP_OED_TXBIAS) << RDP_OED_TYPE_SHIFT);
5166 desc->oed_info.function_flags = cpu_to_be32(flags);
5167 desc->length = cpu_to_be32(sizeof(desc->oed_info));
5168 return sizeof(struct fc_rdp_oed_sfp_desc);
5172 lpfc_rdp_res_oed_txpower_desc(struct lpfc_hba *phba,
5173 struct fc_rdp_oed_sfp_desc *desc,
5178 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5180 desc->oed_info.hi_alarm = page_a2[SSF_TXPOWER_HIGH_ALARM];
5181 desc->oed_info.lo_alarm = page_a2[SSF_TXPOWER_LOW_ALARM];
5182 desc->oed_info.hi_warning = page_a2[SSF_TXPOWER_HIGH_WARNING];
5183 desc->oed_info.lo_warning = page_a2[SSF_TXPOWER_LOW_WARNING];
5185 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TXPOWER)
5186 flags |= RDP_OET_HIGH_ALARM;
5187 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TXPOWER)
5188 flags |= RDP_OET_LOW_ALARM;
5189 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TXPOWER)
5190 flags |= RDP_OET_HIGH_WARNING;
5191 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TXPOWER)
5192 flags |= RDP_OET_LOW_WARNING;
5194 flags |= ((0xf & RDP_OED_TXPOWER) << RDP_OED_TYPE_SHIFT);
5195 desc->oed_info.function_flags = cpu_to_be32(flags);
5196 desc->length = cpu_to_be32(sizeof(desc->oed_info));
5197 return sizeof(struct fc_rdp_oed_sfp_desc);
5202 lpfc_rdp_res_oed_rxpower_desc(struct lpfc_hba *phba,
5203 struct fc_rdp_oed_sfp_desc *desc,
5208 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5210 desc->oed_info.hi_alarm = page_a2[SSF_RXPOWER_HIGH_ALARM];
5211 desc->oed_info.lo_alarm = page_a2[SSF_RXPOWER_LOW_ALARM];
5212 desc->oed_info.hi_warning = page_a2[SSF_RXPOWER_HIGH_WARNING];
5213 desc->oed_info.lo_warning = page_a2[SSF_RXPOWER_LOW_WARNING];
5215 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_RXPOWER)
5216 flags |= RDP_OET_HIGH_ALARM;
5217 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_RXPOWER)
5218 flags |= RDP_OET_LOW_ALARM;
5219 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_RXPOWER)
5220 flags |= RDP_OET_HIGH_WARNING;
5221 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_RXPOWER)
5222 flags |= RDP_OET_LOW_WARNING;
5224 flags |= ((0xf & RDP_OED_RXPOWER) << RDP_OED_TYPE_SHIFT);
5225 desc->oed_info.function_flags = cpu_to_be32(flags);
5226 desc->length = cpu_to_be32(sizeof(desc->oed_info));
5227 return sizeof(struct fc_rdp_oed_sfp_desc);
5231 lpfc_rdp_res_opd_desc(struct fc_rdp_opd_sfp_desc *desc,
5232 uint8_t *page_a0, struct lpfc_vport *vport)
5234 desc->tag = cpu_to_be32(RDP_OPD_DESC_TAG);
5235 memcpy(desc->opd_info.vendor_name, &page_a0[SSF_VENDOR_NAME], 16);
5236 memcpy(desc->opd_info.model_number, &page_a0[SSF_VENDOR_PN], 16);
5237 memcpy(desc->opd_info.serial_number, &page_a0[SSF_VENDOR_SN], 16);
5238 memcpy(desc->opd_info.revision, &page_a0[SSF_VENDOR_REV], 4);
5239 memcpy(desc->opd_info.date, &page_a0[SSF_DATE_CODE], 8);
5240 desc->length = cpu_to_be32(sizeof(desc->opd_info));
5241 return sizeof(struct fc_rdp_opd_sfp_desc);
5245 lpfc_rdp_res_fec_desc(struct fc_fec_rdp_desc *desc, READ_LNK_VAR *stat)
5247 if (bf_get(lpfc_read_link_stat_gec2, stat) == 0)
5249 desc->tag = cpu_to_be32(RDP_FEC_DESC_TAG);
5251 desc->info.CorrectedBlocks =
5252 cpu_to_be32(stat->fecCorrBlkCount);
5253 desc->info.UncorrectableBlocks =
5254 cpu_to_be32(stat->fecUncorrBlkCount);
5256 desc->length = cpu_to_be32(sizeof(desc->info));
5258 return sizeof(struct fc_fec_rdp_desc);
5262 lpfc_rdp_res_speed(struct fc_rdp_port_speed_desc *desc, struct lpfc_hba *phba)
5264 uint16_t rdp_cap = 0;
5267 desc->tag = cpu_to_be32(RDP_PORT_SPEED_DESC_TAG);
5269 switch (phba->fc_linkspeed) {
5270 case LPFC_LINK_SPEED_1GHZ:
5271 rdp_speed = RDP_PS_1GB;
5273 case LPFC_LINK_SPEED_2GHZ:
5274 rdp_speed = RDP_PS_2GB;
5276 case LPFC_LINK_SPEED_4GHZ:
5277 rdp_speed = RDP_PS_4GB;
5279 case LPFC_LINK_SPEED_8GHZ:
5280 rdp_speed = RDP_PS_8GB;
5282 case LPFC_LINK_SPEED_10GHZ:
5283 rdp_speed = RDP_PS_10GB;
5285 case LPFC_LINK_SPEED_16GHZ:
5286 rdp_speed = RDP_PS_16GB;
5288 case LPFC_LINK_SPEED_32GHZ:
5289 rdp_speed = RDP_PS_32GB;
5291 case LPFC_LINK_SPEED_64GHZ:
5292 rdp_speed = RDP_PS_64GB;
5295 rdp_speed = RDP_PS_UNKNOWN;
5299 desc->info.port_speed.speed = cpu_to_be16(rdp_speed);
5301 if (phba->lmt & LMT_64Gb)
5302 rdp_cap |= RDP_PS_64GB;
5303 if (phba->lmt & LMT_32Gb)
5304 rdp_cap |= RDP_PS_32GB;
5305 if (phba->lmt & LMT_16Gb)
5306 rdp_cap |= RDP_PS_16GB;
5307 if (phba->lmt & LMT_10Gb)
5308 rdp_cap |= RDP_PS_10GB;
5309 if (phba->lmt & LMT_8Gb)
5310 rdp_cap |= RDP_PS_8GB;
5311 if (phba->lmt & LMT_4Gb)
5312 rdp_cap |= RDP_PS_4GB;
5313 if (phba->lmt & LMT_2Gb)
5314 rdp_cap |= RDP_PS_2GB;
5315 if (phba->lmt & LMT_1Gb)
5316 rdp_cap |= RDP_PS_1GB;
5319 rdp_cap = RDP_CAP_UNKNOWN;
5320 if (phba->cfg_link_speed != LPFC_USER_LINK_SPEED_AUTO)
5321 rdp_cap |= RDP_CAP_USER_CONFIGURED;
5323 desc->info.port_speed.capabilities = cpu_to_be16(rdp_cap);
5324 desc->length = cpu_to_be32(sizeof(desc->info));
5325 return sizeof(struct fc_rdp_port_speed_desc);
5329 lpfc_rdp_res_diag_port_names(struct fc_rdp_port_name_desc *desc,
5330 struct lpfc_vport *vport)
5333 desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG);
5335 memcpy(desc->port_names.wwnn, &vport->fc_nodename,
5336 sizeof(desc->port_names.wwnn));
5338 memcpy(desc->port_names.wwpn, &vport->fc_portname,
5339 sizeof(desc->port_names.wwpn));
5341 desc->length = cpu_to_be32(sizeof(desc->port_names));
5342 return sizeof(struct fc_rdp_port_name_desc);
5346 lpfc_rdp_res_attach_port_names(struct fc_rdp_port_name_desc *desc,
5347 struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
5350 desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG);
5351 if (vport->fc_flag & FC_FABRIC) {
5352 memcpy(desc->port_names.wwnn, &vport->fabric_nodename,
5353 sizeof(desc->port_names.wwnn));
5355 memcpy(desc->port_names.wwpn, &vport->fabric_portname,
5356 sizeof(desc->port_names.wwpn));
5357 } else { /* Point to Point */
5358 memcpy(desc->port_names.wwnn, &ndlp->nlp_nodename,
5359 sizeof(desc->port_names.wwnn));
5361 memcpy(desc->port_names.wwnn, &ndlp->nlp_portname,
5362 sizeof(desc->port_names.wwpn));
5365 desc->length = cpu_to_be32(sizeof(desc->port_names));
5366 return sizeof(struct fc_rdp_port_name_desc);
5370 lpfc_els_rdp_cmpl(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context,
5373 struct lpfc_nodelist *ndlp = rdp_context->ndlp;
5374 struct lpfc_vport *vport = ndlp->vport;
5375 struct lpfc_iocbq *elsiocb;
5376 struct ulp_bde64 *bpl;
5379 struct ls_rjt *stat;
5380 struct fc_rdp_res_frame *rdp_res;
5381 uint32_t cmdsize, len;
5385 if (status != SUCCESS)
5388 /* This will change once we know the true size of the RDP payload */
5389 cmdsize = sizeof(struct fc_rdp_res_frame);
5391 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize,
5392 lpfc_max_els_tries, rdp_context->ndlp,
5393 rdp_context->ndlp->nlp_DID, ELS_CMD_ACC);
5396 goto free_rdp_context;
5398 icmd = &elsiocb->iocb;
5399 icmd->ulpContext = rdp_context->rx_id;
5400 icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id;
5402 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5403 "2171 Xmit RDP response tag x%x xri x%x, "
5404 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x",
5405 elsiocb->iotag, elsiocb->iocb.ulpContext,
5406 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5408 rdp_res = (struct fc_rdp_res_frame *)
5409 (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5410 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5411 memset(pcmd, 0, sizeof(struct fc_rdp_res_frame));
5412 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5414 /* Update Alarm and Warning */
5415 flag_ptr = (uint16_t *)(rdp_context->page_a2 + SSF_ALARM_FLAGS);
5416 phba->sfp_alarm |= *flag_ptr;
5417 flag_ptr = (uint16_t *)(rdp_context->page_a2 + SSF_WARNING_FLAGS);
5418 phba->sfp_warning |= *flag_ptr;
5420 /* For RDP payload */
5422 len += lpfc_rdp_res_link_service((struct fc_rdp_link_service_desc *)
5423 (len + pcmd), ELS_CMD_RDP);
5425 len += lpfc_rdp_res_sfp_desc((struct fc_rdp_sfp_desc *)(len + pcmd),
5426 rdp_context->page_a0, rdp_context->page_a2);
5427 len += lpfc_rdp_res_speed((struct fc_rdp_port_speed_desc *)(len + pcmd),
5429 len += lpfc_rdp_res_link_error((struct fc_rdp_link_error_status_desc *)
5430 (len + pcmd), &rdp_context->link_stat);
5431 len += lpfc_rdp_res_diag_port_names((struct fc_rdp_port_name_desc *)
5432 (len + pcmd), vport);
5433 len += lpfc_rdp_res_attach_port_names((struct fc_rdp_port_name_desc *)
5434 (len + pcmd), vport, ndlp);
5435 len += lpfc_rdp_res_fec_desc((struct fc_fec_rdp_desc *)(len + pcmd),
5436 &rdp_context->link_stat);
5437 len += lpfc_rdp_res_bbc_desc((struct fc_rdp_bbc_desc *)(len + pcmd),
5438 &rdp_context->link_stat, vport);
5439 len += lpfc_rdp_res_oed_temp_desc(phba,
5440 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5441 rdp_context->page_a2);
5442 len += lpfc_rdp_res_oed_voltage_desc(phba,
5443 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5444 rdp_context->page_a2);
5445 len += lpfc_rdp_res_oed_txbias_desc(phba,
5446 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5447 rdp_context->page_a2);
5448 len += lpfc_rdp_res_oed_txpower_desc(phba,
5449 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5450 rdp_context->page_a2);
5451 len += lpfc_rdp_res_oed_rxpower_desc(phba,
5452 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5453 rdp_context->page_a2);
5454 len += lpfc_rdp_res_opd_desc((struct fc_rdp_opd_sfp_desc *)(len + pcmd),
5455 rdp_context->page_a0, vport);
5457 rdp_res->length = cpu_to_be32(len - 8);
5458 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5460 /* Now that we know the true size of the payload, update the BPL */
5461 bpl = (struct ulp_bde64 *)
5462 (((struct lpfc_dmabuf *)(elsiocb->context3))->virt);
5463 bpl->tus.f.bdeSize = len;
5464 bpl->tus.f.bdeFlags = 0;
5465 bpl->tus.w = le32_to_cpu(bpl->tus.w);
5467 phba->fc_stat.elsXmitACC++;
5468 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5469 if (rc == IOCB_ERROR)
5470 lpfc_els_free_iocb(phba, elsiocb);
5476 cmdsize = 2 * sizeof(uint32_t);
5477 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, lpfc_max_els_tries,
5478 ndlp, ndlp->nlp_DID, ELS_CMD_LS_RJT);
5481 goto free_rdp_context;
5483 icmd = &elsiocb->iocb;
5484 icmd->ulpContext = rdp_context->rx_id;
5485 icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id;
5486 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5488 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
5489 stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t));
5490 stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5492 phba->fc_stat.elsXmitLSRJT++;
5493 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5494 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5496 if (rc == IOCB_ERROR)
5497 lpfc_els_free_iocb(phba, elsiocb);
5503 lpfc_get_rdp_info(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context)
5505 LPFC_MBOXQ_t *mbox = NULL;
5508 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5510 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_ELS,
5511 "7105 failed to allocate mailbox memory");
5515 if (lpfc_sli4_dump_page_a0(phba, mbox))
5516 goto prep_mbox_fail;
5517 mbox->vport = rdp_context->ndlp->vport;
5518 mbox->mbox_cmpl = lpfc_mbx_cmpl_rdp_page_a0;
5519 mbox->context2 = (struct lpfc_rdp_context *) rdp_context;
5520 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
5521 if (rc == MBX_NOT_FINISHED)
5522 goto issue_mbox_fail;
5528 mempool_free(mbox, phba->mbox_mem_pool);
5533 * lpfc_els_rcv_rdp - Process an unsolicited RDP ELS.
5534 * @vport: pointer to a host virtual N_Port data structure.
5535 * @cmdiocb: pointer to lpfc command iocb data structure.
5536 * @ndlp: pointer to a node-list data structure.
5538 * This routine processes an unsolicited RDP(Read Diagnostic Parameters)
5539 * IOCB. First, the payload of the unsolicited RDP is checked.
5540 * Then it will (1) send MBX_DUMP_MEMORY, Embedded DMP_LMSD sub command TYPE-3
5541 * for Page A0, (2) send MBX_DUMP_MEMORY, DMP_LMSD for Page A2,
5542 * (3) send MBX_READ_LNK_STAT to get link stat, (4) Call lpfc_els_rdp_cmpl
5543 * gather all data and send RDP response.
5546 * 0 - Sent the acc response
5547 * 1 - Sent the reject response.
5550 lpfc_els_rcv_rdp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5551 struct lpfc_nodelist *ndlp)
5553 struct lpfc_hba *phba = vport->phba;
5554 struct lpfc_dmabuf *pcmd;
5555 uint8_t rjt_err, rjt_expl = LSEXP_NOTHING_MORE;
5556 struct fc_rdp_req_frame *rdp_req;
5557 struct lpfc_rdp_context *rdp_context;
5561 if (phba->sli_rev < LPFC_SLI_REV4 ||
5562 bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
5563 LPFC_SLI_INTF_IF_TYPE_2) {
5564 rjt_err = LSRJT_UNABLE_TPC;
5565 rjt_expl = LSEXP_REQ_UNSUPPORTED;
5569 if (phba->sli_rev < LPFC_SLI_REV4 || (phba->hba_flag & HBA_FCOE_MODE)) {
5570 rjt_err = LSRJT_UNABLE_TPC;
5571 rjt_expl = LSEXP_REQ_UNSUPPORTED;
5575 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5576 rdp_req = (struct fc_rdp_req_frame *) pcmd->virt;
5578 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5579 "2422 ELS RDP Request "
5580 "dec len %d tag x%x port_id %d len %d\n",
5581 be32_to_cpu(rdp_req->rdp_des_length),
5582 be32_to_cpu(rdp_req->nport_id_desc.tag),
5583 be32_to_cpu(rdp_req->nport_id_desc.nport_id),
5584 be32_to_cpu(rdp_req->nport_id_desc.length));
5586 if (sizeof(struct fc_rdp_nport_desc) !=
5587 be32_to_cpu(rdp_req->rdp_des_length))
5589 if (RDP_N_PORT_DESC_TAG != be32_to_cpu(rdp_req->nport_id_desc.tag))
5591 if (RDP_NPORT_ID_SIZE !=
5592 be32_to_cpu(rdp_req->nport_id_desc.length))
5594 rdp_context = kzalloc(sizeof(struct lpfc_rdp_context), GFP_KERNEL);
5596 rjt_err = LSRJT_UNABLE_TPC;
5600 cmd = &cmdiocb->iocb;
5601 rdp_context->ndlp = lpfc_nlp_get(ndlp);
5602 rdp_context->ox_id = cmd->unsli3.rcvsli3.ox_id;
5603 rdp_context->rx_id = cmd->ulpContext;
5604 rdp_context->cmpl = lpfc_els_rdp_cmpl;
5605 if (lpfc_get_rdp_info(phba, rdp_context)) {
5606 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_ELS,
5607 "2423 Unable to send mailbox");
5609 rjt_err = LSRJT_UNABLE_TPC;
5617 rjt_err = LSRJT_LOGICAL_ERR;
5620 memset(&stat, 0, sizeof(stat));
5621 stat.un.b.lsRjtRsnCode = rjt_err;
5622 stat.un.b.lsRjtRsnCodeExp = rjt_expl;
5623 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5629 lpfc_els_lcb_rsp(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
5634 struct lpfc_iocbq *elsiocb;
5635 struct lpfc_nodelist *ndlp;
5636 struct ls_rjt *stat;
5637 union lpfc_sli4_cfg_shdr *shdr;
5638 struct lpfc_lcb_context *lcb_context;
5639 struct fc_lcb_res_frame *lcb_res;
5640 uint32_t cmdsize, shdr_status, shdr_add_status;
5644 lcb_context = (struct lpfc_lcb_context *)pmb->context1;
5645 ndlp = lcb_context->ndlp;
5646 pmb->context1 = NULL;
5647 pmb->context2 = NULL;
5649 shdr = (union lpfc_sli4_cfg_shdr *)
5650 &pmb->u.mqe.un.beacon_config.header.cfg_shdr;
5651 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
5652 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
5654 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX,
5655 "0194 SET_BEACON_CONFIG mailbox "
5656 "completed with status x%x add_status x%x,"
5657 " mbx status x%x\n",
5658 shdr_status, shdr_add_status, mb->mbxStatus);
5660 if ((mb->mbxStatus != MBX_SUCCESS) || shdr_status ||
5661 (shdr_add_status == ADD_STATUS_OPERATION_ALREADY_ACTIVE) ||
5662 (shdr_add_status == ADD_STATUS_INVALID_REQUEST)) {
5663 mempool_free(pmb, phba->mbox_mem_pool);
5667 mempool_free(pmb, phba->mbox_mem_pool);
5668 cmdsize = sizeof(struct fc_lcb_res_frame);
5669 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5670 lpfc_max_els_tries, ndlp,
5671 ndlp->nlp_DID, ELS_CMD_ACC);
5673 /* Decrement the ndlp reference count from previous mbox command */
5677 goto free_lcb_context;
5679 lcb_res = (struct fc_lcb_res_frame *)
5680 (((struct lpfc_dmabuf *)elsiocb->context2)->virt);
5682 memset(lcb_res, 0, sizeof(struct fc_lcb_res_frame));
5683 icmd = &elsiocb->iocb;
5684 icmd->ulpContext = lcb_context->rx_id;
5685 icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id;
5687 pcmd = (uint8_t *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt);
5688 *((uint32_t *)(pcmd)) = ELS_CMD_ACC;
5689 lcb_res->lcb_sub_command = lcb_context->sub_command;
5690 lcb_res->lcb_type = lcb_context->type;
5691 lcb_res->capability = lcb_context->capability;
5692 lcb_res->lcb_frequency = lcb_context->frequency;
5693 lcb_res->lcb_duration = lcb_context->duration;
5694 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5695 phba->fc_stat.elsXmitACC++;
5696 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5697 if (rc == IOCB_ERROR)
5698 lpfc_els_free_iocb(phba, elsiocb);
5704 cmdsize = sizeof(struct fc_lcb_res_frame);
5705 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5706 lpfc_max_els_tries, ndlp,
5707 ndlp->nlp_DID, ELS_CMD_LS_RJT);
5710 goto free_lcb_context;
5712 icmd = &elsiocb->iocb;
5713 icmd->ulpContext = lcb_context->rx_id;
5714 icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id;
5715 pcmd = (uint8_t *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt);
5717 *((uint32_t *)(pcmd)) = ELS_CMD_LS_RJT;
5718 stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t));
5719 stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5721 if (shdr_add_status == ADD_STATUS_OPERATION_ALREADY_ACTIVE)
5722 stat->un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS;
5724 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5725 phba->fc_stat.elsXmitLSRJT++;
5726 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5727 if (rc == IOCB_ERROR)
5728 lpfc_els_free_iocb(phba, elsiocb);
5734 lpfc_sli4_set_beacon(struct lpfc_vport *vport,
5735 struct lpfc_lcb_context *lcb_context,
5736 uint32_t beacon_state)
5738 struct lpfc_hba *phba = vport->phba;
5739 union lpfc_sli4_cfg_shdr *cfg_shdr;
5740 LPFC_MBOXQ_t *mbox = NULL;
5744 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5748 cfg_shdr = &mbox->u.mqe.un.sli4_config.header.cfg_shdr;
5749 len = sizeof(struct lpfc_mbx_set_beacon_config) -
5750 sizeof(struct lpfc_sli4_cfg_mhdr);
5751 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
5752 LPFC_MBOX_OPCODE_SET_BEACON_CONFIG, len,
5753 LPFC_SLI4_MBX_EMBED);
5754 mbox->context1 = (void *)lcb_context;
5755 mbox->vport = phba->pport;
5756 mbox->mbox_cmpl = lpfc_els_lcb_rsp;
5757 bf_set(lpfc_mbx_set_beacon_port_num, &mbox->u.mqe.un.beacon_config,
5758 phba->sli4_hba.physical_port);
5759 bf_set(lpfc_mbx_set_beacon_state, &mbox->u.mqe.un.beacon_config,
5761 mbox->u.mqe.un.beacon_config.word5 = 0; /* Reserved */
5764 * Check bv1s bit before issuing the mailbox
5765 * if bv1s == 1, LCB V1 supported
5766 * else, LCB V0 supported
5769 if (phba->sli4_hba.pc_sli4_params.bv1s) {
5770 /* COMMON_SET_BEACON_CONFIG_V1 */
5771 cfg_shdr->request.word9 = BEACON_VERSION_V1;
5772 lcb_context->capability |= LCB_CAPABILITY_DURATION;
5773 bf_set(lpfc_mbx_set_beacon_port_type,
5774 &mbox->u.mqe.un.beacon_config, 0);
5775 bf_set(lpfc_mbx_set_beacon_duration_v1,
5776 &mbox->u.mqe.un.beacon_config,
5777 be16_to_cpu(lcb_context->duration));
5779 /* COMMON_SET_BEACON_CONFIG_V0 */
5780 if (be16_to_cpu(lcb_context->duration) != 0) {
5781 mempool_free(mbox, phba->mbox_mem_pool);
5784 cfg_shdr->request.word9 = BEACON_VERSION_V0;
5785 lcb_context->capability &= ~(LCB_CAPABILITY_DURATION);
5786 bf_set(lpfc_mbx_set_beacon_state,
5787 &mbox->u.mqe.un.beacon_config, beacon_state);
5788 bf_set(lpfc_mbx_set_beacon_port_type,
5789 &mbox->u.mqe.un.beacon_config, 1);
5790 bf_set(lpfc_mbx_set_beacon_duration,
5791 &mbox->u.mqe.un.beacon_config,
5792 be16_to_cpu(lcb_context->duration));
5795 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
5796 if (rc == MBX_NOT_FINISHED) {
5797 mempool_free(mbox, phba->mbox_mem_pool);
5806 * lpfc_els_rcv_lcb - Process an unsolicited LCB
5807 * @vport: pointer to a host virtual N_Port data structure.
5808 * @cmdiocb: pointer to lpfc command iocb data structure.
5809 * @ndlp: pointer to a node-list data structure.
5811 * This routine processes an unsolicited LCB(LINK CABLE BEACON) IOCB.
5812 * First, the payload of the unsolicited LCB is checked.
5813 * Then based on Subcommand beacon will either turn on or off.
5816 * 0 - Sent the acc response
5817 * 1 - Sent the reject response.
5820 lpfc_els_rcv_lcb(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5821 struct lpfc_nodelist *ndlp)
5823 struct lpfc_hba *phba = vport->phba;
5824 struct lpfc_dmabuf *pcmd;
5826 struct fc_lcb_request_frame *beacon;
5827 struct lpfc_lcb_context *lcb_context;
5828 uint8_t state, rjt_err;
5831 pcmd = (struct lpfc_dmabuf *)cmdiocb->context2;
5832 lp = (uint8_t *)pcmd->virt;
5833 beacon = (struct fc_lcb_request_frame *)pcmd->virt;
5835 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5836 "0192 ELS LCB Data x%x x%x x%x x%x sub x%x "
5837 "type x%x frequency %x duration x%x\n",
5838 lp[0], lp[1], lp[2],
5839 beacon->lcb_command,
5840 beacon->lcb_sub_command,
5842 beacon->lcb_frequency,
5843 be16_to_cpu(beacon->lcb_duration));
5845 if (beacon->lcb_sub_command != LPFC_LCB_ON &&
5846 beacon->lcb_sub_command != LPFC_LCB_OFF) {
5847 rjt_err = LSRJT_CMD_UNSUPPORTED;
5851 if (phba->sli_rev < LPFC_SLI_REV4 ||
5852 phba->hba_flag & HBA_FCOE_MODE ||
5853 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
5854 LPFC_SLI_INTF_IF_TYPE_2)) {
5855 rjt_err = LSRJT_CMD_UNSUPPORTED;
5859 lcb_context = kmalloc(sizeof(*lcb_context), GFP_KERNEL);
5861 rjt_err = LSRJT_UNABLE_TPC;
5865 state = (beacon->lcb_sub_command == LPFC_LCB_ON) ? 1 : 0;
5866 lcb_context->sub_command = beacon->lcb_sub_command;
5867 lcb_context->capability = 0;
5868 lcb_context->type = beacon->lcb_type;
5869 lcb_context->frequency = beacon->lcb_frequency;
5870 lcb_context->duration = beacon->lcb_duration;
5871 lcb_context->ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id;
5872 lcb_context->rx_id = cmdiocb->iocb.ulpContext;
5873 lcb_context->ndlp = lpfc_nlp_get(ndlp);
5874 if (lpfc_sli4_set_beacon(vport, lcb_context, state)) {
5875 lpfc_printf_vlog(ndlp->vport, KERN_ERR,
5876 LOG_ELS, "0193 failed to send mail box");
5879 rjt_err = LSRJT_UNABLE_TPC;
5884 memset(&stat, 0, sizeof(stat));
5885 stat.un.b.lsRjtRsnCode = rjt_err;
5886 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5892 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
5893 * @vport: pointer to a host virtual N_Port data structure.
5895 * This routine cleans up any Registration State Change Notification
5896 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
5897 * @vport together with the host_lock is used to prevent multiple thread
5898 * trying to access the RSCN array on a same @vport at the same time.
5901 lpfc_els_flush_rscn(struct lpfc_vport *vport)
5903 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5904 struct lpfc_hba *phba = vport->phba;
5907 spin_lock_irq(shost->host_lock);
5908 if (vport->fc_rscn_flush) {
5909 /* Another thread is walking fc_rscn_id_list on this vport */
5910 spin_unlock_irq(shost->host_lock);
5913 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
5914 vport->fc_rscn_flush = 1;
5915 spin_unlock_irq(shost->host_lock);
5917 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
5918 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
5919 vport->fc_rscn_id_list[i] = NULL;
5921 spin_lock_irq(shost->host_lock);
5922 vport->fc_rscn_id_cnt = 0;
5923 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
5924 spin_unlock_irq(shost->host_lock);
5925 lpfc_can_disctmo(vport);
5926 /* Indicate we are done walking this fc_rscn_id_list */
5927 vport->fc_rscn_flush = 0;
5931 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
5932 * @vport: pointer to a host virtual N_Port data structure.
5933 * @did: remote destination port identifier.
5935 * This routine checks whether there is any pending Registration State
5936 * Configuration Notification (RSCN) to a @did on @vport.
5939 * None zero - The @did matched with a pending rscn
5940 * 0 - not able to match @did with a pending rscn
5943 lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
5948 uint32_t payload_len, i;
5949 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5951 ns_did.un.word = did;
5953 /* Never match fabric nodes for RSCNs */
5954 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
5957 /* If we are doing a FULL RSCN rediscovery, match everything */
5958 if (vport->fc_flag & FC_RSCN_DISCOVERY)
5961 spin_lock_irq(shost->host_lock);
5962 if (vport->fc_rscn_flush) {
5963 /* Another thread is walking fc_rscn_id_list on this vport */
5964 spin_unlock_irq(shost->host_lock);
5967 /* Indicate we are walking fc_rscn_id_list on this vport */
5968 vport->fc_rscn_flush = 1;
5969 spin_unlock_irq(shost->host_lock);
5970 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
5971 lp = vport->fc_rscn_id_list[i]->virt;
5972 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
5973 payload_len -= sizeof(uint32_t); /* take off word 0 */
5974 while (payload_len) {
5975 rscn_did.un.word = be32_to_cpu(*lp++);
5976 payload_len -= sizeof(uint32_t);
5977 switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) {
5978 case RSCN_ADDRESS_FORMAT_PORT:
5979 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
5980 && (ns_did.un.b.area == rscn_did.un.b.area)
5981 && (ns_did.un.b.id == rscn_did.un.b.id))
5982 goto return_did_out;
5984 case RSCN_ADDRESS_FORMAT_AREA:
5985 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
5986 && (ns_did.un.b.area == rscn_did.un.b.area))
5987 goto return_did_out;
5989 case RSCN_ADDRESS_FORMAT_DOMAIN:
5990 if (ns_did.un.b.domain == rscn_did.un.b.domain)
5991 goto return_did_out;
5993 case RSCN_ADDRESS_FORMAT_FABRIC:
5994 goto return_did_out;
5998 /* Indicate we are done with walking fc_rscn_id_list on this vport */
5999 vport->fc_rscn_flush = 0;
6002 /* Indicate we are done with walking fc_rscn_id_list on this vport */
6003 vport->fc_rscn_flush = 0;
6008 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
6009 * @vport: pointer to a host virtual N_Port data structure.
6011 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
6012 * state machine for a @vport's nodes that are with pending RSCN (Registration
6013 * State Change Notification).
6016 * 0 - Successful (currently alway return 0)
6019 lpfc_rscn_recovery_check(struct lpfc_vport *vport)
6021 struct lpfc_nodelist *ndlp = NULL;
6023 /* Move all affected nodes by pending RSCNs to NPR state. */
6024 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
6025 if (!NLP_CHK_NODE_ACT(ndlp) ||
6026 (ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
6027 !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
6030 /* NVME Target mode does not do RSCN Recovery. */
6031 if (vport->phba->nvmet_support)
6034 lpfc_disc_state_machine(vport, ndlp, NULL,
6035 NLP_EVT_DEVICE_RECOVERY);
6036 lpfc_cancel_retry_delay_tmo(vport, ndlp);
6042 * lpfc_send_rscn_event - Send an RSCN event to management application
6043 * @vport: pointer to a host virtual N_Port data structure.
6044 * @cmdiocb: pointer to lpfc command iocb data structure.
6046 * lpfc_send_rscn_event sends an RSCN netlink event to management
6050 lpfc_send_rscn_event(struct lpfc_vport *vport,
6051 struct lpfc_iocbq *cmdiocb)
6053 struct lpfc_dmabuf *pcmd;
6054 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6055 uint32_t *payload_ptr;
6056 uint32_t payload_len;
6057 struct lpfc_rscn_event_header *rscn_event_data;
6059 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6060 payload_ptr = (uint32_t *) pcmd->virt;
6061 payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK);
6063 rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) +
6064 payload_len, GFP_KERNEL);
6065 if (!rscn_event_data) {
6066 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6067 "0147 Failed to allocate memory for RSCN event\n");
6070 rscn_event_data->event_type = FC_REG_RSCN_EVENT;
6071 rscn_event_data->payload_length = payload_len;
6072 memcpy(rscn_event_data->rscn_payload, payload_ptr,
6075 fc_host_post_vendor_event(shost,
6076 fc_get_event_number(),
6077 sizeof(struct lpfc_rscn_event_header) + payload_len,
6078 (char *)rscn_event_data,
6081 kfree(rscn_event_data);
6085 * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
6086 * @vport: pointer to a host virtual N_Port data structure.
6087 * @cmdiocb: pointer to lpfc command iocb data structure.
6088 * @ndlp: pointer to a node-list data structure.
6090 * This routine processes an unsolicited RSCN (Registration State Change
6091 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
6092 * to invoke fc_host_post_event() routine to the FC transport layer. If the
6093 * discover state machine is about to begin discovery, it just accepts the
6094 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
6095 * contains N_Port IDs for other vports on this HBA, it just accepts the
6096 * RSCN and ignore processing it. If the state machine is in the recovery
6097 * state, the fc_rscn_id_list of this @vport is walked and the
6098 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
6099 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
6100 * routine is invoked to handle the RSCN event.
6103 * 0 - Just sent the acc response
6104 * 1 - Sent the acc response and waited for name server completion
6107 lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6108 struct lpfc_nodelist *ndlp)
6110 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6111 struct lpfc_hba *phba = vport->phba;
6112 struct lpfc_dmabuf *pcmd;
6113 uint32_t *lp, *datap;
6114 uint32_t payload_len, length, nportid, *cmd;
6116 int rscn_id = 0, hba_id = 0;
6119 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6120 lp = (uint32_t *) pcmd->virt;
6122 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
6123 payload_len -= sizeof(uint32_t); /* take off word 0 */
6125 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6126 "0214 RSCN received Data: x%x x%x x%x x%x\n",
6127 vport->fc_flag, payload_len, *lp,
6128 vport->fc_rscn_id_cnt);
6130 /* Send an RSCN event to the management application */
6131 lpfc_send_rscn_event(vport, cmdiocb);
6133 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
6134 fc_host_post_event(shost, fc_get_event_number(),
6135 FCH_EVT_RSCN, lp[i]);
6137 /* If we are about to begin discovery, just ACC the RSCN.
6138 * Discovery processing will satisfy it.
6140 if (vport->port_state <= LPFC_NS_QRY) {
6141 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6142 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
6143 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
6145 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
6149 /* If this RSCN just contains NPortIDs for other vports on this HBA,
6150 * just ACC and ignore it.
6152 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
6153 !(vport->cfg_peer_port_login)) {
6158 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
6159 i -= sizeof(uint32_t);
6161 if (lpfc_find_vport_by_did(phba, nportid))
6164 if (rscn_id == hba_id) {
6165 /* ALL NPortIDs in RSCN are on HBA */
6166 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6168 "Data: x%x x%x x%x x%x\n",
6169 vport->fc_flag, payload_len,
6170 *lp, vport->fc_rscn_id_cnt);
6171 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6172 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
6173 ndlp->nlp_DID, vport->port_state,
6176 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
6182 spin_lock_irq(shost->host_lock);
6183 if (vport->fc_rscn_flush) {
6184 /* Another thread is walking fc_rscn_id_list on this vport */
6185 vport->fc_flag |= FC_RSCN_DISCOVERY;
6186 spin_unlock_irq(shost->host_lock);
6188 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
6191 /* Indicate we are walking fc_rscn_id_list on this vport */
6192 vport->fc_rscn_flush = 1;
6193 spin_unlock_irq(shost->host_lock);
6194 /* Get the array count after successfully have the token */
6195 rscn_cnt = vport->fc_rscn_id_cnt;
6196 /* If we are already processing an RSCN, save the received
6197 * RSCN payload buffer, cmdiocb->context2 to process later.
6199 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
6200 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6201 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
6202 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
6204 spin_lock_irq(shost->host_lock);
6205 vport->fc_flag |= FC_RSCN_DEFERRED;
6206 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
6207 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
6208 vport->fc_flag |= FC_RSCN_MODE;
6209 spin_unlock_irq(shost->host_lock);
6211 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
6212 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
6215 (payload_len + length <= LPFC_BPL_SIZE)) {
6216 *cmd &= ELS_CMD_MASK;
6217 *cmd |= cpu_to_be32(payload_len + length);
6218 memcpy(((uint8_t *)cmd) + length, lp,
6221 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
6222 vport->fc_rscn_id_cnt++;
6223 /* If we zero, cmdiocb->context2, the calling
6224 * routine will not try to free it.
6226 cmdiocb->context2 = NULL;
6229 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6230 "0235 Deferred RSCN "
6231 "Data: x%x x%x x%x\n",
6232 vport->fc_rscn_id_cnt, vport->fc_flag,
6235 vport->fc_flag |= FC_RSCN_DISCOVERY;
6236 spin_unlock_irq(shost->host_lock);
6237 /* ReDiscovery RSCN */
6238 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6239 "0234 ReDiscovery RSCN "
6240 "Data: x%x x%x x%x\n",
6241 vport->fc_rscn_id_cnt, vport->fc_flag,
6244 /* Indicate we are done walking fc_rscn_id_list on this vport */
6245 vport->fc_rscn_flush = 0;
6247 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
6248 /* send RECOVERY event for ALL nodes that match RSCN payload */
6249 lpfc_rscn_recovery_check(vport);
6252 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6253 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
6254 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
6256 spin_lock_irq(shost->host_lock);
6257 vport->fc_flag |= FC_RSCN_MODE;
6258 spin_unlock_irq(shost->host_lock);
6259 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
6260 /* Indicate we are done walking fc_rscn_id_list on this vport */
6261 vport->fc_rscn_flush = 0;
6263 * If we zero, cmdiocb->context2, the calling routine will
6264 * not try to free it.
6266 cmdiocb->context2 = NULL;
6267 lpfc_set_disctmo(vport);
6269 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
6270 /* send RECOVERY event for ALL nodes that match RSCN payload */
6271 lpfc_rscn_recovery_check(vport);
6272 return lpfc_els_handle_rscn(vport);
6276 * lpfc_els_handle_rscn - Handle rscn for a vport
6277 * @vport: pointer to a host virtual N_Port data structure.
6279 * This routine handles the Registration State Configuration Notification
6280 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
6281 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
6282 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
6283 * NameServer shall be issued. If CT command to the NameServer fails to be
6284 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
6285 * RSCN activities with the @vport.
6288 * 0 - Cleaned up rscn on the @vport
6289 * 1 - Wait for plogi to name server before proceed
6292 lpfc_els_handle_rscn(struct lpfc_vport *vport)
6294 struct lpfc_nodelist *ndlp;
6296 /* Ignore RSCN if the port is being torn down. */
6297 if (vport->load_flag & FC_UNLOADING) {
6298 lpfc_els_flush_rscn(vport);
6302 /* Start timer for RSCN processing */
6303 lpfc_set_disctmo(vport);
6305 /* RSCN processed */
6306 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6307 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
6308 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
6311 /* To process RSCN, first compare RSCN data with NameServer */
6312 vport->fc_ns_retry = 0;
6313 vport->num_disc_nodes = 0;
6315 ndlp = lpfc_findnode_did(vport, NameServer_DID);
6316 if (ndlp && NLP_CHK_NODE_ACT(ndlp)
6317 && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
6318 /* Good ndlp, issue CT Request to NameServer. Need to
6319 * know how many gidfts were issued. If none, then just
6320 * flush the RSCN. Otherwise, the outstanding requests
6323 if (lpfc_issue_gidft(vport) > 0)
6326 /* Nameserver login in question. Revalidate. */
6328 ndlp = lpfc_enable_node(vport, ndlp,
6329 NLP_STE_PLOGI_ISSUE);
6331 lpfc_els_flush_rscn(vport);
6334 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
6336 ndlp = lpfc_nlp_init(vport, NameServer_DID);
6338 lpfc_els_flush_rscn(vport);
6341 ndlp->nlp_prev_state = ndlp->nlp_state;
6342 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
6344 ndlp->nlp_type |= NLP_FABRIC;
6345 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
6346 /* Wait for NameServer login cmpl before we can
6352 lpfc_els_flush_rscn(vport);
6357 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
6358 * @vport: pointer to a host virtual N_Port data structure.
6359 * @cmdiocb: pointer to lpfc command iocb data structure.
6360 * @ndlp: pointer to a node-list data structure.
6362 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
6363 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
6364 * point topology. As an unsolicited FLOGI should not be received in a loop
6365 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
6366 * lpfc_check_sparm() routine is invoked to check the parameters in the
6367 * unsolicited FLOGI. If parameters validation failed, the routine
6368 * lpfc_els_rsp_reject() shall be called with reject reason code set to
6369 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
6370 * FLOGI shall be compared with the Port WWN of the @vport to determine who
6371 * will initiate PLOGI. The higher lexicographical value party shall has
6372 * higher priority (as the winning port) and will initiate PLOGI and
6373 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
6374 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
6375 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
6378 * 0 - Successfully processed the unsolicited flogi
6379 * 1 - Failed to process the unsolicited flogi
6382 lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6383 struct lpfc_nodelist *ndlp)
6385 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6386 struct lpfc_hba *phba = vport->phba;
6387 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6388 uint32_t *lp = (uint32_t *) pcmd->virt;
6389 IOCB_t *icmd = &cmdiocb->iocb;
6390 struct serv_parm *sp;
6394 uint32_t fc_flag = 0;
6395 uint32_t port_state = 0;
6398 sp = (struct serv_parm *) lp;
6400 /* FLOGI received */
6402 lpfc_set_disctmo(vport);
6404 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
6405 /* We should never receive a FLOGI in loop mode, ignore it */
6406 did = icmd->un.elsreq64.remoteID;
6408 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
6410 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6411 "0113 An FLOGI ELS command x%x was "
6412 "received from DID x%x in Loop Mode\n",
6417 (void) lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1);
6420 * If our portname is greater than the remote portname,
6421 * then we initiate Nport login.
6424 rc = memcmp(&vport->fc_portname, &sp->portName,
6425 sizeof(struct lpfc_name));
6428 if (phba->sli_rev < LPFC_SLI_REV4) {
6429 mbox = mempool_alloc(phba->mbox_mem_pool,
6433 lpfc_linkdown(phba);
6434 lpfc_init_link(phba, mbox,
6436 phba->cfg_link_speed);
6437 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
6438 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
6439 mbox->vport = vport;
6440 rc = lpfc_sli_issue_mbox(phba, mbox,
6442 lpfc_set_loopback_flag(phba);
6443 if (rc == MBX_NOT_FINISHED)
6444 mempool_free(mbox, phba->mbox_mem_pool);
6448 /* abort the flogi coming back to ourselves
6449 * due to external loopback on the port.
6451 lpfc_els_abort_flogi(phba);
6454 } else if (rc > 0) { /* greater than */
6455 spin_lock_irq(shost->host_lock);
6456 vport->fc_flag |= FC_PT2PT_PLOGI;
6457 spin_unlock_irq(shost->host_lock);
6459 /* If we have the high WWPN we can assign our own
6460 * myDID; otherwise, we have to WAIT for a PLOGI
6461 * from the remote NPort to find out what it
6464 vport->fc_myDID = PT2PT_LocalID;
6466 vport->fc_myDID = PT2PT_RemoteID;
6470 * The vport state should go to LPFC_FLOGI only
6471 * AFTER we issue a FLOGI, not receive one.
6473 spin_lock_irq(shost->host_lock);
6474 fc_flag = vport->fc_flag;
6475 port_state = vport->port_state;
6476 vport->fc_flag |= FC_PT2PT;
6477 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
6479 /* Acking an unsol FLOGI. Count 1 for link bounce
6482 vport->rcv_flogi_cnt++;
6483 spin_unlock_irq(shost->host_lock);
6484 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6485 "3311 Rcv Flogi PS x%x new PS x%x "
6486 "fc_flag x%x new fc_flag x%x\n",
6487 port_state, vport->port_state,
6488 fc_flag, vport->fc_flag);
6491 * We temporarily set fc_myDID to make it look like we are
6492 * a Fabric. This is done just so we end up with the right
6493 * did / sid on the FLOGI ACC rsp.
6495 did = vport->fc_myDID;
6496 vport->fc_myDID = Fabric_DID;
6498 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
6501 lpfc_els_rsp_acc(vport, ELS_CMD_FLOGI, cmdiocb, ndlp, NULL);
6503 /* Now lets put fc_myDID back to what its supposed to be */
6504 vport->fc_myDID = did;
6510 * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
6511 * @vport: pointer to a host virtual N_Port data structure.
6512 * @cmdiocb: pointer to lpfc command iocb data structure.
6513 * @ndlp: pointer to a node-list data structure.
6515 * This routine processes Request Node Identification Data (RNID) IOCB
6516 * received as an ELS unsolicited event. Only when the RNID specified format
6517 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
6518 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
6519 * Accept (ACC) the RNID ELS command. All the other RNID formats are
6520 * rejected by invoking the lpfc_els_rsp_reject() routine.
6523 * 0 - Successfully processed rnid iocb (currently always return 0)
6526 lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6527 struct lpfc_nodelist *ndlp)
6529 struct lpfc_dmabuf *pcmd;
6535 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6536 lp = (uint32_t *) pcmd->virt;
6543 switch (rn->Format) {
6545 case RNID_TOPOLOGY_DISC:
6547 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
6550 /* Reject this request because format not supported */
6551 stat.un.b.lsRjtRsvd0 = 0;
6552 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6553 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
6554 stat.un.b.vendorUnique = 0;
6555 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
6562 * lpfc_els_rcv_echo - Process an unsolicited echo 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.
6568 * 0 - Successfully processed echo iocb (currently always return 0)
6571 lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6572 struct lpfc_nodelist *ndlp)
6576 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
6578 /* skip over first word of echo command to find echo data */
6579 pcmd += sizeof(uint32_t);
6581 lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp);
6586 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
6587 * @vport: pointer to a host virtual N_Port data structure.
6588 * @cmdiocb: pointer to lpfc command iocb data structure.
6589 * @ndlp: pointer to a node-list data structure.
6591 * This routine processes a Link Incident Report Registration(LIRR) IOCB
6592 * received as an ELS unsolicited event. Currently, this function just invokes
6593 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
6596 * 0 - Successfully processed lirr iocb (currently always return 0)
6599 lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6600 struct lpfc_nodelist *ndlp)
6604 /* For now, unconditionally reject this command */
6605 stat.un.b.lsRjtRsvd0 = 0;
6606 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6607 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
6608 stat.un.b.vendorUnique = 0;
6609 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
6614 * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb
6615 * @vport: pointer to a host virtual N_Port data structure.
6616 * @cmdiocb: pointer to lpfc command iocb data structure.
6617 * @ndlp: pointer to a node-list data structure.
6619 * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB
6620 * received as an ELS unsolicited event. A request to RRQ shall only
6621 * be accepted if the Originator Nx_Port N_Port_ID or the Responder
6622 * Nx_Port N_Port_ID of the target Exchange is the same as the
6623 * N_Port_ID of the Nx_Port that makes the request. If the RRQ is
6624 * not accepted, an LS_RJT with reason code "Unable to perform
6625 * command request" and reason code explanation "Invalid Originator
6626 * S_ID" shall be returned. For now, we just unconditionally accept
6627 * RRQ from the target.
6630 lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6631 struct lpfc_nodelist *ndlp)
6633 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
6634 if (vport->phba->sli_rev == LPFC_SLI_REV4)
6635 lpfc_els_clear_rrq(vport, cmdiocb, ndlp);
6639 * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
6640 * @phba: pointer to lpfc hba data structure.
6641 * @pmb: pointer to the driver internal queue element for mailbox command.
6643 * This routine is the completion callback function for the MBX_READ_LNK_STAT
6644 * mailbox command. This callback function is to actually send the Accept
6645 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
6646 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
6647 * mailbox command, constructs the RPS response with the link statistics
6648 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
6649 * response to the RPS.
6651 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6652 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6653 * will be stored into the context1 field of the IOCB for the completion
6654 * callback function to the RPS Accept Response ELS IOCB command.
6658 lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
6662 struct RLS_RSP *rls_rsp;
6664 struct lpfc_iocbq *elsiocb;
6665 struct lpfc_nodelist *ndlp;
6672 ndlp = (struct lpfc_nodelist *) pmb->context2;
6673 rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff);
6674 oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff);
6675 pmb->context1 = NULL;
6676 pmb->context2 = NULL;
6678 if (mb->mbxStatus) {
6679 mempool_free(pmb, phba->mbox_mem_pool);
6683 cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t);
6684 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
6685 lpfc_max_els_tries, ndlp,
6686 ndlp->nlp_DID, ELS_CMD_ACC);
6688 /* Decrement the ndlp reference count from previous mbox command */
6692 mempool_free(pmb, phba->mbox_mem_pool);
6696 icmd = &elsiocb->iocb;
6697 icmd->ulpContext = rxid;
6698 icmd->unsli3.rcvsli3.ox_id = oxid;
6700 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6701 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
6702 pcmd += sizeof(uint32_t); /* Skip past command */
6703 rls_rsp = (struct RLS_RSP *)pcmd;
6705 rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
6706 rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
6707 rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
6708 rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
6709 rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
6710 rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
6711 mempool_free(pmb, phba->mbox_mem_pool);
6712 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
6713 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
6714 "2874 Xmit ELS RLS ACC response tag x%x xri x%x, "
6715 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
6716 elsiocb->iotag, elsiocb->iocb.ulpContext,
6717 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
6719 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
6720 phba->fc_stat.elsXmitACC++;
6721 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
6722 lpfc_els_free_iocb(phba, elsiocb);
6726 * lpfc_els_rsp_rps_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
6727 * @phba: pointer to lpfc hba data structure.
6728 * @pmb: pointer to the driver internal queue element for mailbox command.
6730 * This routine is the completion callback function for the MBX_READ_LNK_STAT
6731 * mailbox command. This callback function is to actually send the Accept
6732 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
6733 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
6734 * mailbox command, constructs the RPS response with the link statistics
6735 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
6736 * response to the RPS.
6738 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6739 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6740 * will be stored into the context1 field of the IOCB for the completion
6741 * callback function to the RPS Accept Response ELS IOCB command.
6745 lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
6751 struct lpfc_iocbq *elsiocb;
6752 struct lpfc_nodelist *ndlp;
6760 ndlp = (struct lpfc_nodelist *) pmb->context2;
6761 rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff);
6762 oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff);
6763 pmb->context1 = NULL;
6764 pmb->context2 = NULL;
6766 if (mb->mbxStatus) {
6767 mempool_free(pmb, phba->mbox_mem_pool);
6771 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
6772 mempool_free(pmb, phba->mbox_mem_pool);
6773 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
6774 lpfc_max_els_tries, ndlp,
6775 ndlp->nlp_DID, ELS_CMD_ACC);
6777 /* Decrement the ndlp reference count from previous mbox command */
6783 icmd = &elsiocb->iocb;
6784 icmd->ulpContext = rxid;
6785 icmd->unsli3.rcvsli3.ox_id = oxid;
6787 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6788 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
6789 pcmd += sizeof(uint32_t); /* Skip past command */
6790 rps_rsp = (RPS_RSP *)pcmd;
6792 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP)
6796 if (phba->pport->fc_flag & FC_FABRIC)
6800 rps_rsp->portStatus = cpu_to_be16(status);
6801 rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
6802 rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
6803 rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
6804 rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
6805 rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
6806 rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
6807 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
6808 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
6809 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
6810 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
6811 elsiocb->iotag, elsiocb->iocb.ulpContext,
6812 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
6814 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
6815 phba->fc_stat.elsXmitACC++;
6816 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
6817 lpfc_els_free_iocb(phba, elsiocb);
6822 * lpfc_els_rcv_rls - Process an unsolicited rls iocb
6823 * @vport: pointer to a host virtual N_Port data structure.
6824 * @cmdiocb: pointer to lpfc command iocb data structure.
6825 * @ndlp: pointer to a node-list data structure.
6827 * This routine processes Read Port Status (RPL) IOCB received as an
6828 * ELS unsolicited event. It first checks the remote port state. If the
6829 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
6830 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
6831 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
6832 * for reading the HBA link statistics. It is for the callback function,
6833 * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command
6834 * to actually sending out RPL Accept (ACC) response.
6837 * 0 - Successfully processed rls iocb (currently always return 0)
6840 lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6841 struct lpfc_nodelist *ndlp)
6843 struct lpfc_hba *phba = vport->phba;
6847 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
6848 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
6849 /* reject the unsolicited RPS request and done with it */
6852 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
6854 lpfc_read_lnk_stat(phba, mbox);
6855 mbox->context1 = (void *)((unsigned long)
6856 ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) |
6857 cmdiocb->iocb.ulpContext)); /* rx_id */
6858 mbox->context2 = lpfc_nlp_get(ndlp);
6859 mbox->vport = vport;
6860 mbox->mbox_cmpl = lpfc_els_rsp_rls_acc;
6861 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
6862 != MBX_NOT_FINISHED)
6863 /* Mbox completion will send ELS Response */
6865 /* Decrement reference count used for the failed mbox
6869 mempool_free(mbox, phba->mbox_mem_pool);
6872 /* issue rejection response */
6873 stat.un.b.lsRjtRsvd0 = 0;
6874 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6875 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
6876 stat.un.b.vendorUnique = 0;
6877 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
6882 * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb
6883 * @vport: pointer to a host virtual N_Port data structure.
6884 * @cmdiocb: pointer to lpfc command iocb data structure.
6885 * @ndlp: pointer to a node-list data structure.
6887 * This routine processes Read Timout Value (RTV) IOCB received as an
6888 * ELS unsolicited event. It first checks the remote port state. If the
6889 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
6890 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
6891 * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout
6892 * Value (RTV) unsolicited IOCB event.
6894 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6895 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6896 * will be stored into the context1 field of the IOCB for the completion
6897 * callback function to the RPS Accept Response ELS IOCB command.
6900 * 0 - Successfully processed rtv iocb (currently always return 0)
6903 lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6904 struct lpfc_nodelist *ndlp)
6906 struct lpfc_hba *phba = vport->phba;
6908 struct RTV_RSP *rtv_rsp;
6910 struct lpfc_iocbq *elsiocb;
6914 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
6915 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
6916 /* reject the unsolicited RPS request and done with it */
6919 cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t);
6920 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
6921 lpfc_max_els_tries, ndlp,
6922 ndlp->nlp_DID, ELS_CMD_ACC);
6927 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6928 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
6929 pcmd += sizeof(uint32_t); /* Skip past command */
6931 /* use the command's xri in the response */
6932 elsiocb->iocb.ulpContext = cmdiocb->iocb.ulpContext; /* Xri / rx_id */
6933 elsiocb->iocb.unsli3.rcvsli3.ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id;
6935 rtv_rsp = (struct RTV_RSP *)pcmd;
6937 /* populate RTV payload */
6938 rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000); /* report msecs */
6939 rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov);
6940 bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0);
6941 bf_set(qtov_rttov, rtv_rsp, 0); /* Field is for FC ONLY */
6942 rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov);
6944 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
6945 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
6946 "2875 Xmit ELS RTV ACC response tag x%x xri x%x, "
6947 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, "
6948 "Data: x%x x%x x%x\n",
6949 elsiocb->iotag, elsiocb->iocb.ulpContext,
6950 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
6952 rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov);
6953 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
6954 phba->fc_stat.elsXmitACC++;
6955 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
6956 lpfc_els_free_iocb(phba, elsiocb);
6960 /* issue rejection response */
6961 stat.un.b.lsRjtRsvd0 = 0;
6962 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6963 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
6964 stat.un.b.vendorUnique = 0;
6965 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
6969 /* lpfc_els_rcv_rps - Process an unsolicited rps iocb
6970 * @vport: pointer to a host virtual N_Port data structure.
6971 * @cmdiocb: pointer to lpfc command iocb data structure.
6972 * @ndlp: pointer to a node-list data structure.
6974 * This routine processes Read Port Status (RPS) IOCB received as an
6975 * ELS unsolicited event. It first checks the remote port state. If the
6976 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
6977 * state, it invokes the lpfc_els_rsp_reject() routine to send the reject
6978 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
6979 * for reading the HBA link statistics. It is for the callback function,
6980 * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command
6981 * to actually sending out RPS Accept (ACC) response.
6984 * 0 - Successfully processed rps iocb (currently always return 0)
6987 lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6988 struct lpfc_nodelist *ndlp)
6990 struct lpfc_hba *phba = vport->phba;
6994 struct lpfc_dmabuf *pcmd;
6998 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
6999 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
7000 /* reject the unsolicited RPS request and done with it */
7003 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7004 lp = (uint32_t *) pcmd->virt;
7005 flag = (be32_to_cpu(*lp++) & 0xf);
7009 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
7010 ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
7011 sizeof(struct lpfc_name)) == 0))) {
7013 printk("Fix me....\n");
7015 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
7017 lpfc_read_lnk_stat(phba, mbox);
7018 mbox->context1 = (void *)((unsigned long)
7019 ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) |
7020 cmdiocb->iocb.ulpContext)); /* rx_id */
7021 mbox->context2 = lpfc_nlp_get(ndlp);
7022 mbox->vport = vport;
7023 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
7024 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
7025 != MBX_NOT_FINISHED)
7026 /* Mbox completion will send ELS Response */
7028 /* Decrement reference count used for the failed mbox
7032 mempool_free(mbox, phba->mbox_mem_pool);
7037 /* issue rejection response */
7038 stat.un.b.lsRjtRsvd0 = 0;
7039 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
7040 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
7041 stat.un.b.vendorUnique = 0;
7042 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
7046 /* lpfc_issue_els_rrq - Process an unsolicited rps iocb
7047 * @vport: pointer to a host virtual N_Port data structure.
7048 * @ndlp: pointer to a node-list data structure.
7049 * @did: DID of the target.
7050 * @rrq: Pointer to the rrq struct.
7052 * Build a ELS RRQ command and send it to the target. If the issue_iocb is
7053 * Successful the the completion handler will clear the RRQ.
7056 * 0 - Successfully sent rrq els iocb.
7057 * 1 - Failed to send rrq els iocb.
7060 lpfc_issue_els_rrq(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
7061 uint32_t did, struct lpfc_node_rrq *rrq)
7063 struct lpfc_hba *phba = vport->phba;
7064 struct RRQ *els_rrq;
7065 struct lpfc_iocbq *elsiocb;
7071 if (ndlp != rrq->ndlp)
7073 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
7076 /* If ndlp is not NULL, we will bump the reference count on it */
7077 cmdsize = (sizeof(uint32_t) + sizeof(struct RRQ));
7078 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, did,
7083 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7085 /* For RRQ request, remainder of payload is Exchange IDs */
7086 *((uint32_t *) (pcmd)) = ELS_CMD_RRQ;
7087 pcmd += sizeof(uint32_t);
7088 els_rrq = (struct RRQ *) pcmd;
7090 bf_set(rrq_oxid, els_rrq, phba->sli4_hba.xri_ids[rrq->xritag]);
7091 bf_set(rrq_rxid, els_rrq, rrq->rxid);
7092 bf_set(rrq_did, els_rrq, vport->fc_myDID);
7093 els_rrq->rrq = cpu_to_be32(els_rrq->rrq);
7094 els_rrq->rrq_exchg = cpu_to_be32(els_rrq->rrq_exchg);
7097 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7098 "Issue RRQ: did:x%x",
7099 did, rrq->xritag, rrq->rxid);
7100 elsiocb->context_un.rrq = rrq;
7101 elsiocb->iocb_cmpl = lpfc_cmpl_els_rrq;
7102 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
7104 if (ret == IOCB_ERROR) {
7105 lpfc_els_free_iocb(phba, elsiocb);
7112 * lpfc_send_rrq - Sends ELS RRQ if needed.
7113 * @phba: pointer to lpfc hba data structure.
7114 * @rrq: pointer to the active rrq.
7116 * This routine will call the lpfc_issue_els_rrq if the rrq is
7117 * still active for the xri. If this function returns a failure then
7118 * the caller needs to clean up the RRQ by calling lpfc_clr_active_rrq.
7120 * Returns 0 Success.
7124 lpfc_send_rrq(struct lpfc_hba *phba, struct lpfc_node_rrq *rrq)
7126 struct lpfc_nodelist *ndlp = lpfc_findnode_did(rrq->vport,
7131 if (lpfc_test_rrq_active(phba, ndlp, rrq->xritag))
7132 return lpfc_issue_els_rrq(rrq->vport, ndlp,
7139 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
7140 * @vport: pointer to a host virtual N_Port data structure.
7141 * @cmdsize: size of the ELS command.
7142 * @oldiocb: pointer to the original lpfc command iocb data structure.
7143 * @ndlp: pointer to a node-list data structure.
7145 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
7146 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
7148 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7149 * will be incremented by 1 for holding the ndlp and the reference to ndlp
7150 * will be stored into the context1 field of the IOCB for the completion
7151 * callback function to the RPL Accept Response ELS command.
7154 * 0 - Successfully issued ACC RPL ELS command
7155 * 1 - Failed to issue ACC RPL ELS command
7158 lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
7159 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
7161 struct lpfc_hba *phba = vport->phba;
7162 IOCB_t *icmd, *oldcmd;
7164 struct lpfc_iocbq *elsiocb;
7167 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
7168 ndlp->nlp_DID, ELS_CMD_ACC);
7173 icmd = &elsiocb->iocb;
7174 oldcmd = &oldiocb->iocb;
7175 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
7176 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
7178 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7179 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
7180 pcmd += sizeof(uint16_t);
7181 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
7182 pcmd += sizeof(uint16_t);
7184 /* Setup the RPL ACC payload */
7185 rpl_rsp.listLen = be32_to_cpu(1);
7187 rpl_rsp.port_num_blk.portNum = 0;
7188 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
7189 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
7190 sizeof(struct lpfc_name));
7191 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
7192 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
7193 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7194 "0120 Xmit ELS RPL ACC response tag x%x "
7195 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
7197 elsiocb->iotag, elsiocb->iocb.ulpContext,
7198 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
7200 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
7201 phba->fc_stat.elsXmitACC++;
7202 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
7204 lpfc_els_free_iocb(phba, elsiocb);
7211 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
7212 * @vport: pointer to a host virtual N_Port data structure.
7213 * @cmdiocb: pointer to lpfc command iocb data structure.
7214 * @ndlp: pointer to a node-list data structure.
7216 * This routine processes Read Port List (RPL) IOCB received as an ELS
7217 * unsolicited event. It first checks the remote port state. If the remote
7218 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
7219 * invokes the lpfc_els_rsp_reject() routine to send reject response.
7220 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
7221 * to accept the RPL.
7224 * 0 - Successfully processed rpl iocb (currently always return 0)
7227 lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7228 struct lpfc_nodelist *ndlp)
7230 struct lpfc_dmabuf *pcmd;
7237 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
7238 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
7239 /* issue rejection response */
7240 stat.un.b.lsRjtRsvd0 = 0;
7241 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
7242 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
7243 stat.un.b.vendorUnique = 0;
7244 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
7246 /* rejected the unsolicited RPL request and done with it */
7250 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7251 lp = (uint32_t *) pcmd->virt;
7252 rpl = (RPL *) (lp + 1);
7253 maxsize = be32_to_cpu(rpl->maxsize);
7255 /* We support only one port */
7256 if ((rpl->index == 0) &&
7258 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
7259 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
7261 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
7263 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
7269 * lpfc_els_rcv_farp - Process an unsolicited farp request els command
7270 * @vport: pointer to a virtual N_Port data structure.
7271 * @cmdiocb: pointer to lpfc command iocb data structure.
7272 * @ndlp: pointer to a node-list data structure.
7274 * This routine processes Fibre Channel Address Resolution Protocol
7275 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
7276 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
7277 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
7278 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
7279 * remote PortName is compared against the FC PortName stored in the @vport
7280 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
7281 * compared against the FC NodeName stored in the @vport data structure.
7282 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
7283 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
7284 * invoked to send out FARP Response to the remote node. Before sending the
7285 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
7286 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
7287 * routine is invoked to log into the remote port first.
7290 * 0 - Either the FARP Match Mode not supported or successfully processed
7293 lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7294 struct lpfc_nodelist *ndlp)
7296 struct lpfc_dmabuf *pcmd;
7300 uint32_t cmd, cnt, did;
7302 icmd = &cmdiocb->iocb;
7303 did = icmd->un.elsreq64.remoteID;
7304 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7305 lp = (uint32_t *) pcmd->virt;
7309 /* FARP-REQ received from DID <did> */
7310 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7311 "0601 FARP-REQ received from DID x%x\n", did);
7312 /* We will only support match on WWPN or WWNN */
7313 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
7318 /* If this FARP command is searching for my portname */
7319 if (fp->Mflags & FARP_MATCH_PORT) {
7320 if (memcmp(&fp->RportName, &vport->fc_portname,
7321 sizeof(struct lpfc_name)) == 0)
7325 /* If this FARP command is searching for my nodename */
7326 if (fp->Mflags & FARP_MATCH_NODE) {
7327 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
7328 sizeof(struct lpfc_name)) == 0)
7333 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
7334 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
7335 /* Log back into the node before sending the FARP. */
7336 if (fp->Rflags & FARP_REQUEST_PLOGI) {
7337 ndlp->nlp_prev_state = ndlp->nlp_state;
7338 lpfc_nlp_set_state(vport, ndlp,
7339 NLP_STE_PLOGI_ISSUE);
7340 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
7343 /* Send a FARP response to that node */
7344 if (fp->Rflags & FARP_REQUEST_FARPR)
7345 lpfc_issue_els_farpr(vport, did, 0);
7352 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
7353 * @vport: pointer to a host virtual N_Port data structure.
7354 * @cmdiocb: pointer to lpfc command iocb data structure.
7355 * @ndlp: pointer to a node-list data structure.
7357 * This routine processes Fibre Channel Address Resolution Protocol
7358 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
7359 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
7360 * the FARP response request.
7363 * 0 - Successfully processed FARPR IOCB (currently always return 0)
7366 lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7367 struct lpfc_nodelist *ndlp)
7369 struct lpfc_dmabuf *pcmd;
7374 icmd = &cmdiocb->iocb;
7375 did = icmd->un.elsreq64.remoteID;
7376 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7377 lp = (uint32_t *) pcmd->virt;
7380 /* FARP-RSP received from DID <did> */
7381 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7382 "0600 FARP-RSP received from DID x%x\n", did);
7383 /* ACCEPT the Farp resp request */
7384 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
7390 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
7391 * @vport: pointer to a host virtual N_Port data structure.
7392 * @cmdiocb: pointer to lpfc command iocb data structure.
7393 * @fan_ndlp: pointer to a node-list data structure.
7395 * This routine processes a Fabric Address Notification (FAN) IOCB
7396 * command received as an ELS unsolicited event. The FAN ELS command will
7397 * only be processed on a physical port (i.e., the @vport represents the
7398 * physical port). The fabric NodeName and PortName from the FAN IOCB are
7399 * compared against those in the phba data structure. If any of those is
7400 * different, the lpfc_initial_flogi() routine is invoked to initialize
7401 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
7402 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
7403 * is invoked to register login to the fabric.
7406 * 0 - Successfully processed fan iocb (currently always return 0).
7409 lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7410 struct lpfc_nodelist *fan_ndlp)
7412 struct lpfc_hba *phba = vport->phba;
7416 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
7417 lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
7419 /* FAN received; Fan does not have a reply sequence */
7420 if ((vport == phba->pport) &&
7421 (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
7422 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
7423 sizeof(struct lpfc_name))) ||
7424 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
7425 sizeof(struct lpfc_name)))) {
7426 /* This port has switched fabrics. FLOGI is required */
7427 lpfc_issue_init_vfi(vport);
7429 /* FAN verified - skip FLOGI */
7430 vport->fc_myDID = vport->fc_prevDID;
7431 if (phba->sli_rev < LPFC_SLI_REV4)
7432 lpfc_issue_fabric_reglogin(vport);
7434 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7435 "3138 Need register VFI: (x%x/%x)\n",
7436 vport->fc_prevDID, vport->fc_myDID);
7437 lpfc_issue_reg_vfi(vport);
7445 * lpfc_els_timeout - Handler funciton to the els timer
7446 * @ptr: holder for the timer function associated data.
7448 * This routine is invoked by the ELS timer after timeout. It posts the ELS
7449 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
7450 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
7451 * up the worker thread. It is for the worker thread to invoke the routine
7452 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
7455 lpfc_els_timeout(struct timer_list *t)
7457 struct lpfc_vport *vport = from_timer(vport, t, els_tmofunc);
7458 struct lpfc_hba *phba = vport->phba;
7459 uint32_t tmo_posted;
7460 unsigned long iflag;
7462 spin_lock_irqsave(&vport->work_port_lock, iflag);
7463 tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
7464 if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING)))
7465 vport->work_port_events |= WORKER_ELS_TMO;
7466 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
7468 if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING)))
7469 lpfc_worker_wake_up(phba);
7475 * lpfc_els_timeout_handler - Process an els timeout event
7476 * @vport: pointer to a virtual N_Port data structure.
7478 * This routine is the actual handler function that processes an ELS timeout
7479 * event. It walks the ELS ring to get and abort all the IOCBs (except the
7480 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
7481 * invoking the lpfc_sli_issue_abort_iotag() routine.
7484 lpfc_els_timeout_handler(struct lpfc_vport *vport)
7486 struct lpfc_hba *phba = vport->phba;
7487 struct lpfc_sli_ring *pring;
7488 struct lpfc_iocbq *tmp_iocb, *piocb;
7490 struct lpfc_dmabuf *pcmd;
7491 uint32_t els_command = 0;
7493 uint32_t remote_ID = 0xffffffff;
7494 LIST_HEAD(abort_list);
7497 timeout = (uint32_t)(phba->fc_ratov << 1);
7499 pring = lpfc_phba_elsring(phba);
7500 if (unlikely(!pring))
7503 if ((phba->pport->load_flag & FC_UNLOADING))
7505 spin_lock_irq(&phba->hbalock);
7506 if (phba->sli_rev == LPFC_SLI_REV4)
7507 spin_lock(&pring->ring_lock);
7509 if ((phba->pport->load_flag & FC_UNLOADING)) {
7510 if (phba->sli_rev == LPFC_SLI_REV4)
7511 spin_unlock(&pring->ring_lock);
7512 spin_unlock_irq(&phba->hbalock);
7516 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
7519 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
7520 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
7521 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
7524 if (piocb->vport != vport)
7527 pcmd = (struct lpfc_dmabuf *) piocb->context2;
7529 els_command = *(uint32_t *) (pcmd->virt);
7531 if (els_command == ELS_CMD_FARP ||
7532 els_command == ELS_CMD_FARPR ||
7533 els_command == ELS_CMD_FDISC)
7536 if (piocb->drvrTimeout > 0) {
7537 if (piocb->drvrTimeout >= timeout)
7538 piocb->drvrTimeout -= timeout;
7540 piocb->drvrTimeout = 0;
7544 remote_ID = 0xffffffff;
7545 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
7546 remote_ID = cmd->un.elsreq64.remoteID;
7548 struct lpfc_nodelist *ndlp;
7549 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
7550 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
7551 remote_ID = ndlp->nlp_DID;
7553 list_add_tail(&piocb->dlist, &abort_list);
7555 if (phba->sli_rev == LPFC_SLI_REV4)
7556 spin_unlock(&pring->ring_lock);
7557 spin_unlock_irq(&phba->hbalock);
7559 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
7561 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7562 "0127 ELS timeout Data: x%x x%x x%x "
7563 "x%x\n", els_command,
7564 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
7565 spin_lock_irq(&phba->hbalock);
7566 list_del_init(&piocb->dlist);
7567 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
7568 spin_unlock_irq(&phba->hbalock);
7571 if (!list_empty(&pring->txcmplq))
7572 if (!(phba->pport->load_flag & FC_UNLOADING))
7573 mod_timer(&vport->els_tmofunc,
7574 jiffies + msecs_to_jiffies(1000 * timeout));
7578 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
7579 * @vport: pointer to a host virtual N_Port data structure.
7581 * This routine is used to clean up all the outstanding ELS commands on a
7582 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
7583 * routine. After that, it walks the ELS transmit queue to remove all the
7584 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
7585 * the IOCBs with a non-NULL completion callback function, the callback
7586 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
7587 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
7588 * callback function, the IOCB will simply be released. Finally, it walks
7589 * the ELS transmit completion queue to issue an abort IOCB to any transmit
7590 * completion queue IOCB that is associated with the @vport and is not
7591 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
7592 * part of the discovery state machine) out to HBA by invoking the
7593 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
7594 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
7595 * the IOCBs are aborted when this function returns.
7598 lpfc_els_flush_cmd(struct lpfc_vport *vport)
7600 LIST_HEAD(abort_list);
7601 struct lpfc_hba *phba = vport->phba;
7602 struct lpfc_sli_ring *pring;
7603 struct lpfc_iocbq *tmp_iocb, *piocb;
7606 lpfc_fabric_abort_vport(vport);
7608 * For SLI3, only the hbalock is required. But SLI4 needs to coordinate
7609 * with the ring insert operation. Because lpfc_sli_issue_abort_iotag
7610 * ultimately grabs the ring_lock, the driver must splice the list into
7611 * a working list and release the locks before calling the abort.
7613 spin_lock_irq(&phba->hbalock);
7614 pring = lpfc_phba_elsring(phba);
7616 /* Bail out if we've no ELS wq, like in PCI error recovery case. */
7617 if (unlikely(!pring)) {
7618 spin_unlock_irq(&phba->hbalock);
7622 if (phba->sli_rev == LPFC_SLI_REV4)
7623 spin_lock(&pring->ring_lock);
7625 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
7626 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
7629 if (piocb->vport != vport)
7631 list_add_tail(&piocb->dlist, &abort_list);
7633 if (phba->sli_rev == LPFC_SLI_REV4)
7634 spin_unlock(&pring->ring_lock);
7635 spin_unlock_irq(&phba->hbalock);
7636 /* Abort each iocb on the aborted list and remove the dlist links. */
7637 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
7638 spin_lock_irq(&phba->hbalock);
7639 list_del_init(&piocb->dlist);
7640 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
7641 spin_unlock_irq(&phba->hbalock);
7643 if (!list_empty(&abort_list))
7644 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7645 "3387 abort list for txq not empty\n");
7646 INIT_LIST_HEAD(&abort_list);
7648 spin_lock_irq(&phba->hbalock);
7649 if (phba->sli_rev == LPFC_SLI_REV4)
7650 spin_lock(&pring->ring_lock);
7652 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
7655 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
7659 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
7660 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
7661 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
7662 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
7663 cmd->ulpCommand == CMD_ABORT_XRI_CN)
7666 if (piocb->vport != vport)
7669 list_del_init(&piocb->list);
7670 list_add_tail(&piocb->list, &abort_list);
7672 if (phba->sli_rev == LPFC_SLI_REV4)
7673 spin_unlock(&pring->ring_lock);
7674 spin_unlock_irq(&phba->hbalock);
7676 /* Cancell all the IOCBs from the completions list */
7677 lpfc_sli_cancel_iocbs(phba, &abort_list,
7678 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
7684 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
7685 * @phba: pointer to lpfc hba data structure.
7687 * This routine is used to clean up all the outstanding ELS commands on a
7688 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
7689 * routine. After that, it walks the ELS transmit queue to remove all the
7690 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
7691 * the IOCBs with the completion callback function associated, the callback
7692 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
7693 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
7694 * callback function associated, the IOCB will simply be released. Finally,
7695 * it walks the ELS transmit completion queue to issue an abort IOCB to any
7696 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
7697 * management plane IOCBs that are not part of the discovery state machine)
7698 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
7701 lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
7703 struct lpfc_vport *vport;
7704 list_for_each_entry(vport, &phba->port_list, listentry)
7705 lpfc_els_flush_cmd(vport);
7711 * lpfc_send_els_failure_event - Posts an ELS command failure event
7712 * @phba: Pointer to hba context object.
7713 * @cmdiocbp: Pointer to command iocb which reported error.
7714 * @rspiocbp: Pointer to response iocb which reported error.
7716 * This function sends an event when there is an ELS command
7720 lpfc_send_els_failure_event(struct lpfc_hba *phba,
7721 struct lpfc_iocbq *cmdiocbp,
7722 struct lpfc_iocbq *rspiocbp)
7724 struct lpfc_vport *vport = cmdiocbp->vport;
7725 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7726 struct lpfc_lsrjt_event lsrjt_event;
7727 struct lpfc_fabric_event_header fabric_event;
7729 struct lpfc_nodelist *ndlp;
7732 ndlp = cmdiocbp->context1;
7733 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
7736 if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) {
7737 lsrjt_event.header.event_type = FC_REG_ELS_EVENT;
7738 lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV;
7739 memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname,
7740 sizeof(struct lpfc_name));
7741 memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename,
7742 sizeof(struct lpfc_name));
7743 pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
7744 cmdiocbp->context2)->virt);
7745 lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0;
7746 stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]);
7747 lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode;
7748 lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp;
7749 fc_host_post_vendor_event(shost,
7750 fc_get_event_number(),
7751 sizeof(lsrjt_event),
7752 (char *)&lsrjt_event,
7756 if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) ||
7757 (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) {
7758 fabric_event.event_type = FC_REG_FABRIC_EVENT;
7759 if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY)
7760 fabric_event.subcategory = LPFC_EVENT_PORT_BUSY;
7762 fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY;
7763 memcpy(fabric_event.wwpn, &ndlp->nlp_portname,
7764 sizeof(struct lpfc_name));
7765 memcpy(fabric_event.wwnn, &ndlp->nlp_nodename,
7766 sizeof(struct lpfc_name));
7767 fc_host_post_vendor_event(shost,
7768 fc_get_event_number(),
7769 sizeof(fabric_event),
7770 (char *)&fabric_event,
7778 * lpfc_send_els_event - Posts unsolicited els event
7779 * @vport: Pointer to vport object.
7780 * @ndlp: Pointer FC node object.
7781 * @cmd: ELS command code.
7783 * This function posts an event when there is an incoming
7784 * unsolicited ELS command.
7787 lpfc_send_els_event(struct lpfc_vport *vport,
7788 struct lpfc_nodelist *ndlp,
7791 struct lpfc_els_event_header *els_data = NULL;
7792 struct lpfc_logo_event *logo_data = NULL;
7793 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7795 if (*payload == ELS_CMD_LOGO) {
7796 logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL);
7798 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7799 "0148 Failed to allocate memory "
7800 "for LOGO event\n");
7803 els_data = &logo_data->header;
7805 els_data = kmalloc(sizeof(struct lpfc_els_event_header),
7808 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7809 "0149 Failed to allocate memory "
7814 els_data->event_type = FC_REG_ELS_EVENT;
7817 els_data->subcategory = LPFC_EVENT_PLOGI_RCV;
7820 els_data->subcategory = LPFC_EVENT_PRLO_RCV;
7823 els_data->subcategory = LPFC_EVENT_ADISC_RCV;
7826 els_data->subcategory = LPFC_EVENT_LOGO_RCV;
7827 /* Copy the WWPN in the LOGO payload */
7828 memcpy(logo_data->logo_wwpn, &payload[2],
7829 sizeof(struct lpfc_name));
7835 memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name));
7836 memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name));
7837 if (*payload == ELS_CMD_LOGO) {
7838 fc_host_post_vendor_event(shost,
7839 fc_get_event_number(),
7840 sizeof(struct lpfc_logo_event),
7845 fc_host_post_vendor_event(shost,
7846 fc_get_event_number(),
7847 sizeof(struct lpfc_els_event_header),
7858 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
7859 * @phba: pointer to lpfc hba data structure.
7860 * @pring: pointer to a SLI ring.
7861 * @vport: pointer to a host virtual N_Port data structure.
7862 * @elsiocb: pointer to lpfc els command iocb data structure.
7864 * This routine is used for processing the IOCB associated with a unsolicited
7865 * event. It first determines whether there is an existing ndlp that matches
7866 * the DID from the unsolicited IOCB. If not, it will create a new one with
7867 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
7868 * IOCB is then used to invoke the proper routine and to set up proper state
7869 * of the discovery state machine.
7872 lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
7873 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
7875 struct Scsi_Host *shost;
7876 struct lpfc_nodelist *ndlp;
7879 uint32_t cmd, did, newnode;
7880 uint8_t rjt_exp, rjt_err = 0, init_link = 0;
7881 IOCB_t *icmd = &elsiocb->iocb;
7884 if (!vport || !(elsiocb->context2))
7888 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
7890 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
7891 lpfc_post_buffer(phba, pring, 1);
7893 did = icmd->un.rcvels.remoteID;
7894 if (icmd->ulpStatus) {
7895 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7896 "RCV Unsol ELS: status:x%x/x%x did:x%x",
7897 icmd->ulpStatus, icmd->un.ulpWord[4], did);
7901 /* Check to see if link went down during discovery */
7902 if (lpfc_els_chk_latt(vport))
7905 /* Ignore traffic received during vport shutdown. */
7906 if (vport->load_flag & FC_UNLOADING)
7909 /* If NPort discovery is delayed drop incoming ELS */
7910 if ((vport->fc_flag & FC_DISC_DELAYED) &&
7911 (cmd != ELS_CMD_PLOGI))
7914 ndlp = lpfc_findnode_did(vport, did);
7916 /* Cannot find existing Fabric ndlp, so allocate a new one */
7917 ndlp = lpfc_nlp_init(vport, did);
7920 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
7922 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
7923 ndlp->nlp_type |= NLP_FABRIC;
7924 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
7925 ndlp = lpfc_enable_node(vport, ndlp,
7926 NLP_STE_UNUSED_NODE);
7929 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
7931 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
7932 ndlp->nlp_type |= NLP_FABRIC;
7933 } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
7934 /* This is similar to the new node path */
7935 ndlp = lpfc_nlp_get(ndlp);
7938 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
7942 phba->fc_stat.elsRcvFrame++;
7945 * Do not process any unsolicited ELS commands
7946 * if the ndlp is in DEV_LOSS
7948 shost = lpfc_shost_from_vport(vport);
7949 spin_lock_irq(shost->host_lock);
7950 if (ndlp->nlp_flag & NLP_IN_DEV_LOSS) {
7951 spin_unlock_irq(shost->host_lock);
7954 spin_unlock_irq(shost->host_lock);
7956 elsiocb->context1 = lpfc_nlp_get(ndlp);
7957 elsiocb->vport = vport;
7959 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
7960 cmd &= ELS_CMD_MASK;
7962 /* ELS command <elsCmd> received from NPORT <did> */
7963 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7964 "0112 ELS command x%x received from NPORT x%x "
7965 "Data: x%x x%x x%x x%x\n",
7966 cmd, did, vport->port_state, vport->fc_flag,
7967 vport->fc_myDID, vport->fc_prevDID);
7969 /* reject till our FLOGI completes */
7970 if ((vport->port_state < LPFC_FABRIC_CFG_LINK) &&
7971 (cmd != ELS_CMD_FLOGI)) {
7972 rjt_err = LSRJT_LOGICAL_BSY;
7973 rjt_exp = LSEXP_NOTHING_MORE;
7979 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7980 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
7981 did, vport->port_state, ndlp->nlp_flag);
7983 phba->fc_stat.elsRcvPLOGI++;
7984 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
7985 if (phba->sli_rev == LPFC_SLI_REV4 &&
7986 (phba->pport->fc_flag & FC_PT2PT)) {
7987 vport->fc_prevDID = vport->fc_myDID;
7988 /* Our DID needs to be updated before registering
7989 * the vfi. This is done in lpfc_rcv_plogi but
7990 * that is called after the reg_vfi.
7992 vport->fc_myDID = elsiocb->iocb.un.rcvels.parmRo;
7993 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7994 "3312 Remote port assigned DID x%x "
7995 "%x\n", vport->fc_myDID,
7999 lpfc_send_els_event(vport, ndlp, payload);
8001 /* If Nport discovery is delayed, reject PLOGIs */
8002 if (vport->fc_flag & FC_DISC_DELAYED) {
8003 rjt_err = LSRJT_UNABLE_TPC;
8004 rjt_exp = LSEXP_NOTHING_MORE;
8008 if (vport->port_state < LPFC_DISC_AUTH) {
8009 if (!(phba->pport->fc_flag & FC_PT2PT) ||
8010 (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
8011 rjt_err = LSRJT_UNABLE_TPC;
8012 rjt_exp = LSEXP_NOTHING_MORE;
8017 spin_lock_irq(shost->host_lock);
8018 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
8019 spin_unlock_irq(shost->host_lock);
8021 lpfc_disc_state_machine(vport, ndlp, elsiocb,
8026 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8027 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
8028 did, vport->port_state, ndlp->nlp_flag);
8030 phba->fc_stat.elsRcvFLOGI++;
8032 /* If the driver believes fabric discovery is done and is ready,
8033 * bounce the link. There is some descrepancy.
8035 if (vport->port_state >= LPFC_LOCAL_CFG_LINK &&
8036 vport->fc_flag & FC_PT2PT &&
8037 vport->rcv_flogi_cnt >= 1) {
8038 rjt_err = LSRJT_LOGICAL_BSY;
8039 rjt_exp = LSEXP_NOTHING_MORE;
8044 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
8049 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8050 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
8051 did, vport->port_state, ndlp->nlp_flag);
8053 phba->fc_stat.elsRcvLOGO++;
8054 lpfc_send_els_event(vport, ndlp, payload);
8055 if (vport->port_state < LPFC_DISC_AUTH) {
8056 rjt_err = LSRJT_UNABLE_TPC;
8057 rjt_exp = LSEXP_NOTHING_MORE;
8060 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
8063 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8064 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
8065 did, vport->port_state, ndlp->nlp_flag);
8067 phba->fc_stat.elsRcvPRLO++;
8068 lpfc_send_els_event(vport, ndlp, payload);
8069 if (vport->port_state < LPFC_DISC_AUTH) {
8070 rjt_err = LSRJT_UNABLE_TPC;
8071 rjt_exp = LSEXP_NOTHING_MORE;
8074 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
8077 phba->fc_stat.elsRcvLCB++;
8078 lpfc_els_rcv_lcb(vport, elsiocb, ndlp);
8081 phba->fc_stat.elsRcvRDP++;
8082 lpfc_els_rcv_rdp(vport, elsiocb, ndlp);
8085 phba->fc_stat.elsRcvRSCN++;
8086 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
8091 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8092 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
8093 did, vport->port_state, ndlp->nlp_flag);
8095 lpfc_send_els_event(vport, ndlp, payload);
8096 phba->fc_stat.elsRcvADISC++;
8097 if (vport->port_state < LPFC_DISC_AUTH) {
8098 rjt_err = LSRJT_UNABLE_TPC;
8099 rjt_exp = LSEXP_NOTHING_MORE;
8102 lpfc_disc_state_machine(vport, ndlp, elsiocb,
8106 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8107 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
8108 did, vport->port_state, ndlp->nlp_flag);
8110 phba->fc_stat.elsRcvPDISC++;
8111 if (vport->port_state < LPFC_DISC_AUTH) {
8112 rjt_err = LSRJT_UNABLE_TPC;
8113 rjt_exp = LSEXP_NOTHING_MORE;
8116 lpfc_disc_state_machine(vport, ndlp, elsiocb,
8120 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8121 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
8122 did, vport->port_state, ndlp->nlp_flag);
8124 phba->fc_stat.elsRcvFARPR++;
8125 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
8128 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8129 "RCV FARP: did:x%x/ste:x%x flg:x%x",
8130 did, vport->port_state, ndlp->nlp_flag);
8132 phba->fc_stat.elsRcvFARP++;
8133 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
8136 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8137 "RCV FAN: did:x%x/ste:x%x flg:x%x",
8138 did, vport->port_state, ndlp->nlp_flag);
8140 phba->fc_stat.elsRcvFAN++;
8141 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
8144 case ELS_CMD_NVMEPRLI:
8145 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8146 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
8147 did, vport->port_state, ndlp->nlp_flag);
8149 phba->fc_stat.elsRcvPRLI++;
8150 if ((vport->port_state < LPFC_DISC_AUTH) &&
8151 (vport->fc_flag & FC_FABRIC)) {
8152 rjt_err = LSRJT_UNABLE_TPC;
8153 rjt_exp = LSEXP_NOTHING_MORE;
8156 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
8159 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8160 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
8161 did, vport->port_state, ndlp->nlp_flag);
8163 phba->fc_stat.elsRcvLIRR++;
8164 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
8169 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8170 "RCV RLS: did:x%x/ste:x%x flg:x%x",
8171 did, vport->port_state, ndlp->nlp_flag);
8173 phba->fc_stat.elsRcvRLS++;
8174 lpfc_els_rcv_rls(vport, elsiocb, ndlp);
8179 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8180 "RCV RPS: did:x%x/ste:x%x flg:x%x",
8181 did, vport->port_state, ndlp->nlp_flag);
8183 phba->fc_stat.elsRcvRPS++;
8184 lpfc_els_rcv_rps(vport, elsiocb, ndlp);
8189 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8190 "RCV RPL: did:x%x/ste:x%x flg:x%x",
8191 did, vport->port_state, ndlp->nlp_flag);
8193 phba->fc_stat.elsRcvRPL++;
8194 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
8199 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8200 "RCV RNID: did:x%x/ste:x%x flg:x%x",
8201 did, vport->port_state, ndlp->nlp_flag);
8203 phba->fc_stat.elsRcvRNID++;
8204 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
8209 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8210 "RCV RTV: did:x%x/ste:x%x flg:x%x",
8211 did, vport->port_state, ndlp->nlp_flag);
8212 phba->fc_stat.elsRcvRTV++;
8213 lpfc_els_rcv_rtv(vport, elsiocb, ndlp);
8218 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8219 "RCV RRQ: did:x%x/ste:x%x flg:x%x",
8220 did, vport->port_state, ndlp->nlp_flag);
8222 phba->fc_stat.elsRcvRRQ++;
8223 lpfc_els_rcv_rrq(vport, elsiocb, ndlp);
8228 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8229 "RCV ECHO: did:x%x/ste:x%x flg:x%x",
8230 did, vport->port_state, ndlp->nlp_flag);
8232 phba->fc_stat.elsRcvECHO++;
8233 lpfc_els_rcv_echo(vport, elsiocb, ndlp);
8238 /* receive this due to exchange closed */
8239 rjt_err = LSRJT_UNABLE_TPC;
8240 rjt_exp = LSEXP_INVALID_OX_RX;
8243 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8244 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
8245 cmd, did, vport->port_state);
8247 /* Unsupported ELS command, reject */
8248 rjt_err = LSRJT_CMD_UNSUPPORTED;
8249 rjt_exp = LSEXP_NOTHING_MORE;
8251 /* Unknown ELS command <elsCmd> received from NPORT <did> */
8252 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8253 "0115 Unknown ELS command x%x "
8254 "received from NPORT x%x\n", cmd, did);
8261 /* check if need to LS_RJT received ELS cmd */
8263 memset(&stat, 0, sizeof(stat));
8264 stat.un.b.lsRjtRsnCode = rjt_err;
8265 stat.un.b.lsRjtRsnCodeExp = rjt_exp;
8266 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
8270 lpfc_nlp_put(elsiocb->context1);
8271 elsiocb->context1 = NULL;
8273 /* Special case. Driver received an unsolicited command that
8274 * unsupportable given the driver's current state. Reset the
8275 * link and start over.
8278 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
8281 lpfc_linkdown(phba);
8282 lpfc_init_link(phba, mbox,
8284 phba->cfg_link_speed);
8285 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
8286 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
8287 mbox->vport = vport;
8288 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) ==
8290 mempool_free(mbox, phba->mbox_mem_pool);
8296 if (vport && !(vport->load_flag & FC_UNLOADING))
8297 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8298 "0111 Dropping received ELS cmd "
8299 "Data: x%x x%x x%x\n",
8300 icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout);
8301 phba->fc_stat.elsRcvDrop++;
8305 * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
8306 * @phba: pointer to lpfc hba data structure.
8307 * @pring: pointer to a SLI ring.
8308 * @elsiocb: pointer to lpfc els iocb data structure.
8310 * This routine is used to process an unsolicited event received from a SLI
8311 * (Service Level Interface) ring. The actual processing of the data buffer
8312 * associated with the unsolicited event is done by invoking the routine
8313 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
8314 * SLI ring on which the unsolicited event was received.
8317 lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
8318 struct lpfc_iocbq *elsiocb)
8320 struct lpfc_vport *vport = phba->pport;
8321 IOCB_t *icmd = &elsiocb->iocb;
8323 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
8324 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
8326 elsiocb->context1 = NULL;
8327 elsiocb->context2 = NULL;
8328 elsiocb->context3 = NULL;
8330 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
8331 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
8332 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
8333 (icmd->un.ulpWord[4] & IOERR_PARAM_MASK) ==
8334 IOERR_RCV_BUFFER_WAITING) {
8335 phba->fc_stat.NoRcvBuf++;
8336 /* Not enough posted buffers; Try posting more buffers */
8337 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
8338 lpfc_post_buffer(phba, pring, 0);
8342 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
8343 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
8344 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
8345 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
8346 vport = phba->pport;
8348 vport = lpfc_find_vport_by_vpid(phba,
8349 icmd->unsli3.rcvsli3.vpi);
8352 /* If there are no BDEs associated
8353 * with this IOCB, there is nothing to do.
8355 if (icmd->ulpBdeCount == 0)
8358 /* type of ELS cmd is first 32bit word
8361 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
8362 elsiocb->context2 = bdeBuf1;
8364 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
8365 icmd->un.cont64[0].addrLow);
8366 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
8370 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
8372 * The different unsolicited event handlers would tell us
8373 * if they are done with "mp" by setting context2 to NULL.
8375 if (elsiocb->context2) {
8376 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
8377 elsiocb->context2 = NULL;
8380 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
8381 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
8382 icmd->ulpBdeCount == 2) {
8383 elsiocb->context2 = bdeBuf2;
8384 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
8385 /* free mp if we are done with it */
8386 if (elsiocb->context2) {
8387 lpfc_in_buf_free(phba, elsiocb->context2);
8388 elsiocb->context2 = NULL;
8394 lpfc_start_fdmi(struct lpfc_vport *vport)
8396 struct lpfc_nodelist *ndlp;
8398 /* If this is the first time, allocate an ndlp and initialize
8399 * it. Otherwise, make sure the node is enabled and then do the
8402 ndlp = lpfc_findnode_did(vport, FDMI_DID);
8404 ndlp = lpfc_nlp_init(vport, FDMI_DID);
8406 ndlp->nlp_type |= NLP_FABRIC;
8411 if (!NLP_CHK_NODE_ACT(ndlp))
8412 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_NPR_NODE);
8415 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
8416 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
8421 * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
8422 * @phba: pointer to lpfc hba data structure.
8423 * @vport: pointer to a virtual N_Port data structure.
8425 * This routine issues a Port Login (PLOGI) to the Name Server with
8426 * State Change Request (SCR) for a @vport. This routine will create an
8427 * ndlp for the Name Server associated to the @vport if such node does
8428 * not already exist. The PLOGI to Name Server is issued by invoking the
8429 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
8430 * (FDMI) is configured to the @vport, a FDMI node will be created and
8431 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
8434 lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
8436 struct lpfc_nodelist *ndlp;
8437 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8440 * If lpfc_delay_discovery parameter is set and the clean address
8441 * bit is cleared and fc fabric parameters chenged, delay FC NPort
8444 spin_lock_irq(shost->host_lock);
8445 if (vport->fc_flag & FC_DISC_DELAYED) {
8446 spin_unlock_irq(shost->host_lock);
8447 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
8448 "3334 Delay fc port discovery for %d seconds\n",
8450 mod_timer(&vport->delayed_disc_tmo,
8451 jiffies + msecs_to_jiffies(1000 * phba->fc_ratov));
8454 spin_unlock_irq(shost->host_lock);
8456 ndlp = lpfc_findnode_did(vport, NameServer_DID);
8458 ndlp = lpfc_nlp_init(vport, NameServer_DID);
8460 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
8461 lpfc_disc_start(vport);
8464 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
8465 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8466 "0251 NameServer login: no memory\n");
8469 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
8470 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
8472 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
8473 lpfc_disc_start(vport);
8476 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
8477 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8478 "0348 NameServer login: node freed\n");
8482 ndlp->nlp_type |= NLP_FABRIC;
8484 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
8486 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
8487 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
8488 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8489 "0252 Cannot issue NameServer login\n");
8493 if ((phba->cfg_enable_SmartSAN ||
8494 (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) &&
8495 (vport->load_flag & FC_ALLOW_FDMI))
8496 lpfc_start_fdmi(vport);
8500 * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
8501 * @phba: pointer to lpfc hba data structure.
8502 * @pmb: pointer to the driver internal queue element for mailbox command.
8504 * This routine is the completion callback function to register new vport
8505 * mailbox command. If the new vport mailbox command completes successfully,
8506 * the fabric registration login shall be performed on physical port (the
8507 * new vport created is actually a physical port, with VPI 0) or the port
8508 * login to Name Server for State Change Request (SCR) will be performed
8509 * on virtual port (real virtual port, with VPI greater than 0).
8512 lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
8514 struct lpfc_vport *vport = pmb->vport;
8515 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8516 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
8517 MAILBOX_t *mb = &pmb->u.mb;
8520 spin_lock_irq(shost->host_lock);
8521 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
8522 spin_unlock_irq(shost->host_lock);
8524 if (mb->mbxStatus) {
8525 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
8526 "0915 Register VPI failed : Status: x%x"
8527 " upd bit: x%x \n", mb->mbxStatus,
8528 mb->un.varRegVpi.upd);
8529 if (phba->sli_rev == LPFC_SLI_REV4 &&
8530 mb->un.varRegVpi.upd)
8531 goto mbox_err_exit ;
8533 switch (mb->mbxStatus) {
8534 case 0x11: /* unsupported feature */
8535 case 0x9603: /* max_vpi exceeded */
8536 case 0x9602: /* Link event since CLEAR_LA */
8537 /* giving up on vport registration */
8538 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
8539 spin_lock_irq(shost->host_lock);
8540 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
8541 spin_unlock_irq(shost->host_lock);
8542 lpfc_can_disctmo(vport);
8544 /* If reg_vpi fail with invalid VPI status, re-init VPI */
8546 spin_lock_irq(shost->host_lock);
8547 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
8548 spin_unlock_irq(shost->host_lock);
8549 lpfc_init_vpi(phba, pmb, vport->vpi);
8551 pmb->mbox_cmpl = lpfc_init_vpi_cmpl;
8552 rc = lpfc_sli_issue_mbox(phba, pmb,
8554 if (rc == MBX_NOT_FINISHED) {
8555 lpfc_printf_vlog(vport,
8557 "2732 Failed to issue INIT_VPI"
8558 " mailbox command\n");
8565 /* Try to recover from this error */
8566 if (phba->sli_rev == LPFC_SLI_REV4)
8567 lpfc_sli4_unreg_all_rpis(vport);
8568 lpfc_mbx_unreg_vpi(vport);
8569 spin_lock_irq(shost->host_lock);
8570 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
8571 spin_unlock_irq(shost->host_lock);
8572 if (mb->mbxStatus == MBX_NOT_FINISHED)
8574 if ((vport->port_type == LPFC_PHYSICAL_PORT) &&
8575 !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG)) {
8576 if (phba->sli_rev == LPFC_SLI_REV4)
8577 lpfc_issue_init_vfi(vport);
8579 lpfc_initial_flogi(vport);
8581 lpfc_initial_fdisc(vport);
8586 spin_lock_irq(shost->host_lock);
8587 vport->vpi_state |= LPFC_VPI_REGISTERED;
8588 spin_unlock_irq(shost->host_lock);
8589 if (vport == phba->pport) {
8590 if (phba->sli_rev < LPFC_SLI_REV4)
8591 lpfc_issue_fabric_reglogin(vport);
8594 * If the physical port is instantiated using
8595 * FDISC, do not start vport discovery.
8597 if (vport->port_state != LPFC_FDISC)
8598 lpfc_start_fdiscs(phba);
8599 lpfc_do_scr_ns_plogi(phba, vport);
8602 lpfc_do_scr_ns_plogi(phba, vport);
8605 /* Now, we decrement the ndlp reference count held for this
8610 mempool_free(pmb, phba->mbox_mem_pool);
8615 * lpfc_register_new_vport - Register a new vport with a HBA
8616 * @phba: pointer to lpfc hba data structure.
8617 * @vport: pointer to a host virtual N_Port data structure.
8618 * @ndlp: pointer to a node-list data structure.
8620 * This routine registers the @vport as a new virtual port with a HBA.
8621 * It is done through a registering vpi mailbox command.
8624 lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
8625 struct lpfc_nodelist *ndlp)
8627 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8630 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
8632 lpfc_reg_vpi(vport, mbox);
8633 mbox->vport = vport;
8634 mbox->context2 = lpfc_nlp_get(ndlp);
8635 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
8636 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
8637 == MBX_NOT_FINISHED) {
8638 /* mailbox command not success, decrement ndlp
8639 * reference count for this command
8642 mempool_free(mbox, phba->mbox_mem_pool);
8644 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
8645 "0253 Register VPI: Can't send mbox\n");
8649 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
8650 "0254 Register VPI: no memory\n");
8656 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
8657 spin_lock_irq(shost->host_lock);
8658 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
8659 spin_unlock_irq(shost->host_lock);
8664 * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer
8665 * @phba: pointer to lpfc hba data structure.
8667 * This routine cancels the retry delay timers to all the vports.
8670 lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba)
8672 struct lpfc_vport **vports;
8673 struct lpfc_nodelist *ndlp;
8674 uint32_t link_state;
8677 /* Treat this failure as linkdown for all vports */
8678 link_state = phba->link_state;
8679 lpfc_linkdown(phba);
8680 phba->link_state = link_state;
8682 vports = lpfc_create_vport_work_array(phba);
8685 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
8686 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
8688 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
8689 lpfc_els_flush_cmd(vports[i]);
8691 lpfc_destroy_vport_work_array(phba, vports);
8696 * lpfc_retry_pport_discovery - Start timer to retry FLOGI.
8697 * @phba: pointer to lpfc hba data structure.
8699 * This routine abort all pending discovery commands and
8700 * start a timer to retry FLOGI for the physical port
8704 lpfc_retry_pport_discovery(struct lpfc_hba *phba)
8706 struct lpfc_nodelist *ndlp;
8707 struct Scsi_Host *shost;
8709 /* Cancel the all vports retry delay retry timers */
8710 lpfc_cancel_all_vport_retry_delay_timer(phba);
8712 /* If fabric require FLOGI, then re-instantiate physical login */
8713 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
8717 shost = lpfc_shost_from_vport(phba->pport);
8718 mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000));
8719 spin_lock_irq(shost->host_lock);
8720 ndlp->nlp_flag |= NLP_DELAY_TMO;
8721 spin_unlock_irq(shost->host_lock);
8722 ndlp->nlp_last_elscmd = ELS_CMD_FLOGI;
8723 phba->pport->port_state = LPFC_FLOGI;
8728 * lpfc_fabric_login_reqd - Check if FLOGI required.
8729 * @phba: pointer to lpfc hba data structure.
8730 * @cmdiocb: pointer to FDISC command iocb.
8731 * @rspiocb: pointer to FDISC response iocb.
8733 * This routine checks if a FLOGI is reguired for FDISC
8737 lpfc_fabric_login_reqd(struct lpfc_hba *phba,
8738 struct lpfc_iocbq *cmdiocb,
8739 struct lpfc_iocbq *rspiocb)
8742 if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) ||
8743 (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED))
8750 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
8751 * @phba: pointer to lpfc hba data structure.
8752 * @cmdiocb: pointer to lpfc command iocb data structure.
8753 * @rspiocb: pointer to lpfc response iocb data structure.
8755 * This routine is the completion callback function to a Fabric Discover
8756 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
8757 * single threaded, each FDISC completion callback function will reset
8758 * the discovery timer for all vports such that the timers will not get
8759 * unnecessary timeout. The function checks the FDISC IOCB status. If error
8760 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
8761 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
8762 * assigned to the vport has been changed with the completion of the FDISC
8763 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
8764 * are unregistered from the HBA, and then the lpfc_register_new_vport()
8765 * routine is invoked to register new vport with the HBA. Otherwise, the
8766 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
8767 * Server for State Change Request (SCR).
8770 lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
8771 struct lpfc_iocbq *rspiocb)
8773 struct lpfc_vport *vport = cmdiocb->vport;
8774 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8775 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
8776 struct lpfc_nodelist *np;
8777 struct lpfc_nodelist *next_np;
8778 IOCB_t *irsp = &rspiocb->iocb;
8779 struct lpfc_iocbq *piocb;
8780 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
8781 struct serv_parm *sp;
8782 uint8_t fabric_param_changed;
8784 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
8785 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
8786 irsp->ulpStatus, irsp->un.ulpWord[4],
8788 /* Since all FDISCs are being single threaded, we
8789 * must reset the discovery timer for ALL vports
8790 * waiting to send FDISC when one completes.
8792 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
8793 lpfc_set_disctmo(piocb->vport);
8796 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
8797 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
8798 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
8800 if (irsp->ulpStatus) {
8802 if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) {
8803 lpfc_retry_pport_discovery(phba);
8807 /* Check for retry */
8808 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
8811 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8812 "0126 FDISC failed. (x%x/x%x)\n",
8813 irsp->ulpStatus, irsp->un.ulpWord[4]);
8816 spin_lock_irq(shost->host_lock);
8817 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
8818 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
8819 vport->fc_flag |= FC_FABRIC;
8820 if (vport->phba->fc_topology == LPFC_TOPOLOGY_LOOP)
8821 vport->fc_flag |= FC_PUBLIC_LOOP;
8822 spin_unlock_irq(shost->host_lock);
8824 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
8825 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
8826 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
8829 sp = prsp->virt + sizeof(uint32_t);
8830 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
8831 memcpy(&vport->fabric_portname, &sp->portName,
8832 sizeof(struct lpfc_name));
8833 memcpy(&vport->fabric_nodename, &sp->nodeName,
8834 sizeof(struct lpfc_name));
8835 if (fabric_param_changed &&
8836 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
8837 /* If our NportID changed, we need to ensure all
8838 * remaining NPORTs get unreg_login'ed so we can
8841 list_for_each_entry_safe(np, next_np,
8842 &vport->fc_nodes, nlp_listp) {
8843 if (!NLP_CHK_NODE_ACT(ndlp) ||
8844 (np->nlp_state != NLP_STE_NPR_NODE) ||
8845 !(np->nlp_flag & NLP_NPR_ADISC))
8847 spin_lock_irq(shost->host_lock);
8848 np->nlp_flag &= ~NLP_NPR_ADISC;
8849 spin_unlock_irq(shost->host_lock);
8850 lpfc_unreg_rpi(vport, np);
8852 lpfc_cleanup_pending_mbox(vport);
8854 if (phba->sli_rev == LPFC_SLI_REV4)
8855 lpfc_sli4_unreg_all_rpis(vport);
8857 lpfc_mbx_unreg_vpi(vport);
8858 spin_lock_irq(shost->host_lock);
8859 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
8860 if (phba->sli_rev == LPFC_SLI_REV4)
8861 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
8863 vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG;
8864 spin_unlock_irq(shost->host_lock);
8865 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
8866 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
8868 * Driver needs to re-reg VPI in order for f/w
8869 * to update the MAC address.
8871 lpfc_register_new_vport(phba, vport, ndlp);
8875 if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)
8876 lpfc_issue_init_vpi(vport);
8877 else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
8878 lpfc_register_new_vport(phba, vport, ndlp);
8880 lpfc_do_scr_ns_plogi(phba, vport);
8883 if (vport->fc_vport &&
8884 (vport->fc_vport->vport_state != FC_VPORT_NO_FABRIC_RSCS))
8885 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
8886 /* Cancel discovery timer */
8887 lpfc_can_disctmo(vport);
8890 lpfc_els_free_iocb(phba, cmdiocb);
8894 * lpfc_issue_els_fdisc - Issue a fdisc iocb command
8895 * @vport: pointer to a virtual N_Port data structure.
8896 * @ndlp: pointer to a node-list data structure.
8897 * @retry: number of retries to the command IOCB.
8899 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
8900 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
8901 * routine to issue the IOCB, which makes sure only one outstanding fabric
8902 * IOCB will be sent off HBA at any given time.
8904 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
8905 * will be incremented by 1 for holding the ndlp and the reference to ndlp
8906 * will be stored into the context1 field of the IOCB for the completion
8907 * callback function to the FDISC ELS command.
8910 * 0 - Successfully issued fdisc iocb command
8911 * 1 - Failed to issue fdisc iocb command
8914 lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
8917 struct lpfc_hba *phba = vport->phba;
8919 struct lpfc_iocbq *elsiocb;
8920 struct serv_parm *sp;
8923 int did = ndlp->nlp_DID;
8926 vport->port_state = LPFC_FDISC;
8927 vport->fc_myDID = 0;
8928 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
8929 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
8932 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
8933 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8934 "0255 Issue FDISC: no IOCB\n");
8938 icmd = &elsiocb->iocb;
8939 icmd->un.elsreq64.myID = 0;
8940 icmd->un.elsreq64.fl = 1;
8943 * SLI3 ports require a different context type value than SLI4.
8944 * Catch SLI3 ports here and override the prep.
8946 if (phba->sli_rev == LPFC_SLI_REV3) {
8951 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
8952 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
8953 pcmd += sizeof(uint32_t); /* CSP Word 1 */
8954 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
8955 sp = (struct serv_parm *) pcmd;
8956 /* Setup CSPs accordingly for Fabric */
8957 sp->cmn.e_d_tov = 0;
8958 sp->cmn.w2.r_a_tov = 0;
8959 sp->cmn.virtual_fabric_support = 0;
8960 sp->cls1.classValid = 0;
8961 sp->cls2.seqDelivery = 1;
8962 sp->cls3.seqDelivery = 1;
8964 pcmd += sizeof(uint32_t); /* CSP Word 2 */
8965 pcmd += sizeof(uint32_t); /* CSP Word 3 */
8966 pcmd += sizeof(uint32_t); /* CSP Word 4 */
8967 pcmd += sizeof(uint32_t); /* Port Name */
8968 memcpy(pcmd, &vport->fc_portname, 8);
8969 pcmd += sizeof(uint32_t); /* Node Name */
8970 pcmd += sizeof(uint32_t); /* Node Name */
8971 memcpy(pcmd, &vport->fc_nodename, 8);
8972 sp->cmn.valid_vendor_ver_level = 0;
8973 memset(sp->un.vendorVersion, 0, sizeof(sp->un.vendorVersion));
8974 lpfc_set_disctmo(vport);
8976 phba->fc_stat.elsXmitFDISC++;
8977 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
8979 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
8980 "Issue FDISC: did:x%x",
8983 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
8984 if (rc == IOCB_ERROR) {
8985 lpfc_els_free_iocb(phba, elsiocb);
8986 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
8987 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8988 "0256 Issue FDISC: Cannot send IOCB\n");
8991 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
8996 * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
8997 * @phba: pointer to lpfc hba data structure.
8998 * @cmdiocb: pointer to lpfc command iocb data structure.
8999 * @rspiocb: pointer to lpfc response iocb data structure.
9001 * This routine is the completion callback function to the issuing of a LOGO
9002 * ELS command off a vport. It frees the command IOCB and then decrement the
9003 * reference count held on ndlp for this completion function, indicating that
9004 * the reference to the ndlp is no long needed. Note that the
9005 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
9006 * callback function and an additional explicit ndlp reference decrementation
9007 * will trigger the actual release of the ndlp.
9010 lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
9011 struct lpfc_iocbq *rspiocb)
9013 struct lpfc_vport *vport = cmdiocb->vport;
9015 struct lpfc_nodelist *ndlp;
9016 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
9018 ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
9019 irsp = &rspiocb->iocb;
9020 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
9021 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
9022 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
9024 lpfc_els_free_iocb(phba, cmdiocb);
9025 vport->unreg_vpi_cmpl = VPORT_ERROR;
9027 /* Trigger the release of the ndlp after logo */
9030 /* NPIV LOGO completes to NPort <nlp_DID> */
9031 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
9032 "2928 NPIV LOGO completes to NPort x%x "
9033 "Data: x%x x%x x%x x%x\n",
9034 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
9035 irsp->ulpTimeout, vport->num_disc_nodes);
9037 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
9038 spin_lock_irq(shost->host_lock);
9039 vport->fc_flag &= ~FC_NDISC_ACTIVE;
9040 vport->fc_flag &= ~FC_FABRIC;
9041 spin_unlock_irq(shost->host_lock);
9042 lpfc_can_disctmo(vport);
9047 * lpfc_issue_els_npiv_logo - Issue a logo off a vport
9048 * @vport: pointer to a virtual N_Port data structure.
9049 * @ndlp: pointer to a node-list data structure.
9051 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
9053 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
9054 * will be incremented by 1 for holding the ndlp and the reference to ndlp
9055 * will be stored into the context1 field of the IOCB for the completion
9056 * callback function to the LOGO ELS command.
9059 * 0 - Successfully issued logo off the @vport
9060 * 1 - Failed to issue logo off the @vport
9063 lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
9065 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
9066 struct lpfc_hba *phba = vport->phba;
9067 struct lpfc_iocbq *elsiocb;
9071 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
9072 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
9077 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
9078 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
9079 pcmd += sizeof(uint32_t);
9081 /* Fill in LOGO payload */
9082 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
9083 pcmd += sizeof(uint32_t);
9084 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
9086 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
9087 "Issue LOGO npiv did:x%x flg:x%x",
9088 ndlp->nlp_DID, ndlp->nlp_flag, 0);
9090 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
9091 spin_lock_irq(shost->host_lock);
9092 ndlp->nlp_flag |= NLP_LOGO_SND;
9093 spin_unlock_irq(shost->host_lock);
9094 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
9096 spin_lock_irq(shost->host_lock);
9097 ndlp->nlp_flag &= ~NLP_LOGO_SND;
9098 spin_unlock_irq(shost->host_lock);
9099 lpfc_els_free_iocb(phba, elsiocb);
9106 * lpfc_fabric_block_timeout - Handler function to the fabric block timer
9107 * @ptr: holder for the timer function associated data.
9109 * This routine is invoked by the fabric iocb block timer after
9110 * timeout. It posts the fabric iocb block timeout event by setting the
9111 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
9112 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
9113 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
9114 * posted event WORKER_FABRIC_BLOCK_TMO.
9117 lpfc_fabric_block_timeout(struct timer_list *t)
9119 struct lpfc_hba *phba = from_timer(phba, t, fabric_block_timer);
9120 unsigned long iflags;
9121 uint32_t tmo_posted;
9123 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
9124 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
9126 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
9127 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
9130 lpfc_worker_wake_up(phba);
9135 * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
9136 * @phba: pointer to lpfc hba data structure.
9138 * This routine issues one fabric iocb from the driver internal list to
9139 * the HBA. It first checks whether it's ready to issue one fabric iocb to
9140 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
9141 * remove one pending fabric iocb from the driver internal list and invokes
9142 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
9145 lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
9147 struct lpfc_iocbq *iocb;
9148 unsigned long iflags;
9154 spin_lock_irqsave(&phba->hbalock, iflags);
9155 /* Post any pending iocb to the SLI layer */
9156 if (atomic_read(&phba->fabric_iocb_count) == 0) {
9157 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
9160 /* Increment fabric iocb count to hold the position */
9161 atomic_inc(&phba->fabric_iocb_count);
9163 spin_unlock_irqrestore(&phba->hbalock, iflags);
9165 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
9166 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
9167 iocb->iocb_flag |= LPFC_IO_FABRIC;
9169 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
9170 "Fabric sched1: ste:x%x",
9171 iocb->vport->port_state, 0, 0);
9173 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
9175 if (ret == IOCB_ERROR) {
9176 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
9177 iocb->fabric_iocb_cmpl = NULL;
9178 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
9180 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
9181 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
9182 iocb->iocb_cmpl(phba, iocb, iocb);
9184 atomic_dec(&phba->fabric_iocb_count);
9193 * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
9194 * @phba: pointer to lpfc hba data structure.
9196 * This routine unblocks the issuing fabric iocb command. The function
9197 * will clear the fabric iocb block bit and then invoke the routine
9198 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
9199 * from the driver internal fabric iocb list.
9202 lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
9204 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
9206 lpfc_resume_fabric_iocbs(phba);
9211 * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
9212 * @phba: pointer to lpfc hba data structure.
9214 * This routine blocks the issuing fabric iocb for a specified amount of
9215 * time (currently 100 ms). This is done by set the fabric iocb block bit
9216 * and set up a timeout timer for 100ms. When the block bit is set, no more
9217 * fabric iocb will be issued out of the HBA.
9220 lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
9224 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
9225 /* Start a timer to unblock fabric iocbs after 100ms */
9227 mod_timer(&phba->fabric_block_timer,
9228 jiffies + msecs_to_jiffies(100));
9234 * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
9235 * @phba: pointer to lpfc hba data structure.
9236 * @cmdiocb: pointer to lpfc command iocb data structure.
9237 * @rspiocb: pointer to lpfc response iocb data structure.
9239 * This routine is the callback function that is put to the fabric iocb's
9240 * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
9241 * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
9242 * function first restores and invokes the original iocb's callback function
9243 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
9244 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
9247 lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
9248 struct lpfc_iocbq *rspiocb)
9252 BUG_ON((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC);
9254 switch (rspiocb->iocb.ulpStatus) {
9255 case IOSTAT_NPORT_RJT:
9256 case IOSTAT_FABRIC_RJT:
9257 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
9258 lpfc_block_fabric_iocbs(phba);
9262 case IOSTAT_NPORT_BSY:
9263 case IOSTAT_FABRIC_BSY:
9264 lpfc_block_fabric_iocbs(phba);
9268 stat.un.lsRjtError =
9269 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
9270 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
9271 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
9272 lpfc_block_fabric_iocbs(phba);
9276 BUG_ON(atomic_read(&phba->fabric_iocb_count) == 0);
9278 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
9279 cmdiocb->fabric_iocb_cmpl = NULL;
9280 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
9281 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
9283 atomic_dec(&phba->fabric_iocb_count);
9284 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
9285 /* Post any pending iocbs to HBA */
9286 lpfc_resume_fabric_iocbs(phba);
9291 * lpfc_issue_fabric_iocb - Issue a fabric iocb command
9292 * @phba: pointer to lpfc hba data structure.
9293 * @iocb: pointer to lpfc command iocb data structure.
9295 * This routine is used as the top-level API for issuing a fabric iocb command
9296 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
9297 * function makes sure that only one fabric bound iocb will be outstanding at
9298 * any given time. As such, this function will first check to see whether there
9299 * is already an outstanding fabric iocb on the wire. If so, it will put the
9300 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
9301 * issued later. Otherwise, it will issue the iocb on the wire and update the
9302 * fabric iocb count it indicate that there is one fabric iocb on the wire.
9304 * Note, this implementation has a potential sending out fabric IOCBs out of
9305 * order. The problem is caused by the construction of the "ready" boolen does
9306 * not include the condition that the internal fabric IOCB list is empty. As
9307 * such, it is possible a fabric IOCB issued by this routine might be "jump"
9308 * ahead of the fabric IOCBs in the internal list.
9311 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
9312 * IOCB_ERROR - failed to issue fabric iocb
9315 lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
9317 unsigned long iflags;
9321 BUG_ON(atomic_read(&phba->fabric_iocb_count) > 1);
9323 spin_lock_irqsave(&phba->hbalock, iflags);
9324 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
9325 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
9328 /* Increment fabric iocb count to hold the position */
9329 atomic_inc(&phba->fabric_iocb_count);
9330 spin_unlock_irqrestore(&phba->hbalock, iflags);
9332 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
9333 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
9334 iocb->iocb_flag |= LPFC_IO_FABRIC;
9336 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
9337 "Fabric sched2: ste:x%x",
9338 iocb->vport->port_state, 0, 0);
9340 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
9342 if (ret == IOCB_ERROR) {
9343 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
9344 iocb->fabric_iocb_cmpl = NULL;
9345 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
9346 atomic_dec(&phba->fabric_iocb_count);
9349 spin_lock_irqsave(&phba->hbalock, iflags);
9350 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
9351 spin_unlock_irqrestore(&phba->hbalock, iflags);
9358 * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
9359 * @vport: pointer to a virtual N_Port data structure.
9361 * This routine aborts all the IOCBs associated with a @vport from the
9362 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
9363 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
9364 * list, removes each IOCB associated with the @vport off the list, set the
9365 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
9366 * associated with the IOCB.
9368 static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
9370 LIST_HEAD(completions);
9371 struct lpfc_hba *phba = vport->phba;
9372 struct lpfc_iocbq *tmp_iocb, *piocb;
9374 spin_lock_irq(&phba->hbalock);
9375 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
9378 if (piocb->vport != vport)
9381 list_move_tail(&piocb->list, &completions);
9383 spin_unlock_irq(&phba->hbalock);
9385 /* Cancel all the IOCBs from the completions list */
9386 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
9391 * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
9392 * @ndlp: pointer to a node-list data structure.
9394 * This routine aborts all the IOCBs associated with an @ndlp from the
9395 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
9396 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
9397 * list, removes each IOCB associated with the @ndlp off the list, set the
9398 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
9399 * associated with the IOCB.
9401 void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
9403 LIST_HEAD(completions);
9404 struct lpfc_hba *phba = ndlp->phba;
9405 struct lpfc_iocbq *tmp_iocb, *piocb;
9406 struct lpfc_sli_ring *pring;
9408 pring = lpfc_phba_elsring(phba);
9410 if (unlikely(!pring))
9413 spin_lock_irq(&phba->hbalock);
9414 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
9416 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
9418 list_move_tail(&piocb->list, &completions);
9421 spin_unlock_irq(&phba->hbalock);
9423 /* Cancel all the IOCBs from the completions list */
9424 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
9429 * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
9430 * @phba: pointer to lpfc hba data structure.
9432 * This routine aborts all the IOCBs currently on the driver internal
9433 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
9434 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
9435 * list, removes IOCBs off the list, set the status feild to
9436 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
9439 void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
9441 LIST_HEAD(completions);
9443 spin_lock_irq(&phba->hbalock);
9444 list_splice_init(&phba->fabric_iocb_list, &completions);
9445 spin_unlock_irq(&phba->hbalock);
9447 /* Cancel all the IOCBs from the completions list */
9448 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
9453 * lpfc_sli4_vport_delete_els_xri_aborted -Remove all ndlp references for vport
9454 * @vport: pointer to lpfc vport data structure.
9456 * This routine is invoked by the vport cleanup for deletions and the cleanup
9457 * for an ndlp on removal.
9460 lpfc_sli4_vport_delete_els_xri_aborted(struct lpfc_vport *vport)
9462 struct lpfc_hba *phba = vport->phba;
9463 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
9464 unsigned long iflag = 0;
9466 spin_lock_irqsave(&phba->hbalock, iflag);
9467 spin_lock(&phba->sli4_hba.sgl_list_lock);
9468 list_for_each_entry_safe(sglq_entry, sglq_next,
9469 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
9470 if (sglq_entry->ndlp && sglq_entry->ndlp->vport == vport)
9471 sglq_entry->ndlp = NULL;
9473 spin_unlock(&phba->sli4_hba.sgl_list_lock);
9474 spin_unlock_irqrestore(&phba->hbalock, iflag);
9479 * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
9480 * @phba: pointer to lpfc hba data structure.
9481 * @axri: pointer to the els xri abort wcqe structure.
9483 * This routine is invoked by the worker thread to process a SLI4 slow-path
9487 lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba,
9488 struct sli4_wcqe_xri_aborted *axri)
9490 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
9491 uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri);
9494 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
9495 unsigned long iflag = 0;
9496 struct lpfc_nodelist *ndlp;
9497 struct lpfc_sli_ring *pring;
9499 pring = lpfc_phba_elsring(phba);
9501 spin_lock_irqsave(&phba->hbalock, iflag);
9502 spin_lock(&phba->sli4_hba.sgl_list_lock);
9503 list_for_each_entry_safe(sglq_entry, sglq_next,
9504 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
9505 if (sglq_entry->sli4_xritag == xri) {
9506 list_del(&sglq_entry->list);
9507 ndlp = sglq_entry->ndlp;
9508 sglq_entry->ndlp = NULL;
9509 list_add_tail(&sglq_entry->list,
9510 &phba->sli4_hba.lpfc_els_sgl_list);
9511 sglq_entry->state = SGL_FREED;
9512 spin_unlock(&phba->sli4_hba.sgl_list_lock);
9513 spin_unlock_irqrestore(&phba->hbalock, iflag);
9514 lpfc_set_rrq_active(phba, ndlp,
9515 sglq_entry->sli4_lxritag,
9518 /* Check if TXQ queue needs to be serviced */
9519 if (pring && !list_empty(&pring->txq))
9520 lpfc_worker_wake_up(phba);
9524 spin_unlock(&phba->sli4_hba.sgl_list_lock);
9525 lxri = lpfc_sli4_xri_inrange(phba, xri);
9526 if (lxri == NO_XRI) {
9527 spin_unlock_irqrestore(&phba->hbalock, iflag);
9530 spin_lock(&phba->sli4_hba.sgl_list_lock);
9531 sglq_entry = __lpfc_get_active_sglq(phba, lxri);
9532 if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) {
9533 spin_unlock(&phba->sli4_hba.sgl_list_lock);
9534 spin_unlock_irqrestore(&phba->hbalock, iflag);
9537 sglq_entry->state = SGL_XRI_ABORTED;
9538 spin_unlock(&phba->sli4_hba.sgl_list_lock);
9539 spin_unlock_irqrestore(&phba->hbalock, iflag);
9543 /* lpfc_sli_abts_recover_port - Recover a port that failed a BLS_ABORT req.
9544 * @vport: pointer to virtual port object.
9545 * @ndlp: nodelist pointer for the impacted node.
9547 * The driver calls this routine in response to an SLI4 XRI ABORT CQE
9548 * or an SLI3 ASYNC_STATUS_CN event from the port. For either event,
9549 * the driver is required to send a LOGO to the remote node before it
9550 * attempts to recover its login to the remote node.
9553 lpfc_sli_abts_recover_port(struct lpfc_vport *vport,
9554 struct lpfc_nodelist *ndlp)
9556 struct Scsi_Host *shost;
9557 struct lpfc_hba *phba;
9558 unsigned long flags = 0;
9560 shost = lpfc_shost_from_vport(vport);
9562 if (ndlp->nlp_state != NLP_STE_MAPPED_NODE) {
9563 lpfc_printf_log(phba, KERN_INFO,
9564 LOG_SLI, "3093 No rport recovery needed. "
9565 "rport in state 0x%x\n", ndlp->nlp_state);
9568 lpfc_printf_log(phba, KERN_ERR,
9569 LOG_ELS | LOG_FCP_ERROR | LOG_NVME_IOERR,
9570 "3094 Start rport recovery on shost id 0x%x "
9571 "fc_id 0x%06x vpi 0x%x rpi 0x%x state 0x%x "
9573 shost->host_no, ndlp->nlp_DID,
9574 vport->vpi, ndlp->nlp_rpi, ndlp->nlp_state,
9577 * The rport is not responding. Remove the FCP-2 flag to prevent
9578 * an ADISC in the follow-up recovery code.
9580 spin_lock_irqsave(shost->host_lock, flags);
9581 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
9582 ndlp->nlp_flag |= NLP_ISSUE_LOGO;
9583 spin_unlock_irqrestore(shost->host_lock, flags);
9584 lpfc_unreg_rpi(vport, ndlp);