1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2017 Broadcom. All Rights Reserved. The term *
5 * “Broadcom” refers to Broadcom Limited and/or its subsidiaries. *
6 * Copyright (C) 2004-2016 Emulex. All rights reserved. *
7 * EMULEX and SLI are trademarks of Emulex. *
9 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
11 * This program is free software; you can redistribute it and/or *
12 * modify it under the terms of version 2 of the GNU General *
13 * Public License as published by the Free Software Foundation. *
14 * This program is distributed in the hope that it will be useful. *
15 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
16 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
17 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
18 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
19 * TO BE LEGALLY INVALID. See the GNU General Public License for *
20 * more details, a copy of which can be found in the file COPYING *
21 * included with this package. *
22 *******************************************************************/
23 /* See Fibre Channel protocol T11 FC-LS for details */
24 #include <linux/blkdev.h>
25 #include <linux/pci.h>
26 #include <linux/slab.h>
27 #include <linux/interrupt.h>
29 #include <scsi/scsi.h>
30 #include <scsi/scsi_device.h>
31 #include <scsi/scsi_host.h>
32 #include <scsi/scsi_transport_fc.h>
37 #include "lpfc_sli4.h"
39 #include "lpfc_disc.h"
40 #include "lpfc_scsi.h"
42 #include "lpfc_logmsg.h"
43 #include "lpfc_crtn.h"
44 #include "lpfc_vport.h"
45 #include "lpfc_debugfs.h"
47 static int lpfc_els_retry(struct lpfc_hba *, struct lpfc_iocbq *,
49 static void lpfc_cmpl_fabric_iocb(struct lpfc_hba *, struct lpfc_iocbq *,
51 static void lpfc_fabric_abort_vport(struct lpfc_vport *vport);
52 static int lpfc_issue_els_fdisc(struct lpfc_vport *vport,
53 struct lpfc_nodelist *ndlp, uint8_t retry);
54 static int lpfc_issue_fabric_iocb(struct lpfc_hba *phba,
55 struct lpfc_iocbq *iocb);
57 static int lpfc_max_els_tries = 3;
60 * lpfc_els_chk_latt - Check host link attention event for a vport
61 * @vport: pointer to a host virtual N_Port data structure.
63 * This routine checks whether there is an outstanding host link
64 * attention event during the discovery process with the @vport. It is done
65 * by reading the HBA's Host Attention (HA) register. If there is any host
66 * link attention events during this @vport's discovery process, the @vport
67 * shall be marked as FC_ABORT_DISCOVERY, a host link attention clear shall
68 * be issued if the link state is not already in host link cleared state,
69 * and a return code shall indicate whether the host link attention event
72 * Note that, if either the host link is in state LPFC_LINK_DOWN or @vport
73 * state in LPFC_VPORT_READY, the request for checking host link attention
74 * event will be ignored and a return code shall indicate no host link
75 * attention event had happened.
78 * 0 - no host link attention event happened
79 * 1 - host link attention event happened
82 lpfc_els_chk_latt(struct lpfc_vport *vport)
84 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
85 struct lpfc_hba *phba = vport->phba;
88 if (vport->port_state >= LPFC_VPORT_READY ||
89 phba->link_state == LPFC_LINK_DOWN ||
90 phba->sli_rev > LPFC_SLI_REV3)
93 /* Read the HBA Host Attention Register */
94 if (lpfc_readl(phba->HAregaddr, &ha_copy))
97 if (!(ha_copy & HA_LATT))
100 /* Pending Link Event during Discovery */
101 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
102 "0237 Pending Link Event during "
103 "Discovery: State x%x\n",
104 phba->pport->port_state);
106 /* CLEAR_LA should re-enable link attention events and
107 * we should then immediately take a LATT event. The
108 * LATT processing should call lpfc_linkdown() which
109 * will cleanup any left over in-progress discovery
112 spin_lock_irq(shost->host_lock);
113 vport->fc_flag |= FC_ABORT_DISCOVERY;
114 spin_unlock_irq(shost->host_lock);
116 if (phba->link_state != LPFC_CLEAR_LA)
117 lpfc_issue_clear_la(phba, vport);
123 * lpfc_prep_els_iocb - Allocate and prepare a lpfc iocb data structure
124 * @vport: pointer to a host virtual N_Port data structure.
125 * @expectRsp: flag indicating whether response is expected.
126 * @cmdSize: size of the ELS command.
127 * @retry: number of retries to the command IOCB when it fails.
128 * @ndlp: pointer to a node-list data structure.
129 * @did: destination identifier.
130 * @elscmd: the ELS command code.
132 * This routine is used for allocating a lpfc-IOCB data structure from
133 * the driver lpfc-IOCB free-list and prepare the IOCB with the parameters
134 * passed into the routine for discovery state machine to issue an Extended
135 * Link Service (ELS) commands. It is a generic lpfc-IOCB allocation
136 * and preparation routine that is used by all the discovery state machine
137 * routines and the ELS command-specific fields will be later set up by
138 * the individual discovery machine routines after calling this routine
139 * allocating and preparing a generic IOCB data structure. It fills in the
140 * Buffer Descriptor Entries (BDEs), allocates buffers for both command
141 * payload and response payload (if expected). The reference count on the
142 * ndlp is incremented by 1 and the reference to the ndlp is put into
143 * context1 of the IOCB data structure for this IOCB to hold the ndlp
144 * reference for the command's callback function to access later.
147 * Pointer to the newly allocated/prepared els iocb data structure
148 * NULL - when els iocb data structure allocation/preparation failed
151 lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp,
152 uint16_t cmdSize, uint8_t retry,
153 struct lpfc_nodelist *ndlp, uint32_t did,
156 struct lpfc_hba *phba = vport->phba;
157 struct lpfc_iocbq *elsiocb;
158 struct lpfc_dmabuf *pcmd, *prsp, *pbuflist;
159 struct ulp_bde64 *bpl;
163 if (!lpfc_is_link_up(phba))
166 /* Allocate buffer for command iocb */
167 elsiocb = lpfc_sli_get_iocbq(phba);
173 * If this command is for fabric controller and HBA running
174 * in FIP mode send FLOGI, FDISC and LOGO as FIP frames.
176 if ((did == Fabric_DID) &&
177 (phba->hba_flag & HBA_FIP_SUPPORT) &&
178 ((elscmd == ELS_CMD_FLOGI) ||
179 (elscmd == ELS_CMD_FDISC) ||
180 (elscmd == ELS_CMD_LOGO)))
183 elsiocb->iocb_flag |=
184 ((LPFC_ELS_ID_FLOGI << LPFC_FIP_ELS_ID_SHIFT)
185 & LPFC_FIP_ELS_ID_MASK);
188 elsiocb->iocb_flag |=
189 ((LPFC_ELS_ID_FDISC << LPFC_FIP_ELS_ID_SHIFT)
190 & LPFC_FIP_ELS_ID_MASK);
193 elsiocb->iocb_flag |=
194 ((LPFC_ELS_ID_LOGO << LPFC_FIP_ELS_ID_SHIFT)
195 & LPFC_FIP_ELS_ID_MASK);
199 elsiocb->iocb_flag &= ~LPFC_FIP_ELS_ID_MASK;
201 icmd = &elsiocb->iocb;
203 /* fill in BDEs for command */
204 /* Allocate buffer for command payload */
205 pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
207 pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys);
208 if (!pcmd || !pcmd->virt)
209 goto els_iocb_free_pcmb_exit;
211 INIT_LIST_HEAD(&pcmd->list);
213 /* Allocate buffer for response payload */
215 prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
217 prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
219 if (!prsp || !prsp->virt)
220 goto els_iocb_free_prsp_exit;
221 INIT_LIST_HEAD(&prsp->list);
225 /* Allocate buffer for Buffer ptr list */
226 pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
228 pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
230 if (!pbuflist || !pbuflist->virt)
231 goto els_iocb_free_pbuf_exit;
233 INIT_LIST_HEAD(&pbuflist->list);
236 icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
237 icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
238 icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
239 icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64));
241 icmd->un.elsreq64.remoteID = did; /* DID */
242 icmd->ulpCommand = CMD_ELS_REQUEST64_CR;
243 if (elscmd == ELS_CMD_FLOGI)
244 icmd->ulpTimeout = FF_DEF_RATOV * 2;
246 icmd->ulpTimeout = phba->fc_ratov * 2;
248 icmd->un.xseq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
249 icmd->un.xseq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
250 icmd->un.xseq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
251 icmd->un.xseq64.bdl.bdeSize = sizeof(struct ulp_bde64);
252 icmd->un.xseq64.xmit_els_remoteID = did; /* DID */
253 icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX;
255 icmd->ulpBdeCount = 1;
257 icmd->ulpClass = CLASS3;
260 * If we have NPIV enabled, we want to send ELS traffic by VPI.
261 * For SLI4, since the driver controls VPIs we also want to include
262 * all ELS pt2pt protocol traffic as well.
264 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) ||
265 ((phba->sli_rev == LPFC_SLI_REV4) &&
266 (vport->fc_flag & FC_PT2PT))) {
269 icmd->un.elsreq64.myID = vport->fc_myDID;
271 /* For ELS_REQUEST64_CR, use the VPI by default */
272 icmd->ulpContext = phba->vpi_ids[vport->vpi];
276 /* The CT field must be 0=INVALID_RPI for the ECHO cmd */
277 if (elscmd == ELS_CMD_ECHO)
278 icmd->ulpCt_l = 0; /* context = invalid RPI */
280 icmd->ulpCt_l = 1; /* context = VPI */
283 bpl = (struct ulp_bde64 *) pbuflist->virt;
284 bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys));
285 bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys));
286 bpl->tus.f.bdeSize = cmdSize;
287 bpl->tus.f.bdeFlags = 0;
288 bpl->tus.w = le32_to_cpu(bpl->tus.w);
292 bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys));
293 bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys));
294 bpl->tus.f.bdeSize = FCELSSIZE;
295 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
296 bpl->tus.w = le32_to_cpu(bpl->tus.w);
299 /* prevent preparing iocb with NULL ndlp reference */
300 elsiocb->context1 = lpfc_nlp_get(ndlp);
301 if (!elsiocb->context1)
302 goto els_iocb_free_pbuf_exit;
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"
318 elscmd, did, elsiocb->iotag,
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 fc_flag x%x\n",
327 elscmd, ndlp->nlp_DID, elsiocb->iotag,
328 cmdSize, vport->port_state,
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);
377 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
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->context2 = lpfc_nlp_get(ndlp);
418 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
419 if (rc == MBX_NOT_FINISHED) {
421 goto fail_issue_reg_login;
426 fail_issue_reg_login:
427 /* decrement the reference count on ndlp just incremented
428 * for the failed mbox command.
431 mp = (struct lpfc_dmabuf *) mbox->context1;
432 lpfc_mbuf_free(phba, mp->virt, mp->phys);
435 mempool_free(mbox, phba->mbox_mem_pool);
438 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
439 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
440 "0249 Cannot issue Register Fabric login: Err %d\n", err);
445 * lpfc_issue_reg_vfi - Register VFI for this vport's fabric login
446 * @vport: pointer to a host virtual N_Port data structure.
448 * This routine issues a REG_VFI mailbox for the vfi, vpi, fcfi triplet for
449 * the @vport. This mailbox command is necessary for SLI4 port only.
452 * 0 - successfully issued REG_VFI for @vport
453 * A failure code otherwise.
456 lpfc_issue_reg_vfi(struct lpfc_vport *vport)
458 struct lpfc_hba *phba = vport->phba;
459 LPFC_MBOXQ_t *mboxq = NULL;
460 struct lpfc_nodelist *ndlp;
461 struct lpfc_dmabuf *dmabuf = NULL;
464 /* move forward in case of SLI4 FC port loopback test and pt2pt mode */
465 if ((phba->sli_rev == LPFC_SLI_REV4) &&
466 !(phba->link_flag & LS_LOOPBACK_MODE) &&
467 !(vport->fc_flag & FC_PT2PT)) {
468 ndlp = lpfc_findnode_did(vport, Fabric_DID);
469 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
475 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
481 /* Supply CSP's only if we are fabric connect or pt-to-pt connect */
482 if ((vport->fc_flag & FC_FABRIC) || (vport->fc_flag & FC_PT2PT)) {
483 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
488 dmabuf->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &dmabuf->phys);
493 memcpy(dmabuf->virt, &phba->fc_fabparam,
494 sizeof(struct serv_parm));
497 vport->port_state = LPFC_FABRIC_CFG_LINK;
499 lpfc_reg_vfi(mboxq, vport, dmabuf->phys);
501 lpfc_reg_vfi(mboxq, vport, 0);
503 mboxq->mbox_cmpl = lpfc_mbx_cmpl_reg_vfi;
504 mboxq->vport = vport;
505 mboxq->context1 = dmabuf;
506 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
507 if (rc == MBX_NOT_FINISHED) {
515 mempool_free(mboxq, phba->mbox_mem_pool);
518 lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys);
522 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
523 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
524 "0289 Issue Register VFI failed: Err %d\n", rc);
529 * lpfc_issue_unreg_vfi - Unregister VFI for this vport's fabric login
530 * @vport: pointer to a host virtual N_Port data structure.
532 * This routine issues a UNREG_VFI mailbox with the vfi, vpi, fcfi triplet for
533 * the @vport. This mailbox command is necessary for SLI4 port only.
536 * 0 - successfully issued REG_VFI for @vport
537 * A failure code otherwise.
540 lpfc_issue_unreg_vfi(struct lpfc_vport *vport)
542 struct lpfc_hba *phba = vport->phba;
543 struct Scsi_Host *shost;
547 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
549 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
550 "2556 UNREG_VFI mbox allocation failed"
551 "HBA state x%x\n", phba->pport->port_state);
555 lpfc_unreg_vfi(mboxq, vport);
556 mboxq->vport = vport;
557 mboxq->mbox_cmpl = lpfc_unregister_vfi_cmpl;
559 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
560 if (rc == MBX_NOT_FINISHED) {
561 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
562 "2557 UNREG_VFI issue mbox failed rc x%x "
564 rc, phba->pport->port_state);
565 mempool_free(mboxq, phba->mbox_mem_pool);
569 shost = lpfc_shost_from_vport(vport);
570 spin_lock_irq(shost->host_lock);
571 vport->fc_flag &= ~FC_VFI_REGISTERED;
572 spin_unlock_irq(shost->host_lock);
577 * lpfc_check_clean_addr_bit - Check whether assigned FCID is clean.
578 * @vport: pointer to a host virtual N_Port data structure.
579 * @sp: pointer to service parameter data structure.
581 * This routine is called from FLOGI/FDISC completion handler functions.
582 * lpfc_check_clean_addr_bit return 1 when FCID/Fabric portname/ Fabric
583 * node nodename is changed in the completion service parameter else return
584 * 0. This function also set flag in the vport data structure to delay
585 * NP_Port discovery after the FLOGI/FDISC completion if Clean address bit
586 * in FLOGI/FDISC response is cleared and FCID/Fabric portname/ Fabric
587 * node nodename is changed in the completion service parameter.
590 * 0 - FCID and Fabric Nodename and Fabric portname is not changed.
591 * 1 - FCID or Fabric Nodename or Fabric portname is changed.
595 lpfc_check_clean_addr_bit(struct lpfc_vport *vport,
596 struct serv_parm *sp)
598 struct lpfc_hba *phba = vport->phba;
599 uint8_t fabric_param_changed = 0;
600 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
602 if ((vport->fc_prevDID != vport->fc_myDID) ||
603 memcmp(&vport->fabric_portname, &sp->portName,
604 sizeof(struct lpfc_name)) ||
605 memcmp(&vport->fabric_nodename, &sp->nodeName,
606 sizeof(struct lpfc_name)) ||
607 (vport->vport_flag & FAWWPN_PARAM_CHG)) {
608 fabric_param_changed = 1;
609 vport->vport_flag &= ~FAWWPN_PARAM_CHG;
612 * Word 1 Bit 31 in common service parameter is overloaded.
613 * Word 1 Bit 31 in FLOGI request is multiple NPort request
614 * Word 1 Bit 31 in FLOGI response is clean address bit
616 * If fabric parameter is changed and clean address bit is
617 * cleared delay nport discovery if
618 * - vport->fc_prevDID != 0 (not initial discovery) OR
619 * - lpfc_delay_discovery module parameter is set.
621 if (fabric_param_changed && !sp->cmn.clean_address_bit &&
622 (vport->fc_prevDID || phba->cfg_delay_discovery)) {
623 spin_lock_irq(shost->host_lock);
624 vport->fc_flag |= FC_DISC_DELAYED;
625 spin_unlock_irq(shost->host_lock);
628 return fabric_param_changed;
633 * lpfc_cmpl_els_flogi_fabric - Completion function for flogi to a fabric port
634 * @vport: pointer to a host virtual N_Port data structure.
635 * @ndlp: pointer to a node-list data structure.
636 * @sp: pointer to service parameter data structure.
637 * @irsp: pointer to the IOCB within the lpfc response IOCB.
639 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
640 * function to handle the completion of a Fabric Login (FLOGI) into a fabric
641 * port in a fabric topology. It properly sets up the parameters to the @ndlp
642 * from the IOCB response. It also check the newly assigned N_Port ID to the
643 * @vport against the previously assigned N_Port ID. If it is different from
644 * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine
645 * is invoked on all the remaining nodes with the @vport to unregister the
646 * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin()
647 * is invoked to register login to the fabric.
650 * 0 - Success (currently, always return 0)
653 lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
654 struct serv_parm *sp, IOCB_t *irsp)
656 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
657 struct lpfc_hba *phba = vport->phba;
658 struct lpfc_nodelist *np;
659 struct lpfc_nodelist *next_np;
660 uint8_t fabric_param_changed;
662 spin_lock_irq(shost->host_lock);
663 vport->fc_flag |= FC_FABRIC;
664 spin_unlock_irq(shost->host_lock);
666 phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
667 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
668 phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
670 phba->fc_edtovResol = sp->cmn.edtovResolution;
671 phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
673 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
674 spin_lock_irq(shost->host_lock);
675 vport->fc_flag |= FC_PUBLIC_LOOP;
676 spin_unlock_irq(shost->host_lock);
679 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
680 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
681 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name));
682 ndlp->nlp_class_sup = 0;
683 if (sp->cls1.classValid)
684 ndlp->nlp_class_sup |= FC_COS_CLASS1;
685 if (sp->cls2.classValid)
686 ndlp->nlp_class_sup |= FC_COS_CLASS2;
687 if (sp->cls3.classValid)
688 ndlp->nlp_class_sup |= FC_COS_CLASS3;
689 if (sp->cls4.classValid)
690 ndlp->nlp_class_sup |= FC_COS_CLASS4;
691 ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
692 sp->cmn.bbRcvSizeLsb;
694 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
695 if (fabric_param_changed) {
696 /* Reset FDMI attribute masks based on config parameter */
697 if (phba->cfg_enable_SmartSAN ||
698 (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) {
699 /* Setup appropriate attribute masks */
700 vport->fdmi_hba_mask = LPFC_FDMI2_HBA_ATTR;
701 if (phba->cfg_enable_SmartSAN)
702 vport->fdmi_port_mask = LPFC_FDMI2_SMART_ATTR;
704 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
706 vport->fdmi_hba_mask = 0;
707 vport->fdmi_port_mask = 0;
711 memcpy(&vport->fabric_portname, &sp->portName,
712 sizeof(struct lpfc_name));
713 memcpy(&vport->fabric_nodename, &sp->nodeName,
714 sizeof(struct lpfc_name));
715 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
717 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
718 if (sp->cmn.response_multiple_NPort) {
719 lpfc_printf_vlog(vport, KERN_WARNING,
721 "1816 FLOGI NPIV supported, "
722 "response data 0x%x\n",
723 sp->cmn.response_multiple_NPort);
724 spin_lock_irq(&phba->hbalock);
725 phba->link_flag |= LS_NPIV_FAB_SUPPORTED;
726 spin_unlock_irq(&phba->hbalock);
728 /* Because we asked f/w for NPIV it still expects us
729 to call reg_vnpid atleast for the physcial host */
730 lpfc_printf_vlog(vport, KERN_WARNING,
732 "1817 Fabric does not support NPIV "
733 "- configuring single port mode.\n");
734 spin_lock_irq(&phba->hbalock);
735 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
736 spin_unlock_irq(&phba->hbalock);
741 * For FC we need to do some special processing because of the SLI
742 * Port's default settings of the Common Service Parameters.
744 if ((phba->sli_rev == LPFC_SLI_REV4) &&
745 (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC)) {
746 /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */
747 if (fabric_param_changed)
748 lpfc_unregister_fcf_prep(phba);
750 /* This should just update the VFI CSPs*/
751 if (vport->fc_flag & FC_VFI_REGISTERED)
752 lpfc_issue_reg_vfi(vport);
755 if (fabric_param_changed &&
756 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
758 /* If our NportID changed, we need to ensure all
759 * remaining NPORTs get unreg_login'ed.
761 list_for_each_entry_safe(np, next_np,
762 &vport->fc_nodes, nlp_listp) {
763 if (!NLP_CHK_NODE_ACT(np))
765 if ((np->nlp_state != NLP_STE_NPR_NODE) ||
766 !(np->nlp_flag & NLP_NPR_ADISC))
768 spin_lock_irq(shost->host_lock);
769 np->nlp_flag &= ~NLP_NPR_ADISC;
770 spin_unlock_irq(shost->host_lock);
771 lpfc_unreg_rpi(vport, np);
773 lpfc_cleanup_pending_mbox(vport);
775 if (phba->sli_rev == LPFC_SLI_REV4) {
776 lpfc_sli4_unreg_all_rpis(vport);
777 lpfc_mbx_unreg_vpi(vport);
778 spin_lock_irq(shost->host_lock);
779 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
780 spin_unlock_irq(shost->host_lock);
784 * For SLI3 and SLI4, the VPI needs to be reregistered in
785 * response to this fabric parameter change event.
787 spin_lock_irq(shost->host_lock);
788 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
789 spin_unlock_irq(shost->host_lock);
790 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
791 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
793 * Driver needs to re-reg VPI in order for f/w
794 * to update the MAC address.
796 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
797 lpfc_register_new_vport(phba, vport, ndlp);
801 if (phba->sli_rev < LPFC_SLI_REV4) {
802 lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
803 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED &&
804 vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
805 lpfc_register_new_vport(phba, vport, ndlp);
807 lpfc_issue_fabric_reglogin(vport);
809 ndlp->nlp_type |= NLP_FABRIC;
810 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
811 if ((!(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) &&
812 (vport->vpi_state & LPFC_VPI_REGISTERED)) {
813 lpfc_start_fdiscs(phba);
814 lpfc_do_scr_ns_plogi(phba, vport);
815 } else if (vport->fc_flag & FC_VFI_REGISTERED)
816 lpfc_issue_init_vpi(vport);
818 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
819 "3135 Need register VFI: (x%x/%x)\n",
820 vport->fc_prevDID, vport->fc_myDID);
821 lpfc_issue_reg_vfi(vport);
828 * lpfc_cmpl_els_flogi_nport - Completion function for flogi to an N_Port
829 * @vport: pointer to a host virtual N_Port data structure.
830 * @ndlp: pointer to a node-list data structure.
831 * @sp: pointer to service parameter data structure.
833 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
834 * function to handle the completion of a Fabric Login (FLOGI) into an N_Port
835 * in a point-to-point topology. First, the @vport's N_Port Name is compared
836 * with the received N_Port Name: if the @vport's N_Port Name is greater than
837 * the received N_Port Name lexicographically, this node shall assign local
838 * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and
839 * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise,
840 * this node shall just wait for the remote node to issue PLOGI and assign
848 lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
849 struct serv_parm *sp)
851 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
852 struct lpfc_hba *phba = vport->phba;
856 spin_lock_irq(shost->host_lock);
857 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
858 vport->fc_flag |= FC_PT2PT;
859 spin_unlock_irq(shost->host_lock);
861 /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */
862 if ((phba->sli_rev == LPFC_SLI_REV4) && phba->fc_topology_changed) {
863 lpfc_unregister_fcf_prep(phba);
865 spin_lock_irq(shost->host_lock);
866 vport->fc_flag &= ~FC_VFI_REGISTERED;
867 spin_unlock_irq(shost->host_lock);
868 phba->fc_topology_changed = 0;
871 rc = memcmp(&vport->fc_portname, &sp->portName,
872 sizeof(vport->fc_portname));
875 /* This side will initiate the PLOGI */
876 spin_lock_irq(shost->host_lock);
877 vport->fc_flag |= FC_PT2PT_PLOGI;
878 spin_unlock_irq(shost->host_lock);
881 * N_Port ID cannot be 0, set our Id to LocalID
882 * the other side will be RemoteID.
887 vport->fc_myDID = PT2PT_LocalID;
889 /* Decrement ndlp reference count indicating that ndlp can be
890 * safely released when other references to it are done.
894 ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
897 * Cannot find existing Fabric ndlp, so allocate a
900 ndlp = lpfc_nlp_init(vport, PT2PT_RemoteID);
903 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
904 ndlp = lpfc_enable_node(vport, ndlp,
905 NLP_STE_UNUSED_NODE);
910 memcpy(&ndlp->nlp_portname, &sp->portName,
911 sizeof(struct lpfc_name));
912 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
913 sizeof(struct lpfc_name));
914 /* Set state will put ndlp onto node list if not already done */
915 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
916 spin_lock_irq(shost->host_lock);
917 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
918 spin_unlock_irq(shost->host_lock);
920 /* This side will wait for the PLOGI, decrement ndlp reference
921 * count indicating that ndlp can be released when other
922 * references to it are done.
926 /* If we are pt2pt with another NPort, force NPIV off! */
927 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
929 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
933 lpfc_config_link(phba, mbox);
935 mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link;
937 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
938 if (rc == MBX_NOT_FINISHED) {
939 mempool_free(mbox, phba->mbox_mem_pool);
949 * lpfc_cmpl_els_flogi - Completion callback function for flogi
950 * @phba: pointer to lpfc hba data structure.
951 * @cmdiocb: pointer to lpfc command iocb data structure.
952 * @rspiocb: pointer to lpfc response iocb data structure.
954 * This routine is the top-level completion callback function for issuing
955 * a Fabric Login (FLOGI) command. If the response IOCB reported error,
956 * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If
957 * retry has been made (either immediately or delayed with lpfc_els_retry()
958 * returning 1), the command IOCB will be released and function returned.
959 * If the retry attempt has been given up (possibly reach the maximum
960 * number of retries), one additional decrement of ndlp reference shall be
961 * invoked before going out after releasing the command IOCB. This will
962 * actually release the remote node (Note, lpfc_els_free_iocb() will also
963 * invoke one decrement of ndlp reference count). If no error reported in
964 * the IOCB status, the command Port ID field is used to determine whether
965 * this is a point-to-point topology or a fabric topology: if the Port ID
966 * field is assigned, it is a fabric topology; otherwise, it is a
967 * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or
968 * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the
969 * specific topology completion conditions.
972 lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
973 struct lpfc_iocbq *rspiocb)
975 struct lpfc_vport *vport = cmdiocb->vport;
976 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
977 IOCB_t *irsp = &rspiocb->iocb;
978 struct lpfc_nodelist *ndlp = cmdiocb->context1;
979 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
980 struct serv_parm *sp;
984 /* Check to see if link went down during discovery */
985 if (lpfc_els_chk_latt(vport)) {
986 /* One additional decrement on node reference count to
987 * trigger the release of the node
993 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
994 "FLOGI cmpl: status:x%x/x%x state:x%x",
995 irsp->ulpStatus, irsp->un.ulpWord[4],
998 if (irsp->ulpStatus) {
1000 * In case of FIP mode, perform roundrobin FCF failover
1001 * due to new FCF discovery
1003 if ((phba->hba_flag & HBA_FIP_SUPPORT) &&
1004 (phba->fcf.fcf_flag & FCF_DISCOVERY)) {
1005 if (phba->link_state < LPFC_LINK_UP)
1006 goto stop_rr_fcf_flogi;
1007 if ((phba->fcoe_cvl_eventtag_attn ==
1008 phba->fcoe_cvl_eventtag) &&
1009 (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
1010 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1012 goto stop_rr_fcf_flogi;
1014 phba->fcoe_cvl_eventtag_attn =
1015 phba->fcoe_cvl_eventtag;
1016 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
1017 "2611 FLOGI failed on FCF (x%x), "
1018 "status:x%x/x%x, tmo:x%x, perform "
1019 "roundrobin FCF failover\n",
1020 phba->fcf.current_rec.fcf_indx,
1021 irsp->ulpStatus, irsp->un.ulpWord[4],
1023 lpfc_sli4_set_fcf_flogi_fail(phba,
1024 phba->fcf.current_rec.fcf_indx);
1025 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
1026 rc = lpfc_sli4_fcf_rr_next_proc(vport, fcf_index);
1033 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1034 "2858 FLOGI failure Status:x%x/x%x TMO:x%x "
1036 irsp->ulpStatus, irsp->un.ulpWord[4],
1037 irsp->ulpTimeout, phba->hba_flag,
1038 phba->fcf.fcf_flag);
1040 /* Check for retry */
1041 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
1045 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1046 "0100 FLOGI failure Status:x%x/x%x TMO:x%x\n",
1047 irsp->ulpStatus, irsp->un.ulpWord[4],
1050 /* FLOGI failed, so there is no fabric */
1051 spin_lock_irq(shost->host_lock);
1052 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
1053 spin_unlock_irq(shost->host_lock);
1055 /* If private loop, then allow max outstanding els to be
1056 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
1057 * alpa map would take too long otherwise.
1059 if (phba->alpa_map[0] == 0)
1060 vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
1061 if ((phba->sli_rev == LPFC_SLI_REV4) &&
1062 (!(vport->fc_flag & FC_VFI_REGISTERED) ||
1063 (vport->fc_prevDID != vport->fc_myDID) ||
1064 phba->fc_topology_changed)) {
1065 if (vport->fc_flag & FC_VFI_REGISTERED) {
1066 if (phba->fc_topology_changed) {
1067 lpfc_unregister_fcf_prep(phba);
1068 spin_lock_irq(shost->host_lock);
1069 vport->fc_flag &= ~FC_VFI_REGISTERED;
1070 spin_unlock_irq(shost->host_lock);
1071 phba->fc_topology_changed = 0;
1073 lpfc_sli4_unreg_all_rpis(vport);
1077 /* Do not register VFI if the driver aborted FLOGI */
1078 if (!lpfc_error_lost_link(irsp))
1079 lpfc_issue_reg_vfi(vport);
1085 spin_lock_irq(shost->host_lock);
1086 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
1087 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
1088 spin_unlock_irq(shost->host_lock);
1091 * The FLogI succeeded. Sync the data for the CPU before
1094 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
1097 sp = prsp->virt + sizeof(uint32_t);
1099 /* FLOGI completes successfully */
1100 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1101 "0101 FLOGI completes successfully, I/O tag:x%x, "
1102 "Data: x%x x%x x%x x%x x%x x%x\n", cmdiocb->iotag,
1103 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
1104 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution,
1105 vport->port_state, vport->fc_flag);
1107 if (vport->port_state == LPFC_FLOGI) {
1109 * If Common Service Parameters indicate Nport
1110 * we are point to point, if Fport we are Fabric.
1113 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
1114 else if (!(phba->hba_flag & HBA_FCOE_MODE))
1115 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
1117 lpfc_printf_vlog(vport, KERN_ERR,
1119 "2831 FLOGI response with cleared Fabric "
1120 "bit fcf_index 0x%x "
1121 "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x "
1123 "%02x%02x%02x%02x%02x%02x%02x%02x\n",
1124 phba->fcf.current_rec.fcf_indx,
1125 phba->fcf.current_rec.switch_name[0],
1126 phba->fcf.current_rec.switch_name[1],
1127 phba->fcf.current_rec.switch_name[2],
1128 phba->fcf.current_rec.switch_name[3],
1129 phba->fcf.current_rec.switch_name[4],
1130 phba->fcf.current_rec.switch_name[5],
1131 phba->fcf.current_rec.switch_name[6],
1132 phba->fcf.current_rec.switch_name[7],
1133 phba->fcf.current_rec.fabric_name[0],
1134 phba->fcf.current_rec.fabric_name[1],
1135 phba->fcf.current_rec.fabric_name[2],
1136 phba->fcf.current_rec.fabric_name[3],
1137 phba->fcf.current_rec.fabric_name[4],
1138 phba->fcf.current_rec.fabric_name[5],
1139 phba->fcf.current_rec.fabric_name[6],
1140 phba->fcf.current_rec.fabric_name[7]);
1142 spin_lock_irq(&phba->hbalock);
1143 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
1144 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
1145 spin_unlock_irq(&phba->hbalock);
1149 /* Mark the FCF discovery process done */
1150 if (phba->hba_flag & HBA_FIP_SUPPORT)
1151 lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP |
1153 "2769 FLOGI to FCF (x%x) "
1154 "completed successfully\n",
1155 phba->fcf.current_rec.fcf_indx);
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);
1165 spin_lock_irq(&phba->hbalock);
1166 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
1167 spin_unlock_irq(&phba->hbalock);
1171 if (!lpfc_error_lost_link(irsp)) {
1172 /* FLOGI failed, so just use loop map to make discovery list */
1173 lpfc_disc_list_loopmap(vport);
1175 /* Start discovery */
1176 lpfc_disc_start(vport);
1177 } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
1178 (((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
1179 IOERR_SLI_ABORTED) &&
1180 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
1181 IOERR_SLI_DOWN))) &&
1182 (phba->link_state != LPFC_CLEAR_LA)) {
1183 /* If FLOGI failed enable link interrupt. */
1184 lpfc_issue_clear_la(phba, vport);
1187 lpfc_els_free_iocb(phba, cmdiocb);
1191 * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport
1192 * @vport: pointer to a host virtual N_Port data structure.
1193 * @ndlp: pointer to a node-list data structure.
1194 * @retry: number of retries to the command IOCB.
1196 * This routine issues a Fabric Login (FLOGI) Request ELS command
1197 * for a @vport. The initiator service parameters are put into the payload
1198 * of the FLOGI Request IOCB and the top-level callback function pointer
1199 * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
1200 * function field. The lpfc_issue_fabric_iocb routine is invoked to send
1201 * out FLOGI ELS command with one outstanding fabric IOCB at a time.
1203 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1204 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1205 * will be stored into the context1 field of the IOCB for the completion
1206 * callback function to the FLOGI ELS command.
1209 * 0 - successfully issued flogi iocb for @vport
1210 * 1 - failed to issue flogi iocb for @vport
1213 lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1216 struct lpfc_hba *phba = vport->phba;
1217 struct serv_parm *sp;
1219 struct lpfc_iocbq *elsiocb;
1225 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
1226 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1227 ndlp->nlp_DID, ELS_CMD_FLOGI);
1232 icmd = &elsiocb->iocb;
1233 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1235 /* For FLOGI request, remainder of payload is service parameters */
1236 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
1237 pcmd += sizeof(uint32_t);
1238 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
1239 sp = (struct serv_parm *) pcmd;
1241 /* Setup CSPs accordingly for Fabric */
1242 sp->cmn.e_d_tov = 0;
1243 sp->cmn.w2.r_a_tov = 0;
1244 sp->cmn.virtual_fabric_support = 0;
1245 sp->cls1.classValid = 0;
1246 if (sp->cmn.fcphLow < FC_PH3)
1247 sp->cmn.fcphLow = FC_PH3;
1248 if (sp->cmn.fcphHigh < FC_PH3)
1249 sp->cmn.fcphHigh = FC_PH3;
1251 if (phba->sli_rev == LPFC_SLI_REV4) {
1252 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
1253 LPFC_SLI_INTF_IF_TYPE_0) {
1254 elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1);
1255 elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1);
1256 /* FLOGI needs to be 3 for WQE FCFI */
1257 /* Set the fcfi to the fcfi we registered with */
1258 elsiocb->iocb.ulpContext = phba->fcf.fcfi;
1260 /* Can't do SLI4 class2 without support sequence coalescing */
1261 sp->cls2.classValid = 0;
1262 sp->cls2.seqDelivery = 0;
1264 /* Historical, setting sequential-delivery bit for SLI3 */
1265 sp->cls2.seqDelivery = (sp->cls2.classValid) ? 1 : 0;
1266 sp->cls3.seqDelivery = (sp->cls3.classValid) ? 1 : 0;
1267 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
1268 sp->cmn.request_multiple_Nport = 1;
1269 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
1273 sp->cmn.request_multiple_Nport = 0;
1276 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
1277 icmd->un.elsreq64.myID = 0;
1278 icmd->un.elsreq64.fl = 1;
1281 tmo = phba->fc_ratov;
1282 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
1283 lpfc_set_disctmo(vport);
1284 phba->fc_ratov = tmo;
1286 phba->fc_stat.elsXmitFLOGI++;
1287 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
1289 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1290 "Issue FLOGI: opt:x%x",
1291 phba->sli3_options, 0, 0);
1293 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
1294 if (rc == IOCB_ERROR) {
1295 lpfc_els_free_iocb(phba, elsiocb);
1302 * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs
1303 * @phba: pointer to lpfc hba data structure.
1305 * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
1306 * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
1307 * list and issues an abort IOCB commond on each outstanding IOCB that
1308 * contains a active Fabric_DID ndlp. Note that this function is to issue
1309 * the abort IOCB command on all the outstanding IOCBs, thus when this
1310 * function returns, it does not guarantee all the IOCBs are actually aborted.
1313 * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0)
1316 lpfc_els_abort_flogi(struct lpfc_hba *phba)
1318 struct lpfc_sli_ring *pring;
1319 struct lpfc_iocbq *iocb, *next_iocb;
1320 struct lpfc_nodelist *ndlp;
1323 /* Abort outstanding I/O on NPort <nlp_DID> */
1324 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
1325 "0201 Abort outstanding I/O on NPort x%x\n",
1328 pring = lpfc_phba_elsring(phba);
1331 * Check the txcmplq for an iocb that matches the nport the driver is
1334 spin_lock_irq(&phba->hbalock);
1335 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
1337 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR) {
1338 ndlp = (struct lpfc_nodelist *)(iocb->context1);
1339 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
1340 (ndlp->nlp_DID == Fabric_DID))
1341 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
1344 spin_unlock_irq(&phba->hbalock);
1350 * lpfc_initial_flogi - Issue an initial fabric login for a vport
1351 * @vport: pointer to a host virtual N_Port data structure.
1353 * This routine issues an initial Fabric Login (FLOGI) for the @vport
1354 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1355 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1356 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1357 * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
1358 * is then invoked with the @vport and the ndlp to perform the FLOGI for the
1362 * 0 - failed to issue initial flogi for @vport
1363 * 1 - successfully issued initial flogi for @vport
1366 lpfc_initial_flogi(struct lpfc_vport *vport)
1368 struct lpfc_nodelist *ndlp;
1370 vport->port_state = LPFC_FLOGI;
1371 lpfc_set_disctmo(vport);
1373 /* First look for the Fabric ndlp */
1374 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1376 /* Cannot find existing Fabric ndlp, so allocate a new one */
1377 ndlp = lpfc_nlp_init(vport, Fabric_DID);
1380 /* Set the node type */
1381 ndlp->nlp_type |= NLP_FABRIC;
1382 /* Put ndlp onto node list */
1383 lpfc_enqueue_node(vport, ndlp);
1384 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1385 /* re-setup ndlp without removing from node list */
1386 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1391 if (lpfc_issue_els_flogi(vport, ndlp, 0)) {
1392 /* This decrement of reference count to node shall kick off
1393 * the release of the node.
1402 * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport
1403 * @vport: pointer to a host virtual N_Port data structure.
1405 * This routine issues an initial Fabric Discover (FDISC) for the @vport
1406 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1407 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1408 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1409 * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
1410 * is then invoked with the @vport and the ndlp to perform the FDISC for the
1414 * 0 - failed to issue initial fdisc for @vport
1415 * 1 - successfully issued initial fdisc for @vport
1418 lpfc_initial_fdisc(struct lpfc_vport *vport)
1420 struct lpfc_nodelist *ndlp;
1422 /* First look for the Fabric ndlp */
1423 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1425 /* Cannot find existing Fabric ndlp, so allocate a new one */
1426 ndlp = lpfc_nlp_init(vport, Fabric_DID);
1429 /* Put ndlp onto node list */
1430 lpfc_enqueue_node(vport, ndlp);
1431 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1432 /* re-setup ndlp without removing from node list */
1433 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1438 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
1439 /* decrement node reference count to trigger the release of
1449 * lpfc_more_plogi - Check and issue remaining plogis for a vport
1450 * @vport: pointer to a host virtual N_Port data structure.
1452 * This routine checks whether there are more remaining Port Logins
1453 * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
1454 * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
1455 * to issue ELS PLOGIs up to the configured discover threads with the
1456 * @vport (@vport->cfg_discovery_threads). The function also decrement
1457 * the @vport's num_disc_node by 1 if it is not already 0.
1460 lpfc_more_plogi(struct lpfc_vport *vport)
1462 if (vport->num_disc_nodes)
1463 vport->num_disc_nodes--;
1465 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
1466 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1467 "0232 Continue discovery with %d PLOGIs to go "
1468 "Data: x%x x%x x%x\n",
1469 vport->num_disc_nodes, vport->fc_plogi_cnt,
1470 vport->fc_flag, vport->port_state);
1471 /* Check to see if there are more PLOGIs to be sent */
1472 if (vport->fc_flag & FC_NLP_MORE)
1473 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
1474 lpfc_els_disc_plogi(vport);
1480 * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp
1481 * @phba: pointer to lpfc hba data structure.
1482 * @prsp: pointer to response IOCB payload.
1483 * @ndlp: pointer to a node-list data structure.
1485 * This routine checks and indicates whether the WWPN of an N_Port, retrieved
1486 * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
1487 * The following cases are considered N_Port confirmed:
1488 * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
1489 * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
1490 * it does not have WWPN assigned either. If the WWPN is confirmed, the
1491 * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
1492 * 1) if there is a node on vport list other than the @ndlp with the same
1493 * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
1494 * on that node to release the RPI associated with the node; 2) if there is
1495 * no node found on vport list with the same WWPN of the N_Port PLOGI logged
1496 * into, a new node shall be allocated (or activated). In either case, the
1497 * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
1498 * be released and the new_ndlp shall be put on to the vport node list and
1499 * its pointer returned as the confirmed node.
1501 * Note that before the @ndlp got "released", the keepDID from not-matching
1502 * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
1503 * of the @ndlp. This is because the release of @ndlp is actually to put it
1504 * into an inactive state on the vport node list and the vport node list
1505 * management algorithm does not allow two node with a same DID.
1508 * pointer to the PLOGI N_Port @ndlp
1510 static struct lpfc_nodelist *
1511 lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
1512 struct lpfc_nodelist *ndlp)
1514 struct lpfc_vport *vport = ndlp->vport;
1515 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1516 struct lpfc_nodelist *new_ndlp;
1517 struct lpfc_rport_data *rdata;
1518 struct fc_rport *rport;
1519 struct serv_parm *sp;
1520 uint8_t name[sizeof(struct lpfc_name)];
1521 uint32_t rc, keepDID = 0, keep_nlp_flag = 0;
1522 uint16_t keep_nlp_state;
1525 unsigned long *active_rrqs_xri_bitmap = NULL;
1527 /* Fabric nodes can have the same WWPN so we don't bother searching
1528 * by WWPN. Just return the ndlp that was given to us.
1530 if (ndlp->nlp_type & NLP_FABRIC)
1533 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
1534 memset(name, 0, sizeof(struct lpfc_name));
1536 /* Now we find out if the NPort we are logging into, matches the WWPN
1537 * we have for that ndlp. If not, we have some work to do.
1539 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
1541 if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp))
1543 if (phba->sli_rev == LPFC_SLI_REV4) {
1544 active_rrqs_xri_bitmap = mempool_alloc(phba->active_rrq_pool,
1546 if (active_rrqs_xri_bitmap)
1547 memset(active_rrqs_xri_bitmap, 0,
1548 phba->cfg_rrq_xri_bitmap_sz);
1551 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1552 "3178 PLOGI confirm: ndlp %p x%x: new_ndlp %p\n",
1553 ndlp, ndlp->nlp_DID, new_ndlp);
1556 rc = memcmp(&ndlp->nlp_portname, name,
1557 sizeof(struct lpfc_name));
1559 if (active_rrqs_xri_bitmap)
1560 mempool_free(active_rrqs_xri_bitmap,
1561 phba->active_rrq_pool);
1564 new_ndlp = lpfc_nlp_init(vport, ndlp->nlp_DID);
1566 if (active_rrqs_xri_bitmap)
1567 mempool_free(active_rrqs_xri_bitmap,
1568 phba->active_rrq_pool);
1571 } else if (!NLP_CHK_NODE_ACT(new_ndlp)) {
1572 rc = memcmp(&ndlp->nlp_portname, name,
1573 sizeof(struct lpfc_name));
1575 if (active_rrqs_xri_bitmap)
1576 mempool_free(active_rrqs_xri_bitmap,
1577 phba->active_rrq_pool);
1580 new_ndlp = lpfc_enable_node(vport, new_ndlp,
1581 NLP_STE_UNUSED_NODE);
1583 if (active_rrqs_xri_bitmap)
1584 mempool_free(active_rrqs_xri_bitmap,
1585 phba->active_rrq_pool);
1588 keepDID = new_ndlp->nlp_DID;
1589 if ((phba->sli_rev == LPFC_SLI_REV4) && active_rrqs_xri_bitmap)
1590 memcpy(active_rrqs_xri_bitmap,
1591 new_ndlp->active_rrqs_xri_bitmap,
1592 phba->cfg_rrq_xri_bitmap_sz);
1594 keepDID = new_ndlp->nlp_DID;
1595 if (phba->sli_rev == LPFC_SLI_REV4 &&
1596 active_rrqs_xri_bitmap)
1597 memcpy(active_rrqs_xri_bitmap,
1598 new_ndlp->active_rrqs_xri_bitmap,
1599 phba->cfg_rrq_xri_bitmap_sz);
1602 lpfc_unreg_rpi(vport, new_ndlp);
1603 new_ndlp->nlp_DID = ndlp->nlp_DID;
1604 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
1605 if (phba->sli_rev == LPFC_SLI_REV4)
1606 memcpy(new_ndlp->active_rrqs_xri_bitmap,
1607 ndlp->active_rrqs_xri_bitmap,
1608 phba->cfg_rrq_xri_bitmap_sz);
1610 spin_lock_irq(shost->host_lock);
1611 keep_nlp_flag = new_ndlp->nlp_flag;
1612 new_ndlp->nlp_flag = ndlp->nlp_flag;
1613 ndlp->nlp_flag = keep_nlp_flag;
1614 spin_unlock_irq(shost->host_lock);
1616 /* Set nlp_states accordingly */
1617 keep_nlp_state = new_ndlp->nlp_state;
1618 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
1620 /* Move this back to NPR state */
1621 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
1622 /* The new_ndlp is replacing ndlp totally, so we need
1623 * to put ndlp on UNUSED list and try to free it.
1625 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1626 "3179 PLOGI confirm NEW: %x %x\n",
1627 new_ndlp->nlp_DID, keepDID);
1629 /* Fix up the rport accordingly */
1630 rport = ndlp->rport;
1632 rdata = rport->dd_data;
1633 if (rdata->pnode == ndlp) {
1634 /* break the link before dropping the ref */
1637 rdata->pnode = lpfc_nlp_get(new_ndlp);
1638 new_ndlp->rport = rport;
1640 new_ndlp->nlp_type = ndlp->nlp_type;
1642 /* We shall actually free the ndlp with both nlp_DID and
1643 * nlp_portname fields equals 0 to avoid any ndlp on the
1644 * nodelist never to be used.
1646 if (ndlp->nlp_DID == 0) {
1647 spin_lock_irq(&phba->ndlp_lock);
1648 NLP_SET_FREE_REQ(ndlp);
1649 spin_unlock_irq(&phba->ndlp_lock);
1652 /* Two ndlps cannot have the same did on the nodelist */
1653 ndlp->nlp_DID = keepDID;
1654 if (phba->sli_rev == LPFC_SLI_REV4 &&
1655 active_rrqs_xri_bitmap)
1656 memcpy(ndlp->active_rrqs_xri_bitmap,
1657 active_rrqs_xri_bitmap,
1658 phba->cfg_rrq_xri_bitmap_sz);
1660 if (!NLP_CHK_NODE_ACT(ndlp))
1661 lpfc_drop_node(vport, ndlp);
1664 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1665 "3180 PLOGI confirm SWAP: %x %x\n",
1666 new_ndlp->nlp_DID, keepDID);
1668 lpfc_unreg_rpi(vport, ndlp);
1670 /* Two ndlps cannot have the same did */
1671 ndlp->nlp_DID = keepDID;
1672 if (phba->sli_rev == LPFC_SLI_REV4 &&
1673 active_rrqs_xri_bitmap)
1674 memcpy(ndlp->active_rrqs_xri_bitmap,
1675 active_rrqs_xri_bitmap,
1676 phba->cfg_rrq_xri_bitmap_sz);
1678 /* Since we are switching over to the new_ndlp,
1679 * reset the old ndlp state
1681 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
1682 (ndlp->nlp_state == NLP_STE_MAPPED_NODE))
1683 keep_nlp_state = NLP_STE_NPR_NODE;
1684 lpfc_nlp_set_state(vport, ndlp, keep_nlp_state);
1686 /* Fix up the rport accordingly */
1687 rport = ndlp->rport;
1689 rdata = rport->dd_data;
1690 put_node = rdata->pnode != NULL;
1691 put_rport = ndlp->rport != NULL;
1692 rdata->pnode = NULL;
1697 put_device(&rport->dev);
1700 if (phba->sli_rev == LPFC_SLI_REV4 &&
1701 active_rrqs_xri_bitmap)
1702 mempool_free(active_rrqs_xri_bitmap,
1703 phba->active_rrq_pool);
1708 * lpfc_end_rscn - Check and handle more rscn for a vport
1709 * @vport: pointer to a host virtual N_Port data structure.
1711 * This routine checks whether more Registration State Change
1712 * Notifications (RSCNs) came in while the discovery state machine was in
1713 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1714 * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1715 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1716 * handling the RSCNs.
1719 lpfc_end_rscn(struct lpfc_vport *vport)
1721 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1723 if (vport->fc_flag & FC_RSCN_MODE) {
1725 * Check to see if more RSCNs came in while we were
1726 * processing this one.
1728 if (vport->fc_rscn_id_cnt ||
1729 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
1730 lpfc_els_handle_rscn(vport);
1732 spin_lock_irq(shost->host_lock);
1733 vport->fc_flag &= ~FC_RSCN_MODE;
1734 spin_unlock_irq(shost->host_lock);
1740 * lpfc_cmpl_els_rrq - Completion handled for els RRQs.
1741 * @phba: pointer to lpfc hba data structure.
1742 * @cmdiocb: pointer to lpfc command iocb data structure.
1743 * @rspiocb: pointer to lpfc response iocb data structure.
1745 * This routine will call the clear rrq function to free the rrq and
1746 * clear the xri's bit in the ndlp's xri_bitmap. If the ndlp does not
1747 * exist then the clear_rrq is still called because the rrq needs to
1752 lpfc_cmpl_els_rrq(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1753 struct lpfc_iocbq *rspiocb)
1755 struct lpfc_vport *vport = cmdiocb->vport;
1757 struct lpfc_nodelist *ndlp;
1758 struct lpfc_node_rrq *rrq;
1760 /* we pass cmdiocb to state machine which needs rspiocb as well */
1761 rrq = cmdiocb->context_un.rrq;
1762 cmdiocb->context_un.rsp_iocb = rspiocb;
1764 irsp = &rspiocb->iocb;
1765 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1766 "RRQ cmpl: status:x%x/x%x did:x%x",
1767 irsp->ulpStatus, irsp->un.ulpWord[4],
1768 irsp->un.elsreq64.remoteID);
1770 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
1771 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || ndlp != rrq->ndlp) {
1772 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1773 "2882 RRQ completes to NPort x%x "
1774 "with no ndlp. Data: x%x x%x x%x\n",
1775 irsp->un.elsreq64.remoteID,
1776 irsp->ulpStatus, irsp->un.ulpWord[4],
1781 /* rrq completes to NPort <nlp_DID> */
1782 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1783 "2880 RRQ completes to NPort x%x "
1784 "Data: x%x x%x x%x x%x x%x\n",
1785 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1786 irsp->ulpTimeout, rrq->xritag, rrq->rxid);
1788 if (irsp->ulpStatus) {
1789 /* Check for retry */
1790 /* RRQ failed Don't print the vport to vport rjts */
1791 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1792 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1793 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1794 (phba)->pport->cfg_log_verbose & LOG_ELS)
1795 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1796 "2881 RRQ failure DID:%06X Status:x%x/x%x\n",
1797 ndlp->nlp_DID, irsp->ulpStatus,
1798 irsp->un.ulpWord[4]);
1802 lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
1803 lpfc_els_free_iocb(phba, cmdiocb);
1807 * lpfc_cmpl_els_plogi - Completion callback function for plogi
1808 * @phba: pointer to lpfc hba data structure.
1809 * @cmdiocb: pointer to lpfc command iocb data structure.
1810 * @rspiocb: pointer to lpfc response iocb data structure.
1812 * This routine is the completion callback function for issuing the Port
1813 * Login (PLOGI) command. For PLOGI completion, there must be an active
1814 * ndlp on the vport node list that matches the remote node ID from the
1815 * PLOGI response IOCB. If such ndlp does not exist, the PLOGI is simply
1816 * ignored and command IOCB released. The PLOGI response IOCB status is
1817 * checked for error conditons. If there is error status reported, PLOGI
1818 * retry shall be attempted by invoking the lpfc_els_retry() routine.
1819 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1820 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1821 * (DSM) is set for this PLOGI completion. Finally, it checks whether
1822 * there are additional N_Port nodes with the vport that need to perform
1823 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
1827 lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1828 struct lpfc_iocbq *rspiocb)
1830 struct lpfc_vport *vport = cmdiocb->vport;
1831 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1833 struct lpfc_nodelist *ndlp;
1834 struct lpfc_dmabuf *prsp;
1837 /* we pass cmdiocb to state machine which needs rspiocb as well */
1838 cmdiocb->context_un.rsp_iocb = rspiocb;
1840 irsp = &rspiocb->iocb;
1841 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1842 "PLOGI cmpl: status:x%x/x%x did:x%x",
1843 irsp->ulpStatus, irsp->un.ulpWord[4],
1844 irsp->un.elsreq64.remoteID);
1846 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
1847 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
1848 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1849 "0136 PLOGI completes to NPort x%x "
1850 "with no ndlp. Data: x%x x%x x%x\n",
1851 irsp->un.elsreq64.remoteID,
1852 irsp->ulpStatus, irsp->un.ulpWord[4],
1857 /* Since ndlp can be freed in the disc state machine, note if this node
1858 * is being used during discovery.
1860 spin_lock_irq(shost->host_lock);
1861 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
1862 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1863 spin_unlock_irq(shost->host_lock);
1866 /* PLOGI completes to NPort <nlp_DID> */
1867 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1868 "0102 PLOGI completes to NPort x%06x "
1869 "Data: x%x x%x x%x x%x x%x\n",
1870 ndlp->nlp_DID, ndlp->nlp_fc4_type,
1871 irsp->ulpStatus, irsp->un.ulpWord[4],
1872 disc, vport->num_disc_nodes);
1874 /* Check to see if link went down during discovery */
1875 if (lpfc_els_chk_latt(vport)) {
1876 spin_lock_irq(shost->host_lock);
1877 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1878 spin_unlock_irq(shost->host_lock);
1882 if (irsp->ulpStatus) {
1883 /* Check for retry */
1884 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1885 /* ELS command is being retried */
1887 spin_lock_irq(shost->host_lock);
1888 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1889 spin_unlock_irq(shost->host_lock);
1893 /* PLOGI failed Don't print the vport to vport rjts */
1894 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1895 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1896 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1897 (phba)->pport->cfg_log_verbose & LOG_ELS)
1898 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1899 "2753 PLOGI failure DID:%06X Status:x%x/x%x\n",
1900 ndlp->nlp_DID, irsp->ulpStatus,
1901 irsp->un.ulpWord[4]);
1902 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1903 if (lpfc_error_lost_link(irsp))
1904 rc = NLP_STE_FREED_NODE;
1906 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1907 NLP_EVT_CMPL_PLOGI);
1909 /* Good status, call state machine */
1910 prsp = list_entry(((struct lpfc_dmabuf *)
1911 cmdiocb->context2)->list.next,
1912 struct lpfc_dmabuf, list);
1913 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
1914 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1915 NLP_EVT_CMPL_PLOGI);
1918 if (disc && vport->num_disc_nodes) {
1919 /* Check to see if there are more PLOGIs to be sent */
1920 lpfc_more_plogi(vport);
1922 if (vport->num_disc_nodes == 0) {
1923 spin_lock_irq(shost->host_lock);
1924 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1925 spin_unlock_irq(shost->host_lock);
1927 lpfc_can_disctmo(vport);
1928 lpfc_end_rscn(vport);
1933 lpfc_els_free_iocb(phba, cmdiocb);
1938 * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
1939 * @vport: pointer to a host virtual N_Port data structure.
1940 * @did: destination port identifier.
1941 * @retry: number of retries to the command IOCB.
1943 * This routine issues a Port Login (PLOGI) command to a remote N_Port
1944 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
1945 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
1946 * This routine constructs the proper feilds of the PLOGI IOCB and invokes
1947 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
1949 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1950 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1951 * will be stored into the context1 field of the IOCB for the completion
1952 * callback function to the PLOGI ELS command.
1955 * 0 - Successfully issued a plogi for @vport
1956 * 1 - failed to issue a plogi for @vport
1959 lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
1961 struct lpfc_hba *phba = vport->phba;
1962 struct serv_parm *sp;
1963 struct lpfc_nodelist *ndlp;
1964 struct lpfc_iocbq *elsiocb;
1969 ndlp = lpfc_findnode_did(vport, did);
1970 if (ndlp && !NLP_CHK_NODE_ACT(ndlp))
1973 /* If ndlp is not NULL, we will bump the reference count on it */
1974 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
1975 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
1980 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1982 /* For PLOGI request, remainder of payload is service parameters */
1983 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
1984 pcmd += sizeof(uint32_t);
1985 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
1986 sp = (struct serv_parm *) pcmd;
1989 * If we are a N-port connected to a Fabric, fix-up paramm's so logins
1990 * to device on remote loops work.
1992 if ((vport->fc_flag & FC_FABRIC) && !(vport->fc_flag & FC_PUBLIC_LOOP))
1993 sp->cmn.altBbCredit = 1;
1995 if (sp->cmn.fcphLow < FC_PH_4_3)
1996 sp->cmn.fcphLow = FC_PH_4_3;
1998 if (sp->cmn.fcphHigh < FC_PH3)
1999 sp->cmn.fcphHigh = FC_PH3;
2001 sp->cmn.valid_vendor_ver_level = 0;
2002 memset(sp->un.vendorVersion, 0, sizeof(sp->un.vendorVersion));
2004 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2005 "Issue PLOGI: did:x%x",
2008 /* If our firmware supports this feature, convey that
2009 * information to the target using the vendor specific field.
2011 if (phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) {
2012 sp->cmn.valid_vendor_ver_level = 1;
2013 sp->un.vv.vid = cpu_to_be32(LPFC_VV_EMLX_ID);
2014 sp->un.vv.flags = cpu_to_be32(LPFC_VV_SUPPRESS_RSP);
2017 phba->fc_stat.elsXmitPLOGI++;
2018 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
2019 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
2021 if (ret == IOCB_ERROR) {
2022 lpfc_els_free_iocb(phba, elsiocb);
2029 * lpfc_cmpl_els_prli - Completion callback function for prli
2030 * @phba: pointer to lpfc hba data structure.
2031 * @cmdiocb: pointer to lpfc command iocb data structure.
2032 * @rspiocb: pointer to lpfc response iocb data structure.
2034 * This routine is the completion callback function for a Process Login
2035 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
2036 * status. If there is error status reported, PRLI retry shall be attempted
2037 * by invoking the lpfc_els_retry() routine. Otherwise, the state
2038 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
2039 * ndlp to mark the PRLI completion.
2042 lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2043 struct lpfc_iocbq *rspiocb)
2045 struct lpfc_vport *vport = cmdiocb->vport;
2046 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2048 struct lpfc_nodelist *ndlp;
2050 /* we pass cmdiocb to state machine which needs rspiocb as well */
2051 cmdiocb->context_un.rsp_iocb = rspiocb;
2053 irsp = &(rspiocb->iocb);
2054 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2055 spin_lock_irq(shost->host_lock);
2056 ndlp->nlp_flag &= ~NLP_PRLI_SND;
2057 spin_unlock_irq(shost->host_lock);
2059 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2060 "PRLI cmpl: status:x%x/x%x did:x%x",
2061 irsp->ulpStatus, irsp->un.ulpWord[4],
2064 /* Ddriver supports multiple FC4 types. Counters matter. */
2065 vport->fc_prli_sent--;
2067 /* PRLI completes to NPort <nlp_DID> */
2068 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2069 "0103 PRLI completes to NPort x%06x "
2070 "Data: x%x x%x x%x x%x\n",
2071 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2072 vport->num_disc_nodes, ndlp->fc4_prli_sent);
2074 /* Check to see if link went down during discovery */
2075 if (lpfc_els_chk_latt(vport))
2078 if (irsp->ulpStatus) {
2079 /* Check for retry */
2080 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2081 /* ELS command is being retried */
2082 ndlp->fc4_prli_sent--;
2086 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2087 "2754 PRLI failure DID:%06X Status:x%x/x%x\n",
2088 ndlp->nlp_DID, irsp->ulpStatus,
2089 irsp->un.ulpWord[4]);
2090 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2091 if (lpfc_error_lost_link(irsp))
2094 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2097 /* Good status, call state machine. However, if another
2098 * PRLI is outstanding, don't call the state machine
2099 * because final disposition to Mapped or Unmapped is
2102 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2106 lpfc_els_free_iocb(phba, cmdiocb);
2111 * lpfc_issue_els_prli - Issue a prli iocb command for a vport
2112 * @vport: pointer to a host virtual N_Port data structure.
2113 * @ndlp: pointer to a node-list data structure.
2114 * @retry: number of retries to the command IOCB.
2116 * This routine issues a Process Login (PRLI) ELS command for the
2117 * @vport. The PRLI service parameters are set up in the payload of the
2118 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
2119 * is put to the IOCB completion callback func field before invoking the
2120 * routine lpfc_sli_issue_iocb() to send out PRLI command.
2122 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2123 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2124 * will be stored into the context1 field of the IOCB for the completion
2125 * callback function to the PRLI ELS command.
2128 * 0 - successfully issued prli iocb command for @vport
2129 * 1 - failed to issue prli iocb command for @vport
2132 lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2135 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2136 struct lpfc_hba *phba = vport->phba;
2138 struct lpfc_nvme_prli *npr_nvme;
2139 struct lpfc_iocbq *elsiocb;
2142 u32 local_nlp_type, elscmd;
2144 local_nlp_type = ndlp->nlp_fc4_type;
2147 if (local_nlp_type & NLP_FC4_FCP) {
2148 /* Payload is 4 + 16 = 20 x14 bytes. */
2149 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
2150 elscmd = ELS_CMD_PRLI;
2151 } else if (local_nlp_type & NLP_FC4_NVME) {
2152 /* Payload is 4 + 20 = 24 x18 bytes. */
2153 cmdsize = (sizeof(uint32_t) + sizeof(struct lpfc_nvme_prli));
2154 elscmd = ELS_CMD_NVMEPRLI;
2156 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2157 "3083 Unknown FC_TYPE x%x ndlp x%06x\n",
2158 ndlp->nlp_fc4_type, ndlp->nlp_DID);
2161 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2162 ndlp->nlp_DID, elscmd);
2166 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2168 /* For PRLI request, remainder of payload is service parameters */
2169 memset(pcmd, 0, cmdsize);
2171 if (local_nlp_type & NLP_FC4_FCP) {
2172 /* Remainder of payload is FCP PRLI parameter page.
2173 * Note: this data structure is defined as
2174 * BE/LE in the structure definition so no
2175 * byte swap call is made.
2177 *((uint32_t *)(pcmd)) = ELS_CMD_PRLI;
2178 pcmd += sizeof(uint32_t);
2182 * If our firmware version is 3.20 or later,
2183 * set the following bits for FC-TAPE support.
2185 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
2186 npr->ConfmComplAllowed = 1;
2188 npr->TaskRetryIdReq = 1;
2190 npr->estabImagePair = 1;
2191 npr->readXferRdyDis = 1;
2192 if (vport->cfg_first_burst_size)
2193 npr->writeXferRdyDis = 1;
2195 /* For FCP support */
2196 npr->prliType = PRLI_FCP_TYPE;
2197 npr->initiatorFunc = 1;
2198 elsiocb->iocb_flag |= LPFC_PRLI_FCP_REQ;
2200 /* Remove FCP type - processed. */
2201 local_nlp_type &= ~NLP_FC4_FCP;
2202 } else if (local_nlp_type & NLP_FC4_NVME) {
2203 /* Remainder of payload is NVME PRLI parameter page.
2204 * This data structure is the newer definition that
2205 * uses bf macros so a byte swap is required.
2207 *((uint32_t *)(pcmd)) = ELS_CMD_NVMEPRLI;
2208 pcmd += sizeof(uint32_t);
2209 npr_nvme = (struct lpfc_nvme_prli *)pcmd;
2210 bf_set(prli_type_code, npr_nvme, PRLI_NVME_TYPE);
2211 bf_set(prli_estabImagePair, npr_nvme, 0); /* Should be 0 */
2213 /* Only initiators request first burst. */
2214 if ((phba->cfg_nvme_enable_fb) &&
2215 !phba->nvmet_support)
2216 bf_set(prli_fba, npr_nvme, 1);
2218 if (phba->nvmet_support) {
2219 bf_set(prli_tgt, npr_nvme, 1);
2220 bf_set(prli_disc, npr_nvme, 1);
2223 bf_set(prli_init, npr_nvme, 1);
2225 npr_nvme->word1 = cpu_to_be32(npr_nvme->word1);
2226 npr_nvme->word4 = cpu_to_be32(npr_nvme->word4);
2227 elsiocb->iocb_flag |= LPFC_PRLI_NVME_REQ;
2229 /* Remove NVME type - processed. */
2230 local_nlp_type &= ~NLP_FC4_NVME;
2233 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2234 "Issue PRLI: did:x%x",
2235 ndlp->nlp_DID, 0, 0);
2237 phba->fc_stat.elsXmitPRLI++;
2238 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
2239 spin_lock_irq(shost->host_lock);
2240 ndlp->nlp_flag |= NLP_PRLI_SND;
2241 spin_unlock_irq(shost->host_lock);
2242 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2244 spin_lock_irq(shost->host_lock);
2245 ndlp->nlp_flag &= ~NLP_PRLI_SND;
2246 spin_unlock_irq(shost->host_lock);
2247 lpfc_els_free_iocb(phba, elsiocb);
2251 /* The vport counters are used for lpfc_scan_finished, but
2252 * the ndlp is used to track outstanding PRLIs for different
2255 vport->fc_prli_sent++;
2256 ndlp->fc4_prli_sent++;
2258 /* The driver supports 2 FC4 types. Make sure
2259 * a PRLI is issued for all types before exiting.
2261 if (local_nlp_type & (NLP_FC4_FCP | NLP_FC4_NVME))
2262 goto send_next_prli;
2268 * lpfc_rscn_disc - Perform rscn discovery for a vport
2269 * @vport: pointer to a host virtual N_Port data structure.
2271 * This routine performs Registration State Change Notification (RSCN)
2272 * discovery for a @vport. If the @vport's node port recovery count is not
2273 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
2274 * the nodes that need recovery. If none of the PLOGI were needed through
2275 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
2276 * invoked to check and handle possible more RSCN came in during the period
2277 * of processing the current ones.
2280 lpfc_rscn_disc(struct lpfc_vport *vport)
2282 lpfc_can_disctmo(vport);
2284 /* RSCN discovery */
2285 /* go thru NPR nodes and issue ELS PLOGIs */
2286 if (vport->fc_npr_cnt)
2287 if (lpfc_els_disc_plogi(vport))
2290 lpfc_end_rscn(vport);
2294 * lpfc_adisc_done - Complete the adisc phase of discovery
2295 * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
2297 * This function is called when the final ADISC is completed during discovery.
2298 * This function handles clearing link attention or issuing reg_vpi depending
2299 * on whether npiv is enabled. This function also kicks off the PLOGI phase of
2301 * This function is called with no locks held.
2304 lpfc_adisc_done(struct lpfc_vport *vport)
2306 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2307 struct lpfc_hba *phba = vport->phba;
2310 * For NPIV, cmpl_reg_vpi will set port_state to READY,
2311 * and continue discovery.
2313 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2314 !(vport->fc_flag & FC_RSCN_MODE) &&
2315 (phba->sli_rev < LPFC_SLI_REV4)) {
2316 /* The ADISCs are complete. Doesn't matter if they
2317 * succeeded or failed because the ADISC completion
2318 * routine guarantees to call the state machine and
2319 * the RPI is either unregistered (failed ADISC response)
2320 * or the RPI is still valid and the node is marked
2321 * mapped for a target. The exchanges should be in the
2322 * correct state. This code is specific to SLI3.
2324 lpfc_issue_clear_la(phba, vport);
2325 lpfc_issue_reg_vpi(phba, vport);
2329 * For SLI2, we need to set port_state to READY
2330 * and continue discovery.
2332 if (vport->port_state < LPFC_VPORT_READY) {
2333 /* If we get here, there is nothing to ADISC */
2334 lpfc_issue_clear_la(phba, vport);
2335 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
2336 vport->num_disc_nodes = 0;
2337 /* go thru NPR list, issue ELS PLOGIs */
2338 if (vport->fc_npr_cnt)
2339 lpfc_els_disc_plogi(vport);
2340 if (!vport->num_disc_nodes) {
2341 spin_lock_irq(shost->host_lock);
2342 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2343 spin_unlock_irq(shost->host_lock);
2344 lpfc_can_disctmo(vport);
2345 lpfc_end_rscn(vport);
2348 vport->port_state = LPFC_VPORT_READY;
2350 lpfc_rscn_disc(vport);
2354 * lpfc_more_adisc - Issue more adisc as needed
2355 * @vport: pointer to a host virtual N_Port data structure.
2357 * This routine determines whether there are more ndlps on a @vport
2358 * node list need to have Address Discover (ADISC) issued. If so, it will
2359 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
2360 * remaining nodes which need to have ADISC sent.
2363 lpfc_more_adisc(struct lpfc_vport *vport)
2365 if (vport->num_disc_nodes)
2366 vport->num_disc_nodes--;
2367 /* Continue discovery with <num_disc_nodes> ADISCs to go */
2368 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2369 "0210 Continue discovery with %d ADISCs to go "
2370 "Data: x%x x%x x%x\n",
2371 vport->num_disc_nodes, vport->fc_adisc_cnt,
2372 vport->fc_flag, vport->port_state);
2373 /* Check to see if there are more ADISCs to be sent */
2374 if (vport->fc_flag & FC_NLP_MORE) {
2375 lpfc_set_disctmo(vport);
2376 /* go thru NPR nodes and issue any remaining ELS ADISCs */
2377 lpfc_els_disc_adisc(vport);
2379 if (!vport->num_disc_nodes)
2380 lpfc_adisc_done(vport);
2385 * lpfc_cmpl_els_adisc - Completion callback function for adisc
2386 * @phba: pointer to lpfc hba data structure.
2387 * @cmdiocb: pointer to lpfc command iocb data structure.
2388 * @rspiocb: pointer to lpfc response iocb data structure.
2390 * This routine is the completion function for issuing the Address Discover
2391 * (ADISC) command. It first checks to see whether link went down during
2392 * the discovery process. If so, the node will be marked as node port
2393 * recovery for issuing discover IOCB by the link attention handler and
2394 * exit. Otherwise, the response status is checked. If error was reported
2395 * in the response status, the ADISC command shall be retried by invoking
2396 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
2397 * the response status, the state machine is invoked to set transition
2398 * with respect to NLP_EVT_CMPL_ADISC event.
2401 lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2402 struct lpfc_iocbq *rspiocb)
2404 struct lpfc_vport *vport = cmdiocb->vport;
2405 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2407 struct lpfc_nodelist *ndlp;
2410 /* we pass cmdiocb to state machine which needs rspiocb as well */
2411 cmdiocb->context_un.rsp_iocb = rspiocb;
2413 irsp = &(rspiocb->iocb);
2414 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2416 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2417 "ADISC cmpl: status:x%x/x%x did:x%x",
2418 irsp->ulpStatus, irsp->un.ulpWord[4],
2421 /* Since ndlp can be freed in the disc state machine, note if this node
2422 * is being used during discovery.
2424 spin_lock_irq(shost->host_lock);
2425 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
2426 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
2427 spin_unlock_irq(shost->host_lock);
2428 /* ADISC completes to NPort <nlp_DID> */
2429 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2430 "0104 ADISC completes to NPort x%x "
2431 "Data: x%x x%x x%x x%x x%x\n",
2432 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2433 irsp->ulpTimeout, disc, vport->num_disc_nodes);
2434 /* Check to see if link went down during discovery */
2435 if (lpfc_els_chk_latt(vport)) {
2436 spin_lock_irq(shost->host_lock);
2437 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2438 spin_unlock_irq(shost->host_lock);
2442 if (irsp->ulpStatus) {
2443 /* Check for retry */
2444 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2445 /* ELS command is being retried */
2447 spin_lock_irq(shost->host_lock);
2448 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2449 spin_unlock_irq(shost->host_lock);
2450 lpfc_set_disctmo(vport);
2455 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2456 "2755 ADISC failure DID:%06X Status:x%x/x%x\n",
2457 ndlp->nlp_DID, irsp->ulpStatus,
2458 irsp->un.ulpWord[4]);
2459 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2460 if (!lpfc_error_lost_link(irsp))
2461 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2462 NLP_EVT_CMPL_ADISC);
2464 /* Good status, call state machine */
2465 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2466 NLP_EVT_CMPL_ADISC);
2468 /* Check to see if there are more ADISCs to be sent */
2469 if (disc && vport->num_disc_nodes)
2470 lpfc_more_adisc(vport);
2472 lpfc_els_free_iocb(phba, cmdiocb);
2477 * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
2478 * @vport: pointer to a virtual N_Port data structure.
2479 * @ndlp: pointer to a node-list data structure.
2480 * @retry: number of retries to the command IOCB.
2482 * This routine issues an Address Discover (ADISC) for an @ndlp on a
2483 * @vport. It prepares the payload of the ADISC ELS command, updates the
2484 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
2485 * to issue the ADISC ELS command.
2487 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2488 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2489 * will be stored into the context1 field of the IOCB for the completion
2490 * callback function to the ADISC ELS command.
2493 * 0 - successfully issued adisc
2494 * 1 - failed to issue adisc
2497 lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2500 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2501 struct lpfc_hba *phba = vport->phba;
2503 struct lpfc_iocbq *elsiocb;
2507 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
2508 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2509 ndlp->nlp_DID, ELS_CMD_ADISC);
2513 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2515 /* For ADISC request, remainder of payload is service parameters */
2516 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
2517 pcmd += sizeof(uint32_t);
2519 /* Fill in ADISC payload */
2520 ap = (ADISC *) pcmd;
2521 ap->hardAL_PA = phba->fc_pref_ALPA;
2522 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2523 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
2524 ap->DID = be32_to_cpu(vport->fc_myDID);
2526 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2527 "Issue ADISC: did:x%x",
2528 ndlp->nlp_DID, 0, 0);
2530 phba->fc_stat.elsXmitADISC++;
2531 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
2532 spin_lock_irq(shost->host_lock);
2533 ndlp->nlp_flag |= NLP_ADISC_SND;
2534 spin_unlock_irq(shost->host_lock);
2535 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2537 spin_lock_irq(shost->host_lock);
2538 ndlp->nlp_flag &= ~NLP_ADISC_SND;
2539 spin_unlock_irq(shost->host_lock);
2540 lpfc_els_free_iocb(phba, elsiocb);
2547 * lpfc_cmpl_els_logo - Completion callback function for logo
2548 * @phba: pointer to lpfc hba data structure.
2549 * @cmdiocb: pointer to lpfc command iocb data structure.
2550 * @rspiocb: pointer to lpfc response iocb data structure.
2552 * This routine is the completion function for issuing the ELS Logout (LOGO)
2553 * command. If no error status was reported from the LOGO response, the
2554 * state machine of the associated ndlp shall be invoked for transition with
2555 * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
2556 * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
2559 lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2560 struct lpfc_iocbq *rspiocb)
2562 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2563 struct lpfc_vport *vport = ndlp->vport;
2564 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2566 struct lpfcMboxq *mbox;
2567 unsigned long flags;
2568 uint32_t skip_recovery = 0;
2570 /* we pass cmdiocb to state machine which needs rspiocb as well */
2571 cmdiocb->context_un.rsp_iocb = rspiocb;
2573 irsp = &(rspiocb->iocb);
2574 spin_lock_irq(shost->host_lock);
2575 ndlp->nlp_flag &= ~NLP_LOGO_SND;
2576 spin_unlock_irq(shost->host_lock);
2578 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2579 "LOGO cmpl: status:x%x/x%x did:x%x",
2580 irsp->ulpStatus, irsp->un.ulpWord[4],
2583 /* LOGO completes to NPort <nlp_DID> */
2584 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2585 "0105 LOGO completes to NPort x%x "
2586 "Data: x%x x%x x%x x%x\n",
2587 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2588 irsp->ulpTimeout, vport->num_disc_nodes);
2590 if (lpfc_els_chk_latt(vport)) {
2595 /* Check to see if link went down during discovery */
2596 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
2597 /* NLP_EVT_DEVICE_RM should unregister the RPI
2598 * which should abort all outstanding IOs.
2600 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2606 if (irsp->ulpStatus) {
2607 /* Check for retry */
2608 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2609 /* ELS command is being retried */
2614 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2615 "2756 LOGO failure DID:%06X Status:x%x/x%x\n",
2616 ndlp->nlp_DID, irsp->ulpStatus,
2617 irsp->un.ulpWord[4]);
2618 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2619 if (lpfc_error_lost_link(irsp)) {
2625 /* Call state machine. This will unregister the rpi if needed. */
2626 lpfc_disc_state_machine(vport, ndlp, cmdiocb, NLP_EVT_CMPL_LOGO);
2629 lpfc_els_free_iocb(phba, cmdiocb);
2630 /* If we are in pt2pt mode, we could rcv new S_ID on PLOGI */
2631 if ((vport->fc_flag & FC_PT2PT) &&
2632 !(vport->fc_flag & FC_PT2PT_PLOGI)) {
2633 phba->pport->fc_myDID = 0;
2635 if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
2636 (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
2637 if (phba->nvmet_support)
2638 lpfc_nvmet_update_targetport(phba);
2640 lpfc_nvme_update_localport(phba->pport);
2643 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2645 lpfc_config_link(phba, mbox);
2646 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
2647 mbox->vport = vport;
2648 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) ==
2650 mempool_free(mbox, phba->mbox_mem_pool);
2657 * If the node is a target, the handling attempts to recover the port.
2658 * For any other port type, the rpi is unregistered as an implicit
2661 if ((ndlp->nlp_type & NLP_FCP_TARGET) && (skip_recovery == 0)) {
2662 lpfc_cancel_retry_delay_tmo(vport, ndlp);
2663 spin_lock_irqsave(shost->host_lock, flags);
2664 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2665 spin_unlock_irqrestore(shost->host_lock, flags);
2667 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2668 "3187 LOGO completes to NPort x%x: Start "
2669 "Recovery Data: x%x x%x x%x x%x\n",
2670 ndlp->nlp_DID, irsp->ulpStatus,
2671 irsp->un.ulpWord[4], irsp->ulpTimeout,
2672 vport->num_disc_nodes);
2673 lpfc_disc_start(vport);
2679 * lpfc_issue_els_logo - Issue a logo to an node on a vport
2680 * @vport: pointer to a virtual N_Port data structure.
2681 * @ndlp: pointer to a node-list data structure.
2682 * @retry: number of retries to the command IOCB.
2684 * This routine constructs and issues an ELS Logout (LOGO) iocb command
2685 * to a remote node, referred by an @ndlp on a @vport. It constructs the
2686 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
2687 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
2689 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2690 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2691 * will be stored into the context1 field of the IOCB for the completion
2692 * callback function to the LOGO ELS command.
2695 * 0 - successfully issued logo
2696 * 1 - failed to issue logo
2699 lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2702 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2703 struct lpfc_hba *phba = vport->phba;
2704 struct lpfc_iocbq *elsiocb;
2709 spin_lock_irq(shost->host_lock);
2710 if (ndlp->nlp_flag & NLP_LOGO_SND) {
2711 spin_unlock_irq(shost->host_lock);
2714 spin_unlock_irq(shost->host_lock);
2716 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
2717 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2718 ndlp->nlp_DID, ELS_CMD_LOGO);
2722 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2723 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
2724 pcmd += sizeof(uint32_t);
2726 /* Fill in LOGO payload */
2727 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
2728 pcmd += sizeof(uint32_t);
2729 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
2731 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2732 "Issue LOGO: did:x%x",
2733 ndlp->nlp_DID, 0, 0);
2736 * If we are issuing a LOGO, we may try to recover the remote NPort
2737 * by issuing a PLOGI later. Even though we issue ELS cmds by the
2738 * VPI, if we have a valid RPI, and that RPI gets unreg'ed while
2739 * that ELS command is in-flight, the HBA returns a IOERR_INVALID_RPI
2740 * for that ELS cmd. To avoid this situation, lets get rid of the
2741 * RPI right now, before any ELS cmds are sent.
2743 spin_lock_irq(shost->host_lock);
2744 ndlp->nlp_flag |= NLP_ISSUE_LOGO;
2745 spin_unlock_irq(shost->host_lock);
2746 if (lpfc_unreg_rpi(vport, ndlp)) {
2747 lpfc_els_free_iocb(phba, elsiocb);
2751 phba->fc_stat.elsXmitLOGO++;
2752 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
2753 spin_lock_irq(shost->host_lock);
2754 ndlp->nlp_flag |= NLP_LOGO_SND;
2755 ndlp->nlp_flag &= ~NLP_ISSUE_LOGO;
2756 spin_unlock_irq(shost->host_lock);
2757 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
2759 if (rc == IOCB_ERROR) {
2760 spin_lock_irq(shost->host_lock);
2761 ndlp->nlp_flag &= ~NLP_LOGO_SND;
2762 spin_unlock_irq(shost->host_lock);
2763 lpfc_els_free_iocb(phba, elsiocb);
2770 * lpfc_cmpl_els_cmd - Completion callback function for generic els command
2771 * @phba: pointer to lpfc hba data structure.
2772 * @cmdiocb: pointer to lpfc command iocb data structure.
2773 * @rspiocb: pointer to lpfc response iocb data structure.
2775 * This routine is a generic completion callback function for ELS commands.
2776 * Specifically, it is the callback function which does not need to perform
2777 * any command specific operations. It is currently used by the ELS command
2778 * issuing routines for the ELS State Change Request (SCR),
2779 * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution
2780 * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than
2781 * certain debug loggings, this callback function simply invokes the
2782 * lpfc_els_chk_latt() routine to check whether link went down during the
2783 * discovery process.
2786 lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2787 struct lpfc_iocbq *rspiocb)
2789 struct lpfc_vport *vport = cmdiocb->vport;
2792 irsp = &rspiocb->iocb;
2794 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2795 "ELS cmd cmpl: status:x%x/x%x did:x%x",
2796 irsp->ulpStatus, irsp->un.ulpWord[4],
2797 irsp->un.elsreq64.remoteID);
2798 /* ELS cmd tag <ulpIoTag> completes */
2799 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2800 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
2801 irsp->ulpIoTag, irsp->ulpStatus,
2802 irsp->un.ulpWord[4], irsp->ulpTimeout);
2803 /* Check to see if link went down during discovery */
2804 lpfc_els_chk_latt(vport);
2805 lpfc_els_free_iocb(phba, cmdiocb);
2810 * lpfc_issue_els_scr - Issue a scr to an node on a vport
2811 * @vport: pointer to a host virtual N_Port data structure.
2812 * @nportid: N_Port identifier to the remote node.
2813 * @retry: number of retries to the command IOCB.
2815 * This routine issues a State Change Request (SCR) to a fabric node
2816 * on a @vport. The remote node @nportid is passed into the function. It
2817 * first search the @vport node list to find the matching ndlp. If no such
2818 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
2819 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
2820 * routine is invoked to send the SCR IOCB.
2822 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2823 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2824 * will be stored into the context1 field of the IOCB for the completion
2825 * callback function to the SCR ELS command.
2828 * 0 - Successfully issued scr command
2829 * 1 - Failed to issue scr command
2832 lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
2834 struct lpfc_hba *phba = vport->phba;
2835 struct lpfc_iocbq *elsiocb;
2838 struct lpfc_nodelist *ndlp;
2840 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
2842 ndlp = lpfc_findnode_did(vport, nportid);
2844 ndlp = lpfc_nlp_init(vport, nportid);
2847 lpfc_enqueue_node(vport, ndlp);
2848 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2849 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2854 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2855 ndlp->nlp_DID, ELS_CMD_SCR);
2858 /* This will trigger the release of the node just
2865 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2867 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
2868 pcmd += sizeof(uint32_t);
2870 /* For SCR, remainder of payload is SCR parameter page */
2871 memset(pcmd, 0, sizeof(SCR));
2872 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
2874 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2875 "Issue SCR: did:x%x",
2876 ndlp->nlp_DID, 0, 0);
2878 phba->fc_stat.elsXmitSCR++;
2879 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
2880 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2882 /* The additional lpfc_nlp_put will cause the following
2883 * lpfc_els_free_iocb routine to trigger the rlease of
2887 lpfc_els_free_iocb(phba, elsiocb);
2890 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2891 * trigger the release of node.
2899 * lpfc_issue_els_farpr - Issue a farp to an node on a vport
2900 * @vport: pointer to a host virtual N_Port data structure.
2901 * @nportid: N_Port identifier to the remote node.
2902 * @retry: number of retries to the command IOCB.
2904 * This routine issues a Fibre Channel Address Resolution Response
2905 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
2906 * is passed into the function. It first search the @vport node list to find
2907 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
2908 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
2909 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
2911 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2912 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2913 * will be stored into the context1 field of the IOCB for the completion
2914 * callback function to the PARPR ELS command.
2917 * 0 - Successfully issued farpr command
2918 * 1 - Failed to issue farpr command
2921 lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
2923 struct lpfc_hba *phba = vport->phba;
2924 struct lpfc_iocbq *elsiocb;
2929 struct lpfc_nodelist *ondlp;
2930 struct lpfc_nodelist *ndlp;
2932 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
2934 ndlp = lpfc_findnode_did(vport, nportid);
2936 ndlp = lpfc_nlp_init(vport, nportid);
2939 lpfc_enqueue_node(vport, ndlp);
2940 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2941 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2946 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2947 ndlp->nlp_DID, ELS_CMD_RNID);
2949 /* This will trigger the release of the node just
2956 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2958 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
2959 pcmd += sizeof(uint32_t);
2961 /* Fill in FARPR payload */
2962 fp = (FARP *) (pcmd);
2963 memset(fp, 0, sizeof(FARP));
2964 lp = (uint32_t *) pcmd;
2965 *lp++ = be32_to_cpu(nportid);
2966 *lp++ = be32_to_cpu(vport->fc_myDID);
2968 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
2970 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
2971 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
2972 ondlp = lpfc_findnode_did(vport, nportid);
2973 if (ondlp && NLP_CHK_NODE_ACT(ondlp)) {
2974 memcpy(&fp->OportName, &ondlp->nlp_portname,
2975 sizeof(struct lpfc_name));
2976 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
2977 sizeof(struct lpfc_name));
2980 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2981 "Issue FARPR: did:x%x",
2982 ndlp->nlp_DID, 0, 0);
2984 phba->fc_stat.elsXmitFARPR++;
2985 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
2986 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2988 /* The additional lpfc_nlp_put will cause the following
2989 * lpfc_els_free_iocb routine to trigger the release of
2993 lpfc_els_free_iocb(phba, elsiocb);
2996 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2997 * trigger the release of the node.
3004 * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
3005 * @vport: pointer to a host virtual N_Port data structure.
3006 * @nlp: pointer to a node-list data structure.
3008 * This routine cancels the timer with a delayed IOCB-command retry for
3009 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
3010 * removes the ELS retry event if it presents. In addition, if the
3011 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
3012 * commands are sent for the @vport's nodes that require issuing discovery
3016 lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
3018 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3019 struct lpfc_work_evt *evtp;
3021 if (!(nlp->nlp_flag & NLP_DELAY_TMO))
3023 spin_lock_irq(shost->host_lock);
3024 nlp->nlp_flag &= ~NLP_DELAY_TMO;
3025 spin_unlock_irq(shost->host_lock);
3026 del_timer_sync(&nlp->nlp_delayfunc);
3027 nlp->nlp_last_elscmd = 0;
3028 if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
3029 list_del_init(&nlp->els_retry_evt.evt_listp);
3030 /* Decrement nlp reference count held for the delayed retry */
3031 evtp = &nlp->els_retry_evt;
3032 lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
3034 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
3035 spin_lock_irq(shost->host_lock);
3036 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
3037 spin_unlock_irq(shost->host_lock);
3038 if (vport->num_disc_nodes) {
3039 if (vport->port_state < LPFC_VPORT_READY) {
3040 /* Check if there are more ADISCs to be sent */
3041 lpfc_more_adisc(vport);
3043 /* Check if there are more PLOGIs to be sent */
3044 lpfc_more_plogi(vport);
3045 if (vport->num_disc_nodes == 0) {
3046 spin_lock_irq(shost->host_lock);
3047 vport->fc_flag &= ~FC_NDISC_ACTIVE;
3048 spin_unlock_irq(shost->host_lock);
3049 lpfc_can_disctmo(vport);
3050 lpfc_end_rscn(vport);
3059 * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
3060 * @ptr: holder for the pointer to the timer function associated data (ndlp).
3062 * This routine is invoked by the ndlp delayed-function timer to check
3063 * whether there is any pending ELS retry event(s) with the node. If not, it
3064 * simply returns. Otherwise, if there is at least one ELS delayed event, it
3065 * adds the delayed events to the HBA work list and invokes the
3066 * lpfc_worker_wake_up() routine to wake up worker thread to process the
3067 * event. Note that lpfc_nlp_get() is called before posting the event to
3068 * the work list to hold reference count of ndlp so that it guarantees the
3069 * reference to ndlp will still be available when the worker thread gets
3070 * to the event associated with the ndlp.
3073 lpfc_els_retry_delay(unsigned long ptr)
3075 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr;
3076 struct lpfc_vport *vport = ndlp->vport;
3077 struct lpfc_hba *phba = vport->phba;
3078 unsigned long flags;
3079 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
3081 spin_lock_irqsave(&phba->hbalock, flags);
3082 if (!list_empty(&evtp->evt_listp)) {
3083 spin_unlock_irqrestore(&phba->hbalock, flags);
3087 /* We need to hold the node by incrementing the reference
3088 * count until the queued work is done
3090 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
3091 if (evtp->evt_arg1) {
3092 evtp->evt = LPFC_EVT_ELS_RETRY;
3093 list_add_tail(&evtp->evt_listp, &phba->work_list);
3094 lpfc_worker_wake_up(phba);
3096 spin_unlock_irqrestore(&phba->hbalock, flags);
3101 * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
3102 * @ndlp: pointer to a node-list data structure.
3104 * This routine is the worker-thread handler for processing the @ndlp delayed
3105 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
3106 * the last ELS command from the associated ndlp and invokes the proper ELS
3107 * function according to the delayed ELS command to retry the command.
3110 lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
3112 struct lpfc_vport *vport = ndlp->vport;
3113 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3114 uint32_t cmd, retry;
3116 spin_lock_irq(shost->host_lock);
3117 cmd = ndlp->nlp_last_elscmd;
3118 ndlp->nlp_last_elscmd = 0;
3120 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
3121 spin_unlock_irq(shost->host_lock);
3125 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
3126 spin_unlock_irq(shost->host_lock);
3128 * If a discovery event readded nlp_delayfunc after timer
3129 * firing and before processing the timer, cancel the
3132 del_timer_sync(&ndlp->nlp_delayfunc);
3133 retry = ndlp->nlp_retry;
3134 ndlp->nlp_retry = 0;
3138 lpfc_issue_els_flogi(vport, ndlp, retry);
3141 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
3142 ndlp->nlp_prev_state = ndlp->nlp_state;
3143 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
3147 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
3148 ndlp->nlp_prev_state = ndlp->nlp_state;
3149 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
3153 case ELS_CMD_NVMEPRLI:
3154 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
3155 ndlp->nlp_prev_state = ndlp->nlp_state;
3156 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
3160 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
3161 ndlp->nlp_prev_state = ndlp->nlp_state;
3162 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
3166 if (!(vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI))
3167 lpfc_issue_els_fdisc(vport, ndlp, retry);
3174 * lpfc_els_retry - Make retry decision on an els command iocb
3175 * @phba: pointer to lpfc hba data structure.
3176 * @cmdiocb: pointer to lpfc command iocb data structure.
3177 * @rspiocb: pointer to lpfc response iocb data structure.
3179 * This routine makes a retry decision on an ELS command IOCB, which has
3180 * failed. The following ELS IOCBs use this function for retrying the command
3181 * when previously issued command responsed with error status: FLOGI, PLOGI,
3182 * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
3183 * returned error status, it makes the decision whether a retry shall be
3184 * issued for the command, and whether a retry shall be made immediately or
3185 * delayed. In the former case, the corresponding ELS command issuing-function
3186 * is called to retry the command. In the later case, the ELS command shall
3187 * be posted to the ndlp delayed event and delayed function timer set to the
3188 * ndlp for the delayed command issusing.
3191 * 0 - No retry of els command is made
3192 * 1 - Immediate or delayed retry of els command is made
3195 lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3196 struct lpfc_iocbq *rspiocb)
3198 struct lpfc_vport *vport = cmdiocb->vport;
3199 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3200 IOCB_t *irsp = &rspiocb->iocb;
3201 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3202 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3205 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
3211 /* Note: context2 may be 0 for internal driver abort
3212 * of delays ELS command.
3215 if (pcmd && pcmd->virt) {
3216 elscmd = (uint32_t *) (pcmd->virt);
3220 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
3221 did = ndlp->nlp_DID;
3223 /* We should only hit this case for retrying PLOGI */
3224 did = irsp->un.elsreq64.remoteID;
3225 ndlp = lpfc_findnode_did(vport, did);
3226 if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp))
3227 && (cmd != ELS_CMD_PLOGI))
3231 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3232 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
3233 *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
3235 switch (irsp->ulpStatus) {
3236 case IOSTAT_FCP_RSP_ERROR:
3238 case IOSTAT_REMOTE_STOP:
3239 if (phba->sli_rev == LPFC_SLI_REV4) {
3240 /* This IO was aborted by the target, we don't
3241 * know the rxid and because we did not send the
3242 * ABTS we cannot generate and RRQ.
3244 lpfc_set_rrq_active(phba, ndlp,
3245 cmdiocb->sli4_lxritag, 0, 0);
3248 case IOSTAT_LOCAL_REJECT:
3249 switch ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK)) {
3250 case IOERR_LOOP_OPEN_FAILURE:
3251 if (cmd == ELS_CMD_FLOGI) {
3252 if (PCI_DEVICE_ID_HORNET ==
3253 phba->pcidev->device) {
3254 phba->fc_topology = LPFC_TOPOLOGY_LOOP;
3255 phba->pport->fc_myDID = 0;
3256 phba->alpa_map[0] = 0;
3257 phba->alpa_map[1] = 0;
3260 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
3265 case IOERR_ILLEGAL_COMMAND:
3266 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3267 "0124 Retry illegal cmd x%x "
3268 "retry:x%x delay:x%x\n",
3269 cmd, cmdiocb->retry, delay);
3271 /* All command's retry policy */
3273 if (cmdiocb->retry > 2)
3277 case IOERR_NO_RESOURCES:
3278 logerr = 1; /* HBA out of resources */
3280 if (cmdiocb->retry > 100)
3285 case IOERR_ILLEGAL_FRAME:
3290 case IOERR_SEQUENCE_TIMEOUT:
3291 case IOERR_INVALID_RPI:
3292 if (cmd == ELS_CMD_PLOGI &&
3293 did == NameServer_DID) {
3294 /* Continue forever if plogi to */
3295 /* the nameserver fails */
3304 case IOSTAT_NPORT_RJT:
3305 case IOSTAT_FABRIC_RJT:
3306 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
3312 case IOSTAT_NPORT_BSY:
3313 case IOSTAT_FABRIC_BSY:
3314 logerr = 1; /* Fabric / Remote NPort out of resources */
3319 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
3320 /* Added for Vendor specifc support
3321 * Just keep retrying for these Rsn / Exp codes
3323 switch (stat.un.b.lsRjtRsnCode) {
3324 case LSRJT_UNABLE_TPC:
3325 if (stat.un.b.lsRjtRsnCodeExp ==
3326 LSEXP_CMD_IN_PROGRESS) {
3327 if (cmd == ELS_CMD_PLOGI) {
3334 if (stat.un.b.lsRjtRsnCodeExp ==
3335 LSEXP_CANT_GIVE_DATA) {
3336 if (cmd == ELS_CMD_PLOGI) {
3343 if ((cmd == ELS_CMD_PLOGI) ||
3344 (cmd == ELS_CMD_PRLI) ||
3345 (cmd == ELS_CMD_NVMEPRLI)) {
3347 maxretry = lpfc_max_els_tries + 1;
3351 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
3352 (cmd == ELS_CMD_FDISC) &&
3353 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
3354 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3355 "0125 FDISC Failed (x%x). "
3356 "Fabric out of resources\n",
3357 stat.un.lsRjtError);
3358 lpfc_vport_set_state(vport,
3359 FC_VPORT_NO_FABRIC_RSCS);
3363 case LSRJT_LOGICAL_BSY:
3364 if ((cmd == ELS_CMD_PLOGI) ||
3365 (cmd == ELS_CMD_PRLI) ||
3366 (cmd == ELS_CMD_NVMEPRLI)) {
3369 } else if (cmd == ELS_CMD_FDISC) {
3370 /* FDISC retry policy */
3372 if (cmdiocb->retry >= 32)
3378 case LSRJT_LOGICAL_ERR:
3379 /* There are some cases where switches return this
3380 * error when they are not ready and should be returning
3381 * Logical Busy. We should delay every time.
3383 if (cmd == ELS_CMD_FDISC &&
3384 stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
3390 case LSRJT_PROTOCOL_ERR:
3391 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
3392 (cmd == ELS_CMD_FDISC) &&
3393 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
3394 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
3396 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3397 "0122 FDISC Failed (x%x). "
3398 "Fabric Detected Bad WWN\n",
3399 stat.un.lsRjtError);
3400 lpfc_vport_set_state(vport,
3401 FC_VPORT_FABRIC_REJ_WWN);
3404 case LSRJT_VENDOR_UNIQUE:
3405 if ((stat.un.b.vendorUnique == 0x45) &&
3406 (cmd == ELS_CMD_FLOGI)) {
3413 case IOSTAT_INTERMED_RSP:
3421 if (did == FDMI_DID)
3424 if ((cmd == ELS_CMD_FLOGI) &&
3425 (phba->fc_topology != LPFC_TOPOLOGY_LOOP) &&
3426 !lpfc_error_lost_link(irsp)) {
3427 /* FLOGI retry policy */
3429 /* retry FLOGI forever */
3430 if (phba->link_flag != LS_LOOPBACK_MODE)
3435 if (cmdiocb->retry >= 100)
3437 else if (cmdiocb->retry >= 32)
3439 } else if ((cmd == ELS_CMD_FDISC) && !lpfc_error_lost_link(irsp)) {
3440 /* retry FDISCs every second up to devloss */
3442 maxretry = vport->cfg_devloss_tmo;
3447 if (maxretry && (cmdiocb->retry >= maxretry)) {
3448 phba->fc_stat.elsRetryExceeded++;
3452 if ((vport->load_flag & FC_UNLOADING) != 0)
3457 if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) {
3458 /* Stop retrying PLOGI and FDISC if in FCF discovery */
3459 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
3460 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3461 "2849 Stop retry ELS command "
3462 "x%x to remote NPORT x%x, "
3463 "Data: x%x x%x\n", cmd, did,
3464 cmdiocb->retry, delay);
3469 /* Retry ELS command <elsCmd> to remote NPORT <did> */
3470 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3471 "0107 Retry ELS command x%x to remote "
3472 "NPORT x%x Data: x%x x%x\n",
3473 cmd, did, cmdiocb->retry, delay);
3475 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
3476 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
3477 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
3478 IOERR_NO_RESOURCES))) {
3479 /* Don't reset timer for no resources */
3481 /* If discovery / RSCN timer is running, reset it */
3482 if (timer_pending(&vport->fc_disctmo) ||
3483 (vport->fc_flag & FC_RSCN_MODE))
3484 lpfc_set_disctmo(vport);
3487 phba->fc_stat.elsXmitRetry++;
3488 if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) {
3489 phba->fc_stat.elsDelayRetry++;
3490 ndlp->nlp_retry = cmdiocb->retry;
3492 /* delay is specified in milliseconds */
3493 mod_timer(&ndlp->nlp_delayfunc,
3494 jiffies + msecs_to_jiffies(delay));
3495 spin_lock_irq(shost->host_lock);
3496 ndlp->nlp_flag |= NLP_DELAY_TMO;
3497 spin_unlock_irq(shost->host_lock);
3499 ndlp->nlp_prev_state = ndlp->nlp_state;
3500 if ((cmd == ELS_CMD_PRLI) ||
3501 (cmd == ELS_CMD_NVMEPRLI))
3502 lpfc_nlp_set_state(vport, ndlp,
3503 NLP_STE_PRLI_ISSUE);
3505 lpfc_nlp_set_state(vport, ndlp,
3507 ndlp->nlp_last_elscmd = cmd;
3513 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
3516 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
3519 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
3520 ndlp->nlp_prev_state = ndlp->nlp_state;
3521 lpfc_nlp_set_state(vport, ndlp,
3522 NLP_STE_PLOGI_ISSUE);
3524 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
3527 ndlp->nlp_prev_state = ndlp->nlp_state;
3528 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
3529 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
3532 case ELS_CMD_NVMEPRLI:
3533 ndlp->nlp_prev_state = ndlp->nlp_state;
3534 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
3535 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
3538 ndlp->nlp_prev_state = ndlp->nlp_state;
3539 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
3540 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
3544 /* No retry ELS command <elsCmd> to remote NPORT <did> */
3546 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3547 "0137 No retry ELS command x%x to remote "
3548 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
3549 cmd, did, irsp->ulpStatus,
3550 irsp->un.ulpWord[4]);
3553 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3554 "0108 No retry ELS command x%x to remote "
3555 "NPORT x%x Retried:%d Error:x%x/%x\n",
3556 cmd, did, cmdiocb->retry, irsp->ulpStatus,
3557 irsp->un.ulpWord[4]);
3563 * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
3564 * @phba: pointer to lpfc hba data structure.
3565 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
3567 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
3568 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
3569 * checks to see whether there is a lpfc DMA buffer associated with the
3570 * response of the command IOCB. If so, it will be released before releasing
3571 * the lpfc DMA buffer associated with the IOCB itself.
3574 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3577 lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
3579 struct lpfc_dmabuf *buf_ptr;
3581 /* Free the response before processing the command. */
3582 if (!list_empty(&buf_ptr1->list)) {
3583 list_remove_head(&buf_ptr1->list, buf_ptr,
3586 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3589 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
3595 * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
3596 * @phba: pointer to lpfc hba data structure.
3597 * @buf_ptr: pointer to the lpfc dma buffer data structure.
3599 * This routine releases the lpfc Direct Memory Access (DMA) buffer
3600 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
3604 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3607 lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
3609 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3615 * lpfc_els_free_iocb - Free a command iocb and its associated resources
3616 * @phba: pointer to lpfc hba data structure.
3617 * @elsiocb: pointer to lpfc els command iocb data structure.
3619 * This routine frees a command IOCB and its associated resources. The
3620 * command IOCB data structure contains the reference to various associated
3621 * resources, these fields must be set to NULL if the associated reference
3623 * context1 - reference to ndlp
3624 * context2 - reference to cmd
3625 * context2->next - reference to rsp
3626 * context3 - reference to bpl
3628 * It first properly decrements the reference count held on ndlp for the
3629 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
3630 * set, it invokes the lpfc_els_free_data() routine to release the Direct
3631 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
3632 * adds the DMA buffer the @phba data structure for the delayed release.
3633 * If reference to the Buffer Pointer List (BPL) is present, the
3634 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
3635 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
3636 * invoked to release the IOCB data structure back to @phba IOCBQ list.
3639 * 0 - Success (currently, always return 0)
3642 lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
3644 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
3645 struct lpfc_nodelist *ndlp;
3647 ndlp = (struct lpfc_nodelist *)elsiocb->context1;
3649 if (ndlp->nlp_flag & NLP_DEFER_RM) {
3652 /* If the ndlp is not being used by another discovery
3655 if (!lpfc_nlp_not_used(ndlp)) {
3656 /* If ndlp is being used by another discovery
3657 * thread, just clear NLP_DEFER_RM
3659 ndlp->nlp_flag &= ~NLP_DEFER_RM;
3664 elsiocb->context1 = NULL;
3666 /* context2 = cmd, context2->next = rsp, context3 = bpl */
3667 if (elsiocb->context2) {
3668 if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
3669 /* Firmware could still be in progress of DMAing
3670 * payload, so don't free data buffer till after
3673 elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
3674 buf_ptr = elsiocb->context2;
3675 elsiocb->context2 = NULL;
3678 spin_lock_irq(&phba->hbalock);
3679 if (!list_empty(&buf_ptr->list)) {
3680 list_remove_head(&buf_ptr->list,
3681 buf_ptr1, struct lpfc_dmabuf,
3683 INIT_LIST_HEAD(&buf_ptr1->list);
3684 list_add_tail(&buf_ptr1->list,
3688 INIT_LIST_HEAD(&buf_ptr->list);
3689 list_add_tail(&buf_ptr->list, &phba->elsbuf);
3691 spin_unlock_irq(&phba->hbalock);
3694 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
3695 lpfc_els_free_data(phba, buf_ptr1);
3696 elsiocb->context2 = NULL;
3700 if (elsiocb->context3) {
3701 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
3702 lpfc_els_free_bpl(phba, buf_ptr);
3703 elsiocb->context3 = NULL;
3705 lpfc_sli_release_iocbq(phba, elsiocb);
3710 * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
3711 * @phba: pointer to lpfc hba data structure.
3712 * @cmdiocb: pointer to lpfc command iocb data structure.
3713 * @rspiocb: pointer to lpfc response iocb data structure.
3715 * This routine is the completion callback function to the Logout (LOGO)
3716 * Accept (ACC) Response ELS command. This routine is invoked to indicate
3717 * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
3718 * release the ndlp if it has the last reference remaining (reference count
3719 * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
3720 * field to NULL to inform the following lpfc_els_free_iocb() routine no
3721 * ndlp reference count needs to be decremented. Otherwise, the ndlp
3722 * reference use-count shall be decremented by the lpfc_els_free_iocb()
3723 * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
3724 * IOCB data structure.
3727 lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3728 struct lpfc_iocbq *rspiocb)
3730 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3731 struct lpfc_vport *vport = cmdiocb->vport;
3734 irsp = &rspiocb->iocb;
3735 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3736 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
3737 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
3738 /* ACC to LOGO completes to NPort <nlp_DID> */
3739 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3740 "0109 ACC to LOGO completes to NPort x%x "
3741 "Data: x%x x%x x%x\n",
3742 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3745 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
3746 /* NPort Recovery mode or node is just allocated */
3747 if (!lpfc_nlp_not_used(ndlp)) {
3748 /* If the ndlp is being used by another discovery
3749 * thread, just unregister the RPI.
3751 lpfc_unreg_rpi(vport, ndlp);
3753 /* Indicate the node has already released, should
3754 * not reference to it from within lpfc_els_free_iocb.
3756 cmdiocb->context1 = NULL;
3761 * The driver received a LOGO from the rport and has ACK'd it.
3762 * At this point, the driver is done so release the IOCB
3764 lpfc_els_free_iocb(phba, cmdiocb);
3768 * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
3769 * @phba: pointer to lpfc hba data structure.
3770 * @pmb: pointer to the driver internal queue element for mailbox command.
3772 * This routine is the completion callback function for unregister default
3773 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
3774 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
3775 * decrements the ndlp reference count held for this completion callback
3776 * function. After that, it invokes the lpfc_nlp_not_used() to check
3777 * whether there is only one reference left on the ndlp. If so, it will
3778 * perform one more decrement and trigger the release of the ndlp.
3781 lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3783 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
3784 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
3786 pmb->context1 = NULL;
3787 pmb->context2 = NULL;
3789 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3791 mempool_free(pmb, phba->mbox_mem_pool);
3793 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
3794 "0006 rpi%x DID:%x flg:%x %d map:%x %p\n",
3795 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
3796 kref_read(&ndlp->kref),
3797 ndlp->nlp_usg_map, ndlp);
3798 if (NLP_CHK_NODE_ACT(ndlp)) {
3800 /* This is the end of the default RPI cleanup logic for
3801 * this ndlp. If no other discovery threads are using
3802 * this ndlp, free all resources associated with it.
3804 lpfc_nlp_not_used(ndlp);
3806 lpfc_drop_node(ndlp->vport, ndlp);
3814 * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
3815 * @phba: pointer to lpfc hba data structure.
3816 * @cmdiocb: pointer to lpfc command iocb data structure.
3817 * @rspiocb: pointer to lpfc response iocb data structure.
3819 * This routine is the completion callback function for ELS Response IOCB
3820 * command. In normal case, this callback function just properly sets the
3821 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
3822 * field in the command IOCB is not NULL, the referred mailbox command will
3823 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
3824 * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
3825 * link down event occurred during the discovery, the lpfc_nlp_not_used()
3826 * routine shall be invoked trying to release the ndlp if no other threads
3827 * are currently referring it.
3830 lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3831 struct lpfc_iocbq *rspiocb)
3833 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3834 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
3835 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
3838 LPFC_MBOXQ_t *mbox = NULL;
3839 struct lpfc_dmabuf *mp = NULL;
3840 uint32_t ls_rjt = 0;
3842 irsp = &rspiocb->iocb;
3844 if (cmdiocb->context_un.mbox)
3845 mbox = cmdiocb->context_un.mbox;
3847 /* First determine if this is a LS_RJT cmpl. Note, this callback
3848 * function can have cmdiocb->contest1 (ndlp) field set to NULL.
3850 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
3851 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3852 (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) {
3853 /* A LS_RJT associated with Default RPI cleanup has its own
3854 * separate code path.
3856 if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
3860 /* Check to see if link went down during discovery */
3861 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) {
3863 mp = (struct lpfc_dmabuf *) mbox->context1;
3865 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3868 mempool_free(mbox, phba->mbox_mem_pool);
3870 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3871 (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
3872 if (lpfc_nlp_not_used(ndlp)) {
3874 /* Indicate the node has already released,
3875 * should not reference to it from within
3876 * the routine lpfc_els_free_iocb.
3878 cmdiocb->context1 = NULL;
3883 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3884 "ELS rsp cmpl: status:x%x/x%x did:x%x",
3885 irsp->ulpStatus, irsp->un.ulpWord[4],
3886 cmdiocb->iocb.un.elsreq64.remoteID);
3887 /* ELS response tag <ulpIoTag> completes */
3888 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3889 "0110 ELS response tag x%x completes "
3890 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
3891 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
3892 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
3893 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3896 if ((rspiocb->iocb.ulpStatus == 0)
3897 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
3898 lpfc_unreg_rpi(vport, ndlp);
3899 /* Increment reference count to ndlp to hold the
3900 * reference to ndlp for the callback function.
3902 mbox->context2 = lpfc_nlp_get(ndlp);
3903 mbox->vport = vport;
3904 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
3905 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
3906 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
3909 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
3910 ndlp->nlp_prev_state = ndlp->nlp_state;
3911 lpfc_nlp_set_state(vport, ndlp,
3912 NLP_STE_REG_LOGIN_ISSUE);
3915 ndlp->nlp_flag |= NLP_REG_LOGIN_SEND;
3916 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
3917 != MBX_NOT_FINISHED)
3920 /* Decrement the ndlp reference count we
3921 * set for this failed mailbox command.
3924 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
3926 /* ELS rsp: Cannot issue reg_login for <NPortid> */
3927 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3928 "0138 ELS rsp: Cannot issue reg_login for x%x "
3929 "Data: x%x x%x x%x\n",
3930 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3933 if (lpfc_nlp_not_used(ndlp)) {
3935 /* Indicate node has already been released,
3936 * should not reference to it from within
3937 * the routine lpfc_els_free_iocb.
3939 cmdiocb->context1 = NULL;
3942 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
3943 if (!lpfc_error_lost_link(irsp) &&
3944 ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
3945 if (lpfc_nlp_not_used(ndlp)) {
3947 /* Indicate node has already been
3948 * released, should not reference
3949 * to it from within the routine
3950 * lpfc_els_free_iocb.
3952 cmdiocb->context1 = NULL;
3956 mp = (struct lpfc_dmabuf *) mbox->context1;
3958 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3961 mempool_free(mbox, phba->mbox_mem_pool);
3964 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
3965 spin_lock_irq(shost->host_lock);
3966 ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI);
3967 spin_unlock_irq(shost->host_lock);
3969 /* If the node is not being used by another discovery thread,
3970 * and we are sending a reject, we are done with it.
3971 * Release driver reference count here and free associated
3975 if (lpfc_nlp_not_used(ndlp))
3976 /* Indicate node has already been released,
3977 * should not reference to it from within
3978 * the routine lpfc_els_free_iocb.
3980 cmdiocb->context1 = NULL;
3984 lpfc_els_free_iocb(phba, cmdiocb);
3989 * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
3990 * @vport: pointer to a host virtual N_Port data structure.
3991 * @flag: the els command code to be accepted.
3992 * @oldiocb: pointer to the original lpfc command iocb data structure.
3993 * @ndlp: pointer to a node-list data structure.
3994 * @mbox: pointer to the driver internal queue element for mailbox command.
3996 * This routine prepares and issues an Accept (ACC) response IOCB
3997 * command. It uses the @flag to properly set up the IOCB field for the
3998 * specific ACC response command to be issued and invokes the
3999 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
4000 * @mbox pointer is passed in, it will be put into the context_un.mbox
4001 * field of the IOCB for the completion callback function to issue the
4002 * mailbox command to the HBA later when callback is invoked.
4004 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4005 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4006 * will be stored into the context1 field of the IOCB for the completion
4007 * callback function to the corresponding response ELS IOCB command.
4010 * 0 - Successfully issued acc response
4011 * 1 - Failed to issue acc response
4014 lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
4015 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
4018 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4019 struct lpfc_hba *phba = vport->phba;
4022 struct lpfc_iocbq *elsiocb;
4024 struct serv_parm *sp;
4027 ELS_PKT *els_pkt_ptr;
4029 oldcmd = &oldiocb->iocb;
4033 cmdsize = sizeof(uint32_t);
4034 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
4035 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
4037 spin_lock_irq(shost->host_lock);
4038 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
4039 spin_unlock_irq(shost->host_lock);
4043 icmd = &elsiocb->iocb;
4044 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4045 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4046 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4047 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4048 pcmd += sizeof(uint32_t);
4050 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4051 "Issue ACC: did:x%x flg:x%x",
4052 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4056 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
4057 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
4058 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
4062 icmd = &elsiocb->iocb;
4063 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4064 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4065 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4068 elsiocb->context_un.mbox = mbox;
4070 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4071 pcmd += sizeof(uint32_t);
4072 sp = (struct serv_parm *)pcmd;
4074 if (flag == ELS_CMD_FLOGI) {
4075 /* Copy the received service parameters back */
4076 memcpy(sp, &phba->fc_fabparam,
4077 sizeof(struct serv_parm));
4079 /* Clear the F_Port bit */
4082 /* Mark all class service parameters as invalid */
4083 sp->cls1.classValid = 0;
4084 sp->cls2.classValid = 0;
4085 sp->cls3.classValid = 0;
4086 sp->cls4.classValid = 0;
4088 /* Copy our worldwide names */
4089 memcpy(&sp->portName, &vport->fc_sparam.portName,
4090 sizeof(struct lpfc_name));
4091 memcpy(&sp->nodeName, &vport->fc_sparam.nodeName,
4092 sizeof(struct lpfc_name));
4094 memcpy(pcmd, &vport->fc_sparam,
4095 sizeof(struct serv_parm));
4097 sp->cmn.valid_vendor_ver_level = 0;
4098 memset(sp->un.vendorVersion, 0,
4099 sizeof(sp->un.vendorVersion));
4101 /* If our firmware supports this feature, convey that
4102 * info to the target using the vendor specific field.
4104 if (phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) {
4105 sp->cmn.valid_vendor_ver_level = 1;
4106 sp->un.vv.vid = cpu_to_be32(LPFC_VV_EMLX_ID);
4108 cpu_to_be32(LPFC_VV_SUPPRESS_RSP);
4112 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4113 "Issue ACC FLOGI/PLOGI: did:x%x flg:x%x",
4114 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4117 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
4118 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
4119 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
4123 icmd = &elsiocb->iocb;
4124 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4125 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4126 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4128 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
4129 sizeof(uint32_t) + sizeof(PRLO));
4130 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
4131 els_pkt_ptr = (ELS_PKT *) pcmd;
4132 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
4134 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4135 "Issue ACC PRLO: did:x%x flg:x%x",
4136 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4141 /* Xmit ELS ACC response tag <ulpIoTag> */
4142 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4143 "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
4144 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x "
4146 elsiocb->iotag, elsiocb->iocb.ulpContext,
4147 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4148 ndlp->nlp_rpi, vport->fc_flag);
4149 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
4150 spin_lock_irq(shost->host_lock);
4151 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED ||
4152 ndlp->nlp_flag & NLP_REG_LOGIN_SEND))
4153 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
4154 spin_unlock_irq(shost->host_lock);
4155 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
4157 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4160 phba->fc_stat.elsXmitACC++;
4161 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4162 if (rc == IOCB_ERROR) {
4163 lpfc_els_free_iocb(phba, elsiocb);
4170 * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command
4171 * @vport: pointer to a virtual N_Port data structure.
4173 * @oldiocb: pointer to the original lpfc command iocb data structure.
4174 * @ndlp: pointer to a node-list data structure.
4175 * @mbox: pointer to the driver internal queue element for mailbox command.
4177 * This routine prepares and issue an Reject (RJT) response IOCB
4178 * command. If a @mbox pointer is passed in, it will be put into the
4179 * context_un.mbox field of the IOCB for the completion callback function
4180 * to issue to the HBA later.
4182 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4183 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4184 * will be stored into the context1 field of the IOCB for the completion
4185 * callback function to the reject response ELS IOCB command.
4188 * 0 - Successfully issued reject response
4189 * 1 - Failed to issue reject response
4192 lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
4193 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
4196 struct lpfc_hba *phba = vport->phba;
4199 struct lpfc_iocbq *elsiocb;
4204 cmdsize = 2 * sizeof(uint32_t);
4205 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4206 ndlp->nlp_DID, ELS_CMD_LS_RJT);
4210 icmd = &elsiocb->iocb;
4211 oldcmd = &oldiocb->iocb;
4212 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4213 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4214 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4216 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
4217 pcmd += sizeof(uint32_t);
4218 *((uint32_t *) (pcmd)) = rejectError;
4221 elsiocb->context_un.mbox = mbox;
4223 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
4224 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4225 "0129 Xmit ELS RJT x%x response tag x%x "
4226 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
4228 rejectError, elsiocb->iotag,
4229 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
4230 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
4231 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4232 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
4233 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
4235 phba->fc_stat.elsXmitLSRJT++;
4236 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4237 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4239 if (rc == IOCB_ERROR) {
4240 lpfc_els_free_iocb(phba, elsiocb);
4247 * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
4248 * @vport: pointer to a virtual N_Port data structure.
4249 * @oldiocb: pointer to the original lpfc command iocb data structure.
4250 * @ndlp: pointer to a node-list data structure.
4252 * This routine prepares and issues an Accept (ACC) response to Address
4253 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
4254 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
4256 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4257 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4258 * will be stored into the context1 field of the IOCB for the completion
4259 * callback function to the ADISC Accept response ELS IOCB command.
4262 * 0 - Successfully issued acc adisc response
4263 * 1 - Failed to issue adisc acc response
4266 lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
4267 struct lpfc_nodelist *ndlp)
4269 struct lpfc_hba *phba = vport->phba;
4271 IOCB_t *icmd, *oldcmd;
4272 struct lpfc_iocbq *elsiocb;
4277 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
4278 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4279 ndlp->nlp_DID, ELS_CMD_ACC);
4283 icmd = &elsiocb->iocb;
4284 oldcmd = &oldiocb->iocb;
4285 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4286 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4288 /* Xmit ADISC ACC response tag <ulpIoTag> */
4289 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4290 "0130 Xmit ADISC ACC response iotag x%x xri: "
4291 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
4292 elsiocb->iotag, elsiocb->iocb.ulpContext,
4293 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4295 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4297 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4298 pcmd += sizeof(uint32_t);
4300 ap = (ADISC *) (pcmd);
4301 ap->hardAL_PA = phba->fc_pref_ALPA;
4302 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
4303 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
4304 ap->DID = be32_to_cpu(vport->fc_myDID);
4306 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4307 "Issue ACC ADISC: did:x%x flg:x%x",
4308 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4310 phba->fc_stat.elsXmitACC++;
4311 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4312 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4313 if (rc == IOCB_ERROR) {
4314 lpfc_els_free_iocb(phba, elsiocb);
4321 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
4322 * @vport: pointer to a virtual N_Port data structure.
4323 * @oldiocb: pointer to the original lpfc command iocb data structure.
4324 * @ndlp: pointer to a node-list data structure.
4326 * This routine prepares and issues an Accept (ACC) response to Process
4327 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
4328 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
4330 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4331 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4332 * will be stored into the context1 field of the IOCB for the completion
4333 * callback function to the PRLI Accept response ELS IOCB command.
4336 * 0 - Successfully issued acc prli response
4337 * 1 - Failed to issue acc prli response
4340 lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
4341 struct lpfc_nodelist *ndlp)
4343 struct lpfc_hba *phba = vport->phba;
4345 struct lpfc_nvme_prli *npr_nvme;
4349 struct lpfc_iocbq *elsiocb;
4352 uint32_t prli_fc4_req, *req_payload;
4353 struct lpfc_dmabuf *req_buf;
4357 /* Need the incoming PRLI payload to determine if the ACC is for an
4358 * FC4 or NVME PRLI type. The PRLI type is at word 1.
4360 req_buf = (struct lpfc_dmabuf *)oldiocb->context2;
4361 req_payload = (((uint32_t *)req_buf->virt) + 1);
4363 /* PRLI type payload is at byte 3 for FCP or NVME. */
4364 prli_fc4_req = be32_to_cpu(*req_payload);
4365 prli_fc4_req = (prli_fc4_req >> 24) & 0xff;
4366 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4367 "6127 PRLI_ACC: Req Type x%x, Word1 x%08x\n",
4368 prli_fc4_req, *((uint32_t *)req_payload));
4370 if (prli_fc4_req == PRLI_FCP_TYPE) {
4371 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
4372 elsrspcmd = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
4373 } else if (prli_fc4_req & PRLI_NVME_TYPE) {
4374 cmdsize = sizeof(uint32_t) + sizeof(struct lpfc_nvme_prli);
4375 elsrspcmd = (ELS_CMD_ACC | (ELS_CMD_NVMEPRLI & ~ELS_RSP_MASK));
4380 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4381 ndlp->nlp_DID, elsrspcmd);
4385 icmd = &elsiocb->iocb;
4386 oldcmd = &oldiocb->iocb;
4387 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4388 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4390 /* Xmit PRLI ACC response tag <ulpIoTag> */
4391 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4392 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
4393 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
4394 elsiocb->iotag, elsiocb->iocb.ulpContext,
4395 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4397 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4398 memset(pcmd, 0, cmdsize);
4400 *((uint32_t *)(pcmd)) = elsrspcmd;
4401 pcmd += sizeof(uint32_t);
4403 /* For PRLI, remainder of payload is PRLI parameter page */
4406 if (prli_fc4_req == PRLI_FCP_TYPE) {
4408 * If the remote port is a target and our firmware version
4409 * is 3.20 or later, set the following bits for FC-TAPE
4412 npr = (PRLI *) pcmd;
4413 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
4414 (vpd->rev.feaLevelHigh >= 0x02)) {
4415 npr->ConfmComplAllowed = 1;
4417 npr->TaskRetryIdReq = 1;
4419 npr->acceptRspCode = PRLI_REQ_EXECUTED;
4420 npr->estabImagePair = 1;
4421 npr->readXferRdyDis = 1;
4422 npr->ConfmComplAllowed = 1;
4423 npr->prliType = PRLI_FCP_TYPE;
4424 npr->initiatorFunc = 1;
4425 } else if (prli_fc4_req & PRLI_NVME_TYPE) {
4426 /* Respond with an NVME PRLI Type */
4427 npr_nvme = (struct lpfc_nvme_prli *) pcmd;
4428 bf_set(prli_type_code, npr_nvme, PRLI_NVME_TYPE);
4429 bf_set(prli_estabImagePair, npr_nvme, 0); /* Should be 0 */
4430 bf_set(prli_acc_rsp_code, npr_nvme, PRLI_REQ_EXECUTED);
4431 if (phba->nvmet_support) {
4432 bf_set(prli_tgt, npr_nvme, 1);
4433 bf_set(prli_disc, npr_nvme, 1);
4434 if (phba->cfg_nvme_enable_fb) {
4435 bf_set(prli_fba, npr_nvme, 1);
4437 /* TBD. Target mode needs to post buffers
4438 * that support the configured first burst
4441 bf_set(prli_fb_sz, npr_nvme,
4442 phba->cfg_nvmet_fb_size);
4445 bf_set(prli_init, npr_nvme, 1);
4448 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
4449 "6015 NVME issue PRLI ACC word1 x%08x "
4450 "word4 x%08x word5 x%08x flag x%x, "
4451 "fcp_info x%x nlp_type x%x\n",
4452 npr_nvme->word1, npr_nvme->word4,
4453 npr_nvme->word5, ndlp->nlp_flag,
4454 ndlp->nlp_fcp_info, ndlp->nlp_type);
4455 npr_nvme->word1 = cpu_to_be32(npr_nvme->word1);
4456 npr_nvme->word4 = cpu_to_be32(npr_nvme->word4);
4457 npr_nvme->word5 = cpu_to_be32(npr_nvme->word5);
4459 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4460 "6128 Unknown FC_TYPE x%x x%x ndlp x%06x\n",
4461 prli_fc4_req, ndlp->nlp_fc4_type,
4464 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4465 "Issue ACC PRLI: did:x%x flg:x%x",
4466 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4468 phba->fc_stat.elsXmitACC++;
4469 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4471 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4472 if (rc == IOCB_ERROR) {
4473 lpfc_els_free_iocb(phba, elsiocb);
4480 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
4481 * @vport: pointer to a virtual N_Port data structure.
4482 * @format: rnid command format.
4483 * @oldiocb: pointer to the original lpfc command iocb data structure.
4484 * @ndlp: pointer to a node-list data structure.
4486 * This routine issues a Request Node Identification Data (RNID) Accept
4487 * (ACC) response. It constructs the RNID ACC response command according to
4488 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
4489 * issue the response. Note that this command does not need to hold the ndlp
4490 * reference count for the callback. So, the ndlp reference count taken by
4491 * the lpfc_prep_els_iocb() routine is put back and the context1 field of
4492 * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
4493 * there is no ndlp reference available.
4495 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4496 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4497 * will be stored into the context1 field of the IOCB for the completion
4498 * callback function. However, for the RNID Accept Response ELS command,
4499 * this is undone later by this routine after the IOCB is allocated.
4502 * 0 - Successfully issued acc rnid response
4503 * 1 - Failed to issue acc rnid response
4506 lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
4507 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
4509 struct lpfc_hba *phba = vport->phba;
4511 IOCB_t *icmd, *oldcmd;
4512 struct lpfc_iocbq *elsiocb;
4517 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
4518 + (2 * sizeof(struct lpfc_name));
4520 cmdsize += sizeof(RNID_TOP_DISC);
4522 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4523 ndlp->nlp_DID, ELS_CMD_ACC);
4527 icmd = &elsiocb->iocb;
4528 oldcmd = &oldiocb->iocb;
4529 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4530 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4532 /* Xmit RNID ACC response tag <ulpIoTag> */
4533 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4534 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
4535 elsiocb->iotag, elsiocb->iocb.ulpContext);
4536 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4537 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4538 pcmd += sizeof(uint32_t);
4540 memset(pcmd, 0, sizeof(RNID));
4541 rn = (RNID *) (pcmd);
4542 rn->Format = format;
4543 rn->CommonLen = (2 * sizeof(struct lpfc_name));
4544 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
4545 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
4548 rn->SpecificLen = 0;
4550 case RNID_TOPOLOGY_DISC:
4551 rn->SpecificLen = sizeof(RNID_TOP_DISC);
4552 memcpy(&rn->un.topologyDisc.portName,
4553 &vport->fc_portname, sizeof(struct lpfc_name));
4554 rn->un.topologyDisc.unitType = RNID_HBA;
4555 rn->un.topologyDisc.physPort = 0;
4556 rn->un.topologyDisc.attachedNodes = 0;
4560 rn->SpecificLen = 0;
4564 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4565 "Issue ACC RNID: did:x%x flg:x%x",
4566 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4568 phba->fc_stat.elsXmitACC++;
4569 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4571 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4572 if (rc == IOCB_ERROR) {
4573 lpfc_els_free_iocb(phba, elsiocb);
4580 * lpfc_els_clear_rrq - Clear the rq that this rrq describes.
4581 * @vport: pointer to a virtual N_Port data structure.
4582 * @iocb: pointer to the lpfc command iocb data structure.
4583 * @ndlp: pointer to a node-list data structure.
4588 lpfc_els_clear_rrq(struct lpfc_vport *vport,
4589 struct lpfc_iocbq *iocb, struct lpfc_nodelist *ndlp)
4591 struct lpfc_hba *phba = vport->phba;
4596 struct lpfc_node_rrq *prrq;
4599 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) iocb->context2)->virt);
4600 pcmd += sizeof(uint32_t);
4601 rrq = (struct RRQ *)pcmd;
4602 rrq->rrq_exchg = be32_to_cpu(rrq->rrq_exchg);
4603 rxid = bf_get(rrq_rxid, rrq);
4605 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4606 "2883 Clear RRQ for SID:x%x OXID:x%x RXID:x%x"
4608 be32_to_cpu(bf_get(rrq_did, rrq)),
4609 bf_get(rrq_oxid, rrq),
4611 iocb->iotag, iocb->iocb.ulpContext);
4613 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4614 "Clear RRQ: did:x%x flg:x%x exchg:x%.08x",
4615 ndlp->nlp_DID, ndlp->nlp_flag, rrq->rrq_exchg);
4616 if (vport->fc_myDID == be32_to_cpu(bf_get(rrq_did, rrq)))
4617 xri = bf_get(rrq_oxid, rrq);
4620 prrq = lpfc_get_active_rrq(vport, xri, ndlp->nlp_DID);
4622 lpfc_clr_rrq_active(phba, xri, prrq);
4627 * lpfc_els_rsp_echo_acc - Issue echo acc response
4628 * @vport: pointer to a virtual N_Port data structure.
4629 * @data: pointer to echo data to return in the accept.
4630 * @oldiocb: pointer to the original lpfc command iocb data structure.
4631 * @ndlp: pointer to a node-list data structure.
4634 * 0 - Successfully issued acc echo response
4635 * 1 - Failed to issue acc echo response
4638 lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data,
4639 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
4641 struct lpfc_hba *phba = vport->phba;
4642 struct lpfc_iocbq *elsiocb;
4647 cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len;
4649 /* The accumulated length can exceed the BPL_SIZE. For
4650 * now, use this as the limit
4652 if (cmdsize > LPFC_BPL_SIZE)
4653 cmdsize = LPFC_BPL_SIZE;
4654 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4655 ndlp->nlp_DID, ELS_CMD_ACC);
4659 elsiocb->iocb.ulpContext = oldiocb->iocb.ulpContext; /* Xri / rx_id */
4660 elsiocb->iocb.unsli3.rcvsli3.ox_id = oldiocb->iocb.unsli3.rcvsli3.ox_id;
4662 /* Xmit ECHO ACC response tag <ulpIoTag> */
4663 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4664 "2876 Xmit ECHO ACC response tag x%x xri x%x\n",
4665 elsiocb->iotag, elsiocb->iocb.ulpContext);
4666 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4667 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4668 pcmd += sizeof(uint32_t);
4669 memcpy(pcmd, data, cmdsize - sizeof(uint32_t));
4671 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4672 "Issue ACC ECHO: did:x%x flg:x%x",
4673 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4675 phba->fc_stat.elsXmitACC++;
4676 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4678 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4679 if (rc == IOCB_ERROR) {
4680 lpfc_els_free_iocb(phba, elsiocb);
4687 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
4688 * @vport: pointer to a host virtual N_Port data structure.
4690 * This routine issues Address Discover (ADISC) ELS commands to those
4691 * N_Ports which are in node port recovery state and ADISC has not been issued
4692 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
4693 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
4694 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
4695 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
4696 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
4697 * IOCBs quit for later pick up. On the other hand, after walking through
4698 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
4699 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
4700 * no more ADISC need to be sent.
4703 * The number of N_Ports with adisc issued.
4706 lpfc_els_disc_adisc(struct lpfc_vport *vport)
4708 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4709 struct lpfc_nodelist *ndlp, *next_ndlp;
4712 /* go thru NPR nodes and issue any remaining ELS ADISCs */
4713 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
4714 if (!NLP_CHK_NODE_ACT(ndlp))
4716 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
4717 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
4718 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
4719 spin_lock_irq(shost->host_lock);
4720 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
4721 spin_unlock_irq(shost->host_lock);
4722 ndlp->nlp_prev_state = ndlp->nlp_state;
4723 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
4724 lpfc_issue_els_adisc(vport, ndlp, 0);
4726 vport->num_disc_nodes++;
4727 if (vport->num_disc_nodes >=
4728 vport->cfg_discovery_threads) {
4729 spin_lock_irq(shost->host_lock);
4730 vport->fc_flag |= FC_NLP_MORE;
4731 spin_unlock_irq(shost->host_lock);
4736 if (sentadisc == 0) {
4737 spin_lock_irq(shost->host_lock);
4738 vport->fc_flag &= ~FC_NLP_MORE;
4739 spin_unlock_irq(shost->host_lock);
4745 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
4746 * @vport: pointer to a host virtual N_Port data structure.
4748 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
4749 * which are in node port recovery state, with a @vport. Each time an ELS
4750 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
4751 * the per @vport number of discover count (num_disc_nodes) shall be
4752 * incremented. If the num_disc_nodes reaches a pre-configured threshold
4753 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
4754 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
4755 * later pick up. On the other hand, after walking through all the ndlps with
4756 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
4757 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
4758 * PLOGI need to be sent.
4761 * The number of N_Ports with plogi issued.
4764 lpfc_els_disc_plogi(struct lpfc_vport *vport)
4766 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4767 struct lpfc_nodelist *ndlp, *next_ndlp;
4770 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
4771 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
4772 if (!NLP_CHK_NODE_ACT(ndlp))
4774 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
4775 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
4776 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
4777 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
4778 ndlp->nlp_prev_state = ndlp->nlp_state;
4779 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
4780 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
4782 vport->num_disc_nodes++;
4783 if (vport->num_disc_nodes >=
4784 vport->cfg_discovery_threads) {
4785 spin_lock_irq(shost->host_lock);
4786 vport->fc_flag |= FC_NLP_MORE;
4787 spin_unlock_irq(shost->host_lock);
4793 lpfc_set_disctmo(vport);
4796 spin_lock_irq(shost->host_lock);
4797 vport->fc_flag &= ~FC_NLP_MORE;
4798 spin_unlock_irq(shost->host_lock);
4804 lpfc_rdp_res_link_service(struct fc_rdp_link_service_desc *desc,
4808 desc->tag = cpu_to_be32(RDP_LINK_SERVICE_DESC_TAG);
4809 desc->payload.els_req = word0;
4810 desc->length = cpu_to_be32(sizeof(desc->payload));
4812 return sizeof(struct fc_rdp_link_service_desc);
4816 lpfc_rdp_res_sfp_desc(struct fc_rdp_sfp_desc *desc,
4817 uint8_t *page_a0, uint8_t *page_a2)
4819 uint16_t wavelength;
4820 uint16_t temperature;
4826 struct sff_trasnceiver_codes_byte4 *trasn_code_byte4;
4827 struct sff_trasnceiver_codes_byte5 *trasn_code_byte5;
4829 desc->tag = cpu_to_be32(RDP_SFP_DESC_TAG);
4831 trasn_code_byte4 = (struct sff_trasnceiver_codes_byte4 *)
4832 &page_a0[SSF_TRANSCEIVER_CODE_B4];
4833 trasn_code_byte5 = (struct sff_trasnceiver_codes_byte5 *)
4834 &page_a0[SSF_TRANSCEIVER_CODE_B5];
4836 if ((trasn_code_byte4->fc_sw_laser) ||
4837 (trasn_code_byte5->fc_sw_laser_sl) ||
4838 (trasn_code_byte5->fc_sw_laser_sn)) { /* check if its short WL */
4839 flag |= (SFP_FLAG_PT_SWLASER << SFP_FLAG_PT_SHIFT);
4840 } else if (trasn_code_byte4->fc_lw_laser) {
4841 wavelength = (page_a0[SSF_WAVELENGTH_B1] << 8) |
4842 page_a0[SSF_WAVELENGTH_B0];
4843 if (wavelength == SFP_WAVELENGTH_LC1310)
4844 flag |= SFP_FLAG_PT_LWLASER_LC1310 << SFP_FLAG_PT_SHIFT;
4845 if (wavelength == SFP_WAVELENGTH_LL1550)
4846 flag |= SFP_FLAG_PT_LWLASER_LL1550 << SFP_FLAG_PT_SHIFT;
4848 /* check if its SFP+ */
4849 flag |= ((page_a0[SSF_IDENTIFIER] == SFF_PG0_IDENT_SFP) ?
4850 SFP_FLAG_CT_SFP_PLUS : SFP_FLAG_CT_UNKNOWN)
4851 << SFP_FLAG_CT_SHIFT;
4853 /* check if its OPTICAL */
4854 flag |= ((page_a0[SSF_CONNECTOR] == SFF_PG0_CONNECTOR_LC) ?
4855 SFP_FLAG_IS_OPTICAL_PORT : 0)
4856 << SFP_FLAG_IS_OPTICAL_SHIFT;
4858 temperature = (page_a2[SFF_TEMPERATURE_B1] << 8 |
4859 page_a2[SFF_TEMPERATURE_B0]);
4860 vcc = (page_a2[SFF_VCC_B1] << 8 |
4861 page_a2[SFF_VCC_B0]);
4862 tx_power = (page_a2[SFF_TXPOWER_B1] << 8 |
4863 page_a2[SFF_TXPOWER_B0]);
4864 tx_bias = (page_a2[SFF_TX_BIAS_CURRENT_B1] << 8 |
4865 page_a2[SFF_TX_BIAS_CURRENT_B0]);
4866 rx_power = (page_a2[SFF_RXPOWER_B1] << 8 |
4867 page_a2[SFF_RXPOWER_B0]);
4868 desc->sfp_info.temperature = cpu_to_be16(temperature);
4869 desc->sfp_info.rx_power = cpu_to_be16(rx_power);
4870 desc->sfp_info.tx_bias = cpu_to_be16(tx_bias);
4871 desc->sfp_info.tx_power = cpu_to_be16(tx_power);
4872 desc->sfp_info.vcc = cpu_to_be16(vcc);
4874 desc->sfp_info.flags = cpu_to_be16(flag);
4875 desc->length = cpu_to_be32(sizeof(desc->sfp_info));
4877 return sizeof(struct fc_rdp_sfp_desc);
4881 lpfc_rdp_res_link_error(struct fc_rdp_link_error_status_desc *desc,
4886 desc->tag = cpu_to_be32(RDP_LINK_ERROR_STATUS_DESC_TAG);
4888 type = VN_PT_PHY_PF_PORT << VN_PT_PHY_SHIFT;
4890 desc->info.port_type = cpu_to_be32(type);
4892 desc->info.link_status.link_failure_cnt =
4893 cpu_to_be32(stat->linkFailureCnt);
4894 desc->info.link_status.loss_of_synch_cnt =
4895 cpu_to_be32(stat->lossSyncCnt);
4896 desc->info.link_status.loss_of_signal_cnt =
4897 cpu_to_be32(stat->lossSignalCnt);
4898 desc->info.link_status.primitive_seq_proto_err =
4899 cpu_to_be32(stat->primSeqErrCnt);
4900 desc->info.link_status.invalid_trans_word =
4901 cpu_to_be32(stat->invalidXmitWord);
4902 desc->info.link_status.invalid_crc_cnt = cpu_to_be32(stat->crcCnt);
4904 desc->length = cpu_to_be32(sizeof(desc->info));
4906 return sizeof(struct fc_rdp_link_error_status_desc);
4910 lpfc_rdp_res_bbc_desc(struct fc_rdp_bbc_desc *desc, READ_LNK_VAR *stat,
4911 struct lpfc_vport *vport)
4915 desc->tag = cpu_to_be32(RDP_BBC_DESC_TAG);
4917 bbCredit = vport->fc_sparam.cmn.bbCreditLsb |
4918 (vport->fc_sparam.cmn.bbCreditMsb << 8);
4919 desc->bbc_info.port_bbc = cpu_to_be32(bbCredit);
4920 if (vport->phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
4921 bbCredit = vport->phba->fc_fabparam.cmn.bbCreditLsb |
4922 (vport->phba->fc_fabparam.cmn.bbCreditMsb << 8);
4923 desc->bbc_info.attached_port_bbc = cpu_to_be32(bbCredit);
4925 desc->bbc_info.attached_port_bbc = 0;
4928 desc->bbc_info.rtt = 0;
4929 desc->length = cpu_to_be32(sizeof(desc->bbc_info));
4931 return sizeof(struct fc_rdp_bbc_desc);
4935 lpfc_rdp_res_oed_temp_desc(struct lpfc_hba *phba,
4936 struct fc_rdp_oed_sfp_desc *desc, uint8_t *page_a2)
4940 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
4942 desc->oed_info.hi_alarm = page_a2[SSF_TEMP_HIGH_ALARM];
4943 desc->oed_info.lo_alarm = page_a2[SSF_TEMP_LOW_ALARM];
4944 desc->oed_info.hi_warning = page_a2[SSF_TEMP_HIGH_WARNING];
4945 desc->oed_info.lo_warning = page_a2[SSF_TEMP_LOW_WARNING];
4947 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TEMPERATURE)
4948 flags |= RDP_OET_HIGH_ALARM;
4949 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TEMPERATURE)
4950 flags |= RDP_OET_LOW_ALARM;
4951 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TEMPERATURE)
4952 flags |= RDP_OET_HIGH_WARNING;
4953 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TEMPERATURE)
4954 flags |= RDP_OET_LOW_WARNING;
4956 flags |= ((0xf & RDP_OED_TEMPERATURE) << RDP_OED_TYPE_SHIFT);
4957 desc->oed_info.function_flags = cpu_to_be32(flags);
4958 desc->length = cpu_to_be32(sizeof(desc->oed_info));
4959 return sizeof(struct fc_rdp_oed_sfp_desc);
4963 lpfc_rdp_res_oed_voltage_desc(struct lpfc_hba *phba,
4964 struct fc_rdp_oed_sfp_desc *desc,
4969 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
4971 desc->oed_info.hi_alarm = page_a2[SSF_VOLTAGE_HIGH_ALARM];
4972 desc->oed_info.lo_alarm = page_a2[SSF_VOLTAGE_LOW_ALARM];
4973 desc->oed_info.hi_warning = page_a2[SSF_VOLTAGE_HIGH_WARNING];
4974 desc->oed_info.lo_warning = page_a2[SSF_VOLTAGE_LOW_WARNING];
4976 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_VOLTAGE)
4977 flags |= RDP_OET_HIGH_ALARM;
4978 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_VOLTAGE)
4979 flags |= RDP_OET_LOW_ALARM;
4980 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_VOLTAGE)
4981 flags |= RDP_OET_HIGH_WARNING;
4982 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_VOLTAGE)
4983 flags |= RDP_OET_LOW_WARNING;
4985 flags |= ((0xf & RDP_OED_VOLTAGE) << RDP_OED_TYPE_SHIFT);
4986 desc->oed_info.function_flags = cpu_to_be32(flags);
4987 desc->length = cpu_to_be32(sizeof(desc->oed_info));
4988 return sizeof(struct fc_rdp_oed_sfp_desc);
4992 lpfc_rdp_res_oed_txbias_desc(struct lpfc_hba *phba,
4993 struct fc_rdp_oed_sfp_desc *desc,
4998 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5000 desc->oed_info.hi_alarm = page_a2[SSF_BIAS_HIGH_ALARM];
5001 desc->oed_info.lo_alarm = page_a2[SSF_BIAS_LOW_ALARM];
5002 desc->oed_info.hi_warning = page_a2[SSF_BIAS_HIGH_WARNING];
5003 desc->oed_info.lo_warning = page_a2[SSF_BIAS_LOW_WARNING];
5005 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TXBIAS)
5006 flags |= RDP_OET_HIGH_ALARM;
5007 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TXBIAS)
5008 flags |= RDP_OET_LOW_ALARM;
5009 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TXBIAS)
5010 flags |= RDP_OET_HIGH_WARNING;
5011 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TXBIAS)
5012 flags |= RDP_OET_LOW_WARNING;
5014 flags |= ((0xf & RDP_OED_TXBIAS) << RDP_OED_TYPE_SHIFT);
5015 desc->oed_info.function_flags = cpu_to_be32(flags);
5016 desc->length = cpu_to_be32(sizeof(desc->oed_info));
5017 return sizeof(struct fc_rdp_oed_sfp_desc);
5021 lpfc_rdp_res_oed_txpower_desc(struct lpfc_hba *phba,
5022 struct fc_rdp_oed_sfp_desc *desc,
5027 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5029 desc->oed_info.hi_alarm = page_a2[SSF_TXPOWER_HIGH_ALARM];
5030 desc->oed_info.lo_alarm = page_a2[SSF_TXPOWER_LOW_ALARM];
5031 desc->oed_info.hi_warning = page_a2[SSF_TXPOWER_HIGH_WARNING];
5032 desc->oed_info.lo_warning = page_a2[SSF_TXPOWER_LOW_WARNING];
5034 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TXPOWER)
5035 flags |= RDP_OET_HIGH_ALARM;
5036 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TXPOWER)
5037 flags |= RDP_OET_LOW_ALARM;
5038 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TXPOWER)
5039 flags |= RDP_OET_HIGH_WARNING;
5040 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TXPOWER)
5041 flags |= RDP_OET_LOW_WARNING;
5043 flags |= ((0xf & RDP_OED_TXPOWER) << RDP_OED_TYPE_SHIFT);
5044 desc->oed_info.function_flags = cpu_to_be32(flags);
5045 desc->length = cpu_to_be32(sizeof(desc->oed_info));
5046 return sizeof(struct fc_rdp_oed_sfp_desc);
5051 lpfc_rdp_res_oed_rxpower_desc(struct lpfc_hba *phba,
5052 struct fc_rdp_oed_sfp_desc *desc,
5057 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5059 desc->oed_info.hi_alarm = page_a2[SSF_RXPOWER_HIGH_ALARM];
5060 desc->oed_info.lo_alarm = page_a2[SSF_RXPOWER_LOW_ALARM];
5061 desc->oed_info.hi_warning = page_a2[SSF_RXPOWER_HIGH_WARNING];
5062 desc->oed_info.lo_warning = page_a2[SSF_RXPOWER_LOW_WARNING];
5064 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_RXPOWER)
5065 flags |= RDP_OET_HIGH_ALARM;
5066 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_RXPOWER)
5067 flags |= RDP_OET_LOW_ALARM;
5068 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_RXPOWER)
5069 flags |= RDP_OET_HIGH_WARNING;
5070 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_RXPOWER)
5071 flags |= RDP_OET_LOW_WARNING;
5073 flags |= ((0xf & RDP_OED_RXPOWER) << RDP_OED_TYPE_SHIFT);
5074 desc->oed_info.function_flags = cpu_to_be32(flags);
5075 desc->length = cpu_to_be32(sizeof(desc->oed_info));
5076 return sizeof(struct fc_rdp_oed_sfp_desc);
5080 lpfc_rdp_res_opd_desc(struct fc_rdp_opd_sfp_desc *desc,
5081 uint8_t *page_a0, struct lpfc_vport *vport)
5083 desc->tag = cpu_to_be32(RDP_OPD_DESC_TAG);
5084 memcpy(desc->opd_info.vendor_name, &page_a0[SSF_VENDOR_NAME], 16);
5085 memcpy(desc->opd_info.model_number, &page_a0[SSF_VENDOR_PN], 16);
5086 memcpy(desc->opd_info.serial_number, &page_a0[SSF_VENDOR_SN], 16);
5087 memcpy(desc->opd_info.revision, &page_a0[SSF_VENDOR_REV], 4);
5088 memcpy(desc->opd_info.date, &page_a0[SSF_DATE_CODE], 8);
5089 desc->length = cpu_to_be32(sizeof(desc->opd_info));
5090 return sizeof(struct fc_rdp_opd_sfp_desc);
5094 lpfc_rdp_res_fec_desc(struct fc_fec_rdp_desc *desc, READ_LNK_VAR *stat)
5096 if (bf_get(lpfc_read_link_stat_gec2, stat) == 0)
5098 desc->tag = cpu_to_be32(RDP_FEC_DESC_TAG);
5100 desc->info.CorrectedBlocks =
5101 cpu_to_be32(stat->fecCorrBlkCount);
5102 desc->info.UncorrectableBlocks =
5103 cpu_to_be32(stat->fecUncorrBlkCount);
5105 desc->length = cpu_to_be32(sizeof(desc->info));
5107 return sizeof(struct fc_fec_rdp_desc);
5111 lpfc_rdp_res_speed(struct fc_rdp_port_speed_desc *desc, struct lpfc_hba *phba)
5113 uint16_t rdp_cap = 0;
5116 desc->tag = cpu_to_be32(RDP_PORT_SPEED_DESC_TAG);
5118 switch (phba->fc_linkspeed) {
5119 case LPFC_LINK_SPEED_1GHZ:
5120 rdp_speed = RDP_PS_1GB;
5122 case LPFC_LINK_SPEED_2GHZ:
5123 rdp_speed = RDP_PS_2GB;
5125 case LPFC_LINK_SPEED_4GHZ:
5126 rdp_speed = RDP_PS_4GB;
5128 case LPFC_LINK_SPEED_8GHZ:
5129 rdp_speed = RDP_PS_8GB;
5131 case LPFC_LINK_SPEED_10GHZ:
5132 rdp_speed = RDP_PS_10GB;
5134 case LPFC_LINK_SPEED_16GHZ:
5135 rdp_speed = RDP_PS_16GB;
5137 case LPFC_LINK_SPEED_32GHZ:
5138 rdp_speed = RDP_PS_32GB;
5141 rdp_speed = RDP_PS_UNKNOWN;
5145 desc->info.port_speed.speed = cpu_to_be16(rdp_speed);
5147 if (phba->lmt & LMT_32Gb)
5148 rdp_cap |= RDP_PS_32GB;
5149 if (phba->lmt & LMT_16Gb)
5150 rdp_cap |= RDP_PS_16GB;
5151 if (phba->lmt & LMT_10Gb)
5152 rdp_cap |= RDP_PS_10GB;
5153 if (phba->lmt & LMT_8Gb)
5154 rdp_cap |= RDP_PS_8GB;
5155 if (phba->lmt & LMT_4Gb)
5156 rdp_cap |= RDP_PS_4GB;
5157 if (phba->lmt & LMT_2Gb)
5158 rdp_cap |= RDP_PS_2GB;
5159 if (phba->lmt & LMT_1Gb)
5160 rdp_cap |= RDP_PS_1GB;
5163 rdp_cap = RDP_CAP_UNKNOWN;
5164 if (phba->cfg_link_speed != LPFC_USER_LINK_SPEED_AUTO)
5165 rdp_cap |= RDP_CAP_USER_CONFIGURED;
5167 desc->info.port_speed.capabilities = cpu_to_be16(rdp_cap);
5168 desc->length = cpu_to_be32(sizeof(desc->info));
5169 return sizeof(struct fc_rdp_port_speed_desc);
5173 lpfc_rdp_res_diag_port_names(struct fc_rdp_port_name_desc *desc,
5174 struct lpfc_vport *vport)
5177 desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG);
5179 memcpy(desc->port_names.wwnn, &vport->fc_nodename,
5180 sizeof(desc->port_names.wwnn));
5182 memcpy(desc->port_names.wwpn, &vport->fc_portname,
5183 sizeof(desc->port_names.wwpn));
5185 desc->length = cpu_to_be32(sizeof(desc->port_names));
5186 return sizeof(struct fc_rdp_port_name_desc);
5190 lpfc_rdp_res_attach_port_names(struct fc_rdp_port_name_desc *desc,
5191 struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
5194 desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG);
5195 if (vport->fc_flag & FC_FABRIC) {
5196 memcpy(desc->port_names.wwnn, &vport->fabric_nodename,
5197 sizeof(desc->port_names.wwnn));
5199 memcpy(desc->port_names.wwpn, &vport->fabric_portname,
5200 sizeof(desc->port_names.wwpn));
5201 } else { /* Point to Point */
5202 memcpy(desc->port_names.wwnn, &ndlp->nlp_nodename,
5203 sizeof(desc->port_names.wwnn));
5205 memcpy(desc->port_names.wwnn, &ndlp->nlp_portname,
5206 sizeof(desc->port_names.wwpn));
5209 desc->length = cpu_to_be32(sizeof(desc->port_names));
5210 return sizeof(struct fc_rdp_port_name_desc);
5214 lpfc_els_rdp_cmpl(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context,
5217 struct lpfc_nodelist *ndlp = rdp_context->ndlp;
5218 struct lpfc_vport *vport = ndlp->vport;
5219 struct lpfc_iocbq *elsiocb;
5220 struct ulp_bde64 *bpl;
5223 struct ls_rjt *stat;
5224 struct fc_rdp_res_frame *rdp_res;
5225 uint32_t cmdsize, len;
5229 if (status != SUCCESS)
5232 /* This will change once we know the true size of the RDP payload */
5233 cmdsize = sizeof(struct fc_rdp_res_frame);
5235 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize,
5236 lpfc_max_els_tries, rdp_context->ndlp,
5237 rdp_context->ndlp->nlp_DID, ELS_CMD_ACC);
5240 goto free_rdp_context;
5242 icmd = &elsiocb->iocb;
5243 icmd->ulpContext = rdp_context->rx_id;
5244 icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id;
5246 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5247 "2171 Xmit RDP response tag x%x xri x%x, "
5248 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x",
5249 elsiocb->iotag, elsiocb->iocb.ulpContext,
5250 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5252 rdp_res = (struct fc_rdp_res_frame *)
5253 (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5254 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5255 memset(pcmd, 0, sizeof(struct fc_rdp_res_frame));
5256 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5258 /* Update Alarm and Warning */
5259 flag_ptr = (uint16_t *)(rdp_context->page_a2 + SSF_ALARM_FLAGS);
5260 phba->sfp_alarm |= *flag_ptr;
5261 flag_ptr = (uint16_t *)(rdp_context->page_a2 + SSF_WARNING_FLAGS);
5262 phba->sfp_warning |= *flag_ptr;
5264 /* For RDP payload */
5266 len += lpfc_rdp_res_link_service((struct fc_rdp_link_service_desc *)
5267 (len + pcmd), ELS_CMD_RDP);
5269 len += lpfc_rdp_res_sfp_desc((struct fc_rdp_sfp_desc *)(len + pcmd),
5270 rdp_context->page_a0, rdp_context->page_a2);
5271 len += lpfc_rdp_res_speed((struct fc_rdp_port_speed_desc *)(len + pcmd),
5273 len += lpfc_rdp_res_link_error((struct fc_rdp_link_error_status_desc *)
5274 (len + pcmd), &rdp_context->link_stat);
5275 len += lpfc_rdp_res_diag_port_names((struct fc_rdp_port_name_desc *)
5276 (len + pcmd), vport);
5277 len += lpfc_rdp_res_attach_port_names((struct fc_rdp_port_name_desc *)
5278 (len + pcmd), vport, ndlp);
5279 len += lpfc_rdp_res_fec_desc((struct fc_fec_rdp_desc *)(len + pcmd),
5280 &rdp_context->link_stat);
5281 /* Check if nport is logged, BZ190632 */
5282 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED))
5283 goto lpfc_skip_descriptor;
5285 len += lpfc_rdp_res_bbc_desc((struct fc_rdp_bbc_desc *)(len + pcmd),
5286 &rdp_context->link_stat, vport);
5287 len += lpfc_rdp_res_oed_temp_desc(phba,
5288 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5289 rdp_context->page_a2);
5290 len += lpfc_rdp_res_oed_voltage_desc(phba,
5291 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5292 rdp_context->page_a2);
5293 len += lpfc_rdp_res_oed_txbias_desc(phba,
5294 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5295 rdp_context->page_a2);
5296 len += lpfc_rdp_res_oed_txpower_desc(phba,
5297 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5298 rdp_context->page_a2);
5299 len += lpfc_rdp_res_oed_rxpower_desc(phba,
5300 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5301 rdp_context->page_a2);
5302 len += lpfc_rdp_res_opd_desc((struct fc_rdp_opd_sfp_desc *)(len + pcmd),
5303 rdp_context->page_a0, vport);
5305 lpfc_skip_descriptor:
5306 rdp_res->length = cpu_to_be32(len - 8);
5307 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5309 /* Now that we know the true size of the payload, update the BPL */
5310 bpl = (struct ulp_bde64 *)
5311 (((struct lpfc_dmabuf *)(elsiocb->context3))->virt);
5312 bpl->tus.f.bdeSize = len;
5313 bpl->tus.f.bdeFlags = 0;
5314 bpl->tus.w = le32_to_cpu(bpl->tus.w);
5316 phba->fc_stat.elsXmitACC++;
5317 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5318 if (rc == IOCB_ERROR)
5319 lpfc_els_free_iocb(phba, elsiocb);
5325 cmdsize = 2 * sizeof(uint32_t);
5326 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, lpfc_max_els_tries,
5327 ndlp, ndlp->nlp_DID, ELS_CMD_LS_RJT);
5330 goto free_rdp_context;
5332 icmd = &elsiocb->iocb;
5333 icmd->ulpContext = rdp_context->rx_id;
5334 icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id;
5335 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5337 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
5338 stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t));
5339 stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5341 phba->fc_stat.elsXmitLSRJT++;
5342 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5343 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5345 if (rc == IOCB_ERROR)
5346 lpfc_els_free_iocb(phba, elsiocb);
5352 lpfc_get_rdp_info(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context)
5354 LPFC_MBOXQ_t *mbox = NULL;
5357 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5359 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_ELS,
5360 "7105 failed to allocate mailbox memory");
5364 if (lpfc_sli4_dump_page_a0(phba, mbox))
5365 goto prep_mbox_fail;
5366 mbox->vport = rdp_context->ndlp->vport;
5367 mbox->mbox_cmpl = lpfc_mbx_cmpl_rdp_page_a0;
5368 mbox->context2 = (struct lpfc_rdp_context *) rdp_context;
5369 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
5370 if (rc == MBX_NOT_FINISHED)
5371 goto issue_mbox_fail;
5377 mempool_free(mbox, phba->mbox_mem_pool);
5382 * lpfc_els_rcv_rdp - Process an unsolicited RDP ELS.
5383 * @vport: pointer to a host virtual N_Port data structure.
5384 * @cmdiocb: pointer to lpfc command iocb data structure.
5385 * @ndlp: pointer to a node-list data structure.
5387 * This routine processes an unsolicited RDP(Read Diagnostic Parameters)
5388 * IOCB. First, the payload of the unsolicited RDP is checked.
5389 * Then it will (1) send MBX_DUMP_MEMORY, Embedded DMP_LMSD sub command TYPE-3
5390 * for Page A0, (2) send MBX_DUMP_MEMORY, DMP_LMSD for Page A2,
5391 * (3) send MBX_READ_LNK_STAT to get link stat, (4) Call lpfc_els_rdp_cmpl
5392 * gather all data and send RDP response.
5395 * 0 - Sent the acc response
5396 * 1 - Sent the reject response.
5399 lpfc_els_rcv_rdp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5400 struct lpfc_nodelist *ndlp)
5402 struct lpfc_hba *phba = vport->phba;
5403 struct lpfc_dmabuf *pcmd;
5404 uint8_t rjt_err, rjt_expl = LSEXP_NOTHING_MORE;
5405 struct fc_rdp_req_frame *rdp_req;
5406 struct lpfc_rdp_context *rdp_context;
5410 if (phba->sli_rev < LPFC_SLI_REV4 ||
5411 bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
5412 LPFC_SLI_INTF_IF_TYPE_2) {
5413 rjt_err = LSRJT_UNABLE_TPC;
5414 rjt_expl = LSEXP_REQ_UNSUPPORTED;
5418 if (phba->sli_rev < LPFC_SLI_REV4 || (phba->hba_flag & HBA_FCOE_MODE)) {
5419 rjt_err = LSRJT_UNABLE_TPC;
5420 rjt_expl = LSEXP_REQ_UNSUPPORTED;
5424 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5425 rdp_req = (struct fc_rdp_req_frame *) pcmd->virt;
5428 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5429 "2422 ELS RDP Request "
5430 "dec len %d tag x%x port_id %d len %d\n",
5431 be32_to_cpu(rdp_req->rdp_des_length),
5432 be32_to_cpu(rdp_req->nport_id_desc.tag),
5433 be32_to_cpu(rdp_req->nport_id_desc.nport_id),
5434 be32_to_cpu(rdp_req->nport_id_desc.length));
5436 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED) &&
5437 !phba->cfg_enable_SmartSAN) {
5438 rjt_err = LSRJT_UNABLE_TPC;
5439 rjt_expl = LSEXP_PORT_LOGIN_REQ;
5442 if (sizeof(struct fc_rdp_nport_desc) !=
5443 be32_to_cpu(rdp_req->rdp_des_length))
5445 if (RDP_N_PORT_DESC_TAG != be32_to_cpu(rdp_req->nport_id_desc.tag))
5447 if (RDP_NPORT_ID_SIZE !=
5448 be32_to_cpu(rdp_req->nport_id_desc.length))
5450 rdp_context = kzalloc(sizeof(struct lpfc_rdp_context), GFP_KERNEL);
5452 rjt_err = LSRJT_UNABLE_TPC;
5456 cmd = &cmdiocb->iocb;
5457 rdp_context->ndlp = lpfc_nlp_get(ndlp);
5458 rdp_context->ox_id = cmd->unsli3.rcvsli3.ox_id;
5459 rdp_context->rx_id = cmd->ulpContext;
5460 rdp_context->cmpl = lpfc_els_rdp_cmpl;
5461 if (lpfc_get_rdp_info(phba, rdp_context)) {
5462 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_ELS,
5463 "2423 Unable to send mailbox");
5465 rjt_err = LSRJT_UNABLE_TPC;
5473 rjt_err = LSRJT_LOGICAL_ERR;
5476 memset(&stat, 0, sizeof(stat));
5477 stat.un.b.lsRjtRsnCode = rjt_err;
5478 stat.un.b.lsRjtRsnCodeExp = rjt_expl;
5479 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5485 lpfc_els_lcb_rsp(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
5490 struct lpfc_iocbq *elsiocb;
5491 struct lpfc_nodelist *ndlp;
5492 struct ls_rjt *stat;
5493 union lpfc_sli4_cfg_shdr *shdr;
5494 struct lpfc_lcb_context *lcb_context;
5495 struct fc_lcb_res_frame *lcb_res;
5496 uint32_t cmdsize, shdr_status, shdr_add_status;
5500 lcb_context = (struct lpfc_lcb_context *)pmb->context1;
5501 ndlp = lcb_context->ndlp;
5502 pmb->context1 = NULL;
5503 pmb->context2 = NULL;
5505 shdr = (union lpfc_sli4_cfg_shdr *)
5506 &pmb->u.mqe.un.beacon_config.header.cfg_shdr;
5507 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
5508 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
5510 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX,
5511 "0194 SET_BEACON_CONFIG mailbox "
5512 "completed with status x%x add_status x%x,"
5513 " mbx status x%x\n",
5514 shdr_status, shdr_add_status, mb->mbxStatus);
5516 if (mb->mbxStatus && !(shdr_status &&
5517 shdr_add_status == ADD_STATUS_OPERATION_ALREADY_ACTIVE)) {
5518 mempool_free(pmb, phba->mbox_mem_pool);
5522 mempool_free(pmb, phba->mbox_mem_pool);
5523 cmdsize = sizeof(struct fc_lcb_res_frame);
5524 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5525 lpfc_max_els_tries, ndlp,
5526 ndlp->nlp_DID, ELS_CMD_ACC);
5528 /* Decrement the ndlp reference count from previous mbox command */
5532 goto free_lcb_context;
5534 lcb_res = (struct fc_lcb_res_frame *)
5535 (((struct lpfc_dmabuf *)elsiocb->context2)->virt);
5537 icmd = &elsiocb->iocb;
5538 icmd->ulpContext = lcb_context->rx_id;
5539 icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id;
5541 pcmd = (uint8_t *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt);
5542 *((uint32_t *)(pcmd)) = ELS_CMD_ACC;
5543 lcb_res->lcb_sub_command = lcb_context->sub_command;
5544 lcb_res->lcb_type = lcb_context->type;
5545 lcb_res->lcb_frequency = lcb_context->frequency;
5546 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5547 phba->fc_stat.elsXmitACC++;
5548 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5549 if (rc == IOCB_ERROR)
5550 lpfc_els_free_iocb(phba, elsiocb);
5556 cmdsize = sizeof(struct fc_lcb_res_frame);
5557 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5558 lpfc_max_els_tries, ndlp,
5559 ndlp->nlp_DID, ELS_CMD_LS_RJT);
5562 goto free_lcb_context;
5564 icmd = &elsiocb->iocb;
5565 icmd->ulpContext = lcb_context->rx_id;
5566 icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id;
5567 pcmd = (uint8_t *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt);
5569 *((uint32_t *)(pcmd)) = ELS_CMD_LS_RJT;
5570 stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t));
5571 stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5573 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5574 phba->fc_stat.elsXmitLSRJT++;
5575 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5576 if (rc == IOCB_ERROR)
5577 lpfc_els_free_iocb(phba, elsiocb);
5583 lpfc_sli4_set_beacon(struct lpfc_vport *vport,
5584 struct lpfc_lcb_context *lcb_context,
5585 uint32_t beacon_state)
5587 struct lpfc_hba *phba = vport->phba;
5588 LPFC_MBOXQ_t *mbox = NULL;
5592 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5596 len = sizeof(struct lpfc_mbx_set_beacon_config) -
5597 sizeof(struct lpfc_sli4_cfg_mhdr);
5598 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
5599 LPFC_MBOX_OPCODE_SET_BEACON_CONFIG, len,
5600 LPFC_SLI4_MBX_EMBED);
5601 mbox->context1 = (void *)lcb_context;
5602 mbox->vport = phba->pport;
5603 mbox->mbox_cmpl = lpfc_els_lcb_rsp;
5604 bf_set(lpfc_mbx_set_beacon_port_num, &mbox->u.mqe.un.beacon_config,
5605 phba->sli4_hba.physical_port);
5606 bf_set(lpfc_mbx_set_beacon_state, &mbox->u.mqe.un.beacon_config,
5608 bf_set(lpfc_mbx_set_beacon_port_type, &mbox->u.mqe.un.beacon_config, 1);
5609 bf_set(lpfc_mbx_set_beacon_duration, &mbox->u.mqe.un.beacon_config, 0);
5610 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
5611 if (rc == MBX_NOT_FINISHED) {
5612 mempool_free(mbox, phba->mbox_mem_pool);
5621 * lpfc_els_rcv_lcb - Process an unsolicited LCB
5622 * @vport: pointer to a host virtual N_Port data structure.
5623 * @cmdiocb: pointer to lpfc command iocb data structure.
5624 * @ndlp: pointer to a node-list data structure.
5626 * This routine processes an unsolicited LCB(LINK CABLE BEACON) IOCB.
5627 * First, the payload of the unsolicited LCB is checked.
5628 * Then based on Subcommand beacon will either turn on or off.
5631 * 0 - Sent the acc response
5632 * 1 - Sent the reject response.
5635 lpfc_els_rcv_lcb(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5636 struct lpfc_nodelist *ndlp)
5638 struct lpfc_hba *phba = vport->phba;
5639 struct lpfc_dmabuf *pcmd;
5641 struct fc_lcb_request_frame *beacon;
5642 struct lpfc_lcb_context *lcb_context;
5643 uint8_t state, rjt_err;
5646 pcmd = (struct lpfc_dmabuf *)cmdiocb->context2;
5647 lp = (uint8_t *)pcmd->virt;
5648 beacon = (struct fc_lcb_request_frame *)pcmd->virt;
5650 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5651 "0192 ELS LCB Data x%x x%x x%x x%x sub x%x "
5652 "type x%x frequency %x duration x%x\n",
5653 lp[0], lp[1], lp[2],
5654 beacon->lcb_command,
5655 beacon->lcb_sub_command,
5657 beacon->lcb_frequency,
5658 be16_to_cpu(beacon->lcb_duration));
5660 if (phba->sli_rev < LPFC_SLI_REV4 ||
5661 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
5662 LPFC_SLI_INTF_IF_TYPE_2)) {
5663 rjt_err = LSRJT_CMD_UNSUPPORTED;
5667 if (phba->hba_flag & HBA_FCOE_MODE) {
5668 rjt_err = LSRJT_CMD_UNSUPPORTED;
5671 if (beacon->lcb_frequency == 0) {
5672 rjt_err = LSRJT_CMD_UNSUPPORTED;
5675 if ((beacon->lcb_type != LPFC_LCB_GREEN) &&
5676 (beacon->lcb_type != LPFC_LCB_AMBER)) {
5677 rjt_err = LSRJT_CMD_UNSUPPORTED;
5680 if ((beacon->lcb_sub_command != LPFC_LCB_ON) &&
5681 (beacon->lcb_sub_command != LPFC_LCB_OFF)) {
5682 rjt_err = LSRJT_CMD_UNSUPPORTED;
5685 if ((beacon->lcb_sub_command == LPFC_LCB_ON) &&
5686 (beacon->lcb_type != LPFC_LCB_GREEN) &&
5687 (beacon->lcb_type != LPFC_LCB_AMBER)) {
5688 rjt_err = LSRJT_CMD_UNSUPPORTED;
5691 if (be16_to_cpu(beacon->lcb_duration) != 0) {
5692 rjt_err = LSRJT_CMD_UNSUPPORTED;
5696 lcb_context = kmalloc(sizeof(*lcb_context), GFP_KERNEL);
5698 rjt_err = LSRJT_UNABLE_TPC;
5702 state = (beacon->lcb_sub_command == LPFC_LCB_ON) ? 1 : 0;
5703 lcb_context->sub_command = beacon->lcb_sub_command;
5704 lcb_context->type = beacon->lcb_type;
5705 lcb_context->frequency = beacon->lcb_frequency;
5706 lcb_context->ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id;
5707 lcb_context->rx_id = cmdiocb->iocb.ulpContext;
5708 lcb_context->ndlp = lpfc_nlp_get(ndlp);
5709 if (lpfc_sli4_set_beacon(vport, lcb_context, state)) {
5710 lpfc_printf_vlog(ndlp->vport, KERN_ERR,
5711 LOG_ELS, "0193 failed to send mail box");
5714 rjt_err = LSRJT_UNABLE_TPC;
5719 memset(&stat, 0, sizeof(stat));
5720 stat.un.b.lsRjtRsnCode = rjt_err;
5721 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5727 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
5728 * @vport: pointer to a host virtual N_Port data structure.
5730 * This routine cleans up any Registration State Change Notification
5731 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
5732 * @vport together with the host_lock is used to prevent multiple thread
5733 * trying to access the RSCN array on a same @vport at the same time.
5736 lpfc_els_flush_rscn(struct lpfc_vport *vport)
5738 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5739 struct lpfc_hba *phba = vport->phba;
5742 spin_lock_irq(shost->host_lock);
5743 if (vport->fc_rscn_flush) {
5744 /* Another thread is walking fc_rscn_id_list on this vport */
5745 spin_unlock_irq(shost->host_lock);
5748 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
5749 vport->fc_rscn_flush = 1;
5750 spin_unlock_irq(shost->host_lock);
5752 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
5753 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
5754 vport->fc_rscn_id_list[i] = NULL;
5756 spin_lock_irq(shost->host_lock);
5757 vport->fc_rscn_id_cnt = 0;
5758 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
5759 spin_unlock_irq(shost->host_lock);
5760 lpfc_can_disctmo(vport);
5761 /* Indicate we are done walking this fc_rscn_id_list */
5762 vport->fc_rscn_flush = 0;
5766 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
5767 * @vport: pointer to a host virtual N_Port data structure.
5768 * @did: remote destination port identifier.
5770 * This routine checks whether there is any pending Registration State
5771 * Configuration Notification (RSCN) to a @did on @vport.
5774 * None zero - The @did matched with a pending rscn
5775 * 0 - not able to match @did with a pending rscn
5778 lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
5783 uint32_t payload_len, i;
5784 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5786 ns_did.un.word = did;
5788 /* Never match fabric nodes for RSCNs */
5789 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
5792 /* If we are doing a FULL RSCN rediscovery, match everything */
5793 if (vport->fc_flag & FC_RSCN_DISCOVERY)
5796 spin_lock_irq(shost->host_lock);
5797 if (vport->fc_rscn_flush) {
5798 /* Another thread is walking fc_rscn_id_list on this vport */
5799 spin_unlock_irq(shost->host_lock);
5802 /* Indicate we are walking fc_rscn_id_list on this vport */
5803 vport->fc_rscn_flush = 1;
5804 spin_unlock_irq(shost->host_lock);
5805 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
5806 lp = vport->fc_rscn_id_list[i]->virt;
5807 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
5808 payload_len -= sizeof(uint32_t); /* take off word 0 */
5809 while (payload_len) {
5810 rscn_did.un.word = be32_to_cpu(*lp++);
5811 payload_len -= sizeof(uint32_t);
5812 switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) {
5813 case RSCN_ADDRESS_FORMAT_PORT:
5814 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
5815 && (ns_did.un.b.area == rscn_did.un.b.area)
5816 && (ns_did.un.b.id == rscn_did.un.b.id))
5817 goto return_did_out;
5819 case RSCN_ADDRESS_FORMAT_AREA:
5820 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
5821 && (ns_did.un.b.area == rscn_did.un.b.area))
5822 goto return_did_out;
5824 case RSCN_ADDRESS_FORMAT_DOMAIN:
5825 if (ns_did.un.b.domain == rscn_did.un.b.domain)
5826 goto return_did_out;
5828 case RSCN_ADDRESS_FORMAT_FABRIC:
5829 goto return_did_out;
5833 /* Indicate we are done with walking fc_rscn_id_list on this vport */
5834 vport->fc_rscn_flush = 0;
5837 /* Indicate we are done with walking fc_rscn_id_list on this vport */
5838 vport->fc_rscn_flush = 0;
5843 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
5844 * @vport: pointer to a host virtual N_Port data structure.
5846 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
5847 * state machine for a @vport's nodes that are with pending RSCN (Registration
5848 * State Change Notification).
5851 * 0 - Successful (currently alway return 0)
5854 lpfc_rscn_recovery_check(struct lpfc_vport *vport)
5856 struct lpfc_nodelist *ndlp = NULL;
5858 /* Move all affected nodes by pending RSCNs to NPR state. */
5859 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
5860 if (!NLP_CHK_NODE_ACT(ndlp) ||
5861 (ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
5862 !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
5865 /* NVME Target mode does not do RSCN Recovery. */
5866 if (vport->phba->nvmet_support)
5869 lpfc_disc_state_machine(vport, ndlp, NULL,
5870 NLP_EVT_DEVICE_RECOVERY);
5871 lpfc_cancel_retry_delay_tmo(vport, ndlp);
5877 * lpfc_send_rscn_event - Send an RSCN event to management application
5878 * @vport: pointer to a host virtual N_Port data structure.
5879 * @cmdiocb: pointer to lpfc command iocb data structure.
5881 * lpfc_send_rscn_event sends an RSCN netlink event to management
5885 lpfc_send_rscn_event(struct lpfc_vport *vport,
5886 struct lpfc_iocbq *cmdiocb)
5888 struct lpfc_dmabuf *pcmd;
5889 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5890 uint32_t *payload_ptr;
5891 uint32_t payload_len;
5892 struct lpfc_rscn_event_header *rscn_event_data;
5894 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5895 payload_ptr = (uint32_t *) pcmd->virt;
5896 payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK);
5898 rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) +
5899 payload_len, GFP_KERNEL);
5900 if (!rscn_event_data) {
5901 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5902 "0147 Failed to allocate memory for RSCN event\n");
5905 rscn_event_data->event_type = FC_REG_RSCN_EVENT;
5906 rscn_event_data->payload_length = payload_len;
5907 memcpy(rscn_event_data->rscn_payload, payload_ptr,
5910 fc_host_post_vendor_event(shost,
5911 fc_get_event_number(),
5912 sizeof(struct lpfc_rscn_event_header) + payload_len,
5913 (char *)rscn_event_data,
5916 kfree(rscn_event_data);
5920 * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
5921 * @vport: pointer to a host virtual N_Port data structure.
5922 * @cmdiocb: pointer to lpfc command iocb data structure.
5923 * @ndlp: pointer to a node-list data structure.
5925 * This routine processes an unsolicited RSCN (Registration State Change
5926 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
5927 * to invoke fc_host_post_event() routine to the FC transport layer. If the
5928 * discover state machine is about to begin discovery, it just accepts the
5929 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
5930 * contains N_Port IDs for other vports on this HBA, it just accepts the
5931 * RSCN and ignore processing it. If the state machine is in the recovery
5932 * state, the fc_rscn_id_list of this @vport is walked and the
5933 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
5934 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
5935 * routine is invoked to handle the RSCN event.
5938 * 0 - Just sent the acc response
5939 * 1 - Sent the acc response and waited for name server completion
5942 lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5943 struct lpfc_nodelist *ndlp)
5945 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5946 struct lpfc_hba *phba = vport->phba;
5947 struct lpfc_dmabuf *pcmd;
5948 uint32_t *lp, *datap;
5949 uint32_t payload_len, length, nportid, *cmd;
5951 int rscn_id = 0, hba_id = 0;
5954 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5955 lp = (uint32_t *) pcmd->virt;
5957 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
5958 payload_len -= sizeof(uint32_t); /* take off word 0 */
5960 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5961 "0214 RSCN received Data: x%x x%x x%x x%x\n",
5962 vport->fc_flag, payload_len, *lp,
5963 vport->fc_rscn_id_cnt);
5965 /* Send an RSCN event to the management application */
5966 lpfc_send_rscn_event(vport, cmdiocb);
5968 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
5969 fc_host_post_event(shost, fc_get_event_number(),
5970 FCH_EVT_RSCN, lp[i]);
5972 /* If we are about to begin discovery, just ACC the RSCN.
5973 * Discovery processing will satisfy it.
5975 if (vport->port_state <= LPFC_NS_QRY) {
5976 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5977 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
5978 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
5980 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
5984 /* If this RSCN just contains NPortIDs for other vports on this HBA,
5985 * just ACC and ignore it.
5987 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
5988 !(vport->cfg_peer_port_login)) {
5993 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
5994 i -= sizeof(uint32_t);
5996 if (lpfc_find_vport_by_did(phba, nportid))
5999 if (rscn_id == hba_id) {
6000 /* ALL NPortIDs in RSCN are on HBA */
6001 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6003 "Data: x%x x%x x%x x%x\n",
6004 vport->fc_flag, payload_len,
6005 *lp, vport->fc_rscn_id_cnt);
6006 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6007 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
6008 ndlp->nlp_DID, vport->port_state,
6011 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
6017 spin_lock_irq(shost->host_lock);
6018 if (vport->fc_rscn_flush) {
6019 /* Another thread is walking fc_rscn_id_list on this vport */
6020 vport->fc_flag |= FC_RSCN_DISCOVERY;
6021 spin_unlock_irq(shost->host_lock);
6023 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
6026 /* Indicate we are walking fc_rscn_id_list on this vport */
6027 vport->fc_rscn_flush = 1;
6028 spin_unlock_irq(shost->host_lock);
6029 /* Get the array count after successfully have the token */
6030 rscn_cnt = vport->fc_rscn_id_cnt;
6031 /* If we are already processing an RSCN, save the received
6032 * RSCN payload buffer, cmdiocb->context2 to process later.
6034 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
6035 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6036 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
6037 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
6039 spin_lock_irq(shost->host_lock);
6040 vport->fc_flag |= FC_RSCN_DEFERRED;
6041 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
6042 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
6043 vport->fc_flag |= FC_RSCN_MODE;
6044 spin_unlock_irq(shost->host_lock);
6046 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
6047 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
6050 (payload_len + length <= LPFC_BPL_SIZE)) {
6051 *cmd &= ELS_CMD_MASK;
6052 *cmd |= cpu_to_be32(payload_len + length);
6053 memcpy(((uint8_t *)cmd) + length, lp,
6056 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
6057 vport->fc_rscn_id_cnt++;
6058 /* If we zero, cmdiocb->context2, the calling
6059 * routine will not try to free it.
6061 cmdiocb->context2 = NULL;
6064 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6065 "0235 Deferred RSCN "
6066 "Data: x%x x%x x%x\n",
6067 vport->fc_rscn_id_cnt, vport->fc_flag,
6070 vport->fc_flag |= FC_RSCN_DISCOVERY;
6071 spin_unlock_irq(shost->host_lock);
6072 /* ReDiscovery RSCN */
6073 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6074 "0234 ReDiscovery RSCN "
6075 "Data: x%x x%x x%x\n",
6076 vport->fc_rscn_id_cnt, vport->fc_flag,
6079 /* Indicate we are done walking fc_rscn_id_list on this vport */
6080 vport->fc_rscn_flush = 0;
6082 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
6083 /* send RECOVERY event for ALL nodes that match RSCN payload */
6084 lpfc_rscn_recovery_check(vport);
6085 spin_lock_irq(shost->host_lock);
6086 vport->fc_flag &= ~FC_RSCN_DEFERRED;
6087 spin_unlock_irq(shost->host_lock);
6090 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6091 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
6092 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
6094 spin_lock_irq(shost->host_lock);
6095 vport->fc_flag |= FC_RSCN_MODE;
6096 spin_unlock_irq(shost->host_lock);
6097 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
6098 /* Indicate we are done walking fc_rscn_id_list on this vport */
6099 vport->fc_rscn_flush = 0;
6101 * If we zero, cmdiocb->context2, the calling routine will
6102 * not try to free it.
6104 cmdiocb->context2 = NULL;
6105 lpfc_set_disctmo(vport);
6107 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
6108 /* send RECOVERY event for ALL nodes that match RSCN payload */
6109 lpfc_rscn_recovery_check(vport);
6110 return lpfc_els_handle_rscn(vport);
6114 * lpfc_els_handle_rscn - Handle rscn for a vport
6115 * @vport: pointer to a host virtual N_Port data structure.
6117 * This routine handles the Registration State Configuration Notification
6118 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
6119 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
6120 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
6121 * NameServer shall be issued. If CT command to the NameServer fails to be
6122 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
6123 * RSCN activities with the @vport.
6126 * 0 - Cleaned up rscn on the @vport
6127 * 1 - Wait for plogi to name server before proceed
6130 lpfc_els_handle_rscn(struct lpfc_vport *vport)
6132 struct lpfc_nodelist *ndlp;
6134 /* Ignore RSCN if the port is being torn down. */
6135 if (vport->load_flag & FC_UNLOADING) {
6136 lpfc_els_flush_rscn(vport);
6140 /* Start timer for RSCN processing */
6141 lpfc_set_disctmo(vport);
6143 /* RSCN processed */
6144 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6145 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
6146 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
6149 /* To process RSCN, first compare RSCN data with NameServer */
6150 vport->fc_ns_retry = 0;
6151 vport->num_disc_nodes = 0;
6153 ndlp = lpfc_findnode_did(vport, NameServer_DID);
6154 if (ndlp && NLP_CHK_NODE_ACT(ndlp)
6155 && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
6156 /* Good ndlp, issue CT Request to NameServer. Need to
6157 * know how many gidfts were issued. If none, then just
6158 * flush the RSCN. Otherwise, the outstanding requests
6161 vport->gidft_inp = 0;
6162 if (lpfc_issue_gidft(vport) > 0)
6165 /* Nameserver login in question. Revalidate. */
6167 ndlp = lpfc_enable_node(vport, ndlp,
6168 NLP_STE_PLOGI_ISSUE);
6170 lpfc_els_flush_rscn(vport);
6173 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
6175 ndlp = lpfc_nlp_init(vport, NameServer_DID);
6177 lpfc_els_flush_rscn(vport);
6180 ndlp->nlp_prev_state = ndlp->nlp_state;
6181 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
6183 ndlp->nlp_type |= NLP_FABRIC;
6184 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
6185 /* Wait for NameServer login cmpl before we can
6191 lpfc_els_flush_rscn(vport);
6196 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
6197 * @vport: pointer to a host virtual N_Port data structure.
6198 * @cmdiocb: pointer to lpfc command iocb data structure.
6199 * @ndlp: pointer to a node-list data structure.
6201 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
6202 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
6203 * point topology. As an unsolicited FLOGI should not be received in a loop
6204 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
6205 * lpfc_check_sparm() routine is invoked to check the parameters in the
6206 * unsolicited FLOGI. If parameters validation failed, the routine
6207 * lpfc_els_rsp_reject() shall be called with reject reason code set to
6208 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
6209 * FLOGI shall be compared with the Port WWN of the @vport to determine who
6210 * will initiate PLOGI. The higher lexicographical value party shall has
6211 * higher priority (as the winning port) and will initiate PLOGI and
6212 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
6213 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
6214 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
6217 * 0 - Successfully processed the unsolicited flogi
6218 * 1 - Failed to process the unsolicited flogi
6221 lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6222 struct lpfc_nodelist *ndlp)
6224 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6225 struct lpfc_hba *phba = vport->phba;
6226 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6227 uint32_t *lp = (uint32_t *) pcmd->virt;
6228 IOCB_t *icmd = &cmdiocb->iocb;
6229 struct serv_parm *sp;
6233 uint32_t fc_flag = 0;
6234 uint32_t port_state = 0;
6237 sp = (struct serv_parm *) lp;
6239 /* FLOGI received */
6241 lpfc_set_disctmo(vport);
6243 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
6244 /* We should never receive a FLOGI in loop mode, ignore it */
6245 did = icmd->un.elsreq64.remoteID;
6247 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
6249 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6250 "0113 An FLOGI ELS command x%x was "
6251 "received from DID x%x in Loop Mode\n",
6256 (void) lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1);
6259 * If our portname is greater than the remote portname,
6260 * then we initiate Nport login.
6263 rc = memcmp(&vport->fc_portname, &sp->portName,
6264 sizeof(struct lpfc_name));
6267 if (phba->sli_rev < LPFC_SLI_REV4) {
6268 mbox = mempool_alloc(phba->mbox_mem_pool,
6272 lpfc_linkdown(phba);
6273 lpfc_init_link(phba, mbox,
6275 phba->cfg_link_speed);
6276 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
6277 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
6278 mbox->vport = vport;
6279 rc = lpfc_sli_issue_mbox(phba, mbox,
6281 lpfc_set_loopback_flag(phba);
6282 if (rc == MBX_NOT_FINISHED)
6283 mempool_free(mbox, phba->mbox_mem_pool);
6287 /* abort the flogi coming back to ourselves
6288 * due to external loopback on the port.
6290 lpfc_els_abort_flogi(phba);
6293 } else if (rc > 0) { /* greater than */
6294 spin_lock_irq(shost->host_lock);
6295 vport->fc_flag |= FC_PT2PT_PLOGI;
6296 spin_unlock_irq(shost->host_lock);
6298 /* If we have the high WWPN we can assign our own
6299 * myDID; otherwise, we have to WAIT for a PLOGI
6300 * from the remote NPort to find out what it
6303 vport->fc_myDID = PT2PT_LocalID;
6305 vport->fc_myDID = PT2PT_RemoteID;
6309 * The vport state should go to LPFC_FLOGI only
6310 * AFTER we issue a FLOGI, not receive one.
6312 spin_lock_irq(shost->host_lock);
6313 fc_flag = vport->fc_flag;
6314 port_state = vport->port_state;
6315 vport->fc_flag |= FC_PT2PT;
6316 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
6317 spin_unlock_irq(shost->host_lock);
6318 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6319 "3311 Rcv Flogi PS x%x new PS x%x "
6320 "fc_flag x%x new fc_flag x%x\n",
6321 port_state, vport->port_state,
6322 fc_flag, vport->fc_flag);
6325 * We temporarily set fc_myDID to make it look like we are
6326 * a Fabric. This is done just so we end up with the right
6327 * did / sid on the FLOGI ACC rsp.
6329 did = vport->fc_myDID;
6330 vport->fc_myDID = Fabric_DID;
6332 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
6335 lpfc_els_rsp_acc(vport, ELS_CMD_FLOGI, cmdiocb, ndlp, NULL);
6337 /* Now lets put fc_myDID back to what its supposed to be */
6338 vport->fc_myDID = did;
6344 * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
6345 * @vport: pointer to a host virtual N_Port data structure.
6346 * @cmdiocb: pointer to lpfc command iocb data structure.
6347 * @ndlp: pointer to a node-list data structure.
6349 * This routine processes Request Node Identification Data (RNID) IOCB
6350 * received as an ELS unsolicited event. Only when the RNID specified format
6351 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
6352 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
6353 * Accept (ACC) the RNID ELS command. All the other RNID formats are
6354 * rejected by invoking the lpfc_els_rsp_reject() routine.
6357 * 0 - Successfully processed rnid iocb (currently always return 0)
6360 lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6361 struct lpfc_nodelist *ndlp)
6363 struct lpfc_dmabuf *pcmd;
6369 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6370 lp = (uint32_t *) pcmd->virt;
6377 switch (rn->Format) {
6379 case RNID_TOPOLOGY_DISC:
6381 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
6384 /* Reject this request because format not supported */
6385 stat.un.b.lsRjtRsvd0 = 0;
6386 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6387 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
6388 stat.un.b.vendorUnique = 0;
6389 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
6396 * lpfc_els_rcv_echo - Process an unsolicited echo iocb
6397 * @vport: pointer to a host virtual N_Port data structure.
6398 * @cmdiocb: pointer to lpfc command iocb data structure.
6399 * @ndlp: pointer to a node-list data structure.
6402 * 0 - Successfully processed echo iocb (currently always return 0)
6405 lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6406 struct lpfc_nodelist *ndlp)
6410 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
6412 /* skip over first word of echo command to find echo data */
6413 pcmd += sizeof(uint32_t);
6415 lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp);
6420 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
6421 * @vport: pointer to a host virtual N_Port data structure.
6422 * @cmdiocb: pointer to lpfc command iocb data structure.
6423 * @ndlp: pointer to a node-list data structure.
6425 * This routine processes a Link Incident Report Registration(LIRR) IOCB
6426 * received as an ELS unsolicited event. Currently, this function just invokes
6427 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
6430 * 0 - Successfully processed lirr iocb (currently always return 0)
6433 lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6434 struct lpfc_nodelist *ndlp)
6438 /* For now, unconditionally reject this command */
6439 stat.un.b.lsRjtRsvd0 = 0;
6440 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6441 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
6442 stat.un.b.vendorUnique = 0;
6443 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
6448 * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb
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 a Reinstate Recovery Qualifier (RRQ) IOCB
6454 * received as an ELS unsolicited event. A request to RRQ shall only
6455 * be accepted if the Originator Nx_Port N_Port_ID or the Responder
6456 * Nx_Port N_Port_ID of the target Exchange is the same as the
6457 * N_Port_ID of the Nx_Port that makes the request. If the RRQ is
6458 * not accepted, an LS_RJT with reason code "Unable to perform
6459 * command request" and reason code explanation "Invalid Originator
6460 * S_ID" shall be returned. For now, we just unconditionally accept
6461 * RRQ from the target.
6464 lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6465 struct lpfc_nodelist *ndlp)
6467 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
6468 if (vport->phba->sli_rev == LPFC_SLI_REV4)
6469 lpfc_els_clear_rrq(vport, cmdiocb, ndlp);
6473 * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
6474 * @phba: pointer to lpfc hba data structure.
6475 * @pmb: pointer to the driver internal queue element for mailbox command.
6477 * This routine is the completion callback function for the MBX_READ_LNK_STAT
6478 * mailbox command. This callback function is to actually send the Accept
6479 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
6480 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
6481 * mailbox command, constructs the RPS response with the link statistics
6482 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
6483 * response to the RPS.
6485 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6486 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6487 * will be stored into the context1 field of the IOCB for the completion
6488 * callback function to the RPS Accept Response ELS IOCB command.
6492 lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
6496 struct RLS_RSP *rls_rsp;
6498 struct lpfc_iocbq *elsiocb;
6499 struct lpfc_nodelist *ndlp;
6506 ndlp = (struct lpfc_nodelist *) pmb->context2;
6507 rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff);
6508 oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff);
6509 pmb->context1 = NULL;
6510 pmb->context2 = NULL;
6512 if (mb->mbxStatus) {
6513 mempool_free(pmb, phba->mbox_mem_pool);
6517 cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t);
6518 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
6519 lpfc_max_els_tries, ndlp,
6520 ndlp->nlp_DID, ELS_CMD_ACC);
6522 /* Decrement the ndlp reference count from previous mbox command */
6526 mempool_free(pmb, phba->mbox_mem_pool);
6530 icmd = &elsiocb->iocb;
6531 icmd->ulpContext = rxid;
6532 icmd->unsli3.rcvsli3.ox_id = oxid;
6534 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6535 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
6536 pcmd += sizeof(uint32_t); /* Skip past command */
6537 rls_rsp = (struct RLS_RSP *)pcmd;
6539 rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
6540 rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
6541 rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
6542 rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
6543 rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
6544 rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
6545 mempool_free(pmb, phba->mbox_mem_pool);
6546 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
6547 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
6548 "2874 Xmit ELS RLS ACC response tag x%x xri x%x, "
6549 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
6550 elsiocb->iotag, elsiocb->iocb.ulpContext,
6551 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
6553 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
6554 phba->fc_stat.elsXmitACC++;
6555 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
6556 lpfc_els_free_iocb(phba, elsiocb);
6560 * lpfc_els_rsp_rps_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
6561 * @phba: pointer to lpfc hba data structure.
6562 * @pmb: pointer to the driver internal queue element for mailbox command.
6564 * This routine is the completion callback function for the MBX_READ_LNK_STAT
6565 * mailbox command. This callback function is to actually send the Accept
6566 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
6567 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
6568 * mailbox command, constructs the RPS response with the link statistics
6569 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
6570 * response to the RPS.
6572 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6573 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6574 * will be stored into the context1 field of the IOCB for the completion
6575 * callback function to the RPS Accept Response ELS IOCB command.
6579 lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
6585 struct lpfc_iocbq *elsiocb;
6586 struct lpfc_nodelist *ndlp;
6594 ndlp = (struct lpfc_nodelist *) pmb->context2;
6595 rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff);
6596 oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff);
6597 pmb->context1 = NULL;
6598 pmb->context2 = NULL;
6600 if (mb->mbxStatus) {
6601 mempool_free(pmb, phba->mbox_mem_pool);
6605 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
6606 mempool_free(pmb, phba->mbox_mem_pool);
6607 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
6608 lpfc_max_els_tries, ndlp,
6609 ndlp->nlp_DID, ELS_CMD_ACC);
6611 /* Decrement the ndlp reference count from previous mbox command */
6617 icmd = &elsiocb->iocb;
6618 icmd->ulpContext = rxid;
6619 icmd->unsli3.rcvsli3.ox_id = oxid;
6621 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6622 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
6623 pcmd += sizeof(uint32_t); /* Skip past command */
6624 rps_rsp = (RPS_RSP *)pcmd;
6626 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP)
6630 if (phba->pport->fc_flag & FC_FABRIC)
6634 rps_rsp->portStatus = cpu_to_be16(status);
6635 rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
6636 rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
6637 rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
6638 rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
6639 rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
6640 rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
6641 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
6642 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
6643 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
6644 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
6645 elsiocb->iotag, elsiocb->iocb.ulpContext,
6646 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
6648 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
6649 phba->fc_stat.elsXmitACC++;
6650 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
6651 lpfc_els_free_iocb(phba, elsiocb);
6656 * lpfc_els_rcv_rls - Process an unsolicited rls iocb
6657 * @vport: pointer to a host virtual N_Port data structure.
6658 * @cmdiocb: pointer to lpfc command iocb data structure.
6659 * @ndlp: pointer to a node-list data structure.
6661 * This routine processes Read Port Status (RPL) IOCB received as an
6662 * ELS unsolicited event. It first checks the remote port state. If the
6663 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
6664 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
6665 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
6666 * for reading the HBA link statistics. It is for the callback function,
6667 * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command
6668 * to actually sending out RPL Accept (ACC) response.
6671 * 0 - Successfully processed rls iocb (currently always return 0)
6674 lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6675 struct lpfc_nodelist *ndlp)
6677 struct lpfc_hba *phba = vport->phba;
6681 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
6682 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
6683 /* reject the unsolicited RPS request and done with it */
6686 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
6688 lpfc_read_lnk_stat(phba, mbox);
6689 mbox->context1 = (void *)((unsigned long)
6690 ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) |
6691 cmdiocb->iocb.ulpContext)); /* rx_id */
6692 mbox->context2 = lpfc_nlp_get(ndlp);
6693 mbox->vport = vport;
6694 mbox->mbox_cmpl = lpfc_els_rsp_rls_acc;
6695 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
6696 != MBX_NOT_FINISHED)
6697 /* Mbox completion will send ELS Response */
6699 /* Decrement reference count used for the failed mbox
6703 mempool_free(mbox, phba->mbox_mem_pool);
6706 /* issue rejection response */
6707 stat.un.b.lsRjtRsvd0 = 0;
6708 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6709 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
6710 stat.un.b.vendorUnique = 0;
6711 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
6716 * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb
6717 * @vport: pointer to a host virtual N_Port data structure.
6718 * @cmdiocb: pointer to lpfc command iocb data structure.
6719 * @ndlp: pointer to a node-list data structure.
6721 * This routine processes Read Timout Value (RTV) IOCB received as an
6722 * ELS unsolicited event. It first checks the remote port state. If the
6723 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
6724 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
6725 * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout
6726 * Value (RTV) unsolicited IOCB event.
6728 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6729 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6730 * will be stored into the context1 field of the IOCB for the completion
6731 * callback function to the RPS Accept Response ELS IOCB command.
6734 * 0 - Successfully processed rtv iocb (currently always return 0)
6737 lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6738 struct lpfc_nodelist *ndlp)
6740 struct lpfc_hba *phba = vport->phba;
6742 struct RTV_RSP *rtv_rsp;
6744 struct lpfc_iocbq *elsiocb;
6748 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
6749 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
6750 /* reject the unsolicited RPS request and done with it */
6753 cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t);
6754 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
6755 lpfc_max_els_tries, ndlp,
6756 ndlp->nlp_DID, ELS_CMD_ACC);
6761 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6762 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
6763 pcmd += sizeof(uint32_t); /* Skip past command */
6765 /* use the command's xri in the response */
6766 elsiocb->iocb.ulpContext = cmdiocb->iocb.ulpContext; /* Xri / rx_id */
6767 elsiocb->iocb.unsli3.rcvsli3.ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id;
6769 rtv_rsp = (struct RTV_RSP *)pcmd;
6771 /* populate RTV payload */
6772 rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000); /* report msecs */
6773 rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov);
6774 bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0);
6775 bf_set(qtov_rttov, rtv_rsp, 0); /* Field is for FC ONLY */
6776 rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov);
6778 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
6779 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
6780 "2875 Xmit ELS RTV ACC response tag x%x xri x%x, "
6781 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, "
6782 "Data: x%x x%x x%x\n",
6783 elsiocb->iotag, elsiocb->iocb.ulpContext,
6784 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
6786 rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov);
6787 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
6788 phba->fc_stat.elsXmitACC++;
6789 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
6790 lpfc_els_free_iocb(phba, elsiocb);
6794 /* issue rejection response */
6795 stat.un.b.lsRjtRsvd0 = 0;
6796 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6797 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
6798 stat.un.b.vendorUnique = 0;
6799 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
6803 /* lpfc_els_rcv_rps - Process an unsolicited rps iocb
6804 * @vport: pointer to a host virtual N_Port data structure.
6805 * @cmdiocb: pointer to lpfc command iocb data structure.
6806 * @ndlp: pointer to a node-list data structure.
6808 * This routine processes Read Port Status (RPS) IOCB received as an
6809 * ELS unsolicited event. It first checks the remote port state. If the
6810 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
6811 * state, it invokes the lpfc_els_rsp_reject() routine to send the reject
6812 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
6813 * for reading the HBA link statistics. It is for the callback function,
6814 * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command
6815 * to actually sending out RPS Accept (ACC) response.
6818 * 0 - Successfully processed rps iocb (currently always return 0)
6821 lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6822 struct lpfc_nodelist *ndlp)
6824 struct lpfc_hba *phba = vport->phba;
6828 struct lpfc_dmabuf *pcmd;
6832 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
6833 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
6834 /* reject the unsolicited RPS request and done with it */
6837 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6838 lp = (uint32_t *) pcmd->virt;
6839 flag = (be32_to_cpu(*lp++) & 0xf);
6843 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
6844 ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
6845 sizeof(struct lpfc_name)) == 0))) {
6847 printk("Fix me....\n");
6849 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
6851 lpfc_read_lnk_stat(phba, mbox);
6852 mbox->context1 = (void *)((unsigned long)
6853 ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) |
6854 cmdiocb->iocb.ulpContext)); /* rx_id */
6855 mbox->context2 = lpfc_nlp_get(ndlp);
6856 mbox->vport = vport;
6857 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
6858 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
6859 != MBX_NOT_FINISHED)
6860 /* Mbox completion will send ELS Response */
6862 /* Decrement reference count used for the failed mbox
6866 mempool_free(mbox, phba->mbox_mem_pool);
6871 /* issue rejection response */
6872 stat.un.b.lsRjtRsvd0 = 0;
6873 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6874 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
6875 stat.un.b.vendorUnique = 0;
6876 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
6880 /* lpfc_issue_els_rrq - Process an unsolicited rps iocb
6881 * @vport: pointer to a host virtual N_Port data structure.
6882 * @ndlp: pointer to a node-list data structure.
6883 * @did: DID of the target.
6884 * @rrq: Pointer to the rrq struct.
6886 * Build a ELS RRQ command and send it to the target. If the issue_iocb is
6887 * Successful the the completion handler will clear the RRQ.
6890 * 0 - Successfully sent rrq els iocb.
6891 * 1 - Failed to send rrq els iocb.
6894 lpfc_issue_els_rrq(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
6895 uint32_t did, struct lpfc_node_rrq *rrq)
6897 struct lpfc_hba *phba = vport->phba;
6898 struct RRQ *els_rrq;
6899 struct lpfc_iocbq *elsiocb;
6905 if (ndlp != rrq->ndlp)
6907 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
6910 /* If ndlp is not NULL, we will bump the reference count on it */
6911 cmdsize = (sizeof(uint32_t) + sizeof(struct RRQ));
6912 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, did,
6917 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6919 /* For RRQ request, remainder of payload is Exchange IDs */
6920 *((uint32_t *) (pcmd)) = ELS_CMD_RRQ;
6921 pcmd += sizeof(uint32_t);
6922 els_rrq = (struct RRQ *) pcmd;
6924 bf_set(rrq_oxid, els_rrq, phba->sli4_hba.xri_ids[rrq->xritag]);
6925 bf_set(rrq_rxid, els_rrq, rrq->rxid);
6926 bf_set(rrq_did, els_rrq, vport->fc_myDID);
6927 els_rrq->rrq = cpu_to_be32(els_rrq->rrq);
6928 els_rrq->rrq_exchg = cpu_to_be32(els_rrq->rrq_exchg);
6931 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6932 "Issue RRQ: did:x%x",
6933 did, rrq->xritag, rrq->rxid);
6934 elsiocb->context_un.rrq = rrq;
6935 elsiocb->iocb_cmpl = lpfc_cmpl_els_rrq;
6936 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
6938 if (ret == IOCB_ERROR) {
6939 lpfc_els_free_iocb(phba, elsiocb);
6946 * lpfc_send_rrq - Sends ELS RRQ if needed.
6947 * @phba: pointer to lpfc hba data structure.
6948 * @rrq: pointer to the active rrq.
6950 * This routine will call the lpfc_issue_els_rrq if the rrq is
6951 * still active for the xri. If this function returns a failure then
6952 * the caller needs to clean up the RRQ by calling lpfc_clr_active_rrq.
6954 * Returns 0 Success.
6958 lpfc_send_rrq(struct lpfc_hba *phba, struct lpfc_node_rrq *rrq)
6960 struct lpfc_nodelist *ndlp = lpfc_findnode_did(rrq->vport,
6962 if (lpfc_test_rrq_active(phba, ndlp, rrq->xritag))
6963 return lpfc_issue_els_rrq(rrq->vport, ndlp,
6970 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
6971 * @vport: pointer to a host virtual N_Port data structure.
6972 * @cmdsize: size of the ELS command.
6973 * @oldiocb: pointer to the original lpfc command iocb data structure.
6974 * @ndlp: pointer to a node-list data structure.
6976 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
6977 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
6979 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6980 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6981 * will be stored into the context1 field of the IOCB for the completion
6982 * callback function to the RPL Accept Response ELS command.
6985 * 0 - Successfully issued ACC RPL ELS command
6986 * 1 - Failed to issue ACC RPL ELS command
6989 lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
6990 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
6992 struct lpfc_hba *phba = vport->phba;
6993 IOCB_t *icmd, *oldcmd;
6995 struct lpfc_iocbq *elsiocb;
6998 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
6999 ndlp->nlp_DID, ELS_CMD_ACC);
7004 icmd = &elsiocb->iocb;
7005 oldcmd = &oldiocb->iocb;
7006 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
7007 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
7009 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7010 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
7011 pcmd += sizeof(uint16_t);
7012 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
7013 pcmd += sizeof(uint16_t);
7015 /* Setup the RPL ACC payload */
7016 rpl_rsp.listLen = be32_to_cpu(1);
7018 rpl_rsp.port_num_blk.portNum = 0;
7019 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
7020 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
7021 sizeof(struct lpfc_name));
7022 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
7023 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
7024 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7025 "0120 Xmit ELS RPL ACC response tag x%x "
7026 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
7028 elsiocb->iotag, elsiocb->iocb.ulpContext,
7029 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
7031 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
7032 phba->fc_stat.elsXmitACC++;
7033 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
7035 lpfc_els_free_iocb(phba, elsiocb);
7042 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
7043 * @vport: pointer to a host virtual N_Port data structure.
7044 * @cmdiocb: pointer to lpfc command iocb data structure.
7045 * @ndlp: pointer to a node-list data structure.
7047 * This routine processes Read Port List (RPL) IOCB received as an ELS
7048 * unsolicited event. It first checks the remote port state. If the remote
7049 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
7050 * invokes the lpfc_els_rsp_reject() routine to send reject response.
7051 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
7052 * to accept the RPL.
7055 * 0 - Successfully processed rpl iocb (currently always return 0)
7058 lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7059 struct lpfc_nodelist *ndlp)
7061 struct lpfc_dmabuf *pcmd;
7068 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
7069 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
7070 /* issue rejection response */
7071 stat.un.b.lsRjtRsvd0 = 0;
7072 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
7073 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
7074 stat.un.b.vendorUnique = 0;
7075 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
7077 /* rejected the unsolicited RPL request and done with it */
7081 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7082 lp = (uint32_t *) pcmd->virt;
7083 rpl = (RPL *) (lp + 1);
7084 maxsize = be32_to_cpu(rpl->maxsize);
7086 /* We support only one port */
7087 if ((rpl->index == 0) &&
7089 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
7090 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
7092 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
7094 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
7100 * lpfc_els_rcv_farp - Process an unsolicited farp request els command
7101 * @vport: pointer to a virtual N_Port data structure.
7102 * @cmdiocb: pointer to lpfc command iocb data structure.
7103 * @ndlp: pointer to a node-list data structure.
7105 * This routine processes Fibre Channel Address Resolution Protocol
7106 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
7107 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
7108 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
7109 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
7110 * remote PortName is compared against the FC PortName stored in the @vport
7111 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
7112 * compared against the FC NodeName stored in the @vport data structure.
7113 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
7114 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
7115 * invoked to send out FARP Response to the remote node. Before sending the
7116 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
7117 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
7118 * routine is invoked to log into the remote port first.
7121 * 0 - Either the FARP Match Mode not supported or successfully processed
7124 lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7125 struct lpfc_nodelist *ndlp)
7127 struct lpfc_dmabuf *pcmd;
7131 uint32_t cmd, cnt, did;
7133 icmd = &cmdiocb->iocb;
7134 did = icmd->un.elsreq64.remoteID;
7135 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7136 lp = (uint32_t *) pcmd->virt;
7140 /* FARP-REQ received from DID <did> */
7141 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7142 "0601 FARP-REQ received from DID x%x\n", did);
7143 /* We will only support match on WWPN or WWNN */
7144 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
7149 /* If this FARP command is searching for my portname */
7150 if (fp->Mflags & FARP_MATCH_PORT) {
7151 if (memcmp(&fp->RportName, &vport->fc_portname,
7152 sizeof(struct lpfc_name)) == 0)
7156 /* If this FARP command is searching for my nodename */
7157 if (fp->Mflags & FARP_MATCH_NODE) {
7158 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
7159 sizeof(struct lpfc_name)) == 0)
7164 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
7165 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
7166 /* Log back into the node before sending the FARP. */
7167 if (fp->Rflags & FARP_REQUEST_PLOGI) {
7168 ndlp->nlp_prev_state = ndlp->nlp_state;
7169 lpfc_nlp_set_state(vport, ndlp,
7170 NLP_STE_PLOGI_ISSUE);
7171 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
7174 /* Send a FARP response to that node */
7175 if (fp->Rflags & FARP_REQUEST_FARPR)
7176 lpfc_issue_els_farpr(vport, did, 0);
7183 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
7184 * @vport: pointer to a host virtual N_Port data structure.
7185 * @cmdiocb: pointer to lpfc command iocb data structure.
7186 * @ndlp: pointer to a node-list data structure.
7188 * This routine processes Fibre Channel Address Resolution Protocol
7189 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
7190 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
7191 * the FARP response request.
7194 * 0 - Successfully processed FARPR IOCB (currently always return 0)
7197 lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7198 struct lpfc_nodelist *ndlp)
7200 struct lpfc_dmabuf *pcmd;
7205 icmd = &cmdiocb->iocb;
7206 did = icmd->un.elsreq64.remoteID;
7207 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7208 lp = (uint32_t *) pcmd->virt;
7211 /* FARP-RSP received from DID <did> */
7212 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7213 "0600 FARP-RSP received from DID x%x\n", did);
7214 /* ACCEPT the Farp resp request */
7215 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
7221 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
7222 * @vport: pointer to a host virtual N_Port data structure.
7223 * @cmdiocb: pointer to lpfc command iocb data structure.
7224 * @fan_ndlp: pointer to a node-list data structure.
7226 * This routine processes a Fabric Address Notification (FAN) IOCB
7227 * command received as an ELS unsolicited event. The FAN ELS command will
7228 * only be processed on a physical port (i.e., the @vport represents the
7229 * physical port). The fabric NodeName and PortName from the FAN IOCB are
7230 * compared against those in the phba data structure. If any of those is
7231 * different, the lpfc_initial_flogi() routine is invoked to initialize
7232 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
7233 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
7234 * is invoked to register login to the fabric.
7237 * 0 - Successfully processed fan iocb (currently always return 0).
7240 lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7241 struct lpfc_nodelist *fan_ndlp)
7243 struct lpfc_hba *phba = vport->phba;
7247 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
7248 lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
7250 /* FAN received; Fan does not have a reply sequence */
7251 if ((vport == phba->pport) &&
7252 (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
7253 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
7254 sizeof(struct lpfc_name))) ||
7255 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
7256 sizeof(struct lpfc_name)))) {
7257 /* This port has switched fabrics. FLOGI is required */
7258 lpfc_issue_init_vfi(vport);
7260 /* FAN verified - skip FLOGI */
7261 vport->fc_myDID = vport->fc_prevDID;
7262 if (phba->sli_rev < LPFC_SLI_REV4)
7263 lpfc_issue_fabric_reglogin(vport);
7265 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7266 "3138 Need register VFI: (x%x/%x)\n",
7267 vport->fc_prevDID, vport->fc_myDID);
7268 lpfc_issue_reg_vfi(vport);
7276 * lpfc_els_timeout - Handler funciton to the els timer
7277 * @ptr: holder for the timer function associated data.
7279 * This routine is invoked by the ELS timer after timeout. It posts the ELS
7280 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
7281 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
7282 * up the worker thread. It is for the worker thread to invoke the routine
7283 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
7286 lpfc_els_timeout(unsigned long ptr)
7288 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
7289 struct lpfc_hba *phba = vport->phba;
7290 uint32_t tmo_posted;
7291 unsigned long iflag;
7293 spin_lock_irqsave(&vport->work_port_lock, iflag);
7294 tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
7295 if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING)))
7296 vport->work_port_events |= WORKER_ELS_TMO;
7297 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
7299 if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING)))
7300 lpfc_worker_wake_up(phba);
7306 * lpfc_els_timeout_handler - Process an els timeout event
7307 * @vport: pointer to a virtual N_Port data structure.
7309 * This routine is the actual handler function that processes an ELS timeout
7310 * event. It walks the ELS ring to get and abort all the IOCBs (except the
7311 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
7312 * invoking the lpfc_sli_issue_abort_iotag() routine.
7315 lpfc_els_timeout_handler(struct lpfc_vport *vport)
7317 struct lpfc_hba *phba = vport->phba;
7318 struct lpfc_sli_ring *pring;
7319 struct lpfc_iocbq *tmp_iocb, *piocb;
7321 struct lpfc_dmabuf *pcmd;
7322 uint32_t els_command = 0;
7324 uint32_t remote_ID = 0xffffffff;
7325 LIST_HEAD(abort_list);
7328 timeout = (uint32_t)(phba->fc_ratov << 1);
7330 pring = lpfc_phba_elsring(phba);
7332 if ((phba->pport->load_flag & FC_UNLOADING))
7334 spin_lock_irq(&phba->hbalock);
7335 if (phba->sli_rev == LPFC_SLI_REV4)
7336 spin_lock(&pring->ring_lock);
7338 if ((phba->pport->load_flag & FC_UNLOADING)) {
7339 if (phba->sli_rev == LPFC_SLI_REV4)
7340 spin_unlock(&pring->ring_lock);
7341 spin_unlock_irq(&phba->hbalock);
7345 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
7348 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
7349 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
7350 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
7353 if (piocb->vport != vport)
7356 pcmd = (struct lpfc_dmabuf *) piocb->context2;
7358 els_command = *(uint32_t *) (pcmd->virt);
7360 if (els_command == ELS_CMD_FARP ||
7361 els_command == ELS_CMD_FARPR ||
7362 els_command == ELS_CMD_FDISC)
7365 if (piocb->drvrTimeout > 0) {
7366 if (piocb->drvrTimeout >= timeout)
7367 piocb->drvrTimeout -= timeout;
7369 piocb->drvrTimeout = 0;
7373 remote_ID = 0xffffffff;
7374 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
7375 remote_ID = cmd->un.elsreq64.remoteID;
7377 struct lpfc_nodelist *ndlp;
7378 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
7379 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
7380 remote_ID = ndlp->nlp_DID;
7382 list_add_tail(&piocb->dlist, &abort_list);
7384 if (phba->sli_rev == LPFC_SLI_REV4)
7385 spin_unlock(&pring->ring_lock);
7386 spin_unlock_irq(&phba->hbalock);
7388 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
7390 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7391 "0127 ELS timeout Data: x%x x%x x%x "
7392 "x%x\n", els_command,
7393 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
7394 spin_lock_irq(&phba->hbalock);
7395 list_del_init(&piocb->dlist);
7396 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
7397 spin_unlock_irq(&phba->hbalock);
7400 if (!list_empty(&pring->txcmplq))
7401 if (!(phba->pport->load_flag & FC_UNLOADING))
7402 mod_timer(&vport->els_tmofunc,
7403 jiffies + msecs_to_jiffies(1000 * timeout));
7407 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
7408 * @vport: pointer to a host virtual N_Port data structure.
7410 * This routine is used to clean up all the outstanding ELS commands on a
7411 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
7412 * routine. After that, it walks the ELS transmit queue to remove all the
7413 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
7414 * the IOCBs with a non-NULL completion callback function, the callback
7415 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
7416 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
7417 * callback function, the IOCB will simply be released. Finally, it walks
7418 * the ELS transmit completion queue to issue an abort IOCB to any transmit
7419 * completion queue IOCB that is associated with the @vport and is not
7420 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
7421 * part of the discovery state machine) out to HBA by invoking the
7422 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
7423 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
7424 * the IOCBs are aborted when this function returns.
7427 lpfc_els_flush_cmd(struct lpfc_vport *vport)
7429 LIST_HEAD(abort_list);
7430 struct lpfc_hba *phba = vport->phba;
7431 struct lpfc_sli_ring *pring;
7432 struct lpfc_iocbq *tmp_iocb, *piocb;
7435 lpfc_fabric_abort_vport(vport);
7437 * For SLI3, only the hbalock is required. But SLI4 needs to coordinate
7438 * with the ring insert operation. Because lpfc_sli_issue_abort_iotag
7439 * ultimately grabs the ring_lock, the driver must splice the list into
7440 * a working list and release the locks before calling the abort.
7442 spin_lock_irq(&phba->hbalock);
7443 pring = lpfc_phba_elsring(phba);
7444 if (phba->sli_rev == LPFC_SLI_REV4)
7445 spin_lock(&pring->ring_lock);
7447 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
7448 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
7451 if (piocb->vport != vport)
7453 list_add_tail(&piocb->dlist, &abort_list);
7455 if (phba->sli_rev == LPFC_SLI_REV4)
7456 spin_unlock(&pring->ring_lock);
7457 spin_unlock_irq(&phba->hbalock);
7458 /* Abort each iocb on the aborted list and remove the dlist links. */
7459 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
7460 spin_lock_irq(&phba->hbalock);
7461 list_del_init(&piocb->dlist);
7462 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
7463 spin_unlock_irq(&phba->hbalock);
7465 if (!list_empty(&abort_list))
7466 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7467 "3387 abort list for txq not empty\n");
7468 INIT_LIST_HEAD(&abort_list);
7470 spin_lock_irq(&phba->hbalock);
7471 if (phba->sli_rev == LPFC_SLI_REV4)
7472 spin_lock(&pring->ring_lock);
7474 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
7477 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
7481 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
7482 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
7483 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
7484 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
7485 cmd->ulpCommand == CMD_ABORT_XRI_CN)
7488 if (piocb->vport != vport)
7491 list_del_init(&piocb->list);
7492 list_add_tail(&piocb->list, &abort_list);
7494 if (phba->sli_rev == LPFC_SLI_REV4)
7495 spin_unlock(&pring->ring_lock);
7496 spin_unlock_irq(&phba->hbalock);
7498 /* Cancell all the IOCBs from the completions list */
7499 lpfc_sli_cancel_iocbs(phba, &abort_list,
7500 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
7506 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
7507 * @phba: pointer to lpfc hba data structure.
7509 * This routine is used to clean up all the outstanding ELS commands on a
7510 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
7511 * routine. After that, it walks the ELS transmit queue to remove all the
7512 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
7513 * the IOCBs with the completion callback function associated, the callback
7514 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
7515 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
7516 * callback function associated, the IOCB will simply be released. Finally,
7517 * it walks the ELS transmit completion queue to issue an abort IOCB to any
7518 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
7519 * management plane IOCBs that are not part of the discovery state machine)
7520 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
7523 lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
7525 struct lpfc_vport *vport;
7526 list_for_each_entry(vport, &phba->port_list, listentry)
7527 lpfc_els_flush_cmd(vport);
7533 * lpfc_send_els_failure_event - Posts an ELS command failure event
7534 * @phba: Pointer to hba context object.
7535 * @cmdiocbp: Pointer to command iocb which reported error.
7536 * @rspiocbp: Pointer to response iocb which reported error.
7538 * This function sends an event when there is an ELS command
7542 lpfc_send_els_failure_event(struct lpfc_hba *phba,
7543 struct lpfc_iocbq *cmdiocbp,
7544 struct lpfc_iocbq *rspiocbp)
7546 struct lpfc_vport *vport = cmdiocbp->vport;
7547 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7548 struct lpfc_lsrjt_event lsrjt_event;
7549 struct lpfc_fabric_event_header fabric_event;
7551 struct lpfc_nodelist *ndlp;
7554 ndlp = cmdiocbp->context1;
7555 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
7558 if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) {
7559 lsrjt_event.header.event_type = FC_REG_ELS_EVENT;
7560 lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV;
7561 memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname,
7562 sizeof(struct lpfc_name));
7563 memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename,
7564 sizeof(struct lpfc_name));
7565 pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
7566 cmdiocbp->context2)->virt);
7567 lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0;
7568 stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]);
7569 lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode;
7570 lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp;
7571 fc_host_post_vendor_event(shost,
7572 fc_get_event_number(),
7573 sizeof(lsrjt_event),
7574 (char *)&lsrjt_event,
7578 if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) ||
7579 (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) {
7580 fabric_event.event_type = FC_REG_FABRIC_EVENT;
7581 if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY)
7582 fabric_event.subcategory = LPFC_EVENT_PORT_BUSY;
7584 fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY;
7585 memcpy(fabric_event.wwpn, &ndlp->nlp_portname,
7586 sizeof(struct lpfc_name));
7587 memcpy(fabric_event.wwnn, &ndlp->nlp_nodename,
7588 sizeof(struct lpfc_name));
7589 fc_host_post_vendor_event(shost,
7590 fc_get_event_number(),
7591 sizeof(fabric_event),
7592 (char *)&fabric_event,
7600 * lpfc_send_els_event - Posts unsolicited els event
7601 * @vport: Pointer to vport object.
7602 * @ndlp: Pointer FC node object.
7603 * @cmd: ELS command code.
7605 * This function posts an event when there is an incoming
7606 * unsolicited ELS command.
7609 lpfc_send_els_event(struct lpfc_vport *vport,
7610 struct lpfc_nodelist *ndlp,
7613 struct lpfc_els_event_header *els_data = NULL;
7614 struct lpfc_logo_event *logo_data = NULL;
7615 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7617 if (*payload == ELS_CMD_LOGO) {
7618 logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL);
7620 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7621 "0148 Failed to allocate memory "
7622 "for LOGO event\n");
7625 els_data = &logo_data->header;
7627 els_data = kmalloc(sizeof(struct lpfc_els_event_header),
7630 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7631 "0149 Failed to allocate memory "
7636 els_data->event_type = FC_REG_ELS_EVENT;
7639 els_data->subcategory = LPFC_EVENT_PLOGI_RCV;
7642 els_data->subcategory = LPFC_EVENT_PRLO_RCV;
7645 els_data->subcategory = LPFC_EVENT_ADISC_RCV;
7648 els_data->subcategory = LPFC_EVENT_LOGO_RCV;
7649 /* Copy the WWPN in the LOGO payload */
7650 memcpy(logo_data->logo_wwpn, &payload[2],
7651 sizeof(struct lpfc_name));
7657 memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name));
7658 memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name));
7659 if (*payload == ELS_CMD_LOGO) {
7660 fc_host_post_vendor_event(shost,
7661 fc_get_event_number(),
7662 sizeof(struct lpfc_logo_event),
7667 fc_host_post_vendor_event(shost,
7668 fc_get_event_number(),
7669 sizeof(struct lpfc_els_event_header),
7680 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
7681 * @phba: pointer to lpfc hba data structure.
7682 * @pring: pointer to a SLI ring.
7683 * @vport: pointer to a host virtual N_Port data structure.
7684 * @elsiocb: pointer to lpfc els command iocb data structure.
7686 * This routine is used for processing the IOCB associated with a unsolicited
7687 * event. It first determines whether there is an existing ndlp that matches
7688 * the DID from the unsolicited IOCB. If not, it will create a new one with
7689 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
7690 * IOCB is then used to invoke the proper routine and to set up proper state
7691 * of the discovery state machine.
7694 lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
7695 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
7697 struct Scsi_Host *shost;
7698 struct lpfc_nodelist *ndlp;
7701 uint32_t cmd, did, newnode;
7702 uint8_t rjt_exp, rjt_err = 0;
7703 IOCB_t *icmd = &elsiocb->iocb;
7705 if (!vport || !(elsiocb->context2))
7709 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
7711 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
7712 lpfc_post_buffer(phba, pring, 1);
7714 did = icmd->un.rcvels.remoteID;
7715 if (icmd->ulpStatus) {
7716 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7717 "RCV Unsol ELS: status:x%x/x%x did:x%x",
7718 icmd->ulpStatus, icmd->un.ulpWord[4], did);
7722 /* Check to see if link went down during discovery */
7723 if (lpfc_els_chk_latt(vport))
7726 /* Ignore traffic received during vport shutdown. */
7727 if (vport->load_flag & FC_UNLOADING)
7730 /* If NPort discovery is delayed drop incoming ELS */
7731 if ((vport->fc_flag & FC_DISC_DELAYED) &&
7732 (cmd != ELS_CMD_PLOGI))
7735 ndlp = lpfc_findnode_did(vport, did);
7737 /* Cannot find existing Fabric ndlp, so allocate a new one */
7738 ndlp = lpfc_nlp_init(vport, did);
7741 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
7743 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
7744 ndlp->nlp_type |= NLP_FABRIC;
7745 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
7746 ndlp = lpfc_enable_node(vport, ndlp,
7747 NLP_STE_UNUSED_NODE);
7750 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
7752 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
7753 ndlp->nlp_type |= NLP_FABRIC;
7754 } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
7755 /* This is similar to the new node path */
7756 ndlp = lpfc_nlp_get(ndlp);
7759 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
7763 phba->fc_stat.elsRcvFrame++;
7766 * Do not process any unsolicited ELS commands
7767 * if the ndlp is in DEV_LOSS
7769 shost = lpfc_shost_from_vport(vport);
7770 spin_lock_irq(shost->host_lock);
7771 if (ndlp->nlp_flag & NLP_IN_DEV_LOSS) {
7772 spin_unlock_irq(shost->host_lock);
7775 spin_unlock_irq(shost->host_lock);
7777 elsiocb->context1 = lpfc_nlp_get(ndlp);
7778 elsiocb->vport = vport;
7780 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
7781 cmd &= ELS_CMD_MASK;
7783 /* ELS command <elsCmd> received from NPORT <did> */
7784 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7785 "0112 ELS command x%x received from NPORT x%x "
7786 "Data: x%x x%x x%x x%x\n",
7787 cmd, did, vport->port_state, vport->fc_flag,
7788 vport->fc_myDID, vport->fc_prevDID);
7790 /* reject till our FLOGI completes */
7791 if ((vport->port_state < LPFC_FABRIC_CFG_LINK) &&
7792 (cmd != ELS_CMD_FLOGI)) {
7793 rjt_err = LSRJT_LOGICAL_BSY;
7794 rjt_exp = LSEXP_NOTHING_MORE;
7800 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7801 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
7802 did, vport->port_state, ndlp->nlp_flag);
7804 phba->fc_stat.elsRcvPLOGI++;
7805 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
7806 if (phba->sli_rev == LPFC_SLI_REV4 &&
7807 (phba->pport->fc_flag & FC_PT2PT)) {
7808 vport->fc_prevDID = vport->fc_myDID;
7809 /* Our DID needs to be updated before registering
7810 * the vfi. This is done in lpfc_rcv_plogi but
7811 * that is called after the reg_vfi.
7813 vport->fc_myDID = elsiocb->iocb.un.rcvels.parmRo;
7814 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7815 "3312 Remote port assigned DID x%x "
7816 "%x\n", vport->fc_myDID,
7820 lpfc_send_els_event(vport, ndlp, payload);
7822 /* If Nport discovery is delayed, reject PLOGIs */
7823 if (vport->fc_flag & FC_DISC_DELAYED) {
7824 rjt_err = LSRJT_UNABLE_TPC;
7825 rjt_exp = LSEXP_NOTHING_MORE;
7829 if (vport->port_state < LPFC_DISC_AUTH) {
7830 if (!(phba->pport->fc_flag & FC_PT2PT) ||
7831 (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
7832 rjt_err = LSRJT_UNABLE_TPC;
7833 rjt_exp = LSEXP_NOTHING_MORE;
7838 spin_lock_irq(shost->host_lock);
7839 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
7840 spin_unlock_irq(shost->host_lock);
7842 lpfc_disc_state_machine(vport, ndlp, elsiocb,
7847 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7848 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
7849 did, vport->port_state, ndlp->nlp_flag);
7851 phba->fc_stat.elsRcvFLOGI++;
7852 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
7857 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7858 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
7859 did, vport->port_state, ndlp->nlp_flag);
7861 phba->fc_stat.elsRcvLOGO++;
7862 lpfc_send_els_event(vport, ndlp, payload);
7863 if (vport->port_state < LPFC_DISC_AUTH) {
7864 rjt_err = LSRJT_UNABLE_TPC;
7865 rjt_exp = LSEXP_NOTHING_MORE;
7868 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
7871 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7872 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
7873 did, vport->port_state, ndlp->nlp_flag);
7875 phba->fc_stat.elsRcvPRLO++;
7876 lpfc_send_els_event(vport, ndlp, payload);
7877 if (vport->port_state < LPFC_DISC_AUTH) {
7878 rjt_err = LSRJT_UNABLE_TPC;
7879 rjt_exp = LSEXP_NOTHING_MORE;
7882 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
7885 phba->fc_stat.elsRcvLCB++;
7886 lpfc_els_rcv_lcb(vport, elsiocb, ndlp);
7889 phba->fc_stat.elsRcvRDP++;
7890 lpfc_els_rcv_rdp(vport, elsiocb, ndlp);
7893 phba->fc_stat.elsRcvRSCN++;
7894 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
7899 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7900 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
7901 did, vport->port_state, ndlp->nlp_flag);
7903 lpfc_send_els_event(vport, ndlp, payload);
7904 phba->fc_stat.elsRcvADISC++;
7905 if (vport->port_state < LPFC_DISC_AUTH) {
7906 rjt_err = LSRJT_UNABLE_TPC;
7907 rjt_exp = LSEXP_NOTHING_MORE;
7910 lpfc_disc_state_machine(vport, ndlp, elsiocb,
7914 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7915 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
7916 did, vport->port_state, ndlp->nlp_flag);
7918 phba->fc_stat.elsRcvPDISC++;
7919 if (vport->port_state < LPFC_DISC_AUTH) {
7920 rjt_err = LSRJT_UNABLE_TPC;
7921 rjt_exp = LSEXP_NOTHING_MORE;
7924 lpfc_disc_state_machine(vport, ndlp, elsiocb,
7928 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7929 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
7930 did, vport->port_state, ndlp->nlp_flag);
7932 phba->fc_stat.elsRcvFARPR++;
7933 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
7936 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7937 "RCV FARP: did:x%x/ste:x%x flg:x%x",
7938 did, vport->port_state, ndlp->nlp_flag);
7940 phba->fc_stat.elsRcvFARP++;
7941 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
7944 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7945 "RCV FAN: did:x%x/ste:x%x flg:x%x",
7946 did, vport->port_state, ndlp->nlp_flag);
7948 phba->fc_stat.elsRcvFAN++;
7949 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
7952 case ELS_CMD_NVMEPRLI:
7953 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7954 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
7955 did, vport->port_state, ndlp->nlp_flag);
7957 phba->fc_stat.elsRcvPRLI++;
7958 if ((vport->port_state < LPFC_DISC_AUTH) &&
7959 (vport->fc_flag & FC_FABRIC)) {
7960 rjt_err = LSRJT_UNABLE_TPC;
7961 rjt_exp = LSEXP_NOTHING_MORE;
7964 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
7967 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7968 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
7969 did, vport->port_state, ndlp->nlp_flag);
7971 phba->fc_stat.elsRcvLIRR++;
7972 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
7977 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7978 "RCV RLS: did:x%x/ste:x%x flg:x%x",
7979 did, vport->port_state, ndlp->nlp_flag);
7981 phba->fc_stat.elsRcvRLS++;
7982 lpfc_els_rcv_rls(vport, elsiocb, ndlp);
7987 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7988 "RCV RPS: did:x%x/ste:x%x flg:x%x",
7989 did, vport->port_state, ndlp->nlp_flag);
7991 phba->fc_stat.elsRcvRPS++;
7992 lpfc_els_rcv_rps(vport, elsiocb, ndlp);
7997 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7998 "RCV RPL: did:x%x/ste:x%x flg:x%x",
7999 did, vport->port_state, ndlp->nlp_flag);
8001 phba->fc_stat.elsRcvRPL++;
8002 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
8007 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8008 "RCV RNID: did:x%x/ste:x%x flg:x%x",
8009 did, vport->port_state, ndlp->nlp_flag);
8011 phba->fc_stat.elsRcvRNID++;
8012 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
8017 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8018 "RCV RTV: did:x%x/ste:x%x flg:x%x",
8019 did, vport->port_state, ndlp->nlp_flag);
8020 phba->fc_stat.elsRcvRTV++;
8021 lpfc_els_rcv_rtv(vport, elsiocb, ndlp);
8026 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8027 "RCV RRQ: did:x%x/ste:x%x flg:x%x",
8028 did, vport->port_state, ndlp->nlp_flag);
8030 phba->fc_stat.elsRcvRRQ++;
8031 lpfc_els_rcv_rrq(vport, elsiocb, ndlp);
8036 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8037 "RCV ECHO: did:x%x/ste:x%x flg:x%x",
8038 did, vport->port_state, ndlp->nlp_flag);
8040 phba->fc_stat.elsRcvECHO++;
8041 lpfc_els_rcv_echo(vport, elsiocb, ndlp);
8046 /* receive this due to exchange closed */
8047 rjt_err = LSRJT_UNABLE_TPC;
8048 rjt_exp = LSEXP_INVALID_OX_RX;
8051 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8052 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
8053 cmd, did, vport->port_state);
8055 /* Unsupported ELS command, reject */
8056 rjt_err = LSRJT_CMD_UNSUPPORTED;
8057 rjt_exp = LSEXP_NOTHING_MORE;
8059 /* Unknown ELS command <elsCmd> received from NPORT <did> */
8060 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8061 "0115 Unknown ELS command x%x "
8062 "received from NPORT x%x\n", cmd, did);
8069 /* check if need to LS_RJT received ELS cmd */
8071 memset(&stat, 0, sizeof(stat));
8072 stat.un.b.lsRjtRsnCode = rjt_err;
8073 stat.un.b.lsRjtRsnCodeExp = rjt_exp;
8074 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
8078 lpfc_nlp_put(elsiocb->context1);
8079 elsiocb->context1 = NULL;
8083 if (vport && !(vport->load_flag & FC_UNLOADING))
8084 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8085 "0111 Dropping received ELS cmd "
8086 "Data: x%x x%x x%x\n",
8087 icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout);
8088 phba->fc_stat.elsRcvDrop++;
8092 * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
8093 * @phba: pointer to lpfc hba data structure.
8094 * @pring: pointer to a SLI ring.
8095 * @elsiocb: pointer to lpfc els iocb data structure.
8097 * This routine is used to process an unsolicited event received from a SLI
8098 * (Service Level Interface) ring. The actual processing of the data buffer
8099 * associated with the unsolicited event is done by invoking the routine
8100 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
8101 * SLI ring on which the unsolicited event was received.
8104 lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
8105 struct lpfc_iocbq *elsiocb)
8107 struct lpfc_vport *vport = phba->pport;
8108 IOCB_t *icmd = &elsiocb->iocb;
8110 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
8111 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
8113 elsiocb->context1 = NULL;
8114 elsiocb->context2 = NULL;
8115 elsiocb->context3 = NULL;
8117 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
8118 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
8119 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
8120 (icmd->un.ulpWord[4] & IOERR_PARAM_MASK) ==
8121 IOERR_RCV_BUFFER_WAITING) {
8122 phba->fc_stat.NoRcvBuf++;
8123 /* Not enough posted buffers; Try posting more buffers */
8124 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
8125 lpfc_post_buffer(phba, pring, 0);
8129 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
8130 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
8131 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
8132 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
8133 vport = phba->pport;
8135 vport = lpfc_find_vport_by_vpid(phba,
8136 icmd->unsli3.rcvsli3.vpi);
8139 /* If there are no BDEs associated
8140 * with this IOCB, there is nothing to do.
8142 if (icmd->ulpBdeCount == 0)
8145 /* type of ELS cmd is first 32bit word
8148 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
8149 elsiocb->context2 = bdeBuf1;
8151 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
8152 icmd->un.cont64[0].addrLow);
8153 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
8157 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
8159 * The different unsolicited event handlers would tell us
8160 * if they are done with "mp" by setting context2 to NULL.
8162 if (elsiocb->context2) {
8163 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
8164 elsiocb->context2 = NULL;
8167 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
8168 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
8169 icmd->ulpBdeCount == 2) {
8170 elsiocb->context2 = bdeBuf2;
8171 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
8172 /* free mp if we are done with it */
8173 if (elsiocb->context2) {
8174 lpfc_in_buf_free(phba, elsiocb->context2);
8175 elsiocb->context2 = NULL;
8181 lpfc_start_fdmi(struct lpfc_vport *vport)
8183 struct lpfc_nodelist *ndlp;
8185 /* If this is the first time, allocate an ndlp and initialize
8186 * it. Otherwise, make sure the node is enabled and then do the
8189 ndlp = lpfc_findnode_did(vport, FDMI_DID);
8191 ndlp = lpfc_nlp_init(vport, FDMI_DID);
8193 ndlp->nlp_type |= NLP_FABRIC;
8198 if (!NLP_CHK_NODE_ACT(ndlp))
8199 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_NPR_NODE);
8202 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
8203 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
8208 * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
8209 * @phba: pointer to lpfc hba data structure.
8210 * @vport: pointer to a virtual N_Port data structure.
8212 * This routine issues a Port Login (PLOGI) to the Name Server with
8213 * State Change Request (SCR) for a @vport. This routine will create an
8214 * ndlp for the Name Server associated to the @vport if such node does
8215 * not already exist. The PLOGI to Name Server is issued by invoking the
8216 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
8217 * (FDMI) is configured to the @vport, a FDMI node will be created and
8218 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
8221 lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
8223 struct lpfc_nodelist *ndlp;
8224 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8227 * If lpfc_delay_discovery parameter is set and the clean address
8228 * bit is cleared and fc fabric parameters chenged, delay FC NPort
8231 spin_lock_irq(shost->host_lock);
8232 if (vport->fc_flag & FC_DISC_DELAYED) {
8233 spin_unlock_irq(shost->host_lock);
8234 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
8235 "3334 Delay fc port discovery for %d seconds\n",
8237 mod_timer(&vport->delayed_disc_tmo,
8238 jiffies + msecs_to_jiffies(1000 * phba->fc_ratov));
8241 spin_unlock_irq(shost->host_lock);
8243 ndlp = lpfc_findnode_did(vport, NameServer_DID);
8245 ndlp = lpfc_nlp_init(vport, NameServer_DID);
8247 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
8248 lpfc_disc_start(vport);
8251 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
8252 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8253 "0251 NameServer login: no memory\n");
8256 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
8257 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
8259 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
8260 lpfc_disc_start(vport);
8263 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
8264 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8265 "0348 NameServer login: node freed\n");
8269 ndlp->nlp_type |= NLP_FABRIC;
8271 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
8273 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
8274 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
8275 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8276 "0252 Cannot issue NameServer login\n");
8280 if ((phba->cfg_enable_SmartSAN ||
8281 (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) &&
8282 (vport->load_flag & FC_ALLOW_FDMI))
8283 lpfc_start_fdmi(vport);
8287 * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
8288 * @phba: pointer to lpfc hba data structure.
8289 * @pmb: pointer to the driver internal queue element for mailbox command.
8291 * This routine is the completion callback function to register new vport
8292 * mailbox command. If the new vport mailbox command completes successfully,
8293 * the fabric registration login shall be performed on physical port (the
8294 * new vport created is actually a physical port, with VPI 0) or the port
8295 * login to Name Server for State Change Request (SCR) will be performed
8296 * on virtual port (real virtual port, with VPI greater than 0).
8299 lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
8301 struct lpfc_vport *vport = pmb->vport;
8302 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8303 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
8304 MAILBOX_t *mb = &pmb->u.mb;
8307 spin_lock_irq(shost->host_lock);
8308 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
8309 spin_unlock_irq(shost->host_lock);
8311 if (mb->mbxStatus) {
8312 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
8313 "0915 Register VPI failed : Status: x%x"
8314 " upd bit: x%x \n", mb->mbxStatus,
8315 mb->un.varRegVpi.upd);
8316 if (phba->sli_rev == LPFC_SLI_REV4 &&
8317 mb->un.varRegVpi.upd)
8318 goto mbox_err_exit ;
8320 switch (mb->mbxStatus) {
8321 case 0x11: /* unsupported feature */
8322 case 0x9603: /* max_vpi exceeded */
8323 case 0x9602: /* Link event since CLEAR_LA */
8324 /* giving up on vport registration */
8325 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
8326 spin_lock_irq(shost->host_lock);
8327 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
8328 spin_unlock_irq(shost->host_lock);
8329 lpfc_can_disctmo(vport);
8331 /* If reg_vpi fail with invalid VPI status, re-init VPI */
8333 spin_lock_irq(shost->host_lock);
8334 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
8335 spin_unlock_irq(shost->host_lock);
8336 lpfc_init_vpi(phba, pmb, vport->vpi);
8338 pmb->mbox_cmpl = lpfc_init_vpi_cmpl;
8339 rc = lpfc_sli_issue_mbox(phba, pmb,
8341 if (rc == MBX_NOT_FINISHED) {
8342 lpfc_printf_vlog(vport,
8344 "2732 Failed to issue INIT_VPI"
8345 " mailbox command\n");
8352 /* Try to recover from this error */
8353 if (phba->sli_rev == LPFC_SLI_REV4)
8354 lpfc_sli4_unreg_all_rpis(vport);
8355 lpfc_mbx_unreg_vpi(vport);
8356 spin_lock_irq(shost->host_lock);
8357 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
8358 spin_unlock_irq(shost->host_lock);
8359 if (mb->mbxStatus == MBX_NOT_FINISHED)
8361 if ((vport->port_type == LPFC_PHYSICAL_PORT) &&
8362 !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG)) {
8363 if (phba->sli_rev == LPFC_SLI_REV4)
8364 lpfc_issue_init_vfi(vport);
8366 lpfc_initial_flogi(vport);
8368 lpfc_initial_fdisc(vport);
8373 spin_lock_irq(shost->host_lock);
8374 vport->vpi_state |= LPFC_VPI_REGISTERED;
8375 spin_unlock_irq(shost->host_lock);
8376 if (vport == phba->pport) {
8377 if (phba->sli_rev < LPFC_SLI_REV4)
8378 lpfc_issue_fabric_reglogin(vport);
8381 * If the physical port is instantiated using
8382 * FDISC, do not start vport discovery.
8384 if (vport->port_state != LPFC_FDISC)
8385 lpfc_start_fdiscs(phba);
8386 lpfc_do_scr_ns_plogi(phba, vport);
8389 lpfc_do_scr_ns_plogi(phba, vport);
8392 /* Now, we decrement the ndlp reference count held for this
8397 mempool_free(pmb, phba->mbox_mem_pool);
8402 * lpfc_register_new_vport - Register a new vport with a HBA
8403 * @phba: pointer to lpfc hba data structure.
8404 * @vport: pointer to a host virtual N_Port data structure.
8405 * @ndlp: pointer to a node-list data structure.
8407 * This routine registers the @vport as a new virtual port with a HBA.
8408 * It is done through a registering vpi mailbox command.
8411 lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
8412 struct lpfc_nodelist *ndlp)
8414 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8417 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
8419 lpfc_reg_vpi(vport, mbox);
8420 mbox->vport = vport;
8421 mbox->context2 = lpfc_nlp_get(ndlp);
8422 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
8423 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
8424 == MBX_NOT_FINISHED) {
8425 /* mailbox command not success, decrement ndlp
8426 * reference count for this command
8429 mempool_free(mbox, phba->mbox_mem_pool);
8431 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
8432 "0253 Register VPI: Can't send mbox\n");
8436 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
8437 "0254 Register VPI: no memory\n");
8443 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
8444 spin_lock_irq(shost->host_lock);
8445 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
8446 spin_unlock_irq(shost->host_lock);
8451 * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer
8452 * @phba: pointer to lpfc hba data structure.
8454 * This routine cancels the retry delay timers to all the vports.
8457 lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba)
8459 struct lpfc_vport **vports;
8460 struct lpfc_nodelist *ndlp;
8461 uint32_t link_state;
8464 /* Treat this failure as linkdown for all vports */
8465 link_state = phba->link_state;
8466 lpfc_linkdown(phba);
8467 phba->link_state = link_state;
8469 vports = lpfc_create_vport_work_array(phba);
8472 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
8473 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
8475 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
8476 lpfc_els_flush_cmd(vports[i]);
8478 lpfc_destroy_vport_work_array(phba, vports);
8483 * lpfc_retry_pport_discovery - Start timer to retry FLOGI.
8484 * @phba: pointer to lpfc hba data structure.
8486 * This routine abort all pending discovery commands and
8487 * start a timer to retry FLOGI for the physical port
8491 lpfc_retry_pport_discovery(struct lpfc_hba *phba)
8493 struct lpfc_nodelist *ndlp;
8494 struct Scsi_Host *shost;
8496 /* Cancel the all vports retry delay retry timers */
8497 lpfc_cancel_all_vport_retry_delay_timer(phba);
8499 /* If fabric require FLOGI, then re-instantiate physical login */
8500 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
8504 shost = lpfc_shost_from_vport(phba->pport);
8505 mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000));
8506 spin_lock_irq(shost->host_lock);
8507 ndlp->nlp_flag |= NLP_DELAY_TMO;
8508 spin_unlock_irq(shost->host_lock);
8509 ndlp->nlp_last_elscmd = ELS_CMD_FLOGI;
8510 phba->pport->port_state = LPFC_FLOGI;
8515 * lpfc_fabric_login_reqd - Check if FLOGI required.
8516 * @phba: pointer to lpfc hba data structure.
8517 * @cmdiocb: pointer to FDISC command iocb.
8518 * @rspiocb: pointer to FDISC response iocb.
8520 * This routine checks if a FLOGI is reguired for FDISC
8524 lpfc_fabric_login_reqd(struct lpfc_hba *phba,
8525 struct lpfc_iocbq *cmdiocb,
8526 struct lpfc_iocbq *rspiocb)
8529 if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) ||
8530 (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED))
8537 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
8538 * @phba: pointer to lpfc hba data structure.
8539 * @cmdiocb: pointer to lpfc command iocb data structure.
8540 * @rspiocb: pointer to lpfc response iocb data structure.
8542 * This routine is the completion callback function to a Fabric Discover
8543 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
8544 * single threaded, each FDISC completion callback function will reset
8545 * the discovery timer for all vports such that the timers will not get
8546 * unnecessary timeout. The function checks the FDISC IOCB status. If error
8547 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
8548 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
8549 * assigned to the vport has been changed with the completion of the FDISC
8550 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
8551 * are unregistered from the HBA, and then the lpfc_register_new_vport()
8552 * routine is invoked to register new vport with the HBA. Otherwise, the
8553 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
8554 * Server for State Change Request (SCR).
8557 lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
8558 struct lpfc_iocbq *rspiocb)
8560 struct lpfc_vport *vport = cmdiocb->vport;
8561 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8562 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
8563 struct lpfc_nodelist *np;
8564 struct lpfc_nodelist *next_np;
8565 IOCB_t *irsp = &rspiocb->iocb;
8566 struct lpfc_iocbq *piocb;
8567 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
8568 struct serv_parm *sp;
8569 uint8_t fabric_param_changed;
8571 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
8572 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
8573 irsp->ulpStatus, irsp->un.ulpWord[4],
8575 /* Since all FDISCs are being single threaded, we
8576 * must reset the discovery timer for ALL vports
8577 * waiting to send FDISC when one completes.
8579 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
8580 lpfc_set_disctmo(piocb->vport);
8583 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
8584 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
8585 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
8587 if (irsp->ulpStatus) {
8589 if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) {
8590 lpfc_retry_pport_discovery(phba);
8594 /* Check for retry */
8595 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
8598 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8599 "0126 FDISC failed. (x%x/x%x)\n",
8600 irsp->ulpStatus, irsp->un.ulpWord[4]);
8603 spin_lock_irq(shost->host_lock);
8604 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
8605 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
8606 vport->fc_flag |= FC_FABRIC;
8607 if (vport->phba->fc_topology == LPFC_TOPOLOGY_LOOP)
8608 vport->fc_flag |= FC_PUBLIC_LOOP;
8609 spin_unlock_irq(shost->host_lock);
8611 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
8612 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
8613 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
8616 sp = prsp->virt + sizeof(uint32_t);
8617 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
8618 memcpy(&vport->fabric_portname, &sp->portName,
8619 sizeof(struct lpfc_name));
8620 memcpy(&vport->fabric_nodename, &sp->nodeName,
8621 sizeof(struct lpfc_name));
8622 if (fabric_param_changed &&
8623 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
8624 /* If our NportID changed, we need to ensure all
8625 * remaining NPORTs get unreg_login'ed so we can
8628 list_for_each_entry_safe(np, next_np,
8629 &vport->fc_nodes, nlp_listp) {
8630 if (!NLP_CHK_NODE_ACT(ndlp) ||
8631 (np->nlp_state != NLP_STE_NPR_NODE) ||
8632 !(np->nlp_flag & NLP_NPR_ADISC))
8634 spin_lock_irq(shost->host_lock);
8635 np->nlp_flag &= ~NLP_NPR_ADISC;
8636 spin_unlock_irq(shost->host_lock);
8637 lpfc_unreg_rpi(vport, np);
8639 lpfc_cleanup_pending_mbox(vport);
8641 if (phba->sli_rev == LPFC_SLI_REV4)
8642 lpfc_sli4_unreg_all_rpis(vport);
8644 lpfc_mbx_unreg_vpi(vport);
8645 spin_lock_irq(shost->host_lock);
8646 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
8647 if (phba->sli_rev == LPFC_SLI_REV4)
8648 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
8650 vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG;
8651 spin_unlock_irq(shost->host_lock);
8652 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
8653 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
8655 * Driver needs to re-reg VPI in order for f/w
8656 * to update the MAC address.
8658 lpfc_register_new_vport(phba, vport, ndlp);
8662 if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)
8663 lpfc_issue_init_vpi(vport);
8664 else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
8665 lpfc_register_new_vport(phba, vport, ndlp);
8667 lpfc_do_scr_ns_plogi(phba, vport);
8670 if (vport->fc_vport->vport_state != FC_VPORT_NO_FABRIC_RSCS)
8671 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
8672 /* Cancel discovery timer */
8673 lpfc_can_disctmo(vport);
8676 lpfc_els_free_iocb(phba, cmdiocb);
8680 * lpfc_issue_els_fdisc - Issue a fdisc iocb command
8681 * @vport: pointer to a virtual N_Port data structure.
8682 * @ndlp: pointer to a node-list data structure.
8683 * @retry: number of retries to the command IOCB.
8685 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
8686 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
8687 * routine to issue the IOCB, which makes sure only one outstanding fabric
8688 * IOCB will be sent off HBA at any given time.
8690 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
8691 * will be incremented by 1 for holding the ndlp and the reference to ndlp
8692 * will be stored into the context1 field of the IOCB for the completion
8693 * callback function to the FDISC ELS command.
8696 * 0 - Successfully issued fdisc iocb command
8697 * 1 - Failed to issue fdisc iocb command
8700 lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
8703 struct lpfc_hba *phba = vport->phba;
8705 struct lpfc_iocbq *elsiocb;
8706 struct serv_parm *sp;
8709 int did = ndlp->nlp_DID;
8712 vport->port_state = LPFC_FDISC;
8713 vport->fc_myDID = 0;
8714 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
8715 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
8718 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
8719 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8720 "0255 Issue FDISC: no IOCB\n");
8724 icmd = &elsiocb->iocb;
8725 icmd->un.elsreq64.myID = 0;
8726 icmd->un.elsreq64.fl = 1;
8729 * SLI3 ports require a different context type value than SLI4.
8730 * Catch SLI3 ports here and override the prep.
8732 if (phba->sli_rev == LPFC_SLI_REV3) {
8737 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
8738 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
8739 pcmd += sizeof(uint32_t); /* CSP Word 1 */
8740 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
8741 sp = (struct serv_parm *) pcmd;
8742 /* Setup CSPs accordingly for Fabric */
8743 sp->cmn.e_d_tov = 0;
8744 sp->cmn.w2.r_a_tov = 0;
8745 sp->cmn.virtual_fabric_support = 0;
8746 sp->cls1.classValid = 0;
8747 sp->cls2.seqDelivery = 1;
8748 sp->cls3.seqDelivery = 1;
8750 pcmd += sizeof(uint32_t); /* CSP Word 2 */
8751 pcmd += sizeof(uint32_t); /* CSP Word 3 */
8752 pcmd += sizeof(uint32_t); /* CSP Word 4 */
8753 pcmd += sizeof(uint32_t); /* Port Name */
8754 memcpy(pcmd, &vport->fc_portname, 8);
8755 pcmd += sizeof(uint32_t); /* Node Name */
8756 pcmd += sizeof(uint32_t); /* Node Name */
8757 memcpy(pcmd, &vport->fc_nodename, 8);
8758 memset(sp->un.vendorVersion, 0, sizeof(sp->un.vendorVersion));
8759 lpfc_set_disctmo(vport);
8761 phba->fc_stat.elsXmitFDISC++;
8762 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
8764 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
8765 "Issue FDISC: did:x%x",
8768 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
8769 if (rc == IOCB_ERROR) {
8770 lpfc_els_free_iocb(phba, elsiocb);
8771 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
8772 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8773 "0256 Issue FDISC: Cannot send IOCB\n");
8776 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
8781 * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
8782 * @phba: pointer to lpfc hba data structure.
8783 * @cmdiocb: pointer to lpfc command iocb data structure.
8784 * @rspiocb: pointer to lpfc response iocb data structure.
8786 * This routine is the completion callback function to the issuing of a LOGO
8787 * ELS command off a vport. It frees the command IOCB and then decrement the
8788 * reference count held on ndlp for this completion function, indicating that
8789 * the reference to the ndlp is no long needed. Note that the
8790 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
8791 * callback function and an additional explicit ndlp reference decrementation
8792 * will trigger the actual release of the ndlp.
8795 lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
8796 struct lpfc_iocbq *rspiocb)
8798 struct lpfc_vport *vport = cmdiocb->vport;
8800 struct lpfc_nodelist *ndlp;
8801 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8803 ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
8804 irsp = &rspiocb->iocb;
8805 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
8806 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
8807 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
8809 lpfc_els_free_iocb(phba, cmdiocb);
8810 vport->unreg_vpi_cmpl = VPORT_ERROR;
8812 /* Trigger the release of the ndlp after logo */
8815 /* NPIV LOGO completes to NPort <nlp_DID> */
8816 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
8817 "2928 NPIV LOGO completes to NPort x%x "
8818 "Data: x%x x%x x%x x%x\n",
8819 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
8820 irsp->ulpTimeout, vport->num_disc_nodes);
8822 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
8823 spin_lock_irq(shost->host_lock);
8824 vport->fc_flag &= ~FC_NDISC_ACTIVE;
8825 vport->fc_flag &= ~FC_FABRIC;
8826 spin_unlock_irq(shost->host_lock);
8827 lpfc_can_disctmo(vport);
8832 * lpfc_issue_els_npiv_logo - Issue a logo off a vport
8833 * @vport: pointer to a virtual N_Port data structure.
8834 * @ndlp: pointer to a node-list data structure.
8836 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
8838 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
8839 * will be incremented by 1 for holding the ndlp and the reference to ndlp
8840 * will be stored into the context1 field of the IOCB for the completion
8841 * callback function to the LOGO ELS command.
8844 * 0 - Successfully issued logo off the @vport
8845 * 1 - Failed to issue logo off the @vport
8848 lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
8850 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8851 struct lpfc_hba *phba = vport->phba;
8852 struct lpfc_iocbq *elsiocb;
8856 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
8857 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
8862 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
8863 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
8864 pcmd += sizeof(uint32_t);
8866 /* Fill in LOGO payload */
8867 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
8868 pcmd += sizeof(uint32_t);
8869 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
8871 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
8872 "Issue LOGO npiv did:x%x flg:x%x",
8873 ndlp->nlp_DID, ndlp->nlp_flag, 0);
8875 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
8876 spin_lock_irq(shost->host_lock);
8877 ndlp->nlp_flag |= NLP_LOGO_SND;
8878 spin_unlock_irq(shost->host_lock);
8879 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
8881 spin_lock_irq(shost->host_lock);
8882 ndlp->nlp_flag &= ~NLP_LOGO_SND;
8883 spin_unlock_irq(shost->host_lock);
8884 lpfc_els_free_iocb(phba, elsiocb);
8891 * lpfc_fabric_block_timeout - Handler function to the fabric block timer
8892 * @ptr: holder for the timer function associated data.
8894 * This routine is invoked by the fabric iocb block timer after
8895 * timeout. It posts the fabric iocb block timeout event by setting the
8896 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
8897 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
8898 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
8899 * posted event WORKER_FABRIC_BLOCK_TMO.
8902 lpfc_fabric_block_timeout(unsigned long ptr)
8904 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
8905 unsigned long iflags;
8906 uint32_t tmo_posted;
8908 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
8909 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
8911 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
8912 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
8915 lpfc_worker_wake_up(phba);
8920 * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
8921 * @phba: pointer to lpfc hba data structure.
8923 * This routine issues one fabric iocb from the driver internal list to
8924 * the HBA. It first checks whether it's ready to issue one fabric iocb to
8925 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
8926 * remove one pending fabric iocb from the driver internal list and invokes
8927 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
8930 lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
8932 struct lpfc_iocbq *iocb;
8933 unsigned long iflags;
8939 spin_lock_irqsave(&phba->hbalock, iflags);
8940 /* Post any pending iocb to the SLI layer */
8941 if (atomic_read(&phba->fabric_iocb_count) == 0) {
8942 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
8945 /* Increment fabric iocb count to hold the position */
8946 atomic_inc(&phba->fabric_iocb_count);
8948 spin_unlock_irqrestore(&phba->hbalock, iflags);
8950 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
8951 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
8952 iocb->iocb_flag |= LPFC_IO_FABRIC;
8954 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
8955 "Fabric sched1: ste:x%x",
8956 iocb->vport->port_state, 0, 0);
8958 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
8960 if (ret == IOCB_ERROR) {
8961 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
8962 iocb->fabric_iocb_cmpl = NULL;
8963 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
8965 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
8966 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
8967 iocb->iocb_cmpl(phba, iocb, iocb);
8969 atomic_dec(&phba->fabric_iocb_count);
8978 * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
8979 * @phba: pointer to lpfc hba data structure.
8981 * This routine unblocks the issuing fabric iocb command. The function
8982 * will clear the fabric iocb block bit and then invoke the routine
8983 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
8984 * from the driver internal fabric iocb list.
8987 lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
8989 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
8991 lpfc_resume_fabric_iocbs(phba);
8996 * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
8997 * @phba: pointer to lpfc hba data structure.
8999 * This routine blocks the issuing fabric iocb for a specified amount of
9000 * time (currently 100 ms). This is done by set the fabric iocb block bit
9001 * and set up a timeout timer for 100ms. When the block bit is set, no more
9002 * fabric iocb will be issued out of the HBA.
9005 lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
9009 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
9010 /* Start a timer to unblock fabric iocbs after 100ms */
9012 mod_timer(&phba->fabric_block_timer,
9013 jiffies + msecs_to_jiffies(100));
9019 * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
9020 * @phba: pointer to lpfc hba data structure.
9021 * @cmdiocb: pointer to lpfc command iocb data structure.
9022 * @rspiocb: pointer to lpfc response iocb data structure.
9024 * This routine is the callback function that is put to the fabric iocb's
9025 * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
9026 * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
9027 * function first restores and invokes the original iocb's callback function
9028 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
9029 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
9032 lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
9033 struct lpfc_iocbq *rspiocb)
9037 BUG_ON((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC);
9039 switch (rspiocb->iocb.ulpStatus) {
9040 case IOSTAT_NPORT_RJT:
9041 case IOSTAT_FABRIC_RJT:
9042 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
9043 lpfc_block_fabric_iocbs(phba);
9047 case IOSTAT_NPORT_BSY:
9048 case IOSTAT_FABRIC_BSY:
9049 lpfc_block_fabric_iocbs(phba);
9053 stat.un.lsRjtError =
9054 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
9055 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
9056 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
9057 lpfc_block_fabric_iocbs(phba);
9061 BUG_ON(atomic_read(&phba->fabric_iocb_count) == 0);
9063 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
9064 cmdiocb->fabric_iocb_cmpl = NULL;
9065 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
9066 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
9068 atomic_dec(&phba->fabric_iocb_count);
9069 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
9070 /* Post any pending iocbs to HBA */
9071 lpfc_resume_fabric_iocbs(phba);
9076 * lpfc_issue_fabric_iocb - Issue a fabric iocb command
9077 * @phba: pointer to lpfc hba data structure.
9078 * @iocb: pointer to lpfc command iocb data structure.
9080 * This routine is used as the top-level API for issuing a fabric iocb command
9081 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
9082 * function makes sure that only one fabric bound iocb will be outstanding at
9083 * any given time. As such, this function will first check to see whether there
9084 * is already an outstanding fabric iocb on the wire. If so, it will put the
9085 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
9086 * issued later. Otherwise, it will issue the iocb on the wire and update the
9087 * fabric iocb count it indicate that there is one fabric iocb on the wire.
9089 * Note, this implementation has a potential sending out fabric IOCBs out of
9090 * order. The problem is caused by the construction of the "ready" boolen does
9091 * not include the condition that the internal fabric IOCB list is empty. As
9092 * such, it is possible a fabric IOCB issued by this routine might be "jump"
9093 * ahead of the fabric IOCBs in the internal list.
9096 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
9097 * IOCB_ERROR - failed to issue fabric iocb
9100 lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
9102 unsigned long iflags;
9106 BUG_ON(atomic_read(&phba->fabric_iocb_count) > 1);
9108 spin_lock_irqsave(&phba->hbalock, iflags);
9109 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
9110 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
9113 /* Increment fabric iocb count to hold the position */
9114 atomic_inc(&phba->fabric_iocb_count);
9115 spin_unlock_irqrestore(&phba->hbalock, iflags);
9117 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
9118 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
9119 iocb->iocb_flag |= LPFC_IO_FABRIC;
9121 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
9122 "Fabric sched2: ste:x%x",
9123 iocb->vport->port_state, 0, 0);
9125 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
9127 if (ret == IOCB_ERROR) {
9128 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
9129 iocb->fabric_iocb_cmpl = NULL;
9130 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
9131 atomic_dec(&phba->fabric_iocb_count);
9134 spin_lock_irqsave(&phba->hbalock, iflags);
9135 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
9136 spin_unlock_irqrestore(&phba->hbalock, iflags);
9143 * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
9144 * @vport: pointer to a virtual N_Port data structure.
9146 * This routine aborts all the IOCBs associated with a @vport from the
9147 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
9148 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
9149 * list, removes each IOCB associated with the @vport off the list, set the
9150 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
9151 * associated with the IOCB.
9153 static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
9155 LIST_HEAD(completions);
9156 struct lpfc_hba *phba = vport->phba;
9157 struct lpfc_iocbq *tmp_iocb, *piocb;
9159 spin_lock_irq(&phba->hbalock);
9160 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
9163 if (piocb->vport != vport)
9166 list_move_tail(&piocb->list, &completions);
9168 spin_unlock_irq(&phba->hbalock);
9170 /* Cancel all the IOCBs from the completions list */
9171 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
9176 * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
9177 * @ndlp: pointer to a node-list data structure.
9179 * This routine aborts all the IOCBs associated with an @ndlp from the
9180 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
9181 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
9182 * list, removes each IOCB associated with the @ndlp off the list, set the
9183 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
9184 * associated with the IOCB.
9186 void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
9188 LIST_HEAD(completions);
9189 struct lpfc_hba *phba = ndlp->phba;
9190 struct lpfc_iocbq *tmp_iocb, *piocb;
9191 struct lpfc_sli_ring *pring;
9193 pring = lpfc_phba_elsring(phba);
9195 spin_lock_irq(&phba->hbalock);
9196 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
9198 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
9200 list_move_tail(&piocb->list, &completions);
9203 spin_unlock_irq(&phba->hbalock);
9205 /* Cancel all the IOCBs from the completions list */
9206 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
9211 * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
9212 * @phba: pointer to lpfc hba data structure.
9214 * This routine aborts all the IOCBs currently on the driver internal
9215 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
9216 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
9217 * list, removes IOCBs off the list, set the status feild to
9218 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
9221 void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
9223 LIST_HEAD(completions);
9225 spin_lock_irq(&phba->hbalock);
9226 list_splice_init(&phba->fabric_iocb_list, &completions);
9227 spin_unlock_irq(&phba->hbalock);
9229 /* Cancel all the IOCBs from the completions list */
9230 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
9235 * lpfc_sli4_vport_delete_els_xri_aborted -Remove all ndlp references for vport
9236 * @vport: pointer to lpfc vport data structure.
9238 * This routine is invoked by the vport cleanup for deletions and the cleanup
9239 * for an ndlp on removal.
9242 lpfc_sli4_vport_delete_els_xri_aborted(struct lpfc_vport *vport)
9244 struct lpfc_hba *phba = vport->phba;
9245 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
9246 unsigned long iflag = 0;
9248 spin_lock_irqsave(&phba->hbalock, iflag);
9249 spin_lock(&phba->sli4_hba.sgl_list_lock);
9250 list_for_each_entry_safe(sglq_entry, sglq_next,
9251 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
9252 if (sglq_entry->ndlp && sglq_entry->ndlp->vport == vport)
9253 sglq_entry->ndlp = NULL;
9255 spin_unlock(&phba->sli4_hba.sgl_list_lock);
9256 spin_unlock_irqrestore(&phba->hbalock, iflag);
9261 * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
9262 * @phba: pointer to lpfc hba data structure.
9263 * @axri: pointer to the els xri abort wcqe structure.
9265 * This routine is invoked by the worker thread to process a SLI4 slow-path
9269 lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba,
9270 struct sli4_wcqe_xri_aborted *axri)
9272 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
9273 uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri);
9276 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
9277 unsigned long iflag = 0;
9278 struct lpfc_nodelist *ndlp;
9279 struct lpfc_sli_ring *pring;
9281 pring = lpfc_phba_elsring(phba);
9283 spin_lock_irqsave(&phba->hbalock, iflag);
9284 spin_lock(&phba->sli4_hba.sgl_list_lock);
9285 list_for_each_entry_safe(sglq_entry, sglq_next,
9286 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
9287 if (sglq_entry->sli4_xritag == xri) {
9288 list_del(&sglq_entry->list);
9289 ndlp = sglq_entry->ndlp;
9290 sglq_entry->ndlp = NULL;
9291 list_add_tail(&sglq_entry->list,
9292 &phba->sli4_hba.lpfc_els_sgl_list);
9293 sglq_entry->state = SGL_FREED;
9294 spin_unlock(&phba->sli4_hba.sgl_list_lock);
9295 spin_unlock_irqrestore(&phba->hbalock, iflag);
9296 lpfc_set_rrq_active(phba, ndlp,
9297 sglq_entry->sli4_lxritag,
9300 /* Check if TXQ queue needs to be serviced */
9301 if (!(list_empty(&pring->txq)))
9302 lpfc_worker_wake_up(phba);
9306 spin_unlock(&phba->sli4_hba.sgl_list_lock);
9307 lxri = lpfc_sli4_xri_inrange(phba, xri);
9308 if (lxri == NO_XRI) {
9309 spin_unlock_irqrestore(&phba->hbalock, iflag);
9312 spin_lock(&phba->sli4_hba.sgl_list_lock);
9313 sglq_entry = __lpfc_get_active_sglq(phba, lxri);
9314 if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) {
9315 spin_unlock(&phba->sli4_hba.sgl_list_lock);
9316 spin_unlock_irqrestore(&phba->hbalock, iflag);
9319 sglq_entry->state = SGL_XRI_ABORTED;
9320 spin_unlock(&phba->sli4_hba.sgl_list_lock);
9321 spin_unlock_irqrestore(&phba->hbalock, iflag);
9325 /* lpfc_sli_abts_recover_port - Recover a port that failed a BLS_ABORT req.
9326 * @vport: pointer to virtual port object.
9327 * @ndlp: nodelist pointer for the impacted node.
9329 * The driver calls this routine in response to an SLI4 XRI ABORT CQE
9330 * or an SLI3 ASYNC_STATUS_CN event from the port. For either event,
9331 * the driver is required to send a LOGO to the remote node before it
9332 * attempts to recover its login to the remote node.
9335 lpfc_sli_abts_recover_port(struct lpfc_vport *vport,
9336 struct lpfc_nodelist *ndlp)
9338 struct Scsi_Host *shost;
9339 struct lpfc_hba *phba;
9340 unsigned long flags = 0;
9342 shost = lpfc_shost_from_vport(vport);
9344 if (ndlp->nlp_state != NLP_STE_MAPPED_NODE) {
9345 lpfc_printf_log(phba, KERN_INFO,
9346 LOG_SLI, "3093 No rport recovery needed. "
9347 "rport in state 0x%x\n", ndlp->nlp_state);
9350 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
9351 "3094 Start rport recovery on shost id 0x%x "
9352 "fc_id 0x%06x vpi 0x%x rpi 0x%x state 0x%x "
9354 shost->host_no, ndlp->nlp_DID,
9355 vport->vpi, ndlp->nlp_rpi, ndlp->nlp_state,
9358 * The rport is not responding. Remove the FCP-2 flag to prevent
9359 * an ADISC in the follow-up recovery code.
9361 spin_lock_irqsave(shost->host_lock, flags);
9362 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
9363 spin_unlock_irqrestore(shost->host_lock, flags);
9364 lpfc_issue_els_logo(vport, ndlp, 0);
9365 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);