1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2017-2020 Broadcom. All Rights Reserved. The term *
5 * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. *
6 * Copyright (C) 2004-2016 Emulex. All rights reserved. *
7 * EMULEX and SLI are trademarks of Emulex. *
9 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
11 * This program is free software; you can redistribute it and/or *
12 * modify it under the terms of version 2 of the GNU General *
13 * Public License as published by the Free Software Foundation. *
14 * This program is distributed in the hope that it will be useful. *
15 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
16 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
17 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
18 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
19 * TO BE LEGALLY INVALID. See the GNU General Public License for *
20 * more details, a copy of which can be found in the file COPYING *
21 * included with this package. *
22 *******************************************************************/
23 /* See Fibre Channel protocol T11 FC-LS for details */
24 #include <linux/blkdev.h>
25 #include <linux/pci.h>
26 #include <linux/slab.h>
27 #include <linux/interrupt.h>
29 #include <scsi/scsi.h>
30 #include <scsi/scsi_device.h>
31 #include <scsi/scsi_host.h>
32 #include <scsi/scsi_transport_fc.h>
33 #include <uapi/scsi/fc/fc_fs.h>
34 #include <uapi/scsi/fc/fc_els.h>
39 #include "lpfc_sli4.h"
41 #include "lpfc_disc.h"
42 #include "lpfc_scsi.h"
44 #include "lpfc_logmsg.h"
45 #include "lpfc_crtn.h"
46 #include "lpfc_vport.h"
47 #include "lpfc_debugfs.h"
49 static int lpfc_els_retry(struct lpfc_hba *, struct lpfc_iocbq *,
51 static void lpfc_cmpl_fabric_iocb(struct lpfc_hba *, struct lpfc_iocbq *,
53 static void lpfc_fabric_abort_vport(struct lpfc_vport *vport);
54 static int lpfc_issue_els_fdisc(struct lpfc_vport *vport,
55 struct lpfc_nodelist *ndlp, uint8_t retry);
56 static int lpfc_issue_fabric_iocb(struct lpfc_hba *phba,
57 struct lpfc_iocbq *iocb);
59 static int lpfc_max_els_tries = 3;
62 * lpfc_els_chk_latt - Check host link attention event for a vport
63 * @vport: pointer to a host virtual N_Port data structure.
65 * This routine checks whether there is an outstanding host link
66 * attention event during the discovery process with the @vport. It is done
67 * by reading the HBA's Host Attention (HA) register. If there is any host
68 * link attention events during this @vport's discovery process, the @vport
69 * shall be marked as FC_ABORT_DISCOVERY, a host link attention clear shall
70 * be issued if the link state is not already in host link cleared state,
71 * and a return code shall indicate whether the host link attention event
74 * Note that, if either the host link is in state LPFC_LINK_DOWN or @vport
75 * state in LPFC_VPORT_READY, the request for checking host link attention
76 * event will be ignored and a return code shall indicate no host link
77 * attention event had happened.
80 * 0 - no host link attention event happened
81 * 1 - host link attention event happened
84 lpfc_els_chk_latt(struct lpfc_vport *vport)
86 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
87 struct lpfc_hba *phba = vport->phba;
90 if (vport->port_state >= LPFC_VPORT_READY ||
91 phba->link_state == LPFC_LINK_DOWN ||
92 phba->sli_rev > LPFC_SLI_REV3)
95 /* Read the HBA Host Attention Register */
96 if (lpfc_readl(phba->HAregaddr, &ha_copy))
99 if (!(ha_copy & HA_LATT))
102 /* Pending Link Event during Discovery */
103 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
104 "0237 Pending Link Event during "
105 "Discovery: State x%x\n",
106 phba->pport->port_state);
108 /* CLEAR_LA should re-enable link attention events and
109 * we should then immediately take a LATT event. The
110 * LATT processing should call lpfc_linkdown() which
111 * will cleanup any left over in-progress discovery
114 spin_lock_irq(shost->host_lock);
115 vport->fc_flag |= FC_ABORT_DISCOVERY;
116 spin_unlock_irq(shost->host_lock);
118 if (phba->link_state != LPFC_CLEAR_LA)
119 lpfc_issue_clear_la(phba, vport);
125 * lpfc_prep_els_iocb - Allocate and prepare a lpfc iocb data structure
126 * @vport: pointer to a host virtual N_Port data structure.
127 * @expectRsp: flag indicating whether response is expected.
128 * @cmdSize: size of the ELS command.
129 * @retry: number of retries to the command IOCB when it fails.
130 * @ndlp: pointer to a node-list data structure.
131 * @did: destination identifier.
132 * @elscmd: the ELS command code.
134 * This routine is used for allocating a lpfc-IOCB data structure from
135 * the driver lpfc-IOCB free-list and prepare the IOCB with the parameters
136 * passed into the routine for discovery state machine to issue an Extended
137 * Link Service (ELS) commands. It is a generic lpfc-IOCB allocation
138 * and preparation routine that is used by all the discovery state machine
139 * routines and the ELS command-specific fields will be later set up by
140 * the individual discovery machine routines after calling this routine
141 * allocating and preparing a generic IOCB data structure. It fills in the
142 * Buffer Descriptor Entries (BDEs), allocates buffers for both command
143 * payload and response payload (if expected). The reference count on the
144 * ndlp is incremented by 1 and the reference to the ndlp is put into
145 * context1 of the IOCB data structure for this IOCB to hold the ndlp
146 * reference for the command's callback function to access later.
149 * Pointer to the newly allocated/prepared els iocb data structure
150 * NULL - when els iocb data structure allocation/preparation failed
153 lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp,
154 uint16_t cmdSize, uint8_t retry,
155 struct lpfc_nodelist *ndlp, uint32_t did,
158 struct lpfc_hba *phba = vport->phba;
159 struct lpfc_iocbq *elsiocb;
160 struct lpfc_dmabuf *pcmd, *prsp, *pbuflist;
161 struct ulp_bde64 *bpl;
165 if (!lpfc_is_link_up(phba))
168 /* Allocate buffer for command iocb */
169 elsiocb = lpfc_sli_get_iocbq(phba);
175 * If this command is for fabric controller and HBA running
176 * in FIP mode send FLOGI, FDISC and LOGO as FIP frames.
178 if ((did == Fabric_DID) &&
179 (phba->hba_flag & HBA_FIP_SUPPORT) &&
180 ((elscmd == ELS_CMD_FLOGI) ||
181 (elscmd == ELS_CMD_FDISC) ||
182 (elscmd == ELS_CMD_LOGO)))
185 elsiocb->iocb_flag |=
186 ((LPFC_ELS_ID_FLOGI << LPFC_FIP_ELS_ID_SHIFT)
187 & LPFC_FIP_ELS_ID_MASK);
190 elsiocb->iocb_flag |=
191 ((LPFC_ELS_ID_FDISC << LPFC_FIP_ELS_ID_SHIFT)
192 & LPFC_FIP_ELS_ID_MASK);
195 elsiocb->iocb_flag |=
196 ((LPFC_ELS_ID_LOGO << LPFC_FIP_ELS_ID_SHIFT)
197 & LPFC_FIP_ELS_ID_MASK);
201 elsiocb->iocb_flag &= ~LPFC_FIP_ELS_ID_MASK;
203 icmd = &elsiocb->iocb;
205 /* fill in BDEs for command */
206 /* Allocate buffer for command payload */
207 pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
209 pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys);
210 if (!pcmd || !pcmd->virt)
211 goto els_iocb_free_pcmb_exit;
213 INIT_LIST_HEAD(&pcmd->list);
215 /* Allocate buffer for response payload */
217 prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
219 prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
221 if (!prsp || !prsp->virt)
222 goto els_iocb_free_prsp_exit;
223 INIT_LIST_HEAD(&prsp->list);
227 /* Allocate buffer for Buffer ptr list */
228 pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
230 pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
232 if (!pbuflist || !pbuflist->virt)
233 goto els_iocb_free_pbuf_exit;
235 INIT_LIST_HEAD(&pbuflist->list);
238 icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
239 icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
240 icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
241 icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64));
243 icmd->un.elsreq64.remoteID = did; /* DID */
244 icmd->ulpCommand = CMD_ELS_REQUEST64_CR;
245 if (elscmd == ELS_CMD_FLOGI)
246 icmd->ulpTimeout = FF_DEF_RATOV * 2;
247 else if (elscmd == ELS_CMD_LOGO)
248 icmd->ulpTimeout = phba->fc_ratov;
250 icmd->ulpTimeout = phba->fc_ratov * 2;
252 icmd->un.xseq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
253 icmd->un.xseq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
254 icmd->un.xseq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
255 icmd->un.xseq64.bdl.bdeSize = sizeof(struct ulp_bde64);
256 icmd->un.xseq64.xmit_els_remoteID = did; /* DID */
257 icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX;
259 icmd->ulpBdeCount = 1;
261 icmd->ulpClass = CLASS3;
264 * If we have NPIV enabled, we want to send ELS traffic by VPI.
265 * For SLI4, since the driver controls VPIs we also want to include
266 * all ELS pt2pt protocol traffic as well.
268 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) ||
269 ((phba->sli_rev == LPFC_SLI_REV4) &&
270 (vport->fc_flag & FC_PT2PT))) {
273 icmd->un.elsreq64.myID = vport->fc_myDID;
275 /* For ELS_REQUEST64_CR, use the VPI by default */
276 icmd->ulpContext = phba->vpi_ids[vport->vpi];
280 /* The CT field must be 0=INVALID_RPI for the ECHO cmd */
281 if (elscmd == ELS_CMD_ECHO)
282 icmd->ulpCt_l = 0; /* context = invalid RPI */
284 icmd->ulpCt_l = 1; /* context = VPI */
287 bpl = (struct ulp_bde64 *) pbuflist->virt;
288 bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys));
289 bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys));
290 bpl->tus.f.bdeSize = cmdSize;
291 bpl->tus.f.bdeFlags = 0;
292 bpl->tus.w = le32_to_cpu(bpl->tus.w);
296 bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys));
297 bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys));
298 bpl->tus.f.bdeSize = FCELSSIZE;
299 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
300 bpl->tus.w = le32_to_cpu(bpl->tus.w);
303 /* prevent preparing iocb with NULL ndlp reference */
304 elsiocb->context1 = lpfc_nlp_get(ndlp);
305 if (!elsiocb->context1)
306 goto els_iocb_free_pbuf_exit;
307 elsiocb->context2 = pcmd;
308 elsiocb->context3 = pbuflist;
309 elsiocb->retry = retry;
310 elsiocb->vport = vport;
311 elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT;
314 list_add(&prsp->list, &pcmd->list);
317 /* Xmit ELS command <elsCmd> to remote NPORT <did> */
318 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
319 "0116 Xmit ELS command x%x to remote "
320 "NPORT x%x I/O tag: x%x, port state:x%x "
321 "rpi x%x fc_flag:x%x\n",
322 elscmd, did, elsiocb->iotag,
323 vport->port_state, ndlp->nlp_rpi,
326 /* Xmit ELS response <elsCmd> to remote NPORT <did> */
327 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
328 "0117 Xmit ELS response x%x to remote "
329 "NPORT x%x I/O tag: x%x, size: x%x "
330 "port_state x%x rpi x%x fc_flag x%x\n",
331 elscmd, ndlp->nlp_DID, elsiocb->iotag,
332 cmdSize, vport->port_state,
333 ndlp->nlp_rpi, vport->fc_flag);
337 els_iocb_free_pbuf_exit:
339 lpfc_mbuf_free(phba, prsp->virt, prsp->phys);
342 els_iocb_free_prsp_exit:
343 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
346 els_iocb_free_pcmb_exit:
348 lpfc_sli_release_iocbq(phba, elsiocb);
353 * lpfc_issue_fabric_reglogin - Issue fabric registration login for a vport
354 * @vport: pointer to a host virtual N_Port data structure.
356 * This routine issues a fabric registration login for a @vport. An
357 * active ndlp node with Fabric_DID must already exist for this @vport.
358 * The routine invokes two mailbox commands to carry out fabric registration
359 * login through the HBA firmware: the first mailbox command requests the
360 * HBA to perform link configuration for the @vport; and the second mailbox
361 * command requests the HBA to perform the actual fabric registration login
365 * 0 - successfully issued fabric registration login for @vport
366 * -ENXIO -- failed to issue fabric registration login for @vport
369 lpfc_issue_fabric_reglogin(struct lpfc_vport *vport)
371 struct lpfc_hba *phba = vport->phba;
373 struct lpfc_dmabuf *mp;
374 struct lpfc_nodelist *ndlp;
375 struct serv_parm *sp;
379 sp = &phba->fc_fabparam;
380 ndlp = lpfc_findnode_did(vport, Fabric_DID);
381 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
386 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
392 vport->port_state = LPFC_FABRIC_CFG_LINK;
393 lpfc_config_link(phba, mbox);
394 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
397 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
398 if (rc == MBX_NOT_FINISHED) {
403 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
408 rc = lpfc_reg_rpi(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox,
415 mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login;
417 /* increment the reference count on ndlp to hold reference
418 * for the callback routine.
420 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
422 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
423 if (rc == MBX_NOT_FINISHED) {
425 goto fail_issue_reg_login;
430 fail_issue_reg_login:
431 /* decrement the reference count on ndlp just incremented
432 * for the failed mbox command.
435 mp = (struct lpfc_dmabuf *)mbox->ctx_buf;
436 lpfc_mbuf_free(phba, mp->virt, mp->phys);
439 mempool_free(mbox, phba->mbox_mem_pool);
442 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
443 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
444 "0249 Cannot issue Register Fabric login: Err %d\n", err);
449 * lpfc_issue_reg_vfi - Register VFI for this vport's fabric login
450 * @vport: pointer to a host virtual N_Port data structure.
452 * This routine issues a REG_VFI mailbox for the vfi, vpi, fcfi triplet for
453 * the @vport. This mailbox command is necessary for SLI4 port only.
456 * 0 - successfully issued REG_VFI for @vport
457 * A failure code otherwise.
460 lpfc_issue_reg_vfi(struct lpfc_vport *vport)
462 struct lpfc_hba *phba = vport->phba;
463 LPFC_MBOXQ_t *mboxq = NULL;
464 struct lpfc_nodelist *ndlp;
465 struct lpfc_dmabuf *dmabuf = NULL;
468 /* move forward in case of SLI4 FC port loopback test and pt2pt mode */
469 if ((phba->sli_rev == LPFC_SLI_REV4) &&
470 !(phba->link_flag & LS_LOOPBACK_MODE) &&
471 !(vport->fc_flag & FC_PT2PT)) {
472 ndlp = lpfc_findnode_did(vport, Fabric_DID);
473 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
479 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
485 /* Supply CSP's only if we are fabric connect or pt-to-pt connect */
486 if ((vport->fc_flag & FC_FABRIC) || (vport->fc_flag & FC_PT2PT)) {
487 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
492 dmabuf->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &dmabuf->phys);
497 memcpy(dmabuf->virt, &phba->fc_fabparam,
498 sizeof(struct serv_parm));
501 vport->port_state = LPFC_FABRIC_CFG_LINK;
503 lpfc_reg_vfi(mboxq, vport, dmabuf->phys);
505 lpfc_reg_vfi(mboxq, vport, 0);
507 mboxq->mbox_cmpl = lpfc_mbx_cmpl_reg_vfi;
508 mboxq->vport = vport;
509 mboxq->ctx_buf = dmabuf;
510 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
511 if (rc == MBX_NOT_FINISHED) {
519 mempool_free(mboxq, phba->mbox_mem_pool);
522 lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys);
526 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
527 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
528 "0289 Issue Register VFI failed: Err %d\n", rc);
533 * lpfc_issue_unreg_vfi - Unregister VFI for this vport's fabric login
534 * @vport: pointer to a host virtual N_Port data structure.
536 * This routine issues a UNREG_VFI mailbox with the vfi, vpi, fcfi triplet for
537 * the @vport. This mailbox command is necessary for SLI4 port only.
540 * 0 - successfully issued REG_VFI for @vport
541 * A failure code otherwise.
544 lpfc_issue_unreg_vfi(struct lpfc_vport *vport)
546 struct lpfc_hba *phba = vport->phba;
547 struct Scsi_Host *shost;
551 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
553 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
554 "2556 UNREG_VFI mbox allocation failed"
555 "HBA state x%x\n", phba->pport->port_state);
559 lpfc_unreg_vfi(mboxq, vport);
560 mboxq->vport = vport;
561 mboxq->mbox_cmpl = lpfc_unregister_vfi_cmpl;
563 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
564 if (rc == MBX_NOT_FINISHED) {
565 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
566 "2557 UNREG_VFI issue mbox failed rc x%x "
568 rc, phba->pport->port_state);
569 mempool_free(mboxq, phba->mbox_mem_pool);
573 shost = lpfc_shost_from_vport(vport);
574 spin_lock_irq(shost->host_lock);
575 vport->fc_flag &= ~FC_VFI_REGISTERED;
576 spin_unlock_irq(shost->host_lock);
581 * lpfc_check_clean_addr_bit - Check whether assigned FCID is clean.
582 * @vport: pointer to a host virtual N_Port data structure.
583 * @sp: pointer to service parameter data structure.
585 * This routine is called from FLOGI/FDISC completion handler functions.
586 * lpfc_check_clean_addr_bit return 1 when FCID/Fabric portname/ Fabric
587 * node nodename is changed in the completion service parameter else return
588 * 0. This function also set flag in the vport data structure to delay
589 * NP_Port discovery after the FLOGI/FDISC completion if Clean address bit
590 * in FLOGI/FDISC response is cleared and FCID/Fabric portname/ Fabric
591 * node nodename is changed in the completion service parameter.
594 * 0 - FCID and Fabric Nodename and Fabric portname is not changed.
595 * 1 - FCID or Fabric Nodename or Fabric portname is changed.
599 lpfc_check_clean_addr_bit(struct lpfc_vport *vport,
600 struct serv_parm *sp)
602 struct lpfc_hba *phba = vport->phba;
603 uint8_t fabric_param_changed = 0;
604 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
606 if ((vport->fc_prevDID != vport->fc_myDID) ||
607 memcmp(&vport->fabric_portname, &sp->portName,
608 sizeof(struct lpfc_name)) ||
609 memcmp(&vport->fabric_nodename, &sp->nodeName,
610 sizeof(struct lpfc_name)) ||
611 (vport->vport_flag & FAWWPN_PARAM_CHG)) {
612 fabric_param_changed = 1;
613 vport->vport_flag &= ~FAWWPN_PARAM_CHG;
616 * Word 1 Bit 31 in common service parameter is overloaded.
617 * Word 1 Bit 31 in FLOGI request is multiple NPort request
618 * Word 1 Bit 31 in FLOGI response is clean address bit
620 * If fabric parameter is changed and clean address bit is
621 * cleared delay nport discovery if
622 * - vport->fc_prevDID != 0 (not initial discovery) OR
623 * - lpfc_delay_discovery module parameter is set.
625 if (fabric_param_changed && !sp->cmn.clean_address_bit &&
626 (vport->fc_prevDID || phba->cfg_delay_discovery)) {
627 spin_lock_irq(shost->host_lock);
628 vport->fc_flag |= FC_DISC_DELAYED;
629 spin_unlock_irq(shost->host_lock);
632 return fabric_param_changed;
637 * lpfc_cmpl_els_flogi_fabric - Completion function for flogi to a fabric port
638 * @vport: pointer to a host virtual N_Port data structure.
639 * @ndlp: pointer to a node-list data structure.
640 * @sp: pointer to service parameter data structure.
641 * @irsp: pointer to the IOCB within the lpfc response IOCB.
643 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
644 * function to handle the completion of a Fabric Login (FLOGI) into a fabric
645 * port in a fabric topology. It properly sets up the parameters to the @ndlp
646 * from the IOCB response. It also check the newly assigned N_Port ID to the
647 * @vport against the previously assigned N_Port ID. If it is different from
648 * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine
649 * is invoked on all the remaining nodes with the @vport to unregister the
650 * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin()
651 * is invoked to register login to the fabric.
654 * 0 - Success (currently, always return 0)
657 lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
658 struct serv_parm *sp, IOCB_t *irsp)
660 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
661 struct lpfc_hba *phba = vport->phba;
662 struct lpfc_nodelist *np;
663 struct lpfc_nodelist *next_np;
664 uint8_t fabric_param_changed;
666 spin_lock_irq(shost->host_lock);
667 vport->fc_flag |= FC_FABRIC;
668 spin_unlock_irq(shost->host_lock);
670 phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
671 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
672 phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
674 phba->fc_edtovResol = sp->cmn.edtovResolution;
675 phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
677 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
678 spin_lock_irq(shost->host_lock);
679 vport->fc_flag |= FC_PUBLIC_LOOP;
680 spin_unlock_irq(shost->host_lock);
683 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
684 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
685 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name));
686 ndlp->nlp_class_sup = 0;
687 if (sp->cls1.classValid)
688 ndlp->nlp_class_sup |= FC_COS_CLASS1;
689 if (sp->cls2.classValid)
690 ndlp->nlp_class_sup |= FC_COS_CLASS2;
691 if (sp->cls3.classValid)
692 ndlp->nlp_class_sup |= FC_COS_CLASS3;
693 if (sp->cls4.classValid)
694 ndlp->nlp_class_sup |= FC_COS_CLASS4;
695 ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
696 sp->cmn.bbRcvSizeLsb;
698 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
699 if (fabric_param_changed) {
700 /* Reset FDMI attribute masks based on config parameter */
701 if (phba->cfg_enable_SmartSAN ||
702 (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) {
703 /* Setup appropriate attribute masks */
704 vport->fdmi_hba_mask = LPFC_FDMI2_HBA_ATTR;
705 if (phba->cfg_enable_SmartSAN)
706 vport->fdmi_port_mask = LPFC_FDMI2_SMART_ATTR;
708 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
710 vport->fdmi_hba_mask = 0;
711 vport->fdmi_port_mask = 0;
715 memcpy(&vport->fabric_portname, &sp->portName,
716 sizeof(struct lpfc_name));
717 memcpy(&vport->fabric_nodename, &sp->nodeName,
718 sizeof(struct lpfc_name));
719 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
721 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
722 if (sp->cmn.response_multiple_NPort) {
723 lpfc_printf_vlog(vport, KERN_WARNING,
725 "1816 FLOGI NPIV supported, "
726 "response data 0x%x\n",
727 sp->cmn.response_multiple_NPort);
728 spin_lock_irq(&phba->hbalock);
729 phba->link_flag |= LS_NPIV_FAB_SUPPORTED;
730 spin_unlock_irq(&phba->hbalock);
732 /* Because we asked f/w for NPIV it still expects us
733 to call reg_vnpid atleast for the physcial host */
734 lpfc_printf_vlog(vport, KERN_WARNING,
736 "1817 Fabric does not support NPIV "
737 "- configuring single port mode.\n");
738 spin_lock_irq(&phba->hbalock);
739 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
740 spin_unlock_irq(&phba->hbalock);
745 * For FC we need to do some special processing because of the SLI
746 * Port's default settings of the Common Service Parameters.
748 if ((phba->sli_rev == LPFC_SLI_REV4) &&
749 (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC)) {
750 /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */
751 if (fabric_param_changed)
752 lpfc_unregister_fcf_prep(phba);
754 /* This should just update the VFI CSPs*/
755 if (vport->fc_flag & FC_VFI_REGISTERED)
756 lpfc_issue_reg_vfi(vport);
759 if (fabric_param_changed &&
760 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
762 /* If our NportID changed, we need to ensure all
763 * remaining NPORTs get unreg_login'ed.
765 list_for_each_entry_safe(np, next_np,
766 &vport->fc_nodes, nlp_listp) {
767 if (!NLP_CHK_NODE_ACT(np))
769 if ((np->nlp_state != NLP_STE_NPR_NODE) ||
770 !(np->nlp_flag & NLP_NPR_ADISC))
772 spin_lock_irq(shost->host_lock);
773 np->nlp_flag &= ~NLP_NPR_ADISC;
774 spin_unlock_irq(shost->host_lock);
775 lpfc_unreg_rpi(vport, np);
777 lpfc_cleanup_pending_mbox(vport);
779 if (phba->sli_rev == LPFC_SLI_REV4) {
780 lpfc_sli4_unreg_all_rpis(vport);
781 lpfc_mbx_unreg_vpi(vport);
782 spin_lock_irq(shost->host_lock);
783 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
784 spin_unlock_irq(shost->host_lock);
788 * For SLI3 and SLI4, the VPI needs to be reregistered in
789 * response to this fabric parameter change event.
791 spin_lock_irq(shost->host_lock);
792 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
793 spin_unlock_irq(shost->host_lock);
794 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
795 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
797 * Driver needs to re-reg VPI in order for f/w
798 * to update the MAC address.
800 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
801 lpfc_register_new_vport(phba, vport, ndlp);
805 if (phba->sli_rev < LPFC_SLI_REV4) {
806 lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
807 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED &&
808 vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
809 lpfc_register_new_vport(phba, vport, ndlp);
811 lpfc_issue_fabric_reglogin(vport);
813 ndlp->nlp_type |= NLP_FABRIC;
814 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
815 if ((!(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) &&
816 (vport->vpi_state & LPFC_VPI_REGISTERED)) {
817 lpfc_start_fdiscs(phba);
818 lpfc_do_scr_ns_plogi(phba, vport);
819 } else if (vport->fc_flag & FC_VFI_REGISTERED)
820 lpfc_issue_init_vpi(vport);
822 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
823 "3135 Need register VFI: (x%x/%x)\n",
824 vport->fc_prevDID, vport->fc_myDID);
825 lpfc_issue_reg_vfi(vport);
832 * lpfc_cmpl_els_flogi_nport - Completion function for flogi to an N_Port
833 * @vport: pointer to a host virtual N_Port data structure.
834 * @ndlp: pointer to a node-list data structure.
835 * @sp: pointer to service parameter data structure.
837 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
838 * function to handle the completion of a Fabric Login (FLOGI) into an N_Port
839 * in a point-to-point topology. First, the @vport's N_Port Name is compared
840 * with the received N_Port Name: if the @vport's N_Port Name is greater than
841 * the received N_Port Name lexicographically, this node shall assign local
842 * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and
843 * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise,
844 * this node shall just wait for the remote node to issue PLOGI and assign
852 lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
853 struct serv_parm *sp)
855 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
856 struct lpfc_hba *phba = vport->phba;
860 spin_lock_irq(shost->host_lock);
861 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
862 vport->fc_flag |= FC_PT2PT;
863 spin_unlock_irq(shost->host_lock);
865 /* If we are pt2pt with another NPort, force NPIV off! */
866 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
868 /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */
869 if ((phba->sli_rev == LPFC_SLI_REV4) && phba->fc_topology_changed) {
870 lpfc_unregister_fcf_prep(phba);
872 spin_lock_irq(shost->host_lock);
873 vport->fc_flag &= ~FC_VFI_REGISTERED;
874 spin_unlock_irq(shost->host_lock);
875 phba->fc_topology_changed = 0;
878 rc = memcmp(&vport->fc_portname, &sp->portName,
879 sizeof(vport->fc_portname));
882 /* This side will initiate the PLOGI */
883 spin_lock_irq(shost->host_lock);
884 vport->fc_flag |= FC_PT2PT_PLOGI;
885 spin_unlock_irq(shost->host_lock);
888 * N_Port ID cannot be 0, set our Id to LocalID
889 * the other side will be RemoteID.
894 vport->fc_myDID = PT2PT_LocalID;
896 /* Decrement ndlp reference count indicating that ndlp can be
897 * safely released when other references to it are done.
901 ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
904 * Cannot find existing Fabric ndlp, so allocate a
907 ndlp = lpfc_nlp_init(vport, PT2PT_RemoteID);
910 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
911 ndlp = lpfc_enable_node(vport, ndlp,
912 NLP_STE_UNUSED_NODE);
917 memcpy(&ndlp->nlp_portname, &sp->portName,
918 sizeof(struct lpfc_name));
919 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
920 sizeof(struct lpfc_name));
921 /* Set state will put ndlp onto node list if not already done */
922 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
923 spin_lock_irq(shost->host_lock);
924 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
925 spin_unlock_irq(shost->host_lock);
927 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
931 lpfc_config_link(phba, mbox);
933 mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link;
935 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
936 if (rc == MBX_NOT_FINISHED) {
937 mempool_free(mbox, phba->mbox_mem_pool);
941 /* This side will wait for the PLOGI, decrement ndlp reference
942 * count indicating that ndlp can be released when other
943 * references to it are done.
947 /* Start discovery - this should just do CLEAR_LA */
948 lpfc_disc_start(vport);
957 * lpfc_cmpl_els_flogi - Completion callback function for flogi
958 * @phba: pointer to lpfc hba data structure.
959 * @cmdiocb: pointer to lpfc command iocb data structure.
960 * @rspiocb: pointer to lpfc response iocb data structure.
962 * This routine is the top-level completion callback function for issuing
963 * a Fabric Login (FLOGI) command. If the response IOCB reported error,
964 * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If
965 * retry has been made (either immediately or delayed with lpfc_els_retry()
966 * returning 1), the command IOCB will be released and function returned.
967 * If the retry attempt has been given up (possibly reach the maximum
968 * number of retries), one additional decrement of ndlp reference shall be
969 * invoked before going out after releasing the command IOCB. This will
970 * actually release the remote node (Note, lpfc_els_free_iocb() will also
971 * invoke one decrement of ndlp reference count). If no error reported in
972 * the IOCB status, the command Port ID field is used to determine whether
973 * this is a point-to-point topology or a fabric topology: if the Port ID
974 * field is assigned, it is a fabric topology; otherwise, it is a
975 * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or
976 * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the
977 * specific topology completion conditions.
980 lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
981 struct lpfc_iocbq *rspiocb)
983 struct lpfc_vport *vport = cmdiocb->vport;
984 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
985 IOCB_t *irsp = &rspiocb->iocb;
986 struct lpfc_nodelist *ndlp = cmdiocb->context1;
987 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
988 struct serv_parm *sp;
992 /* Check to see if link went down during discovery */
993 if (lpfc_els_chk_latt(vport)) {
994 /* One additional decrement on node reference count to
995 * trigger the release of the node
1001 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1002 "FLOGI cmpl: status:x%x/x%x state:x%x",
1003 irsp->ulpStatus, irsp->un.ulpWord[4],
1006 if (irsp->ulpStatus) {
1008 * In case of FIP mode, perform roundrobin FCF failover
1009 * due to new FCF discovery
1011 if ((phba->hba_flag & HBA_FIP_SUPPORT) &&
1012 (phba->fcf.fcf_flag & FCF_DISCOVERY)) {
1013 if (phba->link_state < LPFC_LINK_UP)
1014 goto stop_rr_fcf_flogi;
1015 if ((phba->fcoe_cvl_eventtag_attn ==
1016 phba->fcoe_cvl_eventtag) &&
1017 (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
1018 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1020 goto stop_rr_fcf_flogi;
1022 phba->fcoe_cvl_eventtag_attn =
1023 phba->fcoe_cvl_eventtag;
1024 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
1025 "2611 FLOGI failed on FCF (x%x), "
1026 "status:x%x/x%x, tmo:x%x, perform "
1027 "roundrobin FCF failover\n",
1028 phba->fcf.current_rec.fcf_indx,
1029 irsp->ulpStatus, irsp->un.ulpWord[4],
1031 lpfc_sli4_set_fcf_flogi_fail(phba,
1032 phba->fcf.current_rec.fcf_indx);
1033 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
1034 rc = lpfc_sli4_fcf_rr_next_proc(vport, fcf_index);
1041 if (!(irsp->ulpStatus == IOSTAT_LOCAL_REJECT &&
1042 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1043 IOERR_LOOP_OPEN_FAILURE)))
1044 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1045 "2858 FLOGI failure Status:x%x/x%x "
1046 "TMO:x%x Data x%x x%x\n",
1047 irsp->ulpStatus, irsp->un.ulpWord[4],
1048 irsp->ulpTimeout, phba->hba_flag,
1049 phba->fcf.fcf_flag);
1051 /* Check for retry */
1052 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
1055 lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS,
1056 "0150 FLOGI failure Status:x%x/x%x "
1057 "xri x%x TMO:x%x\n",
1058 irsp->ulpStatus, irsp->un.ulpWord[4],
1059 cmdiocb->sli4_xritag, irsp->ulpTimeout);
1061 /* If this is not a loop open failure, bail out */
1062 if (!(irsp->ulpStatus == IOSTAT_LOCAL_REJECT &&
1063 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1064 IOERR_LOOP_OPEN_FAILURE)))
1067 /* FLOGI failed, so there is no fabric */
1068 spin_lock_irq(shost->host_lock);
1069 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
1070 spin_unlock_irq(shost->host_lock);
1072 /* If private loop, then allow max outstanding els to be
1073 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
1074 * alpa map would take too long otherwise.
1076 if (phba->alpa_map[0] == 0)
1077 vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
1078 if ((phba->sli_rev == LPFC_SLI_REV4) &&
1079 (!(vport->fc_flag & FC_VFI_REGISTERED) ||
1080 (vport->fc_prevDID != vport->fc_myDID) ||
1081 phba->fc_topology_changed)) {
1082 if (vport->fc_flag & FC_VFI_REGISTERED) {
1083 if (phba->fc_topology_changed) {
1084 lpfc_unregister_fcf_prep(phba);
1085 spin_lock_irq(shost->host_lock);
1086 vport->fc_flag &= ~FC_VFI_REGISTERED;
1087 spin_unlock_irq(shost->host_lock);
1088 phba->fc_topology_changed = 0;
1090 lpfc_sli4_unreg_all_rpis(vport);
1094 /* Do not register VFI if the driver aborted FLOGI */
1095 if (!lpfc_error_lost_link(irsp))
1096 lpfc_issue_reg_vfi(vport);
1102 spin_lock_irq(shost->host_lock);
1103 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
1104 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
1105 spin_unlock_irq(shost->host_lock);
1108 * The FLogI succeeded. Sync the data for the CPU before
1111 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
1114 sp = prsp->virt + sizeof(uint32_t);
1116 /* FLOGI completes successfully */
1117 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1118 "0101 FLOGI completes successfully, I/O tag:x%x, "
1119 "xri x%x Data: x%x x%x x%x x%x x%x %x\n",
1120 cmdiocb->iotag, cmdiocb->sli4_xritag,
1121 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
1122 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution,
1123 vport->port_state, vport->fc_flag);
1125 if (vport->port_state == LPFC_FLOGI) {
1127 * If Common Service Parameters indicate Nport
1128 * we are point to point, if Fport we are Fabric.
1131 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
1132 else if (!(phba->hba_flag & HBA_FCOE_MODE))
1133 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
1135 lpfc_printf_vlog(vport, KERN_ERR,
1137 "2831 FLOGI response with cleared Fabric "
1138 "bit fcf_index 0x%x "
1139 "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x "
1141 "%02x%02x%02x%02x%02x%02x%02x%02x\n",
1142 phba->fcf.current_rec.fcf_indx,
1143 phba->fcf.current_rec.switch_name[0],
1144 phba->fcf.current_rec.switch_name[1],
1145 phba->fcf.current_rec.switch_name[2],
1146 phba->fcf.current_rec.switch_name[3],
1147 phba->fcf.current_rec.switch_name[4],
1148 phba->fcf.current_rec.switch_name[5],
1149 phba->fcf.current_rec.switch_name[6],
1150 phba->fcf.current_rec.switch_name[7],
1151 phba->fcf.current_rec.fabric_name[0],
1152 phba->fcf.current_rec.fabric_name[1],
1153 phba->fcf.current_rec.fabric_name[2],
1154 phba->fcf.current_rec.fabric_name[3],
1155 phba->fcf.current_rec.fabric_name[4],
1156 phba->fcf.current_rec.fabric_name[5],
1157 phba->fcf.current_rec.fabric_name[6],
1158 phba->fcf.current_rec.fabric_name[7]);
1160 spin_lock_irq(&phba->hbalock);
1161 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
1162 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
1163 spin_unlock_irq(&phba->hbalock);
1164 phba->fcf.fcf_redisc_attempted = 0; /* reset */
1168 /* Mark the FCF discovery process done */
1169 if (phba->hba_flag & HBA_FIP_SUPPORT)
1170 lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP |
1172 "2769 FLOGI to FCF (x%x) "
1173 "completed successfully\n",
1174 phba->fcf.current_rec.fcf_indx);
1175 spin_lock_irq(&phba->hbalock);
1176 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
1177 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
1178 spin_unlock_irq(&phba->hbalock);
1179 phba->fcf.fcf_redisc_attempted = 0; /* reset */
1185 spin_lock_irq(&phba->hbalock);
1186 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
1187 spin_unlock_irq(&phba->hbalock);
1191 if (!lpfc_error_lost_link(irsp)) {
1192 /* FLOGI failed, so just use loop map to make discovery list */
1193 lpfc_disc_list_loopmap(vport);
1195 /* Start discovery */
1196 lpfc_disc_start(vport);
1197 } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
1198 (((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
1199 IOERR_SLI_ABORTED) &&
1200 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
1201 IOERR_SLI_DOWN))) &&
1202 (phba->link_state != LPFC_CLEAR_LA)) {
1203 /* If FLOGI failed enable link interrupt. */
1204 lpfc_issue_clear_la(phba, vport);
1207 lpfc_els_free_iocb(phba, cmdiocb);
1211 * lpfc_cmpl_els_link_down - Completion callback function for ELS command
1212 * aborted during a link down
1213 * @phba: pointer to lpfc hba data structure.
1214 * @cmdiocb: pointer to lpfc command iocb data structure.
1215 * @rspiocb: pointer to lpfc response iocb data structure.
1219 lpfc_cmpl_els_link_down(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1220 struct lpfc_iocbq *rspiocb)
1226 pcmd = (uint32_t *)(((struct lpfc_dmabuf *)cmdiocb->context2)->virt);
1228 irsp = &rspiocb->iocb;
1230 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1231 "6445 ELS completes after LINK_DOWN: "
1232 " Status %x/%x cmd x%x flg x%x\n",
1233 irsp->ulpStatus, irsp->un.ulpWord[4], cmd,
1234 cmdiocb->iocb_flag);
1236 if (cmdiocb->iocb_flag & LPFC_IO_FABRIC) {
1237 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
1238 atomic_dec(&phba->fabric_iocb_count);
1240 lpfc_els_free_iocb(phba, cmdiocb);
1244 * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport
1245 * @vport: pointer to a host virtual N_Port data structure.
1246 * @ndlp: pointer to a node-list data structure.
1247 * @retry: number of retries to the command IOCB.
1249 * This routine issues a Fabric Login (FLOGI) Request ELS command
1250 * for a @vport. The initiator service parameters are put into the payload
1251 * of the FLOGI Request IOCB and the top-level callback function pointer
1252 * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
1253 * function field. The lpfc_issue_fabric_iocb routine is invoked to send
1254 * out FLOGI ELS command with one outstanding fabric IOCB at a time.
1256 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1257 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1258 * will be stored into the context1 field of the IOCB for the completion
1259 * callback function to the FLOGI ELS command.
1262 * 0 - successfully issued flogi iocb for @vport
1263 * 1 - failed to issue flogi iocb for @vport
1266 lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1269 struct lpfc_hba *phba = vport->phba;
1270 struct serv_parm *sp;
1272 struct lpfc_iocbq *elsiocb;
1273 struct lpfc_iocbq defer_flogi_acc;
1279 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
1280 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1281 ndlp->nlp_DID, ELS_CMD_FLOGI);
1286 icmd = &elsiocb->iocb;
1287 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1289 /* For FLOGI request, remainder of payload is service parameters */
1290 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
1291 pcmd += sizeof(uint32_t);
1292 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
1293 sp = (struct serv_parm *) pcmd;
1295 /* Setup CSPs accordingly for Fabric */
1296 sp->cmn.e_d_tov = 0;
1297 sp->cmn.w2.r_a_tov = 0;
1298 sp->cmn.virtual_fabric_support = 0;
1299 sp->cls1.classValid = 0;
1300 if (sp->cmn.fcphLow < FC_PH3)
1301 sp->cmn.fcphLow = FC_PH3;
1302 if (sp->cmn.fcphHigh < FC_PH3)
1303 sp->cmn.fcphHigh = FC_PH3;
1305 if (phba->sli_rev == LPFC_SLI_REV4) {
1306 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
1307 LPFC_SLI_INTF_IF_TYPE_0) {
1308 elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1);
1309 elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1);
1310 /* FLOGI needs to be 3 for WQE FCFI */
1311 /* Set the fcfi to the fcfi we registered with */
1312 elsiocb->iocb.ulpContext = phba->fcf.fcfi;
1314 /* Can't do SLI4 class2 without support sequence coalescing */
1315 sp->cls2.classValid = 0;
1316 sp->cls2.seqDelivery = 0;
1318 /* Historical, setting sequential-delivery bit for SLI3 */
1319 sp->cls2.seqDelivery = (sp->cls2.classValid) ? 1 : 0;
1320 sp->cls3.seqDelivery = (sp->cls3.classValid) ? 1 : 0;
1321 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
1322 sp->cmn.request_multiple_Nport = 1;
1323 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
1327 sp->cmn.request_multiple_Nport = 0;
1330 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
1331 icmd->un.elsreq64.myID = 0;
1332 icmd->un.elsreq64.fl = 1;
1335 tmo = phba->fc_ratov;
1336 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
1337 lpfc_set_disctmo(vport);
1338 phba->fc_ratov = tmo;
1340 phba->fc_stat.elsXmitFLOGI++;
1341 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
1343 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1344 "Issue FLOGI: opt:x%x",
1345 phba->sli3_options, 0, 0);
1347 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
1349 phba->hba_flag |= HBA_FLOGI_ISSUED;
1351 /* Check for a deferred FLOGI ACC condition */
1352 if (phba->defer_flogi_acc_flag) {
1353 did = vport->fc_myDID;
1354 vport->fc_myDID = Fabric_DID;
1356 memset(&defer_flogi_acc, 0, sizeof(struct lpfc_iocbq));
1358 defer_flogi_acc.iocb.ulpContext = phba->defer_flogi_acc_rx_id;
1359 defer_flogi_acc.iocb.unsli3.rcvsli3.ox_id =
1360 phba->defer_flogi_acc_ox_id;
1362 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1363 "3354 Xmit deferred FLOGI ACC: rx_id: x%x,"
1364 " ox_id: x%x, hba_flag x%x\n",
1365 phba->defer_flogi_acc_rx_id,
1366 phba->defer_flogi_acc_ox_id, phba->hba_flag);
1368 /* Send deferred FLOGI ACC */
1369 lpfc_els_rsp_acc(vport, ELS_CMD_FLOGI, &defer_flogi_acc,
1372 phba->defer_flogi_acc_flag = false;
1374 vport->fc_myDID = did;
1377 if (rc == IOCB_ERROR) {
1378 lpfc_els_free_iocb(phba, elsiocb);
1385 * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs
1386 * @phba: pointer to lpfc hba data structure.
1388 * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
1389 * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
1390 * list and issues an abort IOCB commond on each outstanding IOCB that
1391 * contains a active Fabric_DID ndlp. Note that this function is to issue
1392 * the abort IOCB command on all the outstanding IOCBs, thus when this
1393 * function returns, it does not guarantee all the IOCBs are actually aborted.
1396 * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0)
1399 lpfc_els_abort_flogi(struct lpfc_hba *phba)
1401 struct lpfc_sli_ring *pring;
1402 struct lpfc_iocbq *iocb, *next_iocb;
1403 struct lpfc_nodelist *ndlp;
1406 /* Abort outstanding I/O on NPort <nlp_DID> */
1407 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
1408 "0201 Abort outstanding I/O on NPort x%x\n",
1411 pring = lpfc_phba_elsring(phba);
1412 if (unlikely(!pring))
1416 * Check the txcmplq for an iocb that matches the nport the driver is
1419 spin_lock_irq(&phba->hbalock);
1420 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
1422 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR) {
1423 ndlp = (struct lpfc_nodelist *)(iocb->context1);
1424 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
1425 (ndlp->nlp_DID == Fabric_DID))
1426 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
1429 spin_unlock_irq(&phba->hbalock);
1435 * lpfc_initial_flogi - Issue an initial fabric login for a vport
1436 * @vport: pointer to a host virtual N_Port data structure.
1438 * This routine issues an initial Fabric Login (FLOGI) for the @vport
1439 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1440 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1441 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1442 * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
1443 * is then invoked with the @vport and the ndlp to perform the FLOGI for the
1447 * 0 - failed to issue initial flogi for @vport
1448 * 1 - successfully issued initial flogi for @vport
1451 lpfc_initial_flogi(struct lpfc_vport *vport)
1453 struct lpfc_nodelist *ndlp;
1455 vport->port_state = LPFC_FLOGI;
1456 lpfc_set_disctmo(vport);
1458 /* First look for the Fabric ndlp */
1459 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1461 /* Cannot find existing Fabric ndlp, so allocate a new one */
1462 ndlp = lpfc_nlp_init(vport, Fabric_DID);
1465 /* Set the node type */
1466 ndlp->nlp_type |= NLP_FABRIC;
1467 /* Put ndlp onto node list */
1468 lpfc_enqueue_node(vport, ndlp);
1469 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1470 /* re-setup ndlp without removing from node list */
1471 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1476 if (lpfc_issue_els_flogi(vport, ndlp, 0)) {
1477 /* This decrement of reference count to node shall kick off
1478 * the release of the node.
1487 * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport
1488 * @vport: pointer to a host virtual N_Port data structure.
1490 * This routine issues an initial Fabric Discover (FDISC) for the @vport
1491 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1492 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1493 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1494 * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
1495 * is then invoked with the @vport and the ndlp to perform the FDISC for the
1499 * 0 - failed to issue initial fdisc for @vport
1500 * 1 - successfully issued initial fdisc for @vport
1503 lpfc_initial_fdisc(struct lpfc_vport *vport)
1505 struct lpfc_nodelist *ndlp;
1507 /* First look for the Fabric ndlp */
1508 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1510 /* Cannot find existing Fabric ndlp, so allocate a new one */
1511 ndlp = lpfc_nlp_init(vport, Fabric_DID);
1514 /* Put ndlp onto node list */
1515 lpfc_enqueue_node(vport, ndlp);
1516 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1517 /* re-setup ndlp without removing from node list */
1518 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1523 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
1524 /* decrement node reference count to trigger the release of
1534 * lpfc_more_plogi - Check and issue remaining plogis for a vport
1535 * @vport: pointer to a host virtual N_Port data structure.
1537 * This routine checks whether there are more remaining Port Logins
1538 * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
1539 * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
1540 * to issue ELS PLOGIs up to the configured discover threads with the
1541 * @vport (@vport->cfg_discovery_threads). The function also decrement
1542 * the @vport's num_disc_node by 1 if it is not already 0.
1545 lpfc_more_plogi(struct lpfc_vport *vport)
1547 if (vport->num_disc_nodes)
1548 vport->num_disc_nodes--;
1550 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
1551 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1552 "0232 Continue discovery with %d PLOGIs to go "
1553 "Data: x%x x%x x%x\n",
1554 vport->num_disc_nodes, vport->fc_plogi_cnt,
1555 vport->fc_flag, vport->port_state);
1556 /* Check to see if there are more PLOGIs to be sent */
1557 if (vport->fc_flag & FC_NLP_MORE)
1558 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
1559 lpfc_els_disc_plogi(vport);
1565 * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp
1566 * @phba: pointer to lpfc hba data structure.
1567 * @prsp: pointer to response IOCB payload.
1568 * @ndlp: pointer to a node-list data structure.
1570 * This routine checks and indicates whether the WWPN of an N_Port, retrieved
1571 * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
1572 * The following cases are considered N_Port confirmed:
1573 * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
1574 * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
1575 * it does not have WWPN assigned either. If the WWPN is confirmed, the
1576 * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
1577 * 1) if there is a node on vport list other than the @ndlp with the same
1578 * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
1579 * on that node to release the RPI associated with the node; 2) if there is
1580 * no node found on vport list with the same WWPN of the N_Port PLOGI logged
1581 * into, a new node shall be allocated (or activated). In either case, the
1582 * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
1583 * be released and the new_ndlp shall be put on to the vport node list and
1584 * its pointer returned as the confirmed node.
1586 * Note that before the @ndlp got "released", the keepDID from not-matching
1587 * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
1588 * of the @ndlp. This is because the release of @ndlp is actually to put it
1589 * into an inactive state on the vport node list and the vport node list
1590 * management algorithm does not allow two node with a same DID.
1593 * pointer to the PLOGI N_Port @ndlp
1595 static struct lpfc_nodelist *
1596 lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
1597 struct lpfc_nodelist *ndlp)
1599 struct lpfc_vport *vport = ndlp->vport;
1600 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1601 struct lpfc_nodelist *new_ndlp;
1602 struct lpfc_rport_data *rdata;
1603 struct fc_rport *rport;
1604 struct serv_parm *sp;
1605 uint8_t name[sizeof(struct lpfc_name)];
1606 uint32_t rc, keepDID = 0, keep_nlp_flag = 0;
1607 uint32_t keep_new_nlp_flag = 0;
1608 uint16_t keep_nlp_state;
1609 u32 keep_nlp_fc4_type = 0;
1610 struct lpfc_nvme_rport *keep_nrport = NULL;
1613 unsigned long *active_rrqs_xri_bitmap = NULL;
1615 /* Fabric nodes can have the same WWPN so we don't bother searching
1616 * by WWPN. Just return the ndlp that was given to us.
1618 if (ndlp->nlp_type & NLP_FABRIC)
1621 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
1622 memset(name, 0, sizeof(struct lpfc_name));
1624 /* Now we find out if the NPort we are logging into, matches the WWPN
1625 * we have for that ndlp. If not, we have some work to do.
1627 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
1629 /* return immediately if the WWPN matches ndlp */
1630 if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp))
1633 if (phba->sli_rev == LPFC_SLI_REV4) {
1634 active_rrqs_xri_bitmap = mempool_alloc(phba->active_rrq_pool,
1636 if (active_rrqs_xri_bitmap)
1637 memset(active_rrqs_xri_bitmap, 0,
1638 phba->cfg_rrq_xri_bitmap_sz);
1641 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_NODE,
1642 "3178 PLOGI confirm: ndlp x%x x%x x%x: "
1643 "new_ndlp x%x x%x x%x\n",
1644 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_fc4_type,
1645 (new_ndlp ? new_ndlp->nlp_DID : 0),
1646 (new_ndlp ? new_ndlp->nlp_flag : 0),
1647 (new_ndlp ? new_ndlp->nlp_fc4_type : 0));
1650 rc = memcmp(&ndlp->nlp_portname, name,
1651 sizeof(struct lpfc_name));
1653 if (active_rrqs_xri_bitmap)
1654 mempool_free(active_rrqs_xri_bitmap,
1655 phba->active_rrq_pool);
1658 new_ndlp = lpfc_nlp_init(vport, ndlp->nlp_DID);
1660 if (active_rrqs_xri_bitmap)
1661 mempool_free(active_rrqs_xri_bitmap,
1662 phba->active_rrq_pool);
1665 } else if (!NLP_CHK_NODE_ACT(new_ndlp)) {
1666 rc = memcmp(&ndlp->nlp_portname, name,
1667 sizeof(struct lpfc_name));
1669 if (active_rrqs_xri_bitmap)
1670 mempool_free(active_rrqs_xri_bitmap,
1671 phba->active_rrq_pool);
1674 new_ndlp = lpfc_enable_node(vport, new_ndlp,
1675 NLP_STE_UNUSED_NODE);
1677 if (active_rrqs_xri_bitmap)
1678 mempool_free(active_rrqs_xri_bitmap,
1679 phba->active_rrq_pool);
1682 keepDID = new_ndlp->nlp_DID;
1683 if ((phba->sli_rev == LPFC_SLI_REV4) && active_rrqs_xri_bitmap)
1684 memcpy(active_rrqs_xri_bitmap,
1685 new_ndlp->active_rrqs_xri_bitmap,
1686 phba->cfg_rrq_xri_bitmap_sz);
1688 keepDID = new_ndlp->nlp_DID;
1689 if (phba->sli_rev == LPFC_SLI_REV4 &&
1690 active_rrqs_xri_bitmap)
1691 memcpy(active_rrqs_xri_bitmap,
1692 new_ndlp->active_rrqs_xri_bitmap,
1693 phba->cfg_rrq_xri_bitmap_sz);
1696 /* At this point in this routine, we know new_ndlp will be
1697 * returned. however, any previous GID_FTs that were done
1698 * would have updated nlp_fc4_type in ndlp, so we must ensure
1699 * new_ndlp has the right value.
1701 if (vport->fc_flag & FC_FABRIC) {
1702 keep_nlp_fc4_type = new_ndlp->nlp_fc4_type;
1703 new_ndlp->nlp_fc4_type = ndlp->nlp_fc4_type;
1706 lpfc_unreg_rpi(vport, new_ndlp);
1707 new_ndlp->nlp_DID = ndlp->nlp_DID;
1708 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
1709 if (phba->sli_rev == LPFC_SLI_REV4)
1710 memcpy(new_ndlp->active_rrqs_xri_bitmap,
1711 ndlp->active_rrqs_xri_bitmap,
1712 phba->cfg_rrq_xri_bitmap_sz);
1714 spin_lock_irq(shost->host_lock);
1715 keep_new_nlp_flag = new_ndlp->nlp_flag;
1716 keep_nlp_flag = ndlp->nlp_flag;
1717 new_ndlp->nlp_flag = ndlp->nlp_flag;
1719 /* if new_ndlp had NLP_UNREG_INP set, keep it */
1720 if (keep_new_nlp_flag & NLP_UNREG_INP)
1721 new_ndlp->nlp_flag |= NLP_UNREG_INP;
1723 new_ndlp->nlp_flag &= ~NLP_UNREG_INP;
1725 /* if new_ndlp had NLP_RPI_REGISTERED set, keep it */
1726 if (keep_new_nlp_flag & NLP_RPI_REGISTERED)
1727 new_ndlp->nlp_flag |= NLP_RPI_REGISTERED;
1729 new_ndlp->nlp_flag &= ~NLP_RPI_REGISTERED;
1731 ndlp->nlp_flag = keep_new_nlp_flag;
1733 /* if ndlp had NLP_UNREG_INP set, keep it */
1734 if (keep_nlp_flag & NLP_UNREG_INP)
1735 ndlp->nlp_flag |= NLP_UNREG_INP;
1737 ndlp->nlp_flag &= ~NLP_UNREG_INP;
1739 /* if ndlp had NLP_RPI_REGISTERED set, keep it */
1740 if (keep_nlp_flag & NLP_RPI_REGISTERED)
1741 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
1743 ndlp->nlp_flag &= ~NLP_RPI_REGISTERED;
1745 spin_unlock_irq(shost->host_lock);
1747 /* Set nlp_states accordingly */
1748 keep_nlp_state = new_ndlp->nlp_state;
1749 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
1751 /* interchange the nvme remoteport structs */
1752 keep_nrport = new_ndlp->nrport;
1753 new_ndlp->nrport = ndlp->nrport;
1755 /* Move this back to NPR state */
1756 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
1757 /* The new_ndlp is replacing ndlp totally, so we need
1758 * to put ndlp on UNUSED list and try to free it.
1760 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1761 "3179 PLOGI confirm NEW: %x %x\n",
1762 new_ndlp->nlp_DID, keepDID);
1764 /* Fix up the rport accordingly */
1765 rport = ndlp->rport;
1767 rdata = rport->dd_data;
1768 if (rdata->pnode == ndlp) {
1769 /* break the link before dropping the ref */
1772 rdata->pnode = lpfc_nlp_get(new_ndlp);
1773 new_ndlp->rport = rport;
1775 new_ndlp->nlp_type = ndlp->nlp_type;
1778 /* Fix up the nvme rport */
1780 ndlp->nrport = NULL;
1784 /* We shall actually free the ndlp with both nlp_DID and
1785 * nlp_portname fields equals 0 to avoid any ndlp on the
1786 * nodelist never to be used.
1788 if (ndlp->nlp_DID == 0) {
1789 spin_lock_irq(&phba->ndlp_lock);
1790 NLP_SET_FREE_REQ(ndlp);
1791 spin_unlock_irq(&phba->ndlp_lock);
1794 /* Two ndlps cannot have the same did on the nodelist.
1795 * Note: for this case, ndlp has a NULL WWPN so setting
1796 * the nlp_fc4_type isn't required.
1798 ndlp->nlp_DID = keepDID;
1799 lpfc_nlp_set_state(vport, ndlp, keep_nlp_state);
1800 if (phba->sli_rev == LPFC_SLI_REV4 &&
1801 active_rrqs_xri_bitmap)
1802 memcpy(ndlp->active_rrqs_xri_bitmap,
1803 active_rrqs_xri_bitmap,
1804 phba->cfg_rrq_xri_bitmap_sz);
1806 if (!NLP_CHK_NODE_ACT(ndlp))
1807 lpfc_drop_node(vport, ndlp);
1810 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1811 "3180 PLOGI confirm SWAP: %x %x\n",
1812 new_ndlp->nlp_DID, keepDID);
1814 lpfc_unreg_rpi(vport, ndlp);
1816 /* Two ndlps cannot have the same did and the fc4
1817 * type must be transferred because the ndlp is in
1820 ndlp->nlp_DID = keepDID;
1821 ndlp->nlp_fc4_type = keep_nlp_fc4_type;
1823 if (phba->sli_rev == LPFC_SLI_REV4 &&
1824 active_rrqs_xri_bitmap)
1825 memcpy(ndlp->active_rrqs_xri_bitmap,
1826 active_rrqs_xri_bitmap,
1827 phba->cfg_rrq_xri_bitmap_sz);
1829 /* Since we are switching over to the new_ndlp,
1830 * reset the old ndlp state
1832 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
1833 (ndlp->nlp_state == NLP_STE_MAPPED_NODE))
1834 keep_nlp_state = NLP_STE_NPR_NODE;
1835 lpfc_nlp_set_state(vport, ndlp, keep_nlp_state);
1837 /* Previous ndlp no longer active with nvme host transport.
1838 * Remove reference from earlier registration unless the
1839 * nvme host took care of it.
1843 ndlp->nrport = keep_nrport;
1845 /* Fix up the rport accordingly */
1846 rport = ndlp->rport;
1848 rdata = rport->dd_data;
1849 put_node = rdata->pnode != NULL;
1850 put_rport = ndlp->rport != NULL;
1851 rdata->pnode = NULL;
1856 put_device(&rport->dev);
1859 if (phba->sli_rev == LPFC_SLI_REV4 &&
1860 active_rrqs_xri_bitmap)
1861 mempool_free(active_rrqs_xri_bitmap,
1862 phba->active_rrq_pool);
1864 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_NODE,
1865 "3173 PLOGI confirm exit: new_ndlp x%x x%x x%x\n",
1866 new_ndlp->nlp_DID, new_ndlp->nlp_flag,
1867 new_ndlp->nlp_fc4_type);
1873 * lpfc_end_rscn - Check and handle more rscn for a vport
1874 * @vport: pointer to a host virtual N_Port data structure.
1876 * This routine checks whether more Registration State Change
1877 * Notifications (RSCNs) came in while the discovery state machine was in
1878 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1879 * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1880 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1881 * handling the RSCNs.
1884 lpfc_end_rscn(struct lpfc_vport *vport)
1886 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1888 if (vport->fc_flag & FC_RSCN_MODE) {
1890 * Check to see if more RSCNs came in while we were
1891 * processing this one.
1893 if (vport->fc_rscn_id_cnt ||
1894 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
1895 lpfc_els_handle_rscn(vport);
1897 spin_lock_irq(shost->host_lock);
1898 vport->fc_flag &= ~FC_RSCN_MODE;
1899 spin_unlock_irq(shost->host_lock);
1905 * lpfc_cmpl_els_rrq - Completion handled for els RRQs.
1906 * @phba: pointer to lpfc hba data structure.
1907 * @cmdiocb: pointer to lpfc command iocb data structure.
1908 * @rspiocb: pointer to lpfc response iocb data structure.
1910 * This routine will call the clear rrq function to free the rrq and
1911 * clear the xri's bit in the ndlp's xri_bitmap. If the ndlp does not
1912 * exist then the clear_rrq is still called because the rrq needs to
1917 lpfc_cmpl_els_rrq(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1918 struct lpfc_iocbq *rspiocb)
1920 struct lpfc_vport *vport = cmdiocb->vport;
1922 struct lpfc_nodelist *ndlp;
1923 struct lpfc_node_rrq *rrq;
1925 /* we pass cmdiocb to state machine which needs rspiocb as well */
1926 rrq = cmdiocb->context_un.rrq;
1927 cmdiocb->context_un.rsp_iocb = rspiocb;
1929 irsp = &rspiocb->iocb;
1930 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1931 "RRQ cmpl: status:x%x/x%x did:x%x",
1932 irsp->ulpStatus, irsp->un.ulpWord[4],
1933 irsp->un.elsreq64.remoteID);
1935 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
1936 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || ndlp != rrq->ndlp) {
1937 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1938 "2882 RRQ completes to NPort x%x "
1939 "with no ndlp. Data: x%x x%x x%x\n",
1940 irsp->un.elsreq64.remoteID,
1941 irsp->ulpStatus, irsp->un.ulpWord[4],
1946 /* rrq completes to NPort <nlp_DID> */
1947 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1948 "2880 RRQ completes to NPort x%x "
1949 "Data: x%x x%x x%x x%x x%x\n",
1950 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1951 irsp->ulpTimeout, rrq->xritag, rrq->rxid);
1953 if (irsp->ulpStatus) {
1954 /* Check for retry */
1955 /* RRQ failed Don't print the vport to vport rjts */
1956 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1957 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1958 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1959 (phba)->pport->cfg_log_verbose & LOG_ELS)
1960 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1961 "2881 RRQ failure DID:%06X Status:x%x/x%x\n",
1962 ndlp->nlp_DID, irsp->ulpStatus,
1963 irsp->un.ulpWord[4]);
1967 lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
1968 lpfc_els_free_iocb(phba, cmdiocb);
1972 * lpfc_cmpl_els_plogi - Completion callback function for plogi
1973 * @phba: pointer to lpfc hba data structure.
1974 * @cmdiocb: pointer to lpfc command iocb data structure.
1975 * @rspiocb: pointer to lpfc response iocb data structure.
1977 * This routine is the completion callback function for issuing the Port
1978 * Login (PLOGI) command. For PLOGI completion, there must be an active
1979 * ndlp on the vport node list that matches the remote node ID from the
1980 * PLOGI response IOCB. If such ndlp does not exist, the PLOGI is simply
1981 * ignored and command IOCB released. The PLOGI response IOCB status is
1982 * checked for error conditons. If there is error status reported, PLOGI
1983 * retry shall be attempted by invoking the lpfc_els_retry() routine.
1984 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1985 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1986 * (DSM) is set for this PLOGI completion. Finally, it checks whether
1987 * there are additional N_Port nodes with the vport that need to perform
1988 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
1992 lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1993 struct lpfc_iocbq *rspiocb)
1995 struct lpfc_vport *vport = cmdiocb->vport;
1996 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1998 struct lpfc_nodelist *ndlp;
1999 struct lpfc_dmabuf *prsp;
2002 /* we pass cmdiocb to state machine which needs rspiocb as well */
2003 cmdiocb->context_un.rsp_iocb = rspiocb;
2005 irsp = &rspiocb->iocb;
2006 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2007 "PLOGI cmpl: status:x%x/x%x did:x%x",
2008 irsp->ulpStatus, irsp->un.ulpWord[4],
2009 irsp->un.elsreq64.remoteID);
2011 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
2012 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
2013 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2014 "0136 PLOGI completes to NPort x%x "
2015 "with no ndlp. Data: x%x x%x x%x\n",
2016 irsp->un.elsreq64.remoteID,
2017 irsp->ulpStatus, irsp->un.ulpWord[4],
2022 /* Since ndlp can be freed in the disc state machine, note if this node
2023 * is being used during discovery.
2025 spin_lock_irq(shost->host_lock);
2026 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
2027 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
2028 spin_unlock_irq(shost->host_lock);
2030 /* PLOGI completes to NPort <nlp_DID> */
2031 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2032 "0102 PLOGI completes to NPort x%06x "
2033 "Data: x%x x%x x%x x%x x%x\n",
2034 ndlp->nlp_DID, ndlp->nlp_fc4_type,
2035 irsp->ulpStatus, irsp->un.ulpWord[4],
2036 disc, vport->num_disc_nodes);
2038 /* Check to see if link went down during discovery */
2039 if (lpfc_els_chk_latt(vport)) {
2040 spin_lock_irq(shost->host_lock);
2041 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2042 spin_unlock_irq(shost->host_lock);
2046 if (irsp->ulpStatus) {
2047 /* Check for retry */
2048 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2049 /* ELS command is being retried */
2051 spin_lock_irq(shost->host_lock);
2052 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2053 spin_unlock_irq(shost->host_lock);
2057 /* PLOGI failed Don't print the vport to vport rjts */
2058 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
2059 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
2060 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
2061 (phba)->pport->cfg_log_verbose & LOG_ELS)
2062 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2063 "2753 PLOGI failure DID:%06X Status:x%x/x%x\n",
2064 ndlp->nlp_DID, irsp->ulpStatus,
2065 irsp->un.ulpWord[4]);
2066 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2067 if (!lpfc_error_lost_link(irsp))
2068 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2069 NLP_EVT_CMPL_PLOGI);
2071 /* Good status, call state machine */
2072 prsp = list_entry(((struct lpfc_dmabuf *)
2073 cmdiocb->context2)->list.next,
2074 struct lpfc_dmabuf, list);
2075 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
2076 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2077 NLP_EVT_CMPL_PLOGI);
2080 if (disc && vport->num_disc_nodes) {
2081 /* Check to see if there are more PLOGIs to be sent */
2082 lpfc_more_plogi(vport);
2084 if (vport->num_disc_nodes == 0) {
2085 spin_lock_irq(shost->host_lock);
2086 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2087 spin_unlock_irq(shost->host_lock);
2089 lpfc_can_disctmo(vport);
2090 lpfc_end_rscn(vport);
2095 lpfc_els_free_iocb(phba, cmdiocb);
2100 * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
2101 * @vport: pointer to a host virtual N_Port data structure.
2102 * @did: destination port identifier.
2103 * @retry: number of retries to the command IOCB.
2105 * This routine issues a Port Login (PLOGI) command to a remote N_Port
2106 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
2107 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
2108 * This routine constructs the proper feilds of the PLOGI IOCB and invokes
2109 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
2111 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2112 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2113 * will be stored into the context1 field of the IOCB for the completion
2114 * callback function to the PLOGI ELS command.
2117 * 0 - Successfully issued a plogi for @vport
2118 * 1 - failed to issue a plogi for @vport
2121 lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
2123 struct lpfc_hba *phba = vport->phba;
2124 struct Scsi_Host *shost;
2125 struct serv_parm *sp;
2126 struct lpfc_nodelist *ndlp;
2127 struct lpfc_iocbq *elsiocb;
2132 ndlp = lpfc_findnode_did(vport, did);
2135 /* Defer the processing of the issue PLOGI until after the
2136 * outstanding UNREG_RPI mbox command completes, unless we
2137 * are going offline. This logic does not apply for Fabric DIDs
2139 if ((ndlp->nlp_flag & NLP_UNREG_INP) &&
2140 ((ndlp->nlp_DID & Fabric_DID_MASK) != Fabric_DID_MASK) &&
2141 !(vport->fc_flag & FC_OFFLINE_MODE)) {
2142 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2143 "4110 Issue PLOGI x%x deferred "
2144 "on NPort x%x rpi x%x Data: x%px\n",
2145 ndlp->nlp_defer_did, ndlp->nlp_DID,
2146 ndlp->nlp_rpi, ndlp);
2148 /* We can only defer 1st PLOGI */
2149 if (ndlp->nlp_defer_did == NLP_EVT_NOTHING_PENDING)
2150 ndlp->nlp_defer_did = did;
2153 if (!NLP_CHK_NODE_ACT(ndlp))
2157 /* If ndlp is not NULL, we will bump the reference count on it */
2158 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
2159 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
2164 shost = lpfc_shost_from_vport(vport);
2165 spin_lock_irq(shost->host_lock);
2166 ndlp->nlp_flag &= ~NLP_FCP_PRLI_RJT;
2167 spin_unlock_irq(shost->host_lock);
2169 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2171 /* For PLOGI request, remainder of payload is service parameters */
2172 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
2173 pcmd += sizeof(uint32_t);
2174 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
2175 sp = (struct serv_parm *) pcmd;
2178 * If we are a N-port connected to a Fabric, fix-up paramm's so logins
2179 * to device on remote loops work.
2181 if ((vport->fc_flag & FC_FABRIC) && !(vport->fc_flag & FC_PUBLIC_LOOP))
2182 sp->cmn.altBbCredit = 1;
2184 if (sp->cmn.fcphLow < FC_PH_4_3)
2185 sp->cmn.fcphLow = FC_PH_4_3;
2187 if (sp->cmn.fcphHigh < FC_PH3)
2188 sp->cmn.fcphHigh = FC_PH3;
2190 sp->cmn.valid_vendor_ver_level = 0;
2191 memset(sp->un.vendorVersion, 0, sizeof(sp->un.vendorVersion));
2192 sp->cmn.bbRcvSizeMsb &= 0xF;
2194 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2195 "Issue PLOGI: did:x%x",
2198 /* If our firmware supports this feature, convey that
2199 * information to the target using the vendor specific field.
2201 if (phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) {
2202 sp->cmn.valid_vendor_ver_level = 1;
2203 sp->un.vv.vid = cpu_to_be32(LPFC_VV_EMLX_ID);
2204 sp->un.vv.flags = cpu_to_be32(LPFC_VV_SUPPRESS_RSP);
2207 phba->fc_stat.elsXmitPLOGI++;
2208 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
2209 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
2211 if (ret == IOCB_ERROR) {
2212 lpfc_els_free_iocb(phba, elsiocb);
2219 * lpfc_cmpl_els_prli - Completion callback function for prli
2220 * @phba: pointer to lpfc hba data structure.
2221 * @cmdiocb: pointer to lpfc command iocb data structure.
2222 * @rspiocb: pointer to lpfc response iocb data structure.
2224 * This routine is the completion callback function for a Process Login
2225 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
2226 * status. If there is error status reported, PRLI retry shall be attempted
2227 * by invoking the lpfc_els_retry() routine. Otherwise, the state
2228 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
2229 * ndlp to mark the PRLI completion.
2232 lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2233 struct lpfc_iocbq *rspiocb)
2235 struct lpfc_vport *vport = cmdiocb->vport;
2236 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2238 struct lpfc_nodelist *ndlp;
2241 /* we pass cmdiocb to state machine which needs rspiocb as well */
2242 cmdiocb->context_un.rsp_iocb = rspiocb;
2244 irsp = &(rspiocb->iocb);
2245 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2246 spin_lock_irq(shost->host_lock);
2247 ndlp->nlp_flag &= ~NLP_PRLI_SND;
2249 /* Driver supports multiple FC4 types. Counters matter. */
2250 vport->fc_prli_sent--;
2251 ndlp->fc4_prli_sent--;
2252 spin_unlock_irq(shost->host_lock);
2254 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2255 "PRLI cmpl: status:x%x/x%x did:x%x",
2256 irsp->ulpStatus, irsp->un.ulpWord[4],
2259 /* PRLI completes to NPort <nlp_DID> */
2260 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2261 "0103 PRLI completes to NPort x%06x "
2262 "Data: x%x x%x x%x x%x\n",
2263 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2264 vport->num_disc_nodes, ndlp->fc4_prli_sent);
2266 /* Check to see if link went down during discovery */
2267 if (lpfc_els_chk_latt(vport))
2270 if (irsp->ulpStatus) {
2271 /* Check for retry */
2272 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2273 /* ELS command is being retried */
2277 /* If we don't send GFT_ID to Fabric, a PRLI error
2278 * could be expected.
2280 if ((vport->fc_flag & FC_FABRIC) ||
2281 (vport->cfg_enable_fc4_type != LPFC_ENABLE_BOTH))
2287 lpfc_printf_vlog(vport, mode, LOG_ELS,
2288 "2754 PRLI failure DID:%06X Status:x%x/x%x, "
2290 ndlp->nlp_DID, irsp->ulpStatus,
2291 irsp->un.ulpWord[4], ndlp->fc4_prli_sent);
2293 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2294 if (lpfc_error_lost_link(irsp))
2297 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2300 /* Good status, call state machine. However, if another
2301 * PRLI is outstanding, don't call the state machine
2302 * because final disposition to Mapped or Unmapped is
2305 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2310 lpfc_els_free_iocb(phba, cmdiocb);
2315 * lpfc_issue_els_prli - Issue a prli iocb command for a vport
2316 * @vport: pointer to a host virtual N_Port data structure.
2317 * @ndlp: pointer to a node-list data structure.
2318 * @retry: number of retries to the command IOCB.
2320 * This routine issues a Process Login (PRLI) ELS command for the
2321 * @vport. The PRLI service parameters are set up in the payload of the
2322 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
2323 * is put to the IOCB completion callback func field before invoking the
2324 * routine lpfc_sli_issue_iocb() to send out PRLI command.
2326 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2327 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2328 * will be stored into the context1 field of the IOCB for the completion
2329 * callback function to the PRLI ELS command.
2332 * 0 - successfully issued prli iocb command for @vport
2333 * 1 - failed to issue prli iocb command for @vport
2336 lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2339 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2340 struct lpfc_hba *phba = vport->phba;
2342 struct lpfc_nvme_prli *npr_nvme;
2343 struct lpfc_iocbq *elsiocb;
2346 u32 local_nlp_type, elscmd;
2349 * If we are in RSCN mode, the FC4 types supported from a
2350 * previous GFT_ID command may not be accurate. So, if we
2351 * are a NVME Initiator, always look for the possibility of
2352 * the remote NPort beng a NVME Target.
2354 if (phba->sli_rev == LPFC_SLI_REV4 &&
2355 vport->fc_flag & FC_RSCN_MODE &&
2356 vport->nvmei_support)
2357 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
2358 local_nlp_type = ndlp->nlp_fc4_type;
2360 /* This routine will issue 1 or 2 PRLIs, so zero all the ndlp
2361 * fields here before any of them can complete.
2363 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
2364 ndlp->nlp_type &= ~(NLP_NVME_TARGET | NLP_NVME_INITIATOR);
2365 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
2366 ndlp->nlp_flag &= ~(NLP_FIRSTBURST | NLP_NPR_2B_DISC);
2367 ndlp->nvme_fb_size = 0;
2370 if (local_nlp_type & NLP_FC4_FCP) {
2371 /* Payload is 4 + 16 = 20 x14 bytes. */
2372 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
2373 elscmd = ELS_CMD_PRLI;
2374 } else if (local_nlp_type & NLP_FC4_NVME) {
2375 /* Payload is 4 + 20 = 24 x18 bytes. */
2376 cmdsize = (sizeof(uint32_t) + sizeof(struct lpfc_nvme_prli));
2377 elscmd = ELS_CMD_NVMEPRLI;
2379 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2380 "3083 Unknown FC_TYPE x%x ndlp x%06x\n",
2381 ndlp->nlp_fc4_type, ndlp->nlp_DID);
2385 /* SLI3 ports don't support NVME. If this rport is a strict NVME
2386 * FC4 type, implicitly LOGO.
2388 if (phba->sli_rev == LPFC_SLI_REV3 &&
2389 ndlp->nlp_fc4_type == NLP_FC4_NVME) {
2390 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2391 "3088 Rport fc4 type 0x%x not supported by SLI3 adapter\n",
2393 lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM);
2397 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2398 ndlp->nlp_DID, elscmd);
2402 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2404 /* For PRLI request, remainder of payload is service parameters */
2405 memset(pcmd, 0, cmdsize);
2407 if (local_nlp_type & NLP_FC4_FCP) {
2408 /* Remainder of payload is FCP PRLI parameter page.
2409 * Note: this data structure is defined as
2410 * BE/LE in the structure definition so no
2411 * byte swap call is made.
2413 *((uint32_t *)(pcmd)) = ELS_CMD_PRLI;
2414 pcmd += sizeof(uint32_t);
2418 * If our firmware version is 3.20 or later,
2419 * set the following bits for FC-TAPE support.
2421 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
2422 npr->ConfmComplAllowed = 1;
2424 npr->TaskRetryIdReq = 1;
2426 npr->estabImagePair = 1;
2427 npr->readXferRdyDis = 1;
2428 if (vport->cfg_first_burst_size)
2429 npr->writeXferRdyDis = 1;
2431 /* For FCP support */
2432 npr->prliType = PRLI_FCP_TYPE;
2433 npr->initiatorFunc = 1;
2434 elsiocb->iocb_flag |= LPFC_PRLI_FCP_REQ;
2436 /* Remove FCP type - processed. */
2437 local_nlp_type &= ~NLP_FC4_FCP;
2438 } else if (local_nlp_type & NLP_FC4_NVME) {
2439 /* Remainder of payload is NVME PRLI parameter page.
2440 * This data structure is the newer definition that
2441 * uses bf macros so a byte swap is required.
2443 *((uint32_t *)(pcmd)) = ELS_CMD_NVMEPRLI;
2444 pcmd += sizeof(uint32_t);
2445 npr_nvme = (struct lpfc_nvme_prli *)pcmd;
2446 bf_set(prli_type_code, npr_nvme, PRLI_NVME_TYPE);
2447 bf_set(prli_estabImagePair, npr_nvme, 0); /* Should be 0 */
2449 bf_set(prli_nsler, npr_nvme, 1);
2450 bf_set(prli_conf, npr_nvme, 1);
2453 /* Only initiators request first burst. */
2454 if ((phba->cfg_nvme_enable_fb) &&
2455 !phba->nvmet_support)
2456 bf_set(prli_fba, npr_nvme, 1);
2458 if (phba->nvmet_support) {
2459 bf_set(prli_tgt, npr_nvme, 1);
2460 bf_set(prli_disc, npr_nvme, 1);
2462 bf_set(prli_init, npr_nvme, 1);
2463 bf_set(prli_conf, npr_nvme, 1);
2466 npr_nvme->word1 = cpu_to_be32(npr_nvme->word1);
2467 npr_nvme->word4 = cpu_to_be32(npr_nvme->word4);
2468 elsiocb->iocb_flag |= LPFC_PRLI_NVME_REQ;
2470 /* Remove NVME type - processed. */
2471 local_nlp_type &= ~NLP_FC4_NVME;
2474 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2475 "Issue PRLI: did:x%x",
2476 ndlp->nlp_DID, 0, 0);
2478 phba->fc_stat.elsXmitPRLI++;
2479 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
2480 spin_lock_irq(shost->host_lock);
2481 ndlp->nlp_flag |= NLP_PRLI_SND;
2483 /* The vport counters are used for lpfc_scan_finished, but
2484 * the ndlp is used to track outstanding PRLIs for different
2487 vport->fc_prli_sent++;
2488 ndlp->fc4_prli_sent++;
2489 spin_unlock_irq(shost->host_lock);
2490 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2492 spin_lock_irq(shost->host_lock);
2493 ndlp->nlp_flag &= ~NLP_PRLI_SND;
2494 spin_unlock_irq(shost->host_lock);
2495 lpfc_els_free_iocb(phba, elsiocb);
2500 /* The driver supports 2 FC4 types. Make sure
2501 * a PRLI is issued for all types before exiting.
2503 if (phba->sli_rev == LPFC_SLI_REV4 &&
2504 local_nlp_type & (NLP_FC4_FCP | NLP_FC4_NVME))
2505 goto send_next_prli;
2511 * lpfc_rscn_disc - Perform rscn discovery for a vport
2512 * @vport: pointer to a host virtual N_Port data structure.
2514 * This routine performs Registration State Change Notification (RSCN)
2515 * discovery for a @vport. If the @vport's node port recovery count is not
2516 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
2517 * the nodes that need recovery. If none of the PLOGI were needed through
2518 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
2519 * invoked to check and handle possible more RSCN came in during the period
2520 * of processing the current ones.
2523 lpfc_rscn_disc(struct lpfc_vport *vport)
2525 lpfc_can_disctmo(vport);
2527 /* RSCN discovery */
2528 /* go thru NPR nodes and issue ELS PLOGIs */
2529 if (vport->fc_npr_cnt)
2530 if (lpfc_els_disc_plogi(vport))
2533 lpfc_end_rscn(vport);
2537 * lpfc_adisc_done - Complete the adisc phase of discovery
2538 * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
2540 * This function is called when the final ADISC is completed during discovery.
2541 * This function handles clearing link attention or issuing reg_vpi depending
2542 * on whether npiv is enabled. This function also kicks off the PLOGI phase of
2544 * This function is called with no locks held.
2547 lpfc_adisc_done(struct lpfc_vport *vport)
2549 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2550 struct lpfc_hba *phba = vport->phba;
2553 * For NPIV, cmpl_reg_vpi will set port_state to READY,
2554 * and continue discovery.
2556 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2557 !(vport->fc_flag & FC_RSCN_MODE) &&
2558 (phba->sli_rev < LPFC_SLI_REV4)) {
2559 /* The ADISCs are complete. Doesn't matter if they
2560 * succeeded or failed because the ADISC completion
2561 * routine guarantees to call the state machine and
2562 * the RPI is either unregistered (failed ADISC response)
2563 * or the RPI is still valid and the node is marked
2564 * mapped for a target. The exchanges should be in the
2565 * correct state. This code is specific to SLI3.
2567 lpfc_issue_clear_la(phba, vport);
2568 lpfc_issue_reg_vpi(phba, vport);
2572 * For SLI2, we need to set port_state to READY
2573 * and continue discovery.
2575 if (vport->port_state < LPFC_VPORT_READY) {
2576 /* If we get here, there is nothing to ADISC */
2577 lpfc_issue_clear_la(phba, vport);
2578 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
2579 vport->num_disc_nodes = 0;
2580 /* go thru NPR list, issue ELS PLOGIs */
2581 if (vport->fc_npr_cnt)
2582 lpfc_els_disc_plogi(vport);
2583 if (!vport->num_disc_nodes) {
2584 spin_lock_irq(shost->host_lock);
2585 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2586 spin_unlock_irq(shost->host_lock);
2587 lpfc_can_disctmo(vport);
2588 lpfc_end_rscn(vport);
2591 vport->port_state = LPFC_VPORT_READY;
2593 lpfc_rscn_disc(vport);
2597 * lpfc_more_adisc - Issue more adisc as needed
2598 * @vport: pointer to a host virtual N_Port data structure.
2600 * This routine determines whether there are more ndlps on a @vport
2601 * node list need to have Address Discover (ADISC) issued. If so, it will
2602 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
2603 * remaining nodes which need to have ADISC sent.
2606 lpfc_more_adisc(struct lpfc_vport *vport)
2608 if (vport->num_disc_nodes)
2609 vport->num_disc_nodes--;
2610 /* Continue discovery with <num_disc_nodes> ADISCs to go */
2611 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2612 "0210 Continue discovery with %d ADISCs to go "
2613 "Data: x%x x%x x%x\n",
2614 vport->num_disc_nodes, vport->fc_adisc_cnt,
2615 vport->fc_flag, vport->port_state);
2616 /* Check to see if there are more ADISCs to be sent */
2617 if (vport->fc_flag & FC_NLP_MORE) {
2618 lpfc_set_disctmo(vport);
2619 /* go thru NPR nodes and issue any remaining ELS ADISCs */
2620 lpfc_els_disc_adisc(vport);
2622 if (!vport->num_disc_nodes)
2623 lpfc_adisc_done(vport);
2628 * lpfc_cmpl_els_adisc - Completion callback function for adisc
2629 * @phba: pointer to lpfc hba data structure.
2630 * @cmdiocb: pointer to lpfc command iocb data structure.
2631 * @rspiocb: pointer to lpfc response iocb data structure.
2633 * This routine is the completion function for issuing the Address Discover
2634 * (ADISC) command. It first checks to see whether link went down during
2635 * the discovery process. If so, the node will be marked as node port
2636 * recovery for issuing discover IOCB by the link attention handler and
2637 * exit. Otherwise, the response status is checked. If error was reported
2638 * in the response status, the ADISC command shall be retried by invoking
2639 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
2640 * the response status, the state machine is invoked to set transition
2641 * with respect to NLP_EVT_CMPL_ADISC event.
2644 lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2645 struct lpfc_iocbq *rspiocb)
2647 struct lpfc_vport *vport = cmdiocb->vport;
2648 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2650 struct lpfc_nodelist *ndlp;
2653 /* we pass cmdiocb to state machine which needs rspiocb as well */
2654 cmdiocb->context_un.rsp_iocb = rspiocb;
2656 irsp = &(rspiocb->iocb);
2657 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2659 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2660 "ADISC cmpl: status:x%x/x%x did:x%x",
2661 irsp->ulpStatus, irsp->un.ulpWord[4],
2664 /* Since ndlp can be freed in the disc state machine, note if this node
2665 * is being used during discovery.
2667 spin_lock_irq(shost->host_lock);
2668 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
2669 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
2670 spin_unlock_irq(shost->host_lock);
2671 /* ADISC completes to NPort <nlp_DID> */
2672 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2673 "0104 ADISC completes to NPort x%x "
2674 "Data: x%x x%x x%x x%x x%x\n",
2675 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2676 irsp->ulpTimeout, disc, vport->num_disc_nodes);
2677 /* Check to see if link went down during discovery */
2678 if (lpfc_els_chk_latt(vport)) {
2679 spin_lock_irq(shost->host_lock);
2680 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2681 spin_unlock_irq(shost->host_lock);
2685 if (irsp->ulpStatus) {
2686 /* Check for retry */
2687 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2688 /* ELS command is being retried */
2690 spin_lock_irq(shost->host_lock);
2691 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2692 spin_unlock_irq(shost->host_lock);
2693 lpfc_set_disctmo(vport);
2698 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2699 "2755 ADISC failure DID:%06X Status:x%x/x%x\n",
2700 ndlp->nlp_DID, irsp->ulpStatus,
2701 irsp->un.ulpWord[4]);
2702 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2703 if (!lpfc_error_lost_link(irsp))
2704 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2705 NLP_EVT_CMPL_ADISC);
2707 /* Good status, call state machine */
2708 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2709 NLP_EVT_CMPL_ADISC);
2711 /* Check to see if there are more ADISCs to be sent */
2712 if (disc && vport->num_disc_nodes)
2713 lpfc_more_adisc(vport);
2715 lpfc_els_free_iocb(phba, cmdiocb);
2720 * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
2721 * @vport: pointer to a virtual N_Port data structure.
2722 * @ndlp: pointer to a node-list data structure.
2723 * @retry: number of retries to the command IOCB.
2725 * This routine issues an Address Discover (ADISC) for an @ndlp on a
2726 * @vport. It prepares the payload of the ADISC ELS command, updates the
2727 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
2728 * to issue the ADISC ELS command.
2730 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2731 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2732 * will be stored into the context1 field of the IOCB for the completion
2733 * callback function to the ADISC ELS command.
2736 * 0 - successfully issued adisc
2737 * 1 - failed to issue adisc
2740 lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2743 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2744 struct lpfc_hba *phba = vport->phba;
2746 struct lpfc_iocbq *elsiocb;
2750 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
2751 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2752 ndlp->nlp_DID, ELS_CMD_ADISC);
2756 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2758 /* For ADISC request, remainder of payload is service parameters */
2759 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
2760 pcmd += sizeof(uint32_t);
2762 /* Fill in ADISC payload */
2763 ap = (ADISC *) pcmd;
2764 ap->hardAL_PA = phba->fc_pref_ALPA;
2765 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2766 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
2767 ap->DID = be32_to_cpu(vport->fc_myDID);
2769 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2770 "Issue ADISC: did:x%x",
2771 ndlp->nlp_DID, 0, 0);
2773 phba->fc_stat.elsXmitADISC++;
2774 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
2775 spin_lock_irq(shost->host_lock);
2776 ndlp->nlp_flag |= NLP_ADISC_SND;
2777 spin_unlock_irq(shost->host_lock);
2778 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2780 spin_lock_irq(shost->host_lock);
2781 ndlp->nlp_flag &= ~NLP_ADISC_SND;
2782 spin_unlock_irq(shost->host_lock);
2783 lpfc_els_free_iocb(phba, elsiocb);
2790 * lpfc_cmpl_els_logo - Completion callback function for logo
2791 * @phba: pointer to lpfc hba data structure.
2792 * @cmdiocb: pointer to lpfc command iocb data structure.
2793 * @rspiocb: pointer to lpfc response iocb data structure.
2795 * This routine is the completion function for issuing the ELS Logout (LOGO)
2796 * command. If no error status was reported from the LOGO response, the
2797 * state machine of the associated ndlp shall be invoked for transition with
2798 * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
2799 * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
2802 lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2803 struct lpfc_iocbq *rspiocb)
2805 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2806 struct lpfc_vport *vport = ndlp->vport;
2807 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2809 struct lpfcMboxq *mbox;
2810 unsigned long flags;
2811 uint32_t skip_recovery = 0;
2813 /* we pass cmdiocb to state machine which needs rspiocb as well */
2814 cmdiocb->context_un.rsp_iocb = rspiocb;
2816 irsp = &(rspiocb->iocb);
2817 spin_lock_irq(shost->host_lock);
2818 ndlp->nlp_flag &= ~NLP_LOGO_SND;
2819 spin_unlock_irq(shost->host_lock);
2821 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2822 "LOGO cmpl: status:x%x/x%x did:x%x",
2823 irsp->ulpStatus, irsp->un.ulpWord[4],
2826 /* LOGO completes to NPort <nlp_DID> */
2827 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2828 "0105 LOGO completes to NPort x%x "
2829 "Data: x%x x%x x%x x%x\n",
2830 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2831 irsp->ulpTimeout, vport->num_disc_nodes);
2833 if (lpfc_els_chk_latt(vport)) {
2838 /* Check to see if link went down during discovery */
2839 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
2840 /* NLP_EVT_DEVICE_RM should unregister the RPI
2841 * which should abort all outstanding IOs.
2843 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2849 /* The LOGO will not be retried on failure. A LOGO was
2850 * issued to the remote rport and a ACC or RJT or no Answer are
2851 * all acceptable. Note the failure and move forward with
2852 * discovery. The PLOGI will retry.
2854 if (irsp->ulpStatus) {
2856 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2857 "2756 LOGO failure, No Retry DID:%06X Status:x%x/x%x\n",
2858 ndlp->nlp_DID, irsp->ulpStatus,
2859 irsp->un.ulpWord[4]);
2860 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2861 if (lpfc_error_lost_link(irsp)) {
2867 /* Call state machine. This will unregister the rpi if needed. */
2868 lpfc_disc_state_machine(vport, ndlp, cmdiocb, NLP_EVT_CMPL_LOGO);
2871 lpfc_els_free_iocb(phba, cmdiocb);
2872 /* If we are in pt2pt mode, we could rcv new S_ID on PLOGI */
2873 if ((vport->fc_flag & FC_PT2PT) &&
2874 !(vport->fc_flag & FC_PT2PT_PLOGI)) {
2875 phba->pport->fc_myDID = 0;
2877 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
2878 (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
2879 if (phba->nvmet_support)
2880 lpfc_nvmet_update_targetport(phba);
2882 lpfc_nvme_update_localport(phba->pport);
2885 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2887 lpfc_config_link(phba, mbox);
2888 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
2889 mbox->vport = vport;
2890 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) ==
2892 mempool_free(mbox, phba->mbox_mem_pool);
2899 * If the node is a target, the handling attempts to recover the port.
2900 * For any other port type, the rpi is unregistered as an implicit
2903 if (ndlp->nlp_type & (NLP_FCP_TARGET | NLP_NVME_TARGET) &&
2904 skip_recovery == 0) {
2905 lpfc_cancel_retry_delay_tmo(vport, ndlp);
2906 spin_lock_irqsave(shost->host_lock, flags);
2907 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2908 spin_unlock_irqrestore(shost->host_lock, flags);
2910 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2911 "3187 LOGO completes to NPort x%x: Start "
2912 "Recovery Data: x%x x%x x%x x%x\n",
2913 ndlp->nlp_DID, irsp->ulpStatus,
2914 irsp->un.ulpWord[4], irsp->ulpTimeout,
2915 vport->num_disc_nodes);
2916 lpfc_disc_start(vport);
2922 * lpfc_issue_els_logo - Issue a logo to an node on a vport
2923 * @vport: pointer to a virtual N_Port data structure.
2924 * @ndlp: pointer to a node-list data structure.
2925 * @retry: number of retries to the command IOCB.
2927 * This routine constructs and issues an ELS Logout (LOGO) iocb command
2928 * to a remote node, referred by an @ndlp on a @vport. It constructs the
2929 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
2930 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
2932 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2933 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2934 * will be stored into the context1 field of the IOCB for the completion
2935 * callback function to the LOGO ELS command.
2937 * Callers of this routine are expected to unregister the RPI first
2940 * 0 - successfully issued logo
2941 * 1 - failed to issue logo
2944 lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2947 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2948 struct lpfc_hba *phba = vport->phba;
2949 struct lpfc_iocbq *elsiocb;
2954 spin_lock_irq(shost->host_lock);
2955 if (ndlp->nlp_flag & NLP_LOGO_SND) {
2956 spin_unlock_irq(shost->host_lock);
2959 spin_unlock_irq(shost->host_lock);
2961 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
2962 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2963 ndlp->nlp_DID, ELS_CMD_LOGO);
2967 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2968 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
2969 pcmd += sizeof(uint32_t);
2971 /* Fill in LOGO payload */
2972 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
2973 pcmd += sizeof(uint32_t);
2974 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
2976 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2977 "Issue LOGO: did:x%x",
2978 ndlp->nlp_DID, 0, 0);
2980 phba->fc_stat.elsXmitLOGO++;
2981 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
2982 spin_lock_irq(shost->host_lock);
2983 ndlp->nlp_flag |= NLP_LOGO_SND;
2984 ndlp->nlp_flag &= ~NLP_ISSUE_LOGO;
2985 spin_unlock_irq(shost->host_lock);
2986 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
2987 if (rc == IOCB_ERROR) {
2988 spin_lock_irq(shost->host_lock);
2989 ndlp->nlp_flag &= ~NLP_LOGO_SND;
2990 spin_unlock_irq(shost->host_lock);
2991 lpfc_els_free_iocb(phba, elsiocb);
2995 spin_lock_irq(shost->host_lock);
2996 ndlp->nlp_prev_state = ndlp->nlp_state;
2997 spin_unlock_irq(shost->host_lock);
2998 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
3003 * lpfc_cmpl_els_cmd - Completion callback function for generic els command
3004 * @phba: pointer to lpfc hba data structure.
3005 * @cmdiocb: pointer to lpfc command iocb data structure.
3006 * @rspiocb: pointer to lpfc response iocb data structure.
3008 * This routine is a generic completion callback function for ELS commands.
3009 * Specifically, it is the callback function which does not need to perform
3010 * any command specific operations. It is currently used by the ELS command
3011 * issuing routines for RSCN, lpfc_issue_els_rscn, and the ELS Fibre Channel
3012 * Address Resolution Protocol Response (FARPR) routine, lpfc_issue_els_farpr().
3013 * Other than certain debug loggings, this callback function simply invokes the
3014 * lpfc_els_chk_latt() routine to check whether link went down during the
3015 * discovery process.
3018 lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3019 struct lpfc_iocbq *rspiocb)
3021 struct lpfc_vport *vport = cmdiocb->vport;
3024 irsp = &rspiocb->iocb;
3026 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3027 "ELS cmd cmpl: status:x%x/x%x did:x%x",
3028 irsp->ulpStatus, irsp->un.ulpWord[4],
3029 irsp->un.elsreq64.remoteID);
3031 /* ELS cmd tag <ulpIoTag> completes */
3032 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3033 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
3034 irsp->ulpIoTag, irsp->ulpStatus,
3035 irsp->un.ulpWord[4], irsp->ulpTimeout);
3037 /* Check to see if link went down during discovery */
3038 lpfc_els_chk_latt(vport);
3039 lpfc_els_free_iocb(phba, cmdiocb);
3043 * lpfc_cmpl_els_disc_cmd - Completion callback function for Discovery ELS cmd
3044 * @phba: pointer to lpfc hba data structure.
3045 * @cmdiocb: pointer to lpfc command iocb data structure.
3046 * @rspiocb: pointer to lpfc response iocb data structure.
3048 * This routine is a generic completion callback function for Discovery ELS cmd.
3049 * Currently used by the ELS command issuing routines for the ELS State Change
3050 * Request (SCR), lpfc_issue_els_scr() and the ELS RDF, lpfc_issue_els_rdf().
3051 * These commands will be retried once only for ELS timeout errors.
3054 lpfc_cmpl_els_disc_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3055 struct lpfc_iocbq *rspiocb)
3057 struct lpfc_vport *vport = cmdiocb->vport;
3059 struct lpfc_els_rdf_rsp *prdf;
3060 struct lpfc_dmabuf *pcmd, *prsp;
3064 irsp = &rspiocb->iocb;
3066 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3067 "ELS cmd cmpl: status:x%x/x%x did:x%x",
3068 irsp->ulpStatus, irsp->un.ulpWord[4],
3069 irsp->un.elsreq64.remoteID);
3070 /* ELS cmd tag <ulpIoTag> completes */
3071 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3072 "0217 ELS cmd tag x%x completes Data: x%x x%x x%x "
3074 irsp->ulpIoTag, irsp->ulpStatus,
3075 irsp->un.ulpWord[4], irsp->ulpTimeout,
3078 pcmd = (struct lpfc_dmabuf *)cmdiocb->context2;
3082 pdata = (u32 *)pcmd->virt;
3087 /* Only 1 retry for ELS Timeout only */
3088 if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT &&
3089 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
3090 IOERR_SEQUENCE_TIMEOUT)) {
3092 if (cmdiocb->retry <= 1) {
3095 lpfc_issue_els_scr(vport, cmdiocb->retry);
3098 cmdiocb->context1 = NULL; /* save ndlp refcnt */
3099 lpfc_issue_els_rdf(vport, cmdiocb->retry);
3104 phba->fc_stat.elsRetryExceeded++;
3106 if (irsp->ulpStatus) {
3107 /* ELS discovery cmd completes with error */
3108 lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS,
3109 "4203 ELS cmd x%x error: x%x x%X\n", cmd,
3110 irsp->ulpStatus, irsp->un.ulpWord[4]);
3114 /* The RDF response doesn't have any impact on the running driver
3115 * but the notification descriptors are dumped here for support.
3117 if (cmd == ELS_CMD_RDF) {
3120 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
3124 prdf = (struct lpfc_els_rdf_rsp *)prsp->virt;
3128 for (i = 0; i < ELS_RDF_REG_TAG_CNT &&
3129 i < be32_to_cpu(prdf->reg_d1.reg_desc.count); i++)
3130 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3131 "4677 Fabric RDF Notification Grant Data: "
3134 prdf->reg_d1.desc_tags[i]));
3138 /* Check to see if link went down during discovery */
3139 lpfc_els_chk_latt(vport);
3140 lpfc_els_free_iocb(phba, cmdiocb);
3145 * lpfc_issue_els_scr - Issue a scr to an node on a vport
3146 * @vport: pointer to a host virtual N_Port data structure.
3147 * @retry: retry counter for the command IOCB.
3149 * This routine issues a State Change Request (SCR) to a fabric node
3150 * on a @vport. The remote node is Fabric Controller (0xfffffd). It
3151 * first search the @vport node list to find the matching ndlp. If no such
3152 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
3153 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
3154 * routine is invoked to send the SCR IOCB.
3156 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3157 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3158 * will be stored into the context1 field of the IOCB for the completion
3159 * callback function to the SCR ELS command.
3162 * 0 - Successfully issued scr command
3163 * 1 - Failed to issue scr command
3166 lpfc_issue_els_scr(struct lpfc_vport *vport, uint8_t retry)
3168 struct lpfc_hba *phba = vport->phba;
3169 struct lpfc_iocbq *elsiocb;
3172 struct lpfc_nodelist *ndlp;
3174 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
3176 ndlp = lpfc_findnode_did(vport, Fabric_Cntl_DID);
3178 ndlp = lpfc_nlp_init(vport, Fabric_Cntl_DID);
3181 lpfc_enqueue_node(vport, ndlp);
3182 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
3183 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
3188 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
3189 ndlp->nlp_DID, ELS_CMD_SCR);
3192 /* This will trigger the release of the node just
3199 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3201 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
3202 pcmd += sizeof(uint32_t);
3204 /* For SCR, remainder of payload is SCR parameter page */
3205 memset(pcmd, 0, sizeof(SCR));
3206 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
3208 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3209 "Issue SCR: did:x%x",
3210 ndlp->nlp_DID, 0, 0);
3212 phba->fc_stat.elsXmitSCR++;
3213 elsiocb->iocb_cmpl = lpfc_cmpl_els_disc_cmd;
3214 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
3216 /* The additional lpfc_nlp_put will cause the following
3217 * lpfc_els_free_iocb routine to trigger the rlease of
3221 lpfc_els_free_iocb(phba, elsiocb);
3224 /* This will cause the callback-function lpfc_cmpl_els_cmd to
3225 * trigger the release of node.
3227 if (!(vport->fc_flag & FC_PT2PT))
3233 * lpfc_issue_els_rscn - Issue an RSCN to the Fabric Controller (Fabric)
3234 * or the other nport (pt2pt).
3235 * @vport: pointer to a host virtual N_Port data structure.
3236 * @retry: number of retries to the command IOCB.
3238 * This routine issues a RSCN to the Fabric Controller (DID 0xFFFFFD)
3239 * when connected to a fabric, or to the remote port when connected
3240 * in point-to-point mode. When sent to the Fabric Controller, it will
3241 * replay the RSCN to registered recipients.
3243 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3244 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3245 * will be stored into the context1 field of the IOCB for the completion
3246 * callback function to the RSCN ELS command.
3249 * 0 - Successfully issued RSCN command
3250 * 1 - Failed to issue RSCN command
3253 lpfc_issue_els_rscn(struct lpfc_vport *vport, uint8_t retry)
3255 struct lpfc_hba *phba = vport->phba;
3256 struct lpfc_iocbq *elsiocb;
3257 struct lpfc_nodelist *ndlp;
3259 struct fc_els_rscn rscn;
3260 struct fc_els_rscn_page portid;
3263 uint16_t cmdsize = sizeof(*event);
3265 /* Not supported for private loop */
3266 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP &&
3267 !(vport->fc_flag & FC_PUBLIC_LOOP))
3270 if (vport->fc_flag & FC_PT2PT) {
3271 /* find any mapped nport - that would be the other nport */
3272 ndlp = lpfc_findnode_mapped(vport);
3276 nportid = FC_FID_FCTRL;
3277 /* find the fabric controller node */
3278 ndlp = lpfc_findnode_did(vport, nportid);
3280 /* if one didn't exist, make one */
3281 ndlp = lpfc_nlp_init(vport, nportid);
3284 lpfc_enqueue_node(vport, ndlp);
3285 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
3286 ndlp = lpfc_enable_node(vport, ndlp,
3287 NLP_STE_UNUSED_NODE);
3293 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
3294 ndlp->nlp_DID, ELS_CMD_RSCN_XMT);
3297 /* This will trigger the release of the node just
3304 event = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
3306 event->rscn.rscn_cmd = ELS_RSCN;
3307 event->rscn.rscn_page_len = sizeof(struct fc_els_rscn_page);
3308 event->rscn.rscn_plen = cpu_to_be16(cmdsize);
3310 nportid = vport->fc_myDID;
3311 /* appears that page flags must be 0 for fabric to broadcast RSCN */
3312 event->portid.rscn_page_flags = 0;
3313 event->portid.rscn_fid[0] = (nportid & 0x00FF0000) >> 16;
3314 event->portid.rscn_fid[1] = (nportid & 0x0000FF00) >> 8;
3315 event->portid.rscn_fid[2] = nportid & 0x000000FF;
3317 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3318 "Issue RSCN: did:x%x",
3319 ndlp->nlp_DID, 0, 0);
3321 phba->fc_stat.elsXmitRSCN++;
3322 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
3323 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
3325 /* The additional lpfc_nlp_put will cause the following
3326 * lpfc_els_free_iocb routine to trigger the rlease of
3330 lpfc_els_free_iocb(phba, elsiocb);
3333 /* This will cause the callback-function lpfc_cmpl_els_cmd to
3334 * trigger the release of node.
3336 if (!(vport->fc_flag & FC_PT2PT))
3343 * lpfc_issue_els_farpr - Issue a farp to an node on a vport
3344 * @vport: pointer to a host virtual N_Port data structure.
3345 * @nportid: N_Port identifier to the remote node.
3346 * @retry: number of retries to the command IOCB.
3348 * This routine issues a Fibre Channel Address Resolution Response
3349 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
3350 * is passed into the function. It first search the @vport node list to find
3351 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
3352 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
3353 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
3355 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3356 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3357 * will be stored into the context1 field of the IOCB for the completion
3358 * callback function to the PARPR ELS command.
3361 * 0 - Successfully issued farpr command
3362 * 1 - Failed to issue farpr command
3365 lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
3367 struct lpfc_hba *phba = vport->phba;
3368 struct lpfc_iocbq *elsiocb;
3373 struct lpfc_nodelist *ondlp;
3374 struct lpfc_nodelist *ndlp;
3376 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
3378 ndlp = lpfc_findnode_did(vport, nportid);
3380 ndlp = lpfc_nlp_init(vport, nportid);
3383 lpfc_enqueue_node(vport, ndlp);
3384 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
3385 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
3390 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
3391 ndlp->nlp_DID, ELS_CMD_RNID);
3393 /* This will trigger the release of the node just
3400 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3402 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
3403 pcmd += sizeof(uint32_t);
3405 /* Fill in FARPR payload */
3406 fp = (FARP *) (pcmd);
3407 memset(fp, 0, sizeof(FARP));
3408 lp = (uint32_t *) pcmd;
3409 *lp++ = be32_to_cpu(nportid);
3410 *lp++ = be32_to_cpu(vport->fc_myDID);
3412 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
3414 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
3415 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
3416 ondlp = lpfc_findnode_did(vport, nportid);
3417 if (ondlp && NLP_CHK_NODE_ACT(ondlp)) {
3418 memcpy(&fp->OportName, &ondlp->nlp_portname,
3419 sizeof(struct lpfc_name));
3420 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
3421 sizeof(struct lpfc_name));
3424 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3425 "Issue FARPR: did:x%x",
3426 ndlp->nlp_DID, 0, 0);
3428 phba->fc_stat.elsXmitFARPR++;
3429 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
3430 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
3432 /* The additional lpfc_nlp_put will cause the following
3433 * lpfc_els_free_iocb routine to trigger the release of
3437 lpfc_els_free_iocb(phba, elsiocb);
3440 /* This will cause the callback-function lpfc_cmpl_els_cmd to
3441 * trigger the release of the node.
3443 /* Don't release reference count as RDF is likely outstanding */
3448 * lpfc_issue_els_rdf - Register for diagnostic functions from the fabric.
3449 * @vport: pointer to a host virtual N_Port data structure.
3450 * @retry: retry counter for the command IOCB.
3452 * This routine issues an ELS RDF to the Fabric Controller to register
3453 * for diagnostic functions.
3455 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3456 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3457 * will be stored into the context1 field of the IOCB for the completion
3458 * callback function to the RDF ELS command.
3461 * 0 - Successfully issued rdf command
3462 * 1 - Failed to issue rdf command
3465 lpfc_issue_els_rdf(struct lpfc_vport *vport, uint8_t retry)
3467 struct lpfc_hba *phba = vport->phba;
3468 struct lpfc_iocbq *elsiocb;
3469 struct lpfc_els_rdf_req *prdf;
3470 struct lpfc_nodelist *ndlp;
3473 cmdsize = sizeof(*prdf);
3475 ndlp = lpfc_findnode_did(vport, Fabric_Cntl_DID);
3477 ndlp = lpfc_nlp_init(vport, Fabric_Cntl_DID);
3480 lpfc_enqueue_node(vport, ndlp);
3481 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
3482 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
3487 /* RDF ELS is not required on an NPIV VN_Port. */
3488 if (vport->port_type == LPFC_NPIV_PORT) {
3493 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
3494 ndlp->nlp_DID, ELS_CMD_RDF);
3496 /* This will trigger the release of the node just
3503 /* Configure the payload for the supported FPIN events. */
3504 prdf = (struct lpfc_els_rdf_req *)
3505 (((struct lpfc_dmabuf *)elsiocb->context2)->virt);
3506 memset(prdf, 0, cmdsize);
3507 prdf->rdf.fpin_cmd = ELS_RDF;
3508 prdf->rdf.desc_len = cpu_to_be32(sizeof(struct lpfc_els_rdf_req) -
3509 sizeof(struct fc_els_rdf));
3510 prdf->reg_d1.reg_desc.desc_tag = cpu_to_be32(ELS_DTAG_FPIN_REGISTER);
3511 prdf->reg_d1.reg_desc.desc_len = cpu_to_be32(
3512 FC_TLV_DESC_LENGTH_FROM_SZ(prdf->reg_d1));
3513 prdf->reg_d1.reg_desc.count = cpu_to_be32(ELS_RDF_REG_TAG_CNT);
3514 prdf->reg_d1.desc_tags[0] = cpu_to_be32(ELS_DTAG_LNK_INTEGRITY);
3516 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3517 "Issue RDF: did:x%x",
3518 ndlp->nlp_DID, 0, 0);
3520 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3521 "6444 Xmit RDF to remote NPORT x%x\n",
3524 elsiocb->iocb_cmpl = lpfc_cmpl_els_disc_cmd;
3525 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
3527 /* The additional lpfc_nlp_put will cause the following
3528 * lpfc_els_free_iocb routine to trigger the rlease of
3532 lpfc_els_free_iocb(phba, elsiocb);
3536 /* An RDF was issued - this put ensures the ndlp is cleaned up
3537 * when the RDF completes.
3544 * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
3545 * @vport: pointer to a host virtual N_Port data structure.
3546 * @nlp: pointer to a node-list data structure.
3548 * This routine cancels the timer with a delayed IOCB-command retry for
3549 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
3550 * removes the ELS retry event if it presents. In addition, if the
3551 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
3552 * commands are sent for the @vport's nodes that require issuing discovery
3556 lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
3558 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3559 struct lpfc_work_evt *evtp;
3561 if (!(nlp->nlp_flag & NLP_DELAY_TMO))
3563 spin_lock_irq(shost->host_lock);
3564 nlp->nlp_flag &= ~NLP_DELAY_TMO;
3565 spin_unlock_irq(shost->host_lock);
3566 del_timer_sync(&nlp->nlp_delayfunc);
3567 nlp->nlp_last_elscmd = 0;
3568 if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
3569 list_del_init(&nlp->els_retry_evt.evt_listp);
3570 /* Decrement nlp reference count held for the delayed retry */
3571 evtp = &nlp->els_retry_evt;
3572 lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
3574 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
3575 spin_lock_irq(shost->host_lock);
3576 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
3577 spin_unlock_irq(shost->host_lock);
3578 if (vport->num_disc_nodes) {
3579 if (vport->port_state < LPFC_VPORT_READY) {
3580 /* Check if there are more ADISCs to be sent */
3581 lpfc_more_adisc(vport);
3583 /* Check if there are more PLOGIs to be sent */
3584 lpfc_more_plogi(vport);
3585 if (vport->num_disc_nodes == 0) {
3586 spin_lock_irq(shost->host_lock);
3587 vport->fc_flag &= ~FC_NDISC_ACTIVE;
3588 spin_unlock_irq(shost->host_lock);
3589 lpfc_can_disctmo(vport);
3590 lpfc_end_rscn(vport);
3599 * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
3600 * @ptr: holder for the pointer to the timer function associated data (ndlp).
3602 * This routine is invoked by the ndlp delayed-function timer to check
3603 * whether there is any pending ELS retry event(s) with the node. If not, it
3604 * simply returns. Otherwise, if there is at least one ELS delayed event, it
3605 * adds the delayed events to the HBA work list and invokes the
3606 * lpfc_worker_wake_up() routine to wake up worker thread to process the
3607 * event. Note that lpfc_nlp_get() is called before posting the event to
3608 * the work list to hold reference count of ndlp so that it guarantees the
3609 * reference to ndlp will still be available when the worker thread gets
3610 * to the event associated with the ndlp.
3613 lpfc_els_retry_delay(struct timer_list *t)
3615 struct lpfc_nodelist *ndlp = from_timer(ndlp, t, nlp_delayfunc);
3616 struct lpfc_vport *vport = ndlp->vport;
3617 struct lpfc_hba *phba = vport->phba;
3618 unsigned long flags;
3619 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
3621 spin_lock_irqsave(&phba->hbalock, flags);
3622 if (!list_empty(&evtp->evt_listp)) {
3623 spin_unlock_irqrestore(&phba->hbalock, flags);
3627 /* We need to hold the node by incrementing the reference
3628 * count until the queued work is done
3630 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
3631 if (evtp->evt_arg1) {
3632 evtp->evt = LPFC_EVT_ELS_RETRY;
3633 list_add_tail(&evtp->evt_listp, &phba->work_list);
3634 lpfc_worker_wake_up(phba);
3636 spin_unlock_irqrestore(&phba->hbalock, flags);
3641 * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
3642 * @ndlp: pointer to a node-list data structure.
3644 * This routine is the worker-thread handler for processing the @ndlp delayed
3645 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
3646 * the last ELS command from the associated ndlp and invokes the proper ELS
3647 * function according to the delayed ELS command to retry the command.
3650 lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
3652 struct lpfc_vport *vport = ndlp->vport;
3653 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3654 uint32_t cmd, retry;
3656 spin_lock_irq(shost->host_lock);
3657 cmd = ndlp->nlp_last_elscmd;
3658 ndlp->nlp_last_elscmd = 0;
3660 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
3661 spin_unlock_irq(shost->host_lock);
3665 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
3666 spin_unlock_irq(shost->host_lock);
3668 * If a discovery event readded nlp_delayfunc after timer
3669 * firing and before processing the timer, cancel the
3672 del_timer_sync(&ndlp->nlp_delayfunc);
3673 retry = ndlp->nlp_retry;
3674 ndlp->nlp_retry = 0;
3678 lpfc_issue_els_flogi(vport, ndlp, retry);
3681 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
3682 ndlp->nlp_prev_state = ndlp->nlp_state;
3683 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
3687 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
3688 ndlp->nlp_prev_state = ndlp->nlp_state;
3689 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
3693 case ELS_CMD_NVMEPRLI:
3694 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
3695 ndlp->nlp_prev_state = ndlp->nlp_state;
3696 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
3700 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
3701 ndlp->nlp_prev_state = ndlp->nlp_state;
3702 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
3706 if (!(vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI))
3707 lpfc_issue_els_fdisc(vport, ndlp, retry);
3714 * lpfc_link_reset - Issue link reset
3715 * @vport: pointer to a virtual N_Port data structure.
3717 * This routine performs link reset by sending INIT_LINK mailbox command.
3718 * For SLI-3 adapter, link attention interrupt is enabled before issuing
3719 * INIT_LINK mailbox command.
3722 * 0 - Link reset initiated successfully
3723 * 1 - Failed to initiate link reset
3726 lpfc_link_reset(struct lpfc_vport *vport)
3728 struct lpfc_hba *phba = vport->phba;
3733 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3734 "2851 Attempt link reset\n");
3735 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3737 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
3738 "2852 Failed to allocate mbox memory");
3742 /* Enable Link attention interrupts */
3743 if (phba->sli_rev <= LPFC_SLI_REV3) {
3744 spin_lock_irq(&phba->hbalock);
3745 phba->sli.sli_flag |= LPFC_PROCESS_LA;
3746 control = readl(phba->HCregaddr);
3747 control |= HC_LAINT_ENA;
3748 writel(control, phba->HCregaddr);
3749 readl(phba->HCregaddr); /* flush */
3750 spin_unlock_irq(&phba->hbalock);
3753 lpfc_init_link(phba, mbox, phba->cfg_topology,
3754 phba->cfg_link_speed);
3755 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
3756 mbox->vport = vport;
3757 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
3758 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
3759 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
3760 "2853 Failed to issue INIT_LINK "
3761 "mbox command, rc:x%x\n", rc);
3762 mempool_free(mbox, phba->mbox_mem_pool);
3770 * lpfc_els_retry - Make retry decision on an els command iocb
3771 * @phba: pointer to lpfc hba data structure.
3772 * @cmdiocb: pointer to lpfc command iocb data structure.
3773 * @rspiocb: pointer to lpfc response iocb data structure.
3775 * This routine makes a retry decision on an ELS command IOCB, which has
3776 * failed. The following ELS IOCBs use this function for retrying the command
3777 * when previously issued command responsed with error status: FLOGI, PLOGI,
3778 * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
3779 * returned error status, it makes the decision whether a retry shall be
3780 * issued for the command, and whether a retry shall be made immediately or
3781 * delayed. In the former case, the corresponding ELS command issuing-function
3782 * is called to retry the command. In the later case, the ELS command shall
3783 * be posted to the ndlp delayed event and delayed function timer set to the
3784 * ndlp for the delayed command issusing.
3787 * 0 - No retry of els command is made
3788 * 1 - Immediate or delayed retry of els command is made
3791 lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3792 struct lpfc_iocbq *rspiocb)
3794 struct lpfc_vport *vport = cmdiocb->vport;
3795 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3796 IOCB_t *irsp = &rspiocb->iocb;
3797 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3798 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3801 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
3805 int link_reset = 0, rc;
3808 /* Note: context2 may be 0 for internal driver abort
3809 * of delays ELS command.
3812 if (pcmd && pcmd->virt) {
3813 elscmd = (uint32_t *) (pcmd->virt);
3817 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
3818 did = ndlp->nlp_DID;
3820 /* We should only hit this case for retrying PLOGI */
3821 did = irsp->un.elsreq64.remoteID;
3822 ndlp = lpfc_findnode_did(vport, did);
3823 if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp))
3824 && (cmd != ELS_CMD_PLOGI))
3828 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3829 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
3830 *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
3832 switch (irsp->ulpStatus) {
3833 case IOSTAT_FCP_RSP_ERROR:
3835 case IOSTAT_REMOTE_STOP:
3836 if (phba->sli_rev == LPFC_SLI_REV4) {
3837 /* This IO was aborted by the target, we don't
3838 * know the rxid and because we did not send the
3839 * ABTS we cannot generate and RRQ.
3841 lpfc_set_rrq_active(phba, ndlp,
3842 cmdiocb->sli4_lxritag, 0, 0);
3845 case IOSTAT_LOCAL_REJECT:
3846 switch ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK)) {
3847 case IOERR_LOOP_OPEN_FAILURE:
3848 if (cmd == ELS_CMD_FLOGI) {
3849 if (PCI_DEVICE_ID_HORNET ==
3850 phba->pcidev->device) {
3851 phba->fc_topology = LPFC_TOPOLOGY_LOOP;
3852 phba->pport->fc_myDID = 0;
3853 phba->alpa_map[0] = 0;
3854 phba->alpa_map[1] = 0;
3857 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
3862 case IOERR_ILLEGAL_COMMAND:
3863 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3864 "0124 Retry illegal cmd x%x "
3865 "retry:x%x delay:x%x\n",
3866 cmd, cmdiocb->retry, delay);
3868 /* All command's retry policy */
3870 if (cmdiocb->retry > 2)
3874 case IOERR_NO_RESOURCES:
3875 logerr = 1; /* HBA out of resources */
3877 if (cmdiocb->retry > 100)
3882 case IOERR_ILLEGAL_FRAME:
3887 case IOERR_INVALID_RPI:
3888 if (cmd == ELS_CMD_PLOGI &&
3889 did == NameServer_DID) {
3890 /* Continue forever if plogi to */
3891 /* the nameserver fails */
3898 case IOERR_SEQUENCE_TIMEOUT:
3899 if (cmd == ELS_CMD_PLOGI &&
3900 did == NameServer_DID &&
3901 (cmdiocb->retry + 1) == maxretry) {
3902 /* Reset the Link */
3912 case IOSTAT_NPORT_RJT:
3913 case IOSTAT_FABRIC_RJT:
3914 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
3920 case IOSTAT_NPORT_BSY:
3921 case IOSTAT_FABRIC_BSY:
3922 logerr = 1; /* Fabric / Remote NPort out of resources */
3927 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
3928 /* Added for Vendor specifc support
3929 * Just keep retrying for these Rsn / Exp codes
3931 switch (stat.un.b.lsRjtRsnCode) {
3932 case LSRJT_UNABLE_TPC:
3933 /* The driver has a VALID PLOGI but the rport has
3934 * rejected the PRLI - can't do it now. Delay
3935 * for 1 second and try again - don't care about
3938 if (cmd == ELS_CMD_PRLI || cmd == ELS_CMD_NVMEPRLI) {
3940 maxretry = lpfc_max_els_tries + 1;
3945 /* Legacy bug fix code for targets with PLOGI delays. */
3946 if (stat.un.b.lsRjtRsnCodeExp ==
3947 LSEXP_CMD_IN_PROGRESS) {
3948 if (cmd == ELS_CMD_PLOGI) {
3955 if (stat.un.b.lsRjtRsnCodeExp ==
3956 LSEXP_CANT_GIVE_DATA) {
3957 if (cmd == ELS_CMD_PLOGI) {
3964 if (cmd == ELS_CMD_PLOGI) {
3966 maxretry = lpfc_max_els_tries + 1;
3970 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
3971 (cmd == ELS_CMD_FDISC) &&
3972 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
3973 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3974 "0125 FDISC Failed (x%x). "
3975 "Fabric out of resources\n",
3976 stat.un.lsRjtError);
3977 lpfc_vport_set_state(vport,
3978 FC_VPORT_NO_FABRIC_RSCS);
3982 case LSRJT_LOGICAL_BSY:
3983 if ((cmd == ELS_CMD_PLOGI) ||
3984 (cmd == ELS_CMD_PRLI) ||
3985 (cmd == ELS_CMD_NVMEPRLI)) {
3988 } else if (cmd == ELS_CMD_FDISC) {
3989 /* FDISC retry policy */
3991 if (cmdiocb->retry >= 32)
3997 case LSRJT_LOGICAL_ERR:
3998 /* There are some cases where switches return this
3999 * error when they are not ready and should be returning
4000 * Logical Busy. We should delay every time.
4002 if (cmd == ELS_CMD_FDISC &&
4003 stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
4007 } else if (cmd == ELS_CMD_FLOGI &&
4008 stat.un.b.lsRjtRsnCodeExp ==
4009 LSEXP_NOTHING_MORE) {
4010 vport->fc_sparam.cmn.bbRcvSizeMsb &= 0xf;
4012 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4013 "0820 FLOGI Failed (x%x). "
4014 "BBCredit Not Supported\n",
4015 stat.un.lsRjtError);
4019 case LSRJT_PROTOCOL_ERR:
4020 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
4021 (cmd == ELS_CMD_FDISC) &&
4022 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
4023 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
4025 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4026 "0122 FDISC Failed (x%x). "
4027 "Fabric Detected Bad WWN\n",
4028 stat.un.lsRjtError);
4029 lpfc_vport_set_state(vport,
4030 FC_VPORT_FABRIC_REJ_WWN);
4033 case LSRJT_VENDOR_UNIQUE:
4034 if ((stat.un.b.vendorUnique == 0x45) &&
4035 (cmd == ELS_CMD_FLOGI)) {
4039 case LSRJT_CMD_UNSUPPORTED:
4040 /* lpfc nvmet returns this type of LS_RJT when it
4041 * receives an FCP PRLI because lpfc nvmet only
4042 * support NVME. ELS request is terminated for FCP4
4045 if (stat.un.b.lsRjtRsnCodeExp ==
4046 LSEXP_REQ_UNSUPPORTED && cmd == ELS_CMD_PRLI) {
4047 spin_lock_irq(shost->host_lock);
4048 ndlp->nlp_flag |= NLP_FCP_PRLI_RJT;
4049 spin_unlock_irq(shost->host_lock);
4057 case IOSTAT_INTERMED_RSP:
4066 rc = lpfc_link_reset(vport);
4068 /* Do not give up. Retry PLOGI one more time and attempt
4069 * link reset if PLOGI fails again.
4078 if (did == FDMI_DID)
4081 if ((cmd == ELS_CMD_FLOGI) &&
4082 (phba->fc_topology != LPFC_TOPOLOGY_LOOP) &&
4083 !lpfc_error_lost_link(irsp)) {
4084 /* FLOGI retry policy */
4086 /* retry FLOGI forever */
4087 if (phba->link_flag != LS_LOOPBACK_MODE)
4092 if (cmdiocb->retry >= 100)
4094 else if (cmdiocb->retry >= 32)
4096 } else if ((cmd == ELS_CMD_FDISC) && !lpfc_error_lost_link(irsp)) {
4097 /* retry FDISCs every second up to devloss */
4099 maxretry = vport->cfg_devloss_tmo;
4104 if (maxretry && (cmdiocb->retry >= maxretry)) {
4105 phba->fc_stat.elsRetryExceeded++;
4109 if ((vport->load_flag & FC_UNLOADING) != 0)
4114 if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) {
4115 /* Stop retrying PLOGI and FDISC if in FCF discovery */
4116 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
4117 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4118 "2849 Stop retry ELS command "
4119 "x%x to remote NPORT x%x, "
4120 "Data: x%x x%x\n", cmd, did,
4121 cmdiocb->retry, delay);
4126 /* Retry ELS command <elsCmd> to remote NPORT <did> */
4127 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4128 "0107 Retry ELS command x%x to remote "
4129 "NPORT x%x Data: x%x x%x\n",
4130 cmd, did, cmdiocb->retry, delay);
4132 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
4133 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
4134 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
4135 IOERR_NO_RESOURCES))) {
4136 /* Don't reset timer for no resources */
4138 /* If discovery / RSCN timer is running, reset it */
4139 if (timer_pending(&vport->fc_disctmo) ||
4140 (vport->fc_flag & FC_RSCN_MODE))
4141 lpfc_set_disctmo(vport);
4144 phba->fc_stat.elsXmitRetry++;
4145 if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) {
4146 phba->fc_stat.elsDelayRetry++;
4147 ndlp->nlp_retry = cmdiocb->retry;
4149 /* delay is specified in milliseconds */
4150 mod_timer(&ndlp->nlp_delayfunc,
4151 jiffies + msecs_to_jiffies(delay));
4152 spin_lock_irq(shost->host_lock);
4153 ndlp->nlp_flag |= NLP_DELAY_TMO;
4154 spin_unlock_irq(shost->host_lock);
4156 ndlp->nlp_prev_state = ndlp->nlp_state;
4157 if ((cmd == ELS_CMD_PRLI) ||
4158 (cmd == ELS_CMD_NVMEPRLI))
4159 lpfc_nlp_set_state(vport, ndlp,
4160 NLP_STE_PRLI_ISSUE);
4162 lpfc_nlp_set_state(vport, ndlp,
4164 ndlp->nlp_last_elscmd = cmd;
4170 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
4173 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
4176 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
4177 ndlp->nlp_prev_state = ndlp->nlp_state;
4178 lpfc_nlp_set_state(vport, ndlp,
4179 NLP_STE_PLOGI_ISSUE);
4181 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
4184 ndlp->nlp_prev_state = ndlp->nlp_state;
4185 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
4186 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
4189 case ELS_CMD_NVMEPRLI:
4190 ndlp->nlp_prev_state = ndlp->nlp_state;
4191 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
4192 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
4195 ndlp->nlp_prev_state = ndlp->nlp_state;
4196 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
4197 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
4201 /* No retry ELS command <elsCmd> to remote NPORT <did> */
4203 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4204 "0137 No retry ELS command x%x to remote "
4205 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
4206 cmd, did, irsp->ulpStatus,
4207 irsp->un.ulpWord[4]);
4210 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4211 "0108 No retry ELS command x%x to remote "
4212 "NPORT x%x Retried:%d Error:x%x/%x\n",
4213 cmd, did, cmdiocb->retry, irsp->ulpStatus,
4214 irsp->un.ulpWord[4]);
4220 * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
4221 * @phba: pointer to lpfc hba data structure.
4222 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
4224 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
4225 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
4226 * checks to see whether there is a lpfc DMA buffer associated with the
4227 * response of the command IOCB. If so, it will be released before releasing
4228 * the lpfc DMA buffer associated with the IOCB itself.
4231 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
4234 lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
4236 struct lpfc_dmabuf *buf_ptr;
4238 /* Free the response before processing the command. */
4239 if (!list_empty(&buf_ptr1->list)) {
4240 list_remove_head(&buf_ptr1->list, buf_ptr,
4243 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
4246 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
4252 * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
4253 * @phba: pointer to lpfc hba data structure.
4254 * @buf_ptr: pointer to the lpfc dma buffer data structure.
4256 * This routine releases the lpfc Direct Memory Access (DMA) buffer
4257 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
4261 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
4264 lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
4266 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
4272 * lpfc_els_free_iocb - Free a command iocb and its associated resources
4273 * @phba: pointer to lpfc hba data structure.
4274 * @elsiocb: pointer to lpfc els command iocb data structure.
4276 * This routine frees a command IOCB and its associated resources. The
4277 * command IOCB data structure contains the reference to various associated
4278 * resources, these fields must be set to NULL if the associated reference
4280 * context1 - reference to ndlp
4281 * context2 - reference to cmd
4282 * context2->next - reference to rsp
4283 * context3 - reference to bpl
4285 * It first properly decrements the reference count held on ndlp for the
4286 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
4287 * set, it invokes the lpfc_els_free_data() routine to release the Direct
4288 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
4289 * adds the DMA buffer the @phba data structure for the delayed release.
4290 * If reference to the Buffer Pointer List (BPL) is present, the
4291 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
4292 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
4293 * invoked to release the IOCB data structure back to @phba IOCBQ list.
4296 * 0 - Success (currently, always return 0)
4299 lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
4301 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
4302 struct lpfc_nodelist *ndlp;
4304 ndlp = (struct lpfc_nodelist *)elsiocb->context1;
4306 if (ndlp->nlp_flag & NLP_DEFER_RM) {
4309 /* If the ndlp is not being used by another discovery
4312 if (!lpfc_nlp_not_used(ndlp)) {
4313 /* If ndlp is being used by another discovery
4314 * thread, just clear NLP_DEFER_RM
4316 ndlp->nlp_flag &= ~NLP_DEFER_RM;
4321 elsiocb->context1 = NULL;
4323 /* context2 = cmd, context2->next = rsp, context3 = bpl */
4324 if (elsiocb->context2) {
4325 if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
4326 /* Firmware could still be in progress of DMAing
4327 * payload, so don't free data buffer till after
4330 elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
4331 buf_ptr = elsiocb->context2;
4332 elsiocb->context2 = NULL;
4335 spin_lock_irq(&phba->hbalock);
4336 if (!list_empty(&buf_ptr->list)) {
4337 list_remove_head(&buf_ptr->list,
4338 buf_ptr1, struct lpfc_dmabuf,
4340 INIT_LIST_HEAD(&buf_ptr1->list);
4341 list_add_tail(&buf_ptr1->list,
4345 INIT_LIST_HEAD(&buf_ptr->list);
4346 list_add_tail(&buf_ptr->list, &phba->elsbuf);
4348 spin_unlock_irq(&phba->hbalock);
4351 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
4352 lpfc_els_free_data(phba, buf_ptr1);
4353 elsiocb->context2 = NULL;
4357 if (elsiocb->context3) {
4358 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
4359 lpfc_els_free_bpl(phba, buf_ptr);
4360 elsiocb->context3 = NULL;
4362 lpfc_sli_release_iocbq(phba, elsiocb);
4367 * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
4368 * @phba: pointer to lpfc hba data structure.
4369 * @cmdiocb: pointer to lpfc command iocb data structure.
4370 * @rspiocb: pointer to lpfc response iocb data structure.
4372 * This routine is the completion callback function to the Logout (LOGO)
4373 * Accept (ACC) Response ELS command. This routine is invoked to indicate
4374 * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
4375 * release the ndlp if it has the last reference remaining (reference count
4376 * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
4377 * field to NULL to inform the following lpfc_els_free_iocb() routine no
4378 * ndlp reference count needs to be decremented. Otherwise, the ndlp
4379 * reference use-count shall be decremented by the lpfc_els_free_iocb()
4380 * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
4381 * IOCB data structure.
4384 lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
4385 struct lpfc_iocbq *rspiocb)
4387 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
4388 struct lpfc_vport *vport = cmdiocb->vport;
4391 irsp = &rspiocb->iocb;
4392 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4393 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
4394 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
4395 /* ACC to LOGO completes to NPort <nlp_DID> */
4396 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4397 "0109 ACC to LOGO completes to NPort x%x "
4398 "Data: x%x x%x x%x\n",
4399 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4402 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
4403 /* NPort Recovery mode or node is just allocated */
4404 if (!lpfc_nlp_not_used(ndlp)) {
4405 /* If the ndlp is being used by another discovery
4406 * thread, just unregister the RPI.
4408 lpfc_unreg_rpi(vport, ndlp);
4410 /* Indicate the node has already released, should
4411 * not reference to it from within lpfc_els_free_iocb.
4413 cmdiocb->context1 = NULL;
4418 * The driver received a LOGO from the rport and has ACK'd it.
4419 * At this point, the driver is done so release the IOCB
4421 lpfc_els_free_iocb(phba, cmdiocb);
4425 * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
4426 * @phba: pointer to lpfc hba data structure.
4427 * @pmb: pointer to the driver internal queue element for mailbox command.
4429 * This routine is the completion callback function for unregister default
4430 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
4431 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
4432 * decrements the ndlp reference count held for this completion callback
4433 * function. After that, it invokes the lpfc_nlp_not_used() to check
4434 * whether there is only one reference left on the ndlp. If so, it will
4435 * perform one more decrement and trigger the release of the ndlp.
4438 lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4440 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
4441 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
4443 pmb->ctx_buf = NULL;
4444 pmb->ctx_ndlp = NULL;
4446 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4448 mempool_free(pmb, phba->mbox_mem_pool);
4450 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
4451 "0006 rpi%x DID:%x flg:%x %d map:%x x%px\n",
4452 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
4453 kref_read(&ndlp->kref),
4454 ndlp->nlp_usg_map, ndlp);
4455 if (NLP_CHK_NODE_ACT(ndlp)) {
4457 /* This is the end of the default RPI cleanup logic for
4458 * this ndlp. If no other discovery threads are using
4459 * this ndlp, free all resources associated with it.
4461 lpfc_nlp_not_used(ndlp);
4463 lpfc_drop_node(ndlp->vport, ndlp);
4471 * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
4472 * @phba: pointer to lpfc hba data structure.
4473 * @cmdiocb: pointer to lpfc command iocb data structure.
4474 * @rspiocb: pointer to lpfc response iocb data structure.
4476 * This routine is the completion callback function for ELS Response IOCB
4477 * command. In normal case, this callback function just properly sets the
4478 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
4479 * field in the command IOCB is not NULL, the referred mailbox command will
4480 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
4481 * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
4482 * link down event occurred during the discovery, the lpfc_nlp_not_used()
4483 * routine shall be invoked trying to release the ndlp if no other threads
4484 * are currently referring it.
4487 lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
4488 struct lpfc_iocbq *rspiocb)
4490 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
4491 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
4492 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
4495 LPFC_MBOXQ_t *mbox = NULL;
4496 struct lpfc_dmabuf *mp = NULL;
4497 uint32_t ls_rjt = 0;
4499 irsp = &rspiocb->iocb;
4502 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
4503 "3177 ELS response failed\n");
4506 if (cmdiocb->context_un.mbox)
4507 mbox = cmdiocb->context_un.mbox;
4509 /* First determine if this is a LS_RJT cmpl. Note, this callback
4510 * function can have cmdiocb->contest1 (ndlp) field set to NULL.
4512 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
4513 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
4514 (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) {
4515 /* A LS_RJT associated with Default RPI cleanup has its own
4516 * separate code path.
4518 if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
4522 /* Check to see if link went down during discovery */
4523 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) {
4525 mp = (struct lpfc_dmabuf *)mbox->ctx_buf;
4527 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4530 mempool_free(mbox, phba->mbox_mem_pool);
4532 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
4533 (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
4534 if (lpfc_nlp_not_used(ndlp)) {
4536 /* Indicate the node has already released,
4537 * should not reference to it from within
4538 * the routine lpfc_els_free_iocb.
4540 cmdiocb->context1 = NULL;
4545 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4546 "ELS rsp cmpl: status:x%x/x%x did:x%x",
4547 irsp->ulpStatus, irsp->un.ulpWord[4],
4548 cmdiocb->iocb.un.elsreq64.remoteID);
4549 /* ELS response tag <ulpIoTag> completes */
4550 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4551 "0110 ELS response tag x%x completes "
4552 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
4553 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
4554 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
4555 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4558 if ((rspiocb->iocb.ulpStatus == 0)
4559 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
4560 if (!lpfc_unreg_rpi(vport, ndlp) &&
4561 (!(vport->fc_flag & FC_PT2PT)) &&
4562 (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
4563 ndlp->nlp_state == NLP_STE_REG_LOGIN_ISSUE)) {
4564 lpfc_printf_vlog(vport, KERN_INFO,
4566 "0314 PLOGI recov DID x%x "
4567 "Data: x%x x%x x%x\n",
4568 ndlp->nlp_DID, ndlp->nlp_state,
4569 ndlp->nlp_rpi, ndlp->nlp_flag);
4572 lpfc_mbuf_free(phba, mp->virt,
4576 mempool_free(mbox, phba->mbox_mem_pool);
4580 /* Increment reference count to ndlp to hold the
4581 * reference to ndlp for the callback function.
4583 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
4584 mbox->vport = vport;
4585 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
4586 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
4587 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
4590 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
4591 ndlp->nlp_prev_state = ndlp->nlp_state;
4592 lpfc_nlp_set_state(vport, ndlp,
4593 NLP_STE_REG_LOGIN_ISSUE);
4596 ndlp->nlp_flag |= NLP_REG_LOGIN_SEND;
4597 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
4598 != MBX_NOT_FINISHED)
4601 /* Decrement the ndlp reference count we
4602 * set for this failed mailbox command.
4605 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
4607 /* ELS rsp: Cannot issue reg_login for <NPortid> */
4608 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4609 "0138 ELS rsp: Cannot issue reg_login for x%x "
4610 "Data: x%x x%x x%x\n",
4611 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4614 if (lpfc_nlp_not_used(ndlp)) {
4616 /* Indicate node has already been released,
4617 * should not reference to it from within
4618 * the routine lpfc_els_free_iocb.
4620 cmdiocb->context1 = NULL;
4623 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
4624 if (!lpfc_error_lost_link(irsp) &&
4625 ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
4626 if (lpfc_nlp_not_used(ndlp)) {
4628 /* Indicate node has already been
4629 * released, should not reference
4630 * to it from within the routine
4631 * lpfc_els_free_iocb.
4633 cmdiocb->context1 = NULL;
4637 mp = (struct lpfc_dmabuf *)mbox->ctx_buf;
4639 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4642 mempool_free(mbox, phba->mbox_mem_pool);
4645 if (ndlp && NLP_CHK_NODE_ACT(ndlp) && shost) {
4646 spin_lock_irq(shost->host_lock);
4647 ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI);
4648 spin_unlock_irq(shost->host_lock);
4650 /* If the node is not being used by another discovery thread,
4651 * and we are sending a reject, we are done with it.
4652 * Release driver reference count here and free associated
4656 if (lpfc_nlp_not_used(ndlp))
4657 /* Indicate node has already been released,
4658 * should not reference to it from within
4659 * the routine lpfc_els_free_iocb.
4661 cmdiocb->context1 = NULL;
4665 lpfc_els_free_iocb(phba, cmdiocb);
4670 * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
4671 * @vport: pointer to a host virtual N_Port data structure.
4672 * @flag: the els command code to be accepted.
4673 * @oldiocb: pointer to the original lpfc command iocb data structure.
4674 * @ndlp: pointer to a node-list data structure.
4675 * @mbox: pointer to the driver internal queue element for mailbox command.
4677 * This routine prepares and issues an Accept (ACC) response IOCB
4678 * command. It uses the @flag to properly set up the IOCB field for the
4679 * specific ACC response command to be issued and invokes the
4680 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
4681 * @mbox pointer is passed in, it will be put into the context_un.mbox
4682 * field of the IOCB for the completion callback function to issue the
4683 * mailbox command to the HBA later when callback is invoked.
4685 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4686 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4687 * will be stored into the context1 field of the IOCB for the completion
4688 * callback function to the corresponding response ELS IOCB command.
4691 * 0 - Successfully issued acc response
4692 * 1 - Failed to issue acc response
4695 lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
4696 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
4699 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4700 struct lpfc_hba *phba = vport->phba;
4703 struct lpfc_iocbq *elsiocb;
4705 struct serv_parm *sp;
4708 ELS_PKT *els_pkt_ptr;
4710 oldcmd = &oldiocb->iocb;
4714 cmdsize = sizeof(uint32_t);
4715 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
4716 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
4718 spin_lock_irq(shost->host_lock);
4719 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
4720 spin_unlock_irq(shost->host_lock);
4724 icmd = &elsiocb->iocb;
4725 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4726 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4727 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4728 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4729 pcmd += sizeof(uint32_t);
4731 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4732 "Issue ACC: did:x%x flg:x%x",
4733 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4737 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
4738 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
4739 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
4743 icmd = &elsiocb->iocb;
4744 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4745 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4746 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4749 elsiocb->context_un.mbox = mbox;
4751 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4752 pcmd += sizeof(uint32_t);
4753 sp = (struct serv_parm *)pcmd;
4755 if (flag == ELS_CMD_FLOGI) {
4756 /* Copy the received service parameters back */
4757 memcpy(sp, &phba->fc_fabparam,
4758 sizeof(struct serv_parm));
4760 /* Clear the F_Port bit */
4763 /* Mark all class service parameters as invalid */
4764 sp->cls1.classValid = 0;
4765 sp->cls2.classValid = 0;
4766 sp->cls3.classValid = 0;
4767 sp->cls4.classValid = 0;
4769 /* Copy our worldwide names */
4770 memcpy(&sp->portName, &vport->fc_sparam.portName,
4771 sizeof(struct lpfc_name));
4772 memcpy(&sp->nodeName, &vport->fc_sparam.nodeName,
4773 sizeof(struct lpfc_name));
4775 memcpy(pcmd, &vport->fc_sparam,
4776 sizeof(struct serv_parm));
4778 sp->cmn.valid_vendor_ver_level = 0;
4779 memset(sp->un.vendorVersion, 0,
4780 sizeof(sp->un.vendorVersion));
4781 sp->cmn.bbRcvSizeMsb &= 0xF;
4783 /* If our firmware supports this feature, convey that
4784 * info to the target using the vendor specific field.
4786 if (phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) {
4787 sp->cmn.valid_vendor_ver_level = 1;
4788 sp->un.vv.vid = cpu_to_be32(LPFC_VV_EMLX_ID);
4790 cpu_to_be32(LPFC_VV_SUPPRESS_RSP);
4794 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4795 "Issue ACC FLOGI/PLOGI: did:x%x flg:x%x",
4796 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4799 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
4800 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
4801 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
4805 icmd = &elsiocb->iocb;
4806 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4807 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4808 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4810 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
4811 sizeof(uint32_t) + sizeof(PRLO));
4812 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
4813 els_pkt_ptr = (ELS_PKT *) pcmd;
4814 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
4816 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4817 "Issue ACC PRLO: did:x%x flg:x%x",
4818 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4823 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
4824 spin_lock_irq(shost->host_lock);
4825 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED ||
4826 ndlp->nlp_flag & NLP_REG_LOGIN_SEND))
4827 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
4828 spin_unlock_irq(shost->host_lock);
4829 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
4831 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4834 phba->fc_stat.elsXmitACC++;
4835 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4836 if (rc == IOCB_ERROR) {
4837 lpfc_els_free_iocb(phba, elsiocb);
4844 * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command
4845 * @vport: pointer to a virtual N_Port data structure.
4847 * @oldiocb: pointer to the original lpfc command iocb data structure.
4848 * @ndlp: pointer to a node-list data structure.
4849 * @mbox: pointer to the driver internal queue element for mailbox command.
4851 * This routine prepares and issue an Reject (RJT) response IOCB
4852 * command. If a @mbox pointer is passed in, it will be put into the
4853 * context_un.mbox field of the IOCB for the completion callback function
4854 * to issue to the HBA later.
4856 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4857 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4858 * will be stored into the context1 field of the IOCB for the completion
4859 * callback function to the reject response ELS IOCB command.
4862 * 0 - Successfully issued reject response
4863 * 1 - Failed to issue reject response
4866 lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
4867 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
4870 struct lpfc_hba *phba = vport->phba;
4873 struct lpfc_iocbq *elsiocb;
4878 cmdsize = 2 * sizeof(uint32_t);
4879 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4880 ndlp->nlp_DID, ELS_CMD_LS_RJT);
4884 icmd = &elsiocb->iocb;
4885 oldcmd = &oldiocb->iocb;
4886 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4887 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4888 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4890 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
4891 pcmd += sizeof(uint32_t);
4892 *((uint32_t *) (pcmd)) = rejectError;
4895 elsiocb->context_un.mbox = mbox;
4897 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
4898 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4899 "0129 Xmit ELS RJT x%x response tag x%x "
4900 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
4902 rejectError, elsiocb->iotag,
4903 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
4904 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
4905 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4906 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
4907 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
4909 phba->fc_stat.elsXmitLSRJT++;
4910 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4911 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4913 if (rc == IOCB_ERROR) {
4914 lpfc_els_free_iocb(phba, elsiocb);
4921 * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
4922 * @vport: pointer to a virtual N_Port data structure.
4923 * @oldiocb: pointer to the original lpfc command iocb data structure.
4924 * @ndlp: pointer to a node-list data structure.
4926 * This routine prepares and issues an Accept (ACC) response to Address
4927 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
4928 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
4930 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4931 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4932 * will be stored into the context1 field of the IOCB for the completion
4933 * callback function to the ADISC Accept response ELS IOCB command.
4936 * 0 - Successfully issued acc adisc response
4937 * 1 - Failed to issue adisc acc response
4940 lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
4941 struct lpfc_nodelist *ndlp)
4943 struct lpfc_hba *phba = vport->phba;
4945 IOCB_t *icmd, *oldcmd;
4946 struct lpfc_iocbq *elsiocb;
4951 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
4952 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4953 ndlp->nlp_DID, ELS_CMD_ACC);
4957 icmd = &elsiocb->iocb;
4958 oldcmd = &oldiocb->iocb;
4959 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4960 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4962 /* Xmit ADISC ACC response tag <ulpIoTag> */
4963 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4964 "0130 Xmit ADISC ACC response iotag x%x xri: "
4965 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
4966 elsiocb->iotag, elsiocb->iocb.ulpContext,
4967 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4969 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4971 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4972 pcmd += sizeof(uint32_t);
4974 ap = (ADISC *) (pcmd);
4975 ap->hardAL_PA = phba->fc_pref_ALPA;
4976 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
4977 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
4978 ap->DID = be32_to_cpu(vport->fc_myDID);
4980 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4981 "Issue ACC ADISC: did:x%x flg:x%x",
4982 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4984 phba->fc_stat.elsXmitACC++;
4985 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4986 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4987 if (rc == IOCB_ERROR) {
4988 lpfc_els_free_iocb(phba, elsiocb);
4992 /* Xmit ELS ACC response tag <ulpIoTag> */
4993 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4994 "0128 Xmit ELS ACC response Status: x%x, IoTag: x%x, "
4995 "XRI: x%x, DID: x%x, nlp_flag: x%x nlp_state: x%x "
4996 "RPI: x%x, fc_flag x%x\n",
4997 rc, elsiocb->iotag, elsiocb->sli4_xritag,
4998 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4999 ndlp->nlp_rpi, vport->fc_flag);
5004 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
5005 * @vport: pointer to a virtual N_Port data structure.
5006 * @oldiocb: pointer to the original lpfc command iocb data structure.
5007 * @ndlp: pointer to a node-list data structure.
5009 * This routine prepares and issues an Accept (ACC) response to Process
5010 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
5011 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
5013 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5014 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5015 * will be stored into the context1 field of the IOCB for the completion
5016 * callback function to the PRLI Accept response ELS IOCB command.
5019 * 0 - Successfully issued acc prli response
5020 * 1 - Failed to issue acc prli response
5023 lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
5024 struct lpfc_nodelist *ndlp)
5026 struct lpfc_hba *phba = vport->phba;
5028 struct lpfc_nvme_prli *npr_nvme;
5032 struct lpfc_iocbq *elsiocb;
5035 uint32_t prli_fc4_req, *req_payload;
5036 struct lpfc_dmabuf *req_buf;
5040 /* Need the incoming PRLI payload to determine if the ACC is for an
5041 * FC4 or NVME PRLI type. The PRLI type is at word 1.
5043 req_buf = (struct lpfc_dmabuf *)oldiocb->context2;
5044 req_payload = (((uint32_t *)req_buf->virt) + 1);
5046 /* PRLI type payload is at byte 3 for FCP or NVME. */
5047 prli_fc4_req = be32_to_cpu(*req_payload);
5048 prli_fc4_req = (prli_fc4_req >> 24) & 0xff;
5049 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5050 "6127 PRLI_ACC: Req Type x%x, Word1 x%08x\n",
5051 prli_fc4_req, *((uint32_t *)req_payload));
5053 if (prli_fc4_req == PRLI_FCP_TYPE) {
5054 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
5055 elsrspcmd = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
5056 } else if (prli_fc4_req & PRLI_NVME_TYPE) {
5057 cmdsize = sizeof(uint32_t) + sizeof(struct lpfc_nvme_prli);
5058 elsrspcmd = (ELS_CMD_ACC | (ELS_CMD_NVMEPRLI & ~ELS_RSP_MASK));
5063 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
5064 ndlp->nlp_DID, elsrspcmd);
5068 icmd = &elsiocb->iocb;
5069 oldcmd = &oldiocb->iocb;
5070 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
5071 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
5073 /* Xmit PRLI ACC response tag <ulpIoTag> */
5074 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5075 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
5076 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
5077 elsiocb->iotag, elsiocb->iocb.ulpContext,
5078 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5080 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5081 memset(pcmd, 0, cmdsize);
5083 *((uint32_t *)(pcmd)) = elsrspcmd;
5084 pcmd += sizeof(uint32_t);
5086 /* For PRLI, remainder of payload is PRLI parameter page */
5089 if (prli_fc4_req == PRLI_FCP_TYPE) {
5091 * If the remote port is a target and our firmware version
5092 * is 3.20 or later, set the following bits for FC-TAPE
5095 npr = (PRLI *) pcmd;
5096 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
5097 (vpd->rev.feaLevelHigh >= 0x02)) {
5098 npr->ConfmComplAllowed = 1;
5100 npr->TaskRetryIdReq = 1;
5102 npr->acceptRspCode = PRLI_REQ_EXECUTED;
5103 npr->estabImagePair = 1;
5104 npr->readXferRdyDis = 1;
5105 npr->ConfmComplAllowed = 1;
5106 npr->prliType = PRLI_FCP_TYPE;
5107 npr->initiatorFunc = 1;
5108 } else if (prli_fc4_req & PRLI_NVME_TYPE) {
5109 /* Respond with an NVME PRLI Type */
5110 npr_nvme = (struct lpfc_nvme_prli *) pcmd;
5111 bf_set(prli_type_code, npr_nvme, PRLI_NVME_TYPE);
5112 bf_set(prli_estabImagePair, npr_nvme, 0); /* Should be 0 */
5113 bf_set(prli_acc_rsp_code, npr_nvme, PRLI_REQ_EXECUTED);
5114 if (phba->nvmet_support) {
5115 bf_set(prli_tgt, npr_nvme, 1);
5116 bf_set(prli_disc, npr_nvme, 1);
5117 if (phba->cfg_nvme_enable_fb) {
5118 bf_set(prli_fba, npr_nvme, 1);
5120 /* TBD. Target mode needs to post buffers
5121 * that support the configured first burst
5124 bf_set(prli_fb_sz, npr_nvme,
5125 phba->cfg_nvmet_fb_size);
5128 bf_set(prli_init, npr_nvme, 1);
5131 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
5132 "6015 NVME issue PRLI ACC word1 x%08x "
5133 "word4 x%08x word5 x%08x flag x%x, "
5134 "fcp_info x%x nlp_type x%x\n",
5135 npr_nvme->word1, npr_nvme->word4,
5136 npr_nvme->word5, ndlp->nlp_flag,
5137 ndlp->nlp_fcp_info, ndlp->nlp_type);
5138 npr_nvme->word1 = cpu_to_be32(npr_nvme->word1);
5139 npr_nvme->word4 = cpu_to_be32(npr_nvme->word4);
5140 npr_nvme->word5 = cpu_to_be32(npr_nvme->word5);
5142 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5143 "6128 Unknown FC_TYPE x%x x%x ndlp x%06x\n",
5144 prli_fc4_req, ndlp->nlp_fc4_type,
5147 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
5148 "Issue ACC PRLI: did:x%x flg:x%x",
5149 ndlp->nlp_DID, ndlp->nlp_flag, 0);
5151 phba->fc_stat.elsXmitACC++;
5152 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5154 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5155 if (rc == IOCB_ERROR) {
5156 lpfc_els_free_iocb(phba, elsiocb);
5163 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
5164 * @vport: pointer to a virtual N_Port data structure.
5165 * @format: rnid command format.
5166 * @oldiocb: pointer to the original lpfc command iocb data structure.
5167 * @ndlp: pointer to a node-list data structure.
5169 * This routine issues a Request Node Identification Data (RNID) Accept
5170 * (ACC) response. It constructs the RNID ACC response command according to
5171 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
5172 * issue the response. Note that this command does not need to hold the ndlp
5173 * reference count for the callback. So, the ndlp reference count taken by
5174 * the lpfc_prep_els_iocb() routine is put back and the context1 field of
5175 * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
5176 * there is no ndlp reference available.
5178 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5179 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5180 * will be stored into the context1 field of the IOCB for the completion
5181 * callback function. However, for the RNID Accept Response ELS command,
5182 * this is undone later by this routine after the IOCB is allocated.
5185 * 0 - Successfully issued acc rnid response
5186 * 1 - Failed to issue acc rnid response
5189 lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
5190 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
5192 struct lpfc_hba *phba = vport->phba;
5194 IOCB_t *icmd, *oldcmd;
5195 struct lpfc_iocbq *elsiocb;
5200 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
5201 + (2 * sizeof(struct lpfc_name));
5203 cmdsize += sizeof(RNID_TOP_DISC);
5205 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
5206 ndlp->nlp_DID, ELS_CMD_ACC);
5210 icmd = &elsiocb->iocb;
5211 oldcmd = &oldiocb->iocb;
5212 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
5213 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
5215 /* Xmit RNID ACC response tag <ulpIoTag> */
5216 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5217 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
5218 elsiocb->iotag, elsiocb->iocb.ulpContext);
5219 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5220 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5221 pcmd += sizeof(uint32_t);
5223 memset(pcmd, 0, sizeof(RNID));
5224 rn = (RNID *) (pcmd);
5225 rn->Format = format;
5226 rn->CommonLen = (2 * sizeof(struct lpfc_name));
5227 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
5228 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
5231 rn->SpecificLen = 0;
5233 case RNID_TOPOLOGY_DISC:
5234 rn->SpecificLen = sizeof(RNID_TOP_DISC);
5235 memcpy(&rn->un.topologyDisc.portName,
5236 &vport->fc_portname, sizeof(struct lpfc_name));
5237 rn->un.topologyDisc.unitType = RNID_HBA;
5238 rn->un.topologyDisc.physPort = 0;
5239 rn->un.topologyDisc.attachedNodes = 0;
5243 rn->SpecificLen = 0;
5247 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
5248 "Issue ACC RNID: did:x%x flg:x%x",
5249 ndlp->nlp_DID, ndlp->nlp_flag, 0);
5251 phba->fc_stat.elsXmitACC++;
5252 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5254 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5255 if (rc == IOCB_ERROR) {
5256 lpfc_els_free_iocb(phba, elsiocb);
5263 * lpfc_els_clear_rrq - Clear the rq that this rrq describes.
5264 * @vport: pointer to a virtual N_Port data structure.
5265 * @iocb: pointer to the lpfc command iocb data structure.
5266 * @ndlp: pointer to a node-list data structure.
5271 lpfc_els_clear_rrq(struct lpfc_vport *vport,
5272 struct lpfc_iocbq *iocb, struct lpfc_nodelist *ndlp)
5274 struct lpfc_hba *phba = vport->phba;
5279 struct lpfc_node_rrq *prrq;
5282 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) iocb->context2)->virt);
5283 pcmd += sizeof(uint32_t);
5284 rrq = (struct RRQ *)pcmd;
5285 rrq->rrq_exchg = be32_to_cpu(rrq->rrq_exchg);
5286 rxid = bf_get(rrq_rxid, rrq);
5288 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5289 "2883 Clear RRQ for SID:x%x OXID:x%x RXID:x%x"
5291 be32_to_cpu(bf_get(rrq_did, rrq)),
5292 bf_get(rrq_oxid, rrq),
5294 iocb->iotag, iocb->iocb.ulpContext);
5296 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
5297 "Clear RRQ: did:x%x flg:x%x exchg:x%.08x",
5298 ndlp->nlp_DID, ndlp->nlp_flag, rrq->rrq_exchg);
5299 if (vport->fc_myDID == be32_to_cpu(bf_get(rrq_did, rrq)))
5300 xri = bf_get(rrq_oxid, rrq);
5303 prrq = lpfc_get_active_rrq(vport, xri, ndlp->nlp_DID);
5305 lpfc_clr_rrq_active(phba, xri, prrq);
5310 * lpfc_els_rsp_echo_acc - Issue echo acc response
5311 * @vport: pointer to a virtual N_Port data structure.
5312 * @data: pointer to echo data to return in the accept.
5313 * @oldiocb: pointer to the original lpfc command iocb data structure.
5314 * @ndlp: pointer to a node-list data structure.
5317 * 0 - Successfully issued acc echo response
5318 * 1 - Failed to issue acc echo response
5321 lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data,
5322 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
5324 struct lpfc_hba *phba = vport->phba;
5325 struct lpfc_iocbq *elsiocb;
5330 cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len;
5332 /* The accumulated length can exceed the BPL_SIZE. For
5333 * now, use this as the limit
5335 if (cmdsize > LPFC_BPL_SIZE)
5336 cmdsize = LPFC_BPL_SIZE;
5337 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
5338 ndlp->nlp_DID, ELS_CMD_ACC);
5342 elsiocb->iocb.ulpContext = oldiocb->iocb.ulpContext; /* Xri / rx_id */
5343 elsiocb->iocb.unsli3.rcvsli3.ox_id = oldiocb->iocb.unsli3.rcvsli3.ox_id;
5345 /* Xmit ECHO ACC response tag <ulpIoTag> */
5346 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5347 "2876 Xmit ECHO ACC response tag x%x xri x%x\n",
5348 elsiocb->iotag, elsiocb->iocb.ulpContext);
5349 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5350 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5351 pcmd += sizeof(uint32_t);
5352 memcpy(pcmd, data, cmdsize - sizeof(uint32_t));
5354 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
5355 "Issue ACC ECHO: did:x%x flg:x%x",
5356 ndlp->nlp_DID, ndlp->nlp_flag, 0);
5358 phba->fc_stat.elsXmitACC++;
5359 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5361 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5362 if (rc == IOCB_ERROR) {
5363 lpfc_els_free_iocb(phba, elsiocb);
5370 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
5371 * @vport: pointer to a host virtual N_Port data structure.
5373 * This routine issues Address Discover (ADISC) ELS commands to those
5374 * N_Ports which are in node port recovery state and ADISC has not been issued
5375 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
5376 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
5377 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
5378 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
5379 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
5380 * IOCBs quit for later pick up. On the other hand, after walking through
5381 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
5382 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
5383 * no more ADISC need to be sent.
5386 * The number of N_Ports with adisc issued.
5389 lpfc_els_disc_adisc(struct lpfc_vport *vport)
5391 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5392 struct lpfc_nodelist *ndlp, *next_ndlp;
5395 /* go thru NPR nodes and issue any remaining ELS ADISCs */
5396 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
5397 if (!NLP_CHK_NODE_ACT(ndlp))
5399 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
5400 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
5401 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
5402 spin_lock_irq(shost->host_lock);
5403 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
5404 spin_unlock_irq(shost->host_lock);
5405 ndlp->nlp_prev_state = ndlp->nlp_state;
5406 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
5407 lpfc_issue_els_adisc(vport, ndlp, 0);
5409 vport->num_disc_nodes++;
5410 if (vport->num_disc_nodes >=
5411 vport->cfg_discovery_threads) {
5412 spin_lock_irq(shost->host_lock);
5413 vport->fc_flag |= FC_NLP_MORE;
5414 spin_unlock_irq(shost->host_lock);
5419 if (sentadisc == 0) {
5420 spin_lock_irq(shost->host_lock);
5421 vport->fc_flag &= ~FC_NLP_MORE;
5422 spin_unlock_irq(shost->host_lock);
5428 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
5429 * @vport: pointer to a host virtual N_Port data structure.
5431 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
5432 * which are in node port recovery state, with a @vport. Each time an ELS
5433 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
5434 * the per @vport number of discover count (num_disc_nodes) shall be
5435 * incremented. If the num_disc_nodes reaches a pre-configured threshold
5436 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
5437 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
5438 * later pick up. On the other hand, after walking through all the ndlps with
5439 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
5440 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
5441 * PLOGI need to be sent.
5444 * The number of N_Ports with plogi issued.
5447 lpfc_els_disc_plogi(struct lpfc_vport *vport)
5449 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5450 struct lpfc_nodelist *ndlp, *next_ndlp;
5453 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
5454 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
5455 if (!NLP_CHK_NODE_ACT(ndlp))
5457 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
5458 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
5459 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
5460 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
5461 ndlp->nlp_prev_state = ndlp->nlp_state;
5462 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
5463 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
5465 vport->num_disc_nodes++;
5466 if (vport->num_disc_nodes >=
5467 vport->cfg_discovery_threads) {
5468 spin_lock_irq(shost->host_lock);
5469 vport->fc_flag |= FC_NLP_MORE;
5470 spin_unlock_irq(shost->host_lock);
5476 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5477 "6452 Discover PLOGI %d flag x%x\n",
5478 sentplogi, vport->fc_flag);
5481 lpfc_set_disctmo(vport);
5484 spin_lock_irq(shost->host_lock);
5485 vport->fc_flag &= ~FC_NLP_MORE;
5486 spin_unlock_irq(shost->host_lock);
5492 lpfc_rdp_res_link_service(struct fc_rdp_link_service_desc *desc,
5496 desc->tag = cpu_to_be32(RDP_LINK_SERVICE_DESC_TAG);
5497 desc->payload.els_req = word0;
5498 desc->length = cpu_to_be32(sizeof(desc->payload));
5500 return sizeof(struct fc_rdp_link_service_desc);
5504 lpfc_rdp_res_sfp_desc(struct fc_rdp_sfp_desc *desc,
5505 uint8_t *page_a0, uint8_t *page_a2)
5507 uint16_t wavelength;
5508 uint16_t temperature;
5514 struct sff_trasnceiver_codes_byte4 *trasn_code_byte4;
5515 struct sff_trasnceiver_codes_byte5 *trasn_code_byte5;
5517 desc->tag = cpu_to_be32(RDP_SFP_DESC_TAG);
5519 trasn_code_byte4 = (struct sff_trasnceiver_codes_byte4 *)
5520 &page_a0[SSF_TRANSCEIVER_CODE_B4];
5521 trasn_code_byte5 = (struct sff_trasnceiver_codes_byte5 *)
5522 &page_a0[SSF_TRANSCEIVER_CODE_B5];
5524 if ((trasn_code_byte4->fc_sw_laser) ||
5525 (trasn_code_byte5->fc_sw_laser_sl) ||
5526 (trasn_code_byte5->fc_sw_laser_sn)) { /* check if its short WL */
5527 flag |= (SFP_FLAG_PT_SWLASER << SFP_FLAG_PT_SHIFT);
5528 } else if (trasn_code_byte4->fc_lw_laser) {
5529 wavelength = (page_a0[SSF_WAVELENGTH_B1] << 8) |
5530 page_a0[SSF_WAVELENGTH_B0];
5531 if (wavelength == SFP_WAVELENGTH_LC1310)
5532 flag |= SFP_FLAG_PT_LWLASER_LC1310 << SFP_FLAG_PT_SHIFT;
5533 if (wavelength == SFP_WAVELENGTH_LL1550)
5534 flag |= SFP_FLAG_PT_LWLASER_LL1550 << SFP_FLAG_PT_SHIFT;
5536 /* check if its SFP+ */
5537 flag |= ((page_a0[SSF_IDENTIFIER] == SFF_PG0_IDENT_SFP) ?
5538 SFP_FLAG_CT_SFP_PLUS : SFP_FLAG_CT_UNKNOWN)
5539 << SFP_FLAG_CT_SHIFT;
5541 /* check if its OPTICAL */
5542 flag |= ((page_a0[SSF_CONNECTOR] == SFF_PG0_CONNECTOR_LC) ?
5543 SFP_FLAG_IS_OPTICAL_PORT : 0)
5544 << SFP_FLAG_IS_OPTICAL_SHIFT;
5546 temperature = (page_a2[SFF_TEMPERATURE_B1] << 8 |
5547 page_a2[SFF_TEMPERATURE_B0]);
5548 vcc = (page_a2[SFF_VCC_B1] << 8 |
5549 page_a2[SFF_VCC_B0]);
5550 tx_power = (page_a2[SFF_TXPOWER_B1] << 8 |
5551 page_a2[SFF_TXPOWER_B0]);
5552 tx_bias = (page_a2[SFF_TX_BIAS_CURRENT_B1] << 8 |
5553 page_a2[SFF_TX_BIAS_CURRENT_B0]);
5554 rx_power = (page_a2[SFF_RXPOWER_B1] << 8 |
5555 page_a2[SFF_RXPOWER_B0]);
5556 desc->sfp_info.temperature = cpu_to_be16(temperature);
5557 desc->sfp_info.rx_power = cpu_to_be16(rx_power);
5558 desc->sfp_info.tx_bias = cpu_to_be16(tx_bias);
5559 desc->sfp_info.tx_power = cpu_to_be16(tx_power);
5560 desc->sfp_info.vcc = cpu_to_be16(vcc);
5562 desc->sfp_info.flags = cpu_to_be16(flag);
5563 desc->length = cpu_to_be32(sizeof(desc->sfp_info));
5565 return sizeof(struct fc_rdp_sfp_desc);
5569 lpfc_rdp_res_link_error(struct fc_rdp_link_error_status_desc *desc,
5574 desc->tag = cpu_to_be32(RDP_LINK_ERROR_STATUS_DESC_TAG);
5576 type = VN_PT_PHY_PF_PORT << VN_PT_PHY_SHIFT;
5578 desc->info.port_type = cpu_to_be32(type);
5580 desc->info.link_status.link_failure_cnt =
5581 cpu_to_be32(stat->linkFailureCnt);
5582 desc->info.link_status.loss_of_synch_cnt =
5583 cpu_to_be32(stat->lossSyncCnt);
5584 desc->info.link_status.loss_of_signal_cnt =
5585 cpu_to_be32(stat->lossSignalCnt);
5586 desc->info.link_status.primitive_seq_proto_err =
5587 cpu_to_be32(stat->primSeqErrCnt);
5588 desc->info.link_status.invalid_trans_word =
5589 cpu_to_be32(stat->invalidXmitWord);
5590 desc->info.link_status.invalid_crc_cnt = cpu_to_be32(stat->crcCnt);
5592 desc->length = cpu_to_be32(sizeof(desc->info));
5594 return sizeof(struct fc_rdp_link_error_status_desc);
5598 lpfc_rdp_res_bbc_desc(struct fc_rdp_bbc_desc *desc, READ_LNK_VAR *stat,
5599 struct lpfc_vport *vport)
5603 desc->tag = cpu_to_be32(RDP_BBC_DESC_TAG);
5605 bbCredit = vport->fc_sparam.cmn.bbCreditLsb |
5606 (vport->fc_sparam.cmn.bbCreditMsb << 8);
5607 desc->bbc_info.port_bbc = cpu_to_be32(bbCredit);
5608 if (vport->phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
5609 bbCredit = vport->phba->fc_fabparam.cmn.bbCreditLsb |
5610 (vport->phba->fc_fabparam.cmn.bbCreditMsb << 8);
5611 desc->bbc_info.attached_port_bbc = cpu_to_be32(bbCredit);
5613 desc->bbc_info.attached_port_bbc = 0;
5616 desc->bbc_info.rtt = 0;
5617 desc->length = cpu_to_be32(sizeof(desc->bbc_info));
5619 return sizeof(struct fc_rdp_bbc_desc);
5623 lpfc_rdp_res_oed_temp_desc(struct lpfc_hba *phba,
5624 struct fc_rdp_oed_sfp_desc *desc, uint8_t *page_a2)
5628 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5630 desc->oed_info.hi_alarm = page_a2[SSF_TEMP_HIGH_ALARM];
5631 desc->oed_info.lo_alarm = page_a2[SSF_TEMP_LOW_ALARM];
5632 desc->oed_info.hi_warning = page_a2[SSF_TEMP_HIGH_WARNING];
5633 desc->oed_info.lo_warning = page_a2[SSF_TEMP_LOW_WARNING];
5635 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TEMPERATURE)
5636 flags |= RDP_OET_HIGH_ALARM;
5637 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TEMPERATURE)
5638 flags |= RDP_OET_LOW_ALARM;
5639 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TEMPERATURE)
5640 flags |= RDP_OET_HIGH_WARNING;
5641 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TEMPERATURE)
5642 flags |= RDP_OET_LOW_WARNING;
5644 flags |= ((0xf & RDP_OED_TEMPERATURE) << RDP_OED_TYPE_SHIFT);
5645 desc->oed_info.function_flags = cpu_to_be32(flags);
5646 desc->length = cpu_to_be32(sizeof(desc->oed_info));
5647 return sizeof(struct fc_rdp_oed_sfp_desc);
5651 lpfc_rdp_res_oed_voltage_desc(struct lpfc_hba *phba,
5652 struct fc_rdp_oed_sfp_desc *desc,
5657 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5659 desc->oed_info.hi_alarm = page_a2[SSF_VOLTAGE_HIGH_ALARM];
5660 desc->oed_info.lo_alarm = page_a2[SSF_VOLTAGE_LOW_ALARM];
5661 desc->oed_info.hi_warning = page_a2[SSF_VOLTAGE_HIGH_WARNING];
5662 desc->oed_info.lo_warning = page_a2[SSF_VOLTAGE_LOW_WARNING];
5664 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_VOLTAGE)
5665 flags |= RDP_OET_HIGH_ALARM;
5666 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_VOLTAGE)
5667 flags |= RDP_OET_LOW_ALARM;
5668 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_VOLTAGE)
5669 flags |= RDP_OET_HIGH_WARNING;
5670 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_VOLTAGE)
5671 flags |= RDP_OET_LOW_WARNING;
5673 flags |= ((0xf & RDP_OED_VOLTAGE) << RDP_OED_TYPE_SHIFT);
5674 desc->oed_info.function_flags = cpu_to_be32(flags);
5675 desc->length = cpu_to_be32(sizeof(desc->oed_info));
5676 return sizeof(struct fc_rdp_oed_sfp_desc);
5680 lpfc_rdp_res_oed_txbias_desc(struct lpfc_hba *phba,
5681 struct fc_rdp_oed_sfp_desc *desc,
5686 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5688 desc->oed_info.hi_alarm = page_a2[SSF_BIAS_HIGH_ALARM];
5689 desc->oed_info.lo_alarm = page_a2[SSF_BIAS_LOW_ALARM];
5690 desc->oed_info.hi_warning = page_a2[SSF_BIAS_HIGH_WARNING];
5691 desc->oed_info.lo_warning = page_a2[SSF_BIAS_LOW_WARNING];
5693 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TXBIAS)
5694 flags |= RDP_OET_HIGH_ALARM;
5695 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TXBIAS)
5696 flags |= RDP_OET_LOW_ALARM;
5697 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TXBIAS)
5698 flags |= RDP_OET_HIGH_WARNING;
5699 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TXBIAS)
5700 flags |= RDP_OET_LOW_WARNING;
5702 flags |= ((0xf & RDP_OED_TXBIAS) << RDP_OED_TYPE_SHIFT);
5703 desc->oed_info.function_flags = cpu_to_be32(flags);
5704 desc->length = cpu_to_be32(sizeof(desc->oed_info));
5705 return sizeof(struct fc_rdp_oed_sfp_desc);
5709 lpfc_rdp_res_oed_txpower_desc(struct lpfc_hba *phba,
5710 struct fc_rdp_oed_sfp_desc *desc,
5715 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5717 desc->oed_info.hi_alarm = page_a2[SSF_TXPOWER_HIGH_ALARM];
5718 desc->oed_info.lo_alarm = page_a2[SSF_TXPOWER_LOW_ALARM];
5719 desc->oed_info.hi_warning = page_a2[SSF_TXPOWER_HIGH_WARNING];
5720 desc->oed_info.lo_warning = page_a2[SSF_TXPOWER_LOW_WARNING];
5722 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TXPOWER)
5723 flags |= RDP_OET_HIGH_ALARM;
5724 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TXPOWER)
5725 flags |= RDP_OET_LOW_ALARM;
5726 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TXPOWER)
5727 flags |= RDP_OET_HIGH_WARNING;
5728 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TXPOWER)
5729 flags |= RDP_OET_LOW_WARNING;
5731 flags |= ((0xf & RDP_OED_TXPOWER) << RDP_OED_TYPE_SHIFT);
5732 desc->oed_info.function_flags = cpu_to_be32(flags);
5733 desc->length = cpu_to_be32(sizeof(desc->oed_info));
5734 return sizeof(struct fc_rdp_oed_sfp_desc);
5739 lpfc_rdp_res_oed_rxpower_desc(struct lpfc_hba *phba,
5740 struct fc_rdp_oed_sfp_desc *desc,
5745 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5747 desc->oed_info.hi_alarm = page_a2[SSF_RXPOWER_HIGH_ALARM];
5748 desc->oed_info.lo_alarm = page_a2[SSF_RXPOWER_LOW_ALARM];
5749 desc->oed_info.hi_warning = page_a2[SSF_RXPOWER_HIGH_WARNING];
5750 desc->oed_info.lo_warning = page_a2[SSF_RXPOWER_LOW_WARNING];
5752 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_RXPOWER)
5753 flags |= RDP_OET_HIGH_ALARM;
5754 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_RXPOWER)
5755 flags |= RDP_OET_LOW_ALARM;
5756 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_RXPOWER)
5757 flags |= RDP_OET_HIGH_WARNING;
5758 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_RXPOWER)
5759 flags |= RDP_OET_LOW_WARNING;
5761 flags |= ((0xf & RDP_OED_RXPOWER) << RDP_OED_TYPE_SHIFT);
5762 desc->oed_info.function_flags = cpu_to_be32(flags);
5763 desc->length = cpu_to_be32(sizeof(desc->oed_info));
5764 return sizeof(struct fc_rdp_oed_sfp_desc);
5768 lpfc_rdp_res_opd_desc(struct fc_rdp_opd_sfp_desc *desc,
5769 uint8_t *page_a0, struct lpfc_vport *vport)
5771 desc->tag = cpu_to_be32(RDP_OPD_DESC_TAG);
5772 memcpy(desc->opd_info.vendor_name, &page_a0[SSF_VENDOR_NAME], 16);
5773 memcpy(desc->opd_info.model_number, &page_a0[SSF_VENDOR_PN], 16);
5774 memcpy(desc->opd_info.serial_number, &page_a0[SSF_VENDOR_SN], 16);
5775 memcpy(desc->opd_info.revision, &page_a0[SSF_VENDOR_REV], 4);
5776 memcpy(desc->opd_info.date, &page_a0[SSF_DATE_CODE], 8);
5777 desc->length = cpu_to_be32(sizeof(desc->opd_info));
5778 return sizeof(struct fc_rdp_opd_sfp_desc);
5782 lpfc_rdp_res_fec_desc(struct fc_fec_rdp_desc *desc, READ_LNK_VAR *stat)
5784 if (bf_get(lpfc_read_link_stat_gec2, stat) == 0)
5786 desc->tag = cpu_to_be32(RDP_FEC_DESC_TAG);
5788 desc->info.CorrectedBlocks =
5789 cpu_to_be32(stat->fecCorrBlkCount);
5790 desc->info.UncorrectableBlocks =
5791 cpu_to_be32(stat->fecUncorrBlkCount);
5793 desc->length = cpu_to_be32(sizeof(desc->info));
5795 return sizeof(struct fc_fec_rdp_desc);
5799 lpfc_rdp_res_speed(struct fc_rdp_port_speed_desc *desc, struct lpfc_hba *phba)
5801 uint16_t rdp_cap = 0;
5804 desc->tag = cpu_to_be32(RDP_PORT_SPEED_DESC_TAG);
5806 switch (phba->fc_linkspeed) {
5807 case LPFC_LINK_SPEED_1GHZ:
5808 rdp_speed = RDP_PS_1GB;
5810 case LPFC_LINK_SPEED_2GHZ:
5811 rdp_speed = RDP_PS_2GB;
5813 case LPFC_LINK_SPEED_4GHZ:
5814 rdp_speed = RDP_PS_4GB;
5816 case LPFC_LINK_SPEED_8GHZ:
5817 rdp_speed = RDP_PS_8GB;
5819 case LPFC_LINK_SPEED_10GHZ:
5820 rdp_speed = RDP_PS_10GB;
5822 case LPFC_LINK_SPEED_16GHZ:
5823 rdp_speed = RDP_PS_16GB;
5825 case LPFC_LINK_SPEED_32GHZ:
5826 rdp_speed = RDP_PS_32GB;
5828 case LPFC_LINK_SPEED_64GHZ:
5829 rdp_speed = RDP_PS_64GB;
5832 rdp_speed = RDP_PS_UNKNOWN;
5836 desc->info.port_speed.speed = cpu_to_be16(rdp_speed);
5838 if (phba->lmt & LMT_128Gb)
5839 rdp_cap |= RDP_PS_128GB;
5840 if (phba->lmt & LMT_64Gb)
5841 rdp_cap |= RDP_PS_64GB;
5842 if (phba->lmt & LMT_32Gb)
5843 rdp_cap |= RDP_PS_32GB;
5844 if (phba->lmt & LMT_16Gb)
5845 rdp_cap |= RDP_PS_16GB;
5846 if (phba->lmt & LMT_10Gb)
5847 rdp_cap |= RDP_PS_10GB;
5848 if (phba->lmt & LMT_8Gb)
5849 rdp_cap |= RDP_PS_8GB;
5850 if (phba->lmt & LMT_4Gb)
5851 rdp_cap |= RDP_PS_4GB;
5852 if (phba->lmt & LMT_2Gb)
5853 rdp_cap |= RDP_PS_2GB;
5854 if (phba->lmt & LMT_1Gb)
5855 rdp_cap |= RDP_PS_1GB;
5858 rdp_cap = RDP_CAP_UNKNOWN;
5859 if (phba->cfg_link_speed != LPFC_USER_LINK_SPEED_AUTO)
5860 rdp_cap |= RDP_CAP_USER_CONFIGURED;
5862 desc->info.port_speed.capabilities = cpu_to_be16(rdp_cap);
5863 desc->length = cpu_to_be32(sizeof(desc->info));
5864 return sizeof(struct fc_rdp_port_speed_desc);
5868 lpfc_rdp_res_diag_port_names(struct fc_rdp_port_name_desc *desc,
5869 struct lpfc_vport *vport)
5872 desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG);
5874 memcpy(desc->port_names.wwnn, &vport->fc_nodename,
5875 sizeof(desc->port_names.wwnn));
5877 memcpy(desc->port_names.wwpn, &vport->fc_portname,
5878 sizeof(desc->port_names.wwpn));
5880 desc->length = cpu_to_be32(sizeof(desc->port_names));
5881 return sizeof(struct fc_rdp_port_name_desc);
5885 lpfc_rdp_res_attach_port_names(struct fc_rdp_port_name_desc *desc,
5886 struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
5889 desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG);
5890 if (vport->fc_flag & FC_FABRIC) {
5891 memcpy(desc->port_names.wwnn, &vport->fabric_nodename,
5892 sizeof(desc->port_names.wwnn));
5894 memcpy(desc->port_names.wwpn, &vport->fabric_portname,
5895 sizeof(desc->port_names.wwpn));
5896 } else { /* Point to Point */
5897 memcpy(desc->port_names.wwnn, &ndlp->nlp_nodename,
5898 sizeof(desc->port_names.wwnn));
5900 memcpy(desc->port_names.wwpn, &ndlp->nlp_portname,
5901 sizeof(desc->port_names.wwpn));
5904 desc->length = cpu_to_be32(sizeof(desc->port_names));
5905 return sizeof(struct fc_rdp_port_name_desc);
5909 lpfc_els_rdp_cmpl(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context,
5912 struct lpfc_nodelist *ndlp = rdp_context->ndlp;
5913 struct lpfc_vport *vport = ndlp->vport;
5914 struct lpfc_iocbq *elsiocb;
5915 struct ulp_bde64 *bpl;
5918 struct ls_rjt *stat;
5919 struct fc_rdp_res_frame *rdp_res;
5920 uint32_t cmdsize, len;
5924 if (status != SUCCESS)
5927 /* This will change once we know the true size of the RDP payload */
5928 cmdsize = sizeof(struct fc_rdp_res_frame);
5930 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize,
5931 lpfc_max_els_tries, rdp_context->ndlp,
5932 rdp_context->ndlp->nlp_DID, ELS_CMD_ACC);
5935 goto free_rdp_context;
5937 icmd = &elsiocb->iocb;
5938 icmd->ulpContext = rdp_context->rx_id;
5939 icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id;
5941 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5942 "2171 Xmit RDP response tag x%x xri x%x, "
5943 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x",
5944 elsiocb->iotag, elsiocb->iocb.ulpContext,
5945 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5947 rdp_res = (struct fc_rdp_res_frame *)
5948 (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5949 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5950 memset(pcmd, 0, sizeof(struct fc_rdp_res_frame));
5951 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5953 /* Update Alarm and Warning */
5954 flag_ptr = (uint16_t *)(rdp_context->page_a2 + SSF_ALARM_FLAGS);
5955 phba->sfp_alarm |= *flag_ptr;
5956 flag_ptr = (uint16_t *)(rdp_context->page_a2 + SSF_WARNING_FLAGS);
5957 phba->sfp_warning |= *flag_ptr;
5959 /* For RDP payload */
5961 len += lpfc_rdp_res_link_service((struct fc_rdp_link_service_desc *)
5962 (len + pcmd), ELS_CMD_RDP);
5964 len += lpfc_rdp_res_sfp_desc((struct fc_rdp_sfp_desc *)(len + pcmd),
5965 rdp_context->page_a0, rdp_context->page_a2);
5966 len += lpfc_rdp_res_speed((struct fc_rdp_port_speed_desc *)(len + pcmd),
5968 len += lpfc_rdp_res_link_error((struct fc_rdp_link_error_status_desc *)
5969 (len + pcmd), &rdp_context->link_stat);
5970 len += lpfc_rdp_res_diag_port_names((struct fc_rdp_port_name_desc *)
5971 (len + pcmd), vport);
5972 len += lpfc_rdp_res_attach_port_names((struct fc_rdp_port_name_desc *)
5973 (len + pcmd), vport, ndlp);
5974 len += lpfc_rdp_res_fec_desc((struct fc_fec_rdp_desc *)(len + pcmd),
5975 &rdp_context->link_stat);
5976 len += lpfc_rdp_res_bbc_desc((struct fc_rdp_bbc_desc *)(len + pcmd),
5977 &rdp_context->link_stat, vport);
5978 len += lpfc_rdp_res_oed_temp_desc(phba,
5979 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5980 rdp_context->page_a2);
5981 len += lpfc_rdp_res_oed_voltage_desc(phba,
5982 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5983 rdp_context->page_a2);
5984 len += lpfc_rdp_res_oed_txbias_desc(phba,
5985 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5986 rdp_context->page_a2);
5987 len += lpfc_rdp_res_oed_txpower_desc(phba,
5988 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5989 rdp_context->page_a2);
5990 len += lpfc_rdp_res_oed_rxpower_desc(phba,
5991 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5992 rdp_context->page_a2);
5993 len += lpfc_rdp_res_opd_desc((struct fc_rdp_opd_sfp_desc *)(len + pcmd),
5994 rdp_context->page_a0, vport);
5996 rdp_res->length = cpu_to_be32(len - 8);
5997 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5999 /* Now that we know the true size of the payload, update the BPL */
6000 bpl = (struct ulp_bde64 *)
6001 (((struct lpfc_dmabuf *)(elsiocb->context3))->virt);
6002 bpl->tus.f.bdeSize = len;
6003 bpl->tus.f.bdeFlags = 0;
6004 bpl->tus.w = le32_to_cpu(bpl->tus.w);
6006 phba->fc_stat.elsXmitACC++;
6007 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
6008 if (rc == IOCB_ERROR)
6009 lpfc_els_free_iocb(phba, elsiocb);
6015 cmdsize = 2 * sizeof(uint32_t);
6016 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, lpfc_max_els_tries,
6017 ndlp, ndlp->nlp_DID, ELS_CMD_LS_RJT);
6020 goto free_rdp_context;
6022 icmd = &elsiocb->iocb;
6023 icmd->ulpContext = rdp_context->rx_id;
6024 icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id;
6025 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6027 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
6028 stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t));
6029 stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6031 phba->fc_stat.elsXmitLSRJT++;
6032 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
6033 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
6035 if (rc == IOCB_ERROR)
6036 lpfc_els_free_iocb(phba, elsiocb);
6042 lpfc_get_rdp_info(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context)
6044 LPFC_MBOXQ_t *mbox = NULL;
6047 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6049 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_ELS,
6050 "7105 failed to allocate mailbox memory");
6054 if (lpfc_sli4_dump_page_a0(phba, mbox))
6055 goto prep_mbox_fail;
6056 mbox->vport = rdp_context->ndlp->vport;
6057 mbox->mbox_cmpl = lpfc_mbx_cmpl_rdp_page_a0;
6058 mbox->ctx_ndlp = (struct lpfc_rdp_context *)rdp_context;
6059 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
6060 if (rc == MBX_NOT_FINISHED)
6061 goto issue_mbox_fail;
6067 mempool_free(mbox, phba->mbox_mem_pool);
6072 * lpfc_els_rcv_rdp - Process an unsolicited RDP ELS.
6073 * @vport: pointer to a host virtual N_Port data structure.
6074 * @cmdiocb: pointer to lpfc command iocb data structure.
6075 * @ndlp: pointer to a node-list data structure.
6077 * This routine processes an unsolicited RDP(Read Diagnostic Parameters)
6078 * IOCB. First, the payload of the unsolicited RDP is checked.
6079 * Then it will (1) send MBX_DUMP_MEMORY, Embedded DMP_LMSD sub command TYPE-3
6080 * for Page A0, (2) send MBX_DUMP_MEMORY, DMP_LMSD for Page A2,
6081 * (3) send MBX_READ_LNK_STAT to get link stat, (4) Call lpfc_els_rdp_cmpl
6082 * gather all data and send RDP response.
6085 * 0 - Sent the acc response
6086 * 1 - Sent the reject response.
6089 lpfc_els_rcv_rdp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6090 struct lpfc_nodelist *ndlp)
6092 struct lpfc_hba *phba = vport->phba;
6093 struct lpfc_dmabuf *pcmd;
6094 uint8_t rjt_err, rjt_expl = LSEXP_NOTHING_MORE;
6095 struct fc_rdp_req_frame *rdp_req;
6096 struct lpfc_rdp_context *rdp_context;
6100 if (phba->sli_rev < LPFC_SLI_REV4 ||
6101 bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
6102 LPFC_SLI_INTF_IF_TYPE_2) {
6103 rjt_err = LSRJT_UNABLE_TPC;
6104 rjt_expl = LSEXP_REQ_UNSUPPORTED;
6108 if (phba->sli_rev < LPFC_SLI_REV4 || (phba->hba_flag & HBA_FCOE_MODE)) {
6109 rjt_err = LSRJT_UNABLE_TPC;
6110 rjt_expl = LSEXP_REQ_UNSUPPORTED;
6114 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6115 rdp_req = (struct fc_rdp_req_frame *) pcmd->virt;
6117 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6118 "2422 ELS RDP Request "
6119 "dec len %d tag x%x port_id %d len %d\n",
6120 be32_to_cpu(rdp_req->rdp_des_length),
6121 be32_to_cpu(rdp_req->nport_id_desc.tag),
6122 be32_to_cpu(rdp_req->nport_id_desc.nport_id),
6123 be32_to_cpu(rdp_req->nport_id_desc.length));
6125 if (sizeof(struct fc_rdp_nport_desc) !=
6126 be32_to_cpu(rdp_req->rdp_des_length))
6128 if (RDP_N_PORT_DESC_TAG != be32_to_cpu(rdp_req->nport_id_desc.tag))
6130 if (RDP_NPORT_ID_SIZE !=
6131 be32_to_cpu(rdp_req->nport_id_desc.length))
6133 rdp_context = kzalloc(sizeof(struct lpfc_rdp_context), GFP_KERNEL);
6135 rjt_err = LSRJT_UNABLE_TPC;
6139 cmd = &cmdiocb->iocb;
6140 rdp_context->ndlp = lpfc_nlp_get(ndlp);
6141 rdp_context->ox_id = cmd->unsli3.rcvsli3.ox_id;
6142 rdp_context->rx_id = cmd->ulpContext;
6143 rdp_context->cmpl = lpfc_els_rdp_cmpl;
6144 if (lpfc_get_rdp_info(phba, rdp_context)) {
6145 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_ELS,
6146 "2423 Unable to send mailbox");
6148 rjt_err = LSRJT_UNABLE_TPC;
6156 rjt_err = LSRJT_LOGICAL_ERR;
6159 memset(&stat, 0, sizeof(stat));
6160 stat.un.b.lsRjtRsnCode = rjt_err;
6161 stat.un.b.lsRjtRsnCodeExp = rjt_expl;
6162 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
6168 lpfc_els_lcb_rsp(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
6173 struct lpfc_iocbq *elsiocb;
6174 struct lpfc_nodelist *ndlp;
6175 struct ls_rjt *stat;
6176 union lpfc_sli4_cfg_shdr *shdr;
6177 struct lpfc_lcb_context *lcb_context;
6178 struct fc_lcb_res_frame *lcb_res;
6179 uint32_t cmdsize, shdr_status, shdr_add_status;
6183 lcb_context = (struct lpfc_lcb_context *)pmb->ctx_ndlp;
6184 ndlp = lcb_context->ndlp;
6185 pmb->ctx_ndlp = NULL;
6186 pmb->ctx_buf = NULL;
6188 shdr = (union lpfc_sli4_cfg_shdr *)
6189 &pmb->u.mqe.un.beacon_config.header.cfg_shdr;
6190 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
6191 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
6193 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX,
6194 "0194 SET_BEACON_CONFIG mailbox "
6195 "completed with status x%x add_status x%x,"
6196 " mbx status x%x\n",
6197 shdr_status, shdr_add_status, mb->mbxStatus);
6199 if ((mb->mbxStatus != MBX_SUCCESS) || shdr_status ||
6200 (shdr_add_status == ADD_STATUS_OPERATION_ALREADY_ACTIVE) ||
6201 (shdr_add_status == ADD_STATUS_INVALID_REQUEST)) {
6202 mempool_free(pmb, phba->mbox_mem_pool);
6206 mempool_free(pmb, phba->mbox_mem_pool);
6207 cmdsize = sizeof(struct fc_lcb_res_frame);
6208 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
6209 lpfc_max_els_tries, ndlp,
6210 ndlp->nlp_DID, ELS_CMD_ACC);
6212 /* Decrement the ndlp reference count from previous mbox command */
6216 goto free_lcb_context;
6218 lcb_res = (struct fc_lcb_res_frame *)
6219 (((struct lpfc_dmabuf *)elsiocb->context2)->virt);
6221 memset(lcb_res, 0, sizeof(struct fc_lcb_res_frame));
6222 icmd = &elsiocb->iocb;
6223 icmd->ulpContext = lcb_context->rx_id;
6224 icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id;
6226 pcmd = (uint8_t *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt);
6227 *((uint32_t *)(pcmd)) = ELS_CMD_ACC;
6228 lcb_res->lcb_sub_command = lcb_context->sub_command;
6229 lcb_res->lcb_type = lcb_context->type;
6230 lcb_res->capability = lcb_context->capability;
6231 lcb_res->lcb_frequency = lcb_context->frequency;
6232 lcb_res->lcb_duration = lcb_context->duration;
6233 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
6234 phba->fc_stat.elsXmitACC++;
6235 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
6236 if (rc == IOCB_ERROR)
6237 lpfc_els_free_iocb(phba, elsiocb);
6243 cmdsize = sizeof(struct fc_lcb_res_frame);
6244 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
6245 lpfc_max_els_tries, ndlp,
6246 ndlp->nlp_DID, ELS_CMD_LS_RJT);
6249 goto free_lcb_context;
6251 icmd = &elsiocb->iocb;
6252 icmd->ulpContext = lcb_context->rx_id;
6253 icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id;
6254 pcmd = (uint8_t *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt);
6256 *((uint32_t *)(pcmd)) = ELS_CMD_LS_RJT;
6257 stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t));
6258 stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6260 if (shdr_add_status == ADD_STATUS_OPERATION_ALREADY_ACTIVE)
6261 stat->un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS;
6263 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
6264 phba->fc_stat.elsXmitLSRJT++;
6265 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
6266 if (rc == IOCB_ERROR)
6267 lpfc_els_free_iocb(phba, elsiocb);
6273 lpfc_sli4_set_beacon(struct lpfc_vport *vport,
6274 struct lpfc_lcb_context *lcb_context,
6275 uint32_t beacon_state)
6277 struct lpfc_hba *phba = vport->phba;
6278 union lpfc_sli4_cfg_shdr *cfg_shdr;
6279 LPFC_MBOXQ_t *mbox = NULL;
6283 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6287 cfg_shdr = &mbox->u.mqe.un.sli4_config.header.cfg_shdr;
6288 len = sizeof(struct lpfc_mbx_set_beacon_config) -
6289 sizeof(struct lpfc_sli4_cfg_mhdr);
6290 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
6291 LPFC_MBOX_OPCODE_SET_BEACON_CONFIG, len,
6292 LPFC_SLI4_MBX_EMBED);
6293 mbox->ctx_ndlp = (void *)lcb_context;
6294 mbox->vport = phba->pport;
6295 mbox->mbox_cmpl = lpfc_els_lcb_rsp;
6296 bf_set(lpfc_mbx_set_beacon_port_num, &mbox->u.mqe.un.beacon_config,
6297 phba->sli4_hba.physical_port);
6298 bf_set(lpfc_mbx_set_beacon_state, &mbox->u.mqe.un.beacon_config,
6300 mbox->u.mqe.un.beacon_config.word5 = 0; /* Reserved */
6303 * Check bv1s bit before issuing the mailbox
6304 * if bv1s == 1, LCB V1 supported
6305 * else, LCB V0 supported
6308 if (phba->sli4_hba.pc_sli4_params.bv1s) {
6309 /* COMMON_SET_BEACON_CONFIG_V1 */
6310 cfg_shdr->request.word9 = BEACON_VERSION_V1;
6311 lcb_context->capability |= LCB_CAPABILITY_DURATION;
6312 bf_set(lpfc_mbx_set_beacon_port_type,
6313 &mbox->u.mqe.un.beacon_config, 0);
6314 bf_set(lpfc_mbx_set_beacon_duration_v1,
6315 &mbox->u.mqe.un.beacon_config,
6316 be16_to_cpu(lcb_context->duration));
6318 /* COMMON_SET_BEACON_CONFIG_V0 */
6319 if (be16_to_cpu(lcb_context->duration) != 0) {
6320 mempool_free(mbox, phba->mbox_mem_pool);
6323 cfg_shdr->request.word9 = BEACON_VERSION_V0;
6324 lcb_context->capability &= ~(LCB_CAPABILITY_DURATION);
6325 bf_set(lpfc_mbx_set_beacon_state,
6326 &mbox->u.mqe.un.beacon_config, beacon_state);
6327 bf_set(lpfc_mbx_set_beacon_port_type,
6328 &mbox->u.mqe.un.beacon_config, 1);
6329 bf_set(lpfc_mbx_set_beacon_duration,
6330 &mbox->u.mqe.un.beacon_config,
6331 be16_to_cpu(lcb_context->duration));
6334 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
6335 if (rc == MBX_NOT_FINISHED) {
6336 mempool_free(mbox, phba->mbox_mem_pool);
6345 * lpfc_els_rcv_lcb - Process an unsolicited LCB
6346 * @vport: pointer to a host virtual N_Port data structure.
6347 * @cmdiocb: pointer to lpfc command iocb data structure.
6348 * @ndlp: pointer to a node-list data structure.
6350 * This routine processes an unsolicited LCB(LINK CABLE BEACON) IOCB.
6351 * First, the payload of the unsolicited LCB is checked.
6352 * Then based on Subcommand beacon will either turn on or off.
6355 * 0 - Sent the acc response
6356 * 1 - Sent the reject response.
6359 lpfc_els_rcv_lcb(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6360 struct lpfc_nodelist *ndlp)
6362 struct lpfc_hba *phba = vport->phba;
6363 struct lpfc_dmabuf *pcmd;
6365 struct fc_lcb_request_frame *beacon;
6366 struct lpfc_lcb_context *lcb_context;
6367 uint8_t state, rjt_err;
6370 pcmd = (struct lpfc_dmabuf *)cmdiocb->context2;
6371 lp = (uint8_t *)pcmd->virt;
6372 beacon = (struct fc_lcb_request_frame *)pcmd->virt;
6374 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6375 "0192 ELS LCB Data x%x x%x x%x x%x sub x%x "
6376 "type x%x frequency %x duration x%x\n",
6377 lp[0], lp[1], lp[2],
6378 beacon->lcb_command,
6379 beacon->lcb_sub_command,
6381 beacon->lcb_frequency,
6382 be16_to_cpu(beacon->lcb_duration));
6384 if (beacon->lcb_sub_command != LPFC_LCB_ON &&
6385 beacon->lcb_sub_command != LPFC_LCB_OFF) {
6386 rjt_err = LSRJT_CMD_UNSUPPORTED;
6390 if (phba->sli_rev < LPFC_SLI_REV4 ||
6391 phba->hba_flag & HBA_FCOE_MODE ||
6392 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
6393 LPFC_SLI_INTF_IF_TYPE_2)) {
6394 rjt_err = LSRJT_CMD_UNSUPPORTED;
6398 lcb_context = kmalloc(sizeof(*lcb_context), GFP_KERNEL);
6400 rjt_err = LSRJT_UNABLE_TPC;
6404 state = (beacon->lcb_sub_command == LPFC_LCB_ON) ? 1 : 0;
6405 lcb_context->sub_command = beacon->lcb_sub_command;
6406 lcb_context->capability = 0;
6407 lcb_context->type = beacon->lcb_type;
6408 lcb_context->frequency = beacon->lcb_frequency;
6409 lcb_context->duration = beacon->lcb_duration;
6410 lcb_context->ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id;
6411 lcb_context->rx_id = cmdiocb->iocb.ulpContext;
6412 lcb_context->ndlp = lpfc_nlp_get(ndlp);
6413 if (lpfc_sli4_set_beacon(vport, lcb_context, state)) {
6414 lpfc_printf_vlog(ndlp->vport, KERN_ERR,
6415 LOG_ELS, "0193 failed to send mail box");
6418 rjt_err = LSRJT_UNABLE_TPC;
6423 memset(&stat, 0, sizeof(stat));
6424 stat.un.b.lsRjtRsnCode = rjt_err;
6425 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
6431 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
6432 * @vport: pointer to a host virtual N_Port data structure.
6434 * This routine cleans up any Registration State Change Notification
6435 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
6436 * @vport together with the host_lock is used to prevent multiple thread
6437 * trying to access the RSCN array on a same @vport at the same time.
6440 lpfc_els_flush_rscn(struct lpfc_vport *vport)
6442 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6443 struct lpfc_hba *phba = vport->phba;
6446 spin_lock_irq(shost->host_lock);
6447 if (vport->fc_rscn_flush) {
6448 /* Another thread is walking fc_rscn_id_list on this vport */
6449 spin_unlock_irq(shost->host_lock);
6452 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
6453 vport->fc_rscn_flush = 1;
6454 spin_unlock_irq(shost->host_lock);
6456 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
6457 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
6458 vport->fc_rscn_id_list[i] = NULL;
6460 spin_lock_irq(shost->host_lock);
6461 vport->fc_rscn_id_cnt = 0;
6462 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
6463 spin_unlock_irq(shost->host_lock);
6464 lpfc_can_disctmo(vport);
6465 /* Indicate we are done walking this fc_rscn_id_list */
6466 vport->fc_rscn_flush = 0;
6470 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
6471 * @vport: pointer to a host virtual N_Port data structure.
6472 * @did: remote destination port identifier.
6474 * This routine checks whether there is any pending Registration State
6475 * Configuration Notification (RSCN) to a @did on @vport.
6478 * None zero - The @did matched with a pending rscn
6479 * 0 - not able to match @did with a pending rscn
6482 lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
6487 uint32_t payload_len, i;
6488 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6490 ns_did.un.word = did;
6492 /* Never match fabric nodes for RSCNs */
6493 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
6496 /* If we are doing a FULL RSCN rediscovery, match everything */
6497 if (vport->fc_flag & FC_RSCN_DISCOVERY)
6500 spin_lock_irq(shost->host_lock);
6501 if (vport->fc_rscn_flush) {
6502 /* Another thread is walking fc_rscn_id_list on this vport */
6503 spin_unlock_irq(shost->host_lock);
6506 /* Indicate we are walking fc_rscn_id_list on this vport */
6507 vport->fc_rscn_flush = 1;
6508 spin_unlock_irq(shost->host_lock);
6509 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
6510 lp = vport->fc_rscn_id_list[i]->virt;
6511 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
6512 payload_len -= sizeof(uint32_t); /* take off word 0 */
6513 while (payload_len) {
6514 rscn_did.un.word = be32_to_cpu(*lp++);
6515 payload_len -= sizeof(uint32_t);
6516 switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) {
6517 case RSCN_ADDRESS_FORMAT_PORT:
6518 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
6519 && (ns_did.un.b.area == rscn_did.un.b.area)
6520 && (ns_did.un.b.id == rscn_did.un.b.id))
6521 goto return_did_out;
6523 case RSCN_ADDRESS_FORMAT_AREA:
6524 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
6525 && (ns_did.un.b.area == rscn_did.un.b.area))
6526 goto return_did_out;
6528 case RSCN_ADDRESS_FORMAT_DOMAIN:
6529 if (ns_did.un.b.domain == rscn_did.un.b.domain)
6530 goto return_did_out;
6532 case RSCN_ADDRESS_FORMAT_FABRIC:
6533 goto return_did_out;
6537 /* Indicate we are done with walking fc_rscn_id_list on this vport */
6538 vport->fc_rscn_flush = 0;
6541 /* Indicate we are done with walking fc_rscn_id_list on this vport */
6542 vport->fc_rscn_flush = 0;
6547 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
6548 * @vport: pointer to a host virtual N_Port data structure.
6550 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
6551 * state machine for a @vport's nodes that are with pending RSCN (Registration
6552 * State Change Notification).
6555 * 0 - Successful (currently alway return 0)
6558 lpfc_rscn_recovery_check(struct lpfc_vport *vport)
6560 struct lpfc_nodelist *ndlp = NULL;
6562 /* Move all affected nodes by pending RSCNs to NPR state. */
6563 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
6564 if (!NLP_CHK_NODE_ACT(ndlp) ||
6565 (ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
6566 !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
6569 /* NVME Target mode does not do RSCN Recovery. */
6570 if (vport->phba->nvmet_support)
6573 /* If we are in the process of doing discovery on this
6574 * NPort, let it continue on its own.
6576 switch (ndlp->nlp_state) {
6577 case NLP_STE_PLOGI_ISSUE:
6578 case NLP_STE_ADISC_ISSUE:
6579 case NLP_STE_REG_LOGIN_ISSUE:
6580 case NLP_STE_PRLI_ISSUE:
6581 case NLP_STE_LOGO_ISSUE:
6585 /* Check to see if we need to NVME rescan this target
6588 if (ndlp->nlp_fc4_type & NLP_FC4_NVME &&
6589 ndlp->nlp_type & (NLP_NVME_TARGET | NLP_NVME_DISCOVERY))
6590 lpfc_nvme_rescan_port(vport, ndlp);
6592 lpfc_disc_state_machine(vport, ndlp, NULL,
6593 NLP_EVT_DEVICE_RECOVERY);
6594 lpfc_cancel_retry_delay_tmo(vport, ndlp);
6600 * lpfc_send_rscn_event - Send an RSCN event to management application
6601 * @vport: pointer to a host virtual N_Port data structure.
6602 * @cmdiocb: pointer to lpfc command iocb data structure.
6604 * lpfc_send_rscn_event sends an RSCN netlink event to management
6608 lpfc_send_rscn_event(struct lpfc_vport *vport,
6609 struct lpfc_iocbq *cmdiocb)
6611 struct lpfc_dmabuf *pcmd;
6612 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6613 uint32_t *payload_ptr;
6614 uint32_t payload_len;
6615 struct lpfc_rscn_event_header *rscn_event_data;
6617 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6618 payload_ptr = (uint32_t *) pcmd->virt;
6619 payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK);
6621 rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) +
6622 payload_len, GFP_KERNEL);
6623 if (!rscn_event_data) {
6624 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6625 "0147 Failed to allocate memory for RSCN event\n");
6628 rscn_event_data->event_type = FC_REG_RSCN_EVENT;
6629 rscn_event_data->payload_length = payload_len;
6630 memcpy(rscn_event_data->rscn_payload, payload_ptr,
6633 fc_host_post_vendor_event(shost,
6634 fc_get_event_number(),
6635 sizeof(struct lpfc_rscn_event_header) + payload_len,
6636 (char *)rscn_event_data,
6639 kfree(rscn_event_data);
6643 * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
6644 * @vport: pointer to a host virtual N_Port data structure.
6645 * @cmdiocb: pointer to lpfc command iocb data structure.
6646 * @ndlp: pointer to a node-list data structure.
6648 * This routine processes an unsolicited RSCN (Registration State Change
6649 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
6650 * to invoke fc_host_post_event() routine to the FC transport layer. If the
6651 * discover state machine is about to begin discovery, it just accepts the
6652 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
6653 * contains N_Port IDs for other vports on this HBA, it just accepts the
6654 * RSCN and ignore processing it. If the state machine is in the recovery
6655 * state, the fc_rscn_id_list of this @vport is walked and the
6656 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
6657 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
6658 * routine is invoked to handle the RSCN event.
6661 * 0 - Just sent the acc response
6662 * 1 - Sent the acc response and waited for name server completion
6665 lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6666 struct lpfc_nodelist *ndlp)
6668 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6669 struct lpfc_hba *phba = vport->phba;
6670 struct lpfc_dmabuf *pcmd;
6671 uint32_t *lp, *datap;
6672 uint32_t payload_len, length, nportid, *cmd;
6674 int rscn_id = 0, hba_id = 0;
6677 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6678 lp = (uint32_t *) pcmd->virt;
6680 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
6681 payload_len -= sizeof(uint32_t); /* take off word 0 */
6683 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6684 "0214 RSCN received Data: x%x x%x x%x x%x\n",
6685 vport->fc_flag, payload_len, *lp,
6686 vport->fc_rscn_id_cnt);
6688 /* Send an RSCN event to the management application */
6689 lpfc_send_rscn_event(vport, cmdiocb);
6691 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
6692 fc_host_post_event(shost, fc_get_event_number(),
6693 FCH_EVT_RSCN, lp[i]);
6695 /* Check if RSCN is coming from a direct-connected remote NPort */
6696 if (vport->fc_flag & FC_PT2PT) {
6697 /* If so, just ACC it, no other action needed for now */
6698 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6699 "2024 pt2pt RSCN %08x Data: x%x x%x\n",
6700 *lp, vport->fc_flag, payload_len);
6701 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
6703 /* Check to see if we need to NVME rescan this target
6706 if (ndlp->nlp_fc4_type & NLP_FC4_NVME &&
6707 ndlp->nlp_type & (NLP_NVME_TARGET | NLP_NVME_DISCOVERY))
6708 lpfc_nvme_rescan_port(vport, ndlp);
6712 /* If we are about to begin discovery, just ACC the RSCN.
6713 * Discovery processing will satisfy it.
6715 if (vport->port_state <= LPFC_NS_QRY) {
6716 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6717 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
6718 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
6720 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
6724 /* If this RSCN just contains NPortIDs for other vports on this HBA,
6725 * just ACC and ignore it.
6727 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
6728 !(vport->cfg_peer_port_login)) {
6733 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
6734 i -= sizeof(uint32_t);
6736 if (lpfc_find_vport_by_did(phba, nportid))
6739 if (rscn_id == hba_id) {
6740 /* ALL NPortIDs in RSCN are on HBA */
6741 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6743 "Data: x%x x%x x%x x%x\n",
6744 vport->fc_flag, payload_len,
6745 *lp, vport->fc_rscn_id_cnt);
6746 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6747 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
6748 ndlp->nlp_DID, vport->port_state,
6751 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
6757 spin_lock_irq(shost->host_lock);
6758 if (vport->fc_rscn_flush) {
6759 /* Another thread is walking fc_rscn_id_list on this vport */
6760 vport->fc_flag |= FC_RSCN_DISCOVERY;
6761 spin_unlock_irq(shost->host_lock);
6763 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
6766 /* Indicate we are walking fc_rscn_id_list on this vport */
6767 vport->fc_rscn_flush = 1;
6768 spin_unlock_irq(shost->host_lock);
6769 /* Get the array count after successfully have the token */
6770 rscn_cnt = vport->fc_rscn_id_cnt;
6771 /* If we are already processing an RSCN, save the received
6772 * RSCN payload buffer, cmdiocb->context2 to process later.
6774 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
6775 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6776 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
6777 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
6779 spin_lock_irq(shost->host_lock);
6780 vport->fc_flag |= FC_RSCN_DEFERRED;
6782 /* Restart disctmo if its already running */
6783 if (vport->fc_flag & FC_DISC_TMO) {
6784 tmo = ((phba->fc_ratov * 3) + 3);
6785 mod_timer(&vport->fc_disctmo,
6786 jiffies + msecs_to_jiffies(1000 * tmo));
6788 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
6789 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
6790 vport->fc_flag |= FC_RSCN_MODE;
6791 spin_unlock_irq(shost->host_lock);
6793 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
6794 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
6797 (payload_len + length <= LPFC_BPL_SIZE)) {
6798 *cmd &= ELS_CMD_MASK;
6799 *cmd |= cpu_to_be32(payload_len + length);
6800 memcpy(((uint8_t *)cmd) + length, lp,
6803 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
6804 vport->fc_rscn_id_cnt++;
6805 /* If we zero, cmdiocb->context2, the calling
6806 * routine will not try to free it.
6808 cmdiocb->context2 = NULL;
6811 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6812 "0235 Deferred RSCN "
6813 "Data: x%x x%x x%x\n",
6814 vport->fc_rscn_id_cnt, vport->fc_flag,
6817 vport->fc_flag |= FC_RSCN_DISCOVERY;
6818 spin_unlock_irq(shost->host_lock);
6819 /* ReDiscovery RSCN */
6820 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6821 "0234 ReDiscovery RSCN "
6822 "Data: x%x x%x x%x\n",
6823 vport->fc_rscn_id_cnt, vport->fc_flag,
6826 /* Indicate we are done walking fc_rscn_id_list on this vport */
6827 vport->fc_rscn_flush = 0;
6829 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
6830 /* send RECOVERY event for ALL nodes that match RSCN payload */
6831 lpfc_rscn_recovery_check(vport);
6834 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6835 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
6836 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
6838 spin_lock_irq(shost->host_lock);
6839 vport->fc_flag |= FC_RSCN_MODE;
6840 spin_unlock_irq(shost->host_lock);
6841 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
6842 /* Indicate we are done walking fc_rscn_id_list on this vport */
6843 vport->fc_rscn_flush = 0;
6845 * If we zero, cmdiocb->context2, the calling routine will
6846 * not try to free it.
6848 cmdiocb->context2 = NULL;
6849 lpfc_set_disctmo(vport);
6851 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
6852 /* send RECOVERY event for ALL nodes that match RSCN payload */
6853 lpfc_rscn_recovery_check(vport);
6854 return lpfc_els_handle_rscn(vport);
6858 * lpfc_els_handle_rscn - Handle rscn for a vport
6859 * @vport: pointer to a host virtual N_Port data structure.
6861 * This routine handles the Registration State Configuration Notification
6862 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
6863 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
6864 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
6865 * NameServer shall be issued. If CT command to the NameServer fails to be
6866 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
6867 * RSCN activities with the @vport.
6870 * 0 - Cleaned up rscn on the @vport
6871 * 1 - Wait for plogi to name server before proceed
6874 lpfc_els_handle_rscn(struct lpfc_vport *vport)
6876 struct lpfc_nodelist *ndlp;
6877 struct lpfc_hba *phba = vport->phba;
6879 /* Ignore RSCN if the port is being torn down. */
6880 if (vport->load_flag & FC_UNLOADING) {
6881 lpfc_els_flush_rscn(vport);
6885 /* Start timer for RSCN processing */
6886 lpfc_set_disctmo(vport);
6888 /* RSCN processed */
6889 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6890 "0215 RSCN processed Data: x%x x%x x%x x%x x%x x%x\n",
6891 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
6892 vport->port_state, vport->num_disc_nodes,
6895 /* To process RSCN, first compare RSCN data with NameServer */
6896 vport->fc_ns_retry = 0;
6897 vport->num_disc_nodes = 0;
6899 ndlp = lpfc_findnode_did(vport, NameServer_DID);
6900 if (ndlp && NLP_CHK_NODE_ACT(ndlp)
6901 && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
6902 /* Good ndlp, issue CT Request to NameServer. Need to
6903 * know how many gidfts were issued. If none, then just
6904 * flush the RSCN. Otherwise, the outstanding requests
6907 if (phba->cfg_ns_query == LPFC_NS_QUERY_GID_FT) {
6908 if (lpfc_issue_gidft(vport) > 0)
6910 } else if (phba->cfg_ns_query == LPFC_NS_QUERY_GID_PT) {
6911 if (lpfc_issue_gidpt(vport) > 0)
6917 /* Nameserver login in question. Revalidate. */
6919 ndlp = lpfc_enable_node(vport, ndlp,
6920 NLP_STE_PLOGI_ISSUE);
6922 lpfc_els_flush_rscn(vport);
6925 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
6927 ndlp = lpfc_nlp_init(vport, NameServer_DID);
6929 lpfc_els_flush_rscn(vport);
6932 ndlp->nlp_prev_state = ndlp->nlp_state;
6933 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
6935 ndlp->nlp_type |= NLP_FABRIC;
6936 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
6937 /* Wait for NameServer login cmpl before we can
6943 lpfc_els_flush_rscn(vport);
6948 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
6949 * @vport: pointer to a host virtual N_Port data structure.
6950 * @cmdiocb: pointer to lpfc command iocb data structure.
6951 * @ndlp: pointer to a node-list data structure.
6953 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
6954 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
6955 * point topology. As an unsolicited FLOGI should not be received in a loop
6956 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
6957 * lpfc_check_sparm() routine is invoked to check the parameters in the
6958 * unsolicited FLOGI. If parameters validation failed, the routine
6959 * lpfc_els_rsp_reject() shall be called with reject reason code set to
6960 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
6961 * FLOGI shall be compared with the Port WWN of the @vport to determine who
6962 * will initiate PLOGI. The higher lexicographical value party shall has
6963 * higher priority (as the winning port) and will initiate PLOGI and
6964 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
6965 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
6966 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
6969 * 0 - Successfully processed the unsolicited flogi
6970 * 1 - Failed to process the unsolicited flogi
6973 lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6974 struct lpfc_nodelist *ndlp)
6976 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6977 struct lpfc_hba *phba = vport->phba;
6978 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6979 uint32_t *lp = (uint32_t *) pcmd->virt;
6980 IOCB_t *icmd = &cmdiocb->iocb;
6981 struct serv_parm *sp;
6985 uint32_t fc_flag = 0;
6986 uint32_t port_state = 0;
6989 sp = (struct serv_parm *) lp;
6991 /* FLOGI received */
6993 lpfc_set_disctmo(vport);
6995 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
6996 /* We should never receive a FLOGI in loop mode, ignore it */
6997 did = icmd->un.elsreq64.remoteID;
6999 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
7001 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7002 "0113 An FLOGI ELS command x%x was "
7003 "received from DID x%x in Loop Mode\n",
7008 (void) lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1);
7011 * If our portname is greater than the remote portname,
7012 * then we initiate Nport login.
7015 rc = memcmp(&vport->fc_portname, &sp->portName,
7016 sizeof(struct lpfc_name));
7019 if (phba->sli_rev < LPFC_SLI_REV4) {
7020 mbox = mempool_alloc(phba->mbox_mem_pool,
7024 lpfc_linkdown(phba);
7025 lpfc_init_link(phba, mbox,
7027 phba->cfg_link_speed);
7028 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
7029 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
7030 mbox->vport = vport;
7031 rc = lpfc_sli_issue_mbox(phba, mbox,
7033 lpfc_set_loopback_flag(phba);
7034 if (rc == MBX_NOT_FINISHED)
7035 mempool_free(mbox, phba->mbox_mem_pool);
7039 /* abort the flogi coming back to ourselves
7040 * due to external loopback on the port.
7042 lpfc_els_abort_flogi(phba);
7045 } else if (rc > 0) { /* greater than */
7046 spin_lock_irq(shost->host_lock);
7047 vport->fc_flag |= FC_PT2PT_PLOGI;
7048 spin_unlock_irq(shost->host_lock);
7050 /* If we have the high WWPN we can assign our own
7051 * myDID; otherwise, we have to WAIT for a PLOGI
7052 * from the remote NPort to find out what it
7055 vport->fc_myDID = PT2PT_LocalID;
7057 vport->fc_myDID = PT2PT_RemoteID;
7061 * The vport state should go to LPFC_FLOGI only
7062 * AFTER we issue a FLOGI, not receive one.
7064 spin_lock_irq(shost->host_lock);
7065 fc_flag = vport->fc_flag;
7066 port_state = vport->port_state;
7067 vport->fc_flag |= FC_PT2PT;
7068 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
7070 /* Acking an unsol FLOGI. Count 1 for link bounce
7073 vport->rcv_flogi_cnt++;
7074 spin_unlock_irq(shost->host_lock);
7075 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7076 "3311 Rcv Flogi PS x%x new PS x%x "
7077 "fc_flag x%x new fc_flag x%x\n",
7078 port_state, vport->port_state,
7079 fc_flag, vport->fc_flag);
7082 * We temporarily set fc_myDID to make it look like we are
7083 * a Fabric. This is done just so we end up with the right
7084 * did / sid on the FLOGI ACC rsp.
7086 did = vport->fc_myDID;
7087 vport->fc_myDID = Fabric_DID;
7089 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
7091 /* Defer ACC response until AFTER we issue a FLOGI */
7092 if (!(phba->hba_flag & HBA_FLOGI_ISSUED)) {
7093 phba->defer_flogi_acc_rx_id = cmdiocb->iocb.ulpContext;
7094 phba->defer_flogi_acc_ox_id =
7095 cmdiocb->iocb.unsli3.rcvsli3.ox_id;
7097 vport->fc_myDID = did;
7099 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7100 "3344 Deferring FLOGI ACC: rx_id: x%x,"
7101 " ox_id: x%x, hba_flag x%x\n",
7102 phba->defer_flogi_acc_rx_id,
7103 phba->defer_flogi_acc_ox_id, phba->hba_flag);
7105 phba->defer_flogi_acc_flag = true;
7111 lpfc_els_rsp_acc(vport, ELS_CMD_FLOGI, cmdiocb, ndlp, NULL);
7113 /* Now lets put fc_myDID back to what its supposed to be */
7114 vport->fc_myDID = did;
7120 * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
7121 * @vport: pointer to a host virtual N_Port data structure.
7122 * @cmdiocb: pointer to lpfc command iocb data structure.
7123 * @ndlp: pointer to a node-list data structure.
7125 * This routine processes Request Node Identification Data (RNID) IOCB
7126 * received as an ELS unsolicited event. Only when the RNID specified format
7127 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
7128 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
7129 * Accept (ACC) the RNID ELS command. All the other RNID formats are
7130 * rejected by invoking the lpfc_els_rsp_reject() routine.
7133 * 0 - Successfully processed rnid iocb (currently always return 0)
7136 lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7137 struct lpfc_nodelist *ndlp)
7139 struct lpfc_dmabuf *pcmd;
7144 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7145 lp = (uint32_t *) pcmd->virt;
7152 switch (rn->Format) {
7154 case RNID_TOPOLOGY_DISC:
7156 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
7159 /* Reject this request because format not supported */
7160 stat.un.b.lsRjtRsvd0 = 0;
7161 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
7162 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
7163 stat.un.b.vendorUnique = 0;
7164 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
7171 * lpfc_els_rcv_echo - Process an unsolicited echo iocb
7172 * @vport: pointer to a host virtual N_Port data structure.
7173 * @cmdiocb: pointer to lpfc command iocb data structure.
7174 * @ndlp: pointer to a node-list data structure.
7177 * 0 - Successfully processed echo iocb (currently always return 0)
7180 lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7181 struct lpfc_nodelist *ndlp)
7185 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
7187 /* skip over first word of echo command to find echo data */
7188 pcmd += sizeof(uint32_t);
7190 lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp);
7195 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
7196 * @vport: pointer to a host virtual N_Port data structure.
7197 * @cmdiocb: pointer to lpfc command iocb data structure.
7198 * @ndlp: pointer to a node-list data structure.
7200 * This routine processes a Link Incident Report Registration(LIRR) IOCB
7201 * received as an ELS unsolicited event. Currently, this function just invokes
7202 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
7205 * 0 - Successfully processed lirr iocb (currently always return 0)
7208 lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7209 struct lpfc_nodelist *ndlp)
7213 /* For now, unconditionally reject this command */
7214 stat.un.b.lsRjtRsvd0 = 0;
7215 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
7216 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
7217 stat.un.b.vendorUnique = 0;
7218 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
7223 * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb
7224 * @vport: pointer to a host virtual N_Port data structure.
7225 * @cmdiocb: pointer to lpfc command iocb data structure.
7226 * @ndlp: pointer to a node-list data structure.
7228 * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB
7229 * received as an ELS unsolicited event. A request to RRQ shall only
7230 * be accepted if the Originator Nx_Port N_Port_ID or the Responder
7231 * Nx_Port N_Port_ID of the target Exchange is the same as the
7232 * N_Port_ID of the Nx_Port that makes the request. If the RRQ is
7233 * not accepted, an LS_RJT with reason code "Unable to perform
7234 * command request" and reason code explanation "Invalid Originator
7235 * S_ID" shall be returned. For now, we just unconditionally accept
7236 * RRQ from the target.
7239 lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7240 struct lpfc_nodelist *ndlp)
7242 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
7243 if (vport->phba->sli_rev == LPFC_SLI_REV4)
7244 lpfc_els_clear_rrq(vport, cmdiocb, ndlp);
7248 * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
7249 * @phba: pointer to lpfc hba data structure.
7250 * @pmb: pointer to the driver internal queue element for mailbox command.
7252 * This routine is the completion callback function for the MBX_READ_LNK_STAT
7253 * mailbox command. This callback function is to actually send the Accept
7254 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
7255 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
7256 * mailbox command, constructs the RPS response with the link statistics
7257 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
7258 * response to the RPS.
7260 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7261 * will be incremented by 1 for holding the ndlp and the reference to ndlp
7262 * will be stored into the context1 field of the IOCB for the completion
7263 * callback function to the RPS Accept Response ELS IOCB command.
7267 lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
7271 struct RLS_RSP *rls_rsp;
7273 struct lpfc_iocbq *elsiocb;
7274 struct lpfc_nodelist *ndlp;
7281 ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
7282 rxid = (uint16_t)((unsigned long)(pmb->ctx_buf) & 0xffff);
7283 oxid = (uint16_t)(((unsigned long)(pmb->ctx_buf) >> 16) & 0xffff);
7284 pmb->ctx_buf = NULL;
7285 pmb->ctx_ndlp = NULL;
7287 if (mb->mbxStatus) {
7288 mempool_free(pmb, phba->mbox_mem_pool);
7292 cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t);
7293 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
7294 lpfc_max_els_tries, ndlp,
7295 ndlp->nlp_DID, ELS_CMD_ACC);
7297 /* Decrement the ndlp reference count from previous mbox command */
7301 mempool_free(pmb, phba->mbox_mem_pool);
7305 icmd = &elsiocb->iocb;
7306 icmd->ulpContext = rxid;
7307 icmd->unsli3.rcvsli3.ox_id = oxid;
7309 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7310 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
7311 pcmd += sizeof(uint32_t); /* Skip past command */
7312 rls_rsp = (struct RLS_RSP *)pcmd;
7314 rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
7315 rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
7316 rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
7317 rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
7318 rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
7319 rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
7320 mempool_free(pmb, phba->mbox_mem_pool);
7321 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
7322 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
7323 "2874 Xmit ELS RLS ACC response tag x%x xri x%x, "
7324 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
7325 elsiocb->iotag, elsiocb->iocb.ulpContext,
7326 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
7328 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
7329 phba->fc_stat.elsXmitACC++;
7330 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
7331 lpfc_els_free_iocb(phba, elsiocb);
7335 * lpfc_els_rcv_rls - Process an unsolicited rls iocb
7336 * @vport: pointer to a host virtual N_Port data structure.
7337 * @cmdiocb: pointer to lpfc command iocb data structure.
7338 * @ndlp: pointer to a node-list data structure.
7340 * This routine processes Read Link Status (RLS) IOCB received as an
7341 * ELS unsolicited event. It first checks the remote port state. If the
7342 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
7343 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
7344 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
7345 * for reading the HBA link statistics. It is for the callback function,
7346 * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command
7347 * to actually sending out RPL Accept (ACC) response.
7350 * 0 - Successfully processed rls iocb (currently always return 0)
7353 lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7354 struct lpfc_nodelist *ndlp)
7356 struct lpfc_hba *phba = vport->phba;
7360 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
7361 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
7362 /* reject the unsolicited RLS request and done with it */
7365 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
7367 lpfc_read_lnk_stat(phba, mbox);
7368 mbox->ctx_buf = (void *)((unsigned long)
7369 ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) |
7370 cmdiocb->iocb.ulpContext)); /* rx_id */
7371 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
7372 mbox->vport = vport;
7373 mbox->mbox_cmpl = lpfc_els_rsp_rls_acc;
7374 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
7375 != MBX_NOT_FINISHED)
7376 /* Mbox completion will send ELS Response */
7378 /* Decrement reference count used for the failed mbox
7382 mempool_free(mbox, phba->mbox_mem_pool);
7385 /* issue rejection response */
7386 stat.un.b.lsRjtRsvd0 = 0;
7387 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
7388 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
7389 stat.un.b.vendorUnique = 0;
7390 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
7395 * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb
7396 * @vport: pointer to a host virtual N_Port data structure.
7397 * @cmdiocb: pointer to lpfc command iocb data structure.
7398 * @ndlp: pointer to a node-list data structure.
7400 * This routine processes Read Timout Value (RTV) IOCB received as an
7401 * ELS unsolicited event. It first checks the remote port state. If the
7402 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
7403 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
7404 * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout
7405 * Value (RTV) unsolicited IOCB event.
7407 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7408 * will be incremented by 1 for holding the ndlp and the reference to ndlp
7409 * will be stored into the context1 field of the IOCB for the completion
7410 * callback function to the RTV Accept Response ELS IOCB command.
7413 * 0 - Successfully processed rtv iocb (currently always return 0)
7416 lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7417 struct lpfc_nodelist *ndlp)
7419 struct lpfc_hba *phba = vport->phba;
7421 struct RTV_RSP *rtv_rsp;
7423 struct lpfc_iocbq *elsiocb;
7427 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
7428 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
7429 /* reject the unsolicited RTV request and done with it */
7432 cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t);
7433 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
7434 lpfc_max_els_tries, ndlp,
7435 ndlp->nlp_DID, ELS_CMD_ACC);
7440 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7441 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
7442 pcmd += sizeof(uint32_t); /* Skip past command */
7444 /* use the command's xri in the response */
7445 elsiocb->iocb.ulpContext = cmdiocb->iocb.ulpContext; /* Xri / rx_id */
7446 elsiocb->iocb.unsli3.rcvsli3.ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id;
7448 rtv_rsp = (struct RTV_RSP *)pcmd;
7450 /* populate RTV payload */
7451 rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000); /* report msecs */
7452 rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov);
7453 bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0);
7454 bf_set(qtov_rttov, rtv_rsp, 0); /* Field is for FC ONLY */
7455 rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov);
7457 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
7458 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
7459 "2875 Xmit ELS RTV ACC response tag x%x xri x%x, "
7460 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, "
7461 "Data: x%x x%x x%x\n",
7462 elsiocb->iotag, elsiocb->iocb.ulpContext,
7463 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
7465 rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov);
7466 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
7467 phba->fc_stat.elsXmitACC++;
7468 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
7469 lpfc_els_free_iocb(phba, elsiocb);
7473 /* issue rejection response */
7474 stat.un.b.lsRjtRsvd0 = 0;
7475 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
7476 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
7477 stat.un.b.vendorUnique = 0;
7478 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
7482 /* lpfc_issue_els_rrq - Process an unsolicited rrq iocb
7483 * @vport: pointer to a host virtual N_Port data structure.
7484 * @ndlp: pointer to a node-list data structure.
7485 * @did: DID of the target.
7486 * @rrq: Pointer to the rrq struct.
7488 * Build a ELS RRQ command and send it to the target. If the issue_iocb is
7489 * Successful the the completion handler will clear the RRQ.
7492 * 0 - Successfully sent rrq els iocb.
7493 * 1 - Failed to send rrq els iocb.
7496 lpfc_issue_els_rrq(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
7497 uint32_t did, struct lpfc_node_rrq *rrq)
7499 struct lpfc_hba *phba = vport->phba;
7500 struct RRQ *els_rrq;
7501 struct lpfc_iocbq *elsiocb;
7507 if (ndlp != rrq->ndlp)
7509 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
7512 /* If ndlp is not NULL, we will bump the reference count on it */
7513 cmdsize = (sizeof(uint32_t) + sizeof(struct RRQ));
7514 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, did,
7519 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7521 /* For RRQ request, remainder of payload is Exchange IDs */
7522 *((uint32_t *) (pcmd)) = ELS_CMD_RRQ;
7523 pcmd += sizeof(uint32_t);
7524 els_rrq = (struct RRQ *) pcmd;
7526 bf_set(rrq_oxid, els_rrq, phba->sli4_hba.xri_ids[rrq->xritag]);
7527 bf_set(rrq_rxid, els_rrq, rrq->rxid);
7528 bf_set(rrq_did, els_rrq, vport->fc_myDID);
7529 els_rrq->rrq = cpu_to_be32(els_rrq->rrq);
7530 els_rrq->rrq_exchg = cpu_to_be32(els_rrq->rrq_exchg);
7533 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7534 "Issue RRQ: did:x%x",
7535 did, rrq->xritag, rrq->rxid);
7536 elsiocb->context_un.rrq = rrq;
7537 elsiocb->iocb_cmpl = lpfc_cmpl_els_rrq;
7538 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
7540 if (ret == IOCB_ERROR) {
7541 lpfc_els_free_iocb(phba, elsiocb);
7548 * lpfc_send_rrq - Sends ELS RRQ if needed.
7549 * @phba: pointer to lpfc hba data structure.
7550 * @rrq: pointer to the active rrq.
7552 * This routine will call the lpfc_issue_els_rrq if the rrq is
7553 * still active for the xri. If this function returns a failure then
7554 * the caller needs to clean up the RRQ by calling lpfc_clr_active_rrq.
7556 * Returns 0 Success.
7560 lpfc_send_rrq(struct lpfc_hba *phba, struct lpfc_node_rrq *rrq)
7562 struct lpfc_nodelist *ndlp = lpfc_findnode_did(rrq->vport,
7567 if (lpfc_test_rrq_active(phba, ndlp, rrq->xritag))
7568 return lpfc_issue_els_rrq(rrq->vport, ndlp,
7575 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
7576 * @vport: pointer to a host virtual N_Port data structure.
7577 * @cmdsize: size of the ELS command.
7578 * @oldiocb: pointer to the original lpfc command iocb data structure.
7579 * @ndlp: pointer to a node-list data structure.
7581 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
7582 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
7584 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7585 * will be incremented by 1 for holding the ndlp and the reference to ndlp
7586 * will be stored into the context1 field of the IOCB for the completion
7587 * callback function to the RPL Accept Response ELS command.
7590 * 0 - Successfully issued ACC RPL ELS command
7591 * 1 - Failed to issue ACC RPL ELS command
7594 lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
7595 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
7597 struct lpfc_hba *phba = vport->phba;
7598 IOCB_t *icmd, *oldcmd;
7600 struct lpfc_iocbq *elsiocb;
7603 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
7604 ndlp->nlp_DID, ELS_CMD_ACC);
7609 icmd = &elsiocb->iocb;
7610 oldcmd = &oldiocb->iocb;
7611 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
7612 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
7614 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7615 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
7616 pcmd += sizeof(uint16_t);
7617 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
7618 pcmd += sizeof(uint16_t);
7620 /* Setup the RPL ACC payload */
7621 rpl_rsp.listLen = be32_to_cpu(1);
7623 rpl_rsp.port_num_blk.portNum = 0;
7624 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
7625 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
7626 sizeof(struct lpfc_name));
7627 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
7628 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
7629 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7630 "0120 Xmit ELS RPL ACC response tag x%x "
7631 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
7633 elsiocb->iotag, elsiocb->iocb.ulpContext,
7634 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
7636 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
7637 phba->fc_stat.elsXmitACC++;
7638 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
7640 lpfc_els_free_iocb(phba, elsiocb);
7647 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
7648 * @vport: pointer to a host virtual N_Port data structure.
7649 * @cmdiocb: pointer to lpfc command iocb data structure.
7650 * @ndlp: pointer to a node-list data structure.
7652 * This routine processes Read Port List (RPL) IOCB received as an ELS
7653 * unsolicited event. It first checks the remote port state. If the remote
7654 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
7655 * invokes the lpfc_els_rsp_reject() routine to send reject response.
7656 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
7657 * to accept the RPL.
7660 * 0 - Successfully processed rpl iocb (currently always return 0)
7663 lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7664 struct lpfc_nodelist *ndlp)
7666 struct lpfc_dmabuf *pcmd;
7673 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
7674 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
7675 /* issue rejection response */
7676 stat.un.b.lsRjtRsvd0 = 0;
7677 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
7678 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
7679 stat.un.b.vendorUnique = 0;
7680 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
7682 /* rejected the unsolicited RPL request and done with it */
7686 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7687 lp = (uint32_t *) pcmd->virt;
7688 rpl = (RPL *) (lp + 1);
7689 maxsize = be32_to_cpu(rpl->maxsize);
7691 /* We support only one port */
7692 if ((rpl->index == 0) &&
7694 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
7695 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
7697 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
7699 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
7705 * lpfc_els_rcv_farp - Process an unsolicited farp request els command
7706 * @vport: pointer to a virtual N_Port data structure.
7707 * @cmdiocb: pointer to lpfc command iocb data structure.
7708 * @ndlp: pointer to a node-list data structure.
7710 * This routine processes Fibre Channel Address Resolution Protocol
7711 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
7712 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
7713 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
7714 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
7715 * remote PortName is compared against the FC PortName stored in the @vport
7716 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
7717 * compared against the FC NodeName stored in the @vport data structure.
7718 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
7719 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
7720 * invoked to send out FARP Response to the remote node. Before sending the
7721 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
7722 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
7723 * routine is invoked to log into the remote port first.
7726 * 0 - Either the FARP Match Mode not supported or successfully processed
7729 lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7730 struct lpfc_nodelist *ndlp)
7732 struct lpfc_dmabuf *pcmd;
7738 icmd = &cmdiocb->iocb;
7739 did = icmd->un.elsreq64.remoteID;
7740 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7741 lp = (uint32_t *) pcmd->virt;
7745 /* FARP-REQ received from DID <did> */
7746 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7747 "0601 FARP-REQ received from DID x%x\n", did);
7748 /* We will only support match on WWPN or WWNN */
7749 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
7754 /* If this FARP command is searching for my portname */
7755 if (fp->Mflags & FARP_MATCH_PORT) {
7756 if (memcmp(&fp->RportName, &vport->fc_portname,
7757 sizeof(struct lpfc_name)) == 0)
7761 /* If this FARP command is searching for my nodename */
7762 if (fp->Mflags & FARP_MATCH_NODE) {
7763 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
7764 sizeof(struct lpfc_name)) == 0)
7769 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
7770 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
7771 /* Log back into the node before sending the FARP. */
7772 if (fp->Rflags & FARP_REQUEST_PLOGI) {
7773 ndlp->nlp_prev_state = ndlp->nlp_state;
7774 lpfc_nlp_set_state(vport, ndlp,
7775 NLP_STE_PLOGI_ISSUE);
7776 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
7779 /* Send a FARP response to that node */
7780 if (fp->Rflags & FARP_REQUEST_FARPR)
7781 lpfc_issue_els_farpr(vport, did, 0);
7788 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
7789 * @vport: pointer to a host virtual N_Port data structure.
7790 * @cmdiocb: pointer to lpfc command iocb data structure.
7791 * @ndlp: pointer to a node-list data structure.
7793 * This routine processes Fibre Channel Address Resolution Protocol
7794 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
7795 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
7796 * the FARP response request.
7799 * 0 - Successfully processed FARPR IOCB (currently always return 0)
7802 lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7803 struct lpfc_nodelist *ndlp)
7805 struct lpfc_dmabuf *pcmd;
7810 icmd = &cmdiocb->iocb;
7811 did = icmd->un.elsreq64.remoteID;
7812 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7813 lp = (uint32_t *) pcmd->virt;
7816 /* FARP-RSP received from DID <did> */
7817 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7818 "0600 FARP-RSP received from DID x%x\n", did);
7819 /* ACCEPT the Farp resp request */
7820 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
7826 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
7827 * @vport: pointer to a host virtual N_Port data structure.
7828 * @cmdiocb: pointer to lpfc command iocb data structure.
7829 * @fan_ndlp: pointer to a node-list data structure.
7831 * This routine processes a Fabric Address Notification (FAN) IOCB
7832 * command received as an ELS unsolicited event. The FAN ELS command will
7833 * only be processed on a physical port (i.e., the @vport represents the
7834 * physical port). The fabric NodeName and PortName from the FAN IOCB are
7835 * compared against those in the phba data structure. If any of those is
7836 * different, the lpfc_initial_flogi() routine is invoked to initialize
7837 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
7838 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
7839 * is invoked to register login to the fabric.
7842 * 0 - Successfully processed fan iocb (currently always return 0).
7845 lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7846 struct lpfc_nodelist *fan_ndlp)
7848 struct lpfc_hba *phba = vport->phba;
7852 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
7853 lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
7855 /* FAN received; Fan does not have a reply sequence */
7856 if ((vport == phba->pport) &&
7857 (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
7858 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
7859 sizeof(struct lpfc_name))) ||
7860 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
7861 sizeof(struct lpfc_name)))) {
7862 /* This port has switched fabrics. FLOGI is required */
7863 lpfc_issue_init_vfi(vport);
7865 /* FAN verified - skip FLOGI */
7866 vport->fc_myDID = vport->fc_prevDID;
7867 if (phba->sli_rev < LPFC_SLI_REV4)
7868 lpfc_issue_fabric_reglogin(vport);
7870 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7871 "3138 Need register VFI: (x%x/%x)\n",
7872 vport->fc_prevDID, vport->fc_myDID);
7873 lpfc_issue_reg_vfi(vport);
7881 * lpfc_els_timeout - Handler funciton to the els timer
7882 * @ptr: holder for the timer function associated data.
7884 * This routine is invoked by the ELS timer after timeout. It posts the ELS
7885 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
7886 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
7887 * up the worker thread. It is for the worker thread to invoke the routine
7888 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
7891 lpfc_els_timeout(struct timer_list *t)
7893 struct lpfc_vport *vport = from_timer(vport, t, els_tmofunc);
7894 struct lpfc_hba *phba = vport->phba;
7895 uint32_t tmo_posted;
7896 unsigned long iflag;
7898 spin_lock_irqsave(&vport->work_port_lock, iflag);
7899 tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
7900 if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING)))
7901 vport->work_port_events |= WORKER_ELS_TMO;
7902 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
7904 if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING)))
7905 lpfc_worker_wake_up(phba);
7911 * lpfc_els_timeout_handler - Process an els timeout event
7912 * @vport: pointer to a virtual N_Port data structure.
7914 * This routine is the actual handler function that processes an ELS timeout
7915 * event. It walks the ELS ring to get and abort all the IOCBs (except the
7916 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
7917 * invoking the lpfc_sli_issue_abort_iotag() routine.
7920 lpfc_els_timeout_handler(struct lpfc_vport *vport)
7922 struct lpfc_hba *phba = vport->phba;
7923 struct lpfc_sli_ring *pring;
7924 struct lpfc_iocbq *tmp_iocb, *piocb;
7926 struct lpfc_dmabuf *pcmd;
7927 uint32_t els_command = 0;
7929 uint32_t remote_ID = 0xffffffff;
7930 LIST_HEAD(abort_list);
7933 timeout = (uint32_t)(phba->fc_ratov << 1);
7935 pring = lpfc_phba_elsring(phba);
7936 if (unlikely(!pring))
7939 if ((phba->pport->load_flag & FC_UNLOADING))
7941 spin_lock_irq(&phba->hbalock);
7942 if (phba->sli_rev == LPFC_SLI_REV4)
7943 spin_lock(&pring->ring_lock);
7945 if ((phba->pport->load_flag & FC_UNLOADING)) {
7946 if (phba->sli_rev == LPFC_SLI_REV4)
7947 spin_unlock(&pring->ring_lock);
7948 spin_unlock_irq(&phba->hbalock);
7952 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
7955 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
7956 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
7957 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
7960 if (piocb->vport != vport)
7963 pcmd = (struct lpfc_dmabuf *) piocb->context2;
7965 els_command = *(uint32_t *) (pcmd->virt);
7967 if (els_command == ELS_CMD_FARP ||
7968 els_command == ELS_CMD_FARPR ||
7969 els_command == ELS_CMD_FDISC)
7972 if (piocb->drvrTimeout > 0) {
7973 if (piocb->drvrTimeout >= timeout)
7974 piocb->drvrTimeout -= timeout;
7976 piocb->drvrTimeout = 0;
7980 remote_ID = 0xffffffff;
7981 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
7982 remote_ID = cmd->un.elsreq64.remoteID;
7984 struct lpfc_nodelist *ndlp;
7985 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
7986 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
7987 remote_ID = ndlp->nlp_DID;
7989 list_add_tail(&piocb->dlist, &abort_list);
7991 if (phba->sli_rev == LPFC_SLI_REV4)
7992 spin_unlock(&pring->ring_lock);
7993 spin_unlock_irq(&phba->hbalock);
7995 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
7997 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7998 "0127 ELS timeout Data: x%x x%x x%x "
7999 "x%x\n", els_command,
8000 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
8001 spin_lock_irq(&phba->hbalock);
8002 list_del_init(&piocb->dlist);
8003 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
8004 spin_unlock_irq(&phba->hbalock);
8007 if (!list_empty(&pring->txcmplq))
8008 if (!(phba->pport->load_flag & FC_UNLOADING))
8009 mod_timer(&vport->els_tmofunc,
8010 jiffies + msecs_to_jiffies(1000 * timeout));
8014 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
8015 * @vport: pointer to a host virtual N_Port data structure.
8017 * This routine is used to clean up all the outstanding ELS commands on a
8018 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
8019 * routine. After that, it walks the ELS transmit queue to remove all the
8020 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
8021 * the IOCBs with a non-NULL completion callback function, the callback
8022 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
8023 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
8024 * callback function, the IOCB will simply be released. Finally, it walks
8025 * the ELS transmit completion queue to issue an abort IOCB to any transmit
8026 * completion queue IOCB that is associated with the @vport and is not
8027 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
8028 * part of the discovery state machine) out to HBA by invoking the
8029 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
8030 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
8031 * the IOCBs are aborted when this function returns.
8034 lpfc_els_flush_cmd(struct lpfc_vport *vport)
8036 LIST_HEAD(abort_list);
8037 struct lpfc_hba *phba = vport->phba;
8038 struct lpfc_sli_ring *pring;
8039 struct lpfc_iocbq *tmp_iocb, *piocb;
8041 unsigned long iflags = 0;
8043 lpfc_fabric_abort_vport(vport);
8046 * For SLI3, only the hbalock is required. But SLI4 needs to coordinate
8047 * with the ring insert operation. Because lpfc_sli_issue_abort_iotag
8048 * ultimately grabs the ring_lock, the driver must splice the list into
8049 * a working list and release the locks before calling the abort.
8051 spin_lock_irqsave(&phba->hbalock, iflags);
8052 pring = lpfc_phba_elsring(phba);
8054 /* Bail out if we've no ELS wq, like in PCI error recovery case. */
8055 if (unlikely(!pring)) {
8056 spin_unlock_irqrestore(&phba->hbalock, iflags);
8060 if (phba->sli_rev == LPFC_SLI_REV4)
8061 spin_lock(&pring->ring_lock);
8063 /* First we need to issue aborts to outstanding cmds on txcmpl */
8064 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
8065 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
8068 if (piocb->vport != vport)
8071 if (piocb->iocb_flag & LPFC_DRIVER_ABORTED)
8074 /* On the ELS ring we can have ELS_REQUESTs or
8075 * GEN_REQUESTs waiting for a response.
8078 if (cmd->ulpCommand == CMD_ELS_REQUEST64_CR) {
8079 list_add_tail(&piocb->dlist, &abort_list);
8081 /* If the link is down when flushing ELS commands
8082 * the firmware will not complete them till after
8083 * the link comes back up. This may confuse
8084 * discovery for the new link up, so we need to
8085 * change the compl routine to just clean up the iocb
8086 * and avoid any retry logic.
8088 if (phba->link_state == LPFC_LINK_DOWN)
8089 piocb->iocb_cmpl = lpfc_cmpl_els_link_down;
8091 if (cmd->ulpCommand == CMD_GEN_REQUEST64_CR)
8092 list_add_tail(&piocb->dlist, &abort_list);
8095 if (phba->sli_rev == LPFC_SLI_REV4)
8096 spin_unlock(&pring->ring_lock);
8097 spin_unlock_irqrestore(&phba->hbalock, iflags);
8099 /* Abort each txcmpl iocb on aborted list and remove the dlist links. */
8100 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
8101 spin_lock_irqsave(&phba->hbalock, iflags);
8102 list_del_init(&piocb->dlist);
8103 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
8104 spin_unlock_irqrestore(&phba->hbalock, iflags);
8106 if (!list_empty(&abort_list))
8107 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8108 "3387 abort list for txq not empty\n");
8109 INIT_LIST_HEAD(&abort_list);
8111 spin_lock_irqsave(&phba->hbalock, iflags);
8112 if (phba->sli_rev == LPFC_SLI_REV4)
8113 spin_lock(&pring->ring_lock);
8115 /* No need to abort the txq list,
8116 * just queue them up for lpfc_sli_cancel_iocbs
8118 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
8121 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
8125 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
8126 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
8127 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
8128 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
8129 cmd->ulpCommand == CMD_ABORT_XRI_CN)
8132 if (piocb->vport != vport)
8135 list_del_init(&piocb->list);
8136 list_add_tail(&piocb->list, &abort_list);
8139 /* The same holds true for any FLOGI/FDISC on the fabric_iocb_list */
8140 if (vport == phba->pport) {
8141 list_for_each_entry_safe(piocb, tmp_iocb,
8142 &phba->fabric_iocb_list, list) {
8144 list_del_init(&piocb->list);
8145 list_add_tail(&piocb->list, &abort_list);
8149 if (phba->sli_rev == LPFC_SLI_REV4)
8150 spin_unlock(&pring->ring_lock);
8151 spin_unlock_irqrestore(&phba->hbalock, iflags);
8153 /* Cancel all the IOCBs from the completions list */
8154 lpfc_sli_cancel_iocbs(phba, &abort_list,
8155 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
8161 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
8162 * @phba: pointer to lpfc hba data structure.
8164 * This routine is used to clean up all the outstanding ELS commands on a
8165 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
8166 * routine. After that, it walks the ELS transmit queue to remove all the
8167 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
8168 * the IOCBs with the completion callback function associated, the callback
8169 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
8170 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
8171 * callback function associated, the IOCB will simply be released. Finally,
8172 * it walks the ELS transmit completion queue to issue an abort IOCB to any
8173 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
8174 * management plane IOCBs that are not part of the discovery state machine)
8175 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
8178 lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
8180 struct lpfc_vport *vport;
8182 spin_lock_irq(&phba->port_list_lock);
8183 list_for_each_entry(vport, &phba->port_list, listentry)
8184 lpfc_els_flush_cmd(vport);
8185 spin_unlock_irq(&phba->port_list_lock);
8191 * lpfc_send_els_failure_event - Posts an ELS command failure event
8192 * @phba: Pointer to hba context object.
8193 * @cmdiocbp: Pointer to command iocb which reported error.
8194 * @rspiocbp: Pointer to response iocb which reported error.
8196 * This function sends an event when there is an ELS command
8200 lpfc_send_els_failure_event(struct lpfc_hba *phba,
8201 struct lpfc_iocbq *cmdiocbp,
8202 struct lpfc_iocbq *rspiocbp)
8204 struct lpfc_vport *vport = cmdiocbp->vport;
8205 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8206 struct lpfc_lsrjt_event lsrjt_event;
8207 struct lpfc_fabric_event_header fabric_event;
8209 struct lpfc_nodelist *ndlp;
8212 ndlp = cmdiocbp->context1;
8213 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
8216 if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) {
8217 lsrjt_event.header.event_type = FC_REG_ELS_EVENT;
8218 lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV;
8219 memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname,
8220 sizeof(struct lpfc_name));
8221 memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename,
8222 sizeof(struct lpfc_name));
8223 pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
8224 cmdiocbp->context2)->virt);
8225 lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0;
8226 stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]);
8227 lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode;
8228 lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp;
8229 fc_host_post_vendor_event(shost,
8230 fc_get_event_number(),
8231 sizeof(lsrjt_event),
8232 (char *)&lsrjt_event,
8236 if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) ||
8237 (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) {
8238 fabric_event.event_type = FC_REG_FABRIC_EVENT;
8239 if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY)
8240 fabric_event.subcategory = LPFC_EVENT_PORT_BUSY;
8242 fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY;
8243 memcpy(fabric_event.wwpn, &ndlp->nlp_portname,
8244 sizeof(struct lpfc_name));
8245 memcpy(fabric_event.wwnn, &ndlp->nlp_nodename,
8246 sizeof(struct lpfc_name));
8247 fc_host_post_vendor_event(shost,
8248 fc_get_event_number(),
8249 sizeof(fabric_event),
8250 (char *)&fabric_event,
8258 * lpfc_send_els_event - Posts unsolicited els event
8259 * @vport: Pointer to vport object.
8260 * @ndlp: Pointer FC node object.
8261 * @cmd: ELS command code.
8263 * This function posts an event when there is an incoming
8264 * unsolicited ELS command.
8267 lpfc_send_els_event(struct lpfc_vport *vport,
8268 struct lpfc_nodelist *ndlp,
8271 struct lpfc_els_event_header *els_data = NULL;
8272 struct lpfc_logo_event *logo_data = NULL;
8273 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8275 if (*payload == ELS_CMD_LOGO) {
8276 logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL);
8278 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8279 "0148 Failed to allocate memory "
8280 "for LOGO event\n");
8283 els_data = &logo_data->header;
8285 els_data = kmalloc(sizeof(struct lpfc_els_event_header),
8288 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8289 "0149 Failed to allocate memory "
8294 els_data->event_type = FC_REG_ELS_EVENT;
8297 els_data->subcategory = LPFC_EVENT_PLOGI_RCV;
8300 els_data->subcategory = LPFC_EVENT_PRLO_RCV;
8303 els_data->subcategory = LPFC_EVENT_ADISC_RCV;
8306 els_data->subcategory = LPFC_EVENT_LOGO_RCV;
8307 /* Copy the WWPN in the LOGO payload */
8308 memcpy(logo_data->logo_wwpn, &payload[2],
8309 sizeof(struct lpfc_name));
8315 memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name));
8316 memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name));
8317 if (*payload == ELS_CMD_LOGO) {
8318 fc_host_post_vendor_event(shost,
8319 fc_get_event_number(),
8320 sizeof(struct lpfc_logo_event),
8325 fc_host_post_vendor_event(shost,
8326 fc_get_event_number(),
8327 sizeof(struct lpfc_els_event_header),
8337 DECLARE_ENUM2STR_LOOKUP(lpfc_get_tlv_dtag_nm, fc_ls_tlv_dtag,
8338 FC_LS_TLV_DTAG_INIT);
8340 DECLARE_ENUM2STR_LOOKUP(lpfc_get_fpin_li_event_nm, fc_fpin_li_event_types,
8341 FC_FPIN_LI_EVT_TYPES_INIT);
8344 * lpfc_els_rcv_fpin_li - Process an FPIN Link Integrity Event.
8345 * @vport: Pointer to vport object.
8346 * @lnk_not: Pointer to the Link Integrity Notification Descriptor.
8348 * This function processes a link integrity FPIN event by
8352 lpfc_els_rcv_fpin_li(struct lpfc_vport *vport, struct fc_tlv_desc *tlv)
8354 struct fc_fn_li_desc *li = (struct fc_fn_li_desc *)tlv;
8355 const char *li_evt_str;
8358 li_evt = be16_to_cpu(li->event_type);
8359 li_evt_str = lpfc_get_fpin_li_event_nm(li_evt);
8361 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
8362 "4680 FPIN Link Integrity %s (x%x) "
8363 "Detecting PN x%016llx Attached PN x%016llx "
8364 "Duration %d mSecs Count %d Port Cnt %d\n",
8366 be64_to_cpu(li->detecting_wwpn),
8367 be64_to_cpu(li->attached_wwpn),
8368 be32_to_cpu(li->event_threshold),
8369 be32_to_cpu(li->event_count),
8370 be32_to_cpu(li->pname_count));
8374 lpfc_els_rcv_fpin(struct lpfc_vport *vport, struct fc_els_fpin *fpin,
8377 struct fc_tlv_desc *tlv;
8378 const char *dtag_nm;
8379 uint32_t desc_cnt = 0, bytes_remain;
8382 /* FPINs handled only if we are in the right discovery state */
8383 if (vport->port_state < LPFC_DISC_AUTH)
8386 /* make sure there is the full fpin header */
8387 if (fpin_length < sizeof(struct fc_els_fpin))
8390 tlv = (struct fc_tlv_desc *)&fpin->fpin_desc[0];
8391 bytes_remain = fpin_length - offsetof(struct fc_els_fpin, fpin_desc);
8392 bytes_remain = min_t(u32, bytes_remain, be32_to_cpu(fpin->desc_len));
8394 /* process each descriptor */
8395 while (bytes_remain >= FC_TLV_DESC_HDR_SZ &&
8396 bytes_remain >= FC_TLV_DESC_SZ_FROM_LENGTH(tlv)) {
8398 dtag = be32_to_cpu(tlv->desc_tag);
8400 case ELS_DTAG_LNK_INTEGRITY:
8401 lpfc_els_rcv_fpin_li(vport, tlv);
8404 dtag_nm = lpfc_get_tlv_dtag_nm(dtag);
8405 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8406 "4678 skipped FPIN descriptor[%d]: "
8408 desc_cnt, dtag, dtag_nm);
8413 bytes_remain -= FC_TLV_DESC_SZ_FROM_LENGTH(tlv);
8414 tlv = fc_tlv_next_desc(tlv);
8417 fc_host_fpin_rcv(lpfc_shost_from_vport(vport), fpin_length,
8422 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
8423 * @phba: pointer to lpfc hba data structure.
8424 * @pring: pointer to a SLI ring.
8425 * @vport: pointer to a host virtual N_Port data structure.
8426 * @elsiocb: pointer to lpfc els command iocb data structure.
8428 * This routine is used for processing the IOCB associated with a unsolicited
8429 * event. It first determines whether there is an existing ndlp that matches
8430 * the DID from the unsolicited IOCB. If not, it will create a new one with
8431 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
8432 * IOCB is then used to invoke the proper routine and to set up proper state
8433 * of the discovery state machine.
8436 lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
8437 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
8439 struct Scsi_Host *shost;
8440 struct lpfc_nodelist *ndlp;
8442 uint32_t *payload, payload_len;
8443 uint32_t cmd, did, newnode;
8444 uint8_t rjt_exp, rjt_err = 0, init_link = 0;
8445 IOCB_t *icmd = &elsiocb->iocb;
8448 if (!vport || !(elsiocb->context2))
8452 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
8453 payload_len = elsiocb->iocb.unsli3.rcvsli3.acc_len;
8455 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
8456 lpfc_post_buffer(phba, pring, 1);
8458 did = icmd->un.rcvels.remoteID;
8459 if (icmd->ulpStatus) {
8460 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8461 "RCV Unsol ELS: status:x%x/x%x did:x%x",
8462 icmd->ulpStatus, icmd->un.ulpWord[4], did);
8466 /* Check to see if link went down during discovery */
8467 if (lpfc_els_chk_latt(vport))
8470 /* Ignore traffic received during vport shutdown. */
8471 if (vport->load_flag & FC_UNLOADING)
8474 /* If NPort discovery is delayed drop incoming ELS */
8475 if ((vport->fc_flag & FC_DISC_DELAYED) &&
8476 (cmd != ELS_CMD_PLOGI))
8479 ndlp = lpfc_findnode_did(vport, did);
8481 /* Cannot find existing Fabric ndlp, so allocate a new one */
8482 ndlp = lpfc_nlp_init(vport, did);
8485 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
8487 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
8488 ndlp->nlp_type |= NLP_FABRIC;
8489 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
8490 ndlp = lpfc_enable_node(vport, ndlp,
8491 NLP_STE_UNUSED_NODE);
8494 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
8496 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
8497 ndlp->nlp_type |= NLP_FABRIC;
8498 } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
8499 /* This is similar to the new node path */
8500 ndlp = lpfc_nlp_get(ndlp);
8503 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
8507 phba->fc_stat.elsRcvFrame++;
8510 * Do not process any unsolicited ELS commands
8511 * if the ndlp is in DEV_LOSS
8513 shost = lpfc_shost_from_vport(vport);
8514 spin_lock_irq(shost->host_lock);
8515 if (ndlp->nlp_flag & NLP_IN_DEV_LOSS) {
8516 spin_unlock_irq(shost->host_lock);
8519 spin_unlock_irq(shost->host_lock);
8521 elsiocb->context1 = lpfc_nlp_get(ndlp);
8522 elsiocb->vport = vport;
8524 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
8525 cmd &= ELS_CMD_MASK;
8527 /* ELS command <elsCmd> received from NPORT <did> */
8528 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
8529 "0112 ELS command x%x received from NPORT x%x "
8530 "Data: x%x x%x x%x x%x\n",
8531 cmd, did, vport->port_state, vport->fc_flag,
8532 vport->fc_myDID, vport->fc_prevDID);
8534 /* reject till our FLOGI completes or PLOGI assigned DID via PT2PT */
8535 if ((vport->port_state < LPFC_FABRIC_CFG_LINK) &&
8536 (cmd != ELS_CMD_FLOGI) &&
8537 !((cmd == ELS_CMD_PLOGI) && (vport->fc_flag & FC_PT2PT))) {
8538 rjt_err = LSRJT_LOGICAL_BSY;
8539 rjt_exp = LSEXP_NOTHING_MORE;
8545 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8546 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
8547 did, vport->port_state, ndlp->nlp_flag);
8549 phba->fc_stat.elsRcvPLOGI++;
8550 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
8551 if (phba->sli_rev == LPFC_SLI_REV4 &&
8552 (phba->pport->fc_flag & FC_PT2PT)) {
8553 vport->fc_prevDID = vport->fc_myDID;
8554 /* Our DID needs to be updated before registering
8555 * the vfi. This is done in lpfc_rcv_plogi but
8556 * that is called after the reg_vfi.
8558 vport->fc_myDID = elsiocb->iocb.un.rcvels.parmRo;
8559 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
8560 "3312 Remote port assigned DID x%x "
8561 "%x\n", vport->fc_myDID,
8565 lpfc_send_els_event(vport, ndlp, payload);
8567 /* If Nport discovery is delayed, reject PLOGIs */
8568 if (vport->fc_flag & FC_DISC_DELAYED) {
8569 rjt_err = LSRJT_UNABLE_TPC;
8570 rjt_exp = LSEXP_NOTHING_MORE;
8574 if (vport->port_state < LPFC_DISC_AUTH) {
8575 if (!(phba->pport->fc_flag & FC_PT2PT) ||
8576 (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
8577 rjt_err = LSRJT_UNABLE_TPC;
8578 rjt_exp = LSEXP_NOTHING_MORE;
8583 spin_lock_irq(shost->host_lock);
8584 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
8585 spin_unlock_irq(shost->host_lock);
8587 lpfc_disc_state_machine(vport, ndlp, elsiocb,
8592 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8593 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
8594 did, vport->port_state, ndlp->nlp_flag);
8596 phba->fc_stat.elsRcvFLOGI++;
8598 /* If the driver believes fabric discovery is done and is ready,
8599 * bounce the link. There is some descrepancy.
8601 if (vport->port_state >= LPFC_LOCAL_CFG_LINK &&
8602 vport->fc_flag & FC_PT2PT &&
8603 vport->rcv_flogi_cnt >= 1) {
8604 rjt_err = LSRJT_LOGICAL_BSY;
8605 rjt_exp = LSEXP_NOTHING_MORE;
8610 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
8615 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8616 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
8617 did, vport->port_state, ndlp->nlp_flag);
8619 phba->fc_stat.elsRcvLOGO++;
8620 lpfc_send_els_event(vport, ndlp, payload);
8621 if (vport->port_state < LPFC_DISC_AUTH) {
8622 rjt_err = LSRJT_UNABLE_TPC;
8623 rjt_exp = LSEXP_NOTHING_MORE;
8626 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
8629 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8630 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
8631 did, vport->port_state, ndlp->nlp_flag);
8633 phba->fc_stat.elsRcvPRLO++;
8634 lpfc_send_els_event(vport, ndlp, payload);
8635 if (vport->port_state < LPFC_DISC_AUTH) {
8636 rjt_err = LSRJT_UNABLE_TPC;
8637 rjt_exp = LSEXP_NOTHING_MORE;
8640 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
8643 phba->fc_stat.elsRcvLCB++;
8644 lpfc_els_rcv_lcb(vport, elsiocb, ndlp);
8647 phba->fc_stat.elsRcvRDP++;
8648 lpfc_els_rcv_rdp(vport, elsiocb, ndlp);
8651 phba->fc_stat.elsRcvRSCN++;
8652 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
8657 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8658 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
8659 did, vport->port_state, ndlp->nlp_flag);
8661 lpfc_send_els_event(vport, ndlp, payload);
8662 phba->fc_stat.elsRcvADISC++;
8663 if (vport->port_state < LPFC_DISC_AUTH) {
8664 rjt_err = LSRJT_UNABLE_TPC;
8665 rjt_exp = LSEXP_NOTHING_MORE;
8668 lpfc_disc_state_machine(vport, ndlp, elsiocb,
8672 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8673 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
8674 did, vport->port_state, ndlp->nlp_flag);
8676 phba->fc_stat.elsRcvPDISC++;
8677 if (vport->port_state < LPFC_DISC_AUTH) {
8678 rjt_err = LSRJT_UNABLE_TPC;
8679 rjt_exp = LSEXP_NOTHING_MORE;
8682 lpfc_disc_state_machine(vport, ndlp, elsiocb,
8686 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8687 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
8688 did, vport->port_state, ndlp->nlp_flag);
8690 phba->fc_stat.elsRcvFARPR++;
8691 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
8694 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8695 "RCV FARP: did:x%x/ste:x%x flg:x%x",
8696 did, vport->port_state, ndlp->nlp_flag);
8698 phba->fc_stat.elsRcvFARP++;
8699 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
8702 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8703 "RCV FAN: did:x%x/ste:x%x flg:x%x",
8704 did, vport->port_state, ndlp->nlp_flag);
8706 phba->fc_stat.elsRcvFAN++;
8707 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
8710 case ELS_CMD_NVMEPRLI:
8711 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8712 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
8713 did, vport->port_state, ndlp->nlp_flag);
8715 phba->fc_stat.elsRcvPRLI++;
8716 if ((vport->port_state < LPFC_DISC_AUTH) &&
8717 (vport->fc_flag & FC_FABRIC)) {
8718 rjt_err = LSRJT_UNABLE_TPC;
8719 rjt_exp = LSEXP_NOTHING_MORE;
8722 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
8725 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8726 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
8727 did, vport->port_state, ndlp->nlp_flag);
8729 phba->fc_stat.elsRcvLIRR++;
8730 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
8735 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8736 "RCV RLS: did:x%x/ste:x%x flg:x%x",
8737 did, vport->port_state, ndlp->nlp_flag);
8739 phba->fc_stat.elsRcvRLS++;
8740 lpfc_els_rcv_rls(vport, elsiocb, ndlp);
8745 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8746 "RCV RPL: did:x%x/ste:x%x flg:x%x",
8747 did, vport->port_state, ndlp->nlp_flag);
8749 phba->fc_stat.elsRcvRPL++;
8750 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
8755 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8756 "RCV RNID: did:x%x/ste:x%x flg:x%x",
8757 did, vport->port_state, ndlp->nlp_flag);
8759 phba->fc_stat.elsRcvRNID++;
8760 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
8765 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8766 "RCV RTV: did:x%x/ste:x%x flg:x%x",
8767 did, vport->port_state, ndlp->nlp_flag);
8768 phba->fc_stat.elsRcvRTV++;
8769 lpfc_els_rcv_rtv(vport, elsiocb, ndlp);
8774 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8775 "RCV RRQ: did:x%x/ste:x%x flg:x%x",
8776 did, vport->port_state, ndlp->nlp_flag);
8778 phba->fc_stat.elsRcvRRQ++;
8779 lpfc_els_rcv_rrq(vport, elsiocb, ndlp);
8784 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8785 "RCV ECHO: did:x%x/ste:x%x flg:x%x",
8786 did, vport->port_state, ndlp->nlp_flag);
8788 phba->fc_stat.elsRcvECHO++;
8789 lpfc_els_rcv_echo(vport, elsiocb, ndlp);
8794 /* receive this due to exchange closed */
8795 rjt_err = LSRJT_UNABLE_TPC;
8796 rjt_exp = LSEXP_INVALID_OX_RX;
8799 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8800 "RCV FPIN: did:x%x/ste:x%x flg:x%x",
8801 did, vport->port_state, ndlp->nlp_flag);
8803 lpfc_els_rcv_fpin(vport, (struct fc_els_fpin *)payload,
8806 /* There are no replies, so no rjt codes */
8809 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8810 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
8811 cmd, did, vport->port_state);
8813 /* Unsupported ELS command, reject */
8814 rjt_err = LSRJT_CMD_UNSUPPORTED;
8815 rjt_exp = LSEXP_NOTHING_MORE;
8817 /* Unknown ELS command <elsCmd> received from NPORT <did> */
8818 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8819 "0115 Unknown ELS command x%x "
8820 "received from NPORT x%x\n", cmd, did);
8827 /* check if need to LS_RJT received ELS cmd */
8829 memset(&stat, 0, sizeof(stat));
8830 stat.un.b.lsRjtRsnCode = rjt_err;
8831 stat.un.b.lsRjtRsnCodeExp = rjt_exp;
8832 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
8836 lpfc_nlp_put(elsiocb->context1);
8837 elsiocb->context1 = NULL;
8839 /* Special case. Driver received an unsolicited command that
8840 * unsupportable given the driver's current state. Reset the
8841 * link and start over.
8844 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
8847 lpfc_linkdown(phba);
8848 lpfc_init_link(phba, mbox,
8850 phba->cfg_link_speed);
8851 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
8852 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
8853 mbox->vport = vport;
8854 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) ==
8856 mempool_free(mbox, phba->mbox_mem_pool);
8862 if (vport && !(vport->load_flag & FC_UNLOADING))
8863 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8864 "0111 Dropping received ELS cmd "
8865 "Data: x%x x%x x%x\n",
8866 icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout);
8867 phba->fc_stat.elsRcvDrop++;
8871 * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
8872 * @phba: pointer to lpfc hba data structure.
8873 * @pring: pointer to a SLI ring.
8874 * @elsiocb: pointer to lpfc els iocb data structure.
8876 * This routine is used to process an unsolicited event received from a SLI
8877 * (Service Level Interface) ring. The actual processing of the data buffer
8878 * associated with the unsolicited event is done by invoking the routine
8879 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
8880 * SLI ring on which the unsolicited event was received.
8883 lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
8884 struct lpfc_iocbq *elsiocb)
8886 struct lpfc_vport *vport = phba->pport;
8887 IOCB_t *icmd = &elsiocb->iocb;
8889 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
8890 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
8892 elsiocb->context1 = NULL;
8893 elsiocb->context2 = NULL;
8894 elsiocb->context3 = NULL;
8896 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
8897 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
8898 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
8899 (icmd->un.ulpWord[4] & IOERR_PARAM_MASK) ==
8900 IOERR_RCV_BUFFER_WAITING) {
8901 phba->fc_stat.NoRcvBuf++;
8902 /* Not enough posted buffers; Try posting more buffers */
8903 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
8904 lpfc_post_buffer(phba, pring, 0);
8908 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
8909 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
8910 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
8911 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
8912 vport = phba->pport;
8914 vport = lpfc_find_vport_by_vpid(phba,
8915 icmd->unsli3.rcvsli3.vpi);
8918 /* If there are no BDEs associated
8919 * with this IOCB, there is nothing to do.
8921 if (icmd->ulpBdeCount == 0)
8924 /* type of ELS cmd is first 32bit word
8927 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
8928 elsiocb->context2 = bdeBuf1;
8930 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
8931 icmd->un.cont64[0].addrLow);
8932 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
8936 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
8938 * The different unsolicited event handlers would tell us
8939 * if they are done with "mp" by setting context2 to NULL.
8941 if (elsiocb->context2) {
8942 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
8943 elsiocb->context2 = NULL;
8946 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
8947 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
8948 icmd->ulpBdeCount == 2) {
8949 elsiocb->context2 = bdeBuf2;
8950 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
8951 /* free mp if we are done with it */
8952 if (elsiocb->context2) {
8953 lpfc_in_buf_free(phba, elsiocb->context2);
8954 elsiocb->context2 = NULL;
8960 lpfc_start_fdmi(struct lpfc_vport *vport)
8962 struct lpfc_nodelist *ndlp;
8964 /* If this is the first time, allocate an ndlp and initialize
8965 * it. Otherwise, make sure the node is enabled and then do the
8968 ndlp = lpfc_findnode_did(vport, FDMI_DID);
8970 ndlp = lpfc_nlp_init(vport, FDMI_DID);
8972 ndlp->nlp_type |= NLP_FABRIC;
8977 if (!NLP_CHK_NODE_ACT(ndlp))
8978 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_NPR_NODE);
8981 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
8982 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
8987 * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
8988 * @phba: pointer to lpfc hba data structure.
8989 * @vport: pointer to a virtual N_Port data structure.
8991 * This routine issues a Port Login (PLOGI) to the Name Server with
8992 * State Change Request (SCR) for a @vport. This routine will create an
8993 * ndlp for the Name Server associated to the @vport if such node does
8994 * not already exist. The PLOGI to Name Server is issued by invoking the
8995 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
8996 * (FDMI) is configured to the @vport, a FDMI node will be created and
8997 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
9000 lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
9002 struct lpfc_nodelist *ndlp;
9003 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
9006 * If lpfc_delay_discovery parameter is set and the clean address
9007 * bit is cleared and fc fabric parameters chenged, delay FC NPort
9010 spin_lock_irq(shost->host_lock);
9011 if (vport->fc_flag & FC_DISC_DELAYED) {
9012 spin_unlock_irq(shost->host_lock);
9013 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
9014 "3334 Delay fc port discovery for %d seconds\n",
9016 mod_timer(&vport->delayed_disc_tmo,
9017 jiffies + msecs_to_jiffies(1000 * phba->fc_ratov));
9020 spin_unlock_irq(shost->host_lock);
9022 ndlp = lpfc_findnode_did(vport, NameServer_DID);
9024 ndlp = lpfc_nlp_init(vport, NameServer_DID);
9026 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
9027 lpfc_disc_start(vport);
9030 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
9031 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
9032 "0251 NameServer login: no memory\n");
9035 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
9036 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
9038 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
9039 lpfc_disc_start(vport);
9042 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
9043 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
9044 "0348 NameServer login: node freed\n");
9048 ndlp->nlp_type |= NLP_FABRIC;
9050 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
9052 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
9053 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
9054 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
9055 "0252 Cannot issue NameServer login\n");
9059 if ((phba->cfg_enable_SmartSAN ||
9060 (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) &&
9061 (vport->load_flag & FC_ALLOW_FDMI))
9062 lpfc_start_fdmi(vport);
9066 * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
9067 * @phba: pointer to lpfc hba data structure.
9068 * @pmb: pointer to the driver internal queue element for mailbox command.
9070 * This routine is the completion callback function to register new vport
9071 * mailbox command. If the new vport mailbox command completes successfully,
9072 * the fabric registration login shall be performed on physical port (the
9073 * new vport created is actually a physical port, with VPI 0) or the port
9074 * login to Name Server for State Change Request (SCR) will be performed
9075 * on virtual port (real virtual port, with VPI greater than 0).
9078 lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
9080 struct lpfc_vport *vport = pmb->vport;
9081 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
9082 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
9083 MAILBOX_t *mb = &pmb->u.mb;
9086 spin_lock_irq(shost->host_lock);
9087 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
9088 spin_unlock_irq(shost->host_lock);
9090 if (mb->mbxStatus) {
9091 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
9092 "0915 Register VPI failed : Status: x%x"
9093 " upd bit: x%x \n", mb->mbxStatus,
9094 mb->un.varRegVpi.upd);
9095 if (phba->sli_rev == LPFC_SLI_REV4 &&
9096 mb->un.varRegVpi.upd)
9097 goto mbox_err_exit ;
9099 switch (mb->mbxStatus) {
9100 case 0x11: /* unsupported feature */
9101 case 0x9603: /* max_vpi exceeded */
9102 case 0x9602: /* Link event since CLEAR_LA */
9103 /* giving up on vport registration */
9104 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
9105 spin_lock_irq(shost->host_lock);
9106 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
9107 spin_unlock_irq(shost->host_lock);
9108 lpfc_can_disctmo(vport);
9110 /* If reg_vpi fail with invalid VPI status, re-init VPI */
9112 spin_lock_irq(shost->host_lock);
9113 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
9114 spin_unlock_irq(shost->host_lock);
9115 lpfc_init_vpi(phba, pmb, vport->vpi);
9117 pmb->mbox_cmpl = lpfc_init_vpi_cmpl;
9118 rc = lpfc_sli_issue_mbox(phba, pmb,
9120 if (rc == MBX_NOT_FINISHED) {
9121 lpfc_printf_vlog(vport,
9123 "2732 Failed to issue INIT_VPI"
9124 " mailbox command\n");
9131 /* Try to recover from this error */
9132 if (phba->sli_rev == LPFC_SLI_REV4)
9133 lpfc_sli4_unreg_all_rpis(vport);
9134 lpfc_mbx_unreg_vpi(vport);
9135 spin_lock_irq(shost->host_lock);
9136 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
9137 spin_unlock_irq(shost->host_lock);
9138 if (mb->mbxStatus == MBX_NOT_FINISHED)
9140 if ((vport->port_type == LPFC_PHYSICAL_PORT) &&
9141 !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG)) {
9142 if (phba->sli_rev == LPFC_SLI_REV4)
9143 lpfc_issue_init_vfi(vport);
9145 lpfc_initial_flogi(vport);
9147 lpfc_initial_fdisc(vport);
9152 spin_lock_irq(shost->host_lock);
9153 vport->vpi_state |= LPFC_VPI_REGISTERED;
9154 spin_unlock_irq(shost->host_lock);
9155 if (vport == phba->pport) {
9156 if (phba->sli_rev < LPFC_SLI_REV4)
9157 lpfc_issue_fabric_reglogin(vport);
9160 * If the physical port is instantiated using
9161 * FDISC, do not start vport discovery.
9163 if (vport->port_state != LPFC_FDISC)
9164 lpfc_start_fdiscs(phba);
9165 lpfc_do_scr_ns_plogi(phba, vport);
9168 lpfc_do_scr_ns_plogi(phba, vport);
9171 /* Now, we decrement the ndlp reference count held for this
9176 mempool_free(pmb, phba->mbox_mem_pool);
9181 * lpfc_register_new_vport - Register a new vport with a HBA
9182 * @phba: pointer to lpfc hba data structure.
9183 * @vport: pointer to a host virtual N_Port data structure.
9184 * @ndlp: pointer to a node-list data structure.
9186 * This routine registers the @vport as a new virtual port with a HBA.
9187 * It is done through a registering vpi mailbox command.
9190 lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
9191 struct lpfc_nodelist *ndlp)
9193 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
9196 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
9198 lpfc_reg_vpi(vport, mbox);
9199 mbox->vport = vport;
9200 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
9201 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
9202 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
9203 == MBX_NOT_FINISHED) {
9204 /* mailbox command not success, decrement ndlp
9205 * reference count for this command
9208 mempool_free(mbox, phba->mbox_mem_pool);
9210 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
9211 "0253 Register VPI: Can't send mbox\n");
9215 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
9216 "0254 Register VPI: no memory\n");
9222 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
9223 spin_lock_irq(shost->host_lock);
9224 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
9225 spin_unlock_irq(shost->host_lock);
9230 * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer
9231 * @phba: pointer to lpfc hba data structure.
9233 * This routine cancels the retry delay timers to all the vports.
9236 lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba)
9238 struct lpfc_vport **vports;
9239 struct lpfc_nodelist *ndlp;
9240 uint32_t link_state;
9243 /* Treat this failure as linkdown for all vports */
9244 link_state = phba->link_state;
9245 lpfc_linkdown(phba);
9246 phba->link_state = link_state;
9248 vports = lpfc_create_vport_work_array(phba);
9251 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
9252 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
9254 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
9255 lpfc_els_flush_cmd(vports[i]);
9257 lpfc_destroy_vport_work_array(phba, vports);
9262 * lpfc_retry_pport_discovery - Start timer to retry FLOGI.
9263 * @phba: pointer to lpfc hba data structure.
9265 * This routine abort all pending discovery commands and
9266 * start a timer to retry FLOGI for the physical port
9270 lpfc_retry_pport_discovery(struct lpfc_hba *phba)
9272 struct lpfc_nodelist *ndlp;
9273 struct Scsi_Host *shost;
9275 /* Cancel the all vports retry delay retry timers */
9276 lpfc_cancel_all_vport_retry_delay_timer(phba);
9278 /* If fabric require FLOGI, then re-instantiate physical login */
9279 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
9283 shost = lpfc_shost_from_vport(phba->pport);
9284 mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000));
9285 spin_lock_irq(shost->host_lock);
9286 ndlp->nlp_flag |= NLP_DELAY_TMO;
9287 spin_unlock_irq(shost->host_lock);
9288 ndlp->nlp_last_elscmd = ELS_CMD_FLOGI;
9289 phba->pport->port_state = LPFC_FLOGI;
9294 * lpfc_fabric_login_reqd - Check if FLOGI required.
9295 * @phba: pointer to lpfc hba data structure.
9296 * @cmdiocb: pointer to FDISC command iocb.
9297 * @rspiocb: pointer to FDISC response iocb.
9299 * This routine checks if a FLOGI is reguired for FDISC
9303 lpfc_fabric_login_reqd(struct lpfc_hba *phba,
9304 struct lpfc_iocbq *cmdiocb,
9305 struct lpfc_iocbq *rspiocb)
9308 if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) ||
9309 (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED))
9316 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
9317 * @phba: pointer to lpfc hba data structure.
9318 * @cmdiocb: pointer to lpfc command iocb data structure.
9319 * @rspiocb: pointer to lpfc response iocb data structure.
9321 * This routine is the completion callback function to a Fabric Discover
9322 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
9323 * single threaded, each FDISC completion callback function will reset
9324 * the discovery timer for all vports such that the timers will not get
9325 * unnecessary timeout. The function checks the FDISC IOCB status. If error
9326 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
9327 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
9328 * assigned to the vport has been changed with the completion of the FDISC
9329 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
9330 * are unregistered from the HBA, and then the lpfc_register_new_vport()
9331 * routine is invoked to register new vport with the HBA. Otherwise, the
9332 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
9333 * Server for State Change Request (SCR).
9336 lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
9337 struct lpfc_iocbq *rspiocb)
9339 struct lpfc_vport *vport = cmdiocb->vport;
9340 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
9341 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
9342 struct lpfc_nodelist *np;
9343 struct lpfc_nodelist *next_np;
9344 IOCB_t *irsp = &rspiocb->iocb;
9345 struct lpfc_iocbq *piocb;
9346 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
9347 struct serv_parm *sp;
9348 uint8_t fabric_param_changed;
9350 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
9351 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
9352 irsp->ulpStatus, irsp->un.ulpWord[4],
9354 /* Since all FDISCs are being single threaded, we
9355 * must reset the discovery timer for ALL vports
9356 * waiting to send FDISC when one completes.
9358 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
9359 lpfc_set_disctmo(piocb->vport);
9362 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
9363 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
9364 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
9366 if (irsp->ulpStatus) {
9368 if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) {
9369 lpfc_retry_pport_discovery(phba);
9373 /* Check for retry */
9374 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
9377 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
9378 "0126 FDISC failed. (x%x/x%x)\n",
9379 irsp->ulpStatus, irsp->un.ulpWord[4]);
9382 spin_lock_irq(shost->host_lock);
9383 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
9384 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
9385 vport->fc_flag |= FC_FABRIC;
9386 if (vport->phba->fc_topology == LPFC_TOPOLOGY_LOOP)
9387 vport->fc_flag |= FC_PUBLIC_LOOP;
9388 spin_unlock_irq(shost->host_lock);
9390 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
9391 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
9392 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
9395 sp = prsp->virt + sizeof(uint32_t);
9396 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
9397 memcpy(&vport->fabric_portname, &sp->portName,
9398 sizeof(struct lpfc_name));
9399 memcpy(&vport->fabric_nodename, &sp->nodeName,
9400 sizeof(struct lpfc_name));
9401 if (fabric_param_changed &&
9402 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
9403 /* If our NportID changed, we need to ensure all
9404 * remaining NPORTs get unreg_login'ed so we can
9407 list_for_each_entry_safe(np, next_np,
9408 &vport->fc_nodes, nlp_listp) {
9409 if (!NLP_CHK_NODE_ACT(ndlp) ||
9410 (np->nlp_state != NLP_STE_NPR_NODE) ||
9411 !(np->nlp_flag & NLP_NPR_ADISC))
9413 spin_lock_irq(shost->host_lock);
9414 np->nlp_flag &= ~NLP_NPR_ADISC;
9415 spin_unlock_irq(shost->host_lock);
9416 lpfc_unreg_rpi(vport, np);
9418 lpfc_cleanup_pending_mbox(vport);
9420 if (phba->sli_rev == LPFC_SLI_REV4)
9421 lpfc_sli4_unreg_all_rpis(vport);
9423 lpfc_mbx_unreg_vpi(vport);
9424 spin_lock_irq(shost->host_lock);
9425 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
9426 if (phba->sli_rev == LPFC_SLI_REV4)
9427 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
9429 vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG;
9430 spin_unlock_irq(shost->host_lock);
9431 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
9432 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
9434 * Driver needs to re-reg VPI in order for f/w
9435 * to update the MAC address.
9437 lpfc_register_new_vport(phba, vport, ndlp);
9441 if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)
9442 lpfc_issue_init_vpi(vport);
9443 else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
9444 lpfc_register_new_vport(phba, vport, ndlp);
9446 lpfc_do_scr_ns_plogi(phba, vport);
9449 if (vport->fc_vport &&
9450 (vport->fc_vport->vport_state != FC_VPORT_NO_FABRIC_RSCS))
9451 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
9452 /* Cancel discovery timer */
9453 lpfc_can_disctmo(vport);
9456 lpfc_els_free_iocb(phba, cmdiocb);
9460 * lpfc_issue_els_fdisc - Issue a fdisc iocb command
9461 * @vport: pointer to a virtual N_Port data structure.
9462 * @ndlp: pointer to a node-list data structure.
9463 * @retry: number of retries to the command IOCB.
9465 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
9466 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
9467 * routine to issue the IOCB, which makes sure only one outstanding fabric
9468 * IOCB will be sent off HBA at any given time.
9470 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
9471 * will be incremented by 1 for holding the ndlp and the reference to ndlp
9472 * will be stored into the context1 field of the IOCB for the completion
9473 * callback function to the FDISC ELS command.
9476 * 0 - Successfully issued fdisc iocb command
9477 * 1 - Failed to issue fdisc iocb command
9480 lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
9483 struct lpfc_hba *phba = vport->phba;
9485 struct lpfc_iocbq *elsiocb;
9486 struct serv_parm *sp;
9489 int did = ndlp->nlp_DID;
9492 vport->port_state = LPFC_FDISC;
9493 vport->fc_myDID = 0;
9494 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
9495 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
9498 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
9499 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
9500 "0255 Issue FDISC: no IOCB\n");
9504 icmd = &elsiocb->iocb;
9505 icmd->un.elsreq64.myID = 0;
9506 icmd->un.elsreq64.fl = 1;
9509 * SLI3 ports require a different context type value than SLI4.
9510 * Catch SLI3 ports here and override the prep.
9512 if (phba->sli_rev == LPFC_SLI_REV3) {
9517 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
9518 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
9519 pcmd += sizeof(uint32_t); /* CSP Word 1 */
9520 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
9521 sp = (struct serv_parm *) pcmd;
9522 /* Setup CSPs accordingly for Fabric */
9523 sp->cmn.e_d_tov = 0;
9524 sp->cmn.w2.r_a_tov = 0;
9525 sp->cmn.virtual_fabric_support = 0;
9526 sp->cls1.classValid = 0;
9527 sp->cls2.seqDelivery = 1;
9528 sp->cls3.seqDelivery = 1;
9530 pcmd += sizeof(uint32_t); /* CSP Word 2 */
9531 pcmd += sizeof(uint32_t); /* CSP Word 3 */
9532 pcmd += sizeof(uint32_t); /* CSP Word 4 */
9533 pcmd += sizeof(uint32_t); /* Port Name */
9534 memcpy(pcmd, &vport->fc_portname, 8);
9535 pcmd += sizeof(uint32_t); /* Node Name */
9536 pcmd += sizeof(uint32_t); /* Node Name */
9537 memcpy(pcmd, &vport->fc_nodename, 8);
9538 sp->cmn.valid_vendor_ver_level = 0;
9539 memset(sp->un.vendorVersion, 0, sizeof(sp->un.vendorVersion));
9540 lpfc_set_disctmo(vport);
9542 phba->fc_stat.elsXmitFDISC++;
9543 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
9545 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
9546 "Issue FDISC: did:x%x",
9549 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
9550 if (rc == IOCB_ERROR) {
9551 lpfc_els_free_iocb(phba, elsiocb);
9552 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
9553 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
9554 "0256 Issue FDISC: Cannot send IOCB\n");
9557 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
9562 * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
9563 * @phba: pointer to lpfc hba data structure.
9564 * @cmdiocb: pointer to lpfc command iocb data structure.
9565 * @rspiocb: pointer to lpfc response iocb data structure.
9567 * This routine is the completion callback function to the issuing of a LOGO
9568 * ELS command off a vport. It frees the command IOCB and then decrement the
9569 * reference count held on ndlp for this completion function, indicating that
9570 * the reference to the ndlp is no long needed. Note that the
9571 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
9572 * callback function and an additional explicit ndlp reference decrementation
9573 * will trigger the actual release of the ndlp.
9576 lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
9577 struct lpfc_iocbq *rspiocb)
9579 struct lpfc_vport *vport = cmdiocb->vport;
9581 struct lpfc_nodelist *ndlp;
9582 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
9584 ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
9585 irsp = &rspiocb->iocb;
9586 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
9587 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
9588 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
9590 lpfc_els_free_iocb(phba, cmdiocb);
9591 vport->unreg_vpi_cmpl = VPORT_ERROR;
9593 /* Trigger the release of the ndlp after logo */
9596 /* NPIV LOGO completes to NPort <nlp_DID> */
9597 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
9598 "2928 NPIV LOGO completes to NPort x%x "
9599 "Data: x%x x%x x%x x%x\n",
9600 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
9601 irsp->ulpTimeout, vport->num_disc_nodes);
9603 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
9604 spin_lock_irq(shost->host_lock);
9605 vport->fc_flag &= ~FC_NDISC_ACTIVE;
9606 vport->fc_flag &= ~FC_FABRIC;
9607 spin_unlock_irq(shost->host_lock);
9608 lpfc_can_disctmo(vport);
9613 * lpfc_issue_els_npiv_logo - Issue a logo off a vport
9614 * @vport: pointer to a virtual N_Port data structure.
9615 * @ndlp: pointer to a node-list data structure.
9617 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
9619 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
9620 * will be incremented by 1 for holding the ndlp and the reference to ndlp
9621 * will be stored into the context1 field of the IOCB for the completion
9622 * callback function to the LOGO ELS command.
9625 * 0 - Successfully issued logo off the @vport
9626 * 1 - Failed to issue logo off the @vport
9629 lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
9631 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
9632 struct lpfc_hba *phba = vport->phba;
9633 struct lpfc_iocbq *elsiocb;
9637 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
9638 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
9643 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
9644 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
9645 pcmd += sizeof(uint32_t);
9647 /* Fill in LOGO payload */
9648 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
9649 pcmd += sizeof(uint32_t);
9650 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
9652 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
9653 "Issue LOGO npiv did:x%x flg:x%x",
9654 ndlp->nlp_DID, ndlp->nlp_flag, 0);
9656 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
9657 spin_lock_irq(shost->host_lock);
9658 ndlp->nlp_flag |= NLP_LOGO_SND;
9659 spin_unlock_irq(shost->host_lock);
9660 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
9662 spin_lock_irq(shost->host_lock);
9663 ndlp->nlp_flag &= ~NLP_LOGO_SND;
9664 spin_unlock_irq(shost->host_lock);
9665 lpfc_els_free_iocb(phba, elsiocb);
9672 * lpfc_fabric_block_timeout - Handler function to the fabric block timer
9673 * @ptr: holder for the timer function associated data.
9675 * This routine is invoked by the fabric iocb block timer after
9676 * timeout. It posts the fabric iocb block timeout event by setting the
9677 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
9678 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
9679 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
9680 * posted event WORKER_FABRIC_BLOCK_TMO.
9683 lpfc_fabric_block_timeout(struct timer_list *t)
9685 struct lpfc_hba *phba = from_timer(phba, t, fabric_block_timer);
9686 unsigned long iflags;
9687 uint32_t tmo_posted;
9689 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
9690 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
9692 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
9693 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
9696 lpfc_worker_wake_up(phba);
9701 * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
9702 * @phba: pointer to lpfc hba data structure.
9704 * This routine issues one fabric iocb from the driver internal list to
9705 * the HBA. It first checks whether it's ready to issue one fabric iocb to
9706 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
9707 * remove one pending fabric iocb from the driver internal list and invokes
9708 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
9711 lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
9713 struct lpfc_iocbq *iocb;
9714 unsigned long iflags;
9720 spin_lock_irqsave(&phba->hbalock, iflags);
9721 /* Post any pending iocb to the SLI layer */
9722 if (atomic_read(&phba->fabric_iocb_count) == 0) {
9723 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
9726 /* Increment fabric iocb count to hold the position */
9727 atomic_inc(&phba->fabric_iocb_count);
9729 spin_unlock_irqrestore(&phba->hbalock, iflags);
9731 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
9732 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
9733 iocb->iocb_flag |= LPFC_IO_FABRIC;
9735 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
9736 "Fabric sched1: ste:x%x",
9737 iocb->vport->port_state, 0, 0);
9739 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
9741 if (ret == IOCB_ERROR) {
9742 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
9743 iocb->fabric_iocb_cmpl = NULL;
9744 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
9746 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
9747 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
9748 iocb->iocb_cmpl(phba, iocb, iocb);
9750 atomic_dec(&phba->fabric_iocb_count);
9759 * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
9760 * @phba: pointer to lpfc hba data structure.
9762 * This routine unblocks the issuing fabric iocb command. The function
9763 * will clear the fabric iocb block bit and then invoke the routine
9764 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
9765 * from the driver internal fabric iocb list.
9768 lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
9770 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
9772 lpfc_resume_fabric_iocbs(phba);
9777 * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
9778 * @phba: pointer to lpfc hba data structure.
9780 * This routine blocks the issuing fabric iocb for a specified amount of
9781 * time (currently 100 ms). This is done by set the fabric iocb block bit
9782 * and set up a timeout timer for 100ms. When the block bit is set, no more
9783 * fabric iocb will be issued out of the HBA.
9786 lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
9790 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
9791 /* Start a timer to unblock fabric iocbs after 100ms */
9793 mod_timer(&phba->fabric_block_timer,
9794 jiffies + msecs_to_jiffies(100));
9800 * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
9801 * @phba: pointer to lpfc hba data structure.
9802 * @cmdiocb: pointer to lpfc command iocb data structure.
9803 * @rspiocb: pointer to lpfc response iocb data structure.
9805 * This routine is the callback function that is put to the fabric iocb's
9806 * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
9807 * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
9808 * function first restores and invokes the original iocb's callback function
9809 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
9810 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
9813 lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
9814 struct lpfc_iocbq *rspiocb)
9818 BUG_ON((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC);
9820 switch (rspiocb->iocb.ulpStatus) {
9821 case IOSTAT_NPORT_RJT:
9822 case IOSTAT_FABRIC_RJT:
9823 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
9824 lpfc_block_fabric_iocbs(phba);
9828 case IOSTAT_NPORT_BSY:
9829 case IOSTAT_FABRIC_BSY:
9830 lpfc_block_fabric_iocbs(phba);
9834 stat.un.lsRjtError =
9835 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
9836 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
9837 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
9838 lpfc_block_fabric_iocbs(phba);
9842 BUG_ON(atomic_read(&phba->fabric_iocb_count) == 0);
9844 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
9845 cmdiocb->fabric_iocb_cmpl = NULL;
9846 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
9847 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
9849 atomic_dec(&phba->fabric_iocb_count);
9850 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
9851 /* Post any pending iocbs to HBA */
9852 lpfc_resume_fabric_iocbs(phba);
9857 * lpfc_issue_fabric_iocb - Issue a fabric iocb command
9858 * @phba: pointer to lpfc hba data structure.
9859 * @iocb: pointer to lpfc command iocb data structure.
9861 * This routine is used as the top-level API for issuing a fabric iocb command
9862 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
9863 * function makes sure that only one fabric bound iocb will be outstanding at
9864 * any given time. As such, this function will first check to see whether there
9865 * is already an outstanding fabric iocb on the wire. If so, it will put the
9866 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
9867 * issued later. Otherwise, it will issue the iocb on the wire and update the
9868 * fabric iocb count it indicate that there is one fabric iocb on the wire.
9870 * Note, this implementation has a potential sending out fabric IOCBs out of
9871 * order. The problem is caused by the construction of the "ready" boolen does
9872 * not include the condition that the internal fabric IOCB list is empty. As
9873 * such, it is possible a fabric IOCB issued by this routine might be "jump"
9874 * ahead of the fabric IOCBs in the internal list.
9877 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
9878 * IOCB_ERROR - failed to issue fabric iocb
9881 lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
9883 unsigned long iflags;
9887 BUG_ON(atomic_read(&phba->fabric_iocb_count) > 1);
9889 spin_lock_irqsave(&phba->hbalock, iflags);
9890 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
9891 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
9894 /* Increment fabric iocb count to hold the position */
9895 atomic_inc(&phba->fabric_iocb_count);
9896 spin_unlock_irqrestore(&phba->hbalock, iflags);
9898 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
9899 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
9900 iocb->iocb_flag |= LPFC_IO_FABRIC;
9902 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
9903 "Fabric sched2: ste:x%x",
9904 iocb->vport->port_state, 0, 0);
9906 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
9908 if (ret == IOCB_ERROR) {
9909 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
9910 iocb->fabric_iocb_cmpl = NULL;
9911 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
9912 atomic_dec(&phba->fabric_iocb_count);
9915 spin_lock_irqsave(&phba->hbalock, iflags);
9916 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
9917 spin_unlock_irqrestore(&phba->hbalock, iflags);
9924 * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
9925 * @vport: pointer to a virtual N_Port data structure.
9927 * This routine aborts all the IOCBs associated with a @vport from the
9928 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
9929 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
9930 * list, removes each IOCB associated with the @vport off the list, set the
9931 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
9932 * associated with the IOCB.
9934 static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
9936 LIST_HEAD(completions);
9937 struct lpfc_hba *phba = vport->phba;
9938 struct lpfc_iocbq *tmp_iocb, *piocb;
9940 spin_lock_irq(&phba->hbalock);
9941 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
9944 if (piocb->vport != vport)
9947 list_move_tail(&piocb->list, &completions);
9949 spin_unlock_irq(&phba->hbalock);
9951 /* Cancel all the IOCBs from the completions list */
9952 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
9957 * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
9958 * @ndlp: pointer to a node-list data structure.
9960 * This routine aborts all the IOCBs associated with an @ndlp from the
9961 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
9962 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
9963 * list, removes each IOCB associated with the @ndlp off the list, set the
9964 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
9965 * associated with the IOCB.
9967 void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
9969 LIST_HEAD(completions);
9970 struct lpfc_hba *phba = ndlp->phba;
9971 struct lpfc_iocbq *tmp_iocb, *piocb;
9972 struct lpfc_sli_ring *pring;
9974 pring = lpfc_phba_elsring(phba);
9976 if (unlikely(!pring))
9979 spin_lock_irq(&phba->hbalock);
9980 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
9982 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
9984 list_move_tail(&piocb->list, &completions);
9987 spin_unlock_irq(&phba->hbalock);
9989 /* Cancel all the IOCBs from the completions list */
9990 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
9995 * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
9996 * @phba: pointer to lpfc hba data structure.
9998 * This routine aborts all the IOCBs currently on the driver internal
9999 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
10000 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
10001 * list, removes IOCBs off the list, set the status feild to
10002 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
10005 void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
10007 LIST_HEAD(completions);
10009 spin_lock_irq(&phba->hbalock);
10010 list_splice_init(&phba->fabric_iocb_list, &completions);
10011 spin_unlock_irq(&phba->hbalock);
10013 /* Cancel all the IOCBs from the completions list */
10014 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
10015 IOERR_SLI_ABORTED);
10019 * lpfc_sli4_vport_delete_els_xri_aborted -Remove all ndlp references for vport
10020 * @vport: pointer to lpfc vport data structure.
10022 * This routine is invoked by the vport cleanup for deletions and the cleanup
10023 * for an ndlp on removal.
10026 lpfc_sli4_vport_delete_els_xri_aborted(struct lpfc_vport *vport)
10028 struct lpfc_hba *phba = vport->phba;
10029 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
10030 unsigned long iflag = 0;
10032 spin_lock_irqsave(&phba->hbalock, iflag);
10033 spin_lock(&phba->sli4_hba.sgl_list_lock);
10034 list_for_each_entry_safe(sglq_entry, sglq_next,
10035 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
10036 if (sglq_entry->ndlp && sglq_entry->ndlp->vport == vport)
10037 sglq_entry->ndlp = NULL;
10039 spin_unlock(&phba->sli4_hba.sgl_list_lock);
10040 spin_unlock_irqrestore(&phba->hbalock, iflag);
10045 * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
10046 * @phba: pointer to lpfc hba data structure.
10047 * @axri: pointer to the els xri abort wcqe structure.
10049 * This routine is invoked by the worker thread to process a SLI4 slow-path
10053 lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba,
10054 struct sli4_wcqe_xri_aborted *axri)
10056 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
10057 uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri);
10060 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
10061 unsigned long iflag = 0;
10062 struct lpfc_nodelist *ndlp;
10063 struct lpfc_sli_ring *pring;
10065 pring = lpfc_phba_elsring(phba);
10067 spin_lock_irqsave(&phba->hbalock, iflag);
10068 spin_lock(&phba->sli4_hba.sgl_list_lock);
10069 list_for_each_entry_safe(sglq_entry, sglq_next,
10070 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
10071 if (sglq_entry->sli4_xritag == xri) {
10072 list_del(&sglq_entry->list);
10073 ndlp = sglq_entry->ndlp;
10074 sglq_entry->ndlp = NULL;
10075 list_add_tail(&sglq_entry->list,
10076 &phba->sli4_hba.lpfc_els_sgl_list);
10077 sglq_entry->state = SGL_FREED;
10078 spin_unlock(&phba->sli4_hba.sgl_list_lock);
10079 spin_unlock_irqrestore(&phba->hbalock, iflag);
10080 lpfc_set_rrq_active(phba, ndlp,
10081 sglq_entry->sli4_lxritag,
10084 /* Check if TXQ queue needs to be serviced */
10085 if (pring && !list_empty(&pring->txq))
10086 lpfc_worker_wake_up(phba);
10090 spin_unlock(&phba->sli4_hba.sgl_list_lock);
10091 lxri = lpfc_sli4_xri_inrange(phba, xri);
10092 if (lxri == NO_XRI) {
10093 spin_unlock_irqrestore(&phba->hbalock, iflag);
10096 spin_lock(&phba->sli4_hba.sgl_list_lock);
10097 sglq_entry = __lpfc_get_active_sglq(phba, lxri);
10098 if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) {
10099 spin_unlock(&phba->sli4_hba.sgl_list_lock);
10100 spin_unlock_irqrestore(&phba->hbalock, iflag);
10103 sglq_entry->state = SGL_XRI_ABORTED;
10104 spin_unlock(&phba->sli4_hba.sgl_list_lock);
10105 spin_unlock_irqrestore(&phba->hbalock, iflag);
10109 /* lpfc_sli_abts_recover_port - Recover a port that failed a BLS_ABORT req.
10110 * @vport: pointer to virtual port object.
10111 * @ndlp: nodelist pointer for the impacted node.
10113 * The driver calls this routine in response to an SLI4 XRI ABORT CQE
10114 * or an SLI3 ASYNC_STATUS_CN event from the port. For either event,
10115 * the driver is required to send a LOGO to the remote node before it
10116 * attempts to recover its login to the remote node.
10119 lpfc_sli_abts_recover_port(struct lpfc_vport *vport,
10120 struct lpfc_nodelist *ndlp)
10122 struct Scsi_Host *shost;
10123 struct lpfc_hba *phba;
10124 unsigned long flags = 0;
10126 shost = lpfc_shost_from_vport(vport);
10127 phba = vport->phba;
10128 if (ndlp->nlp_state != NLP_STE_MAPPED_NODE) {
10129 lpfc_printf_log(phba, KERN_INFO,
10130 LOG_SLI, "3093 No rport recovery needed. "
10131 "rport in state 0x%x\n", ndlp->nlp_state);
10134 lpfc_printf_log(phba, KERN_ERR,
10135 LOG_ELS | LOG_FCP_ERROR | LOG_NVME_IOERR,
10136 "3094 Start rport recovery on shost id 0x%x "
10137 "fc_id 0x%06x vpi 0x%x rpi 0x%x state 0x%x "
10139 shost->host_no, ndlp->nlp_DID,
10140 vport->vpi, ndlp->nlp_rpi, ndlp->nlp_state,
10143 * The rport is not responding. Remove the FCP-2 flag to prevent
10144 * an ADISC in the follow-up recovery code.
10146 spin_lock_irqsave(shost->host_lock, flags);
10147 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
10148 ndlp->nlp_flag |= NLP_ISSUE_LOGO;
10149 spin_unlock_irqrestore(shost->host_lock, flags);
10150 lpfc_unreg_rpi(vport, ndlp);