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_TRACE_EVENT,
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 elsiocb->context2 = pcmd;
304 elsiocb->context3 = pbuflist;
305 elsiocb->retry = retry;
306 elsiocb->vport = vport;
307 elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT;
310 list_add(&prsp->list, &pcmd->list);
313 /* Xmit ELS command <elsCmd> to remote NPORT <did> */
314 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
315 "0116 Xmit ELS command x%x to remote "
316 "NPORT x%x I/O tag: x%x, port state:x%x "
317 "rpi x%x fc_flag:x%x\n",
318 elscmd, did, elsiocb->iotag,
319 vport->port_state, ndlp->nlp_rpi,
322 /* Xmit ELS response <elsCmd> to remote NPORT <did> */
323 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
324 "0117 Xmit ELS response x%x to remote "
325 "NPORT x%x I/O tag: x%x, size: x%x "
326 "port_state x%x rpi x%x fc_flag x%x\n",
327 elscmd, ndlp->nlp_DID, elsiocb->iotag,
328 cmdSize, vport->port_state,
329 ndlp->nlp_rpi, vport->fc_flag);
333 els_iocb_free_pbuf_exit:
335 lpfc_mbuf_free(phba, prsp->virt, prsp->phys);
338 els_iocb_free_prsp_exit:
339 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
342 els_iocb_free_pcmb_exit:
344 lpfc_sli_release_iocbq(phba, elsiocb);
349 * lpfc_issue_fabric_reglogin - Issue fabric registration login for a vport
350 * @vport: pointer to a host virtual N_Port data structure.
352 * This routine issues a fabric registration login for a @vport. An
353 * active ndlp node with Fabric_DID must already exist for this @vport.
354 * The routine invokes two mailbox commands to carry out fabric registration
355 * login through the HBA firmware: the first mailbox command requests the
356 * HBA to perform link configuration for the @vport; and the second mailbox
357 * command requests the HBA to perform the actual fabric registration login
361 * 0 - successfully issued fabric registration login for @vport
362 * -ENXIO -- failed to issue fabric registration login for @vport
365 lpfc_issue_fabric_reglogin(struct lpfc_vport *vport)
367 struct lpfc_hba *phba = vport->phba;
369 struct lpfc_dmabuf *mp;
370 struct lpfc_nodelist *ndlp;
371 struct serv_parm *sp;
375 sp = &phba->fc_fabparam;
376 ndlp = lpfc_findnode_did(vport, Fabric_DID);
382 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
388 vport->port_state = LPFC_FABRIC_CFG_LINK;
389 lpfc_config_link(phba, mbox);
390 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
393 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
394 if (rc == MBX_NOT_FINISHED) {
399 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
404 rc = lpfc_reg_rpi(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox,
411 mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login;
413 /* increment the reference count on ndlp to hold reference
414 * for the callback routine.
416 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
417 if (!mbox->ctx_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.
436 mp = (struct lpfc_dmabuf *)mbox->ctx_buf;
437 lpfc_mbuf_free(phba, mp->virt, mp->phys);
440 mempool_free(mbox, phba->mbox_mem_pool);
443 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
444 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
445 "0249 Cannot issue Register Fabric login: Err %d\n",
451 * lpfc_issue_reg_vfi - Register VFI for this vport's fabric login
452 * @vport: pointer to a host virtual N_Port data structure.
454 * This routine issues a REG_VFI mailbox for the vfi, vpi, fcfi triplet for
455 * the @vport. This mailbox command is necessary for SLI4 port only.
458 * 0 - successfully issued REG_VFI for @vport
459 * A failure code otherwise.
462 lpfc_issue_reg_vfi(struct lpfc_vport *vport)
464 struct lpfc_hba *phba = vport->phba;
465 LPFC_MBOXQ_t *mboxq = NULL;
466 struct lpfc_nodelist *ndlp;
467 struct lpfc_dmabuf *dmabuf = NULL;
470 /* move forward in case of SLI4 FC port loopback test and pt2pt mode */
471 if ((phba->sli_rev == LPFC_SLI_REV4) &&
472 !(phba->link_flag & LS_LOOPBACK_MODE) &&
473 !(vport->fc_flag & FC_PT2PT)) {
474 ndlp = lpfc_findnode_did(vport, Fabric_DID);
481 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
487 /* Supply CSP's only if we are fabric connect or pt-to-pt connect */
488 if ((vport->fc_flag & FC_FABRIC) || (vport->fc_flag & FC_PT2PT)) {
489 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
494 dmabuf->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &dmabuf->phys);
499 memcpy(dmabuf->virt, &phba->fc_fabparam,
500 sizeof(struct serv_parm));
503 vport->port_state = LPFC_FABRIC_CFG_LINK;
505 lpfc_reg_vfi(mboxq, vport, dmabuf->phys);
507 lpfc_reg_vfi(mboxq, vport, 0);
509 mboxq->mbox_cmpl = lpfc_mbx_cmpl_reg_vfi;
510 mboxq->vport = vport;
511 mboxq->ctx_buf = dmabuf;
512 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
513 if (rc == MBX_NOT_FINISHED) {
521 mempool_free(mboxq, phba->mbox_mem_pool);
524 lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys);
528 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
529 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
530 "0289 Issue Register VFI failed: Err %d\n", rc);
535 * lpfc_issue_unreg_vfi - Unregister VFI for this vport's fabric login
536 * @vport: pointer to a host virtual N_Port data structure.
538 * This routine issues a UNREG_VFI mailbox with the vfi, vpi, fcfi triplet for
539 * the @vport. This mailbox command is necessary for SLI4 port only.
542 * 0 - successfully issued REG_VFI for @vport
543 * A failure code otherwise.
546 lpfc_issue_unreg_vfi(struct lpfc_vport *vport)
548 struct lpfc_hba *phba = vport->phba;
549 struct Scsi_Host *shost;
553 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
555 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
556 "2556 UNREG_VFI mbox allocation failed"
557 "HBA state x%x\n", phba->pport->port_state);
561 lpfc_unreg_vfi(mboxq, vport);
562 mboxq->vport = vport;
563 mboxq->mbox_cmpl = lpfc_unregister_vfi_cmpl;
565 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
566 if (rc == MBX_NOT_FINISHED) {
567 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
568 "2557 UNREG_VFI issue mbox failed rc x%x "
570 rc, phba->pport->port_state);
571 mempool_free(mboxq, phba->mbox_mem_pool);
575 shost = lpfc_shost_from_vport(vport);
576 spin_lock_irq(shost->host_lock);
577 vport->fc_flag &= ~FC_VFI_REGISTERED;
578 spin_unlock_irq(shost->host_lock);
583 * lpfc_check_clean_addr_bit - Check whether assigned FCID is clean.
584 * @vport: pointer to a host virtual N_Port data structure.
585 * @sp: pointer to service parameter data structure.
587 * This routine is called from FLOGI/FDISC completion handler functions.
588 * lpfc_check_clean_addr_bit return 1 when FCID/Fabric portname/ Fabric
589 * node nodename is changed in the completion service parameter else return
590 * 0. This function also set flag in the vport data structure to delay
591 * NP_Port discovery after the FLOGI/FDISC completion if Clean address bit
592 * in FLOGI/FDISC response is cleared and FCID/Fabric portname/ Fabric
593 * node nodename is changed in the completion service parameter.
596 * 0 - FCID and Fabric Nodename and Fabric portname is not changed.
597 * 1 - FCID or Fabric Nodename or Fabric portname is changed.
601 lpfc_check_clean_addr_bit(struct lpfc_vport *vport,
602 struct serv_parm *sp)
604 struct lpfc_hba *phba = vport->phba;
605 uint8_t fabric_param_changed = 0;
606 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
608 if ((vport->fc_prevDID != vport->fc_myDID) ||
609 memcmp(&vport->fabric_portname, &sp->portName,
610 sizeof(struct lpfc_name)) ||
611 memcmp(&vport->fabric_nodename, &sp->nodeName,
612 sizeof(struct lpfc_name)) ||
613 (vport->vport_flag & FAWWPN_PARAM_CHG)) {
614 fabric_param_changed = 1;
615 vport->vport_flag &= ~FAWWPN_PARAM_CHG;
618 * Word 1 Bit 31 in common service parameter is overloaded.
619 * Word 1 Bit 31 in FLOGI request is multiple NPort request
620 * Word 1 Bit 31 in FLOGI response is clean address bit
622 * If fabric parameter is changed and clean address bit is
623 * cleared delay nport discovery if
624 * - vport->fc_prevDID != 0 (not initial discovery) OR
625 * - lpfc_delay_discovery module parameter is set.
627 if (fabric_param_changed && !sp->cmn.clean_address_bit &&
628 (vport->fc_prevDID || phba->cfg_delay_discovery)) {
629 spin_lock_irq(shost->host_lock);
630 vport->fc_flag |= FC_DISC_DELAYED;
631 spin_unlock_irq(shost->host_lock);
634 return fabric_param_changed;
639 * lpfc_cmpl_els_flogi_fabric - Completion function for flogi to a fabric port
640 * @vport: pointer to a host virtual N_Port data structure.
641 * @ndlp: pointer to a node-list data structure.
642 * @sp: pointer to service parameter data structure.
643 * @irsp: pointer to the IOCB within the lpfc response IOCB.
645 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
646 * function to handle the completion of a Fabric Login (FLOGI) into a fabric
647 * port in a fabric topology. It properly sets up the parameters to the @ndlp
648 * from the IOCB response. It also check the newly assigned N_Port ID to the
649 * @vport against the previously assigned N_Port ID. If it is different from
650 * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine
651 * is invoked on all the remaining nodes with the @vport to unregister the
652 * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin()
653 * is invoked to register login to the fabric.
656 * 0 - Success (currently, always return 0)
659 lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
660 struct serv_parm *sp, IOCB_t *irsp)
662 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
663 struct lpfc_hba *phba = vport->phba;
664 struct lpfc_nodelist *np;
665 struct lpfc_nodelist *next_np;
666 uint8_t fabric_param_changed;
668 spin_lock_irq(shost->host_lock);
669 vport->fc_flag |= FC_FABRIC;
670 spin_unlock_irq(shost->host_lock);
672 phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
673 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
674 phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
676 phba->fc_edtovResol = sp->cmn.edtovResolution;
677 phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
679 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
680 spin_lock_irq(shost->host_lock);
681 vport->fc_flag |= FC_PUBLIC_LOOP;
682 spin_unlock_irq(shost->host_lock);
685 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
686 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
687 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name));
688 ndlp->nlp_class_sup = 0;
689 if (sp->cls1.classValid)
690 ndlp->nlp_class_sup |= FC_COS_CLASS1;
691 if (sp->cls2.classValid)
692 ndlp->nlp_class_sup |= FC_COS_CLASS2;
693 if (sp->cls3.classValid)
694 ndlp->nlp_class_sup |= FC_COS_CLASS3;
695 if (sp->cls4.classValid)
696 ndlp->nlp_class_sup |= FC_COS_CLASS4;
697 ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
698 sp->cmn.bbRcvSizeLsb;
700 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
701 if (fabric_param_changed) {
702 /* Reset FDMI attribute masks based on config parameter */
703 if (phba->cfg_enable_SmartSAN ||
704 (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) {
705 /* Setup appropriate attribute masks */
706 vport->fdmi_hba_mask = LPFC_FDMI2_HBA_ATTR;
707 if (phba->cfg_enable_SmartSAN)
708 vport->fdmi_port_mask = LPFC_FDMI2_SMART_ATTR;
710 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
712 vport->fdmi_hba_mask = 0;
713 vport->fdmi_port_mask = 0;
717 memcpy(&vport->fabric_portname, &sp->portName,
718 sizeof(struct lpfc_name));
719 memcpy(&vport->fabric_nodename, &sp->nodeName,
720 sizeof(struct lpfc_name));
721 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
723 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
724 if (sp->cmn.response_multiple_NPort) {
725 lpfc_printf_vlog(vport, KERN_WARNING,
727 "1816 FLOGI NPIV supported, "
728 "response data 0x%x\n",
729 sp->cmn.response_multiple_NPort);
730 spin_lock_irq(&phba->hbalock);
731 phba->link_flag |= LS_NPIV_FAB_SUPPORTED;
732 spin_unlock_irq(&phba->hbalock);
734 /* Because we asked f/w for NPIV it still expects us
735 to call reg_vnpid atleast for the physcial host */
736 lpfc_printf_vlog(vport, KERN_WARNING,
738 "1817 Fabric does not support NPIV "
739 "- configuring single port mode.\n");
740 spin_lock_irq(&phba->hbalock);
741 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
742 spin_unlock_irq(&phba->hbalock);
747 * For FC we need to do some special processing because of the SLI
748 * Port's default settings of the Common Service Parameters.
750 if ((phba->sli_rev == LPFC_SLI_REV4) &&
751 (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC)) {
752 /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */
753 if (fabric_param_changed)
754 lpfc_unregister_fcf_prep(phba);
756 /* This should just update the VFI CSPs*/
757 if (vport->fc_flag & FC_VFI_REGISTERED)
758 lpfc_issue_reg_vfi(vport);
761 if (fabric_param_changed &&
762 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
764 /* If our NportID changed, we need to ensure all
765 * remaining NPORTs get unreg_login'ed.
767 list_for_each_entry_safe(np, next_np,
768 &vport->fc_nodes, nlp_listp) {
769 if ((np->nlp_state != NLP_STE_NPR_NODE) ||
770 !(np->nlp_flag & NLP_NPR_ADISC))
772 spin_lock_irq(&np->lock);
773 np->nlp_flag &= ~NLP_NPR_ADISC;
774 spin_unlock_irq(&np->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);
912 memcpy(&ndlp->nlp_portname, &sp->portName,
913 sizeof(struct lpfc_name));
914 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
915 sizeof(struct lpfc_name));
916 /* Set state will put ndlp onto node list if not already done */
917 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
918 spin_lock_irq(&ndlp->lock);
919 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
920 spin_unlock_irq(&ndlp->lock);
922 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
926 lpfc_config_link(phba, mbox);
928 mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link;
930 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
931 if (rc == MBX_NOT_FINISHED) {
932 mempool_free(mbox, phba->mbox_mem_pool);
936 /* This side will wait for the PLOGI, decrement ndlp reference
937 * count indicating that ndlp can be released when other
938 * references to it are done.
942 /* Start discovery - this should just do CLEAR_LA */
943 lpfc_disc_start(vport);
952 * lpfc_cmpl_els_flogi - Completion callback function for flogi
953 * @phba: pointer to lpfc hba data structure.
954 * @cmdiocb: pointer to lpfc command iocb data structure.
955 * @rspiocb: pointer to lpfc response iocb data structure.
957 * This routine is the top-level completion callback function for issuing
958 * a Fabric Login (FLOGI) command. If the response IOCB reported error,
959 * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If
960 * retry has been made (either immediately or delayed with lpfc_els_retry()
961 * returning 1), the command IOCB will be released and function returned.
962 * If the retry attempt has been given up (possibly reach the maximum
963 * number of retries), one additional decrement of ndlp reference shall be
964 * invoked before going out after releasing the command IOCB. This will
965 * actually release the remote node (Note, lpfc_els_free_iocb() will also
966 * invoke one decrement of ndlp reference count). If no error reported in
967 * the IOCB status, the command Port ID field is used to determine whether
968 * this is a point-to-point topology or a fabric topology: if the Port ID
969 * field is assigned, it is a fabric topology; otherwise, it is a
970 * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or
971 * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the
972 * specific topology completion conditions.
975 lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
976 struct lpfc_iocbq *rspiocb)
978 struct lpfc_vport *vport = cmdiocb->vport;
979 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
980 IOCB_t *irsp = &rspiocb->iocb;
981 struct lpfc_nodelist *ndlp = cmdiocb->context1;
982 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
983 struct serv_parm *sp;
987 /* Check to see if link went down during discovery */
988 if (lpfc_els_chk_latt(vport)) {
989 /* One additional decrement on node reference count to
990 * trigger the release of the node
996 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
997 "FLOGI cmpl: status:x%x/x%x state:x%x",
998 irsp->ulpStatus, irsp->un.ulpWord[4],
1001 if (irsp->ulpStatus) {
1003 * In case of FIP mode, perform roundrobin FCF failover
1004 * due to new FCF discovery
1006 if ((phba->hba_flag & HBA_FIP_SUPPORT) &&
1007 (phba->fcf.fcf_flag & FCF_DISCOVERY)) {
1008 if (phba->link_state < LPFC_LINK_UP)
1009 goto stop_rr_fcf_flogi;
1010 if ((phba->fcoe_cvl_eventtag_attn ==
1011 phba->fcoe_cvl_eventtag) &&
1012 (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
1013 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1015 goto stop_rr_fcf_flogi;
1017 phba->fcoe_cvl_eventtag_attn =
1018 phba->fcoe_cvl_eventtag;
1019 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
1020 "2611 FLOGI failed on FCF (x%x), "
1021 "status:x%x/x%x, tmo:x%x, perform "
1022 "roundrobin FCF failover\n",
1023 phba->fcf.current_rec.fcf_indx,
1024 irsp->ulpStatus, irsp->un.ulpWord[4],
1026 lpfc_sli4_set_fcf_flogi_fail(phba,
1027 phba->fcf.current_rec.fcf_indx);
1028 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
1029 rc = lpfc_sli4_fcf_rr_next_proc(vport, fcf_index);
1036 if (!(irsp->ulpStatus == IOSTAT_LOCAL_REJECT &&
1037 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1038 IOERR_LOOP_OPEN_FAILURE)))
1039 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1040 "2858 FLOGI failure Status:x%x/x%x TMO"
1041 ":x%x Data x%x x%x\n",
1042 irsp->ulpStatus, irsp->un.ulpWord[4],
1043 irsp->ulpTimeout, phba->hba_flag,
1044 phba->fcf.fcf_flag);
1046 /* Check for retry */
1047 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
1050 lpfc_printf_vlog(vport, KERN_WARNING, LOG_TRACE_EVENT,
1051 "0150 FLOGI failure Status:x%x/x%x "
1052 "xri x%x TMO:x%x\n",
1053 irsp->ulpStatus, irsp->un.ulpWord[4],
1054 cmdiocb->sli4_xritag, irsp->ulpTimeout);
1056 /* If this is not a loop open failure, bail out */
1057 if (!(irsp->ulpStatus == IOSTAT_LOCAL_REJECT &&
1058 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1059 IOERR_LOOP_OPEN_FAILURE)))
1062 /* FLOGI failed, so there is no fabric */
1063 spin_lock_irq(shost->host_lock);
1064 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
1065 spin_unlock_irq(shost->host_lock);
1067 /* If private loop, then allow max outstanding els to be
1068 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
1069 * alpa map would take too long otherwise.
1071 if (phba->alpa_map[0] == 0)
1072 vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
1073 if ((phba->sli_rev == LPFC_SLI_REV4) &&
1074 (!(vport->fc_flag & FC_VFI_REGISTERED) ||
1075 (vport->fc_prevDID != vport->fc_myDID) ||
1076 phba->fc_topology_changed)) {
1077 if (vport->fc_flag & FC_VFI_REGISTERED) {
1078 if (phba->fc_topology_changed) {
1079 lpfc_unregister_fcf_prep(phba);
1080 spin_lock_irq(shost->host_lock);
1081 vport->fc_flag &= ~FC_VFI_REGISTERED;
1082 spin_unlock_irq(shost->host_lock);
1083 phba->fc_topology_changed = 0;
1085 lpfc_sli4_unreg_all_rpis(vport);
1089 /* Do not register VFI if the driver aborted FLOGI */
1090 if (!lpfc_error_lost_link(irsp))
1091 lpfc_issue_reg_vfi(vport);
1098 spin_lock_irq(shost->host_lock);
1099 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
1100 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
1101 spin_unlock_irq(shost->host_lock);
1104 * The FLogI succeeded. Sync the data for the CPU before
1107 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
1110 sp = prsp->virt + sizeof(uint32_t);
1112 /* FLOGI completes successfully */
1113 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1114 "0101 FLOGI completes successfully, I/O tag:x%x, "
1115 "xri x%x Data: x%x x%x x%x x%x x%x %x\n",
1116 cmdiocb->iotag, cmdiocb->sli4_xritag,
1117 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
1118 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution,
1119 vport->port_state, vport->fc_flag);
1121 if (vport->port_state == LPFC_FLOGI) {
1123 * If Common Service Parameters indicate Nport
1124 * we are point to point, if Fport we are Fabric.
1127 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
1128 else if (!(phba->hba_flag & HBA_FCOE_MODE))
1129 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
1131 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1132 "2831 FLOGI response with cleared Fabric "
1133 "bit fcf_index 0x%x "
1134 "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x "
1136 "%02x%02x%02x%02x%02x%02x%02x%02x\n",
1137 phba->fcf.current_rec.fcf_indx,
1138 phba->fcf.current_rec.switch_name[0],
1139 phba->fcf.current_rec.switch_name[1],
1140 phba->fcf.current_rec.switch_name[2],
1141 phba->fcf.current_rec.switch_name[3],
1142 phba->fcf.current_rec.switch_name[4],
1143 phba->fcf.current_rec.switch_name[5],
1144 phba->fcf.current_rec.switch_name[6],
1145 phba->fcf.current_rec.switch_name[7],
1146 phba->fcf.current_rec.fabric_name[0],
1147 phba->fcf.current_rec.fabric_name[1],
1148 phba->fcf.current_rec.fabric_name[2],
1149 phba->fcf.current_rec.fabric_name[3],
1150 phba->fcf.current_rec.fabric_name[4],
1151 phba->fcf.current_rec.fabric_name[5],
1152 phba->fcf.current_rec.fabric_name[6],
1153 phba->fcf.current_rec.fabric_name[7]);
1156 spin_lock_irq(&phba->hbalock);
1157 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
1158 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
1159 spin_unlock_irq(&phba->hbalock);
1160 phba->fcf.fcf_redisc_attempted = 0; /* reset */
1164 /* Mark the FCF discovery process done */
1165 if (phba->hba_flag & HBA_FIP_SUPPORT)
1166 lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP |
1168 "2769 FLOGI to FCF (x%x) "
1169 "completed successfully\n",
1170 phba->fcf.current_rec.fcf_indx);
1171 spin_lock_irq(&phba->hbalock);
1172 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
1173 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
1174 spin_unlock_irq(&phba->hbalock);
1175 phba->fcf.fcf_redisc_attempted = 0; /* reset */
1181 spin_lock_irq(&phba->hbalock);
1182 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
1183 spin_unlock_irq(&phba->hbalock);
1186 if (!lpfc_error_lost_link(irsp)) {
1187 /* FLOGI failed, so just use loop map to make discovery list */
1188 lpfc_disc_list_loopmap(vport);
1190 /* Start discovery */
1191 lpfc_disc_start(vport);
1192 } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
1193 (((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
1194 IOERR_SLI_ABORTED) &&
1195 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
1196 IOERR_SLI_DOWN))) &&
1197 (phba->link_state != LPFC_CLEAR_LA)) {
1198 /* If FLOGI failed enable link interrupt. */
1199 lpfc_issue_clear_la(phba, vport);
1202 lpfc_els_free_iocb(phba, cmdiocb);
1207 * lpfc_cmpl_els_link_down - Completion callback function for ELS command
1208 * aborted during a link down
1209 * @phba: pointer to lpfc hba data structure.
1210 * @cmdiocb: pointer to lpfc command iocb data structure.
1211 * @rspiocb: pointer to lpfc response iocb data structure.
1215 lpfc_cmpl_els_link_down(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1216 struct lpfc_iocbq *rspiocb)
1222 pcmd = (uint32_t *)(((struct lpfc_dmabuf *)cmdiocb->context2)->virt);
1224 irsp = &rspiocb->iocb;
1226 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1227 "6445 ELS completes after LINK_DOWN: "
1228 " Status %x/%x cmd x%x flg x%x\n",
1229 irsp->ulpStatus, irsp->un.ulpWord[4], cmd,
1230 cmdiocb->iocb_flag);
1232 if (cmdiocb->iocb_flag & LPFC_IO_FABRIC) {
1233 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
1234 atomic_dec(&phba->fabric_iocb_count);
1236 lpfc_els_free_iocb(phba, cmdiocb);
1240 * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport
1241 * @vport: pointer to a host virtual N_Port data structure.
1242 * @ndlp: pointer to a node-list data structure.
1243 * @retry: number of retries to the command IOCB.
1245 * This routine issues a Fabric Login (FLOGI) Request ELS command
1246 * for a @vport. The initiator service parameters are put into the payload
1247 * of the FLOGI Request IOCB and the top-level callback function pointer
1248 * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
1249 * function field. The lpfc_issue_fabric_iocb routine is invoked to send
1250 * out FLOGI ELS command with one outstanding fabric IOCB at a time.
1252 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1253 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1254 * will be stored into the context1 field of the IOCB for the completion
1255 * callback function to the FLOGI ELS command.
1258 * 0 - successfully issued flogi iocb for @vport
1259 * 1 - failed to issue flogi iocb for @vport
1262 lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1265 struct lpfc_hba *phba = vport->phba;
1266 struct serv_parm *sp;
1268 struct lpfc_iocbq *elsiocb;
1269 struct lpfc_iocbq defer_flogi_acc;
1275 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
1276 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1277 ndlp->nlp_DID, ELS_CMD_FLOGI);
1282 icmd = &elsiocb->iocb;
1283 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1285 /* For FLOGI request, remainder of payload is service parameters */
1286 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
1287 pcmd += sizeof(uint32_t);
1288 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
1289 sp = (struct serv_parm *) pcmd;
1291 /* Setup CSPs accordingly for Fabric */
1292 sp->cmn.e_d_tov = 0;
1293 sp->cmn.w2.r_a_tov = 0;
1294 sp->cmn.virtual_fabric_support = 0;
1295 sp->cls1.classValid = 0;
1296 if (sp->cmn.fcphLow < FC_PH3)
1297 sp->cmn.fcphLow = FC_PH3;
1298 if (sp->cmn.fcphHigh < FC_PH3)
1299 sp->cmn.fcphHigh = FC_PH3;
1301 if (phba->sli_rev == LPFC_SLI_REV4) {
1302 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
1303 LPFC_SLI_INTF_IF_TYPE_0) {
1304 elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1);
1305 elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1);
1306 /* FLOGI needs to be 3 for WQE FCFI */
1307 /* Set the fcfi to the fcfi we registered with */
1308 elsiocb->iocb.ulpContext = phba->fcf.fcfi;
1310 /* Can't do SLI4 class2 without support sequence coalescing */
1311 sp->cls2.classValid = 0;
1312 sp->cls2.seqDelivery = 0;
1314 /* Historical, setting sequential-delivery bit for SLI3 */
1315 sp->cls2.seqDelivery = (sp->cls2.classValid) ? 1 : 0;
1316 sp->cls3.seqDelivery = (sp->cls3.classValid) ? 1 : 0;
1317 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
1318 sp->cmn.request_multiple_Nport = 1;
1319 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
1323 sp->cmn.request_multiple_Nport = 0;
1326 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
1327 icmd->un.elsreq64.myID = 0;
1328 icmd->un.elsreq64.fl = 1;
1331 tmo = phba->fc_ratov;
1332 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
1333 lpfc_set_disctmo(vport);
1334 phba->fc_ratov = tmo;
1336 phba->fc_stat.elsXmitFLOGI++;
1337 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
1339 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1340 "Issue FLOGI: opt:x%x",
1341 phba->sli3_options, 0, 0);
1343 elsiocb->context1 = lpfc_nlp_get(ndlp);
1344 if (!elsiocb->context1)
1347 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
1348 if (rc == IOCB_ERROR)
1351 phba->hba_flag |= HBA_FLOGI_ISSUED;
1353 /* Check for a deferred FLOGI ACC condition */
1354 if (phba->defer_flogi_acc_flag) {
1355 did = vport->fc_myDID;
1356 vport->fc_myDID = Fabric_DID;
1358 memset(&defer_flogi_acc, 0, sizeof(struct lpfc_iocbq));
1360 defer_flogi_acc.iocb.ulpContext = phba->defer_flogi_acc_rx_id;
1361 defer_flogi_acc.iocb.unsli3.rcvsli3.ox_id =
1362 phba->defer_flogi_acc_ox_id;
1364 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1365 "3354 Xmit deferred FLOGI ACC: rx_id: x%x,"
1366 " ox_id: x%x, hba_flag x%x\n",
1367 phba->defer_flogi_acc_rx_id,
1368 phba->defer_flogi_acc_ox_id, phba->hba_flag);
1370 /* Send deferred FLOGI ACC */
1371 lpfc_els_rsp_acc(vport, ELS_CMD_FLOGI, &defer_flogi_acc,
1374 phba->defer_flogi_acc_flag = false;
1376 vport->fc_myDID = did;
1382 lpfc_els_free_iocb(phba, elsiocb);
1387 * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs
1388 * @phba: pointer to lpfc hba data structure.
1390 * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
1391 * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
1392 * list and issues an abort IOCB commond on each outstanding IOCB that
1393 * contains a active Fabric_DID ndlp. Note that this function is to issue
1394 * the abort IOCB command on all the outstanding IOCBs, thus when this
1395 * function returns, it does not guarantee all the IOCBs are actually aborted.
1398 * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0)
1401 lpfc_els_abort_flogi(struct lpfc_hba *phba)
1403 struct lpfc_sli_ring *pring;
1404 struct lpfc_iocbq *iocb, *next_iocb;
1405 struct lpfc_nodelist *ndlp;
1408 /* Abort outstanding I/O on NPort <nlp_DID> */
1409 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
1410 "0201 Abort outstanding I/O on NPort x%x\n",
1413 pring = lpfc_phba_elsring(phba);
1414 if (unlikely(!pring))
1418 * Check the txcmplq for an iocb that matches the nport the driver is
1421 spin_lock_irq(&phba->hbalock);
1422 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
1424 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR) {
1425 ndlp = (struct lpfc_nodelist *)(iocb->context1);
1426 if (ndlp && (ndlp->nlp_DID == Fabric_DID))
1427 lpfc_sli_issue_abort_iotag(phba, pring, iocb,
1431 spin_unlock_irq(&phba->hbalock);
1437 * lpfc_initial_flogi - Issue an initial fabric login for a vport
1438 * @vport: pointer to a host virtual N_Port data structure.
1440 * This routine issues an initial Fabric Login (FLOGI) for the @vport
1441 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1442 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1443 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1444 * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
1445 * is then invoked with the @vport and the ndlp to perform the FLOGI for the
1449 * 0 - failed to issue initial flogi for @vport
1450 * 1 - successfully issued initial flogi for @vport
1453 lpfc_initial_flogi(struct lpfc_vport *vport)
1455 struct lpfc_nodelist *ndlp;
1457 vport->port_state = LPFC_FLOGI;
1458 lpfc_set_disctmo(vport);
1460 /* First look for the Fabric ndlp */
1461 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1463 /* Cannot find existing Fabric ndlp, so allocate a new one */
1464 ndlp = lpfc_nlp_init(vport, Fabric_DID);
1467 /* Set the node type */
1468 ndlp->nlp_type |= NLP_FABRIC;
1470 /* Put ndlp onto node list */
1471 lpfc_enqueue_node(vport, ndlp);
1474 if (lpfc_issue_els_flogi(vport, ndlp, 0)) {
1475 /* This decrement of reference count to node shall kick off
1476 * the release of the node.
1485 * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport
1486 * @vport: pointer to a host virtual N_Port data structure.
1488 * This routine issues an initial Fabric Discover (FDISC) for the @vport
1489 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1490 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1491 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1492 * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
1493 * is then invoked with the @vport and the ndlp to perform the FDISC for the
1497 * 0 - failed to issue initial fdisc for @vport
1498 * 1 - successfully issued initial fdisc for @vport
1501 lpfc_initial_fdisc(struct lpfc_vport *vport)
1503 struct lpfc_nodelist *ndlp;
1505 /* First look for the Fabric ndlp */
1506 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1508 /* Cannot find existing Fabric ndlp, so allocate a new one */
1509 ndlp = lpfc_nlp_init(vport, Fabric_DID);
1513 /* NPIV is only supported in Fabrics. */
1514 ndlp->nlp_type |= NLP_FABRIC;
1516 /* Put ndlp onto node list */
1517 lpfc_enqueue_node(vport, ndlp);
1520 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
1521 /* decrement node reference count to trigger the release of
1531 * lpfc_more_plogi - Check and issue remaining plogis for a vport
1532 * @vport: pointer to a host virtual N_Port data structure.
1534 * This routine checks whether there are more remaining Port Logins
1535 * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
1536 * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
1537 * to issue ELS PLOGIs up to the configured discover threads with the
1538 * @vport (@vport->cfg_discovery_threads). The function also decrement
1539 * the @vport's num_disc_node by 1 if it is not already 0.
1542 lpfc_more_plogi(struct lpfc_vport *vport)
1544 if (vport->num_disc_nodes)
1545 vport->num_disc_nodes--;
1547 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
1548 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1549 "0232 Continue discovery with %d PLOGIs to go "
1550 "Data: x%x x%x x%x\n",
1551 vport->num_disc_nodes, vport->fc_plogi_cnt,
1552 vport->fc_flag, vport->port_state);
1553 /* Check to see if there are more PLOGIs to be sent */
1554 if (vport->fc_flag & FC_NLP_MORE)
1555 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
1556 lpfc_els_disc_plogi(vport);
1562 * lpfc_plogi_confirm_nport - Confirm plogi wwpn matches stored ndlp
1563 * @phba: pointer to lpfc hba data structure.
1564 * @prsp: pointer to response IOCB payload.
1565 * @ndlp: pointer to a node-list data structure.
1567 * This routine checks and indicates whether the WWPN of an N_Port, retrieved
1568 * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
1569 * The following cases are considered N_Port confirmed:
1570 * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
1571 * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
1572 * it does not have WWPN assigned either. If the WWPN is confirmed, the
1573 * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
1574 * 1) if there is a node on vport list other than the @ndlp with the same
1575 * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
1576 * on that node to release the RPI associated with the node; 2) if there is
1577 * no node found on vport list with the same WWPN of the N_Port PLOGI logged
1578 * into, a new node shall be allocated (or activated). In either case, the
1579 * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
1580 * be released and the new_ndlp shall be put on to the vport node list and
1581 * its pointer returned as the confirmed node.
1583 * Note that before the @ndlp got "released", the keepDID from not-matching
1584 * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
1585 * of the @ndlp. This is because the release of @ndlp is actually to put it
1586 * into an inactive state on the vport node list and the vport node list
1587 * management algorithm does not allow two node with a same DID.
1590 * pointer to the PLOGI N_Port @ndlp
1592 static struct lpfc_nodelist *
1593 lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
1594 struct lpfc_nodelist *ndlp)
1596 struct lpfc_vport *vport = ndlp->vport;
1597 struct lpfc_nodelist *new_ndlp;
1598 struct serv_parm *sp;
1599 uint8_t name[sizeof(struct lpfc_name)];
1600 uint32_t rc, keepDID = 0, keep_nlp_flag = 0;
1601 uint32_t keep_new_nlp_flag = 0;
1602 uint16_t keep_nlp_state;
1603 u32 keep_nlp_fc4_type = 0;
1604 struct lpfc_nvme_rport *keep_nrport = NULL;
1605 unsigned long *active_rrqs_xri_bitmap = NULL;
1607 /* Fabric nodes can have the same WWPN so we don't bother searching
1608 * by WWPN. Just return the ndlp that was given to us.
1610 if (ndlp->nlp_type & NLP_FABRIC)
1613 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
1614 memset(name, 0, sizeof(struct lpfc_name));
1616 /* Now we find out if the NPort we are logging into, matches the WWPN
1617 * we have for that ndlp. If not, we have some work to do.
1619 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
1621 /* return immediately if the WWPN matches ndlp */
1622 if (new_ndlp == ndlp)
1625 if (phba->sli_rev == LPFC_SLI_REV4) {
1626 active_rrqs_xri_bitmap = mempool_alloc(phba->active_rrq_pool,
1628 if (active_rrqs_xri_bitmap)
1629 memset(active_rrqs_xri_bitmap, 0,
1630 phba->cfg_rrq_xri_bitmap_sz);
1633 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_NODE,
1634 "3178 PLOGI confirm: ndlp x%x x%x x%x: "
1635 "new_ndlp x%x x%x x%x\n",
1636 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_fc4_type,
1637 (new_ndlp ? new_ndlp->nlp_DID : 0),
1638 (new_ndlp ? new_ndlp->nlp_flag : 0),
1639 (new_ndlp ? new_ndlp->nlp_fc4_type : 0));
1642 rc = memcmp(&ndlp->nlp_portname, name,
1643 sizeof(struct lpfc_name));
1645 if (active_rrqs_xri_bitmap)
1646 mempool_free(active_rrqs_xri_bitmap,
1647 phba->active_rrq_pool);
1650 new_ndlp = lpfc_nlp_init(vport, ndlp->nlp_DID);
1652 if (active_rrqs_xri_bitmap)
1653 mempool_free(active_rrqs_xri_bitmap,
1654 phba->active_rrq_pool);
1658 keepDID = new_ndlp->nlp_DID;
1659 if (phba->sli_rev == LPFC_SLI_REV4 &&
1660 active_rrqs_xri_bitmap)
1661 memcpy(active_rrqs_xri_bitmap,
1662 new_ndlp->active_rrqs_xri_bitmap,
1663 phba->cfg_rrq_xri_bitmap_sz);
1666 /* At this point in this routine, we know new_ndlp will be
1667 * returned. however, any previous GID_FTs that were done
1668 * would have updated nlp_fc4_type in ndlp, so we must ensure
1669 * new_ndlp has the right value.
1671 if (vport->fc_flag & FC_FABRIC) {
1672 keep_nlp_fc4_type = new_ndlp->nlp_fc4_type;
1673 new_ndlp->nlp_fc4_type = ndlp->nlp_fc4_type;
1676 lpfc_unreg_rpi(vport, new_ndlp);
1677 new_ndlp->nlp_DID = ndlp->nlp_DID;
1678 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
1679 if (phba->sli_rev == LPFC_SLI_REV4)
1680 memcpy(new_ndlp->active_rrqs_xri_bitmap,
1681 ndlp->active_rrqs_xri_bitmap,
1682 phba->cfg_rrq_xri_bitmap_sz);
1684 /* Lock both ndlps */
1685 spin_lock_irq(&ndlp->lock);
1686 spin_lock_irq(&new_ndlp->lock);
1687 keep_new_nlp_flag = new_ndlp->nlp_flag;
1688 keep_nlp_flag = ndlp->nlp_flag;
1689 new_ndlp->nlp_flag = ndlp->nlp_flag;
1691 /* if new_ndlp had NLP_UNREG_INP set, keep it */
1692 if (keep_new_nlp_flag & NLP_UNREG_INP)
1693 new_ndlp->nlp_flag |= NLP_UNREG_INP;
1695 new_ndlp->nlp_flag &= ~NLP_UNREG_INP;
1697 /* if new_ndlp had NLP_RPI_REGISTERED set, keep it */
1698 if (keep_new_nlp_flag & NLP_RPI_REGISTERED)
1699 new_ndlp->nlp_flag |= NLP_RPI_REGISTERED;
1701 new_ndlp->nlp_flag &= ~NLP_RPI_REGISTERED;
1703 ndlp->nlp_flag = keep_new_nlp_flag;
1705 /* if ndlp had NLP_UNREG_INP set, keep it */
1706 if (keep_nlp_flag & NLP_UNREG_INP)
1707 ndlp->nlp_flag |= NLP_UNREG_INP;
1709 ndlp->nlp_flag &= ~NLP_UNREG_INP;
1711 /* if ndlp had NLP_RPI_REGISTERED set, keep it */
1712 if (keep_nlp_flag & NLP_RPI_REGISTERED)
1713 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
1715 ndlp->nlp_flag &= ~NLP_RPI_REGISTERED;
1717 spin_unlock_irq(&new_ndlp->lock);
1718 spin_unlock_irq(&ndlp->lock);
1720 /* Set nlp_states accordingly */
1721 keep_nlp_state = new_ndlp->nlp_state;
1722 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
1724 /* interchange the nvme remoteport structs */
1725 keep_nrport = new_ndlp->nrport;
1726 new_ndlp->nrport = ndlp->nrport;
1728 /* Move this back to NPR state */
1729 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
1730 /* The new_ndlp is replacing ndlp totally, so we need
1731 * to put ndlp on UNUSED list and try to free it.
1733 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1734 "3179 PLOGI confirm NEW: %x %x\n",
1735 new_ndlp->nlp_DID, keepDID);
1737 /* Two ndlps cannot have the same did on the nodelist.
1738 * Note: for this case, ndlp has a NULL WWPN so setting
1739 * the nlp_fc4_type isn't required.
1741 ndlp->nlp_DID = keepDID;
1742 lpfc_nlp_set_state(vport, ndlp, keep_nlp_state);
1743 if (phba->sli_rev == LPFC_SLI_REV4 &&
1744 active_rrqs_xri_bitmap)
1745 memcpy(ndlp->active_rrqs_xri_bitmap,
1746 active_rrqs_xri_bitmap,
1747 phba->cfg_rrq_xri_bitmap_sz);
1750 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1751 "3180 PLOGI confirm SWAP: %x %x\n",
1752 new_ndlp->nlp_DID, keepDID);
1754 lpfc_unreg_rpi(vport, ndlp);
1756 /* Two ndlps cannot have the same did and the fc4
1757 * type must be transferred because the ndlp is in
1760 ndlp->nlp_DID = keepDID;
1761 ndlp->nlp_fc4_type = keep_nlp_fc4_type;
1763 if (phba->sli_rev == LPFC_SLI_REV4 &&
1764 active_rrqs_xri_bitmap)
1765 memcpy(ndlp->active_rrqs_xri_bitmap,
1766 active_rrqs_xri_bitmap,
1767 phba->cfg_rrq_xri_bitmap_sz);
1769 /* Since we are switching over to the new_ndlp,
1770 * reset the old ndlp state
1772 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
1773 (ndlp->nlp_state == NLP_STE_MAPPED_NODE))
1774 keep_nlp_state = NLP_STE_NPR_NODE;
1775 lpfc_nlp_set_state(vport, ndlp, keep_nlp_state);
1776 ndlp->nrport = keep_nrport;
1780 * If ndlp is not associated with any rport we can drop it here else
1781 * let dev_loss_tmo_callbk trigger DEVICE_RM event
1783 if (!ndlp->rport && (ndlp->nlp_state == NLP_STE_NPR_NODE))
1784 lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM);
1786 if (phba->sli_rev == LPFC_SLI_REV4 &&
1787 active_rrqs_xri_bitmap)
1788 mempool_free(active_rrqs_xri_bitmap,
1789 phba->active_rrq_pool);
1791 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_NODE,
1792 "3173 PLOGI confirm exit: new_ndlp x%x x%x x%x\n",
1793 new_ndlp->nlp_DID, new_ndlp->nlp_flag,
1794 new_ndlp->nlp_fc4_type);
1800 * lpfc_end_rscn - Check and handle more rscn for a vport
1801 * @vport: pointer to a host virtual N_Port data structure.
1803 * This routine checks whether more Registration State Change
1804 * Notifications (RSCNs) came in while the discovery state machine was in
1805 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1806 * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1807 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1808 * handling the RSCNs.
1811 lpfc_end_rscn(struct lpfc_vport *vport)
1813 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1815 if (vport->fc_flag & FC_RSCN_MODE) {
1817 * Check to see if more RSCNs came in while we were
1818 * processing this one.
1820 if (vport->fc_rscn_id_cnt ||
1821 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
1822 lpfc_els_handle_rscn(vport);
1824 spin_lock_irq(shost->host_lock);
1825 vport->fc_flag &= ~FC_RSCN_MODE;
1826 spin_unlock_irq(shost->host_lock);
1832 * lpfc_cmpl_els_rrq - Completion handled for els RRQs.
1833 * @phba: pointer to lpfc hba data structure.
1834 * @cmdiocb: pointer to lpfc command iocb data structure.
1835 * @rspiocb: pointer to lpfc response iocb data structure.
1837 * This routine will call the clear rrq function to free the rrq and
1838 * clear the xri's bit in the ndlp's xri_bitmap. If the ndlp does not
1839 * exist then the clear_rrq is still called because the rrq needs to
1844 lpfc_cmpl_els_rrq(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1845 struct lpfc_iocbq *rspiocb)
1847 struct lpfc_vport *vport = cmdiocb->vport;
1849 struct lpfc_nodelist *ndlp;
1850 struct lpfc_node_rrq *rrq;
1852 /* we pass cmdiocb to state machine which needs rspiocb as well */
1853 rrq = cmdiocb->context_un.rrq;
1854 cmdiocb->context_un.rsp_iocb = rspiocb;
1856 irsp = &rspiocb->iocb;
1857 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1858 "RRQ cmpl: status:x%x/x%x did:x%x",
1859 irsp->ulpStatus, irsp->un.ulpWord[4],
1860 irsp->un.elsreq64.remoteID);
1862 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
1863 if (!ndlp || ndlp != rrq->ndlp) {
1864 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1865 "2882 RRQ completes to NPort x%x "
1866 "with no ndlp. Data: x%x x%x x%x\n",
1867 irsp->un.elsreq64.remoteID,
1868 irsp->ulpStatus, irsp->un.ulpWord[4],
1873 /* rrq completes to NPort <nlp_DID> */
1874 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1875 "2880 RRQ completes to NPort x%x "
1876 "Data: x%x x%x x%x x%x x%x\n",
1877 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1878 irsp->ulpTimeout, rrq->xritag, rrq->rxid);
1880 if (irsp->ulpStatus) {
1881 /* Check for retry */
1882 /* RRQ failed Don't print the vport to vport rjts */
1883 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1884 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1885 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1886 (phba)->pport->cfg_log_verbose & LOG_ELS)
1887 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1888 "2881 RRQ failure DID:%06X Status:"
1890 ndlp->nlp_DID, irsp->ulpStatus,
1891 irsp->un.ulpWord[4]);
1895 lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
1897 lpfc_els_free_iocb(phba, cmdiocb);
1902 * lpfc_cmpl_els_plogi - Completion callback function for plogi
1903 * @phba: pointer to lpfc hba data structure.
1904 * @cmdiocb: pointer to lpfc command iocb data structure.
1905 * @rspiocb: pointer to lpfc response iocb data structure.
1907 * This routine is the completion callback function for issuing the Port
1908 * Login (PLOGI) command. For PLOGI completion, there must be an active
1909 * ndlp on the vport node list that matches the remote node ID from the
1910 * PLOGI response IOCB. If such ndlp does not exist, the PLOGI is simply
1911 * ignored and command IOCB released. The PLOGI response IOCB status is
1912 * checked for error conditons. If there is error status reported, PLOGI
1913 * retry shall be attempted by invoking the lpfc_els_retry() routine.
1914 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1915 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1916 * (DSM) is set for this PLOGI completion. Finally, it checks whether
1917 * there are additional N_Port nodes with the vport that need to perform
1918 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
1922 lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1923 struct lpfc_iocbq *rspiocb)
1925 struct lpfc_vport *vport = cmdiocb->vport;
1926 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1928 struct lpfc_nodelist *ndlp, *free_ndlp;
1929 struct lpfc_dmabuf *prsp;
1932 /* we pass cmdiocb to state machine which needs rspiocb as well */
1933 cmdiocb->context_un.rsp_iocb = rspiocb;
1935 irsp = &rspiocb->iocb;
1936 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1937 "PLOGI cmpl: status:x%x/x%x did:x%x",
1938 irsp->ulpStatus, irsp->un.ulpWord[4],
1939 irsp->un.elsreq64.remoteID);
1941 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
1943 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1944 "0136 PLOGI completes to NPort x%x "
1945 "with no ndlp. Data: x%x x%x x%x\n",
1946 irsp->un.elsreq64.remoteID,
1947 irsp->ulpStatus, irsp->un.ulpWord[4],
1952 /* Since ndlp can be freed in the disc state machine, note if this node
1953 * is being used during discovery.
1955 spin_lock_irq(&ndlp->lock);
1956 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
1957 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1958 spin_unlock_irq(&ndlp->lock);
1960 /* PLOGI completes to NPort <nlp_DID> */
1961 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1962 "0102 PLOGI completes to NPort x%06x "
1963 "Data: x%x x%x x%x x%x x%x\n",
1964 ndlp->nlp_DID, ndlp->nlp_fc4_type,
1965 irsp->ulpStatus, irsp->un.ulpWord[4],
1966 disc, vport->num_disc_nodes);
1968 /* Check to see if link went down during discovery */
1969 if (lpfc_els_chk_latt(vport)) {
1970 spin_lock_irq(&ndlp->lock);
1971 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1972 spin_unlock_irq(&ndlp->lock);
1976 if (irsp->ulpStatus) {
1977 /* Check for retry */
1978 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1979 /* ELS command is being retried */
1981 spin_lock_irq(&ndlp->lock);
1982 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1983 spin_unlock_irq(&ndlp->lock);
1987 /* PLOGI failed Don't print the vport to vport rjts */
1988 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1989 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1990 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1991 (phba)->pport->cfg_log_verbose & LOG_ELS)
1992 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1993 "2753 PLOGI failure DID:%06X Status:x%x/x%x\n",
1994 ndlp->nlp_DID, irsp->ulpStatus,
1995 irsp->un.ulpWord[4]);
1997 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1998 if (lpfc_error_lost_link(irsp))
2001 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2002 NLP_EVT_CMPL_PLOGI);
2004 /* As long as this node is not registered with the scsi or nvme
2005 * transport, it is no longer an active node. Otherwise
2006 * devloss handles the final cleanup.
2008 if (!(ndlp->fc4_xpt_flags & (SCSI_XPT_REGD | NVME_XPT_REGD))) {
2009 spin_lock_irq(&ndlp->lock);
2010 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
2011 spin_unlock_irq(&ndlp->lock);
2012 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2016 /* Good status, call state machine */
2017 prsp = list_entry(((struct lpfc_dmabuf *)
2018 cmdiocb->context2)->list.next,
2019 struct lpfc_dmabuf, list);
2020 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
2021 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2022 NLP_EVT_CMPL_PLOGI);
2026 if (disc && vport->num_disc_nodes) {
2027 /* Check to see if there are more PLOGIs to be sent */
2028 lpfc_more_plogi(vport);
2030 if (vport->num_disc_nodes == 0) {
2031 spin_lock_irq(shost->host_lock);
2032 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2033 spin_unlock_irq(shost->host_lock);
2035 lpfc_can_disctmo(vport);
2036 lpfc_end_rscn(vport);
2041 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
2042 "PLOGI Cmpl PUT: did:x%x refcnt %d",
2043 ndlp->nlp_DID, kref_read(&ndlp->kref), 0);
2045 /* Release the reference on the original I/O request. */
2046 free_ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
2048 lpfc_els_free_iocb(phba, cmdiocb);
2049 lpfc_nlp_put(free_ndlp);
2054 * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
2055 * @vport: pointer to a host virtual N_Port data structure.
2056 * @did: destination port identifier.
2057 * @retry: number of retries to the command IOCB.
2059 * This routine issues a Port Login (PLOGI) command to a remote N_Port
2060 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
2061 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
2062 * This routine constructs the proper feilds of the PLOGI IOCB and invokes
2063 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
2065 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2066 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2067 * will be stored into the context1 field of the IOCB for the completion
2068 * callback function to the PLOGI ELS command.
2071 * 0 - Successfully issued a plogi for @vport
2072 * 1 - failed to issue a plogi for @vport
2075 lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
2077 struct lpfc_hba *phba = vport->phba;
2078 struct Scsi_Host *shost;
2079 struct serv_parm *sp;
2080 struct lpfc_nodelist *ndlp;
2081 struct lpfc_iocbq *elsiocb;
2086 ndlp = lpfc_findnode_did(vport, did);
2089 /* Defer the processing of the issue PLOGI until after the
2090 * outstanding UNREG_RPI mbox command completes, unless we
2091 * are going offline. This logic does not apply for Fabric DIDs
2093 if ((ndlp->nlp_flag & NLP_UNREG_INP) &&
2094 ((ndlp->nlp_DID & Fabric_DID_MASK) != Fabric_DID_MASK) &&
2095 !(vport->fc_flag & FC_OFFLINE_MODE)) {
2096 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2097 "4110 Issue PLOGI x%x deferred "
2098 "on NPort x%x rpi x%x Data: x%px\n",
2099 ndlp->nlp_defer_did, ndlp->nlp_DID,
2100 ndlp->nlp_rpi, ndlp);
2102 /* We can only defer 1st PLOGI */
2103 if (ndlp->nlp_defer_did == NLP_EVT_NOTHING_PENDING)
2104 ndlp->nlp_defer_did = did;
2109 /* If ndlp is not NULL, we will bump the reference count on it */
2110 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
2111 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
2116 shost = lpfc_shost_from_vport(vport);
2117 spin_lock_irq(&ndlp->lock);
2118 ndlp->nlp_flag &= ~NLP_FCP_PRLI_RJT;
2119 spin_unlock_irq(&ndlp->lock);
2121 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2123 /* For PLOGI request, remainder of payload is service parameters */
2124 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
2125 pcmd += sizeof(uint32_t);
2126 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
2127 sp = (struct serv_parm *) pcmd;
2130 * If we are a N-port connected to a Fabric, fix-up paramm's so logins
2131 * to device on remote loops work.
2133 if ((vport->fc_flag & FC_FABRIC) && !(vport->fc_flag & FC_PUBLIC_LOOP))
2134 sp->cmn.altBbCredit = 1;
2136 if (sp->cmn.fcphLow < FC_PH_4_3)
2137 sp->cmn.fcphLow = FC_PH_4_3;
2139 if (sp->cmn.fcphHigh < FC_PH3)
2140 sp->cmn.fcphHigh = FC_PH3;
2142 sp->cmn.valid_vendor_ver_level = 0;
2143 memset(sp->un.vendorVersion, 0, sizeof(sp->un.vendorVersion));
2144 sp->cmn.bbRcvSizeMsb &= 0xF;
2146 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2147 "Issue PLOGI: did:x%x",
2150 /* If our firmware supports this feature, convey that
2151 * information to the target using the vendor specific field.
2153 if (phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) {
2154 sp->cmn.valid_vendor_ver_level = 1;
2155 sp->un.vv.vid = cpu_to_be32(LPFC_VV_EMLX_ID);
2156 sp->un.vv.flags = cpu_to_be32(LPFC_VV_SUPPRESS_RSP);
2159 phba->fc_stat.elsXmitPLOGI++;
2160 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
2162 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2163 "Issue PLOGI: did:x%x refcnt %d",
2164 did, kref_read(&ndlp->kref), 0);
2165 elsiocb->context1 = lpfc_nlp_get(ndlp);
2166 if (!elsiocb->context1)
2169 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
2177 lpfc_els_free_iocb(phba, elsiocb);
2182 * lpfc_cmpl_els_prli - Completion callback function for prli
2183 * @phba: pointer to lpfc hba data structure.
2184 * @cmdiocb: pointer to lpfc command iocb data structure.
2185 * @rspiocb: pointer to lpfc response iocb data structure.
2187 * This routine is the completion callback function for a Process Login
2188 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
2189 * status. If there is error status reported, PRLI retry shall be attempted
2190 * by invoking the lpfc_els_retry() routine. Otherwise, the state
2191 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
2192 * ndlp to mark the PRLI completion.
2195 lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2196 struct lpfc_iocbq *rspiocb)
2198 struct lpfc_vport *vport = cmdiocb->vport;
2200 struct lpfc_nodelist *ndlp;
2204 /* we pass cmdiocb to state machine which needs rspiocb as well */
2205 cmdiocb->context_un.rsp_iocb = rspiocb;
2207 irsp = &(rspiocb->iocb);
2208 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2209 spin_lock_irq(&ndlp->lock);
2210 ndlp->nlp_flag &= ~NLP_PRLI_SND;
2212 /* Driver supports multiple FC4 types. Counters matter. */
2213 vport->fc_prli_sent--;
2214 ndlp->fc4_prli_sent--;
2215 spin_unlock_irq(&ndlp->lock);
2217 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2218 "PRLI cmpl: status:x%x/x%x did:x%x",
2219 irsp->ulpStatus, irsp->un.ulpWord[4],
2222 /* PRLI completes to NPort <nlp_DID> */
2223 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2224 "0103 PRLI completes to NPort x%06x "
2225 "Data: x%x x%x x%x x%x\n",
2226 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2227 vport->num_disc_nodes, ndlp->fc4_prli_sent);
2229 /* Check to see if link went down during discovery */
2230 if (lpfc_els_chk_latt(vport))
2233 if (irsp->ulpStatus) {
2234 /* Check for retry */
2235 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2236 /* ELS command is being retried */
2240 /* If we don't send GFT_ID to Fabric, a PRLI error
2241 * could be expected.
2243 if ((vport->fc_flag & FC_FABRIC) ||
2244 (vport->cfg_enable_fc4_type != LPFC_ENABLE_BOTH)) {
2246 loglevel = LOG_TRACE_EVENT;
2253 lpfc_printf_vlog(vport, mode, loglevel,
2254 "2754 PRLI failure DID:%06X Status:x%x/x%x, "
2256 ndlp->nlp_DID, irsp->ulpStatus,
2257 irsp->un.ulpWord[4], ndlp->fc4_prli_sent);
2259 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2260 if (lpfc_error_lost_link(irsp))
2263 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2266 /* As long as this node is not registered with the SCSI
2267 * or NVMe transport and no other PRLIs are outstanding,
2268 * it is no longer an active node. Otherwise devloss
2269 * handles the final cleanup.
2271 if (!(ndlp->fc4_xpt_flags & (SCSI_XPT_REGD | NVME_XPT_REGD)) &&
2272 !ndlp->fc4_prli_sent) {
2273 spin_lock_irq(&ndlp->lock);
2274 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
2275 spin_unlock_irq(&ndlp->lock);
2276 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2280 /* Good status, call state machine. However, if another
2281 * PRLI is outstanding, don't call the state machine
2282 * because final disposition to Mapped or Unmapped is
2285 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2290 lpfc_els_free_iocb(phba, cmdiocb);
2296 * lpfc_issue_els_prli - Issue a prli iocb command for a vport
2297 * @vport: pointer to a host virtual N_Port data structure.
2298 * @ndlp: pointer to a node-list data structure.
2299 * @retry: number of retries to the command IOCB.
2301 * This routine issues a Process Login (PRLI) ELS command for the
2302 * @vport. The PRLI service parameters are set up in the payload of the
2303 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
2304 * is put to the IOCB completion callback func field before invoking the
2305 * routine lpfc_sli_issue_iocb() to send out PRLI command.
2307 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2308 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2309 * will be stored into the context1 field of the IOCB for the completion
2310 * callback function to the PRLI ELS command.
2313 * 0 - successfully issued prli iocb command for @vport
2314 * 1 - failed to issue prli iocb command for @vport
2317 lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2321 struct lpfc_hba *phba = vport->phba;
2323 struct lpfc_nvme_prli *npr_nvme;
2324 struct lpfc_iocbq *elsiocb;
2327 u32 local_nlp_type, elscmd;
2330 * If we are in RSCN mode, the FC4 types supported from a
2331 * previous GFT_ID command may not be accurate. So, if we
2332 * are a NVME Initiator, always look for the possibility of
2333 * the remote NPort beng a NVME Target.
2335 if (phba->sli_rev == LPFC_SLI_REV4 &&
2336 vport->fc_flag & FC_RSCN_MODE &&
2337 vport->nvmei_support)
2338 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
2339 local_nlp_type = ndlp->nlp_fc4_type;
2341 /* This routine will issue 1 or 2 PRLIs, so zero all the ndlp
2342 * fields here before any of them can complete.
2344 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
2345 ndlp->nlp_type &= ~(NLP_NVME_TARGET | NLP_NVME_INITIATOR);
2346 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
2347 ndlp->nlp_flag &= ~(NLP_FIRSTBURST | NLP_NPR_2B_DISC);
2348 ndlp->nvme_fb_size = 0;
2351 if (local_nlp_type & NLP_FC4_FCP) {
2352 /* Payload is 4 + 16 = 20 x14 bytes. */
2353 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
2354 elscmd = ELS_CMD_PRLI;
2355 } else if (local_nlp_type & NLP_FC4_NVME) {
2356 /* Payload is 4 + 20 = 24 x18 bytes. */
2357 cmdsize = (sizeof(uint32_t) + sizeof(struct lpfc_nvme_prli));
2358 elscmd = ELS_CMD_NVMEPRLI;
2360 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2361 "3083 Unknown FC_TYPE x%x ndlp x%06x\n",
2362 ndlp->nlp_fc4_type, ndlp->nlp_DID);
2366 /* SLI3 ports don't support NVME. If this rport is a strict NVME
2367 * FC4 type, implicitly LOGO.
2369 if (phba->sli_rev == LPFC_SLI_REV3 &&
2370 ndlp->nlp_fc4_type == NLP_FC4_NVME) {
2371 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2372 "3088 Rport fc4 type 0x%x not supported by SLI3 adapter\n",
2374 lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM);
2378 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2379 ndlp->nlp_DID, elscmd);
2383 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2385 /* For PRLI request, remainder of payload is service parameters */
2386 memset(pcmd, 0, cmdsize);
2388 if (local_nlp_type & NLP_FC4_FCP) {
2389 /* Remainder of payload is FCP PRLI parameter page.
2390 * Note: this data structure is defined as
2391 * BE/LE in the structure definition so no
2392 * byte swap call is made.
2394 *((uint32_t *)(pcmd)) = ELS_CMD_PRLI;
2395 pcmd += sizeof(uint32_t);
2399 * If our firmware version is 3.20 or later,
2400 * set the following bits for FC-TAPE support.
2402 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
2403 npr->ConfmComplAllowed = 1;
2405 npr->TaskRetryIdReq = 1;
2407 npr->estabImagePair = 1;
2408 npr->readXferRdyDis = 1;
2409 if (vport->cfg_first_burst_size)
2410 npr->writeXferRdyDis = 1;
2412 /* For FCP support */
2413 npr->prliType = PRLI_FCP_TYPE;
2414 npr->initiatorFunc = 1;
2415 elsiocb->iocb_flag |= LPFC_PRLI_FCP_REQ;
2417 /* Remove FCP type - processed. */
2418 local_nlp_type &= ~NLP_FC4_FCP;
2419 } else if (local_nlp_type & NLP_FC4_NVME) {
2420 /* Remainder of payload is NVME PRLI parameter page.
2421 * This data structure is the newer definition that
2422 * uses bf macros so a byte swap is required.
2424 *((uint32_t *)(pcmd)) = ELS_CMD_NVMEPRLI;
2425 pcmd += sizeof(uint32_t);
2426 npr_nvme = (struct lpfc_nvme_prli *)pcmd;
2427 bf_set(prli_type_code, npr_nvme, PRLI_NVME_TYPE);
2428 bf_set(prli_estabImagePair, npr_nvme, 0); /* Should be 0 */
2430 bf_set(prli_nsler, npr_nvme, 1);
2431 bf_set(prli_conf, npr_nvme, 1);
2434 /* Only initiators request first burst. */
2435 if ((phba->cfg_nvme_enable_fb) &&
2436 !phba->nvmet_support)
2437 bf_set(prli_fba, npr_nvme, 1);
2439 if (phba->nvmet_support) {
2440 bf_set(prli_tgt, npr_nvme, 1);
2441 bf_set(prli_disc, npr_nvme, 1);
2443 bf_set(prli_init, npr_nvme, 1);
2444 bf_set(prli_conf, npr_nvme, 1);
2447 npr_nvme->word1 = cpu_to_be32(npr_nvme->word1);
2448 npr_nvme->word4 = cpu_to_be32(npr_nvme->word4);
2449 elsiocb->iocb_flag |= LPFC_PRLI_NVME_REQ;
2451 /* Remove NVME type - processed. */
2452 local_nlp_type &= ~NLP_FC4_NVME;
2455 phba->fc_stat.elsXmitPRLI++;
2456 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
2457 spin_lock_irq(&ndlp->lock);
2458 ndlp->nlp_flag |= NLP_PRLI_SND;
2460 /* The vport counters are used for lpfc_scan_finished, but
2461 * the ndlp is used to track outstanding PRLIs for different
2464 vport->fc_prli_sent++;
2465 ndlp->fc4_prli_sent++;
2466 spin_unlock_irq(&ndlp->lock);
2468 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2469 "Issue PRLI: did:x%x refcnt %d",
2470 ndlp->nlp_DID, kref_read(&ndlp->kref), 0);
2471 elsiocb->context1 = lpfc_nlp_get(ndlp);
2472 if (!elsiocb->context1)
2475 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
2476 if (rc == IOCB_ERROR)
2480 /* The driver supports 2 FC4 types. Make sure
2481 * a PRLI is issued for all types before exiting.
2483 if (phba->sli_rev == LPFC_SLI_REV4 &&
2484 local_nlp_type & (NLP_FC4_FCP | NLP_FC4_NVME))
2485 goto send_next_prli;
2492 spin_lock_irq(&ndlp->lock);
2493 ndlp->nlp_flag &= ~NLP_PRLI_SND;
2494 spin_unlock_irq(&ndlp->lock);
2495 lpfc_els_free_iocb(phba, elsiocb);
2500 * lpfc_rscn_disc - Perform rscn discovery for a vport
2501 * @vport: pointer to a host virtual N_Port data structure.
2503 * This routine performs Registration State Change Notification (RSCN)
2504 * discovery for a @vport. If the @vport's node port recovery count is not
2505 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
2506 * the nodes that need recovery. If none of the PLOGI were needed through
2507 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
2508 * invoked to check and handle possible more RSCN came in during the period
2509 * of processing the current ones.
2512 lpfc_rscn_disc(struct lpfc_vport *vport)
2514 lpfc_can_disctmo(vport);
2516 /* RSCN discovery */
2517 /* go thru NPR nodes and issue ELS PLOGIs */
2518 if (vport->fc_npr_cnt)
2519 if (lpfc_els_disc_plogi(vport))
2522 lpfc_end_rscn(vport);
2526 * lpfc_adisc_done - Complete the adisc phase of discovery
2527 * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
2529 * This function is called when the final ADISC is completed during discovery.
2530 * This function handles clearing link attention or issuing reg_vpi depending
2531 * on whether npiv is enabled. This function also kicks off the PLOGI phase of
2533 * This function is called with no locks held.
2536 lpfc_adisc_done(struct lpfc_vport *vport)
2538 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2539 struct lpfc_hba *phba = vport->phba;
2542 * For NPIV, cmpl_reg_vpi will set port_state to READY,
2543 * and continue discovery.
2545 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2546 !(vport->fc_flag & FC_RSCN_MODE) &&
2547 (phba->sli_rev < LPFC_SLI_REV4)) {
2548 /* The ADISCs are complete. Doesn't matter if they
2549 * succeeded or failed because the ADISC completion
2550 * routine guarantees to call the state machine and
2551 * the RPI is either unregistered (failed ADISC response)
2552 * or the RPI is still valid and the node is marked
2553 * mapped for a target. The exchanges should be in the
2554 * correct state. This code is specific to SLI3.
2556 lpfc_issue_clear_la(phba, vport);
2557 lpfc_issue_reg_vpi(phba, vport);
2561 * For SLI2, we need to set port_state to READY
2562 * and continue discovery.
2564 if (vport->port_state < LPFC_VPORT_READY) {
2565 /* If we get here, there is nothing to ADISC */
2566 lpfc_issue_clear_la(phba, vport);
2567 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
2568 vport->num_disc_nodes = 0;
2569 /* go thru NPR list, issue ELS PLOGIs */
2570 if (vport->fc_npr_cnt)
2571 lpfc_els_disc_plogi(vport);
2572 if (!vport->num_disc_nodes) {
2573 spin_lock_irq(shost->host_lock);
2574 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2575 spin_unlock_irq(shost->host_lock);
2576 lpfc_can_disctmo(vport);
2577 lpfc_end_rscn(vport);
2580 vport->port_state = LPFC_VPORT_READY;
2582 lpfc_rscn_disc(vport);
2586 * lpfc_more_adisc - Issue more adisc as needed
2587 * @vport: pointer to a host virtual N_Port data structure.
2589 * This routine determines whether there are more ndlps on a @vport
2590 * node list need to have Address Discover (ADISC) issued. If so, it will
2591 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
2592 * remaining nodes which need to have ADISC sent.
2595 lpfc_more_adisc(struct lpfc_vport *vport)
2597 if (vport->num_disc_nodes)
2598 vport->num_disc_nodes--;
2599 /* Continue discovery with <num_disc_nodes> ADISCs to go */
2600 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2601 "0210 Continue discovery with %d ADISCs to go "
2602 "Data: x%x x%x x%x\n",
2603 vport->num_disc_nodes, vport->fc_adisc_cnt,
2604 vport->fc_flag, vport->port_state);
2605 /* Check to see if there are more ADISCs to be sent */
2606 if (vport->fc_flag & FC_NLP_MORE) {
2607 lpfc_set_disctmo(vport);
2608 /* go thru NPR nodes and issue any remaining ELS ADISCs */
2609 lpfc_els_disc_adisc(vport);
2611 if (!vport->num_disc_nodes)
2612 lpfc_adisc_done(vport);
2617 * lpfc_cmpl_els_adisc - Completion callback function for adisc
2618 * @phba: pointer to lpfc hba data structure.
2619 * @cmdiocb: pointer to lpfc command iocb data structure.
2620 * @rspiocb: pointer to lpfc response iocb data structure.
2622 * This routine is the completion function for issuing the Address Discover
2623 * (ADISC) command. It first checks to see whether link went down during
2624 * the discovery process. If so, the node will be marked as node port
2625 * recovery for issuing discover IOCB by the link attention handler and
2626 * exit. Otherwise, the response status is checked. If error was reported
2627 * in the response status, the ADISC command shall be retried by invoking
2628 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
2629 * the response status, the state machine is invoked to set transition
2630 * with respect to NLP_EVT_CMPL_ADISC event.
2633 lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2634 struct lpfc_iocbq *rspiocb)
2636 struct lpfc_vport *vport = cmdiocb->vport;
2638 struct lpfc_nodelist *ndlp;
2641 /* we pass cmdiocb to state machine which needs rspiocb as well */
2642 cmdiocb->context_un.rsp_iocb = rspiocb;
2644 irsp = &(rspiocb->iocb);
2645 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2647 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2648 "ADISC cmpl: status:x%x/x%x did:x%x",
2649 irsp->ulpStatus, irsp->un.ulpWord[4],
2652 /* Since ndlp can be freed in the disc state machine, note if this node
2653 * is being used during discovery.
2655 spin_lock_irq(&ndlp->lock);
2656 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
2657 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
2658 spin_unlock_irq(&ndlp->lock);
2659 /* ADISC completes to NPort <nlp_DID> */
2660 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2661 "0104 ADISC completes to NPort x%x "
2662 "Data: x%x x%x x%x x%x x%x\n",
2663 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2664 irsp->ulpTimeout, disc, vport->num_disc_nodes);
2665 /* Check to see if link went down during discovery */
2666 if (lpfc_els_chk_latt(vport)) {
2667 spin_lock_irq(&ndlp->lock);
2668 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2669 spin_unlock_irq(&ndlp->lock);
2673 if (irsp->ulpStatus) {
2674 /* Check for retry */
2675 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2676 /* ELS command is being retried */
2678 spin_lock_irq(&ndlp->lock);
2679 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2680 spin_unlock_irq(&ndlp->lock);
2681 lpfc_set_disctmo(vport);
2686 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
2687 "2755 ADISC failure DID:%06X Status:x%x/x%x\n",
2688 ndlp->nlp_DID, irsp->ulpStatus,
2689 irsp->un.ulpWord[4]);
2690 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2691 if (lpfc_error_lost_link(irsp))
2694 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2695 NLP_EVT_CMPL_ADISC);
2697 /* As long as this node is not registered with the SCSI or NVMe
2698 * transport, it is no longer an active node. Otherwise
2699 * devloss handles the final cleanup.
2701 if (!(ndlp->fc4_xpt_flags & (SCSI_XPT_REGD | NVME_XPT_REGD))) {
2702 spin_lock_irq(&ndlp->lock);
2703 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
2704 spin_unlock_irq(&ndlp->lock);
2705 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2709 /* Good status, call state machine */
2710 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2711 NLP_EVT_CMPL_ADISC);
2714 /* Check to see if there are more ADISCs to be sent */
2715 if (disc && vport->num_disc_nodes)
2716 lpfc_more_adisc(vport);
2718 lpfc_els_free_iocb(phba, cmdiocb);
2724 * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
2725 * @vport: pointer to a virtual N_Port data structure.
2726 * @ndlp: pointer to a node-list data structure.
2727 * @retry: number of retries to the command IOCB.
2729 * This routine issues an Address Discover (ADISC) for an @ndlp on a
2730 * @vport. It prepares the payload of the ADISC ELS command, updates the
2731 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
2732 * to issue the ADISC ELS command.
2734 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2735 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2736 * will be stored into the context1 field of the IOCB for the completion
2737 * callback function to the ADISC ELS command.
2740 * 0 - successfully issued adisc
2741 * 1 - failed to issue adisc
2744 lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2748 struct lpfc_hba *phba = vport->phba;
2750 struct lpfc_iocbq *elsiocb;
2754 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
2755 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2756 ndlp->nlp_DID, ELS_CMD_ADISC);
2760 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2762 /* For ADISC request, remainder of payload is service parameters */
2763 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
2764 pcmd += sizeof(uint32_t);
2766 /* Fill in ADISC payload */
2767 ap = (ADISC *) pcmd;
2768 ap->hardAL_PA = phba->fc_pref_ALPA;
2769 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2770 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
2771 ap->DID = be32_to_cpu(vport->fc_myDID);
2773 phba->fc_stat.elsXmitADISC++;
2774 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
2775 spin_lock_irq(&ndlp->lock);
2776 ndlp->nlp_flag |= NLP_ADISC_SND;
2777 spin_unlock_irq(&ndlp->lock);
2778 elsiocb->context1 = lpfc_nlp_get(ndlp);
2779 if (!elsiocb->context1)
2782 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2783 "Issue ADISC: did:x%x refcnt %d",
2784 ndlp->nlp_DID, kref_read(&ndlp->kref), 0);
2785 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
2786 if (rc == IOCB_ERROR)
2793 spin_lock_irq(&ndlp->lock);
2794 ndlp->nlp_flag &= ~NLP_ADISC_SND;
2795 spin_unlock_irq(&ndlp->lock);
2796 lpfc_els_free_iocb(phba, elsiocb);
2801 * lpfc_cmpl_els_logo - Completion callback function for logo
2802 * @phba: pointer to lpfc hba data structure.
2803 * @cmdiocb: pointer to lpfc command iocb data structure.
2804 * @rspiocb: pointer to lpfc response iocb data structure.
2806 * This routine is the completion function for issuing the ELS Logout (LOGO)
2807 * command. If no error status was reported from the LOGO response, the
2808 * state machine of the associated ndlp shall be invoked for transition with
2809 * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
2810 * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
2813 lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2814 struct lpfc_iocbq *rspiocb)
2816 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2817 struct lpfc_vport *vport = ndlp->vport;
2819 struct lpfcMboxq *mbox;
2820 unsigned long flags;
2821 uint32_t skip_recovery = 0;
2823 /* we pass cmdiocb to state machine which needs rspiocb as well */
2824 cmdiocb->context_un.rsp_iocb = rspiocb;
2826 irsp = &(rspiocb->iocb);
2827 spin_lock_irq(&ndlp->lock);
2828 ndlp->nlp_flag &= ~NLP_LOGO_SND;
2829 spin_unlock_irq(&ndlp->lock);
2831 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2832 "LOGO cmpl: status:x%x/x%x did:x%x",
2833 irsp->ulpStatus, irsp->un.ulpWord[4],
2836 /* LOGO completes to NPort <nlp_DID> */
2837 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2838 "0105 LOGO completes to NPort x%x "
2839 "refcnt %d nflags x%x Data: x%x x%x x%x x%x\n",
2840 ndlp->nlp_DID, kref_read(&ndlp->kref), ndlp->nlp_flag,
2841 irsp->ulpStatus, irsp->un.ulpWord[4],
2842 irsp->ulpTimeout, vport->num_disc_nodes);
2844 if (lpfc_els_chk_latt(vport)) {
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_TRACE_EVENT,
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);
2870 /* The driver sets this flag for an NPIV instance that doesn't want to
2871 * log into the remote port.
2873 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
2874 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2876 lpfc_els_free_iocb(phba, cmdiocb);
2879 /* Presume the node was released. */
2884 /* Driver is done with the IO. */
2885 lpfc_els_free_iocb(phba, cmdiocb);
2888 /* If we are in pt2pt mode, we could rcv new S_ID on PLOGI */
2889 if ((vport->fc_flag & FC_PT2PT) &&
2890 !(vport->fc_flag & FC_PT2PT_PLOGI)) {
2891 phba->pport->fc_myDID = 0;
2893 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
2894 (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
2895 if (phba->nvmet_support)
2896 lpfc_nvmet_update_targetport(phba);
2898 lpfc_nvme_update_localport(phba->pport);
2901 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2903 lpfc_config_link(phba, mbox);
2904 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
2905 mbox->vport = vport;
2906 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) ==
2908 mempool_free(mbox, phba->mbox_mem_pool);
2915 * If the node is a target, the handling attempts to recover the port.
2916 * For any other port type, the rpi is unregistered as an implicit
2919 if (ndlp->nlp_type & (NLP_FCP_TARGET | NLP_NVME_TARGET) &&
2920 skip_recovery == 0) {
2921 lpfc_cancel_retry_delay_tmo(vport, ndlp);
2922 spin_lock_irqsave(&ndlp->lock, flags);
2923 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2924 spin_unlock_irqrestore(&ndlp->lock, flags);
2926 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2927 "3187 LOGO completes to NPort x%x: Start "
2928 "Recovery Data: x%x x%x x%x x%x\n",
2929 ndlp->nlp_DID, irsp->ulpStatus,
2930 irsp->un.ulpWord[4], irsp->ulpTimeout,
2931 vport->num_disc_nodes);
2932 lpfc_disc_start(vport);
2936 /* Cleanup path for failed REG_RPI handling. If REG_RPI fails, the
2937 * driver sends a LOGO to the rport to cleanup. For fabric and
2938 * initiator ports cleanup the node as long as it the node is not
2939 * register with the transport.
2941 if (!(ndlp->fc4_xpt_flags & (SCSI_XPT_REGD | NVME_XPT_REGD))) {
2942 spin_lock_irq(&ndlp->lock);
2943 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
2944 spin_unlock_irq(&ndlp->lock);
2945 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2951 * lpfc_issue_els_logo - Issue a logo to an node on a vport
2952 * @vport: pointer to a virtual N_Port data structure.
2953 * @ndlp: pointer to a node-list data structure.
2954 * @retry: number of retries to the command IOCB.
2956 * This routine constructs and issues an ELS Logout (LOGO) iocb command
2957 * to a remote node, referred by an @ndlp on a @vport. It constructs the
2958 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
2959 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
2961 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2962 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2963 * will be stored into the context1 field of the IOCB for the completion
2964 * callback function to the LOGO ELS command.
2966 * Callers of this routine are expected to unregister the RPI first
2969 * 0 - successfully issued logo
2970 * 1 - failed to issue logo
2973 lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2976 struct lpfc_hba *phba = vport->phba;
2977 struct lpfc_iocbq *elsiocb;
2982 spin_lock_irq(&ndlp->lock);
2983 if (ndlp->nlp_flag & NLP_LOGO_SND) {
2984 spin_unlock_irq(&ndlp->lock);
2987 spin_unlock_irq(&ndlp->lock);
2989 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
2990 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2991 ndlp->nlp_DID, ELS_CMD_LOGO);
2995 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2996 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
2997 pcmd += sizeof(uint32_t);
2999 /* Fill in LOGO payload */
3000 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
3001 pcmd += sizeof(uint32_t);
3002 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
3004 phba->fc_stat.elsXmitLOGO++;
3005 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
3006 spin_lock_irq(&ndlp->lock);
3007 ndlp->nlp_flag |= NLP_LOGO_SND;
3008 ndlp->nlp_flag &= ~NLP_ISSUE_LOGO;
3009 spin_unlock_irq(&ndlp->lock);
3010 elsiocb->context1 = lpfc_nlp_get(ndlp);
3011 if (!elsiocb->context1)
3014 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3015 "Issue LOGO: did:x%x refcnt %d",
3016 ndlp->nlp_DID, kref_read(&ndlp->kref), 0);
3017 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
3018 if (rc == IOCB_ERROR)
3021 spin_lock_irq(&ndlp->lock);
3022 ndlp->nlp_prev_state = ndlp->nlp_state;
3023 spin_unlock_irq(&ndlp->lock);
3024 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
3030 spin_lock_irq(&ndlp->lock);
3031 ndlp->nlp_flag &= ~NLP_LOGO_SND;
3032 spin_unlock_irq(&ndlp->lock);
3033 lpfc_els_free_iocb(phba, elsiocb);
3038 * lpfc_cmpl_els_cmd - Completion callback function for generic els command
3039 * @phba: pointer to lpfc hba data structure.
3040 * @cmdiocb: pointer to lpfc command iocb data structure.
3041 * @rspiocb: pointer to lpfc response iocb data structure.
3043 * This routine is a generic completion callback function for ELS commands.
3044 * Specifically, it is the callback function which does not need to perform
3045 * any command specific operations. It is currently used by the ELS command
3046 * issuing routines for RSCN, lpfc_issue_els_rscn, and the ELS Fibre Channel
3047 * Address Resolution Protocol Response (FARPR) routine, lpfc_issue_els_farpr().
3048 * Other than certain debug loggings, this callback function simply invokes the
3049 * lpfc_els_chk_latt() routine to check whether link went down during the
3050 * discovery process.
3053 lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3054 struct lpfc_iocbq *rspiocb)
3056 struct lpfc_vport *vport = cmdiocb->vport;
3057 struct lpfc_nodelist *free_ndlp;
3060 irsp = &rspiocb->iocb;
3062 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3063 "ELS cmd cmpl: status:x%x/x%x did:x%x",
3064 irsp->ulpStatus, irsp->un.ulpWord[4],
3065 irsp->un.elsreq64.remoteID);
3067 /* ELS cmd tag <ulpIoTag> completes */
3068 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3069 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
3070 irsp->ulpIoTag, irsp->ulpStatus,
3071 irsp->un.ulpWord[4], irsp->ulpTimeout);
3073 /* Check to see if link went down during discovery */
3074 lpfc_els_chk_latt(vport);
3076 free_ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
3078 lpfc_els_free_iocb(phba, cmdiocb);
3079 lpfc_nlp_put(free_ndlp);
3083 * lpfc_cmpl_els_disc_cmd - Completion callback function for Discovery ELS cmd
3084 * @phba: pointer to lpfc hba data structure.
3085 * @cmdiocb: pointer to lpfc command iocb data structure.
3086 * @rspiocb: pointer to lpfc response iocb data structure.
3088 * This routine is a generic completion callback function for Discovery ELS cmd.
3089 * Currently used by the ELS command issuing routines for the ELS State Change
3090 * Request (SCR), lpfc_issue_els_scr() and the ELS RDF, lpfc_issue_els_rdf().
3091 * These commands will be retried once only for ELS timeout errors.
3094 lpfc_cmpl_els_disc_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3095 struct lpfc_iocbq *rspiocb)
3097 struct lpfc_vport *vport = cmdiocb->vport;
3099 struct lpfc_els_rdf_rsp *prdf;
3100 struct lpfc_dmabuf *pcmd, *prsp;
3103 struct lpfc_nodelist *ndlp = cmdiocb->context1;
3105 irsp = &rspiocb->iocb;
3107 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3108 "ELS cmd cmpl: status:x%x/x%x did:x%x",
3109 irsp->ulpStatus, irsp->un.ulpWord[4],
3110 irsp->un.elsreq64.remoteID);
3111 /* ELS cmd tag <ulpIoTag> completes */
3112 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3113 "0217 ELS cmd tag x%x completes Data: x%x x%x x%x "
3115 irsp->ulpIoTag, irsp->ulpStatus,
3116 irsp->un.ulpWord[4], irsp->ulpTimeout,
3119 pcmd = (struct lpfc_dmabuf *)cmdiocb->context2;
3123 pdata = (u32 *)pcmd->virt;
3128 /* Only 1 retry for ELS Timeout only */
3129 if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT &&
3130 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
3131 IOERR_SEQUENCE_TIMEOUT)) {
3133 if (cmdiocb->retry <= 1) {
3136 lpfc_issue_els_scr(vport, cmdiocb->retry);
3139 cmdiocb->context1 = NULL; /* save ndlp refcnt */
3140 lpfc_issue_els_rdf(vport, cmdiocb->retry);
3145 phba->fc_stat.elsRetryExceeded++;
3147 if (irsp->ulpStatus) {
3148 /* ELS discovery cmd completes with error */
3149 lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS,
3150 "4203 ELS cmd x%x error: x%x x%X\n", cmd,
3151 irsp->ulpStatus, irsp->un.ulpWord[4]);
3155 /* The RDF response doesn't have any impact on the running driver
3156 * but the notification descriptors are dumped here for support.
3158 if (cmd == ELS_CMD_RDF) {
3161 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
3165 prdf = (struct lpfc_els_rdf_rsp *)prsp->virt;
3169 for (i = 0; i < ELS_RDF_REG_TAG_CNT &&
3170 i < be32_to_cpu(prdf->reg_d1.reg_desc.count); i++)
3171 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3172 "4677 Fabric RDF Notification Grant Data: "
3175 prdf->reg_d1.desc_tags[i]));
3179 /* Check to see if link went down during discovery */
3180 lpfc_els_chk_latt(vport);
3181 lpfc_els_free_iocb(phba, cmdiocb);
3187 * lpfc_issue_els_scr - Issue a scr to an node on a vport
3188 * @vport: pointer to a host virtual N_Port data structure.
3189 * @retry: retry counter for the command IOCB.
3191 * This routine issues a State Change Request (SCR) to a fabric node
3192 * on a @vport. The remote node is Fabric Controller (0xfffffd). It
3193 * first search the @vport node list to find the matching ndlp. If no such
3194 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
3195 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
3196 * routine is invoked to send the SCR IOCB.
3198 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3199 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3200 * will be stored into the context1 field of the IOCB for the completion
3201 * callback function to the SCR ELS command.
3204 * 0 - Successfully issued scr command
3205 * 1 - Failed to issue scr command
3208 lpfc_issue_els_scr(struct lpfc_vport *vport, uint8_t retry)
3211 struct lpfc_hba *phba = vport->phba;
3212 struct lpfc_iocbq *elsiocb;
3215 struct lpfc_nodelist *ndlp;
3217 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
3219 ndlp = lpfc_findnode_did(vport, Fabric_Cntl_DID);
3221 ndlp = lpfc_nlp_init(vport, Fabric_Cntl_DID);
3224 lpfc_enqueue_node(vport, ndlp);
3227 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
3228 ndlp->nlp_DID, ELS_CMD_SCR);
3233 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3235 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
3236 pcmd += sizeof(uint32_t);
3238 /* For SCR, remainder of payload is SCR parameter page */
3239 memset(pcmd, 0, sizeof(SCR));
3240 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
3242 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3243 "Issue SCR: did:x%x",
3244 ndlp->nlp_DID, 0, 0);
3246 phba->fc_stat.elsXmitSCR++;
3247 elsiocb->iocb_cmpl = lpfc_cmpl_els_disc_cmd;
3248 elsiocb->context1 = lpfc_nlp_get(ndlp);
3249 if (!elsiocb->context1)
3252 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3253 "Issue SCR: did:x%x refcnt %d",
3254 ndlp->nlp_DID, kref_read(&ndlp->kref), 0);
3256 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
3257 if (rc == IOCB_ERROR)
3260 /* Keep the ndlp just in case RDF is being sent */
3266 lpfc_els_free_iocb(phba, elsiocb);
3271 * lpfc_issue_els_rscn - Issue an RSCN to the Fabric Controller (Fabric)
3272 * or the other nport (pt2pt).
3273 * @vport: pointer to a host virtual N_Port data structure.
3274 * @retry: number of retries to the command IOCB.
3276 * This routine issues a RSCN to the Fabric Controller (DID 0xFFFFFD)
3277 * when connected to a fabric, or to the remote port when connected
3278 * in point-to-point mode. When sent to the Fabric Controller, it will
3279 * replay the RSCN to registered recipients.
3281 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3282 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3283 * will be stored into the context1 field of the IOCB for the completion
3284 * callback function to the RSCN ELS command.
3287 * 0 - Successfully issued RSCN command
3288 * 1 - Failed to issue RSCN command
3291 lpfc_issue_els_rscn(struct lpfc_vport *vport, uint8_t retry)
3294 struct lpfc_hba *phba = vport->phba;
3295 struct lpfc_iocbq *elsiocb;
3296 struct lpfc_nodelist *ndlp;
3298 struct fc_els_rscn rscn;
3299 struct fc_els_rscn_page portid;
3302 uint16_t cmdsize = sizeof(*event);
3304 /* Not supported for private loop */
3305 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP &&
3306 !(vport->fc_flag & FC_PUBLIC_LOOP))
3309 if (vport->fc_flag & FC_PT2PT) {
3310 /* find any mapped nport - that would be the other nport */
3311 ndlp = lpfc_findnode_mapped(vport);
3315 nportid = FC_FID_FCTRL;
3316 /* find the fabric controller node */
3317 ndlp = lpfc_findnode_did(vport, nportid);
3319 /* if one didn't exist, make one */
3320 ndlp = lpfc_nlp_init(vport, nportid);
3323 lpfc_enqueue_node(vport, ndlp);
3327 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
3328 ndlp->nlp_DID, ELS_CMD_RSCN_XMT);
3333 event = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
3335 event->rscn.rscn_cmd = ELS_RSCN;
3336 event->rscn.rscn_page_len = sizeof(struct fc_els_rscn_page);
3337 event->rscn.rscn_plen = cpu_to_be16(cmdsize);
3339 nportid = vport->fc_myDID;
3340 /* appears that page flags must be 0 for fabric to broadcast RSCN */
3341 event->portid.rscn_page_flags = 0;
3342 event->portid.rscn_fid[0] = (nportid & 0x00FF0000) >> 16;
3343 event->portid.rscn_fid[1] = (nportid & 0x0000FF00) >> 8;
3344 event->portid.rscn_fid[2] = nportid & 0x000000FF;
3346 phba->fc_stat.elsXmitRSCN++;
3347 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
3348 elsiocb->context1 = lpfc_nlp_get(ndlp);
3349 if (!elsiocb->context1)
3352 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3353 "Issue RSCN: did:x%x",
3354 ndlp->nlp_DID, 0, 0);
3356 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
3357 if (rc == IOCB_ERROR)
3360 /* This will cause the callback-function lpfc_cmpl_els_cmd to
3361 * trigger the release of node.
3363 if (!(vport->fc_flag & FC_PT2PT))
3369 lpfc_els_free_iocb(phba, elsiocb);
3374 * lpfc_issue_els_farpr - Issue a farp to an node on a vport
3375 * @vport: pointer to a host virtual N_Port data structure.
3376 * @nportid: N_Port identifier to the remote node.
3377 * @retry: number of retries to the command IOCB.
3379 * This routine issues a Fibre Channel Address Resolution Response
3380 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
3381 * is passed into the function. It first search the @vport node list to find
3382 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
3383 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
3384 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
3386 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3387 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3388 * will be stored into the context1 field of the IOCB for the completion
3389 * callback function to the PARPR ELS command.
3392 * 0 - Successfully issued farpr command
3393 * 1 - Failed to issue farpr command
3396 lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
3399 struct lpfc_hba *phba = vport->phba;
3400 struct lpfc_iocbq *elsiocb;
3405 struct lpfc_nodelist *ondlp;
3406 struct lpfc_nodelist *ndlp;
3408 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
3410 ndlp = lpfc_findnode_did(vport, nportid);
3412 ndlp = lpfc_nlp_init(vport, nportid);
3415 lpfc_enqueue_node(vport, ndlp);
3418 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
3419 ndlp->nlp_DID, ELS_CMD_RNID);
3423 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3425 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
3426 pcmd += sizeof(uint32_t);
3428 /* Fill in FARPR payload */
3429 fp = (FARP *) (pcmd);
3430 memset(fp, 0, sizeof(FARP));
3431 lp = (uint32_t *) pcmd;
3432 *lp++ = be32_to_cpu(nportid);
3433 *lp++ = be32_to_cpu(vport->fc_myDID);
3435 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
3437 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
3438 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
3439 ondlp = lpfc_findnode_did(vport, nportid);
3441 memcpy(&fp->OportName, &ondlp->nlp_portname,
3442 sizeof(struct lpfc_name));
3443 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
3444 sizeof(struct lpfc_name));
3447 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3448 "Issue FARPR: did:x%x",
3449 ndlp->nlp_DID, 0, 0);
3451 phba->fc_stat.elsXmitFARPR++;
3452 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
3453 elsiocb->context1 = lpfc_nlp_get(ndlp);
3454 if (!elsiocb->context1) {
3455 lpfc_els_free_iocb(phba, elsiocb);
3459 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
3460 if (rc == IOCB_ERROR) {
3461 /* The additional lpfc_nlp_put will cause the following
3462 * lpfc_els_free_iocb routine to trigger the release of
3466 lpfc_els_free_iocb(phba, elsiocb);
3469 /* This will cause the callback-function lpfc_cmpl_els_cmd to
3470 * trigger the release of the node.
3472 /* Don't release reference count as RDF is likely outstanding */
3477 * lpfc_issue_els_rdf - Register for diagnostic functions from the fabric.
3478 * @vport: pointer to a host virtual N_Port data structure.
3479 * @retry: retry counter for the command IOCB.
3481 * This routine issues an ELS RDF to the Fabric Controller to register
3482 * for diagnostic functions.
3484 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3485 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3486 * will be stored into the context1 field of the IOCB for the completion
3487 * callback function to the RDF ELS command.
3490 * 0 - Successfully issued rdf command
3491 * 1 - Failed to issue rdf command
3494 lpfc_issue_els_rdf(struct lpfc_vport *vport, uint8_t retry)
3496 struct lpfc_hba *phba = vport->phba;
3497 struct lpfc_iocbq *elsiocb;
3498 struct lpfc_els_rdf_req *prdf;
3499 struct lpfc_nodelist *ndlp;
3503 cmdsize = sizeof(*prdf);
3505 ndlp = lpfc_findnode_did(vport, Fabric_Cntl_DID);
3507 ndlp = lpfc_nlp_init(vport, Fabric_Cntl_DID);
3510 lpfc_enqueue_node(vport, ndlp);
3513 /* RDF ELS is not required on an NPIV VN_Port. */
3514 if (vport->port_type == LPFC_NPIV_PORT) {
3519 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
3520 ndlp->nlp_DID, ELS_CMD_RDF);
3524 /* Configure the payload for the supported FPIN events. */
3525 prdf = (struct lpfc_els_rdf_req *)
3526 (((struct lpfc_dmabuf *)elsiocb->context2)->virt);
3527 memset(prdf, 0, cmdsize);
3528 prdf->rdf.fpin_cmd = ELS_RDF;
3529 prdf->rdf.desc_len = cpu_to_be32(sizeof(struct lpfc_els_rdf_req) -
3530 sizeof(struct fc_els_rdf));
3531 prdf->reg_d1.reg_desc.desc_tag = cpu_to_be32(ELS_DTAG_FPIN_REGISTER);
3532 prdf->reg_d1.reg_desc.desc_len = cpu_to_be32(
3533 FC_TLV_DESC_LENGTH_FROM_SZ(prdf->reg_d1));
3534 prdf->reg_d1.reg_desc.count = cpu_to_be32(ELS_RDF_REG_TAG_CNT);
3535 prdf->reg_d1.desc_tags[0] = cpu_to_be32(ELS_DTAG_LNK_INTEGRITY);
3536 prdf->reg_d1.desc_tags[1] = cpu_to_be32(ELS_DTAG_DELIVERY);
3537 prdf->reg_d1.desc_tags[2] = cpu_to_be32(ELS_DTAG_PEER_CONGEST);
3538 prdf->reg_d1.desc_tags[3] = cpu_to_be32(ELS_DTAG_CONGESTION);
3540 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3541 "6444 Xmit RDF to remote NPORT x%x\n",
3544 elsiocb->iocb_cmpl = lpfc_cmpl_els_disc_cmd;
3545 elsiocb->context1 = lpfc_nlp_get(ndlp);
3546 if (!elsiocb->context1)
3549 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3550 "Issue RDF: did:x%x refcnt %d",
3551 ndlp->nlp_DID, kref_read(&ndlp->kref), 0);
3553 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
3554 if (rc == IOCB_ERROR)
3561 lpfc_els_free_iocb(phba, elsiocb);
3566 * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
3567 * @vport: pointer to a host virtual N_Port data structure.
3568 * @nlp: pointer to a node-list data structure.
3570 * This routine cancels the timer with a delayed IOCB-command retry for
3571 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
3572 * removes the ELS retry event if it presents. In addition, if the
3573 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
3574 * commands are sent for the @vport's nodes that require issuing discovery
3578 lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
3580 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3581 struct lpfc_work_evt *evtp;
3583 if (!(nlp->nlp_flag & NLP_DELAY_TMO))
3585 spin_lock_irq(&nlp->lock);
3586 nlp->nlp_flag &= ~NLP_DELAY_TMO;
3587 spin_unlock_irq(&nlp->lock);
3588 del_timer_sync(&nlp->nlp_delayfunc);
3589 nlp->nlp_last_elscmd = 0;
3590 if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
3591 list_del_init(&nlp->els_retry_evt.evt_listp);
3592 /* Decrement nlp reference count held for the delayed retry */
3593 evtp = &nlp->els_retry_evt;
3594 lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
3596 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
3597 spin_lock_irq(&nlp->lock);
3598 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
3599 spin_unlock_irq(&nlp->lock);
3600 if (vport->num_disc_nodes) {
3601 if (vport->port_state < LPFC_VPORT_READY) {
3602 /* Check if there are more ADISCs to be sent */
3603 lpfc_more_adisc(vport);
3605 /* Check if there are more PLOGIs to be sent */
3606 lpfc_more_plogi(vport);
3607 if (vport->num_disc_nodes == 0) {
3608 spin_lock_irq(shost->host_lock);
3609 vport->fc_flag &= ~FC_NDISC_ACTIVE;
3610 spin_unlock_irq(shost->host_lock);
3611 lpfc_can_disctmo(vport);
3612 lpfc_end_rscn(vport);
3621 * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
3622 * @t: pointer to the timer function associated data (ndlp).
3624 * This routine is invoked by the ndlp delayed-function timer to check
3625 * whether there is any pending ELS retry event(s) with the node. If not, it
3626 * simply returns. Otherwise, if there is at least one ELS delayed event, it
3627 * adds the delayed events to the HBA work list and invokes the
3628 * lpfc_worker_wake_up() routine to wake up worker thread to process the
3629 * event. Note that lpfc_nlp_get() is called before posting the event to
3630 * the work list to hold reference count of ndlp so that it guarantees the
3631 * reference to ndlp will still be available when the worker thread gets
3632 * to the event associated with the ndlp.
3635 lpfc_els_retry_delay(struct timer_list *t)
3637 struct lpfc_nodelist *ndlp = from_timer(ndlp, t, nlp_delayfunc);
3638 struct lpfc_vport *vport = ndlp->vport;
3639 struct lpfc_hba *phba = vport->phba;
3640 unsigned long flags;
3641 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
3643 spin_lock_irqsave(&phba->hbalock, flags);
3644 if (!list_empty(&evtp->evt_listp)) {
3645 spin_unlock_irqrestore(&phba->hbalock, flags);
3649 /* We need to hold the node by incrementing the reference
3650 * count until the queued work is done
3652 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
3653 if (evtp->evt_arg1) {
3654 evtp->evt = LPFC_EVT_ELS_RETRY;
3655 list_add_tail(&evtp->evt_listp, &phba->work_list);
3656 lpfc_worker_wake_up(phba);
3658 spin_unlock_irqrestore(&phba->hbalock, flags);
3663 * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
3664 * @ndlp: pointer to a node-list data structure.
3666 * This routine is the worker-thread handler for processing the @ndlp delayed
3667 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
3668 * the last ELS command from the associated ndlp and invokes the proper ELS
3669 * function according to the delayed ELS command to retry the command.
3672 lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
3674 struct lpfc_vport *vport = ndlp->vport;
3675 uint32_t cmd, retry;
3677 spin_lock_irq(&ndlp->lock);
3678 cmd = ndlp->nlp_last_elscmd;
3679 ndlp->nlp_last_elscmd = 0;
3681 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
3682 spin_unlock_irq(&ndlp->lock);
3686 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
3687 spin_unlock_irq(&ndlp->lock);
3689 * If a discovery event readded nlp_delayfunc after timer
3690 * firing and before processing the timer, cancel the
3693 del_timer_sync(&ndlp->nlp_delayfunc);
3694 retry = ndlp->nlp_retry;
3695 ndlp->nlp_retry = 0;
3699 lpfc_issue_els_flogi(vport, ndlp, retry);
3702 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
3703 ndlp->nlp_prev_state = ndlp->nlp_state;
3704 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
3708 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
3709 ndlp->nlp_prev_state = ndlp->nlp_state;
3710 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
3714 case ELS_CMD_NVMEPRLI:
3715 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
3716 ndlp->nlp_prev_state = ndlp->nlp_state;
3717 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
3721 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
3722 ndlp->nlp_prev_state = ndlp->nlp_state;
3723 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
3727 if (!(vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI))
3728 lpfc_issue_els_fdisc(vport, ndlp, retry);
3735 * lpfc_link_reset - Issue link reset
3736 * @vport: pointer to a virtual N_Port data structure.
3738 * This routine performs link reset by sending INIT_LINK mailbox command.
3739 * For SLI-3 adapter, link attention interrupt is enabled before issuing
3740 * INIT_LINK mailbox command.
3743 * 0 - Link reset initiated successfully
3744 * 1 - Failed to initiate link reset
3747 lpfc_link_reset(struct lpfc_vport *vport)
3749 struct lpfc_hba *phba = vport->phba;
3754 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3755 "2851 Attempt link reset\n");
3756 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3758 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
3759 "2852 Failed to allocate mbox memory");
3763 /* Enable Link attention interrupts */
3764 if (phba->sli_rev <= LPFC_SLI_REV3) {
3765 spin_lock_irq(&phba->hbalock);
3766 phba->sli.sli_flag |= LPFC_PROCESS_LA;
3767 control = readl(phba->HCregaddr);
3768 control |= HC_LAINT_ENA;
3769 writel(control, phba->HCregaddr);
3770 readl(phba->HCregaddr); /* flush */
3771 spin_unlock_irq(&phba->hbalock);
3774 lpfc_init_link(phba, mbox, phba->cfg_topology,
3775 phba->cfg_link_speed);
3776 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
3777 mbox->vport = vport;
3778 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
3779 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
3780 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
3781 "2853 Failed to issue INIT_LINK "
3782 "mbox command, rc:x%x\n", rc);
3783 mempool_free(mbox, phba->mbox_mem_pool);
3791 * lpfc_els_retry - Make retry decision on an els command iocb
3792 * @phba: pointer to lpfc hba data structure.
3793 * @cmdiocb: pointer to lpfc command iocb data structure.
3794 * @rspiocb: pointer to lpfc response iocb data structure.
3796 * This routine makes a retry decision on an ELS command IOCB, which has
3797 * failed. The following ELS IOCBs use this function for retrying the command
3798 * when previously issued command responsed with error status: FLOGI, PLOGI,
3799 * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
3800 * returned error status, it makes the decision whether a retry shall be
3801 * issued for the command, and whether a retry shall be made immediately or
3802 * delayed. In the former case, the corresponding ELS command issuing-function
3803 * is called to retry the command. In the later case, the ELS command shall
3804 * be posted to the ndlp delayed event and delayed function timer set to the
3805 * ndlp for the delayed command issusing.
3808 * 0 - No retry of els command is made
3809 * 1 - Immediate or delayed retry of els command is made
3812 lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3813 struct lpfc_iocbq *rspiocb)
3815 struct lpfc_vport *vport = cmdiocb->vport;
3816 IOCB_t *irsp = &rspiocb->iocb;
3817 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3818 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3821 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
3825 int link_reset = 0, rc;
3828 /* Note: context2 may be 0 for internal driver abort
3829 * of delays ELS command.
3832 if (pcmd && pcmd->virt) {
3833 elscmd = (uint32_t *) (pcmd->virt);
3838 did = ndlp->nlp_DID;
3840 /* We should only hit this case for retrying PLOGI */
3841 did = irsp->un.elsreq64.remoteID;
3842 ndlp = lpfc_findnode_did(vport, did);
3843 if (!ndlp && (cmd != ELS_CMD_PLOGI))
3847 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3848 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
3849 *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
3851 switch (irsp->ulpStatus) {
3852 case IOSTAT_FCP_RSP_ERROR:
3854 case IOSTAT_REMOTE_STOP:
3855 if (phba->sli_rev == LPFC_SLI_REV4) {
3856 /* This IO was aborted by the target, we don't
3857 * know the rxid and because we did not send the
3858 * ABTS we cannot generate and RRQ.
3860 lpfc_set_rrq_active(phba, ndlp,
3861 cmdiocb->sli4_lxritag, 0, 0);
3864 case IOSTAT_LOCAL_REJECT:
3865 switch ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK)) {
3866 case IOERR_LOOP_OPEN_FAILURE:
3867 if (cmd == ELS_CMD_FLOGI) {
3868 if (PCI_DEVICE_ID_HORNET ==
3869 phba->pcidev->device) {
3870 phba->fc_topology = LPFC_TOPOLOGY_LOOP;
3871 phba->pport->fc_myDID = 0;
3872 phba->alpa_map[0] = 0;
3873 phba->alpa_map[1] = 0;
3876 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
3881 case IOERR_ILLEGAL_COMMAND:
3882 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3883 "0124 Retry illegal cmd x%x "
3884 "retry:x%x delay:x%x\n",
3885 cmd, cmdiocb->retry, delay);
3887 /* All command's retry policy */
3889 if (cmdiocb->retry > 2)
3893 case IOERR_NO_RESOURCES:
3894 logerr = 1; /* HBA out of resources */
3896 if (cmdiocb->retry > 100)
3901 case IOERR_ILLEGAL_FRAME:
3906 case IOERR_INVALID_RPI:
3907 if (cmd == ELS_CMD_PLOGI &&
3908 did == NameServer_DID) {
3909 /* Continue forever if plogi to */
3910 /* the nameserver fails */
3917 case IOERR_SEQUENCE_TIMEOUT:
3918 if (cmd == ELS_CMD_PLOGI &&
3919 did == NameServer_DID &&
3920 (cmdiocb->retry + 1) == maxretry) {
3921 /* Reset the Link */
3931 case IOSTAT_NPORT_RJT:
3932 case IOSTAT_FABRIC_RJT:
3933 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
3939 case IOSTAT_NPORT_BSY:
3940 case IOSTAT_FABRIC_BSY:
3941 logerr = 1; /* Fabric / Remote NPort out of resources */
3946 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
3947 /* Added for Vendor specifc support
3948 * Just keep retrying for these Rsn / Exp codes
3950 switch (stat.un.b.lsRjtRsnCode) {
3951 case LSRJT_UNABLE_TPC:
3952 /* The driver has a VALID PLOGI but the rport has
3953 * rejected the PRLI - can't do it now. Delay
3954 * for 1 second and try again.
3956 * However, if explanation is REQ_UNSUPPORTED there's
3957 * no point to retry PRLI.
3959 if ((cmd == ELS_CMD_PRLI || cmd == ELS_CMD_NVMEPRLI) &&
3960 stat.un.b.lsRjtRsnCodeExp !=
3961 LSEXP_REQ_UNSUPPORTED) {
3963 maxretry = lpfc_max_els_tries + 1;
3968 /* Legacy bug fix code for targets with PLOGI delays. */
3969 if (stat.un.b.lsRjtRsnCodeExp ==
3970 LSEXP_CMD_IN_PROGRESS) {
3971 if (cmd == ELS_CMD_PLOGI) {
3978 if (stat.un.b.lsRjtRsnCodeExp ==
3979 LSEXP_CANT_GIVE_DATA) {
3980 if (cmd == ELS_CMD_PLOGI) {
3987 if (cmd == ELS_CMD_PLOGI) {
3989 maxretry = lpfc_max_els_tries + 1;
3993 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
3994 (cmd == ELS_CMD_FDISC) &&
3995 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
3996 lpfc_printf_vlog(vport, KERN_ERR,
3998 "0125 FDISC Failed (x%x). "
3999 "Fabric out of resources\n",
4000 stat.un.lsRjtError);
4001 lpfc_vport_set_state(vport,
4002 FC_VPORT_NO_FABRIC_RSCS);
4006 case LSRJT_LOGICAL_BSY:
4007 if ((cmd == ELS_CMD_PLOGI) ||
4008 (cmd == ELS_CMD_PRLI) ||
4009 (cmd == ELS_CMD_NVMEPRLI)) {
4012 } else if (cmd == ELS_CMD_FDISC) {
4013 /* FDISC retry policy */
4015 if (cmdiocb->retry >= 32)
4021 case LSRJT_LOGICAL_ERR:
4022 /* There are some cases where switches return this
4023 * error when they are not ready and should be returning
4024 * Logical Busy. We should delay every time.
4026 if (cmd == ELS_CMD_FDISC &&
4027 stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
4031 } else if (cmd == ELS_CMD_FLOGI &&
4032 stat.un.b.lsRjtRsnCodeExp ==
4033 LSEXP_NOTHING_MORE) {
4034 vport->fc_sparam.cmn.bbRcvSizeMsb &= 0xf;
4036 lpfc_printf_vlog(vport, KERN_ERR,
4038 "0820 FLOGI Failed (x%x). "
4039 "BBCredit Not Supported\n",
4040 stat.un.lsRjtError);
4044 case LSRJT_PROTOCOL_ERR:
4045 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
4046 (cmd == ELS_CMD_FDISC) &&
4047 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
4048 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
4050 lpfc_printf_vlog(vport, KERN_ERR,
4052 "0122 FDISC Failed (x%x). "
4053 "Fabric Detected Bad WWN\n",
4054 stat.un.lsRjtError);
4055 lpfc_vport_set_state(vport,
4056 FC_VPORT_FABRIC_REJ_WWN);
4059 case LSRJT_VENDOR_UNIQUE:
4060 if ((stat.un.b.vendorUnique == 0x45) &&
4061 (cmd == ELS_CMD_FLOGI)) {
4065 case LSRJT_CMD_UNSUPPORTED:
4066 /* lpfc nvmet returns this type of LS_RJT when it
4067 * receives an FCP PRLI because lpfc nvmet only
4068 * support NVME. ELS request is terminated for FCP4
4071 if (stat.un.b.lsRjtRsnCodeExp ==
4072 LSEXP_REQ_UNSUPPORTED && cmd == ELS_CMD_PRLI) {
4073 spin_lock_irq(&ndlp->lock);
4074 ndlp->nlp_flag |= NLP_FCP_PRLI_RJT;
4075 spin_unlock_irq(&ndlp->lock);
4083 case IOSTAT_INTERMED_RSP:
4092 rc = lpfc_link_reset(vport);
4094 /* Do not give up. Retry PLOGI one more time and attempt
4095 * link reset if PLOGI fails again.
4104 if (did == FDMI_DID)
4107 if ((cmd == ELS_CMD_FLOGI) &&
4108 (phba->fc_topology != LPFC_TOPOLOGY_LOOP) &&
4109 !lpfc_error_lost_link(irsp)) {
4110 /* FLOGI retry policy */
4112 /* retry FLOGI forever */
4113 if (phba->link_flag != LS_LOOPBACK_MODE)
4118 if (cmdiocb->retry >= 100)
4120 else if (cmdiocb->retry >= 32)
4122 } else if ((cmd == ELS_CMD_FDISC) && !lpfc_error_lost_link(irsp)) {
4123 /* retry FDISCs every second up to devloss */
4125 maxretry = vport->cfg_devloss_tmo;
4130 if (maxretry && (cmdiocb->retry >= maxretry)) {
4131 phba->fc_stat.elsRetryExceeded++;
4135 if ((vport->load_flag & FC_UNLOADING) != 0)
4140 if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) {
4141 /* Stop retrying PLOGI and FDISC if in FCF discovery */
4142 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
4143 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4144 "2849 Stop retry ELS command "
4145 "x%x to remote NPORT x%x, "
4146 "Data: x%x x%x\n", cmd, did,
4147 cmdiocb->retry, delay);
4152 /* Retry ELS command <elsCmd> to remote NPORT <did> */
4153 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4154 "0107 Retry ELS command x%x to remote "
4155 "NPORT x%x Data: x%x x%x\n",
4156 cmd, did, cmdiocb->retry, delay);
4158 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
4159 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
4160 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
4161 IOERR_NO_RESOURCES))) {
4162 /* Don't reset timer for no resources */
4164 /* If discovery / RSCN timer is running, reset it */
4165 if (timer_pending(&vport->fc_disctmo) ||
4166 (vport->fc_flag & FC_RSCN_MODE))
4167 lpfc_set_disctmo(vport);
4170 phba->fc_stat.elsXmitRetry++;
4171 if (ndlp && delay) {
4172 phba->fc_stat.elsDelayRetry++;
4173 ndlp->nlp_retry = cmdiocb->retry;
4175 /* delay is specified in milliseconds */
4176 mod_timer(&ndlp->nlp_delayfunc,
4177 jiffies + msecs_to_jiffies(delay));
4178 spin_lock_irq(&ndlp->lock);
4179 ndlp->nlp_flag |= NLP_DELAY_TMO;
4180 spin_unlock_irq(&ndlp->lock);
4182 ndlp->nlp_prev_state = ndlp->nlp_state;
4183 if ((cmd == ELS_CMD_PRLI) ||
4184 (cmd == ELS_CMD_NVMEPRLI))
4185 lpfc_nlp_set_state(vport, ndlp,
4186 NLP_STE_PRLI_ISSUE);
4188 lpfc_nlp_set_state(vport, ndlp,
4190 ndlp->nlp_last_elscmd = cmd;
4196 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
4199 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
4203 ndlp->nlp_prev_state = ndlp->nlp_state;
4204 lpfc_nlp_set_state(vport, ndlp,
4205 NLP_STE_PLOGI_ISSUE);
4207 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
4210 ndlp->nlp_prev_state = ndlp->nlp_state;
4211 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
4212 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
4215 case ELS_CMD_NVMEPRLI:
4216 ndlp->nlp_prev_state = ndlp->nlp_state;
4217 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
4218 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
4221 ndlp->nlp_prev_state = ndlp->nlp_state;
4222 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
4223 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
4227 /* No retry ELS command <elsCmd> to remote NPORT <did> */
4229 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
4230 "0137 No retry ELS command x%x to remote "
4231 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
4232 cmd, did, irsp->ulpStatus,
4233 irsp->un.ulpWord[4]);
4236 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4237 "0108 No retry ELS command x%x to remote "
4238 "NPORT x%x Retried:%d Error:x%x/%x\n",
4239 cmd, did, cmdiocb->retry, irsp->ulpStatus,
4240 irsp->un.ulpWord[4]);
4246 * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
4247 * @phba: pointer to lpfc hba data structure.
4248 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
4250 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
4251 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
4252 * checks to see whether there is a lpfc DMA buffer associated with the
4253 * response of the command IOCB. If so, it will be released before releasing
4254 * the lpfc DMA buffer associated with the IOCB itself.
4257 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
4260 lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
4262 struct lpfc_dmabuf *buf_ptr;
4264 /* Free the response before processing the command. */
4265 if (!list_empty(&buf_ptr1->list)) {
4266 list_remove_head(&buf_ptr1->list, buf_ptr,
4269 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
4272 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
4278 * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
4279 * @phba: pointer to lpfc hba data structure.
4280 * @buf_ptr: pointer to the lpfc dma buffer data structure.
4282 * This routine releases the lpfc Direct Memory Access (DMA) buffer
4283 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
4287 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
4290 lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
4292 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
4298 * lpfc_els_free_iocb - Free a command iocb and its associated resources
4299 * @phba: pointer to lpfc hba data structure.
4300 * @elsiocb: pointer to lpfc els command iocb data structure.
4302 * This routine frees a command IOCB and its associated resources. The
4303 * command IOCB data structure contains the reference to various associated
4304 * resources, these fields must be set to NULL if the associated reference
4306 * context1 - reference to ndlp
4307 * context2 - reference to cmd
4308 * context2->next - reference to rsp
4309 * context3 - reference to bpl
4311 * It first properly decrements the reference count held on ndlp for the
4312 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
4313 * set, it invokes the lpfc_els_free_data() routine to release the Direct
4314 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
4315 * adds the DMA buffer the @phba data structure for the delayed release.
4316 * If reference to the Buffer Pointer List (BPL) is present, the
4317 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
4318 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
4319 * invoked to release the IOCB data structure back to @phba IOCBQ list.
4322 * 0 - Success (currently, always return 0)
4325 lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
4327 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
4329 /* The I/O job is complete. Clear the context1 data. */
4330 elsiocb->context1 = NULL;
4332 /* context2 = cmd, context2->next = rsp, context3 = bpl */
4333 if (elsiocb->context2) {
4334 if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
4335 /* Firmware could still be in progress of DMAing
4336 * payload, so don't free data buffer till after
4339 elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
4340 buf_ptr = elsiocb->context2;
4341 elsiocb->context2 = NULL;
4344 spin_lock_irq(&phba->hbalock);
4345 if (!list_empty(&buf_ptr->list)) {
4346 list_remove_head(&buf_ptr->list,
4347 buf_ptr1, struct lpfc_dmabuf,
4349 INIT_LIST_HEAD(&buf_ptr1->list);
4350 list_add_tail(&buf_ptr1->list,
4354 INIT_LIST_HEAD(&buf_ptr->list);
4355 list_add_tail(&buf_ptr->list, &phba->elsbuf);
4357 spin_unlock_irq(&phba->hbalock);
4360 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
4361 lpfc_els_free_data(phba, buf_ptr1);
4362 elsiocb->context2 = NULL;
4366 if (elsiocb->context3) {
4367 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
4368 lpfc_els_free_bpl(phba, buf_ptr);
4369 elsiocb->context3 = NULL;
4371 lpfc_sli_release_iocbq(phba, elsiocb);
4376 * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
4377 * @phba: pointer to lpfc hba data structure.
4378 * @cmdiocb: pointer to lpfc command iocb data structure.
4379 * @rspiocb: pointer to lpfc response iocb data structure.
4381 * This routine is the completion callback function to the Logout (LOGO)
4382 * Accept (ACC) Response ELS command. This routine is invoked to indicate
4383 * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
4384 * release the ndlp if it has the last reference remaining (reference count
4385 * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
4386 * field to NULL to inform the following lpfc_els_free_iocb() routine no
4387 * ndlp reference count needs to be decremented. Otherwise, the ndlp
4388 * reference use-count shall be decremented by the lpfc_els_free_iocb()
4389 * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
4390 * IOCB data structure.
4393 lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
4394 struct lpfc_iocbq *rspiocb)
4396 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
4397 struct lpfc_vport *vport = cmdiocb->vport;
4400 irsp = &rspiocb->iocb;
4401 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4402 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
4403 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
4404 /* ACC to LOGO completes to NPort <nlp_DID> */
4405 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4406 "0109 ACC to LOGO completes to NPort x%x refcnt %d"
4407 "Data: x%x x%x x%x\n",
4408 ndlp->nlp_DID, kref_read(&ndlp->kref), ndlp->nlp_flag,
4409 ndlp->nlp_state, ndlp->nlp_rpi);
4411 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
4412 /* NPort Recovery mode or node is just allocated */
4413 if (!lpfc_nlp_not_used(ndlp)) {
4414 /* If the ndlp is being used by another discovery
4415 * thread, just unregister the RPI.
4417 lpfc_unreg_rpi(vport, ndlp);
4419 /* Indicate the node has already released, should
4420 * not reference to it from within lpfc_els_free_iocb.
4422 cmdiocb->context1 = NULL;
4427 * The driver received a LOGO from the rport and has ACK'd it.
4428 * At this point, the driver is done so release the IOCB
4430 lpfc_els_free_iocb(phba, cmdiocb);
4435 * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
4436 * @phba: pointer to lpfc hba data structure.
4437 * @pmb: pointer to the driver internal queue element for mailbox command.
4439 * This routine is the completion callback function for unregister default
4440 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
4441 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
4442 * decrements the ndlp reference count held for this completion callback
4443 * function. After that, it invokes the lpfc_nlp_not_used() to check
4444 * whether there is only one reference left on the ndlp. If so, it will
4445 * perform one more decrement and trigger the release of the ndlp.
4448 lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4450 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
4451 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
4453 pmb->ctx_buf = NULL;
4454 pmb->ctx_ndlp = NULL;
4456 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4458 mempool_free(pmb, phba->mbox_mem_pool);
4460 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
4461 "0006 rpi x%x DID:%x flg:%x %d x%px\n",
4462 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
4463 kref_read(&ndlp->kref),
4465 /* This is the end of the default RPI cleanup logic for
4466 * this ndlp and it could get released. Clear the nlp_flags to
4467 * prevent any further processing.
4469 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
4471 lpfc_nlp_not_used(ndlp);
4478 * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
4479 * @phba: pointer to lpfc hba data structure.
4480 * @cmdiocb: pointer to lpfc command iocb data structure.
4481 * @rspiocb: pointer to lpfc response iocb data structure.
4483 * This routine is the completion callback function for ELS Response IOCB
4484 * command. In normal case, this callback function just properly sets the
4485 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
4486 * field in the command IOCB is not NULL, the referred mailbox command will
4487 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
4488 * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
4489 * link down event occurred during the discovery, the lpfc_nlp_not_used()
4490 * routine shall be invoked trying to release the ndlp if no other threads
4491 * are currently referring it.
4494 lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
4495 struct lpfc_iocbq *rspiocb)
4497 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
4498 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
4499 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
4502 LPFC_MBOXQ_t *mbox = NULL;
4503 struct lpfc_dmabuf *mp = NULL;
4504 uint32_t ls_rjt = 0;
4506 irsp = &rspiocb->iocb;
4509 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
4510 "3177 ELS response failed\n");
4513 if (cmdiocb->context_un.mbox)
4514 mbox = cmdiocb->context_un.mbox;
4516 /* First determine if this is a LS_RJT cmpl. Note, this callback
4517 * function can have cmdiocb->contest1 (ndlp) field set to NULL.
4519 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
4520 if (ndlp && (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) {
4521 /* A LS_RJT associated with Default RPI cleanup has its own
4522 * separate code path.
4524 if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
4528 /* Check to see if link went down during discovery */
4529 if (!ndlp || lpfc_els_chk_latt(vport)) {
4531 mp = (struct lpfc_dmabuf *)mbox->ctx_buf;
4533 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4536 mempool_free(mbox, phba->mbox_mem_pool);
4538 if (ndlp && (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
4539 if (lpfc_nlp_not_used(ndlp)) {
4541 /* Indicate the node has already released,
4542 * should not reference to it from within
4543 * the routine lpfc_els_free_iocb.
4545 cmdiocb->context1 = NULL;
4550 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4551 "ELS rsp cmpl: status:x%x/x%x did:x%x",
4552 irsp->ulpStatus, irsp->un.ulpWord[4],
4553 cmdiocb->iocb.un.elsreq64.remoteID);
4554 /* ELS response tag <ulpIoTag> completes */
4555 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4556 "0110 ELS response tag x%x completes "
4557 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
4558 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
4559 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
4560 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4563 if ((rspiocb->iocb.ulpStatus == 0) &&
4564 (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
4565 if (!lpfc_unreg_rpi(vport, ndlp) &&
4566 (!(vport->fc_flag & FC_PT2PT))) {
4567 if (ndlp->nlp_state == NLP_STE_REG_LOGIN_ISSUE) {
4568 lpfc_printf_vlog(vport, KERN_INFO,
4572 "Data: x%x x%x x%x\n",
4579 lpfc_mbuf_free(phba, mp->virt,
4583 mempool_free(mbox, phba->mbox_mem_pool);
4588 /* Increment reference count to ndlp to hold the
4589 * reference to ndlp for the callback function.
4591 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
4592 if (!mbox->ctx_ndlp)
4595 mbox->vport = vport;
4596 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
4597 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
4598 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
4601 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
4602 ndlp->nlp_prev_state = ndlp->nlp_state;
4603 lpfc_nlp_set_state(vport, ndlp,
4604 NLP_STE_REG_LOGIN_ISSUE);
4607 ndlp->nlp_flag |= NLP_REG_LOGIN_SEND;
4608 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
4609 != MBX_NOT_FINISHED)
4612 /* Decrement the ndlp reference count we
4613 * set for this failed mailbox command.
4616 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
4618 /* ELS rsp: Cannot issue reg_login for <NPortid> */
4619 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
4620 "0138 ELS rsp: Cannot issue reg_login for x%x "
4621 "Data: x%x x%x x%x\n",
4622 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4625 if (lpfc_nlp_not_used(ndlp)) {
4627 /* Indicate node has already been released,
4628 * should not reference to it from within
4629 * the routine lpfc_els_free_iocb.
4631 cmdiocb->context1 = NULL;
4634 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
4635 if (!lpfc_error_lost_link(irsp) &&
4636 ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
4637 if (lpfc_nlp_not_used(ndlp)) {
4639 /* Indicate node has already been
4640 * released, should not reference
4641 * to it from within the routine
4642 * lpfc_els_free_iocb.
4644 cmdiocb->context1 = NULL;
4648 mp = (struct lpfc_dmabuf *)mbox->ctx_buf;
4650 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4653 mempool_free(mbox, phba->mbox_mem_pool);
4656 if (ndlp && shost) {
4657 spin_lock_irq(&ndlp->lock);
4659 ndlp->nlp_flag &= ~NLP_ACC_REGLOGIN;
4660 ndlp->nlp_flag &= ~NLP_RM_DFLT_RPI;
4661 spin_unlock_irq(&ndlp->lock);
4663 /* If the node is not being used by another discovery thread,
4664 * and we are sending a reject, we are done with it.
4665 * Release driver reference count here and free associated
4669 if (lpfc_nlp_not_used(ndlp))
4670 /* Indicate node has already been released,
4671 * should not reference to it from within
4672 * the routine lpfc_els_free_iocb.
4674 cmdiocb->context1 = NULL;
4677 /* Release the originating I/O reference. */
4678 lpfc_els_free_iocb(phba, cmdiocb);
4684 * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
4685 * @vport: pointer to a host virtual N_Port data structure.
4686 * @flag: the els command code to be accepted.
4687 * @oldiocb: pointer to the original lpfc command iocb data structure.
4688 * @ndlp: pointer to a node-list data structure.
4689 * @mbox: pointer to the driver internal queue element for mailbox command.
4691 * This routine prepares and issues an Accept (ACC) response IOCB
4692 * command. It uses the @flag to properly set up the IOCB field for the
4693 * specific ACC response command to be issued and invokes the
4694 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
4695 * @mbox pointer is passed in, it will be put into the context_un.mbox
4696 * field of the IOCB for the completion callback function to issue the
4697 * mailbox command to the HBA later when callback is invoked.
4699 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4700 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4701 * will be stored into the context1 field of the IOCB for the completion
4702 * callback function to the corresponding response ELS IOCB command.
4705 * 0 - Successfully issued acc response
4706 * 1 - Failed to issue acc response
4709 lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
4710 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
4713 struct lpfc_hba *phba = vport->phba;
4716 struct lpfc_iocbq *elsiocb;
4718 struct serv_parm *sp;
4721 ELS_PKT *els_pkt_ptr;
4723 oldcmd = &oldiocb->iocb;
4727 cmdsize = sizeof(uint32_t);
4728 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
4729 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
4731 spin_lock_irq(&ndlp->lock);
4732 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
4733 spin_unlock_irq(&ndlp->lock);
4737 icmd = &elsiocb->iocb;
4738 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4739 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4740 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4741 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4742 pcmd += sizeof(uint32_t);
4744 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4745 "Issue ACC: did:x%x flg:x%x",
4746 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4750 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
4751 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
4752 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
4756 icmd = &elsiocb->iocb;
4757 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4758 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4759 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4762 elsiocb->context_un.mbox = mbox;
4764 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4765 pcmd += sizeof(uint32_t);
4766 sp = (struct serv_parm *)pcmd;
4768 if (flag == ELS_CMD_FLOGI) {
4769 /* Copy the received service parameters back */
4770 memcpy(sp, &phba->fc_fabparam,
4771 sizeof(struct serv_parm));
4773 /* Clear the F_Port bit */
4776 /* Mark all class service parameters as invalid */
4777 sp->cls1.classValid = 0;
4778 sp->cls2.classValid = 0;
4779 sp->cls3.classValid = 0;
4780 sp->cls4.classValid = 0;
4782 /* Copy our worldwide names */
4783 memcpy(&sp->portName, &vport->fc_sparam.portName,
4784 sizeof(struct lpfc_name));
4785 memcpy(&sp->nodeName, &vport->fc_sparam.nodeName,
4786 sizeof(struct lpfc_name));
4788 memcpy(pcmd, &vport->fc_sparam,
4789 sizeof(struct serv_parm));
4791 sp->cmn.valid_vendor_ver_level = 0;
4792 memset(sp->un.vendorVersion, 0,
4793 sizeof(sp->un.vendorVersion));
4794 sp->cmn.bbRcvSizeMsb &= 0xF;
4796 /* If our firmware supports this feature, convey that
4797 * info to the target using the vendor specific field.
4799 if (phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) {
4800 sp->cmn.valid_vendor_ver_level = 1;
4801 sp->un.vv.vid = cpu_to_be32(LPFC_VV_EMLX_ID);
4803 cpu_to_be32(LPFC_VV_SUPPRESS_RSP);
4807 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4808 "Issue ACC FLOGI/PLOGI: did:x%x flg:x%x",
4809 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4812 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
4813 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
4814 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
4818 icmd = &elsiocb->iocb;
4819 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4820 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4821 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4823 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
4824 sizeof(uint32_t) + sizeof(PRLO));
4825 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
4826 els_pkt_ptr = (ELS_PKT *) pcmd;
4827 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
4829 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4830 "Issue ACC PRLO: did:x%x flg:x%x",
4831 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4836 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
4837 spin_lock_irq(&ndlp->lock);
4838 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED ||
4839 ndlp->nlp_flag & NLP_REG_LOGIN_SEND))
4840 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
4841 spin_unlock_irq(&ndlp->lock);
4842 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
4844 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4847 phba->fc_stat.elsXmitACC++;
4848 elsiocb->context1 = lpfc_nlp_get(ndlp);
4849 if (!elsiocb->context1)
4852 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4853 if (rc == IOCB_ERROR)
4856 /* Xmit ELS ACC response tag <ulpIoTag> */
4857 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4858 "0128 Xmit ELS ACC response Status: x%x, IoTag: x%x, "
4859 "XRI: x%x, DID: x%x, nlp_flag: x%x nlp_state: x%x "
4860 "RPI: x%x, fc_flag x%x\n",
4861 rc, elsiocb->iotag, elsiocb->sli4_xritag,
4862 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4863 ndlp->nlp_rpi, vport->fc_flag);
4869 lpfc_els_free_iocb(phba, elsiocb);
4874 * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command
4875 * @vport: pointer to a virtual N_Port data structure.
4876 * @rejectError: reject response to issue
4877 * @oldiocb: pointer to the original lpfc command iocb data structure.
4878 * @ndlp: pointer to a node-list data structure.
4879 * @mbox: pointer to the driver internal queue element for mailbox command.
4881 * This routine prepares and issue an Reject (RJT) response IOCB
4882 * command. If a @mbox pointer is passed in, it will be put into the
4883 * context_un.mbox field of the IOCB for the completion callback function
4884 * to issue to the HBA later.
4886 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4887 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4888 * will be stored into the context1 field of the IOCB for the completion
4889 * callback function to the reject response ELS IOCB command.
4892 * 0 - Successfully issued reject response
4893 * 1 - Failed to issue reject response
4896 lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
4897 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
4901 struct lpfc_hba *phba = vport->phba;
4904 struct lpfc_iocbq *elsiocb;
4908 cmdsize = 2 * sizeof(uint32_t);
4909 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4910 ndlp->nlp_DID, ELS_CMD_LS_RJT);
4914 icmd = &elsiocb->iocb;
4915 oldcmd = &oldiocb->iocb;
4916 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4917 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4918 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4920 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
4921 pcmd += sizeof(uint32_t);
4922 *((uint32_t *) (pcmd)) = rejectError;
4925 elsiocb->context_un.mbox = mbox;
4927 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
4928 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4929 "0129 Xmit ELS RJT x%x response tag x%x "
4930 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
4932 rejectError, elsiocb->iotag,
4933 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
4934 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
4935 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4936 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
4937 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
4939 phba->fc_stat.elsXmitLSRJT++;
4940 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4941 elsiocb->context1 = lpfc_nlp_get(ndlp);
4942 if (!elsiocb->context1)
4945 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4946 if (rc == IOCB_ERROR)
4954 lpfc_els_free_iocb(phba, elsiocb);
4959 * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
4960 * @vport: pointer to a virtual N_Port data structure.
4961 * @oldiocb: pointer to the original lpfc command iocb data structure.
4962 * @ndlp: pointer to a node-list data structure.
4964 * This routine prepares and issues an Accept (ACC) response to Address
4965 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
4966 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
4968 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4969 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4970 * will be stored into the context1 field of the IOCB for the completion
4971 * callback function to the ADISC Accept response ELS IOCB command.
4974 * 0 - Successfully issued acc adisc response
4975 * 1 - Failed to issue adisc acc response
4978 lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
4979 struct lpfc_nodelist *ndlp)
4981 struct lpfc_hba *phba = vport->phba;
4983 IOCB_t *icmd, *oldcmd;
4984 struct lpfc_iocbq *elsiocb;
4989 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
4990 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4991 ndlp->nlp_DID, ELS_CMD_ACC);
4995 icmd = &elsiocb->iocb;
4996 oldcmd = &oldiocb->iocb;
4997 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4998 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
5000 /* Xmit ADISC ACC response tag <ulpIoTag> */
5001 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5002 "0130 Xmit ADISC ACC response iotag x%x xri: "
5003 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
5004 elsiocb->iotag, elsiocb->iocb.ulpContext,
5005 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5007 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5009 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5010 pcmd += sizeof(uint32_t);
5012 ap = (ADISC *) (pcmd);
5013 ap->hardAL_PA = phba->fc_pref_ALPA;
5014 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
5015 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
5016 ap->DID = be32_to_cpu(vport->fc_myDID);
5018 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
5019 "Issue ACC ADISC: did:x%x flg:x%x refcnt %d",
5020 ndlp->nlp_DID, ndlp->nlp_flag, kref_read(&ndlp->kref));
5022 phba->fc_stat.elsXmitACC++;
5023 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5024 elsiocb->context1 = lpfc_nlp_get(ndlp);
5025 if (!elsiocb->context1)
5028 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5029 if (rc == IOCB_ERROR)
5032 /* Xmit ELS ACC response tag <ulpIoTag> */
5033 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5034 "0128 Xmit ELS ACC response Status: x%x, IoTag: x%x, "
5035 "XRI: x%x, DID: x%x, nlp_flag: x%x nlp_state: x%x "
5036 "RPI: x%x, fc_flag x%x\n",
5037 rc, elsiocb->iotag, elsiocb->sli4_xritag,
5038 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5039 ndlp->nlp_rpi, vport->fc_flag);
5045 lpfc_els_free_iocb(phba, elsiocb);
5050 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
5051 * @vport: pointer to a virtual N_Port data structure.
5052 * @oldiocb: pointer to the original lpfc command iocb data structure.
5053 * @ndlp: pointer to a node-list data structure.
5055 * This routine prepares and issues an Accept (ACC) response to Process
5056 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
5057 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
5059 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5060 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5061 * will be stored into the context1 field of the IOCB for the completion
5062 * callback function to the PRLI Accept response ELS IOCB command.
5065 * 0 - Successfully issued acc prli response
5066 * 1 - Failed to issue acc prli response
5069 lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
5070 struct lpfc_nodelist *ndlp)
5072 struct lpfc_hba *phba = vport->phba;
5074 struct lpfc_nvme_prli *npr_nvme;
5078 struct lpfc_iocbq *elsiocb;
5081 uint32_t prli_fc4_req, *req_payload;
5082 struct lpfc_dmabuf *req_buf;
5086 /* Need the incoming PRLI payload to determine if the ACC is for an
5087 * FC4 or NVME PRLI type. The PRLI type is at word 1.
5089 req_buf = (struct lpfc_dmabuf *)oldiocb->context2;
5090 req_payload = (((uint32_t *)req_buf->virt) + 1);
5092 /* PRLI type payload is at byte 3 for FCP or NVME. */
5093 prli_fc4_req = be32_to_cpu(*req_payload);
5094 prli_fc4_req = (prli_fc4_req >> 24) & 0xff;
5095 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5096 "6127 PRLI_ACC: Req Type x%x, Word1 x%08x\n",
5097 prli_fc4_req, *((uint32_t *)req_payload));
5099 if (prli_fc4_req == PRLI_FCP_TYPE) {
5100 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
5101 elsrspcmd = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
5102 } else if (prli_fc4_req & PRLI_NVME_TYPE) {
5103 cmdsize = sizeof(uint32_t) + sizeof(struct lpfc_nvme_prli);
5104 elsrspcmd = (ELS_CMD_ACC | (ELS_CMD_NVMEPRLI & ~ELS_RSP_MASK));
5109 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
5110 ndlp->nlp_DID, elsrspcmd);
5114 icmd = &elsiocb->iocb;
5115 oldcmd = &oldiocb->iocb;
5116 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
5117 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
5119 /* Xmit PRLI ACC response tag <ulpIoTag> */
5120 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5121 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
5122 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
5123 elsiocb->iotag, elsiocb->iocb.ulpContext,
5124 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5126 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5127 memset(pcmd, 0, cmdsize);
5129 *((uint32_t *)(pcmd)) = elsrspcmd;
5130 pcmd += sizeof(uint32_t);
5132 /* For PRLI, remainder of payload is PRLI parameter page */
5135 if (prli_fc4_req == PRLI_FCP_TYPE) {
5137 * If the remote port is a target and our firmware version
5138 * is 3.20 or later, set the following bits for FC-TAPE
5141 npr = (PRLI *) pcmd;
5142 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
5143 (vpd->rev.feaLevelHigh >= 0x02)) {
5144 npr->ConfmComplAllowed = 1;
5146 npr->TaskRetryIdReq = 1;
5148 npr->acceptRspCode = PRLI_REQ_EXECUTED;
5149 npr->estabImagePair = 1;
5150 npr->readXferRdyDis = 1;
5151 npr->ConfmComplAllowed = 1;
5152 npr->prliType = PRLI_FCP_TYPE;
5153 npr->initiatorFunc = 1;
5154 } else if (prli_fc4_req & PRLI_NVME_TYPE) {
5155 /* Respond with an NVME PRLI Type */
5156 npr_nvme = (struct lpfc_nvme_prli *) pcmd;
5157 bf_set(prli_type_code, npr_nvme, PRLI_NVME_TYPE);
5158 bf_set(prli_estabImagePair, npr_nvme, 0); /* Should be 0 */
5159 bf_set(prli_acc_rsp_code, npr_nvme, PRLI_REQ_EXECUTED);
5160 if (phba->nvmet_support) {
5161 bf_set(prli_tgt, npr_nvme, 1);
5162 bf_set(prli_disc, npr_nvme, 1);
5163 if (phba->cfg_nvme_enable_fb) {
5164 bf_set(prli_fba, npr_nvme, 1);
5166 /* TBD. Target mode needs to post buffers
5167 * that support the configured first burst
5170 bf_set(prli_fb_sz, npr_nvme,
5171 phba->cfg_nvmet_fb_size);
5174 bf_set(prli_init, npr_nvme, 1);
5177 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
5178 "6015 NVME issue PRLI ACC word1 x%08x "
5179 "word4 x%08x word5 x%08x flag x%x, "
5180 "fcp_info x%x nlp_type x%x\n",
5181 npr_nvme->word1, npr_nvme->word4,
5182 npr_nvme->word5, ndlp->nlp_flag,
5183 ndlp->nlp_fcp_info, ndlp->nlp_type);
5184 npr_nvme->word1 = cpu_to_be32(npr_nvme->word1);
5185 npr_nvme->word4 = cpu_to_be32(npr_nvme->word4);
5186 npr_nvme->word5 = cpu_to_be32(npr_nvme->word5);
5188 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5189 "6128 Unknown FC_TYPE x%x x%x ndlp x%06x\n",
5190 prli_fc4_req, ndlp->nlp_fc4_type,
5193 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
5194 "Issue ACC PRLI: did:x%x flg:x%x",
5195 ndlp->nlp_DID, ndlp->nlp_flag, kref_read(&ndlp->kref));
5197 phba->fc_stat.elsXmitACC++;
5198 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5199 elsiocb->context1 = lpfc_nlp_get(ndlp);
5200 if (!elsiocb->context1)
5203 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5204 if (rc == IOCB_ERROR)
5211 lpfc_els_free_iocb(phba, elsiocb);
5216 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
5217 * @vport: pointer to a virtual N_Port data structure.
5218 * @format: rnid command format.
5219 * @oldiocb: pointer to the original lpfc command iocb data structure.
5220 * @ndlp: pointer to a node-list data structure.
5222 * This routine issues a Request Node Identification Data (RNID) Accept
5223 * (ACC) response. It constructs the RNID ACC response command according to
5224 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
5225 * issue the response. Note that this command does not need to hold the ndlp
5226 * reference count for the callback. So, the ndlp reference count taken by
5227 * the lpfc_prep_els_iocb() routine is put back and the context1 field of
5228 * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
5229 * there is no ndlp reference available.
5231 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5232 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5233 * will be stored into the context1 field of the IOCB for the completion
5234 * callback function. However, for the RNID Accept Response ELS command,
5235 * this is undone later by this routine after the IOCB is allocated.
5238 * 0 - Successfully issued acc rnid response
5239 * 1 - Failed to issue acc rnid response
5242 lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
5243 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
5245 struct lpfc_hba *phba = vport->phba;
5247 IOCB_t *icmd, *oldcmd;
5248 struct lpfc_iocbq *elsiocb;
5253 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
5254 + (2 * sizeof(struct lpfc_name));
5256 cmdsize += sizeof(RNID_TOP_DISC);
5258 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
5259 ndlp->nlp_DID, ELS_CMD_ACC);
5263 icmd = &elsiocb->iocb;
5264 oldcmd = &oldiocb->iocb;
5265 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
5266 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
5268 /* Xmit RNID ACC response tag <ulpIoTag> */
5269 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5270 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
5271 elsiocb->iotag, elsiocb->iocb.ulpContext);
5272 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5273 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5274 pcmd += sizeof(uint32_t);
5276 memset(pcmd, 0, sizeof(RNID));
5277 rn = (RNID *) (pcmd);
5278 rn->Format = format;
5279 rn->CommonLen = (2 * sizeof(struct lpfc_name));
5280 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
5281 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
5284 rn->SpecificLen = 0;
5286 case RNID_TOPOLOGY_DISC:
5287 rn->SpecificLen = sizeof(RNID_TOP_DISC);
5288 memcpy(&rn->un.topologyDisc.portName,
5289 &vport->fc_portname, sizeof(struct lpfc_name));
5290 rn->un.topologyDisc.unitType = RNID_HBA;
5291 rn->un.topologyDisc.physPort = 0;
5292 rn->un.topologyDisc.attachedNodes = 0;
5296 rn->SpecificLen = 0;
5300 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
5301 "Issue ACC RNID: did:x%x flg:x%x refcnt %d",
5302 ndlp->nlp_DID, ndlp->nlp_flag, kref_read(&ndlp->kref));
5304 phba->fc_stat.elsXmitACC++;
5305 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5306 elsiocb->context1 = lpfc_nlp_get(ndlp);
5307 if (!elsiocb->context1)
5310 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5311 if (rc == IOCB_ERROR)
5319 lpfc_els_free_iocb(phba, elsiocb);
5324 * lpfc_els_clear_rrq - Clear the rq that this rrq describes.
5325 * @vport: pointer to a virtual N_Port data structure.
5326 * @iocb: pointer to the lpfc command iocb data structure.
5327 * @ndlp: pointer to a node-list data structure.
5332 lpfc_els_clear_rrq(struct lpfc_vport *vport,
5333 struct lpfc_iocbq *iocb, struct lpfc_nodelist *ndlp)
5335 struct lpfc_hba *phba = vport->phba;
5340 struct lpfc_node_rrq *prrq;
5343 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) iocb->context2)->virt);
5344 pcmd += sizeof(uint32_t);
5345 rrq = (struct RRQ *)pcmd;
5346 rrq->rrq_exchg = be32_to_cpu(rrq->rrq_exchg);
5347 rxid = bf_get(rrq_rxid, rrq);
5349 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5350 "2883 Clear RRQ for SID:x%x OXID:x%x RXID:x%x"
5352 be32_to_cpu(bf_get(rrq_did, rrq)),
5353 bf_get(rrq_oxid, rrq),
5355 iocb->iotag, iocb->iocb.ulpContext);
5357 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
5358 "Clear RRQ: did:x%x flg:x%x exchg:x%.08x",
5359 ndlp->nlp_DID, ndlp->nlp_flag, rrq->rrq_exchg);
5360 if (vport->fc_myDID == be32_to_cpu(bf_get(rrq_did, rrq)))
5361 xri = bf_get(rrq_oxid, rrq);
5364 prrq = lpfc_get_active_rrq(vport, xri, ndlp->nlp_DID);
5366 lpfc_clr_rrq_active(phba, xri, prrq);
5371 * lpfc_els_rsp_echo_acc - Issue echo acc response
5372 * @vport: pointer to a virtual N_Port data structure.
5373 * @data: pointer to echo data to return in the accept.
5374 * @oldiocb: pointer to the original lpfc command iocb data structure.
5375 * @ndlp: pointer to a node-list data structure.
5378 * 0 - Successfully issued acc echo response
5379 * 1 - Failed to issue acc echo response
5382 lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data,
5383 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
5385 struct lpfc_hba *phba = vport->phba;
5386 struct lpfc_iocbq *elsiocb;
5391 cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len;
5393 /* The accumulated length can exceed the BPL_SIZE. For
5394 * now, use this as the limit
5396 if (cmdsize > LPFC_BPL_SIZE)
5397 cmdsize = LPFC_BPL_SIZE;
5398 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
5399 ndlp->nlp_DID, ELS_CMD_ACC);
5403 elsiocb->iocb.ulpContext = oldiocb->iocb.ulpContext; /* Xri / rx_id */
5404 elsiocb->iocb.unsli3.rcvsli3.ox_id = oldiocb->iocb.unsli3.rcvsli3.ox_id;
5406 /* Xmit ECHO ACC response tag <ulpIoTag> */
5407 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5408 "2876 Xmit ECHO ACC response tag x%x xri x%x\n",
5409 elsiocb->iotag, elsiocb->iocb.ulpContext);
5410 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5411 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5412 pcmd += sizeof(uint32_t);
5413 memcpy(pcmd, data, cmdsize - sizeof(uint32_t));
5415 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
5416 "Issue ACC ECHO: did:x%x flg:x%x refcnt %d",
5417 ndlp->nlp_DID, ndlp->nlp_flag, kref_read(&ndlp->kref));
5419 phba->fc_stat.elsXmitACC++;
5420 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5421 elsiocb->context1 = lpfc_nlp_get(ndlp);
5422 if (!elsiocb->context1)
5425 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5426 if (rc == IOCB_ERROR)
5433 lpfc_els_free_iocb(phba, elsiocb);
5438 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
5439 * @vport: pointer to a host virtual N_Port data structure.
5441 * This routine issues Address Discover (ADISC) ELS commands to those
5442 * N_Ports which are in node port recovery state and ADISC has not been issued
5443 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
5444 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
5445 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
5446 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
5447 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
5448 * IOCBs quit for later pick up. On the other hand, after walking through
5449 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
5450 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
5451 * no more ADISC need to be sent.
5454 * The number of N_Ports with adisc issued.
5457 lpfc_els_disc_adisc(struct lpfc_vport *vport)
5459 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5460 struct lpfc_nodelist *ndlp, *next_ndlp;
5463 /* go thru NPR nodes and issue any remaining ELS ADISCs */
5464 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
5465 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
5466 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
5467 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
5468 spin_lock_irq(&ndlp->lock);
5469 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
5470 spin_unlock_irq(&ndlp->lock);
5471 ndlp->nlp_prev_state = ndlp->nlp_state;
5472 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
5473 lpfc_issue_els_adisc(vport, ndlp, 0);
5475 vport->num_disc_nodes++;
5476 if (vport->num_disc_nodes >=
5477 vport->cfg_discovery_threads) {
5478 spin_lock_irq(shost->host_lock);
5479 vport->fc_flag |= FC_NLP_MORE;
5480 spin_unlock_irq(shost->host_lock);
5485 if (sentadisc == 0) {
5486 spin_lock_irq(shost->host_lock);
5487 vport->fc_flag &= ~FC_NLP_MORE;
5488 spin_unlock_irq(shost->host_lock);
5494 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
5495 * @vport: pointer to a host virtual N_Port data structure.
5497 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
5498 * which are in node port recovery state, with a @vport. Each time an ELS
5499 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
5500 * the per @vport number of discover count (num_disc_nodes) shall be
5501 * incremented. If the num_disc_nodes reaches a pre-configured threshold
5502 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
5503 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
5504 * later pick up. On the other hand, after walking through all the ndlps with
5505 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
5506 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
5507 * PLOGI need to be sent.
5510 * The number of N_Ports with plogi issued.
5513 lpfc_els_disc_plogi(struct lpfc_vport *vport)
5515 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5516 struct lpfc_nodelist *ndlp, *next_ndlp;
5519 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
5520 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
5521 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
5522 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
5523 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
5524 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
5525 ndlp->nlp_prev_state = ndlp->nlp_state;
5526 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
5527 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
5529 vport->num_disc_nodes++;
5530 if (vport->num_disc_nodes >=
5531 vport->cfg_discovery_threads) {
5532 spin_lock_irq(shost->host_lock);
5533 vport->fc_flag |= FC_NLP_MORE;
5534 spin_unlock_irq(shost->host_lock);
5540 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5541 "6452 Discover PLOGI %d flag x%x\n",
5542 sentplogi, vport->fc_flag);
5545 lpfc_set_disctmo(vport);
5548 spin_lock_irq(shost->host_lock);
5549 vport->fc_flag &= ~FC_NLP_MORE;
5550 spin_unlock_irq(shost->host_lock);
5556 lpfc_rdp_res_link_service(struct fc_rdp_link_service_desc *desc,
5560 desc->tag = cpu_to_be32(RDP_LINK_SERVICE_DESC_TAG);
5561 desc->payload.els_req = word0;
5562 desc->length = cpu_to_be32(sizeof(desc->payload));
5564 return sizeof(struct fc_rdp_link_service_desc);
5568 lpfc_rdp_res_sfp_desc(struct fc_rdp_sfp_desc *desc,
5569 uint8_t *page_a0, uint8_t *page_a2)
5571 uint16_t wavelength;
5572 uint16_t temperature;
5578 struct sff_trasnceiver_codes_byte4 *trasn_code_byte4;
5579 struct sff_trasnceiver_codes_byte5 *trasn_code_byte5;
5581 desc->tag = cpu_to_be32(RDP_SFP_DESC_TAG);
5583 trasn_code_byte4 = (struct sff_trasnceiver_codes_byte4 *)
5584 &page_a0[SSF_TRANSCEIVER_CODE_B4];
5585 trasn_code_byte5 = (struct sff_trasnceiver_codes_byte5 *)
5586 &page_a0[SSF_TRANSCEIVER_CODE_B5];
5588 if ((trasn_code_byte4->fc_sw_laser) ||
5589 (trasn_code_byte5->fc_sw_laser_sl) ||
5590 (trasn_code_byte5->fc_sw_laser_sn)) { /* check if its short WL */
5591 flag |= (SFP_FLAG_PT_SWLASER << SFP_FLAG_PT_SHIFT);
5592 } else if (trasn_code_byte4->fc_lw_laser) {
5593 wavelength = (page_a0[SSF_WAVELENGTH_B1] << 8) |
5594 page_a0[SSF_WAVELENGTH_B0];
5595 if (wavelength == SFP_WAVELENGTH_LC1310)
5596 flag |= SFP_FLAG_PT_LWLASER_LC1310 << SFP_FLAG_PT_SHIFT;
5597 if (wavelength == SFP_WAVELENGTH_LL1550)
5598 flag |= SFP_FLAG_PT_LWLASER_LL1550 << SFP_FLAG_PT_SHIFT;
5600 /* check if its SFP+ */
5601 flag |= ((page_a0[SSF_IDENTIFIER] == SFF_PG0_IDENT_SFP) ?
5602 SFP_FLAG_CT_SFP_PLUS : SFP_FLAG_CT_UNKNOWN)
5603 << SFP_FLAG_CT_SHIFT;
5605 /* check if its OPTICAL */
5606 flag |= ((page_a0[SSF_CONNECTOR] == SFF_PG0_CONNECTOR_LC) ?
5607 SFP_FLAG_IS_OPTICAL_PORT : 0)
5608 << SFP_FLAG_IS_OPTICAL_SHIFT;
5610 temperature = (page_a2[SFF_TEMPERATURE_B1] << 8 |
5611 page_a2[SFF_TEMPERATURE_B0]);
5612 vcc = (page_a2[SFF_VCC_B1] << 8 |
5613 page_a2[SFF_VCC_B0]);
5614 tx_power = (page_a2[SFF_TXPOWER_B1] << 8 |
5615 page_a2[SFF_TXPOWER_B0]);
5616 tx_bias = (page_a2[SFF_TX_BIAS_CURRENT_B1] << 8 |
5617 page_a2[SFF_TX_BIAS_CURRENT_B0]);
5618 rx_power = (page_a2[SFF_RXPOWER_B1] << 8 |
5619 page_a2[SFF_RXPOWER_B0]);
5620 desc->sfp_info.temperature = cpu_to_be16(temperature);
5621 desc->sfp_info.rx_power = cpu_to_be16(rx_power);
5622 desc->sfp_info.tx_bias = cpu_to_be16(tx_bias);
5623 desc->sfp_info.tx_power = cpu_to_be16(tx_power);
5624 desc->sfp_info.vcc = cpu_to_be16(vcc);
5626 desc->sfp_info.flags = cpu_to_be16(flag);
5627 desc->length = cpu_to_be32(sizeof(desc->sfp_info));
5629 return sizeof(struct fc_rdp_sfp_desc);
5633 lpfc_rdp_res_link_error(struct fc_rdp_link_error_status_desc *desc,
5638 desc->tag = cpu_to_be32(RDP_LINK_ERROR_STATUS_DESC_TAG);
5640 type = VN_PT_PHY_PF_PORT << VN_PT_PHY_SHIFT;
5642 desc->info.port_type = cpu_to_be32(type);
5644 desc->info.link_status.link_failure_cnt =
5645 cpu_to_be32(stat->linkFailureCnt);
5646 desc->info.link_status.loss_of_synch_cnt =
5647 cpu_to_be32(stat->lossSyncCnt);
5648 desc->info.link_status.loss_of_signal_cnt =
5649 cpu_to_be32(stat->lossSignalCnt);
5650 desc->info.link_status.primitive_seq_proto_err =
5651 cpu_to_be32(stat->primSeqErrCnt);
5652 desc->info.link_status.invalid_trans_word =
5653 cpu_to_be32(stat->invalidXmitWord);
5654 desc->info.link_status.invalid_crc_cnt = cpu_to_be32(stat->crcCnt);
5656 desc->length = cpu_to_be32(sizeof(desc->info));
5658 return sizeof(struct fc_rdp_link_error_status_desc);
5662 lpfc_rdp_res_bbc_desc(struct fc_rdp_bbc_desc *desc, READ_LNK_VAR *stat,
5663 struct lpfc_vport *vport)
5667 desc->tag = cpu_to_be32(RDP_BBC_DESC_TAG);
5669 bbCredit = vport->fc_sparam.cmn.bbCreditLsb |
5670 (vport->fc_sparam.cmn.bbCreditMsb << 8);
5671 desc->bbc_info.port_bbc = cpu_to_be32(bbCredit);
5672 if (vport->phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
5673 bbCredit = vport->phba->fc_fabparam.cmn.bbCreditLsb |
5674 (vport->phba->fc_fabparam.cmn.bbCreditMsb << 8);
5675 desc->bbc_info.attached_port_bbc = cpu_to_be32(bbCredit);
5677 desc->bbc_info.attached_port_bbc = 0;
5680 desc->bbc_info.rtt = 0;
5681 desc->length = cpu_to_be32(sizeof(desc->bbc_info));
5683 return sizeof(struct fc_rdp_bbc_desc);
5687 lpfc_rdp_res_oed_temp_desc(struct lpfc_hba *phba,
5688 struct fc_rdp_oed_sfp_desc *desc, uint8_t *page_a2)
5692 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5694 desc->oed_info.hi_alarm = page_a2[SSF_TEMP_HIGH_ALARM];
5695 desc->oed_info.lo_alarm = page_a2[SSF_TEMP_LOW_ALARM];
5696 desc->oed_info.hi_warning = page_a2[SSF_TEMP_HIGH_WARNING];
5697 desc->oed_info.lo_warning = page_a2[SSF_TEMP_LOW_WARNING];
5699 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TEMPERATURE)
5700 flags |= RDP_OET_HIGH_ALARM;
5701 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TEMPERATURE)
5702 flags |= RDP_OET_LOW_ALARM;
5703 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TEMPERATURE)
5704 flags |= RDP_OET_HIGH_WARNING;
5705 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TEMPERATURE)
5706 flags |= RDP_OET_LOW_WARNING;
5708 flags |= ((0xf & RDP_OED_TEMPERATURE) << RDP_OED_TYPE_SHIFT);
5709 desc->oed_info.function_flags = cpu_to_be32(flags);
5710 desc->length = cpu_to_be32(sizeof(desc->oed_info));
5711 return sizeof(struct fc_rdp_oed_sfp_desc);
5715 lpfc_rdp_res_oed_voltage_desc(struct lpfc_hba *phba,
5716 struct fc_rdp_oed_sfp_desc *desc,
5721 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5723 desc->oed_info.hi_alarm = page_a2[SSF_VOLTAGE_HIGH_ALARM];
5724 desc->oed_info.lo_alarm = page_a2[SSF_VOLTAGE_LOW_ALARM];
5725 desc->oed_info.hi_warning = page_a2[SSF_VOLTAGE_HIGH_WARNING];
5726 desc->oed_info.lo_warning = page_a2[SSF_VOLTAGE_LOW_WARNING];
5728 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_VOLTAGE)
5729 flags |= RDP_OET_HIGH_ALARM;
5730 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_VOLTAGE)
5731 flags |= RDP_OET_LOW_ALARM;
5732 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_VOLTAGE)
5733 flags |= RDP_OET_HIGH_WARNING;
5734 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_VOLTAGE)
5735 flags |= RDP_OET_LOW_WARNING;
5737 flags |= ((0xf & RDP_OED_VOLTAGE) << RDP_OED_TYPE_SHIFT);
5738 desc->oed_info.function_flags = cpu_to_be32(flags);
5739 desc->length = cpu_to_be32(sizeof(desc->oed_info));
5740 return sizeof(struct fc_rdp_oed_sfp_desc);
5744 lpfc_rdp_res_oed_txbias_desc(struct lpfc_hba *phba,
5745 struct fc_rdp_oed_sfp_desc *desc,
5750 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5752 desc->oed_info.hi_alarm = page_a2[SSF_BIAS_HIGH_ALARM];
5753 desc->oed_info.lo_alarm = page_a2[SSF_BIAS_LOW_ALARM];
5754 desc->oed_info.hi_warning = page_a2[SSF_BIAS_HIGH_WARNING];
5755 desc->oed_info.lo_warning = page_a2[SSF_BIAS_LOW_WARNING];
5757 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TXBIAS)
5758 flags |= RDP_OET_HIGH_ALARM;
5759 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TXBIAS)
5760 flags |= RDP_OET_LOW_ALARM;
5761 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TXBIAS)
5762 flags |= RDP_OET_HIGH_WARNING;
5763 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TXBIAS)
5764 flags |= RDP_OET_LOW_WARNING;
5766 flags |= ((0xf & RDP_OED_TXBIAS) << RDP_OED_TYPE_SHIFT);
5767 desc->oed_info.function_flags = cpu_to_be32(flags);
5768 desc->length = cpu_to_be32(sizeof(desc->oed_info));
5769 return sizeof(struct fc_rdp_oed_sfp_desc);
5773 lpfc_rdp_res_oed_txpower_desc(struct lpfc_hba *phba,
5774 struct fc_rdp_oed_sfp_desc *desc,
5779 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5781 desc->oed_info.hi_alarm = page_a2[SSF_TXPOWER_HIGH_ALARM];
5782 desc->oed_info.lo_alarm = page_a2[SSF_TXPOWER_LOW_ALARM];
5783 desc->oed_info.hi_warning = page_a2[SSF_TXPOWER_HIGH_WARNING];
5784 desc->oed_info.lo_warning = page_a2[SSF_TXPOWER_LOW_WARNING];
5786 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TXPOWER)
5787 flags |= RDP_OET_HIGH_ALARM;
5788 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TXPOWER)
5789 flags |= RDP_OET_LOW_ALARM;
5790 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TXPOWER)
5791 flags |= RDP_OET_HIGH_WARNING;
5792 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TXPOWER)
5793 flags |= RDP_OET_LOW_WARNING;
5795 flags |= ((0xf & RDP_OED_TXPOWER) << RDP_OED_TYPE_SHIFT);
5796 desc->oed_info.function_flags = cpu_to_be32(flags);
5797 desc->length = cpu_to_be32(sizeof(desc->oed_info));
5798 return sizeof(struct fc_rdp_oed_sfp_desc);
5803 lpfc_rdp_res_oed_rxpower_desc(struct lpfc_hba *phba,
5804 struct fc_rdp_oed_sfp_desc *desc,
5809 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5811 desc->oed_info.hi_alarm = page_a2[SSF_RXPOWER_HIGH_ALARM];
5812 desc->oed_info.lo_alarm = page_a2[SSF_RXPOWER_LOW_ALARM];
5813 desc->oed_info.hi_warning = page_a2[SSF_RXPOWER_HIGH_WARNING];
5814 desc->oed_info.lo_warning = page_a2[SSF_RXPOWER_LOW_WARNING];
5816 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_RXPOWER)
5817 flags |= RDP_OET_HIGH_ALARM;
5818 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_RXPOWER)
5819 flags |= RDP_OET_LOW_ALARM;
5820 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_RXPOWER)
5821 flags |= RDP_OET_HIGH_WARNING;
5822 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_RXPOWER)
5823 flags |= RDP_OET_LOW_WARNING;
5825 flags |= ((0xf & RDP_OED_RXPOWER) << RDP_OED_TYPE_SHIFT);
5826 desc->oed_info.function_flags = cpu_to_be32(flags);
5827 desc->length = cpu_to_be32(sizeof(desc->oed_info));
5828 return sizeof(struct fc_rdp_oed_sfp_desc);
5832 lpfc_rdp_res_opd_desc(struct fc_rdp_opd_sfp_desc *desc,
5833 uint8_t *page_a0, struct lpfc_vport *vport)
5835 desc->tag = cpu_to_be32(RDP_OPD_DESC_TAG);
5836 memcpy(desc->opd_info.vendor_name, &page_a0[SSF_VENDOR_NAME], 16);
5837 memcpy(desc->opd_info.model_number, &page_a0[SSF_VENDOR_PN], 16);
5838 memcpy(desc->opd_info.serial_number, &page_a0[SSF_VENDOR_SN], 16);
5839 memcpy(desc->opd_info.revision, &page_a0[SSF_VENDOR_REV], 4);
5840 memcpy(desc->opd_info.date, &page_a0[SSF_DATE_CODE], 8);
5841 desc->length = cpu_to_be32(sizeof(desc->opd_info));
5842 return sizeof(struct fc_rdp_opd_sfp_desc);
5846 lpfc_rdp_res_fec_desc(struct fc_fec_rdp_desc *desc, READ_LNK_VAR *stat)
5848 if (bf_get(lpfc_read_link_stat_gec2, stat) == 0)
5850 desc->tag = cpu_to_be32(RDP_FEC_DESC_TAG);
5852 desc->info.CorrectedBlocks =
5853 cpu_to_be32(stat->fecCorrBlkCount);
5854 desc->info.UncorrectableBlocks =
5855 cpu_to_be32(stat->fecUncorrBlkCount);
5857 desc->length = cpu_to_be32(sizeof(desc->info));
5859 return sizeof(struct fc_fec_rdp_desc);
5863 lpfc_rdp_res_speed(struct fc_rdp_port_speed_desc *desc, struct lpfc_hba *phba)
5865 uint16_t rdp_cap = 0;
5868 desc->tag = cpu_to_be32(RDP_PORT_SPEED_DESC_TAG);
5870 switch (phba->fc_linkspeed) {
5871 case LPFC_LINK_SPEED_1GHZ:
5872 rdp_speed = RDP_PS_1GB;
5874 case LPFC_LINK_SPEED_2GHZ:
5875 rdp_speed = RDP_PS_2GB;
5877 case LPFC_LINK_SPEED_4GHZ:
5878 rdp_speed = RDP_PS_4GB;
5880 case LPFC_LINK_SPEED_8GHZ:
5881 rdp_speed = RDP_PS_8GB;
5883 case LPFC_LINK_SPEED_10GHZ:
5884 rdp_speed = RDP_PS_10GB;
5886 case LPFC_LINK_SPEED_16GHZ:
5887 rdp_speed = RDP_PS_16GB;
5889 case LPFC_LINK_SPEED_32GHZ:
5890 rdp_speed = RDP_PS_32GB;
5892 case LPFC_LINK_SPEED_64GHZ:
5893 rdp_speed = RDP_PS_64GB;
5896 rdp_speed = RDP_PS_UNKNOWN;
5900 desc->info.port_speed.speed = cpu_to_be16(rdp_speed);
5902 if (phba->lmt & LMT_128Gb)
5903 rdp_cap |= RDP_PS_128GB;
5904 if (phba->lmt & LMT_64Gb)
5905 rdp_cap |= RDP_PS_64GB;
5906 if (phba->lmt & LMT_32Gb)
5907 rdp_cap |= RDP_PS_32GB;
5908 if (phba->lmt & LMT_16Gb)
5909 rdp_cap |= RDP_PS_16GB;
5910 if (phba->lmt & LMT_10Gb)
5911 rdp_cap |= RDP_PS_10GB;
5912 if (phba->lmt & LMT_8Gb)
5913 rdp_cap |= RDP_PS_8GB;
5914 if (phba->lmt & LMT_4Gb)
5915 rdp_cap |= RDP_PS_4GB;
5916 if (phba->lmt & LMT_2Gb)
5917 rdp_cap |= RDP_PS_2GB;
5918 if (phba->lmt & LMT_1Gb)
5919 rdp_cap |= RDP_PS_1GB;
5922 rdp_cap = RDP_CAP_UNKNOWN;
5923 if (phba->cfg_link_speed != LPFC_USER_LINK_SPEED_AUTO)
5924 rdp_cap |= RDP_CAP_USER_CONFIGURED;
5926 desc->info.port_speed.capabilities = cpu_to_be16(rdp_cap);
5927 desc->length = cpu_to_be32(sizeof(desc->info));
5928 return sizeof(struct fc_rdp_port_speed_desc);
5932 lpfc_rdp_res_diag_port_names(struct fc_rdp_port_name_desc *desc,
5933 struct lpfc_vport *vport)
5936 desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG);
5938 memcpy(desc->port_names.wwnn, &vport->fc_nodename,
5939 sizeof(desc->port_names.wwnn));
5941 memcpy(desc->port_names.wwpn, &vport->fc_portname,
5942 sizeof(desc->port_names.wwpn));
5944 desc->length = cpu_to_be32(sizeof(desc->port_names));
5945 return sizeof(struct fc_rdp_port_name_desc);
5949 lpfc_rdp_res_attach_port_names(struct fc_rdp_port_name_desc *desc,
5950 struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
5953 desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG);
5954 if (vport->fc_flag & FC_FABRIC) {
5955 memcpy(desc->port_names.wwnn, &vport->fabric_nodename,
5956 sizeof(desc->port_names.wwnn));
5958 memcpy(desc->port_names.wwpn, &vport->fabric_portname,
5959 sizeof(desc->port_names.wwpn));
5960 } else { /* Point to Point */
5961 memcpy(desc->port_names.wwnn, &ndlp->nlp_nodename,
5962 sizeof(desc->port_names.wwnn));
5964 memcpy(desc->port_names.wwpn, &ndlp->nlp_portname,
5965 sizeof(desc->port_names.wwpn));
5968 desc->length = cpu_to_be32(sizeof(desc->port_names));
5969 return sizeof(struct fc_rdp_port_name_desc);
5973 lpfc_els_rdp_cmpl(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context,
5976 struct lpfc_nodelist *ndlp = rdp_context->ndlp;
5977 struct lpfc_vport *vport = ndlp->vport;
5978 struct lpfc_iocbq *elsiocb;
5979 struct ulp_bde64 *bpl;
5982 struct ls_rjt *stat;
5983 struct fc_rdp_res_frame *rdp_res;
5984 uint32_t cmdsize, len;
5988 if (status != SUCCESS)
5991 /* This will change once we know the true size of the RDP payload */
5992 cmdsize = sizeof(struct fc_rdp_res_frame);
5994 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize,
5995 lpfc_max_els_tries, rdp_context->ndlp,
5996 rdp_context->ndlp->nlp_DID, ELS_CMD_ACC);
5998 goto free_rdp_context;
6000 icmd = &elsiocb->iocb;
6001 icmd->ulpContext = rdp_context->rx_id;
6002 icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id;
6004 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6005 "2171 Xmit RDP response tag x%x xri x%x, "
6006 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x",
6007 elsiocb->iotag, elsiocb->iocb.ulpContext,
6008 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
6010 rdp_res = (struct fc_rdp_res_frame *)
6011 (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6012 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6013 memset(pcmd, 0, sizeof(struct fc_rdp_res_frame));
6014 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
6016 /* Update Alarm and Warning */
6017 flag_ptr = (uint16_t *)(rdp_context->page_a2 + SSF_ALARM_FLAGS);
6018 phba->sfp_alarm |= *flag_ptr;
6019 flag_ptr = (uint16_t *)(rdp_context->page_a2 + SSF_WARNING_FLAGS);
6020 phba->sfp_warning |= *flag_ptr;
6022 /* For RDP payload */
6024 len += lpfc_rdp_res_link_service((struct fc_rdp_link_service_desc *)
6025 (len + pcmd), ELS_CMD_RDP);
6027 len += lpfc_rdp_res_sfp_desc((struct fc_rdp_sfp_desc *)(len + pcmd),
6028 rdp_context->page_a0, rdp_context->page_a2);
6029 len += lpfc_rdp_res_speed((struct fc_rdp_port_speed_desc *)(len + pcmd),
6031 len += lpfc_rdp_res_link_error((struct fc_rdp_link_error_status_desc *)
6032 (len + pcmd), &rdp_context->link_stat);
6033 len += lpfc_rdp_res_diag_port_names((struct fc_rdp_port_name_desc *)
6034 (len + pcmd), vport);
6035 len += lpfc_rdp_res_attach_port_names((struct fc_rdp_port_name_desc *)
6036 (len + pcmd), vport, ndlp);
6037 len += lpfc_rdp_res_fec_desc((struct fc_fec_rdp_desc *)(len + pcmd),
6038 &rdp_context->link_stat);
6039 len += lpfc_rdp_res_bbc_desc((struct fc_rdp_bbc_desc *)(len + pcmd),
6040 &rdp_context->link_stat, vport);
6041 len += lpfc_rdp_res_oed_temp_desc(phba,
6042 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
6043 rdp_context->page_a2);
6044 len += lpfc_rdp_res_oed_voltage_desc(phba,
6045 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
6046 rdp_context->page_a2);
6047 len += lpfc_rdp_res_oed_txbias_desc(phba,
6048 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
6049 rdp_context->page_a2);
6050 len += lpfc_rdp_res_oed_txpower_desc(phba,
6051 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
6052 rdp_context->page_a2);
6053 len += lpfc_rdp_res_oed_rxpower_desc(phba,
6054 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
6055 rdp_context->page_a2);
6056 len += lpfc_rdp_res_opd_desc((struct fc_rdp_opd_sfp_desc *)(len + pcmd),
6057 rdp_context->page_a0, vport);
6059 rdp_res->length = cpu_to_be32(len - 8);
6060 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
6062 /* Now that we know the true size of the payload, update the BPL */
6063 bpl = (struct ulp_bde64 *)
6064 (((struct lpfc_dmabuf *)(elsiocb->context3))->virt);
6065 bpl->tus.f.bdeSize = len;
6066 bpl->tus.f.bdeFlags = 0;
6067 bpl->tus.w = le32_to_cpu(bpl->tus.w);
6069 phba->fc_stat.elsXmitACC++;
6070 elsiocb->context1 = lpfc_nlp_get(ndlp);
6071 if (!elsiocb->context1) {
6072 lpfc_els_free_iocb(phba, elsiocb);
6073 goto free_rdp_context;
6076 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
6077 if (rc == IOCB_ERROR) {
6079 lpfc_els_free_iocb(phba, elsiocb);
6082 goto free_rdp_context;
6085 cmdsize = 2 * sizeof(uint32_t);
6086 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, lpfc_max_els_tries,
6087 ndlp, ndlp->nlp_DID, ELS_CMD_LS_RJT);
6089 goto free_rdp_context;
6091 icmd = &elsiocb->iocb;
6092 icmd->ulpContext = rdp_context->rx_id;
6093 icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id;
6094 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6096 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
6097 stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t));
6098 stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6100 phba->fc_stat.elsXmitLSRJT++;
6101 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
6102 elsiocb->context1 = lpfc_nlp_get(ndlp);
6103 if (!elsiocb->context1) {
6104 lpfc_els_free_iocb(phba, elsiocb);
6105 goto free_rdp_context;
6108 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
6109 if (rc == IOCB_ERROR) {
6111 lpfc_els_free_iocb(phba, elsiocb);
6115 /* This reference put is for the original unsolicited RDP. If the
6116 * iocb prep failed, there is no reference to remove.
6123 lpfc_get_rdp_info(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context)
6125 LPFC_MBOXQ_t *mbox = NULL;
6128 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6130 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_ELS,
6131 "7105 failed to allocate mailbox memory");
6135 if (lpfc_sli4_dump_page_a0(phba, mbox))
6136 goto prep_mbox_fail;
6137 mbox->vport = rdp_context->ndlp->vport;
6138 mbox->mbox_cmpl = lpfc_mbx_cmpl_rdp_page_a0;
6139 mbox->ctx_ndlp = (struct lpfc_rdp_context *)rdp_context;
6140 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
6141 if (rc == MBX_NOT_FINISHED)
6142 goto issue_mbox_fail;
6148 mempool_free(mbox, phba->mbox_mem_pool);
6153 * lpfc_els_rcv_rdp - Process an unsolicited RDP ELS.
6154 * @vport: pointer to a host virtual N_Port data structure.
6155 * @cmdiocb: pointer to lpfc command iocb data structure.
6156 * @ndlp: pointer to a node-list data structure.
6158 * This routine processes an unsolicited RDP(Read Diagnostic Parameters)
6159 * IOCB. First, the payload of the unsolicited RDP is checked.
6160 * Then it will (1) send MBX_DUMP_MEMORY, Embedded DMP_LMSD sub command TYPE-3
6161 * for Page A0, (2) send MBX_DUMP_MEMORY, DMP_LMSD for Page A2,
6162 * (3) send MBX_READ_LNK_STAT to get link stat, (4) Call lpfc_els_rdp_cmpl
6163 * gather all data and send RDP response.
6166 * 0 - Sent the acc response
6167 * 1 - Sent the reject response.
6170 lpfc_els_rcv_rdp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6171 struct lpfc_nodelist *ndlp)
6173 struct lpfc_hba *phba = vport->phba;
6174 struct lpfc_dmabuf *pcmd;
6175 uint8_t rjt_err, rjt_expl = LSEXP_NOTHING_MORE;
6176 struct fc_rdp_req_frame *rdp_req;
6177 struct lpfc_rdp_context *rdp_context;
6181 if (phba->sli_rev < LPFC_SLI_REV4 ||
6182 bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
6183 LPFC_SLI_INTF_IF_TYPE_2) {
6184 rjt_err = LSRJT_UNABLE_TPC;
6185 rjt_expl = LSEXP_REQ_UNSUPPORTED;
6189 if (phba->sli_rev < LPFC_SLI_REV4 || (phba->hba_flag & HBA_FCOE_MODE)) {
6190 rjt_err = LSRJT_UNABLE_TPC;
6191 rjt_expl = LSEXP_REQ_UNSUPPORTED;
6195 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6196 rdp_req = (struct fc_rdp_req_frame *) pcmd->virt;
6198 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6199 "2422 ELS RDP Request "
6200 "dec len %d tag x%x port_id %d len %d\n",
6201 be32_to_cpu(rdp_req->rdp_des_length),
6202 be32_to_cpu(rdp_req->nport_id_desc.tag),
6203 be32_to_cpu(rdp_req->nport_id_desc.nport_id),
6204 be32_to_cpu(rdp_req->nport_id_desc.length));
6206 if (sizeof(struct fc_rdp_nport_desc) !=
6207 be32_to_cpu(rdp_req->rdp_des_length))
6209 if (RDP_N_PORT_DESC_TAG != be32_to_cpu(rdp_req->nport_id_desc.tag))
6211 if (RDP_NPORT_ID_SIZE !=
6212 be32_to_cpu(rdp_req->nport_id_desc.length))
6214 rdp_context = kzalloc(sizeof(struct lpfc_rdp_context), GFP_KERNEL);
6216 rjt_err = LSRJT_UNABLE_TPC;
6220 cmd = &cmdiocb->iocb;
6221 rdp_context->ndlp = lpfc_nlp_get(ndlp);
6222 if (!rdp_context->ndlp) {
6224 rjt_err = LSRJT_UNABLE_TPC;
6227 rdp_context->ox_id = cmd->unsli3.rcvsli3.ox_id;
6228 rdp_context->rx_id = cmd->ulpContext;
6229 rdp_context->cmpl = lpfc_els_rdp_cmpl;
6230 if (lpfc_get_rdp_info(phba, rdp_context)) {
6231 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_ELS,
6232 "2423 Unable to send mailbox");
6234 rjt_err = LSRJT_UNABLE_TPC;
6242 rjt_err = LSRJT_LOGICAL_ERR;
6245 memset(&stat, 0, sizeof(stat));
6246 stat.un.b.lsRjtRsnCode = rjt_err;
6247 stat.un.b.lsRjtRsnCodeExp = rjt_expl;
6248 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
6254 lpfc_els_lcb_rsp(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
6259 struct lpfc_iocbq *elsiocb;
6260 struct lpfc_nodelist *ndlp;
6261 struct ls_rjt *stat;
6262 union lpfc_sli4_cfg_shdr *shdr;
6263 struct lpfc_lcb_context *lcb_context;
6264 struct fc_lcb_res_frame *lcb_res;
6265 uint32_t cmdsize, shdr_status, shdr_add_status;
6269 lcb_context = (struct lpfc_lcb_context *)pmb->ctx_ndlp;
6270 ndlp = lcb_context->ndlp;
6271 pmb->ctx_ndlp = NULL;
6272 pmb->ctx_buf = NULL;
6274 shdr = (union lpfc_sli4_cfg_shdr *)
6275 &pmb->u.mqe.un.beacon_config.header.cfg_shdr;
6276 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
6277 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
6279 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX,
6280 "0194 SET_BEACON_CONFIG mailbox "
6281 "completed with status x%x add_status x%x,"
6282 " mbx status x%x\n",
6283 shdr_status, shdr_add_status, mb->mbxStatus);
6285 if ((mb->mbxStatus != MBX_SUCCESS) || shdr_status ||
6286 (shdr_add_status == ADD_STATUS_OPERATION_ALREADY_ACTIVE) ||
6287 (shdr_add_status == ADD_STATUS_INVALID_REQUEST)) {
6288 mempool_free(pmb, phba->mbox_mem_pool);
6292 mempool_free(pmb, phba->mbox_mem_pool);
6293 cmdsize = sizeof(struct fc_lcb_res_frame);
6294 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
6295 lpfc_max_els_tries, ndlp,
6296 ndlp->nlp_DID, ELS_CMD_ACC);
6298 /* Decrement the ndlp reference count from previous mbox command */
6302 goto free_lcb_context;
6304 lcb_res = (struct fc_lcb_res_frame *)
6305 (((struct lpfc_dmabuf *)elsiocb->context2)->virt);
6307 memset(lcb_res, 0, sizeof(struct fc_lcb_res_frame));
6308 icmd = &elsiocb->iocb;
6309 icmd->ulpContext = lcb_context->rx_id;
6310 icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id;
6312 pcmd = (uint8_t *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt);
6313 *((uint32_t *)(pcmd)) = ELS_CMD_ACC;
6314 lcb_res->lcb_sub_command = lcb_context->sub_command;
6315 lcb_res->lcb_type = lcb_context->type;
6316 lcb_res->capability = lcb_context->capability;
6317 lcb_res->lcb_frequency = lcb_context->frequency;
6318 lcb_res->lcb_duration = lcb_context->duration;
6319 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
6320 phba->fc_stat.elsXmitACC++;
6322 elsiocb->context1 = lpfc_nlp_get(ndlp);
6323 if (!elsiocb->context1)
6326 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
6332 lpfc_els_free_iocb(phba, elsiocb);
6338 cmdsize = sizeof(struct fc_lcb_res_frame);
6339 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
6340 lpfc_max_els_tries, ndlp,
6341 ndlp->nlp_DID, ELS_CMD_LS_RJT);
6344 goto free_lcb_context;
6346 icmd = &elsiocb->iocb;
6347 icmd->ulpContext = lcb_context->rx_id;
6348 icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id;
6349 pcmd = (uint8_t *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt);
6351 *((uint32_t *)(pcmd)) = ELS_CMD_LS_RJT;
6352 stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t));
6353 stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6355 if (shdr_add_status == ADD_STATUS_OPERATION_ALREADY_ACTIVE)
6356 stat->un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS;
6358 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
6359 phba->fc_stat.elsXmitLSRJT++;
6360 elsiocb->context1 = lpfc_nlp_get(ndlp);
6361 if (!elsiocb->context1) {
6362 lpfc_els_free_iocb(phba, elsiocb);
6363 goto free_lcb_context;
6366 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
6367 if (rc == IOCB_ERROR) {
6369 lpfc_els_free_iocb(phba, elsiocb);
6376 lpfc_sli4_set_beacon(struct lpfc_vport *vport,
6377 struct lpfc_lcb_context *lcb_context,
6378 uint32_t beacon_state)
6380 struct lpfc_hba *phba = vport->phba;
6381 union lpfc_sli4_cfg_shdr *cfg_shdr;
6382 LPFC_MBOXQ_t *mbox = NULL;
6386 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6390 cfg_shdr = &mbox->u.mqe.un.sli4_config.header.cfg_shdr;
6391 len = sizeof(struct lpfc_mbx_set_beacon_config) -
6392 sizeof(struct lpfc_sli4_cfg_mhdr);
6393 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
6394 LPFC_MBOX_OPCODE_SET_BEACON_CONFIG, len,
6395 LPFC_SLI4_MBX_EMBED);
6396 mbox->ctx_ndlp = (void *)lcb_context;
6397 mbox->vport = phba->pport;
6398 mbox->mbox_cmpl = lpfc_els_lcb_rsp;
6399 bf_set(lpfc_mbx_set_beacon_port_num, &mbox->u.mqe.un.beacon_config,
6400 phba->sli4_hba.physical_port);
6401 bf_set(lpfc_mbx_set_beacon_state, &mbox->u.mqe.un.beacon_config,
6403 mbox->u.mqe.un.beacon_config.word5 = 0; /* Reserved */
6406 * Check bv1s bit before issuing the mailbox
6407 * if bv1s == 1, LCB V1 supported
6408 * else, LCB V0 supported
6411 if (phba->sli4_hba.pc_sli4_params.bv1s) {
6412 /* COMMON_SET_BEACON_CONFIG_V1 */
6413 cfg_shdr->request.word9 = BEACON_VERSION_V1;
6414 lcb_context->capability |= LCB_CAPABILITY_DURATION;
6415 bf_set(lpfc_mbx_set_beacon_port_type,
6416 &mbox->u.mqe.un.beacon_config, 0);
6417 bf_set(lpfc_mbx_set_beacon_duration_v1,
6418 &mbox->u.mqe.un.beacon_config,
6419 be16_to_cpu(lcb_context->duration));
6421 /* COMMON_SET_BEACON_CONFIG_V0 */
6422 if (be16_to_cpu(lcb_context->duration) != 0) {
6423 mempool_free(mbox, phba->mbox_mem_pool);
6426 cfg_shdr->request.word9 = BEACON_VERSION_V0;
6427 lcb_context->capability &= ~(LCB_CAPABILITY_DURATION);
6428 bf_set(lpfc_mbx_set_beacon_state,
6429 &mbox->u.mqe.un.beacon_config, beacon_state);
6430 bf_set(lpfc_mbx_set_beacon_port_type,
6431 &mbox->u.mqe.un.beacon_config, 1);
6432 bf_set(lpfc_mbx_set_beacon_duration,
6433 &mbox->u.mqe.un.beacon_config,
6434 be16_to_cpu(lcb_context->duration));
6437 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
6438 if (rc == MBX_NOT_FINISHED) {
6439 mempool_free(mbox, phba->mbox_mem_pool);
6448 * lpfc_els_rcv_lcb - Process an unsolicited LCB
6449 * @vport: pointer to a host virtual N_Port data structure.
6450 * @cmdiocb: pointer to lpfc command iocb data structure.
6451 * @ndlp: pointer to a node-list data structure.
6453 * This routine processes an unsolicited LCB(LINK CABLE BEACON) IOCB.
6454 * First, the payload of the unsolicited LCB is checked.
6455 * Then based on Subcommand beacon will either turn on or off.
6458 * 0 - Sent the acc response
6459 * 1 - Sent the reject response.
6462 lpfc_els_rcv_lcb(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6463 struct lpfc_nodelist *ndlp)
6465 struct lpfc_hba *phba = vport->phba;
6466 struct lpfc_dmabuf *pcmd;
6468 struct fc_lcb_request_frame *beacon;
6469 struct lpfc_lcb_context *lcb_context;
6470 u8 state, rjt_err = 0;
6473 pcmd = (struct lpfc_dmabuf *)cmdiocb->context2;
6474 lp = (uint8_t *)pcmd->virt;
6475 beacon = (struct fc_lcb_request_frame *)pcmd->virt;
6477 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6478 "0192 ELS LCB Data x%x x%x x%x x%x sub x%x "
6479 "type x%x frequency %x duration x%x\n",
6480 lp[0], lp[1], lp[2],
6481 beacon->lcb_command,
6482 beacon->lcb_sub_command,
6484 beacon->lcb_frequency,
6485 be16_to_cpu(beacon->lcb_duration));
6487 if (beacon->lcb_sub_command != LPFC_LCB_ON &&
6488 beacon->lcb_sub_command != LPFC_LCB_OFF) {
6489 rjt_err = LSRJT_CMD_UNSUPPORTED;
6493 if (phba->sli_rev < LPFC_SLI_REV4 ||
6494 phba->hba_flag & HBA_FCOE_MODE ||
6495 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
6496 LPFC_SLI_INTF_IF_TYPE_2)) {
6497 rjt_err = LSRJT_CMD_UNSUPPORTED;
6501 lcb_context = kmalloc(sizeof(*lcb_context), GFP_KERNEL);
6503 rjt_err = LSRJT_UNABLE_TPC;
6507 state = (beacon->lcb_sub_command == LPFC_LCB_ON) ? 1 : 0;
6508 lcb_context->sub_command = beacon->lcb_sub_command;
6509 lcb_context->capability = 0;
6510 lcb_context->type = beacon->lcb_type;
6511 lcb_context->frequency = beacon->lcb_frequency;
6512 lcb_context->duration = beacon->lcb_duration;
6513 lcb_context->ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id;
6514 lcb_context->rx_id = cmdiocb->iocb.ulpContext;
6515 lcb_context->ndlp = lpfc_nlp_get(ndlp);
6516 if (!lcb_context->ndlp) {
6517 rjt_err = LSRJT_UNABLE_TPC;
6521 if (lpfc_sli4_set_beacon(vport, lcb_context, state)) {
6522 lpfc_printf_vlog(ndlp->vport, KERN_ERR, LOG_TRACE_EVENT,
6523 "0193 failed to send mail box");
6525 rjt_err = LSRJT_UNABLE_TPC;
6533 memset(&stat, 0, sizeof(stat));
6534 stat.un.b.lsRjtRsnCode = rjt_err;
6535 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
6541 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
6542 * @vport: pointer to a host virtual N_Port data structure.
6544 * This routine cleans up any Registration State Change Notification
6545 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
6546 * @vport together with the host_lock is used to prevent multiple thread
6547 * trying to access the RSCN array on a same @vport at the same time.
6550 lpfc_els_flush_rscn(struct lpfc_vport *vport)
6552 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6553 struct lpfc_hba *phba = vport->phba;
6556 spin_lock_irq(shost->host_lock);
6557 if (vport->fc_rscn_flush) {
6558 /* Another thread is walking fc_rscn_id_list on this vport */
6559 spin_unlock_irq(shost->host_lock);
6562 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
6563 vport->fc_rscn_flush = 1;
6564 spin_unlock_irq(shost->host_lock);
6566 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
6567 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
6568 vport->fc_rscn_id_list[i] = NULL;
6570 spin_lock_irq(shost->host_lock);
6571 vport->fc_rscn_id_cnt = 0;
6572 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
6573 spin_unlock_irq(shost->host_lock);
6574 lpfc_can_disctmo(vport);
6575 /* Indicate we are done walking this fc_rscn_id_list */
6576 vport->fc_rscn_flush = 0;
6580 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
6581 * @vport: pointer to a host virtual N_Port data structure.
6582 * @did: remote destination port identifier.
6584 * This routine checks whether there is any pending Registration State
6585 * Configuration Notification (RSCN) to a @did on @vport.
6588 * None zero - The @did matched with a pending rscn
6589 * 0 - not able to match @did with a pending rscn
6592 lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
6597 uint32_t payload_len, i;
6598 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6600 ns_did.un.word = did;
6602 /* Never match fabric nodes for RSCNs */
6603 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
6606 /* If we are doing a FULL RSCN rediscovery, match everything */
6607 if (vport->fc_flag & FC_RSCN_DISCOVERY)
6610 spin_lock_irq(shost->host_lock);
6611 if (vport->fc_rscn_flush) {
6612 /* Another thread is walking fc_rscn_id_list on this vport */
6613 spin_unlock_irq(shost->host_lock);
6616 /* Indicate we are walking fc_rscn_id_list on this vport */
6617 vport->fc_rscn_flush = 1;
6618 spin_unlock_irq(shost->host_lock);
6619 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
6620 lp = vport->fc_rscn_id_list[i]->virt;
6621 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
6622 payload_len -= sizeof(uint32_t); /* take off word 0 */
6623 while (payload_len) {
6624 rscn_did.un.word = be32_to_cpu(*lp++);
6625 payload_len -= sizeof(uint32_t);
6626 switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) {
6627 case RSCN_ADDRESS_FORMAT_PORT:
6628 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
6629 && (ns_did.un.b.area == rscn_did.un.b.area)
6630 && (ns_did.un.b.id == rscn_did.un.b.id))
6631 goto return_did_out;
6633 case RSCN_ADDRESS_FORMAT_AREA:
6634 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
6635 && (ns_did.un.b.area == rscn_did.un.b.area))
6636 goto return_did_out;
6638 case RSCN_ADDRESS_FORMAT_DOMAIN:
6639 if (ns_did.un.b.domain == rscn_did.un.b.domain)
6640 goto return_did_out;
6642 case RSCN_ADDRESS_FORMAT_FABRIC:
6643 goto return_did_out;
6647 /* Indicate we are done with walking fc_rscn_id_list on this vport */
6648 vport->fc_rscn_flush = 0;
6651 /* Indicate we are done with walking fc_rscn_id_list on this vport */
6652 vport->fc_rscn_flush = 0;
6657 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
6658 * @vport: pointer to a host virtual N_Port data structure.
6660 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
6661 * state machine for a @vport's nodes that are with pending RSCN (Registration
6662 * State Change Notification).
6665 * 0 - Successful (currently alway return 0)
6668 lpfc_rscn_recovery_check(struct lpfc_vport *vport)
6670 struct lpfc_nodelist *ndlp = NULL;
6672 /* Move all affected nodes by pending RSCNs to NPR state. */
6673 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
6674 if ((ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
6675 !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
6678 /* NVME Target mode does not do RSCN Recovery. */
6679 if (vport->phba->nvmet_support)
6682 /* If we are in the process of doing discovery on this
6683 * NPort, let it continue on its own.
6685 switch (ndlp->nlp_state) {
6686 case NLP_STE_PLOGI_ISSUE:
6687 case NLP_STE_ADISC_ISSUE:
6688 case NLP_STE_REG_LOGIN_ISSUE:
6689 case NLP_STE_PRLI_ISSUE:
6690 case NLP_STE_LOGO_ISSUE:
6694 /* Check to see if we need to NVME rescan this target
6697 if (ndlp->nlp_fc4_type & NLP_FC4_NVME &&
6698 ndlp->nlp_type & (NLP_NVME_TARGET | NLP_NVME_DISCOVERY))
6699 lpfc_nvme_rescan_port(vport, ndlp);
6701 lpfc_disc_state_machine(vport, ndlp, NULL,
6702 NLP_EVT_DEVICE_RECOVERY);
6703 lpfc_cancel_retry_delay_tmo(vport, ndlp);
6709 * lpfc_send_rscn_event - Send an RSCN event to management application
6710 * @vport: pointer to a host virtual N_Port data structure.
6711 * @cmdiocb: pointer to lpfc command iocb data structure.
6713 * lpfc_send_rscn_event sends an RSCN netlink event to management
6717 lpfc_send_rscn_event(struct lpfc_vport *vport,
6718 struct lpfc_iocbq *cmdiocb)
6720 struct lpfc_dmabuf *pcmd;
6721 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6722 uint32_t *payload_ptr;
6723 uint32_t payload_len;
6724 struct lpfc_rscn_event_header *rscn_event_data;
6726 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6727 payload_ptr = (uint32_t *) pcmd->virt;
6728 payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK);
6730 rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) +
6731 payload_len, GFP_KERNEL);
6732 if (!rscn_event_data) {
6733 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
6734 "0147 Failed to allocate memory for RSCN event\n");
6737 rscn_event_data->event_type = FC_REG_RSCN_EVENT;
6738 rscn_event_data->payload_length = payload_len;
6739 memcpy(rscn_event_data->rscn_payload, payload_ptr,
6742 fc_host_post_vendor_event(shost,
6743 fc_get_event_number(),
6744 sizeof(struct lpfc_rscn_event_header) + payload_len,
6745 (char *)rscn_event_data,
6748 kfree(rscn_event_data);
6752 * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
6753 * @vport: pointer to a host virtual N_Port data structure.
6754 * @cmdiocb: pointer to lpfc command iocb data structure.
6755 * @ndlp: pointer to a node-list data structure.
6757 * This routine processes an unsolicited RSCN (Registration State Change
6758 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
6759 * to invoke fc_host_post_event() routine to the FC transport layer. If the
6760 * discover state machine is about to begin discovery, it just accepts the
6761 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
6762 * contains N_Port IDs for other vports on this HBA, it just accepts the
6763 * RSCN and ignore processing it. If the state machine is in the recovery
6764 * state, the fc_rscn_id_list of this @vport is walked and the
6765 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
6766 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
6767 * routine is invoked to handle the RSCN event.
6770 * 0 - Just sent the acc response
6771 * 1 - Sent the acc response and waited for name server completion
6774 lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6775 struct lpfc_nodelist *ndlp)
6777 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6778 struct lpfc_hba *phba = vport->phba;
6779 struct lpfc_dmabuf *pcmd;
6780 uint32_t *lp, *datap;
6781 uint32_t payload_len, length, nportid, *cmd;
6783 int rscn_id = 0, hba_id = 0;
6786 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6787 lp = (uint32_t *) pcmd->virt;
6789 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
6790 payload_len -= sizeof(uint32_t); /* take off word 0 */
6792 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6793 "0214 RSCN received Data: x%x x%x x%x x%x\n",
6794 vport->fc_flag, payload_len, *lp,
6795 vport->fc_rscn_id_cnt);
6797 /* Send an RSCN event to the management application */
6798 lpfc_send_rscn_event(vport, cmdiocb);
6800 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
6801 fc_host_post_event(shost, fc_get_event_number(),
6802 FCH_EVT_RSCN, lp[i]);
6804 /* Check if RSCN is coming from a direct-connected remote NPort */
6805 if (vport->fc_flag & FC_PT2PT) {
6806 /* If so, just ACC it, no other action needed for now */
6807 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6808 "2024 pt2pt RSCN %08x Data: x%x x%x\n",
6809 *lp, vport->fc_flag, payload_len);
6810 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
6812 /* Check to see if we need to NVME rescan this target
6815 if (ndlp->nlp_fc4_type & NLP_FC4_NVME &&
6816 ndlp->nlp_type & (NLP_NVME_TARGET | NLP_NVME_DISCOVERY))
6817 lpfc_nvme_rescan_port(vport, ndlp);
6821 /* If we are about to begin discovery, just ACC the RSCN.
6822 * Discovery processing will satisfy it.
6824 if (vport->port_state <= LPFC_NS_QRY) {
6825 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6826 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
6827 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
6829 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
6833 /* If this RSCN just contains NPortIDs for other vports on this HBA,
6834 * just ACC and ignore it.
6836 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
6837 !(vport->cfg_peer_port_login)) {
6842 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
6843 i -= sizeof(uint32_t);
6845 if (lpfc_find_vport_by_did(phba, nportid))
6848 if (rscn_id == hba_id) {
6849 /* ALL NPortIDs in RSCN are on HBA */
6850 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6852 "Data: x%x x%x x%x x%x\n",
6853 vport->fc_flag, payload_len,
6854 *lp, vport->fc_rscn_id_cnt);
6855 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6856 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
6857 ndlp->nlp_DID, vport->port_state,
6860 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
6866 spin_lock_irq(shost->host_lock);
6867 if (vport->fc_rscn_flush) {
6868 /* Another thread is walking fc_rscn_id_list on this vport */
6869 vport->fc_flag |= FC_RSCN_DISCOVERY;
6870 spin_unlock_irq(shost->host_lock);
6872 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
6875 /* Indicate we are walking fc_rscn_id_list on this vport */
6876 vport->fc_rscn_flush = 1;
6877 spin_unlock_irq(shost->host_lock);
6878 /* Get the array count after successfully have the token */
6879 rscn_cnt = vport->fc_rscn_id_cnt;
6880 /* If we are already processing an RSCN, save the received
6881 * RSCN payload buffer, cmdiocb->context2 to process later.
6883 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
6884 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6885 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
6886 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
6888 spin_lock_irq(shost->host_lock);
6889 vport->fc_flag |= FC_RSCN_DEFERRED;
6891 /* Restart disctmo if its already running */
6892 if (vport->fc_flag & FC_DISC_TMO) {
6893 tmo = ((phba->fc_ratov * 3) + 3);
6894 mod_timer(&vport->fc_disctmo,
6895 jiffies + msecs_to_jiffies(1000 * tmo));
6897 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
6898 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
6899 vport->fc_flag |= FC_RSCN_MODE;
6900 spin_unlock_irq(shost->host_lock);
6902 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
6903 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
6906 (payload_len + length <= LPFC_BPL_SIZE)) {
6907 *cmd &= ELS_CMD_MASK;
6908 *cmd |= cpu_to_be32(payload_len + length);
6909 memcpy(((uint8_t *)cmd) + length, lp,
6912 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
6913 vport->fc_rscn_id_cnt++;
6914 /* If we zero, cmdiocb->context2, the calling
6915 * routine will not try to free it.
6917 cmdiocb->context2 = NULL;
6920 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6921 "0235 Deferred RSCN "
6922 "Data: x%x x%x x%x\n",
6923 vport->fc_rscn_id_cnt, vport->fc_flag,
6926 vport->fc_flag |= FC_RSCN_DISCOVERY;
6927 spin_unlock_irq(shost->host_lock);
6928 /* ReDiscovery RSCN */
6929 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6930 "0234 ReDiscovery RSCN "
6931 "Data: x%x x%x x%x\n",
6932 vport->fc_rscn_id_cnt, vport->fc_flag,
6935 /* Indicate we are done walking fc_rscn_id_list on this vport */
6936 vport->fc_rscn_flush = 0;
6938 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
6939 /* send RECOVERY event for ALL nodes that match RSCN payload */
6940 lpfc_rscn_recovery_check(vport);
6943 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6944 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
6945 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
6947 spin_lock_irq(shost->host_lock);
6948 vport->fc_flag |= FC_RSCN_MODE;
6949 spin_unlock_irq(shost->host_lock);
6950 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
6951 /* Indicate we are done walking fc_rscn_id_list on this vport */
6952 vport->fc_rscn_flush = 0;
6954 * If we zero, cmdiocb->context2, the calling routine will
6955 * not try to free it.
6957 cmdiocb->context2 = NULL;
6958 lpfc_set_disctmo(vport);
6960 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
6961 /* send RECOVERY event for ALL nodes that match RSCN payload */
6962 lpfc_rscn_recovery_check(vport);
6963 return lpfc_els_handle_rscn(vport);
6967 * lpfc_els_handle_rscn - Handle rscn for a vport
6968 * @vport: pointer to a host virtual N_Port data structure.
6970 * This routine handles the Registration State Configuration Notification
6971 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
6972 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
6973 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
6974 * NameServer shall be issued. If CT command to the NameServer fails to be
6975 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
6976 * RSCN activities with the @vport.
6979 * 0 - Cleaned up rscn on the @vport
6980 * 1 - Wait for plogi to name server before proceed
6983 lpfc_els_handle_rscn(struct lpfc_vport *vport)
6985 struct lpfc_nodelist *ndlp;
6986 struct lpfc_hba *phba = vport->phba;
6988 /* Ignore RSCN if the port is being torn down. */
6989 if (vport->load_flag & FC_UNLOADING) {
6990 lpfc_els_flush_rscn(vport);
6994 /* Start timer for RSCN processing */
6995 lpfc_set_disctmo(vport);
6997 /* RSCN processed */
6998 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6999 "0215 RSCN processed Data: x%x x%x x%x x%x x%x x%x\n",
7000 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
7001 vport->port_state, vport->num_disc_nodes,
7004 /* To process RSCN, first compare RSCN data with NameServer */
7005 vport->fc_ns_retry = 0;
7006 vport->num_disc_nodes = 0;
7008 ndlp = lpfc_findnode_did(vport, NameServer_DID);
7009 if (ndlp && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
7010 /* Good ndlp, issue CT Request to NameServer. Need to
7011 * know how many gidfts were issued. If none, then just
7012 * flush the RSCN. Otherwise, the outstanding requests
7015 if (phba->cfg_ns_query == LPFC_NS_QUERY_GID_FT) {
7016 if (lpfc_issue_gidft(vport) > 0)
7018 } else if (phba->cfg_ns_query == LPFC_NS_QUERY_GID_PT) {
7019 if (lpfc_issue_gidpt(vport) > 0)
7025 /* Nameserver login in question. Revalidate. */
7027 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
7028 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
7030 ndlp = lpfc_nlp_init(vport, NameServer_DID);
7032 lpfc_els_flush_rscn(vport);
7035 ndlp->nlp_prev_state = ndlp->nlp_state;
7036 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
7038 ndlp->nlp_type |= NLP_FABRIC;
7039 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
7040 /* Wait for NameServer login cmpl before we can
7046 lpfc_els_flush_rscn(vport);
7051 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
7052 * @vport: pointer to a host virtual N_Port data structure.
7053 * @cmdiocb: pointer to lpfc command iocb data structure.
7054 * @ndlp: pointer to a node-list data structure.
7056 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
7057 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
7058 * point topology. As an unsolicited FLOGI should not be received in a loop
7059 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
7060 * lpfc_check_sparm() routine is invoked to check the parameters in the
7061 * unsolicited FLOGI. If parameters validation failed, the routine
7062 * lpfc_els_rsp_reject() shall be called with reject reason code set to
7063 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
7064 * FLOGI shall be compared with the Port WWN of the @vport to determine who
7065 * will initiate PLOGI. The higher lexicographical value party shall has
7066 * higher priority (as the winning port) and will initiate PLOGI and
7067 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
7068 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
7069 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
7072 * 0 - Successfully processed the unsolicited flogi
7073 * 1 - Failed to process the unsolicited flogi
7076 lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7077 struct lpfc_nodelist *ndlp)
7079 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7080 struct lpfc_hba *phba = vport->phba;
7081 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7082 uint32_t *lp = (uint32_t *) pcmd->virt;
7083 IOCB_t *icmd = &cmdiocb->iocb;
7084 struct serv_parm *sp;
7088 uint32_t fc_flag = 0;
7089 uint32_t port_state = 0;
7092 sp = (struct serv_parm *) lp;
7094 /* FLOGI received */
7096 lpfc_set_disctmo(vport);
7098 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
7099 /* We should never receive a FLOGI in loop mode, ignore it */
7100 did = icmd->un.elsreq64.remoteID;
7102 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
7104 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
7105 "0113 An FLOGI ELS command x%x was "
7106 "received from DID x%x in Loop Mode\n",
7111 (void) lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1);
7114 * If our portname is greater than the remote portname,
7115 * then we initiate Nport login.
7118 rc = memcmp(&vport->fc_portname, &sp->portName,
7119 sizeof(struct lpfc_name));
7122 if (phba->sli_rev < LPFC_SLI_REV4) {
7123 mbox = mempool_alloc(phba->mbox_mem_pool,
7127 lpfc_linkdown(phba);
7128 lpfc_init_link(phba, mbox,
7130 phba->cfg_link_speed);
7131 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
7132 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
7133 mbox->vport = vport;
7134 rc = lpfc_sli_issue_mbox(phba, mbox,
7136 lpfc_set_loopback_flag(phba);
7137 if (rc == MBX_NOT_FINISHED)
7138 mempool_free(mbox, phba->mbox_mem_pool);
7142 /* abort the flogi coming back to ourselves
7143 * due to external loopback on the port.
7145 lpfc_els_abort_flogi(phba);
7148 } else if (rc > 0) { /* greater than */
7149 spin_lock_irq(shost->host_lock);
7150 vport->fc_flag |= FC_PT2PT_PLOGI;
7151 spin_unlock_irq(shost->host_lock);
7153 /* If we have the high WWPN we can assign our own
7154 * myDID; otherwise, we have to WAIT for a PLOGI
7155 * from the remote NPort to find out what it
7158 vport->fc_myDID = PT2PT_LocalID;
7160 vport->fc_myDID = PT2PT_RemoteID;
7164 * The vport state should go to LPFC_FLOGI only
7165 * AFTER we issue a FLOGI, not receive one.
7167 spin_lock_irq(shost->host_lock);
7168 fc_flag = vport->fc_flag;
7169 port_state = vport->port_state;
7170 vport->fc_flag |= FC_PT2PT;
7171 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
7173 /* Acking an unsol FLOGI. Count 1 for link bounce
7176 vport->rcv_flogi_cnt++;
7177 spin_unlock_irq(shost->host_lock);
7178 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7179 "3311 Rcv Flogi PS x%x new PS x%x "
7180 "fc_flag x%x new fc_flag x%x\n",
7181 port_state, vport->port_state,
7182 fc_flag, vport->fc_flag);
7185 * We temporarily set fc_myDID to make it look like we are
7186 * a Fabric. This is done just so we end up with the right
7187 * did / sid on the FLOGI ACC rsp.
7189 did = vport->fc_myDID;
7190 vport->fc_myDID = Fabric_DID;
7192 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
7194 /* Defer ACC response until AFTER we issue a FLOGI */
7195 if (!(phba->hba_flag & HBA_FLOGI_ISSUED)) {
7196 phba->defer_flogi_acc_rx_id = cmdiocb->iocb.ulpContext;
7197 phba->defer_flogi_acc_ox_id =
7198 cmdiocb->iocb.unsli3.rcvsli3.ox_id;
7200 vport->fc_myDID = did;
7202 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7203 "3344 Deferring FLOGI ACC: rx_id: x%x,"
7204 " ox_id: x%x, hba_flag x%x\n",
7205 phba->defer_flogi_acc_rx_id,
7206 phba->defer_flogi_acc_ox_id, phba->hba_flag);
7208 phba->defer_flogi_acc_flag = true;
7214 lpfc_els_rsp_acc(vport, ELS_CMD_FLOGI, cmdiocb, ndlp, NULL);
7216 /* Now lets put fc_myDID back to what its supposed to be */
7217 vport->fc_myDID = did;
7223 * lpfc_els_rcv_rnid - Process an unsolicited rnid 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 Request Node Identification Data (RNID) IOCB
7229 * received as an ELS unsolicited event. Only when the RNID specified format
7230 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
7231 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
7232 * Accept (ACC) the RNID ELS command. All the other RNID formats are
7233 * rejected by invoking the lpfc_els_rsp_reject() routine.
7236 * 0 - Successfully processed rnid iocb (currently always return 0)
7239 lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7240 struct lpfc_nodelist *ndlp)
7242 struct lpfc_dmabuf *pcmd;
7247 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7248 lp = (uint32_t *) pcmd->virt;
7255 switch (rn->Format) {
7257 case RNID_TOPOLOGY_DISC:
7259 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
7262 /* Reject this request because format not supported */
7263 stat.un.b.lsRjtRsvd0 = 0;
7264 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
7265 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
7266 stat.un.b.vendorUnique = 0;
7267 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
7274 * lpfc_els_rcv_echo - Process an unsolicited echo iocb
7275 * @vport: pointer to a host virtual N_Port data structure.
7276 * @cmdiocb: pointer to lpfc command iocb data structure.
7277 * @ndlp: pointer to a node-list data structure.
7280 * 0 - Successfully processed echo iocb (currently always return 0)
7283 lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7284 struct lpfc_nodelist *ndlp)
7288 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
7290 /* skip over first word of echo command to find echo data */
7291 pcmd += sizeof(uint32_t);
7293 lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp);
7298 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
7299 * @vport: pointer to a host virtual N_Port data structure.
7300 * @cmdiocb: pointer to lpfc command iocb data structure.
7301 * @ndlp: pointer to a node-list data structure.
7303 * This routine processes a Link Incident Report Registration(LIRR) IOCB
7304 * received as an ELS unsolicited event. Currently, this function just invokes
7305 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
7308 * 0 - Successfully processed lirr iocb (currently always return 0)
7311 lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7312 struct lpfc_nodelist *ndlp)
7316 /* For now, unconditionally reject this command */
7317 stat.un.b.lsRjtRsvd0 = 0;
7318 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
7319 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
7320 stat.un.b.vendorUnique = 0;
7321 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
7326 * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb
7327 * @vport: pointer to a host virtual N_Port data structure.
7328 * @cmdiocb: pointer to lpfc command iocb data structure.
7329 * @ndlp: pointer to a node-list data structure.
7331 * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB
7332 * received as an ELS unsolicited event. A request to RRQ shall only
7333 * be accepted if the Originator Nx_Port N_Port_ID or the Responder
7334 * Nx_Port N_Port_ID of the target Exchange is the same as the
7335 * N_Port_ID of the Nx_Port that makes the request. If the RRQ is
7336 * not accepted, an LS_RJT with reason code "Unable to perform
7337 * command request" and reason code explanation "Invalid Originator
7338 * S_ID" shall be returned. For now, we just unconditionally accept
7339 * RRQ from the target.
7342 lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7343 struct lpfc_nodelist *ndlp)
7345 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
7346 if (vport->phba->sli_rev == LPFC_SLI_REV4)
7347 lpfc_els_clear_rrq(vport, cmdiocb, ndlp);
7351 * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
7352 * @phba: pointer to lpfc hba data structure.
7353 * @pmb: pointer to the driver internal queue element for mailbox command.
7355 * This routine is the completion callback function for the MBX_READ_LNK_STAT
7356 * mailbox command. This callback function is to actually send the Accept
7357 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
7358 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
7359 * mailbox command, constructs the RPS response with the link statistics
7360 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
7361 * response to the RPS.
7363 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7364 * will be incremented by 1 for holding the ndlp and the reference to ndlp
7365 * will be stored into the context1 field of the IOCB for the completion
7366 * callback function to the RPS Accept Response ELS IOCB command.
7370 lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
7375 struct RLS_RSP *rls_rsp;
7377 struct lpfc_iocbq *elsiocb;
7378 struct lpfc_nodelist *ndlp;
7385 ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
7386 rxid = (uint16_t)((unsigned long)(pmb->ctx_buf) & 0xffff);
7387 oxid = (uint16_t)(((unsigned long)(pmb->ctx_buf) >> 16) & 0xffff);
7388 pmb->ctx_buf = NULL;
7389 pmb->ctx_ndlp = NULL;
7391 if (mb->mbxStatus) {
7392 mempool_free(pmb, phba->mbox_mem_pool);
7396 cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t);
7397 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
7398 lpfc_max_els_tries, ndlp,
7399 ndlp->nlp_DID, ELS_CMD_ACC);
7401 /* Decrement the ndlp reference count from previous mbox command */
7405 mempool_free(pmb, phba->mbox_mem_pool);
7409 icmd = &elsiocb->iocb;
7410 icmd->ulpContext = rxid;
7411 icmd->unsli3.rcvsli3.ox_id = oxid;
7413 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7414 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
7415 pcmd += sizeof(uint32_t); /* Skip past command */
7416 rls_rsp = (struct RLS_RSP *)pcmd;
7418 rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
7419 rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
7420 rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
7421 rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
7422 rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
7423 rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
7424 mempool_free(pmb, phba->mbox_mem_pool);
7425 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
7426 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
7427 "2874 Xmit ELS RLS ACC response tag x%x xri x%x, "
7428 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
7429 elsiocb->iotag, elsiocb->iocb.ulpContext,
7430 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
7432 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
7433 phba->fc_stat.elsXmitACC++;
7434 elsiocb->context1 = lpfc_nlp_get(ndlp);
7435 if (!elsiocb->context1)
7438 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
7439 if (rc == IOCB_ERROR)
7446 lpfc_els_free_iocb(phba, elsiocb);
7450 * lpfc_els_rcv_rls - Process an unsolicited rls iocb
7451 * @vport: pointer to a host virtual N_Port data structure.
7452 * @cmdiocb: pointer to lpfc command iocb data structure.
7453 * @ndlp: pointer to a node-list data structure.
7455 * This routine processes Read Link Status (RLS) IOCB received as an
7456 * ELS unsolicited event. It first checks the remote port state. If the
7457 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
7458 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
7459 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
7460 * for reading the HBA link statistics. It is for the callback function,
7461 * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command
7462 * to actually sending out RPL Accept (ACC) response.
7465 * 0 - Successfully processed rls iocb (currently always return 0)
7468 lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7469 struct lpfc_nodelist *ndlp)
7471 struct lpfc_hba *phba = vport->phba;
7475 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
7476 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
7477 /* reject the unsolicited RLS request and done with it */
7480 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
7482 lpfc_read_lnk_stat(phba, mbox);
7483 mbox->ctx_buf = (void *)((unsigned long)
7484 ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) |
7485 cmdiocb->iocb.ulpContext)); /* rx_id */
7486 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
7487 if (!mbox->ctx_ndlp)
7489 mbox->vport = vport;
7490 mbox->mbox_cmpl = lpfc_els_rsp_rls_acc;
7491 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
7492 != MBX_NOT_FINISHED)
7493 /* Mbox completion will send ELS Response */
7495 /* Decrement reference count used for the failed mbox
7500 mempool_free(mbox, phba->mbox_mem_pool);
7503 /* issue rejection response */
7504 stat.un.b.lsRjtRsvd0 = 0;
7505 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
7506 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
7507 stat.un.b.vendorUnique = 0;
7508 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
7513 * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb
7514 * @vport: pointer to a host virtual N_Port data structure.
7515 * @cmdiocb: pointer to lpfc command iocb data structure.
7516 * @ndlp: pointer to a node-list data structure.
7518 * This routine processes Read Timout Value (RTV) IOCB received as an
7519 * ELS unsolicited event. It first checks the remote port state. If the
7520 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
7521 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
7522 * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout
7523 * Value (RTV) unsolicited IOCB event.
7525 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7526 * will be incremented by 1 for holding the ndlp and the reference to ndlp
7527 * will be stored into the context1 field of the IOCB for the completion
7528 * callback function to the RTV Accept Response ELS IOCB command.
7531 * 0 - Successfully processed rtv iocb (currently always return 0)
7534 lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7535 struct lpfc_nodelist *ndlp)
7538 struct lpfc_hba *phba = vport->phba;
7540 struct RTV_RSP *rtv_rsp;
7542 struct lpfc_iocbq *elsiocb;
7546 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
7547 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
7548 /* reject the unsolicited RTV request and done with it */
7551 cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t);
7552 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
7553 lpfc_max_els_tries, ndlp,
7554 ndlp->nlp_DID, ELS_CMD_ACC);
7559 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7560 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
7561 pcmd += sizeof(uint32_t); /* Skip past command */
7563 /* use the command's xri in the response */
7564 elsiocb->iocb.ulpContext = cmdiocb->iocb.ulpContext; /* Xri / rx_id */
7565 elsiocb->iocb.unsli3.rcvsli3.ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id;
7567 rtv_rsp = (struct RTV_RSP *)pcmd;
7569 /* populate RTV payload */
7570 rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000); /* report msecs */
7571 rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov);
7572 bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0);
7573 bf_set(qtov_rttov, rtv_rsp, 0); /* Field is for FC ONLY */
7574 rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov);
7576 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
7577 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
7578 "2875 Xmit ELS RTV ACC response tag x%x xri x%x, "
7579 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, "
7580 "Data: x%x x%x x%x\n",
7581 elsiocb->iotag, elsiocb->iocb.ulpContext,
7582 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
7584 rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov);
7585 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
7586 phba->fc_stat.elsXmitACC++;
7587 elsiocb->context1 = lpfc_nlp_get(ndlp);
7588 if (!elsiocb->context1) {
7589 lpfc_els_free_iocb(phba, elsiocb);
7593 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
7594 if (rc == IOCB_ERROR) {
7596 lpfc_els_free_iocb(phba, elsiocb);
7601 /* issue rejection response */
7602 stat.un.b.lsRjtRsvd0 = 0;
7603 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
7604 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
7605 stat.un.b.vendorUnique = 0;
7606 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
7610 /* lpfc_issue_els_rrq - Process an unsolicited rrq iocb
7611 * @vport: pointer to a host virtual N_Port data structure.
7612 * @ndlp: pointer to a node-list data structure.
7613 * @did: DID of the target.
7614 * @rrq: Pointer to the rrq struct.
7616 * Build a ELS RRQ command and send it to the target. If the issue_iocb is
7617 * Successful the the completion handler will clear the RRQ.
7620 * 0 - Successfully sent rrq els iocb.
7621 * 1 - Failed to send rrq els iocb.
7624 lpfc_issue_els_rrq(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
7625 uint32_t did, struct lpfc_node_rrq *rrq)
7627 struct lpfc_hba *phba = vport->phba;
7628 struct RRQ *els_rrq;
7629 struct lpfc_iocbq *elsiocb;
7635 if (ndlp != rrq->ndlp)
7640 /* If ndlp is not NULL, we will bump the reference count on it */
7641 cmdsize = (sizeof(uint32_t) + sizeof(struct RRQ));
7642 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, did,
7647 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7649 /* For RRQ request, remainder of payload is Exchange IDs */
7650 *((uint32_t *) (pcmd)) = ELS_CMD_RRQ;
7651 pcmd += sizeof(uint32_t);
7652 els_rrq = (struct RRQ *) pcmd;
7654 bf_set(rrq_oxid, els_rrq, phba->sli4_hba.xri_ids[rrq->xritag]);
7655 bf_set(rrq_rxid, els_rrq, rrq->rxid);
7656 bf_set(rrq_did, els_rrq, vport->fc_myDID);
7657 els_rrq->rrq = cpu_to_be32(els_rrq->rrq);
7658 els_rrq->rrq_exchg = cpu_to_be32(els_rrq->rrq_exchg);
7661 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7662 "Issue RRQ: did:x%x",
7663 did, rrq->xritag, rrq->rxid);
7664 elsiocb->context_un.rrq = rrq;
7665 elsiocb->iocb_cmpl = lpfc_cmpl_els_rrq;
7666 elsiocb->context1 = lpfc_nlp_get(ndlp);
7667 if (!elsiocb->context1)
7670 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
7671 if (ret == IOCB_ERROR)
7678 lpfc_els_free_iocb(phba, elsiocb);
7683 * lpfc_send_rrq - Sends ELS RRQ if needed.
7684 * @phba: pointer to lpfc hba data structure.
7685 * @rrq: pointer to the active rrq.
7687 * This routine will call the lpfc_issue_els_rrq if the rrq is
7688 * still active for the xri. If this function returns a failure then
7689 * the caller needs to clean up the RRQ by calling lpfc_clr_active_rrq.
7691 * Returns 0 Success.
7695 lpfc_send_rrq(struct lpfc_hba *phba, struct lpfc_node_rrq *rrq)
7697 struct lpfc_nodelist *ndlp = lpfc_findnode_did(rrq->vport,
7702 if (lpfc_test_rrq_active(phba, ndlp, rrq->xritag))
7703 return lpfc_issue_els_rrq(rrq->vport, ndlp,
7710 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
7711 * @vport: pointer to a host virtual N_Port data structure.
7712 * @cmdsize: size of the ELS command.
7713 * @oldiocb: pointer to the original lpfc command iocb data structure.
7714 * @ndlp: pointer to a node-list data structure.
7716 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
7717 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
7719 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7720 * will be incremented by 1 for holding the ndlp and the reference to ndlp
7721 * will be stored into the context1 field of the IOCB for the completion
7722 * callback function to the RPL Accept Response ELS command.
7725 * 0 - Successfully issued ACC RPL ELS command
7726 * 1 - Failed to issue ACC RPL ELS command
7729 lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
7730 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
7733 struct lpfc_hba *phba = vport->phba;
7734 IOCB_t *icmd, *oldcmd;
7736 struct lpfc_iocbq *elsiocb;
7739 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
7740 ndlp->nlp_DID, ELS_CMD_ACC);
7745 icmd = &elsiocb->iocb;
7746 oldcmd = &oldiocb->iocb;
7747 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
7748 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
7750 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7751 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
7752 pcmd += sizeof(uint16_t);
7753 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
7754 pcmd += sizeof(uint16_t);
7756 /* Setup the RPL ACC payload */
7757 rpl_rsp.listLen = be32_to_cpu(1);
7759 rpl_rsp.port_num_blk.portNum = 0;
7760 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
7761 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
7762 sizeof(struct lpfc_name));
7763 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
7764 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
7765 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7766 "0120 Xmit ELS RPL ACC response tag x%x "
7767 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
7769 elsiocb->iotag, elsiocb->iocb.ulpContext,
7770 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
7772 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
7773 phba->fc_stat.elsXmitACC++;
7774 elsiocb->context1 = lpfc_nlp_get(ndlp);
7775 if (!elsiocb->context1)
7778 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
7779 if (rc == IOCB_ERROR)
7786 lpfc_els_free_iocb(phba, elsiocb);
7791 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
7792 * @vport: pointer to a host virtual N_Port data structure.
7793 * @cmdiocb: pointer to lpfc command iocb data structure.
7794 * @ndlp: pointer to a node-list data structure.
7796 * This routine processes Read Port List (RPL) IOCB received as an ELS
7797 * unsolicited event. It first checks the remote port state. If the remote
7798 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
7799 * invokes the lpfc_els_rsp_reject() routine to send reject response.
7800 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
7801 * to accept the RPL.
7804 * 0 - Successfully processed rpl iocb (currently always return 0)
7807 lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7808 struct lpfc_nodelist *ndlp)
7810 struct lpfc_dmabuf *pcmd;
7817 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
7818 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
7819 /* issue rejection response */
7820 stat.un.b.lsRjtRsvd0 = 0;
7821 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
7822 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
7823 stat.un.b.vendorUnique = 0;
7824 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
7826 /* rejected the unsolicited RPL request and done with it */
7830 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7831 lp = (uint32_t *) pcmd->virt;
7832 rpl = (RPL *) (lp + 1);
7833 maxsize = be32_to_cpu(rpl->maxsize);
7835 /* We support only one port */
7836 if ((rpl->index == 0) &&
7838 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
7839 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
7841 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
7843 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
7849 * lpfc_els_rcv_farp - Process an unsolicited farp request els command
7850 * @vport: pointer to a virtual N_Port data structure.
7851 * @cmdiocb: pointer to lpfc command iocb data structure.
7852 * @ndlp: pointer to a node-list data structure.
7854 * This routine processes Fibre Channel Address Resolution Protocol
7855 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
7856 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
7857 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
7858 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
7859 * remote PortName is compared against the FC PortName stored in the @vport
7860 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
7861 * compared against the FC NodeName stored in the @vport data structure.
7862 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
7863 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
7864 * invoked to send out FARP Response to the remote node. Before sending the
7865 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
7866 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
7867 * routine is invoked to log into the remote port first.
7870 * 0 - Either the FARP Match Mode not supported or successfully processed
7873 lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7874 struct lpfc_nodelist *ndlp)
7876 struct lpfc_dmabuf *pcmd;
7882 icmd = &cmdiocb->iocb;
7883 did = icmd->un.elsreq64.remoteID;
7884 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7885 lp = (uint32_t *) pcmd->virt;
7889 /* FARP-REQ received from DID <did> */
7890 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7891 "0601 FARP-REQ received from DID x%x\n", did);
7892 /* We will only support match on WWPN or WWNN */
7893 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
7898 /* If this FARP command is searching for my portname */
7899 if (fp->Mflags & FARP_MATCH_PORT) {
7900 if (memcmp(&fp->RportName, &vport->fc_portname,
7901 sizeof(struct lpfc_name)) == 0)
7905 /* If this FARP command is searching for my nodename */
7906 if (fp->Mflags & FARP_MATCH_NODE) {
7907 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
7908 sizeof(struct lpfc_name)) == 0)
7913 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
7914 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
7915 /* Log back into the node before sending the FARP. */
7916 if (fp->Rflags & FARP_REQUEST_PLOGI) {
7917 ndlp->nlp_prev_state = ndlp->nlp_state;
7918 lpfc_nlp_set_state(vport, ndlp,
7919 NLP_STE_PLOGI_ISSUE);
7920 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
7923 /* Send a FARP response to that node */
7924 if (fp->Rflags & FARP_REQUEST_FARPR)
7925 lpfc_issue_els_farpr(vport, did, 0);
7932 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
7933 * @vport: pointer to a host virtual N_Port data structure.
7934 * @cmdiocb: pointer to lpfc command iocb data structure.
7935 * @ndlp: pointer to a node-list data structure.
7937 * This routine processes Fibre Channel Address Resolution Protocol
7938 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
7939 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
7940 * the FARP response request.
7943 * 0 - Successfully processed FARPR IOCB (currently always return 0)
7946 lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7947 struct lpfc_nodelist *ndlp)
7949 struct lpfc_dmabuf *pcmd;
7954 icmd = &cmdiocb->iocb;
7955 did = icmd->un.elsreq64.remoteID;
7956 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7957 lp = (uint32_t *) pcmd->virt;
7960 /* FARP-RSP received from DID <did> */
7961 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7962 "0600 FARP-RSP received from DID x%x\n", did);
7963 /* ACCEPT the Farp resp request */
7964 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
7970 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
7971 * @vport: pointer to a host virtual N_Port data structure.
7972 * @cmdiocb: pointer to lpfc command iocb data structure.
7973 * @fan_ndlp: pointer to a node-list data structure.
7975 * This routine processes a Fabric Address Notification (FAN) IOCB
7976 * command received as an ELS unsolicited event. The FAN ELS command will
7977 * only be processed on a physical port (i.e., the @vport represents the
7978 * physical port). The fabric NodeName and PortName from the FAN IOCB are
7979 * compared against those in the phba data structure. If any of those is
7980 * different, the lpfc_initial_flogi() routine is invoked to initialize
7981 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
7982 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
7983 * is invoked to register login to the fabric.
7986 * 0 - Successfully processed fan iocb (currently always return 0).
7989 lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7990 struct lpfc_nodelist *fan_ndlp)
7992 struct lpfc_hba *phba = vport->phba;
7996 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
7997 lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
7999 /* FAN received; Fan does not have a reply sequence */
8000 if ((vport == phba->pport) &&
8001 (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
8002 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
8003 sizeof(struct lpfc_name))) ||
8004 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
8005 sizeof(struct lpfc_name)))) {
8006 /* This port has switched fabrics. FLOGI is required */
8007 lpfc_issue_init_vfi(vport);
8009 /* FAN verified - skip FLOGI */
8010 vport->fc_myDID = vport->fc_prevDID;
8011 if (phba->sli_rev < LPFC_SLI_REV4)
8012 lpfc_issue_fabric_reglogin(vport);
8014 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
8015 "3138 Need register VFI: (x%x/%x)\n",
8016 vport->fc_prevDID, vport->fc_myDID);
8017 lpfc_issue_reg_vfi(vport);
8025 * lpfc_els_timeout - Handler funciton to the els timer
8026 * @t: timer context used to obtain the vport.
8028 * This routine is invoked by the ELS timer after timeout. It posts the ELS
8029 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
8030 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
8031 * up the worker thread. It is for the worker thread to invoke the routine
8032 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
8035 lpfc_els_timeout(struct timer_list *t)
8037 struct lpfc_vport *vport = from_timer(vport, t, els_tmofunc);
8038 struct lpfc_hba *phba = vport->phba;
8039 uint32_t tmo_posted;
8040 unsigned long iflag;
8042 spin_lock_irqsave(&vport->work_port_lock, iflag);
8043 tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
8044 if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING)))
8045 vport->work_port_events |= WORKER_ELS_TMO;
8046 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
8048 if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING)))
8049 lpfc_worker_wake_up(phba);
8055 * lpfc_els_timeout_handler - Process an els timeout event
8056 * @vport: pointer to a virtual N_Port data structure.
8058 * This routine is the actual handler function that processes an ELS timeout
8059 * event. It walks the ELS ring to get and abort all the IOCBs (except the
8060 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
8061 * invoking the lpfc_sli_issue_abort_iotag() routine.
8064 lpfc_els_timeout_handler(struct lpfc_vport *vport)
8066 struct lpfc_hba *phba = vport->phba;
8067 struct lpfc_sli_ring *pring;
8068 struct lpfc_iocbq *tmp_iocb, *piocb;
8070 struct lpfc_dmabuf *pcmd;
8071 uint32_t els_command = 0;
8073 uint32_t remote_ID = 0xffffffff;
8074 LIST_HEAD(abort_list);
8077 timeout = (uint32_t)(phba->fc_ratov << 1);
8079 pring = lpfc_phba_elsring(phba);
8080 if (unlikely(!pring))
8083 if (phba->pport->load_flag & FC_UNLOADING)
8086 spin_lock_irq(&phba->hbalock);
8087 if (phba->sli_rev == LPFC_SLI_REV4)
8088 spin_lock(&pring->ring_lock);
8090 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
8093 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
8094 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
8095 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
8098 if (piocb->vport != vport)
8101 pcmd = (struct lpfc_dmabuf *) piocb->context2;
8103 els_command = *(uint32_t *) (pcmd->virt);
8105 if (els_command == ELS_CMD_FARP ||
8106 els_command == ELS_CMD_FARPR ||
8107 els_command == ELS_CMD_FDISC)
8110 if (piocb->drvrTimeout > 0) {
8111 if (piocb->drvrTimeout >= timeout)
8112 piocb->drvrTimeout -= timeout;
8114 piocb->drvrTimeout = 0;
8118 remote_ID = 0xffffffff;
8119 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
8120 remote_ID = cmd->un.elsreq64.remoteID;
8122 struct lpfc_nodelist *ndlp;
8123 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
8125 remote_ID = ndlp->nlp_DID;
8127 list_add_tail(&piocb->dlist, &abort_list);
8129 if (phba->sli_rev == LPFC_SLI_REV4)
8130 spin_unlock(&pring->ring_lock);
8131 spin_unlock_irq(&phba->hbalock);
8133 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
8135 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
8136 "0127 ELS timeout Data: x%x x%x x%x "
8137 "x%x\n", els_command,
8138 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
8139 spin_lock_irq(&phba->hbalock);
8140 list_del_init(&piocb->dlist);
8141 lpfc_sli_issue_abort_iotag(phba, pring, piocb, NULL);
8142 spin_unlock_irq(&phba->hbalock);
8145 if (!list_empty(&pring->txcmplq))
8146 if (!(phba->pport->load_flag & FC_UNLOADING))
8147 mod_timer(&vport->els_tmofunc,
8148 jiffies + msecs_to_jiffies(1000 * timeout));
8152 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
8153 * @vport: pointer to a host virtual N_Port data structure.
8155 * This routine is used to clean up all the outstanding ELS commands on a
8156 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
8157 * routine. After that, it walks the ELS transmit queue to remove all the
8158 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
8159 * the IOCBs with a non-NULL completion callback function, the callback
8160 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
8161 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
8162 * callback function, the IOCB will simply be released. Finally, it walks
8163 * the ELS transmit completion queue to issue an abort IOCB to any transmit
8164 * completion queue IOCB that is associated with the @vport and is not
8165 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
8166 * part of the discovery state machine) out to HBA by invoking the
8167 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
8168 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
8169 * the IOCBs are aborted when this function returns.
8172 lpfc_els_flush_cmd(struct lpfc_vport *vport)
8174 LIST_HEAD(abort_list);
8175 struct lpfc_hba *phba = vport->phba;
8176 struct lpfc_sli_ring *pring;
8177 struct lpfc_iocbq *tmp_iocb, *piocb;
8179 unsigned long iflags = 0;
8181 lpfc_fabric_abort_vport(vport);
8184 * For SLI3, only the hbalock is required. But SLI4 needs to coordinate
8185 * with the ring insert operation. Because lpfc_sli_issue_abort_iotag
8186 * ultimately grabs the ring_lock, the driver must splice the list into
8187 * a working list and release the locks before calling the abort.
8189 spin_lock_irqsave(&phba->hbalock, iflags);
8190 pring = lpfc_phba_elsring(phba);
8192 /* Bail out if we've no ELS wq, like in PCI error recovery case. */
8193 if (unlikely(!pring)) {
8194 spin_unlock_irqrestore(&phba->hbalock, iflags);
8198 if (phba->sli_rev == LPFC_SLI_REV4)
8199 spin_lock(&pring->ring_lock);
8201 /* First we need to issue aborts to outstanding cmds on txcmpl */
8202 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
8203 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
8206 if (piocb->vport != vport)
8209 if (piocb->iocb_flag & LPFC_DRIVER_ABORTED)
8212 /* On the ELS ring we can have ELS_REQUESTs or
8213 * GEN_REQUESTs waiting for a response.
8216 if (cmd->ulpCommand == CMD_ELS_REQUEST64_CR) {
8217 list_add_tail(&piocb->dlist, &abort_list);
8219 /* If the link is down when flushing ELS commands
8220 * the firmware will not complete them till after
8221 * the link comes back up. This may confuse
8222 * discovery for the new link up, so we need to
8223 * change the compl routine to just clean up the iocb
8224 * and avoid any retry logic.
8226 if (phba->link_state == LPFC_LINK_DOWN)
8227 piocb->iocb_cmpl = lpfc_cmpl_els_link_down;
8229 if (cmd->ulpCommand == CMD_GEN_REQUEST64_CR)
8230 list_add_tail(&piocb->dlist, &abort_list);
8233 if (phba->sli_rev == LPFC_SLI_REV4)
8234 spin_unlock(&pring->ring_lock);
8235 spin_unlock_irqrestore(&phba->hbalock, iflags);
8237 /* Abort each txcmpl iocb on aborted list and remove the dlist links. */
8238 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
8239 spin_lock_irqsave(&phba->hbalock, iflags);
8240 list_del_init(&piocb->dlist);
8241 lpfc_sli_issue_abort_iotag(phba, pring, piocb, NULL);
8242 spin_unlock_irqrestore(&phba->hbalock, iflags);
8244 if (!list_empty(&abort_list))
8245 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
8246 "3387 abort list for txq not empty\n");
8247 INIT_LIST_HEAD(&abort_list);
8249 spin_lock_irqsave(&phba->hbalock, iflags);
8250 if (phba->sli_rev == LPFC_SLI_REV4)
8251 spin_lock(&pring->ring_lock);
8253 /* No need to abort the txq list,
8254 * just queue them up for lpfc_sli_cancel_iocbs
8256 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
8259 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
8263 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
8264 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
8265 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
8266 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
8267 cmd->ulpCommand == CMD_ABORT_XRI_CN)
8270 if (piocb->vport != vport)
8273 list_del_init(&piocb->list);
8274 list_add_tail(&piocb->list, &abort_list);
8277 /* The same holds true for any FLOGI/FDISC on the fabric_iocb_list */
8278 if (vport == phba->pport) {
8279 list_for_each_entry_safe(piocb, tmp_iocb,
8280 &phba->fabric_iocb_list, list) {
8282 list_del_init(&piocb->list);
8283 list_add_tail(&piocb->list, &abort_list);
8287 if (phba->sli_rev == LPFC_SLI_REV4)
8288 spin_unlock(&pring->ring_lock);
8289 spin_unlock_irqrestore(&phba->hbalock, iflags);
8291 /* Cancel all the IOCBs from the completions list */
8292 lpfc_sli_cancel_iocbs(phba, &abort_list,
8293 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
8299 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
8300 * @phba: pointer to lpfc hba data structure.
8302 * This routine is used to clean up all the outstanding ELS commands on a
8303 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
8304 * routine. After that, it walks the ELS transmit queue to remove all the
8305 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
8306 * the IOCBs with the completion callback function associated, the callback
8307 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
8308 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
8309 * callback function associated, the IOCB will simply be released. Finally,
8310 * it walks the ELS transmit completion queue to issue an abort IOCB to any
8311 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
8312 * management plane IOCBs that are not part of the discovery state machine)
8313 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
8316 lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
8318 struct lpfc_vport *vport;
8320 spin_lock_irq(&phba->port_list_lock);
8321 list_for_each_entry(vport, &phba->port_list, listentry)
8322 lpfc_els_flush_cmd(vport);
8323 spin_unlock_irq(&phba->port_list_lock);
8329 * lpfc_send_els_failure_event - Posts an ELS command failure event
8330 * @phba: Pointer to hba context object.
8331 * @cmdiocbp: Pointer to command iocb which reported error.
8332 * @rspiocbp: Pointer to response iocb which reported error.
8334 * This function sends an event when there is an ELS command
8338 lpfc_send_els_failure_event(struct lpfc_hba *phba,
8339 struct lpfc_iocbq *cmdiocbp,
8340 struct lpfc_iocbq *rspiocbp)
8342 struct lpfc_vport *vport = cmdiocbp->vport;
8343 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8344 struct lpfc_lsrjt_event lsrjt_event;
8345 struct lpfc_fabric_event_header fabric_event;
8347 struct lpfc_nodelist *ndlp;
8350 ndlp = cmdiocbp->context1;
8354 if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) {
8355 lsrjt_event.header.event_type = FC_REG_ELS_EVENT;
8356 lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV;
8357 memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname,
8358 sizeof(struct lpfc_name));
8359 memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename,
8360 sizeof(struct lpfc_name));
8361 pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
8362 cmdiocbp->context2)->virt);
8363 lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0;
8364 stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]);
8365 lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode;
8366 lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp;
8367 fc_host_post_vendor_event(shost,
8368 fc_get_event_number(),
8369 sizeof(lsrjt_event),
8370 (char *)&lsrjt_event,
8374 if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) ||
8375 (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) {
8376 fabric_event.event_type = FC_REG_FABRIC_EVENT;
8377 if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY)
8378 fabric_event.subcategory = LPFC_EVENT_PORT_BUSY;
8380 fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY;
8381 memcpy(fabric_event.wwpn, &ndlp->nlp_portname,
8382 sizeof(struct lpfc_name));
8383 memcpy(fabric_event.wwnn, &ndlp->nlp_nodename,
8384 sizeof(struct lpfc_name));
8385 fc_host_post_vendor_event(shost,
8386 fc_get_event_number(),
8387 sizeof(fabric_event),
8388 (char *)&fabric_event,
8396 * lpfc_send_els_event - Posts unsolicited els event
8397 * @vport: Pointer to vport object.
8398 * @ndlp: Pointer FC node object.
8399 * @payload: ELS command code type.
8401 * This function posts an event when there is an incoming
8402 * unsolicited ELS command.
8405 lpfc_send_els_event(struct lpfc_vport *vport,
8406 struct lpfc_nodelist *ndlp,
8409 struct lpfc_els_event_header *els_data = NULL;
8410 struct lpfc_logo_event *logo_data = NULL;
8411 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8413 if (*payload == ELS_CMD_LOGO) {
8414 logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL);
8416 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
8417 "0148 Failed to allocate memory "
8418 "for LOGO event\n");
8421 els_data = &logo_data->header;
8423 els_data = kmalloc(sizeof(struct lpfc_els_event_header),
8426 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
8427 "0149 Failed to allocate memory "
8432 els_data->event_type = FC_REG_ELS_EVENT;
8435 els_data->subcategory = LPFC_EVENT_PLOGI_RCV;
8438 els_data->subcategory = LPFC_EVENT_PRLO_RCV;
8441 els_data->subcategory = LPFC_EVENT_ADISC_RCV;
8444 els_data->subcategory = LPFC_EVENT_LOGO_RCV;
8445 /* Copy the WWPN in the LOGO payload */
8446 memcpy(logo_data->logo_wwpn, &payload[2],
8447 sizeof(struct lpfc_name));
8453 memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name));
8454 memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name));
8455 if (*payload == ELS_CMD_LOGO) {
8456 fc_host_post_vendor_event(shost,
8457 fc_get_event_number(),
8458 sizeof(struct lpfc_logo_event),
8463 fc_host_post_vendor_event(shost,
8464 fc_get_event_number(),
8465 sizeof(struct lpfc_els_event_header),
8475 DECLARE_ENUM2STR_LOOKUP(lpfc_get_tlv_dtag_nm, fc_ls_tlv_dtag,
8476 FC_LS_TLV_DTAG_INIT);
8478 DECLARE_ENUM2STR_LOOKUP(lpfc_get_fpin_li_event_nm, fc_fpin_li_event_types,
8479 FC_FPIN_LI_EVT_TYPES_INIT);
8482 * lpfc_els_rcv_fpin_li - Process an FPIN Link Integrity Event.
8483 * @vport: Pointer to vport object.
8484 * @tlv: Pointer to the Link Integrity Notification Descriptor.
8486 * This function processes a link integrity FPIN event by
8490 lpfc_els_rcv_fpin_li(struct lpfc_vport *vport, struct fc_tlv_desc *tlv)
8492 struct fc_fn_li_desc *li = (struct fc_fn_li_desc *)tlv;
8493 const char *li_evt_str;
8496 li_evt = be16_to_cpu(li->event_type);
8497 li_evt_str = lpfc_get_fpin_li_event_nm(li_evt);
8499 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
8500 "4680 FPIN Link Integrity %s (x%x) "
8501 "Detecting PN x%016llx Attached PN x%016llx "
8502 "Duration %d mSecs Count %d Port Cnt %d\n",
8504 be64_to_cpu(li->detecting_wwpn),
8505 be64_to_cpu(li->attached_wwpn),
8506 be32_to_cpu(li->event_threshold),
8507 be32_to_cpu(li->event_count),
8508 be32_to_cpu(li->pname_count));
8512 lpfc_els_rcv_fpin(struct lpfc_vport *vport, struct fc_els_fpin *fpin,
8515 struct fc_tlv_desc *tlv;
8516 const char *dtag_nm;
8517 uint32_t desc_cnt = 0, bytes_remain;
8520 /* FPINs handled only if we are in the right discovery state */
8521 if (vport->port_state < LPFC_DISC_AUTH)
8524 /* make sure there is the full fpin header */
8525 if (fpin_length < sizeof(struct fc_els_fpin))
8528 tlv = (struct fc_tlv_desc *)&fpin->fpin_desc[0];
8529 bytes_remain = fpin_length - offsetof(struct fc_els_fpin, fpin_desc);
8530 bytes_remain = min_t(u32, bytes_remain, be32_to_cpu(fpin->desc_len));
8532 /* process each descriptor */
8533 while (bytes_remain >= FC_TLV_DESC_HDR_SZ &&
8534 bytes_remain >= FC_TLV_DESC_SZ_FROM_LENGTH(tlv)) {
8536 dtag = be32_to_cpu(tlv->desc_tag);
8538 case ELS_DTAG_LNK_INTEGRITY:
8539 lpfc_els_rcv_fpin_li(vport, tlv);
8542 dtag_nm = lpfc_get_tlv_dtag_nm(dtag);
8543 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
8544 "4678 skipped FPIN descriptor[%d]: "
8546 desc_cnt, dtag, dtag_nm);
8551 bytes_remain -= FC_TLV_DESC_SZ_FROM_LENGTH(tlv);
8552 tlv = fc_tlv_next_desc(tlv);
8555 fc_host_fpin_rcv(lpfc_shost_from_vport(vport), fpin_length,
8560 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
8561 * @phba: pointer to lpfc hba data structure.
8562 * @pring: pointer to a SLI ring.
8563 * @vport: pointer to a host virtual N_Port data structure.
8564 * @elsiocb: pointer to lpfc els command iocb data structure.
8566 * This routine is used for processing the IOCB associated with a unsolicited
8567 * event. It first determines whether there is an existing ndlp that matches
8568 * the DID from the unsolicited IOCB. If not, it will create a new one with
8569 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
8570 * IOCB is then used to invoke the proper routine and to set up proper state
8571 * of the discovery state machine.
8574 lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
8575 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
8577 struct Scsi_Host *shost;
8578 struct lpfc_nodelist *ndlp;
8580 uint32_t *payload, payload_len;
8581 uint32_t cmd, did, newnode;
8582 uint8_t rjt_exp, rjt_err = 0, init_link = 0;
8583 IOCB_t *icmd = &elsiocb->iocb;
8586 if (!vport || !(elsiocb->context2))
8590 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
8591 payload_len = elsiocb->iocb.unsli3.rcvsli3.acc_len;
8593 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
8594 lpfc_post_buffer(phba, pring, 1);
8596 did = icmd->un.rcvels.remoteID;
8597 if (icmd->ulpStatus) {
8598 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8599 "RCV Unsol ELS: status:x%x/x%x did:x%x",
8600 icmd->ulpStatus, icmd->un.ulpWord[4], did);
8604 /* Check to see if link went down during discovery */
8605 if (lpfc_els_chk_latt(vport))
8608 /* Ignore traffic received during vport shutdown. */
8609 if (vport->load_flag & FC_UNLOADING)
8612 /* If NPort discovery is delayed drop incoming ELS */
8613 if ((vport->fc_flag & FC_DISC_DELAYED) &&
8614 (cmd != ELS_CMD_PLOGI))
8617 ndlp = lpfc_findnode_did(vport, did);
8619 /* Cannot find existing Fabric ndlp, so allocate a new one */
8620 ndlp = lpfc_nlp_init(vport, did);
8623 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
8625 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
8626 ndlp->nlp_type |= NLP_FABRIC;
8627 } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
8628 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
8632 phba->fc_stat.elsRcvFrame++;
8635 * Do not process any unsolicited ELS commands
8636 * if the ndlp is in DEV_LOSS
8638 shost = lpfc_shost_from_vport(vport);
8639 spin_lock_irq(&ndlp->lock);
8640 if (ndlp->nlp_flag & NLP_IN_DEV_LOSS) {
8641 spin_unlock_irq(&ndlp->lock);
8646 spin_unlock_irq(&ndlp->lock);
8648 elsiocb->context1 = lpfc_nlp_get(ndlp);
8649 if (!elsiocb->context1)
8651 elsiocb->vport = vport;
8653 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
8654 cmd &= ELS_CMD_MASK;
8656 /* ELS command <elsCmd> received from NPORT <did> */
8657 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
8658 "0112 ELS command x%x received from NPORT x%x "
8659 "refcnt %d Data: x%x x%x x%x x%x\n",
8660 cmd, did, kref_read(&ndlp->kref), vport->port_state,
8661 vport->fc_flag, vport->fc_myDID, vport->fc_prevDID);
8663 /* reject till our FLOGI completes or PLOGI assigned DID via PT2PT */
8664 if ((vport->port_state < LPFC_FABRIC_CFG_LINK) &&
8665 (cmd != ELS_CMD_FLOGI) &&
8666 !((cmd == ELS_CMD_PLOGI) && (vport->fc_flag & FC_PT2PT))) {
8667 rjt_err = LSRJT_LOGICAL_BSY;
8668 rjt_exp = LSEXP_NOTHING_MORE;
8674 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8675 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
8676 did, vport->port_state, ndlp->nlp_flag);
8678 phba->fc_stat.elsRcvPLOGI++;
8679 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
8680 if (phba->sli_rev == LPFC_SLI_REV4 &&
8681 (phba->pport->fc_flag & FC_PT2PT)) {
8682 vport->fc_prevDID = vport->fc_myDID;
8683 /* Our DID needs to be updated before registering
8684 * the vfi. This is done in lpfc_rcv_plogi but
8685 * that is called after the reg_vfi.
8687 vport->fc_myDID = elsiocb->iocb.un.rcvels.parmRo;
8688 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
8689 "3312 Remote port assigned DID x%x "
8690 "%x\n", vport->fc_myDID,
8694 lpfc_send_els_event(vport, ndlp, payload);
8696 /* If Nport discovery is delayed, reject PLOGIs */
8697 if (vport->fc_flag & FC_DISC_DELAYED) {
8698 rjt_err = LSRJT_UNABLE_TPC;
8699 rjt_exp = LSEXP_NOTHING_MORE;
8703 if (vport->port_state < LPFC_DISC_AUTH) {
8704 if (!(phba->pport->fc_flag & FC_PT2PT) ||
8705 (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
8706 rjt_err = LSRJT_UNABLE_TPC;
8707 rjt_exp = LSEXP_NOTHING_MORE;
8712 spin_lock_irq(&ndlp->lock);
8713 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
8714 spin_unlock_irq(&ndlp->lock);
8716 lpfc_disc_state_machine(vport, ndlp, elsiocb,
8721 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8722 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
8723 did, vport->port_state, ndlp->nlp_flag);
8725 phba->fc_stat.elsRcvFLOGI++;
8727 /* If the driver believes fabric discovery is done and is ready,
8728 * bounce the link. There is some descrepancy.
8730 if (vport->port_state >= LPFC_LOCAL_CFG_LINK &&
8731 vport->fc_flag & FC_PT2PT &&
8732 vport->rcv_flogi_cnt >= 1) {
8733 rjt_err = LSRJT_LOGICAL_BSY;
8734 rjt_exp = LSEXP_NOTHING_MORE;
8739 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
8741 lpfc_disc_state_machine(vport, ndlp, NULL,
8745 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8746 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
8747 did, vport->port_state, ndlp->nlp_flag);
8749 phba->fc_stat.elsRcvLOGO++;
8750 lpfc_send_els_event(vport, ndlp, payload);
8751 if (vport->port_state < LPFC_DISC_AUTH) {
8752 rjt_err = LSRJT_UNABLE_TPC;
8753 rjt_exp = LSEXP_NOTHING_MORE;
8756 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
8759 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8760 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
8761 did, vport->port_state, ndlp->nlp_flag);
8763 phba->fc_stat.elsRcvPRLO++;
8764 lpfc_send_els_event(vport, ndlp, payload);
8765 if (vport->port_state < LPFC_DISC_AUTH) {
8766 rjt_err = LSRJT_UNABLE_TPC;
8767 rjt_exp = LSEXP_NOTHING_MORE;
8770 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
8773 phba->fc_stat.elsRcvLCB++;
8774 lpfc_els_rcv_lcb(vport, elsiocb, ndlp);
8777 phba->fc_stat.elsRcvRDP++;
8778 lpfc_els_rcv_rdp(vport, elsiocb, ndlp);
8781 phba->fc_stat.elsRcvRSCN++;
8782 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
8784 lpfc_disc_state_machine(vport, ndlp, NULL,
8788 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8789 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
8790 did, vport->port_state, ndlp->nlp_flag);
8792 lpfc_send_els_event(vport, ndlp, payload);
8793 phba->fc_stat.elsRcvADISC++;
8794 if (vport->port_state < LPFC_DISC_AUTH) {
8795 rjt_err = LSRJT_UNABLE_TPC;
8796 rjt_exp = LSEXP_NOTHING_MORE;
8799 lpfc_disc_state_machine(vport, ndlp, elsiocb,
8803 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8804 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
8805 did, vport->port_state, ndlp->nlp_flag);
8807 phba->fc_stat.elsRcvPDISC++;
8808 if (vport->port_state < LPFC_DISC_AUTH) {
8809 rjt_err = LSRJT_UNABLE_TPC;
8810 rjt_exp = LSEXP_NOTHING_MORE;
8813 lpfc_disc_state_machine(vport, ndlp, elsiocb,
8817 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8818 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
8819 did, vport->port_state, ndlp->nlp_flag);
8821 phba->fc_stat.elsRcvFARPR++;
8822 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
8825 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8826 "RCV FARP: did:x%x/ste:x%x flg:x%x",
8827 did, vport->port_state, ndlp->nlp_flag);
8829 phba->fc_stat.elsRcvFARP++;
8830 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
8833 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8834 "RCV FAN: did:x%x/ste:x%x flg:x%x",
8835 did, vport->port_state, ndlp->nlp_flag);
8837 phba->fc_stat.elsRcvFAN++;
8838 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
8841 case ELS_CMD_NVMEPRLI:
8842 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8843 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
8844 did, vport->port_state, ndlp->nlp_flag);
8846 phba->fc_stat.elsRcvPRLI++;
8847 if ((vport->port_state < LPFC_DISC_AUTH) &&
8848 (vport->fc_flag & FC_FABRIC)) {
8849 rjt_err = LSRJT_UNABLE_TPC;
8850 rjt_exp = LSEXP_NOTHING_MORE;
8853 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
8856 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8857 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
8858 did, vport->port_state, ndlp->nlp_flag);
8860 phba->fc_stat.elsRcvLIRR++;
8861 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
8863 lpfc_disc_state_machine(vport, ndlp, NULL,
8867 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8868 "RCV RLS: did:x%x/ste:x%x flg:x%x",
8869 did, vport->port_state, ndlp->nlp_flag);
8871 phba->fc_stat.elsRcvRLS++;
8872 lpfc_els_rcv_rls(vport, elsiocb, ndlp);
8874 lpfc_disc_state_machine(vport, ndlp, NULL,
8878 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8879 "RCV RPL: did:x%x/ste:x%x flg:x%x",
8880 did, vport->port_state, ndlp->nlp_flag);
8882 phba->fc_stat.elsRcvRPL++;
8883 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
8885 lpfc_disc_state_machine(vport, ndlp, NULL,
8889 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8890 "RCV RNID: did:x%x/ste:x%x flg:x%x",
8891 did, vport->port_state, ndlp->nlp_flag);
8893 phba->fc_stat.elsRcvRNID++;
8894 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
8896 lpfc_disc_state_machine(vport, ndlp, NULL,
8900 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8901 "RCV RTV: did:x%x/ste:x%x flg:x%x",
8902 did, vport->port_state, ndlp->nlp_flag);
8903 phba->fc_stat.elsRcvRTV++;
8904 lpfc_els_rcv_rtv(vport, elsiocb, ndlp);
8906 lpfc_disc_state_machine(vport, ndlp, NULL,
8910 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8911 "RCV RRQ: did:x%x/ste:x%x flg:x%x",
8912 did, vport->port_state, ndlp->nlp_flag);
8914 phba->fc_stat.elsRcvRRQ++;
8915 lpfc_els_rcv_rrq(vport, elsiocb, ndlp);
8917 lpfc_disc_state_machine(vport, ndlp, NULL,
8921 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8922 "RCV ECHO: did:x%x/ste:x%x flg:x%x",
8923 did, vport->port_state, ndlp->nlp_flag);
8925 phba->fc_stat.elsRcvECHO++;
8926 lpfc_els_rcv_echo(vport, elsiocb, ndlp);
8928 lpfc_disc_state_machine(vport, ndlp, NULL,
8932 /* receive this due to exchange closed */
8933 rjt_err = LSRJT_UNABLE_TPC;
8934 rjt_exp = LSEXP_INVALID_OX_RX;
8937 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8938 "RCV FPIN: did:x%x/ste:x%x flg:x%x",
8939 did, vport->port_state, ndlp->nlp_flag);
8941 lpfc_els_rcv_fpin(vport, (struct fc_els_fpin *)payload,
8944 /* There are no replies, so no rjt codes */
8947 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8948 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
8949 cmd, did, vport->port_state);
8951 /* Unsupported ELS command, reject */
8952 rjt_err = LSRJT_CMD_UNSUPPORTED;
8953 rjt_exp = LSEXP_NOTHING_MORE;
8955 /* Unknown ELS command <elsCmd> received from NPORT <did> */
8956 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
8957 "0115 Unknown ELS command x%x "
8958 "received from NPORT x%x\n", cmd, did);
8960 lpfc_disc_state_machine(vport, ndlp, NULL,
8966 /* check if need to LS_RJT received ELS cmd */
8968 memset(&stat, 0, sizeof(stat));
8969 stat.un.b.lsRjtRsnCode = rjt_err;
8970 stat.un.b.lsRjtRsnCodeExp = rjt_exp;
8971 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
8973 /* Remove the reference from above for new nodes. */
8975 lpfc_disc_state_machine(vport, ndlp, NULL,
8979 /* Release the reference on this elsiocb, not the ndlp. */
8980 lpfc_nlp_put(elsiocb->context1);
8981 elsiocb->context1 = NULL;
8983 /* Special case. Driver received an unsolicited command that
8984 * unsupportable given the driver's current state. Reset the
8985 * link and start over.
8988 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
8991 lpfc_linkdown(phba);
8992 lpfc_init_link(phba, mbox,
8994 phba->cfg_link_speed);
8995 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
8996 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
8997 mbox->vport = vport;
8998 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) ==
9000 mempool_free(mbox, phba->mbox_mem_pool);
9006 if (vport && !(vport->load_flag & FC_UNLOADING))
9007 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
9008 "0111 Dropping received ELS cmd "
9009 "Data: x%x x%x x%x\n",
9010 icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout);
9011 phba->fc_stat.elsRcvDrop++;
9015 * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
9016 * @phba: pointer to lpfc hba data structure.
9017 * @pring: pointer to a SLI ring.
9018 * @elsiocb: pointer to lpfc els iocb data structure.
9020 * This routine is used to process an unsolicited event received from a SLI
9021 * (Service Level Interface) ring. The actual processing of the data buffer
9022 * associated with the unsolicited event is done by invoking the routine
9023 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
9024 * SLI ring on which the unsolicited event was received.
9027 lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
9028 struct lpfc_iocbq *elsiocb)
9030 struct lpfc_vport *vport = phba->pport;
9031 IOCB_t *icmd = &elsiocb->iocb;
9033 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
9034 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
9036 elsiocb->context1 = NULL;
9037 elsiocb->context2 = NULL;
9038 elsiocb->context3 = NULL;
9040 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
9041 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
9042 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
9043 (icmd->un.ulpWord[4] & IOERR_PARAM_MASK) ==
9044 IOERR_RCV_BUFFER_WAITING) {
9045 phba->fc_stat.NoRcvBuf++;
9046 /* Not enough posted buffers; Try posting more buffers */
9047 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
9048 lpfc_post_buffer(phba, pring, 0);
9052 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
9053 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
9054 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
9055 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
9056 vport = phba->pport;
9058 vport = lpfc_find_vport_by_vpid(phba,
9059 icmd->unsli3.rcvsli3.vpi);
9062 /* If there are no BDEs associated
9063 * with this IOCB, there is nothing to do.
9065 if (icmd->ulpBdeCount == 0)
9068 /* type of ELS cmd is first 32bit word
9071 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
9072 elsiocb->context2 = bdeBuf1;
9074 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
9075 icmd->un.cont64[0].addrLow);
9076 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
9080 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
9082 * The different unsolicited event handlers would tell us
9083 * if they are done with "mp" by setting context2 to NULL.
9085 if (elsiocb->context2) {
9086 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
9087 elsiocb->context2 = NULL;
9090 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
9091 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
9092 icmd->ulpBdeCount == 2) {
9093 elsiocb->context2 = bdeBuf2;
9094 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
9095 /* free mp if we are done with it */
9096 if (elsiocb->context2) {
9097 lpfc_in_buf_free(phba, elsiocb->context2);
9098 elsiocb->context2 = NULL;
9104 lpfc_start_fdmi(struct lpfc_vport *vport)
9106 struct lpfc_nodelist *ndlp;
9108 /* If this is the first time, allocate an ndlp and initialize
9109 * it. Otherwise, make sure the node is enabled and then do the
9112 ndlp = lpfc_findnode_did(vport, FDMI_DID);
9114 ndlp = lpfc_nlp_init(vport, FDMI_DID);
9116 ndlp->nlp_type |= NLP_FABRIC;
9122 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
9123 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
9127 * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
9128 * @phba: pointer to lpfc hba data structure.
9129 * @vport: pointer to a virtual N_Port data structure.
9131 * This routine issues a Port Login (PLOGI) to the Name Server with
9132 * State Change Request (SCR) for a @vport. This routine will create an
9133 * ndlp for the Name Server associated to the @vport if such node does
9134 * not already exist. The PLOGI to Name Server is issued by invoking the
9135 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
9136 * (FDMI) is configured to the @vport, a FDMI node will be created and
9137 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
9140 lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
9142 struct lpfc_nodelist *ndlp;
9143 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
9146 * If lpfc_delay_discovery parameter is set and the clean address
9147 * bit is cleared and fc fabric parameters chenged, delay FC NPort
9150 spin_lock_irq(shost->host_lock);
9151 if (vport->fc_flag & FC_DISC_DELAYED) {
9152 spin_unlock_irq(shost->host_lock);
9153 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
9154 "3334 Delay fc port discovery for %d secs\n",
9156 mod_timer(&vport->delayed_disc_tmo,
9157 jiffies + msecs_to_jiffies(1000 * phba->fc_ratov));
9160 spin_unlock_irq(shost->host_lock);
9162 ndlp = lpfc_findnode_did(vport, NameServer_DID);
9164 ndlp = lpfc_nlp_init(vport, NameServer_DID);
9166 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
9167 lpfc_disc_start(vport);
9170 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
9171 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
9172 "0251 NameServer login: no memory\n");
9177 ndlp->nlp_type |= NLP_FABRIC;
9179 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
9181 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
9182 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
9183 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
9184 "0252 Cannot issue NameServer login\n");
9188 if ((phba->cfg_enable_SmartSAN ||
9189 (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) &&
9190 (vport->load_flag & FC_ALLOW_FDMI))
9191 lpfc_start_fdmi(vport);
9195 * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
9196 * @phba: pointer to lpfc hba data structure.
9197 * @pmb: pointer to the driver internal queue element for mailbox command.
9199 * This routine is the completion callback function to register new vport
9200 * mailbox command. If the new vport mailbox command completes successfully,
9201 * the fabric registration login shall be performed on physical port (the
9202 * new vport created is actually a physical port, with VPI 0) or the port
9203 * login to Name Server for State Change Request (SCR) will be performed
9204 * on virtual port (real virtual port, with VPI greater than 0).
9207 lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
9209 struct lpfc_vport *vport = pmb->vport;
9210 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
9211 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
9212 MAILBOX_t *mb = &pmb->u.mb;
9215 spin_lock_irq(shost->host_lock);
9216 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
9217 spin_unlock_irq(shost->host_lock);
9219 if (mb->mbxStatus) {
9220 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
9221 "0915 Register VPI failed : Status: x%x"
9222 " upd bit: x%x \n", mb->mbxStatus,
9223 mb->un.varRegVpi.upd);
9224 if (phba->sli_rev == LPFC_SLI_REV4 &&
9225 mb->un.varRegVpi.upd)
9226 goto mbox_err_exit ;
9228 switch (mb->mbxStatus) {
9229 case 0x11: /* unsupported feature */
9230 case 0x9603: /* max_vpi exceeded */
9231 case 0x9602: /* Link event since CLEAR_LA */
9232 /* giving up on vport registration */
9233 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
9234 spin_lock_irq(shost->host_lock);
9235 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
9236 spin_unlock_irq(shost->host_lock);
9237 lpfc_can_disctmo(vport);
9239 /* If reg_vpi fail with invalid VPI status, re-init VPI */
9241 spin_lock_irq(shost->host_lock);
9242 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
9243 spin_unlock_irq(shost->host_lock);
9244 lpfc_init_vpi(phba, pmb, vport->vpi);
9246 pmb->mbox_cmpl = lpfc_init_vpi_cmpl;
9247 rc = lpfc_sli_issue_mbox(phba, pmb,
9249 if (rc == MBX_NOT_FINISHED) {
9250 lpfc_printf_vlog(vport, KERN_ERR,
9252 "2732 Failed to issue INIT_VPI"
9253 " mailbox command\n");
9260 /* Try to recover from this error */
9261 if (phba->sli_rev == LPFC_SLI_REV4)
9262 lpfc_sli4_unreg_all_rpis(vport);
9263 lpfc_mbx_unreg_vpi(vport);
9264 spin_lock_irq(shost->host_lock);
9265 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
9266 spin_unlock_irq(shost->host_lock);
9267 if (mb->mbxStatus == MBX_NOT_FINISHED)
9269 if ((vport->port_type == LPFC_PHYSICAL_PORT) &&
9270 !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG)) {
9271 if (phba->sli_rev == LPFC_SLI_REV4)
9272 lpfc_issue_init_vfi(vport);
9274 lpfc_initial_flogi(vport);
9276 lpfc_initial_fdisc(vport);
9281 spin_lock_irq(shost->host_lock);
9282 vport->vpi_state |= LPFC_VPI_REGISTERED;
9283 spin_unlock_irq(shost->host_lock);
9284 if (vport == phba->pport) {
9285 if (phba->sli_rev < LPFC_SLI_REV4)
9286 lpfc_issue_fabric_reglogin(vport);
9289 * If the physical port is instantiated using
9290 * FDISC, do not start vport discovery.
9292 if (vport->port_state != LPFC_FDISC)
9293 lpfc_start_fdiscs(phba);
9294 lpfc_do_scr_ns_plogi(phba, vport);
9297 lpfc_do_scr_ns_plogi(phba, vport);
9301 /* Now, we decrement the ndlp reference count held for this
9306 mempool_free(pmb, phba->mbox_mem_pool);
9311 * lpfc_register_new_vport - Register a new vport with a HBA
9312 * @phba: pointer to lpfc hba data structure.
9313 * @vport: pointer to a host virtual N_Port data structure.
9314 * @ndlp: pointer to a node-list data structure.
9316 * This routine registers the @vport as a new virtual port with a HBA.
9317 * It is done through a registering vpi mailbox command.
9320 lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
9321 struct lpfc_nodelist *ndlp)
9323 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
9326 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
9328 lpfc_reg_vpi(vport, mbox);
9329 mbox->vport = vport;
9330 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
9331 if (!mbox->ctx_ndlp) {
9332 mempool_free(mbox, phba->mbox_mem_pool);
9336 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
9337 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
9338 == MBX_NOT_FINISHED) {
9339 /* mailbox command not success, decrement ndlp
9340 * reference count for this command
9343 mempool_free(mbox, phba->mbox_mem_pool);
9345 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
9346 "0253 Register VPI: Can't send mbox\n");
9350 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
9351 "0254 Register VPI: no memory\n");
9357 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
9358 spin_lock_irq(shost->host_lock);
9359 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
9360 spin_unlock_irq(shost->host_lock);
9365 * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer
9366 * @phba: pointer to lpfc hba data structure.
9368 * This routine cancels the retry delay timers to all the vports.
9371 lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba)
9373 struct lpfc_vport **vports;
9374 struct lpfc_nodelist *ndlp;
9375 uint32_t link_state;
9378 /* Treat this failure as linkdown for all vports */
9379 link_state = phba->link_state;
9380 lpfc_linkdown(phba);
9381 phba->link_state = link_state;
9383 vports = lpfc_create_vport_work_array(phba);
9386 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
9387 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
9389 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
9390 lpfc_els_flush_cmd(vports[i]);
9392 lpfc_destroy_vport_work_array(phba, vports);
9397 * lpfc_retry_pport_discovery - Start timer to retry FLOGI.
9398 * @phba: pointer to lpfc hba data structure.
9400 * This routine abort all pending discovery commands and
9401 * start a timer to retry FLOGI for the physical port
9405 lpfc_retry_pport_discovery(struct lpfc_hba *phba)
9407 struct lpfc_nodelist *ndlp;
9408 struct Scsi_Host *shost;
9410 /* Cancel the all vports retry delay retry timers */
9411 lpfc_cancel_all_vport_retry_delay_timer(phba);
9413 /* If fabric require FLOGI, then re-instantiate physical login */
9414 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
9418 shost = lpfc_shost_from_vport(phba->pport);
9419 mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000));
9420 spin_lock_irq(&ndlp->lock);
9421 ndlp->nlp_flag |= NLP_DELAY_TMO;
9422 spin_unlock_irq(&ndlp->lock);
9423 ndlp->nlp_last_elscmd = ELS_CMD_FLOGI;
9424 phba->pport->port_state = LPFC_FLOGI;
9429 * lpfc_fabric_login_reqd - Check if FLOGI required.
9430 * @phba: pointer to lpfc hba data structure.
9431 * @cmdiocb: pointer to FDISC command iocb.
9432 * @rspiocb: pointer to FDISC response iocb.
9434 * This routine checks if a FLOGI is reguired for FDISC
9438 lpfc_fabric_login_reqd(struct lpfc_hba *phba,
9439 struct lpfc_iocbq *cmdiocb,
9440 struct lpfc_iocbq *rspiocb)
9443 if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) ||
9444 (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED))
9451 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
9452 * @phba: pointer to lpfc hba data structure.
9453 * @cmdiocb: pointer to lpfc command iocb data structure.
9454 * @rspiocb: pointer to lpfc response iocb data structure.
9456 * This routine is the completion callback function to a Fabric Discover
9457 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
9458 * single threaded, each FDISC completion callback function will reset
9459 * the discovery timer for all vports such that the timers will not get
9460 * unnecessary timeout. The function checks the FDISC IOCB status. If error
9461 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
9462 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
9463 * assigned to the vport has been changed with the completion of the FDISC
9464 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
9465 * are unregistered from the HBA, and then the lpfc_register_new_vport()
9466 * routine is invoked to register new vport with the HBA. Otherwise, the
9467 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
9468 * Server for State Change Request (SCR).
9471 lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
9472 struct lpfc_iocbq *rspiocb)
9474 struct lpfc_vport *vport = cmdiocb->vport;
9475 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
9476 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
9477 struct lpfc_nodelist *np;
9478 struct lpfc_nodelist *next_np;
9479 IOCB_t *irsp = &rspiocb->iocb;
9480 struct lpfc_iocbq *piocb;
9481 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
9482 struct serv_parm *sp;
9483 uint8_t fabric_param_changed;
9485 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
9486 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
9487 irsp->ulpStatus, irsp->un.ulpWord[4],
9489 /* Since all FDISCs are being single threaded, we
9490 * must reset the discovery timer for ALL vports
9491 * waiting to send FDISC when one completes.
9493 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
9494 lpfc_set_disctmo(piocb->vport);
9497 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
9498 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
9499 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
9501 if (irsp->ulpStatus) {
9503 if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) {
9504 lpfc_retry_pport_discovery(phba);
9508 /* Check for retry */
9509 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
9512 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
9513 "0126 FDISC failed. (x%x/x%x)\n",
9514 irsp->ulpStatus, irsp->un.ulpWord[4]);
9517 spin_lock_irq(shost->host_lock);
9518 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
9519 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
9520 vport->fc_flag |= FC_FABRIC;
9521 if (vport->phba->fc_topology == LPFC_TOPOLOGY_LOOP)
9522 vport->fc_flag |= FC_PUBLIC_LOOP;
9523 spin_unlock_irq(shost->host_lock);
9525 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
9526 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
9527 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
9530 sp = prsp->virt + sizeof(uint32_t);
9531 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
9532 memcpy(&vport->fabric_portname, &sp->portName,
9533 sizeof(struct lpfc_name));
9534 memcpy(&vport->fabric_nodename, &sp->nodeName,
9535 sizeof(struct lpfc_name));
9536 if (fabric_param_changed &&
9537 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
9538 /* If our NportID changed, we need to ensure all
9539 * remaining NPORTs get unreg_login'ed so we can
9542 list_for_each_entry_safe(np, next_np,
9543 &vport->fc_nodes, nlp_listp) {
9544 if ((np->nlp_state != NLP_STE_NPR_NODE) ||
9545 !(np->nlp_flag & NLP_NPR_ADISC))
9547 spin_lock_irq(&ndlp->lock);
9548 np->nlp_flag &= ~NLP_NPR_ADISC;
9549 spin_unlock_irq(&ndlp->lock);
9550 lpfc_unreg_rpi(vport, np);
9552 lpfc_cleanup_pending_mbox(vport);
9554 if (phba->sli_rev == LPFC_SLI_REV4)
9555 lpfc_sli4_unreg_all_rpis(vport);
9557 lpfc_mbx_unreg_vpi(vport);
9558 spin_lock_irq(shost->host_lock);
9559 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
9560 if (phba->sli_rev == LPFC_SLI_REV4)
9561 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
9563 vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG;
9564 spin_unlock_irq(shost->host_lock);
9565 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
9566 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
9568 * Driver needs to re-reg VPI in order for f/w
9569 * to update the MAC address.
9571 lpfc_register_new_vport(phba, vport, ndlp);
9572 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
9576 if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)
9577 lpfc_issue_init_vpi(vport);
9578 else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
9579 lpfc_register_new_vport(phba, vport, ndlp);
9581 lpfc_do_scr_ns_plogi(phba, vport);
9583 /* The FDISC completed successfully. Move the fabric ndlp to
9584 * UNMAPPED state and register with the transport.
9586 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
9590 if (vport->fc_vport &&
9591 (vport->fc_vport->vport_state != FC_VPORT_NO_FABRIC_RSCS))
9592 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
9593 /* Cancel discovery timer */
9594 lpfc_can_disctmo(vport);
9596 lpfc_els_free_iocb(phba, cmdiocb);
9601 * lpfc_issue_els_fdisc - Issue a fdisc iocb command
9602 * @vport: pointer to a virtual N_Port data structure.
9603 * @ndlp: pointer to a node-list data structure.
9604 * @retry: number of retries to the command IOCB.
9606 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
9607 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
9608 * routine to issue the IOCB, which makes sure only one outstanding fabric
9609 * IOCB will be sent off HBA at any given time.
9611 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
9612 * will be incremented by 1 for holding the ndlp and the reference to ndlp
9613 * will be stored into the context1 field of the IOCB for the completion
9614 * callback function to the FDISC ELS command.
9617 * 0 - Successfully issued fdisc iocb command
9618 * 1 - Failed to issue fdisc iocb command
9621 lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
9624 struct lpfc_hba *phba = vport->phba;
9626 struct lpfc_iocbq *elsiocb;
9627 struct serv_parm *sp;
9630 int did = ndlp->nlp_DID;
9633 vport->port_state = LPFC_FDISC;
9634 vport->fc_myDID = 0;
9635 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
9636 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
9639 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
9640 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
9641 "0255 Issue FDISC: no IOCB\n");
9645 icmd = &elsiocb->iocb;
9646 icmd->un.elsreq64.myID = 0;
9647 icmd->un.elsreq64.fl = 1;
9650 * SLI3 ports require a different context type value than SLI4.
9651 * Catch SLI3 ports here and override the prep.
9653 if (phba->sli_rev == LPFC_SLI_REV3) {
9658 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
9659 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
9660 pcmd += sizeof(uint32_t); /* CSP Word 1 */
9661 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
9662 sp = (struct serv_parm *) pcmd;
9663 /* Setup CSPs accordingly for Fabric */
9664 sp->cmn.e_d_tov = 0;
9665 sp->cmn.w2.r_a_tov = 0;
9666 sp->cmn.virtual_fabric_support = 0;
9667 sp->cls1.classValid = 0;
9668 sp->cls2.seqDelivery = 1;
9669 sp->cls3.seqDelivery = 1;
9671 pcmd += sizeof(uint32_t); /* CSP Word 2 */
9672 pcmd += sizeof(uint32_t); /* CSP Word 3 */
9673 pcmd += sizeof(uint32_t); /* CSP Word 4 */
9674 pcmd += sizeof(uint32_t); /* Port Name */
9675 memcpy(pcmd, &vport->fc_portname, 8);
9676 pcmd += sizeof(uint32_t); /* Node Name */
9677 pcmd += sizeof(uint32_t); /* Node Name */
9678 memcpy(pcmd, &vport->fc_nodename, 8);
9679 sp->cmn.valid_vendor_ver_level = 0;
9680 memset(sp->un.vendorVersion, 0, sizeof(sp->un.vendorVersion));
9681 lpfc_set_disctmo(vport);
9683 phba->fc_stat.elsXmitFDISC++;
9684 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
9686 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
9687 "Issue FDISC: did:x%x",
9690 elsiocb->context1 = lpfc_nlp_get(ndlp);
9691 if (!elsiocb->context1)
9694 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
9695 if (rc == IOCB_ERROR) {
9700 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
9704 lpfc_els_free_iocb(phba, elsiocb);
9705 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
9706 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
9707 "0256 Issue FDISC: Cannot send IOCB\n");
9712 * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
9713 * @phba: pointer to lpfc hba data structure.
9714 * @cmdiocb: pointer to lpfc command iocb data structure.
9715 * @rspiocb: pointer to lpfc response iocb data structure.
9717 * This routine is the completion callback function to the issuing of a LOGO
9718 * ELS command off a vport. It frees the command IOCB and then decrement the
9719 * reference count held on ndlp for this completion function, indicating that
9720 * the reference to the ndlp is no long needed. Note that the
9721 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
9722 * callback function and an additional explicit ndlp reference decrementation
9723 * will trigger the actual release of the ndlp.
9726 lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
9727 struct lpfc_iocbq *rspiocb)
9729 struct lpfc_vport *vport = cmdiocb->vport;
9731 struct lpfc_nodelist *ndlp;
9732 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
9734 ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
9735 irsp = &rspiocb->iocb;
9736 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
9737 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
9738 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
9740 /* NPIV LOGO completes to NPort <nlp_DID> */
9741 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
9742 "2928 NPIV LOGO completes to NPort x%x "
9743 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
9744 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
9745 irsp->ulpTimeout, vport->num_disc_nodes,
9746 kref_read(&ndlp->kref), ndlp->nlp_flag,
9747 ndlp->fc4_xpt_flags);
9749 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
9750 spin_lock_irq(shost->host_lock);
9751 vport->fc_flag &= ~FC_NDISC_ACTIVE;
9752 vport->fc_flag &= ~FC_FABRIC;
9753 spin_unlock_irq(shost->host_lock);
9754 lpfc_can_disctmo(vport);
9757 /* Safe to release resources now. */
9758 lpfc_els_free_iocb(phba, cmdiocb);
9760 vport->unreg_vpi_cmpl = VPORT_ERROR;
9764 * lpfc_issue_els_npiv_logo - Issue a logo off a vport
9765 * @vport: pointer to a virtual N_Port data structure.
9766 * @ndlp: pointer to a node-list data structure.
9768 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
9770 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
9771 * will be incremented by 1 for holding the ndlp and the reference to ndlp
9772 * will be stored into the context1 field of the IOCB for the completion
9773 * callback function to the LOGO ELS command.
9776 * 0 - Successfully issued logo off the @vport
9777 * 1 - Failed to issue logo off the @vport
9780 lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
9783 struct lpfc_hba *phba = vport->phba;
9784 struct lpfc_iocbq *elsiocb;
9788 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
9789 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
9794 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
9795 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
9796 pcmd += sizeof(uint32_t);
9798 /* Fill in LOGO payload */
9799 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
9800 pcmd += sizeof(uint32_t);
9801 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
9803 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
9804 "Issue LOGO npiv did:x%x flg:x%x",
9805 ndlp->nlp_DID, ndlp->nlp_flag, 0);
9807 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
9808 spin_lock_irq(&ndlp->lock);
9809 ndlp->nlp_flag |= NLP_LOGO_SND;
9810 spin_unlock_irq(&ndlp->lock);
9811 elsiocb->context1 = lpfc_nlp_get(ndlp);
9812 if (!elsiocb->context1)
9814 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
9815 if (rc == IOCB_ERROR)
9822 spin_lock_irq(&ndlp->lock);
9823 ndlp->nlp_flag &= ~NLP_LOGO_SND;
9824 spin_unlock_irq(&ndlp->lock);
9825 lpfc_els_free_iocb(phba, elsiocb);
9830 * lpfc_fabric_block_timeout - Handler function to the fabric block timer
9831 * @t: timer context used to obtain the lpfc hba.
9833 * This routine is invoked by the fabric iocb block timer after
9834 * timeout. It posts the fabric iocb block timeout event by setting the
9835 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
9836 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
9837 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
9838 * posted event WORKER_FABRIC_BLOCK_TMO.
9841 lpfc_fabric_block_timeout(struct timer_list *t)
9843 struct lpfc_hba *phba = from_timer(phba, t, fabric_block_timer);
9844 unsigned long iflags;
9845 uint32_t tmo_posted;
9847 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
9848 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
9850 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
9851 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
9854 lpfc_worker_wake_up(phba);
9859 * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
9860 * @phba: pointer to lpfc hba data structure.
9862 * This routine issues one fabric iocb from the driver internal list to
9863 * the HBA. It first checks whether it's ready to issue one fabric iocb to
9864 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
9865 * remove one pending fabric iocb from the driver internal list and invokes
9866 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
9869 lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
9871 struct lpfc_iocbq *iocb;
9872 unsigned long iflags;
9878 spin_lock_irqsave(&phba->hbalock, iflags);
9879 /* Post any pending iocb to the SLI layer */
9880 if (atomic_read(&phba->fabric_iocb_count) == 0) {
9881 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
9884 /* Increment fabric iocb count to hold the position */
9885 atomic_inc(&phba->fabric_iocb_count);
9887 spin_unlock_irqrestore(&phba->hbalock, iflags);
9889 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
9890 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
9891 iocb->iocb_flag |= LPFC_IO_FABRIC;
9893 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
9894 "Fabric sched1: ste:x%x",
9895 iocb->vport->port_state, 0, 0);
9897 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
9899 if (ret == IOCB_ERROR) {
9900 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
9901 iocb->fabric_iocb_cmpl = NULL;
9902 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
9904 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
9905 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
9906 iocb->iocb_cmpl(phba, iocb, iocb);
9908 atomic_dec(&phba->fabric_iocb_count);
9915 * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
9916 * @phba: pointer to lpfc hba data structure.
9918 * This routine unblocks the issuing fabric iocb command. The function
9919 * will clear the fabric iocb block bit and then invoke the routine
9920 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
9921 * from the driver internal fabric iocb list.
9924 lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
9926 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
9928 lpfc_resume_fabric_iocbs(phba);
9933 * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
9934 * @phba: pointer to lpfc hba data structure.
9936 * This routine blocks the issuing fabric iocb for a specified amount of
9937 * time (currently 100 ms). This is done by set the fabric iocb block bit
9938 * and set up a timeout timer for 100ms. When the block bit is set, no more
9939 * fabric iocb will be issued out of the HBA.
9942 lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
9946 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
9947 /* Start a timer to unblock fabric iocbs after 100ms */
9949 mod_timer(&phba->fabric_block_timer,
9950 jiffies + msecs_to_jiffies(100));
9956 * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
9957 * @phba: pointer to lpfc hba data structure.
9958 * @cmdiocb: pointer to lpfc command iocb data structure.
9959 * @rspiocb: pointer to lpfc response iocb data structure.
9961 * This routine is the callback function that is put to the fabric iocb's
9962 * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
9963 * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
9964 * function first restores and invokes the original iocb's callback function
9965 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
9966 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
9969 lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
9970 struct lpfc_iocbq *rspiocb)
9974 BUG_ON((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC);
9976 switch (rspiocb->iocb.ulpStatus) {
9977 case IOSTAT_NPORT_RJT:
9978 case IOSTAT_FABRIC_RJT:
9979 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
9980 lpfc_block_fabric_iocbs(phba);
9984 case IOSTAT_NPORT_BSY:
9985 case IOSTAT_FABRIC_BSY:
9986 lpfc_block_fabric_iocbs(phba);
9990 stat.un.lsRjtError =
9991 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
9992 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
9993 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
9994 lpfc_block_fabric_iocbs(phba);
9998 BUG_ON(atomic_read(&phba->fabric_iocb_count) == 0);
10000 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
10001 cmdiocb->fabric_iocb_cmpl = NULL;
10002 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
10003 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
10005 atomic_dec(&phba->fabric_iocb_count);
10006 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
10007 /* Post any pending iocbs to HBA */
10008 lpfc_resume_fabric_iocbs(phba);
10013 * lpfc_issue_fabric_iocb - Issue a fabric iocb command
10014 * @phba: pointer to lpfc hba data structure.
10015 * @iocb: pointer to lpfc command iocb data structure.
10017 * This routine is used as the top-level API for issuing a fabric iocb command
10018 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
10019 * function makes sure that only one fabric bound iocb will be outstanding at
10020 * any given time. As such, this function will first check to see whether there
10021 * is already an outstanding fabric iocb on the wire. If so, it will put the
10022 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
10023 * issued later. Otherwise, it will issue the iocb on the wire and update the
10024 * fabric iocb count it indicate that there is one fabric iocb on the wire.
10026 * Note, this implementation has a potential sending out fabric IOCBs out of
10027 * order. The problem is caused by the construction of the "ready" boolen does
10028 * not include the condition that the internal fabric IOCB list is empty. As
10029 * such, it is possible a fabric IOCB issued by this routine might be "jump"
10030 * ahead of the fabric IOCBs in the internal list.
10033 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
10034 * IOCB_ERROR - failed to issue fabric iocb
10037 lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
10039 unsigned long iflags;
10043 BUG_ON(atomic_read(&phba->fabric_iocb_count) > 1);
10045 spin_lock_irqsave(&phba->hbalock, iflags);
10046 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
10047 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
10050 /* Increment fabric iocb count to hold the position */
10051 atomic_inc(&phba->fabric_iocb_count);
10052 spin_unlock_irqrestore(&phba->hbalock, iflags);
10054 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
10055 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
10056 iocb->iocb_flag |= LPFC_IO_FABRIC;
10058 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
10059 "Fabric sched2: ste:x%x",
10060 iocb->vport->port_state, 0, 0);
10062 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
10064 if (ret == IOCB_ERROR) {
10065 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
10066 iocb->fabric_iocb_cmpl = NULL;
10067 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
10068 atomic_dec(&phba->fabric_iocb_count);
10071 spin_lock_irqsave(&phba->hbalock, iflags);
10072 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
10073 spin_unlock_irqrestore(&phba->hbalock, iflags);
10074 ret = IOCB_SUCCESS;
10080 * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
10081 * @vport: pointer to a virtual N_Port data structure.
10083 * This routine aborts all the IOCBs associated with a @vport from the
10084 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
10085 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
10086 * list, removes each IOCB associated with the @vport off the list, set the
10087 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
10088 * associated with the IOCB.
10090 static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
10092 LIST_HEAD(completions);
10093 struct lpfc_hba *phba = vport->phba;
10094 struct lpfc_iocbq *tmp_iocb, *piocb;
10096 spin_lock_irq(&phba->hbalock);
10097 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
10100 if (piocb->vport != vport)
10103 list_move_tail(&piocb->list, &completions);
10105 spin_unlock_irq(&phba->hbalock);
10107 /* Cancel all the IOCBs from the completions list */
10108 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
10109 IOERR_SLI_ABORTED);
10113 * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
10114 * @ndlp: pointer to a node-list data structure.
10116 * This routine aborts all the IOCBs associated with an @ndlp from the
10117 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
10118 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
10119 * list, removes each IOCB associated with the @ndlp off the list, set the
10120 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
10121 * associated with the IOCB.
10123 void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
10125 LIST_HEAD(completions);
10126 struct lpfc_hba *phba = ndlp->phba;
10127 struct lpfc_iocbq *tmp_iocb, *piocb;
10128 struct lpfc_sli_ring *pring;
10130 pring = lpfc_phba_elsring(phba);
10132 if (unlikely(!pring))
10135 spin_lock_irq(&phba->hbalock);
10136 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
10138 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
10140 list_move_tail(&piocb->list, &completions);
10143 spin_unlock_irq(&phba->hbalock);
10145 /* Cancel all the IOCBs from the completions list */
10146 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
10147 IOERR_SLI_ABORTED);
10151 * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
10152 * @phba: pointer to lpfc hba data structure.
10154 * This routine aborts all the IOCBs currently on the driver internal
10155 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
10156 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
10157 * list, removes IOCBs off the list, set the status feild to
10158 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
10161 void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
10163 LIST_HEAD(completions);
10165 spin_lock_irq(&phba->hbalock);
10166 list_splice_init(&phba->fabric_iocb_list, &completions);
10167 spin_unlock_irq(&phba->hbalock);
10169 /* Cancel all the IOCBs from the completions list */
10170 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
10171 IOERR_SLI_ABORTED);
10175 * lpfc_sli4_vport_delete_els_xri_aborted -Remove all ndlp references for vport
10176 * @vport: pointer to lpfc vport data structure.
10178 * This routine is invoked by the vport cleanup for deletions and the cleanup
10179 * for an ndlp on removal.
10182 lpfc_sli4_vport_delete_els_xri_aborted(struct lpfc_vport *vport)
10184 struct lpfc_hba *phba = vport->phba;
10185 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
10186 unsigned long iflag = 0;
10188 spin_lock_irqsave(&phba->hbalock, iflag);
10189 spin_lock(&phba->sli4_hba.sgl_list_lock);
10190 list_for_each_entry_safe(sglq_entry, sglq_next,
10191 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
10192 if (sglq_entry->ndlp && sglq_entry->ndlp->vport == vport) {
10193 lpfc_nlp_put(sglq_entry->ndlp);
10194 sglq_entry->ndlp = NULL;
10197 spin_unlock(&phba->sli4_hba.sgl_list_lock);
10198 spin_unlock_irqrestore(&phba->hbalock, iflag);
10203 * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
10204 * @phba: pointer to lpfc hba data structure.
10205 * @axri: pointer to the els xri abort wcqe structure.
10207 * This routine is invoked by the worker thread to process a SLI4 slow-path
10211 lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba,
10212 struct sli4_wcqe_xri_aborted *axri)
10214 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
10215 uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri);
10218 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
10219 unsigned long iflag = 0;
10220 struct lpfc_nodelist *ndlp;
10221 struct lpfc_sli_ring *pring;
10223 pring = lpfc_phba_elsring(phba);
10225 spin_lock_irqsave(&phba->hbalock, iflag);
10226 spin_lock(&phba->sli4_hba.sgl_list_lock);
10227 list_for_each_entry_safe(sglq_entry, sglq_next,
10228 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
10229 if (sglq_entry->sli4_xritag == xri) {
10230 list_del(&sglq_entry->list);
10231 ndlp = sglq_entry->ndlp;
10232 sglq_entry->ndlp = NULL;
10233 list_add_tail(&sglq_entry->list,
10234 &phba->sli4_hba.lpfc_els_sgl_list);
10235 sglq_entry->state = SGL_FREED;
10236 spin_unlock(&phba->sli4_hba.sgl_list_lock);
10237 spin_unlock_irqrestore(&phba->hbalock, iflag);
10240 lpfc_set_rrq_active(phba, ndlp,
10241 sglq_entry->sli4_lxritag,
10243 lpfc_nlp_put(ndlp);
10246 /* Check if TXQ queue needs to be serviced */
10247 if (pring && !list_empty(&pring->txq))
10248 lpfc_worker_wake_up(phba);
10252 spin_unlock(&phba->sli4_hba.sgl_list_lock);
10253 lxri = lpfc_sli4_xri_inrange(phba, xri);
10254 if (lxri == NO_XRI) {
10255 spin_unlock_irqrestore(&phba->hbalock, iflag);
10258 spin_lock(&phba->sli4_hba.sgl_list_lock);
10259 sglq_entry = __lpfc_get_active_sglq(phba, lxri);
10260 if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) {
10261 spin_unlock(&phba->sli4_hba.sgl_list_lock);
10262 spin_unlock_irqrestore(&phba->hbalock, iflag);
10265 sglq_entry->state = SGL_XRI_ABORTED;
10266 spin_unlock(&phba->sli4_hba.sgl_list_lock);
10267 spin_unlock_irqrestore(&phba->hbalock, iflag);
10271 /* lpfc_sli_abts_recover_port - Recover a port that failed a BLS_ABORT req.
10272 * @vport: pointer to virtual port object.
10273 * @ndlp: nodelist pointer for the impacted node.
10275 * The driver calls this routine in response to an SLI4 XRI ABORT CQE
10276 * or an SLI3 ASYNC_STATUS_CN event from the port. For either event,
10277 * the driver is required to send a LOGO to the remote node before it
10278 * attempts to recover its login to the remote node.
10281 lpfc_sli_abts_recover_port(struct lpfc_vport *vport,
10282 struct lpfc_nodelist *ndlp)
10284 struct Scsi_Host *shost;
10285 struct lpfc_hba *phba;
10286 unsigned long flags = 0;
10288 shost = lpfc_shost_from_vport(vport);
10289 phba = vport->phba;
10290 if (ndlp->nlp_state != NLP_STE_MAPPED_NODE) {
10291 lpfc_printf_log(phba, KERN_INFO,
10292 LOG_SLI, "3093 No rport recovery needed. "
10293 "rport in state 0x%x\n", ndlp->nlp_state);
10296 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10297 "3094 Start rport recovery on shost id 0x%x "
10298 "fc_id 0x%06x vpi 0x%x rpi 0x%x state 0x%x "
10300 shost->host_no, ndlp->nlp_DID,
10301 vport->vpi, ndlp->nlp_rpi, ndlp->nlp_state,
10304 * The rport is not responding. Remove the FCP-2 flag to prevent
10305 * an ADISC in the follow-up recovery code.
10307 spin_lock_irqsave(&ndlp->lock, flags);
10308 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
10309 ndlp->nlp_flag |= NLP_ISSUE_LOGO;
10310 spin_unlock_irqrestore(&ndlp->lock, flags);
10311 lpfc_unreg_rpi(vport, ndlp);