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 fabric_param_changed = 1;
610 * Word 1 Bit 31 in common service parameter is overloaded.
611 * Word 1 Bit 31 in FLOGI request is multiple NPort request
612 * Word 1 Bit 31 in FLOGI response is clean address bit
614 * If fabric parameter is changed and clean address bit is
615 * cleared delay nport discovery if
616 * - vport->fc_prevDID != 0 (not initial discovery) OR
617 * - lpfc_delay_discovery module parameter is set.
619 if (fabric_param_changed && !sp->cmn.clean_address_bit &&
620 (vport->fc_prevDID || phba->cfg_delay_discovery)) {
621 spin_lock_irq(shost->host_lock);
622 vport->fc_flag |= FC_DISC_DELAYED;
623 spin_unlock_irq(shost->host_lock);
626 return fabric_param_changed;
631 * lpfc_cmpl_els_flogi_fabric - Completion function for flogi to a fabric port
632 * @vport: pointer to a host virtual N_Port data structure.
633 * @ndlp: pointer to a node-list data structure.
634 * @sp: pointer to service parameter data structure.
635 * @irsp: pointer to the IOCB within the lpfc response IOCB.
637 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
638 * function to handle the completion of a Fabric Login (FLOGI) into a fabric
639 * port in a fabric topology. It properly sets up the parameters to the @ndlp
640 * from the IOCB response. It also check the newly assigned N_Port ID to the
641 * @vport against the previously assigned N_Port ID. If it is different from
642 * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine
643 * is invoked on all the remaining nodes with the @vport to unregister the
644 * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin()
645 * is invoked to register login to the fabric.
648 * 0 - Success (currently, always return 0)
651 lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
652 struct serv_parm *sp, IOCB_t *irsp)
654 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
655 struct lpfc_hba *phba = vport->phba;
656 struct lpfc_nodelist *np;
657 struct lpfc_nodelist *next_np;
658 uint8_t fabric_param_changed;
660 spin_lock_irq(shost->host_lock);
661 vport->fc_flag |= FC_FABRIC;
662 spin_unlock_irq(shost->host_lock);
664 phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
665 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
666 phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
668 phba->fc_edtovResol = sp->cmn.edtovResolution;
669 phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
671 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
672 spin_lock_irq(shost->host_lock);
673 vport->fc_flag |= FC_PUBLIC_LOOP;
674 spin_unlock_irq(shost->host_lock);
677 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
678 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
679 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name));
680 ndlp->nlp_class_sup = 0;
681 if (sp->cls1.classValid)
682 ndlp->nlp_class_sup |= FC_COS_CLASS1;
683 if (sp->cls2.classValid)
684 ndlp->nlp_class_sup |= FC_COS_CLASS2;
685 if (sp->cls3.classValid)
686 ndlp->nlp_class_sup |= FC_COS_CLASS3;
687 if (sp->cls4.classValid)
688 ndlp->nlp_class_sup |= FC_COS_CLASS4;
689 ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
690 sp->cmn.bbRcvSizeLsb;
692 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
693 if (fabric_param_changed) {
694 /* Reset FDMI attribute masks based on config parameter */
695 if (phba->cfg_enable_SmartSAN ||
696 (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) {
697 /* Setup appropriate attribute masks */
698 vport->fdmi_hba_mask = LPFC_FDMI2_HBA_ATTR;
699 if (phba->cfg_enable_SmartSAN)
700 vport->fdmi_port_mask = LPFC_FDMI2_SMART_ATTR;
702 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
704 vport->fdmi_hba_mask = 0;
705 vport->fdmi_port_mask = 0;
709 memcpy(&vport->fabric_portname, &sp->portName,
710 sizeof(struct lpfc_name));
711 memcpy(&vport->fabric_nodename, &sp->nodeName,
712 sizeof(struct lpfc_name));
713 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
715 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
716 if (sp->cmn.response_multiple_NPort) {
717 lpfc_printf_vlog(vport, KERN_WARNING,
719 "1816 FLOGI NPIV supported, "
720 "response data 0x%x\n",
721 sp->cmn.response_multiple_NPort);
722 spin_lock_irq(&phba->hbalock);
723 phba->link_flag |= LS_NPIV_FAB_SUPPORTED;
724 spin_unlock_irq(&phba->hbalock);
726 /* Because we asked f/w for NPIV it still expects us
727 to call reg_vnpid atleast for the physcial host */
728 lpfc_printf_vlog(vport, KERN_WARNING,
730 "1817 Fabric does not support NPIV "
731 "- configuring single port mode.\n");
732 spin_lock_irq(&phba->hbalock);
733 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
734 spin_unlock_irq(&phba->hbalock);
739 * For FC we need to do some special processing because of the SLI
740 * Port's default settings of the Common Service Parameters.
742 if ((phba->sli_rev == LPFC_SLI_REV4) &&
743 (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC)) {
744 /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */
745 if (fabric_param_changed)
746 lpfc_unregister_fcf_prep(phba);
748 /* This should just update the VFI CSPs*/
749 if (vport->fc_flag & FC_VFI_REGISTERED)
750 lpfc_issue_reg_vfi(vport);
753 if (fabric_param_changed &&
754 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
756 /* If our NportID changed, we need to ensure all
757 * remaining NPORTs get unreg_login'ed.
759 list_for_each_entry_safe(np, next_np,
760 &vport->fc_nodes, nlp_listp) {
761 if (!NLP_CHK_NODE_ACT(np))
763 if ((np->nlp_state != NLP_STE_NPR_NODE) ||
764 !(np->nlp_flag & NLP_NPR_ADISC))
766 spin_lock_irq(shost->host_lock);
767 np->nlp_flag &= ~NLP_NPR_ADISC;
768 spin_unlock_irq(shost->host_lock);
769 lpfc_unreg_rpi(vport, np);
771 lpfc_cleanup_pending_mbox(vport);
773 if (phba->sli_rev == LPFC_SLI_REV4) {
774 lpfc_sli4_unreg_all_rpis(vport);
775 lpfc_mbx_unreg_vpi(vport);
776 spin_lock_irq(shost->host_lock);
777 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
778 spin_unlock_irq(shost->host_lock);
782 * For SLI3 and SLI4, the VPI needs to be reregistered in
783 * response to this fabric parameter change event.
785 spin_lock_irq(shost->host_lock);
786 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
787 spin_unlock_irq(shost->host_lock);
788 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
789 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
791 * Driver needs to re-reg VPI in order for f/w
792 * to update the MAC address.
794 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
795 lpfc_register_new_vport(phba, vport, ndlp);
799 if (phba->sli_rev < LPFC_SLI_REV4) {
800 lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
801 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED &&
802 vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
803 lpfc_register_new_vport(phba, vport, ndlp);
805 lpfc_issue_fabric_reglogin(vport);
807 ndlp->nlp_type |= NLP_FABRIC;
808 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
809 if ((!(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) &&
810 (vport->vpi_state & LPFC_VPI_REGISTERED)) {
811 lpfc_start_fdiscs(phba);
812 lpfc_do_scr_ns_plogi(phba, vport);
813 } else if (vport->fc_flag & FC_VFI_REGISTERED)
814 lpfc_issue_init_vpi(vport);
816 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
817 "3135 Need register VFI: (x%x/%x)\n",
818 vport->fc_prevDID, vport->fc_myDID);
819 lpfc_issue_reg_vfi(vport);
826 * lpfc_cmpl_els_flogi_nport - Completion function for flogi to an N_Port
827 * @vport: pointer to a host virtual N_Port data structure.
828 * @ndlp: pointer to a node-list data structure.
829 * @sp: pointer to service parameter data structure.
831 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
832 * function to handle the completion of a Fabric Login (FLOGI) into an N_Port
833 * in a point-to-point topology. First, the @vport's N_Port Name is compared
834 * with the received N_Port Name: if the @vport's N_Port Name is greater than
835 * the received N_Port Name lexicographically, this node shall assign local
836 * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and
837 * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise,
838 * this node shall just wait for the remote node to issue PLOGI and assign
846 lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
847 struct serv_parm *sp)
849 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
850 struct lpfc_hba *phba = vport->phba;
854 spin_lock_irq(shost->host_lock);
855 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
856 vport->fc_flag |= FC_PT2PT;
857 spin_unlock_irq(shost->host_lock);
859 /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */
860 if ((phba->sli_rev == LPFC_SLI_REV4) && phba->fc_topology_changed) {
861 lpfc_unregister_fcf_prep(phba);
863 spin_lock_irq(shost->host_lock);
864 vport->fc_flag &= ~FC_VFI_REGISTERED;
865 spin_unlock_irq(shost->host_lock);
866 phba->fc_topology_changed = 0;
869 rc = memcmp(&vport->fc_portname, &sp->portName,
870 sizeof(vport->fc_portname));
873 /* This side will initiate the PLOGI */
874 spin_lock_irq(shost->host_lock);
875 vport->fc_flag |= FC_PT2PT_PLOGI;
876 spin_unlock_irq(shost->host_lock);
879 * N_Port ID cannot be 0, set our Id to LocalID
880 * the other side will be RemoteID.
885 vport->fc_myDID = PT2PT_LocalID;
887 /* Decrement ndlp reference count indicating that ndlp can be
888 * safely released when other references to it are done.
892 ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
895 * Cannot find existing Fabric ndlp, so allocate a
898 ndlp = lpfc_nlp_init(vport, PT2PT_RemoteID);
901 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
902 ndlp = lpfc_enable_node(vport, ndlp,
903 NLP_STE_UNUSED_NODE);
908 memcpy(&ndlp->nlp_portname, &sp->portName,
909 sizeof(struct lpfc_name));
910 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
911 sizeof(struct lpfc_name));
912 /* Set state will put ndlp onto node list if not already done */
913 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
914 spin_lock_irq(shost->host_lock);
915 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
916 spin_unlock_irq(shost->host_lock);
918 /* This side will wait for the PLOGI, decrement ndlp reference
919 * count indicating that ndlp can be released when other
920 * references to it are done.
924 /* If we are pt2pt with another NPort, force NPIV off! */
925 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
927 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
931 lpfc_config_link(phba, mbox);
933 mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link;
935 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
936 if (rc == MBX_NOT_FINISHED) {
937 mempool_free(mbox, phba->mbox_mem_pool);
947 * lpfc_cmpl_els_flogi - Completion callback function for flogi
948 * @phba: pointer to lpfc hba data structure.
949 * @cmdiocb: pointer to lpfc command iocb data structure.
950 * @rspiocb: pointer to lpfc response iocb data structure.
952 * This routine is the top-level completion callback function for issuing
953 * a Fabric Login (FLOGI) command. If the response IOCB reported error,
954 * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If
955 * retry has been made (either immediately or delayed with lpfc_els_retry()
956 * returning 1), the command IOCB will be released and function returned.
957 * If the retry attempt has been given up (possibly reach the maximum
958 * number of retries), one additional decrement of ndlp reference shall be
959 * invoked before going out after releasing the command IOCB. This will
960 * actually release the remote node (Note, lpfc_els_free_iocb() will also
961 * invoke one decrement of ndlp reference count). If no error reported in
962 * the IOCB status, the command Port ID field is used to determine whether
963 * this is a point-to-point topology or a fabric topology: if the Port ID
964 * field is assigned, it is a fabric topology; otherwise, it is a
965 * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or
966 * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the
967 * specific topology completion conditions.
970 lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
971 struct lpfc_iocbq *rspiocb)
973 struct lpfc_vport *vport = cmdiocb->vport;
974 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
975 IOCB_t *irsp = &rspiocb->iocb;
976 struct lpfc_nodelist *ndlp = cmdiocb->context1;
977 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
978 struct serv_parm *sp;
982 /* Check to see if link went down during discovery */
983 if (lpfc_els_chk_latt(vport)) {
984 /* One additional decrement on node reference count to
985 * trigger the release of the node
991 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
992 "FLOGI cmpl: status:x%x/x%x state:x%x",
993 irsp->ulpStatus, irsp->un.ulpWord[4],
996 if (irsp->ulpStatus) {
998 * In case of FIP mode, perform roundrobin FCF failover
999 * due to new FCF discovery
1001 if ((phba->hba_flag & HBA_FIP_SUPPORT) &&
1002 (phba->fcf.fcf_flag & FCF_DISCOVERY)) {
1003 if (phba->link_state < LPFC_LINK_UP)
1004 goto stop_rr_fcf_flogi;
1005 if ((phba->fcoe_cvl_eventtag_attn ==
1006 phba->fcoe_cvl_eventtag) &&
1007 (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
1008 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1010 goto stop_rr_fcf_flogi;
1012 phba->fcoe_cvl_eventtag_attn =
1013 phba->fcoe_cvl_eventtag;
1014 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
1015 "2611 FLOGI failed on FCF (x%x), "
1016 "status:x%x/x%x, tmo:x%x, perform "
1017 "roundrobin FCF failover\n",
1018 phba->fcf.current_rec.fcf_indx,
1019 irsp->ulpStatus, irsp->un.ulpWord[4],
1021 lpfc_sli4_set_fcf_flogi_fail(phba,
1022 phba->fcf.current_rec.fcf_indx);
1023 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
1024 rc = lpfc_sli4_fcf_rr_next_proc(vport, fcf_index);
1031 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1032 "2858 FLOGI failure Status:x%x/x%x TMO:x%x "
1034 irsp->ulpStatus, irsp->un.ulpWord[4],
1035 irsp->ulpTimeout, phba->hba_flag,
1036 phba->fcf.fcf_flag);
1038 /* Check for retry */
1039 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
1043 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1044 "0100 FLOGI failure Status:x%x/x%x TMO:x%x\n",
1045 irsp->ulpStatus, irsp->un.ulpWord[4],
1048 /* FLOGI failed, so there is no fabric */
1049 spin_lock_irq(shost->host_lock);
1050 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
1051 spin_unlock_irq(shost->host_lock);
1053 /* If private loop, then allow max outstanding els to be
1054 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
1055 * alpa map would take too long otherwise.
1057 if (phba->alpa_map[0] == 0)
1058 vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
1059 if ((phba->sli_rev == LPFC_SLI_REV4) &&
1060 (!(vport->fc_flag & FC_VFI_REGISTERED) ||
1061 (vport->fc_prevDID != vport->fc_myDID) ||
1062 phba->fc_topology_changed)) {
1063 if (vport->fc_flag & FC_VFI_REGISTERED) {
1064 if (phba->fc_topology_changed) {
1065 lpfc_unregister_fcf_prep(phba);
1066 spin_lock_irq(shost->host_lock);
1067 vport->fc_flag &= ~FC_VFI_REGISTERED;
1068 spin_unlock_irq(shost->host_lock);
1069 phba->fc_topology_changed = 0;
1071 lpfc_sli4_unreg_all_rpis(vport);
1075 /* Do not register VFI if the driver aborted FLOGI */
1076 if (!lpfc_error_lost_link(irsp))
1077 lpfc_issue_reg_vfi(vport);
1083 spin_lock_irq(shost->host_lock);
1084 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
1085 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
1086 spin_unlock_irq(shost->host_lock);
1089 * The FLogI succeeded. Sync the data for the CPU before
1092 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
1095 sp = prsp->virt + sizeof(uint32_t);
1097 /* FLOGI completes successfully */
1098 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1099 "0101 FLOGI completes successfully, I/O tag:x%x, "
1100 "Data: x%x x%x x%x x%x x%x x%x\n", cmdiocb->iotag,
1101 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
1102 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution,
1103 vport->port_state, vport->fc_flag);
1105 if (vport->port_state == LPFC_FLOGI) {
1107 * If Common Service Parameters indicate Nport
1108 * we are point to point, if Fport we are Fabric.
1111 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
1112 else if (!(phba->hba_flag & HBA_FCOE_MODE))
1113 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
1115 lpfc_printf_vlog(vport, KERN_ERR,
1117 "2831 FLOGI response with cleared Fabric "
1118 "bit fcf_index 0x%x "
1119 "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x "
1121 "%02x%02x%02x%02x%02x%02x%02x%02x\n",
1122 phba->fcf.current_rec.fcf_indx,
1123 phba->fcf.current_rec.switch_name[0],
1124 phba->fcf.current_rec.switch_name[1],
1125 phba->fcf.current_rec.switch_name[2],
1126 phba->fcf.current_rec.switch_name[3],
1127 phba->fcf.current_rec.switch_name[4],
1128 phba->fcf.current_rec.switch_name[5],
1129 phba->fcf.current_rec.switch_name[6],
1130 phba->fcf.current_rec.switch_name[7],
1131 phba->fcf.current_rec.fabric_name[0],
1132 phba->fcf.current_rec.fabric_name[1],
1133 phba->fcf.current_rec.fabric_name[2],
1134 phba->fcf.current_rec.fabric_name[3],
1135 phba->fcf.current_rec.fabric_name[4],
1136 phba->fcf.current_rec.fabric_name[5],
1137 phba->fcf.current_rec.fabric_name[6],
1138 phba->fcf.current_rec.fabric_name[7]);
1140 spin_lock_irq(&phba->hbalock);
1141 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
1142 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
1143 spin_unlock_irq(&phba->hbalock);
1147 /* Mark the FCF discovery process done */
1148 if (phba->hba_flag & HBA_FIP_SUPPORT)
1149 lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP |
1151 "2769 FLOGI to FCF (x%x) "
1152 "completed successfully\n",
1153 phba->fcf.current_rec.fcf_indx);
1154 spin_lock_irq(&phba->hbalock);
1155 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
1156 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
1157 spin_unlock_irq(&phba->hbalock);
1163 spin_lock_irq(&phba->hbalock);
1164 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
1165 spin_unlock_irq(&phba->hbalock);
1169 if (!lpfc_error_lost_link(irsp)) {
1170 /* FLOGI failed, so just use loop map to make discovery list */
1171 lpfc_disc_list_loopmap(vport);
1173 /* Start discovery */
1174 lpfc_disc_start(vport);
1175 } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
1176 (((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
1177 IOERR_SLI_ABORTED) &&
1178 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
1179 IOERR_SLI_DOWN))) &&
1180 (phba->link_state != LPFC_CLEAR_LA)) {
1181 /* If FLOGI failed enable link interrupt. */
1182 lpfc_issue_clear_la(phba, vport);
1185 lpfc_els_free_iocb(phba, cmdiocb);
1189 * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport
1190 * @vport: pointer to a host virtual N_Port data structure.
1191 * @ndlp: pointer to a node-list data structure.
1192 * @retry: number of retries to the command IOCB.
1194 * This routine issues a Fabric Login (FLOGI) Request ELS command
1195 * for a @vport. The initiator service parameters are put into the payload
1196 * of the FLOGI Request IOCB and the top-level callback function pointer
1197 * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
1198 * function field. The lpfc_issue_fabric_iocb routine is invoked to send
1199 * out FLOGI ELS command with one outstanding fabric IOCB at a time.
1201 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1202 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1203 * will be stored into the context1 field of the IOCB for the completion
1204 * callback function to the FLOGI ELS command.
1207 * 0 - successfully issued flogi iocb for @vport
1208 * 1 - failed to issue flogi iocb for @vport
1211 lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1214 struct lpfc_hba *phba = vport->phba;
1215 struct serv_parm *sp;
1217 struct lpfc_iocbq *elsiocb;
1223 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
1224 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1225 ndlp->nlp_DID, ELS_CMD_FLOGI);
1230 icmd = &elsiocb->iocb;
1231 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1233 /* For FLOGI request, remainder of payload is service parameters */
1234 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
1235 pcmd += sizeof(uint32_t);
1236 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
1237 sp = (struct serv_parm *) pcmd;
1239 /* Setup CSPs accordingly for Fabric */
1240 sp->cmn.e_d_tov = 0;
1241 sp->cmn.w2.r_a_tov = 0;
1242 sp->cmn.virtual_fabric_support = 0;
1243 sp->cls1.classValid = 0;
1244 if (sp->cmn.fcphLow < FC_PH3)
1245 sp->cmn.fcphLow = FC_PH3;
1246 if (sp->cmn.fcphHigh < FC_PH3)
1247 sp->cmn.fcphHigh = FC_PH3;
1249 if (phba->sli_rev == LPFC_SLI_REV4) {
1250 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
1251 LPFC_SLI_INTF_IF_TYPE_0) {
1252 elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1);
1253 elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1);
1254 /* FLOGI needs to be 3 for WQE FCFI */
1255 /* Set the fcfi to the fcfi we registered with */
1256 elsiocb->iocb.ulpContext = phba->fcf.fcfi;
1258 /* Can't do SLI4 class2 without support sequence coalescing */
1259 sp->cls2.classValid = 0;
1260 sp->cls2.seqDelivery = 0;
1262 /* Historical, setting sequential-delivery bit for SLI3 */
1263 sp->cls2.seqDelivery = (sp->cls2.classValid) ? 1 : 0;
1264 sp->cls3.seqDelivery = (sp->cls3.classValid) ? 1 : 0;
1265 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
1266 sp->cmn.request_multiple_Nport = 1;
1267 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
1271 sp->cmn.request_multiple_Nport = 0;
1274 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
1275 icmd->un.elsreq64.myID = 0;
1276 icmd->un.elsreq64.fl = 1;
1279 tmo = phba->fc_ratov;
1280 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
1281 lpfc_set_disctmo(vport);
1282 phba->fc_ratov = tmo;
1284 phba->fc_stat.elsXmitFLOGI++;
1285 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
1287 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1288 "Issue FLOGI: opt:x%x",
1289 phba->sli3_options, 0, 0);
1291 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
1292 if (rc == IOCB_ERROR) {
1293 lpfc_els_free_iocb(phba, elsiocb);
1300 * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs
1301 * @phba: pointer to lpfc hba data structure.
1303 * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
1304 * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
1305 * list and issues an abort IOCB commond on each outstanding IOCB that
1306 * contains a active Fabric_DID ndlp. Note that this function is to issue
1307 * the abort IOCB command on all the outstanding IOCBs, thus when this
1308 * function returns, it does not guarantee all the IOCBs are actually aborted.
1311 * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0)
1314 lpfc_els_abort_flogi(struct lpfc_hba *phba)
1316 struct lpfc_sli_ring *pring;
1317 struct lpfc_iocbq *iocb, *next_iocb;
1318 struct lpfc_nodelist *ndlp;
1321 /* Abort outstanding I/O on NPort <nlp_DID> */
1322 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
1323 "0201 Abort outstanding I/O on NPort x%x\n",
1326 pring = lpfc_phba_elsring(phba);
1329 * Check the txcmplq for an iocb that matches the nport the driver is
1332 spin_lock_irq(&phba->hbalock);
1333 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
1335 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR) {
1336 ndlp = (struct lpfc_nodelist *)(iocb->context1);
1337 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
1338 (ndlp->nlp_DID == Fabric_DID))
1339 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
1342 spin_unlock_irq(&phba->hbalock);
1348 * lpfc_initial_flogi - Issue an initial fabric login for a vport
1349 * @vport: pointer to a host virtual N_Port data structure.
1351 * This routine issues an initial Fabric Login (FLOGI) for the @vport
1352 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1353 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1354 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1355 * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
1356 * is then invoked with the @vport and the ndlp to perform the FLOGI for the
1360 * 0 - failed to issue initial flogi for @vport
1361 * 1 - successfully issued initial flogi for @vport
1364 lpfc_initial_flogi(struct lpfc_vport *vport)
1366 struct lpfc_nodelist *ndlp;
1368 vport->port_state = LPFC_FLOGI;
1369 lpfc_set_disctmo(vport);
1371 /* First look for the Fabric ndlp */
1372 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1374 /* Cannot find existing Fabric ndlp, so allocate a new one */
1375 ndlp = lpfc_nlp_init(vport, Fabric_DID);
1378 /* Set the node type */
1379 ndlp->nlp_type |= NLP_FABRIC;
1380 /* Put ndlp onto node list */
1381 lpfc_enqueue_node(vport, ndlp);
1382 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1383 /* re-setup ndlp without removing from node list */
1384 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1389 if (lpfc_issue_els_flogi(vport, ndlp, 0)) {
1390 /* This decrement of reference count to node shall kick off
1391 * the release of the node.
1400 * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport
1401 * @vport: pointer to a host virtual N_Port data structure.
1403 * This routine issues an initial Fabric Discover (FDISC) for the @vport
1404 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1405 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1406 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1407 * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
1408 * is then invoked with the @vport and the ndlp to perform the FDISC for the
1412 * 0 - failed to issue initial fdisc for @vport
1413 * 1 - successfully issued initial fdisc for @vport
1416 lpfc_initial_fdisc(struct lpfc_vport *vport)
1418 struct lpfc_nodelist *ndlp;
1420 /* First look for the Fabric ndlp */
1421 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1423 /* Cannot find existing Fabric ndlp, so allocate a new one */
1424 ndlp = lpfc_nlp_init(vport, Fabric_DID);
1427 /* Put ndlp onto node list */
1428 lpfc_enqueue_node(vport, ndlp);
1429 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1430 /* re-setup ndlp without removing from node list */
1431 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1436 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
1437 /* decrement node reference count to trigger the release of
1447 * lpfc_more_plogi - Check and issue remaining plogis for a vport
1448 * @vport: pointer to a host virtual N_Port data structure.
1450 * This routine checks whether there are more remaining Port Logins
1451 * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
1452 * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
1453 * to issue ELS PLOGIs up to the configured discover threads with the
1454 * @vport (@vport->cfg_discovery_threads). The function also decrement
1455 * the @vport's num_disc_node by 1 if it is not already 0.
1458 lpfc_more_plogi(struct lpfc_vport *vport)
1460 if (vport->num_disc_nodes)
1461 vport->num_disc_nodes--;
1463 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
1464 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1465 "0232 Continue discovery with %d PLOGIs to go "
1466 "Data: x%x x%x x%x\n",
1467 vport->num_disc_nodes, vport->fc_plogi_cnt,
1468 vport->fc_flag, vport->port_state);
1469 /* Check to see if there are more PLOGIs to be sent */
1470 if (vport->fc_flag & FC_NLP_MORE)
1471 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
1472 lpfc_els_disc_plogi(vport);
1478 * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp
1479 * @phba: pointer to lpfc hba data structure.
1480 * @prsp: pointer to response IOCB payload.
1481 * @ndlp: pointer to a node-list data structure.
1483 * This routine checks and indicates whether the WWPN of an N_Port, retrieved
1484 * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
1485 * The following cases are considered N_Port confirmed:
1486 * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
1487 * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
1488 * it does not have WWPN assigned either. If the WWPN is confirmed, the
1489 * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
1490 * 1) if there is a node on vport list other than the @ndlp with the same
1491 * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
1492 * on that node to release the RPI associated with the node; 2) if there is
1493 * no node found on vport list with the same WWPN of the N_Port PLOGI logged
1494 * into, a new node shall be allocated (or activated). In either case, the
1495 * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
1496 * be released and the new_ndlp shall be put on to the vport node list and
1497 * its pointer returned as the confirmed node.
1499 * Note that before the @ndlp got "released", the keepDID from not-matching
1500 * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
1501 * of the @ndlp. This is because the release of @ndlp is actually to put it
1502 * into an inactive state on the vport node list and the vport node list
1503 * management algorithm does not allow two node with a same DID.
1506 * pointer to the PLOGI N_Port @ndlp
1508 static struct lpfc_nodelist *
1509 lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
1510 struct lpfc_nodelist *ndlp)
1512 struct lpfc_vport *vport = ndlp->vport;
1513 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1514 struct lpfc_nodelist *new_ndlp;
1515 struct lpfc_rport_data *rdata;
1516 struct fc_rport *rport;
1517 struct serv_parm *sp;
1518 uint8_t name[sizeof(struct lpfc_name)];
1519 uint32_t rc, keepDID = 0, keep_nlp_flag = 0;
1520 uint16_t keep_nlp_state;
1523 unsigned long *active_rrqs_xri_bitmap = NULL;
1525 /* Fabric nodes can have the same WWPN so we don't bother searching
1526 * by WWPN. Just return the ndlp that was given to us.
1528 if (ndlp->nlp_type & NLP_FABRIC)
1531 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
1532 memset(name, 0, sizeof(struct lpfc_name));
1534 /* Now we find out if the NPort we are logging into, matches the WWPN
1535 * we have for that ndlp. If not, we have some work to do.
1537 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
1539 if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp))
1541 if (phba->sli_rev == LPFC_SLI_REV4) {
1542 active_rrqs_xri_bitmap = mempool_alloc(phba->active_rrq_pool,
1544 if (active_rrqs_xri_bitmap)
1545 memset(active_rrqs_xri_bitmap, 0,
1546 phba->cfg_rrq_xri_bitmap_sz);
1549 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1550 "3178 PLOGI confirm: ndlp %p x%x: new_ndlp %p\n",
1551 ndlp, ndlp->nlp_DID, new_ndlp);
1554 rc = memcmp(&ndlp->nlp_portname, name,
1555 sizeof(struct lpfc_name));
1557 if (active_rrqs_xri_bitmap)
1558 mempool_free(active_rrqs_xri_bitmap,
1559 phba->active_rrq_pool);
1562 new_ndlp = lpfc_nlp_init(vport, ndlp->nlp_DID);
1564 if (active_rrqs_xri_bitmap)
1565 mempool_free(active_rrqs_xri_bitmap,
1566 phba->active_rrq_pool);
1569 } else if (!NLP_CHK_NODE_ACT(new_ndlp)) {
1570 rc = memcmp(&ndlp->nlp_portname, name,
1571 sizeof(struct lpfc_name));
1573 if (active_rrqs_xri_bitmap)
1574 mempool_free(active_rrqs_xri_bitmap,
1575 phba->active_rrq_pool);
1578 new_ndlp = lpfc_enable_node(vport, new_ndlp,
1579 NLP_STE_UNUSED_NODE);
1581 if (active_rrqs_xri_bitmap)
1582 mempool_free(active_rrqs_xri_bitmap,
1583 phba->active_rrq_pool);
1586 keepDID = new_ndlp->nlp_DID;
1587 if ((phba->sli_rev == LPFC_SLI_REV4) && active_rrqs_xri_bitmap)
1588 memcpy(active_rrqs_xri_bitmap,
1589 new_ndlp->active_rrqs_xri_bitmap,
1590 phba->cfg_rrq_xri_bitmap_sz);
1592 keepDID = new_ndlp->nlp_DID;
1593 if (phba->sli_rev == LPFC_SLI_REV4 &&
1594 active_rrqs_xri_bitmap)
1595 memcpy(active_rrqs_xri_bitmap,
1596 new_ndlp->active_rrqs_xri_bitmap,
1597 phba->cfg_rrq_xri_bitmap_sz);
1600 lpfc_unreg_rpi(vport, new_ndlp);
1601 new_ndlp->nlp_DID = ndlp->nlp_DID;
1602 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
1603 if (phba->sli_rev == LPFC_SLI_REV4)
1604 memcpy(new_ndlp->active_rrqs_xri_bitmap,
1605 ndlp->active_rrqs_xri_bitmap,
1606 phba->cfg_rrq_xri_bitmap_sz);
1608 spin_lock_irq(shost->host_lock);
1609 keep_nlp_flag = new_ndlp->nlp_flag;
1610 new_ndlp->nlp_flag = ndlp->nlp_flag;
1611 ndlp->nlp_flag = keep_nlp_flag;
1612 spin_unlock_irq(shost->host_lock);
1614 /* Set nlp_states accordingly */
1615 keep_nlp_state = new_ndlp->nlp_state;
1616 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
1618 /* Move this back to NPR state */
1619 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
1620 /* The new_ndlp is replacing ndlp totally, so we need
1621 * to put ndlp on UNUSED list and try to free it.
1623 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1624 "3179 PLOGI confirm NEW: %x %x\n",
1625 new_ndlp->nlp_DID, keepDID);
1627 /* Fix up the rport accordingly */
1628 rport = ndlp->rport;
1630 rdata = rport->dd_data;
1631 if (rdata->pnode == ndlp) {
1632 /* break the link before dropping the ref */
1635 rdata->pnode = lpfc_nlp_get(new_ndlp);
1636 new_ndlp->rport = rport;
1638 new_ndlp->nlp_type = ndlp->nlp_type;
1640 /* We shall actually free the ndlp with both nlp_DID and
1641 * nlp_portname fields equals 0 to avoid any ndlp on the
1642 * nodelist never to be used.
1644 if (ndlp->nlp_DID == 0) {
1645 spin_lock_irq(&phba->ndlp_lock);
1646 NLP_SET_FREE_REQ(ndlp);
1647 spin_unlock_irq(&phba->ndlp_lock);
1650 /* Two ndlps cannot have the same did on the nodelist */
1651 ndlp->nlp_DID = keepDID;
1652 if (phba->sli_rev == LPFC_SLI_REV4 &&
1653 active_rrqs_xri_bitmap)
1654 memcpy(ndlp->active_rrqs_xri_bitmap,
1655 active_rrqs_xri_bitmap,
1656 phba->cfg_rrq_xri_bitmap_sz);
1658 if (!NLP_CHK_NODE_ACT(ndlp))
1659 lpfc_drop_node(vport, ndlp);
1662 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1663 "3180 PLOGI confirm SWAP: %x %x\n",
1664 new_ndlp->nlp_DID, keepDID);
1666 lpfc_unreg_rpi(vport, ndlp);
1668 /* Two ndlps cannot have the same did */
1669 ndlp->nlp_DID = keepDID;
1670 if (phba->sli_rev == LPFC_SLI_REV4 &&
1671 active_rrqs_xri_bitmap)
1672 memcpy(ndlp->active_rrqs_xri_bitmap,
1673 active_rrqs_xri_bitmap,
1674 phba->cfg_rrq_xri_bitmap_sz);
1676 /* Since we are switching over to the new_ndlp,
1677 * reset the old ndlp state
1679 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
1680 (ndlp->nlp_state == NLP_STE_MAPPED_NODE))
1681 keep_nlp_state = NLP_STE_NPR_NODE;
1682 lpfc_nlp_set_state(vport, ndlp, keep_nlp_state);
1684 /* Fix up the rport accordingly */
1685 rport = ndlp->rport;
1687 rdata = rport->dd_data;
1688 put_node = rdata->pnode != NULL;
1689 put_rport = ndlp->rport != NULL;
1690 rdata->pnode = NULL;
1695 put_device(&rport->dev);
1698 if (phba->sli_rev == LPFC_SLI_REV4 &&
1699 active_rrqs_xri_bitmap)
1700 mempool_free(active_rrqs_xri_bitmap,
1701 phba->active_rrq_pool);
1706 * lpfc_end_rscn - Check and handle more rscn for a vport
1707 * @vport: pointer to a host virtual N_Port data structure.
1709 * This routine checks whether more Registration State Change
1710 * Notifications (RSCNs) came in while the discovery state machine was in
1711 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1712 * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1713 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1714 * handling the RSCNs.
1717 lpfc_end_rscn(struct lpfc_vport *vport)
1719 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1721 if (vport->fc_flag & FC_RSCN_MODE) {
1723 * Check to see if more RSCNs came in while we were
1724 * processing this one.
1726 if (vport->fc_rscn_id_cnt ||
1727 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
1728 lpfc_els_handle_rscn(vport);
1730 spin_lock_irq(shost->host_lock);
1731 vport->fc_flag &= ~FC_RSCN_MODE;
1732 spin_unlock_irq(shost->host_lock);
1738 * lpfc_cmpl_els_rrq - Completion handled for els RRQs.
1739 * @phba: pointer to lpfc hba data structure.
1740 * @cmdiocb: pointer to lpfc command iocb data structure.
1741 * @rspiocb: pointer to lpfc response iocb data structure.
1743 * This routine will call the clear rrq function to free the rrq and
1744 * clear the xri's bit in the ndlp's xri_bitmap. If the ndlp does not
1745 * exist then the clear_rrq is still called because the rrq needs to
1750 lpfc_cmpl_els_rrq(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1751 struct lpfc_iocbq *rspiocb)
1753 struct lpfc_vport *vport = cmdiocb->vport;
1755 struct lpfc_nodelist *ndlp;
1756 struct lpfc_node_rrq *rrq;
1758 /* we pass cmdiocb to state machine which needs rspiocb as well */
1759 rrq = cmdiocb->context_un.rrq;
1760 cmdiocb->context_un.rsp_iocb = rspiocb;
1762 irsp = &rspiocb->iocb;
1763 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1764 "RRQ cmpl: status:x%x/x%x did:x%x",
1765 irsp->ulpStatus, irsp->un.ulpWord[4],
1766 irsp->un.elsreq64.remoteID);
1768 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
1769 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || ndlp != rrq->ndlp) {
1770 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1771 "2882 RRQ completes to NPort x%x "
1772 "with no ndlp. Data: x%x x%x x%x\n",
1773 irsp->un.elsreq64.remoteID,
1774 irsp->ulpStatus, irsp->un.ulpWord[4],
1779 /* rrq completes to NPort <nlp_DID> */
1780 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1781 "2880 RRQ completes to NPort x%x "
1782 "Data: x%x x%x x%x x%x x%x\n",
1783 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1784 irsp->ulpTimeout, rrq->xritag, rrq->rxid);
1786 if (irsp->ulpStatus) {
1787 /* Check for retry */
1788 /* RRQ failed Don't print the vport to vport rjts */
1789 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1790 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1791 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1792 (phba)->pport->cfg_log_verbose & LOG_ELS)
1793 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1794 "2881 RRQ failure DID:%06X Status:x%x/x%x\n",
1795 ndlp->nlp_DID, irsp->ulpStatus,
1796 irsp->un.ulpWord[4]);
1800 lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
1801 lpfc_els_free_iocb(phba, cmdiocb);
1805 * lpfc_cmpl_els_plogi - Completion callback function for plogi
1806 * @phba: pointer to lpfc hba data structure.
1807 * @cmdiocb: pointer to lpfc command iocb data structure.
1808 * @rspiocb: pointer to lpfc response iocb data structure.
1810 * This routine is the completion callback function for issuing the Port
1811 * Login (PLOGI) command. For PLOGI completion, there must be an active
1812 * ndlp on the vport node list that matches the remote node ID from the
1813 * PLOGI response IOCB. If such ndlp does not exist, the PLOGI is simply
1814 * ignored and command IOCB released. The PLOGI response IOCB status is
1815 * checked for error conditons. If there is error status reported, PLOGI
1816 * retry shall be attempted by invoking the lpfc_els_retry() routine.
1817 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1818 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1819 * (DSM) is set for this PLOGI completion. Finally, it checks whether
1820 * there are additional N_Port nodes with the vport that need to perform
1821 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
1825 lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1826 struct lpfc_iocbq *rspiocb)
1828 struct lpfc_vport *vport = cmdiocb->vport;
1829 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1831 struct lpfc_nodelist *ndlp;
1832 struct lpfc_dmabuf *prsp;
1835 /* we pass cmdiocb to state machine which needs rspiocb as well */
1836 cmdiocb->context_un.rsp_iocb = rspiocb;
1838 irsp = &rspiocb->iocb;
1839 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1840 "PLOGI cmpl: status:x%x/x%x did:x%x",
1841 irsp->ulpStatus, irsp->un.ulpWord[4],
1842 irsp->un.elsreq64.remoteID);
1844 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
1845 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
1846 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1847 "0136 PLOGI completes to NPort x%x "
1848 "with no ndlp. Data: x%x x%x x%x\n",
1849 irsp->un.elsreq64.remoteID,
1850 irsp->ulpStatus, irsp->un.ulpWord[4],
1855 /* Since ndlp can be freed in the disc state machine, note if this node
1856 * is being used during discovery.
1858 spin_lock_irq(shost->host_lock);
1859 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
1860 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1861 spin_unlock_irq(shost->host_lock);
1864 /* PLOGI completes to NPort <nlp_DID> */
1865 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1866 "0102 PLOGI completes to NPort x%06x "
1867 "Data: x%x x%x x%x x%x x%x\n",
1868 ndlp->nlp_DID, ndlp->nlp_fc4_type,
1869 irsp->ulpStatus, irsp->un.ulpWord[4],
1870 disc, vport->num_disc_nodes);
1872 /* Check to see if link went down during discovery */
1873 if (lpfc_els_chk_latt(vport)) {
1874 spin_lock_irq(shost->host_lock);
1875 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1876 spin_unlock_irq(shost->host_lock);
1880 if (irsp->ulpStatus) {
1881 /* Check for retry */
1882 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1883 /* ELS command is being retried */
1885 spin_lock_irq(shost->host_lock);
1886 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1887 spin_unlock_irq(shost->host_lock);
1891 /* PLOGI failed Don't print the vport to vport rjts */
1892 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1893 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1894 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1895 (phba)->pport->cfg_log_verbose & LOG_ELS)
1896 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1897 "2753 PLOGI failure DID:%06X Status:x%x/x%x\n",
1898 ndlp->nlp_DID, irsp->ulpStatus,
1899 irsp->un.ulpWord[4]);
1900 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1901 if (lpfc_error_lost_link(irsp))
1902 rc = NLP_STE_FREED_NODE;
1904 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1905 NLP_EVT_CMPL_PLOGI);
1907 /* Good status, call state machine */
1908 prsp = list_entry(((struct lpfc_dmabuf *)
1909 cmdiocb->context2)->list.next,
1910 struct lpfc_dmabuf, list);
1911 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
1912 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1913 NLP_EVT_CMPL_PLOGI);
1916 if (disc && vport->num_disc_nodes) {
1917 /* Check to see if there are more PLOGIs to be sent */
1918 lpfc_more_plogi(vport);
1920 if (vport->num_disc_nodes == 0) {
1921 spin_lock_irq(shost->host_lock);
1922 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1923 spin_unlock_irq(shost->host_lock);
1925 lpfc_can_disctmo(vport);
1926 lpfc_end_rscn(vport);
1931 lpfc_els_free_iocb(phba, cmdiocb);
1936 * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
1937 * @vport: pointer to a host virtual N_Port data structure.
1938 * @did: destination port identifier.
1939 * @retry: number of retries to the command IOCB.
1941 * This routine issues a Port Login (PLOGI) command to a remote N_Port
1942 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
1943 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
1944 * This routine constructs the proper feilds of the PLOGI IOCB and invokes
1945 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
1947 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1948 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1949 * will be stored into the context1 field of the IOCB for the completion
1950 * callback function to the PLOGI ELS command.
1953 * 0 - Successfully issued a plogi for @vport
1954 * 1 - failed to issue a plogi for @vport
1957 lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
1959 struct lpfc_hba *phba = vport->phba;
1960 struct serv_parm *sp;
1961 struct lpfc_nodelist *ndlp;
1962 struct lpfc_iocbq *elsiocb;
1967 ndlp = lpfc_findnode_did(vport, did);
1968 if (ndlp && !NLP_CHK_NODE_ACT(ndlp))
1971 /* If ndlp is not NULL, we will bump the reference count on it */
1972 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
1973 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
1978 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1980 /* For PLOGI request, remainder of payload is service parameters */
1981 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
1982 pcmd += sizeof(uint32_t);
1983 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
1984 sp = (struct serv_parm *) pcmd;
1987 * If we are a N-port connected to a Fabric, fix-up paramm's so logins
1988 * to device on remote loops work.
1990 if ((vport->fc_flag & FC_FABRIC) && !(vport->fc_flag & FC_PUBLIC_LOOP))
1991 sp->cmn.altBbCredit = 1;
1993 if (sp->cmn.fcphLow < FC_PH_4_3)
1994 sp->cmn.fcphLow = FC_PH_4_3;
1996 if (sp->cmn.fcphHigh < FC_PH3)
1997 sp->cmn.fcphHigh = FC_PH3;
1999 sp->cmn.valid_vendor_ver_level = 0;
2000 memset(sp->un.vendorVersion, 0, sizeof(sp->un.vendorVersion));
2002 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2003 "Issue PLOGI: did:x%x",
2006 /* If our firmware supports this feature, convey that
2007 * information to the target using the vendor specific field.
2009 if (phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) {
2010 sp->cmn.valid_vendor_ver_level = 1;
2011 sp->un.vv.vid = cpu_to_be32(LPFC_VV_EMLX_ID);
2012 sp->un.vv.flags = cpu_to_be32(LPFC_VV_SUPPRESS_RSP);
2015 phba->fc_stat.elsXmitPLOGI++;
2016 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
2017 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
2019 if (ret == IOCB_ERROR) {
2020 lpfc_els_free_iocb(phba, elsiocb);
2027 * lpfc_cmpl_els_prli - Completion callback function for prli
2028 * @phba: pointer to lpfc hba data structure.
2029 * @cmdiocb: pointer to lpfc command iocb data structure.
2030 * @rspiocb: pointer to lpfc response iocb data structure.
2032 * This routine is the completion callback function for a Process Login
2033 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
2034 * status. If there is error status reported, PRLI retry shall be attempted
2035 * by invoking the lpfc_els_retry() routine. Otherwise, the state
2036 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
2037 * ndlp to mark the PRLI completion.
2040 lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2041 struct lpfc_iocbq *rspiocb)
2043 struct lpfc_vport *vport = cmdiocb->vport;
2044 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2046 struct lpfc_nodelist *ndlp;
2048 /* we pass cmdiocb to state machine which needs rspiocb as well */
2049 cmdiocb->context_un.rsp_iocb = rspiocb;
2051 irsp = &(rspiocb->iocb);
2052 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2053 spin_lock_irq(shost->host_lock);
2054 ndlp->nlp_flag &= ~NLP_PRLI_SND;
2055 spin_unlock_irq(shost->host_lock);
2057 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2058 "PRLI cmpl: status:x%x/x%x did:x%x",
2059 irsp->ulpStatus, irsp->un.ulpWord[4],
2062 /* Ddriver supports multiple FC4 types. Counters matter. */
2063 vport->fc_prli_sent--;
2065 /* PRLI completes to NPort <nlp_DID> */
2066 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2067 "0103 PRLI completes to NPort x%06x "
2068 "Data: x%x x%x x%x x%x\n",
2069 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2070 vport->num_disc_nodes, ndlp->fc4_prli_sent);
2072 /* Check to see if link went down during discovery */
2073 if (lpfc_els_chk_latt(vport))
2076 if (irsp->ulpStatus) {
2077 /* Check for retry */
2078 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2079 /* ELS command is being retried */
2080 ndlp->fc4_prli_sent--;
2084 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2085 "2754 PRLI failure DID:%06X Status:x%x/x%x\n",
2086 ndlp->nlp_DID, irsp->ulpStatus,
2087 irsp->un.ulpWord[4]);
2088 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2089 if (lpfc_error_lost_link(irsp))
2092 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2095 /* Good status, call state machine. However, if another
2096 * PRLI is outstanding, don't call the state machine
2097 * because final disposition to Mapped or Unmapped is
2100 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2104 lpfc_els_free_iocb(phba, cmdiocb);
2109 * lpfc_issue_els_prli - Issue a prli iocb command for a vport
2110 * @vport: pointer to a host virtual N_Port data structure.
2111 * @ndlp: pointer to a node-list data structure.
2112 * @retry: number of retries to the command IOCB.
2114 * This routine issues a Process Login (PRLI) ELS command for the
2115 * @vport. The PRLI service parameters are set up in the payload of the
2116 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
2117 * is put to the IOCB completion callback func field before invoking the
2118 * routine lpfc_sli_issue_iocb() to send out PRLI command.
2120 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2121 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2122 * will be stored into the context1 field of the IOCB for the completion
2123 * callback function to the PRLI ELS command.
2126 * 0 - successfully issued prli iocb command for @vport
2127 * 1 - failed to issue prli iocb command for @vport
2130 lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2133 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2134 struct lpfc_hba *phba = vport->phba;
2136 struct lpfc_nvme_prli *npr_nvme;
2137 struct lpfc_iocbq *elsiocb;
2140 u32 local_nlp_type, elscmd;
2142 local_nlp_type = ndlp->nlp_fc4_type;
2145 if (local_nlp_type & NLP_FC4_FCP) {
2146 /* Payload is 4 + 16 = 20 x14 bytes. */
2147 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
2148 elscmd = ELS_CMD_PRLI;
2149 } else if (local_nlp_type & NLP_FC4_NVME) {
2150 /* Payload is 4 + 20 = 24 x18 bytes. */
2151 cmdsize = (sizeof(uint32_t) + sizeof(struct lpfc_nvme_prli));
2152 elscmd = ELS_CMD_NVMEPRLI;
2154 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2155 "3083 Unknown FC_TYPE x%x ndlp x%06x\n",
2156 ndlp->nlp_fc4_type, ndlp->nlp_DID);
2159 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2160 ndlp->nlp_DID, elscmd);
2164 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2166 /* For PRLI request, remainder of payload is service parameters */
2167 memset(pcmd, 0, cmdsize);
2169 if (local_nlp_type & NLP_FC4_FCP) {
2170 /* Remainder of payload is FCP PRLI parameter page.
2171 * Note: this data structure is defined as
2172 * BE/LE in the structure definition so no
2173 * byte swap call is made.
2175 *((uint32_t *)(pcmd)) = ELS_CMD_PRLI;
2176 pcmd += sizeof(uint32_t);
2180 * If our firmware version is 3.20 or later,
2181 * set the following bits for FC-TAPE support.
2183 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
2184 npr->ConfmComplAllowed = 1;
2186 npr->TaskRetryIdReq = 1;
2188 npr->estabImagePair = 1;
2189 npr->readXferRdyDis = 1;
2190 if (vport->cfg_first_burst_size)
2191 npr->writeXferRdyDis = 1;
2193 /* For FCP support */
2194 npr->prliType = PRLI_FCP_TYPE;
2195 npr->initiatorFunc = 1;
2196 elsiocb->iocb_flag |= LPFC_PRLI_FCP_REQ;
2198 /* Remove FCP type - processed. */
2199 local_nlp_type &= ~NLP_FC4_FCP;
2200 } else if (local_nlp_type & NLP_FC4_NVME) {
2201 /* Remainder of payload is NVME PRLI parameter page.
2202 * This data structure is the newer definition that
2203 * uses bf macros so a byte swap is required.
2205 *((uint32_t *)(pcmd)) = ELS_CMD_NVMEPRLI;
2206 pcmd += sizeof(uint32_t);
2207 npr_nvme = (struct lpfc_nvme_prli *)pcmd;
2208 bf_set(prli_type_code, npr_nvme, PRLI_NVME_TYPE);
2209 bf_set(prli_estabImagePair, npr_nvme, 0); /* Should be 0 */
2211 /* Only initiators request first burst. */
2212 if ((phba->cfg_nvme_enable_fb) &&
2213 !phba->nvmet_support)
2214 bf_set(prli_fba, npr_nvme, 1);
2216 if (phba->nvmet_support) {
2217 bf_set(prli_tgt, npr_nvme, 1);
2218 bf_set(prli_disc, npr_nvme, 1);
2221 bf_set(prli_init, npr_nvme, 1);
2223 npr_nvme->word1 = cpu_to_be32(npr_nvme->word1);
2224 npr_nvme->word4 = cpu_to_be32(npr_nvme->word4);
2225 elsiocb->iocb_flag |= LPFC_PRLI_NVME_REQ;
2227 /* Remove NVME type - processed. */
2228 local_nlp_type &= ~NLP_FC4_NVME;
2231 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2232 "Issue PRLI: did:x%x",
2233 ndlp->nlp_DID, 0, 0);
2235 phba->fc_stat.elsXmitPRLI++;
2236 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
2237 spin_lock_irq(shost->host_lock);
2238 ndlp->nlp_flag |= NLP_PRLI_SND;
2239 spin_unlock_irq(shost->host_lock);
2240 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2242 spin_lock_irq(shost->host_lock);
2243 ndlp->nlp_flag &= ~NLP_PRLI_SND;
2244 spin_unlock_irq(shost->host_lock);
2245 lpfc_els_free_iocb(phba, elsiocb);
2249 /* The vport counters are used for lpfc_scan_finished, but
2250 * the ndlp is used to track outstanding PRLIs for different
2253 vport->fc_prli_sent++;
2254 ndlp->fc4_prli_sent++;
2256 /* The driver supports 2 FC4 types. Make sure
2257 * a PRLI is issued for all types before exiting.
2259 if (local_nlp_type & (NLP_FC4_FCP | NLP_FC4_NVME))
2260 goto send_next_prli;
2266 * lpfc_rscn_disc - Perform rscn discovery for a vport
2267 * @vport: pointer to a host virtual N_Port data structure.
2269 * This routine performs Registration State Change Notification (RSCN)
2270 * discovery for a @vport. If the @vport's node port recovery count is not
2271 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
2272 * the nodes that need recovery. If none of the PLOGI were needed through
2273 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
2274 * invoked to check and handle possible more RSCN came in during the period
2275 * of processing the current ones.
2278 lpfc_rscn_disc(struct lpfc_vport *vport)
2280 lpfc_can_disctmo(vport);
2282 /* RSCN discovery */
2283 /* go thru NPR nodes and issue ELS PLOGIs */
2284 if (vport->fc_npr_cnt)
2285 if (lpfc_els_disc_plogi(vport))
2288 lpfc_end_rscn(vport);
2292 * lpfc_adisc_done - Complete the adisc phase of discovery
2293 * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
2295 * This function is called when the final ADISC is completed during discovery.
2296 * This function handles clearing link attention or issuing reg_vpi depending
2297 * on whether npiv is enabled. This function also kicks off the PLOGI phase of
2299 * This function is called with no locks held.
2302 lpfc_adisc_done(struct lpfc_vport *vport)
2304 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2305 struct lpfc_hba *phba = vport->phba;
2308 * For NPIV, cmpl_reg_vpi will set port_state to READY,
2309 * and continue discovery.
2311 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2312 !(vport->fc_flag & FC_RSCN_MODE) &&
2313 (phba->sli_rev < LPFC_SLI_REV4)) {
2314 /* The ADISCs are complete. Doesn't matter if they
2315 * succeeded or failed because the ADISC completion
2316 * routine guarantees to call the state machine and
2317 * the RPI is either unregistered (failed ADISC response)
2318 * or the RPI is still valid and the node is marked
2319 * mapped for a target. The exchanges should be in the
2320 * correct state. This code is specific to SLI3.
2322 lpfc_issue_clear_la(phba, vport);
2323 lpfc_issue_reg_vpi(phba, vport);
2327 * For SLI2, we need to set port_state to READY
2328 * and continue discovery.
2330 if (vport->port_state < LPFC_VPORT_READY) {
2331 /* If we get here, there is nothing to ADISC */
2332 lpfc_issue_clear_la(phba, vport);
2333 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
2334 vport->num_disc_nodes = 0;
2335 /* go thru NPR list, issue ELS PLOGIs */
2336 if (vport->fc_npr_cnt)
2337 lpfc_els_disc_plogi(vport);
2338 if (!vport->num_disc_nodes) {
2339 spin_lock_irq(shost->host_lock);
2340 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2341 spin_unlock_irq(shost->host_lock);
2342 lpfc_can_disctmo(vport);
2343 lpfc_end_rscn(vport);
2346 vport->port_state = LPFC_VPORT_READY;
2348 lpfc_rscn_disc(vport);
2352 * lpfc_more_adisc - Issue more adisc as needed
2353 * @vport: pointer to a host virtual N_Port data structure.
2355 * This routine determines whether there are more ndlps on a @vport
2356 * node list need to have Address Discover (ADISC) issued. If so, it will
2357 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
2358 * remaining nodes which need to have ADISC sent.
2361 lpfc_more_adisc(struct lpfc_vport *vport)
2363 if (vport->num_disc_nodes)
2364 vport->num_disc_nodes--;
2365 /* Continue discovery with <num_disc_nodes> ADISCs to go */
2366 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2367 "0210 Continue discovery with %d ADISCs to go "
2368 "Data: x%x x%x x%x\n",
2369 vport->num_disc_nodes, vport->fc_adisc_cnt,
2370 vport->fc_flag, vport->port_state);
2371 /* Check to see if there are more ADISCs to be sent */
2372 if (vport->fc_flag & FC_NLP_MORE) {
2373 lpfc_set_disctmo(vport);
2374 /* go thru NPR nodes and issue any remaining ELS ADISCs */
2375 lpfc_els_disc_adisc(vport);
2377 if (!vport->num_disc_nodes)
2378 lpfc_adisc_done(vport);
2383 * lpfc_cmpl_els_adisc - Completion callback function for adisc
2384 * @phba: pointer to lpfc hba data structure.
2385 * @cmdiocb: pointer to lpfc command iocb data structure.
2386 * @rspiocb: pointer to lpfc response iocb data structure.
2388 * This routine is the completion function for issuing the Address Discover
2389 * (ADISC) command. It first checks to see whether link went down during
2390 * the discovery process. If so, the node will be marked as node port
2391 * recovery for issuing discover IOCB by the link attention handler and
2392 * exit. Otherwise, the response status is checked. If error was reported
2393 * in the response status, the ADISC command shall be retried by invoking
2394 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
2395 * the response status, the state machine is invoked to set transition
2396 * with respect to NLP_EVT_CMPL_ADISC event.
2399 lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2400 struct lpfc_iocbq *rspiocb)
2402 struct lpfc_vport *vport = cmdiocb->vport;
2403 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2405 struct lpfc_nodelist *ndlp;
2408 /* we pass cmdiocb to state machine which needs rspiocb as well */
2409 cmdiocb->context_un.rsp_iocb = rspiocb;
2411 irsp = &(rspiocb->iocb);
2412 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2414 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2415 "ADISC cmpl: status:x%x/x%x did:x%x",
2416 irsp->ulpStatus, irsp->un.ulpWord[4],
2419 /* Since ndlp can be freed in the disc state machine, note if this node
2420 * is being used during discovery.
2422 spin_lock_irq(shost->host_lock);
2423 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
2424 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
2425 spin_unlock_irq(shost->host_lock);
2426 /* ADISC completes to NPort <nlp_DID> */
2427 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2428 "0104 ADISC completes to NPort x%x "
2429 "Data: x%x x%x x%x x%x x%x\n",
2430 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2431 irsp->ulpTimeout, disc, vport->num_disc_nodes);
2432 /* Check to see if link went down during discovery */
2433 if (lpfc_els_chk_latt(vport)) {
2434 spin_lock_irq(shost->host_lock);
2435 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2436 spin_unlock_irq(shost->host_lock);
2440 if (irsp->ulpStatus) {
2441 /* Check for retry */
2442 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2443 /* ELS command is being retried */
2445 spin_lock_irq(shost->host_lock);
2446 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2447 spin_unlock_irq(shost->host_lock);
2448 lpfc_set_disctmo(vport);
2453 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2454 "2755 ADISC failure DID:%06X Status:x%x/x%x\n",
2455 ndlp->nlp_DID, irsp->ulpStatus,
2456 irsp->un.ulpWord[4]);
2457 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2458 if (!lpfc_error_lost_link(irsp))
2459 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2460 NLP_EVT_CMPL_ADISC);
2462 /* Good status, call state machine */
2463 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2464 NLP_EVT_CMPL_ADISC);
2466 /* Check to see if there are more ADISCs to be sent */
2467 if (disc && vport->num_disc_nodes)
2468 lpfc_more_adisc(vport);
2470 lpfc_els_free_iocb(phba, cmdiocb);
2475 * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
2476 * @vport: pointer to a virtual N_Port data structure.
2477 * @ndlp: pointer to a node-list data structure.
2478 * @retry: number of retries to the command IOCB.
2480 * This routine issues an Address Discover (ADISC) for an @ndlp on a
2481 * @vport. It prepares the payload of the ADISC ELS command, updates the
2482 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
2483 * to issue the ADISC ELS command.
2485 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2486 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2487 * will be stored into the context1 field of the IOCB for the completion
2488 * callback function to the ADISC ELS command.
2491 * 0 - successfully issued adisc
2492 * 1 - failed to issue adisc
2495 lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2498 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2499 struct lpfc_hba *phba = vport->phba;
2501 struct lpfc_iocbq *elsiocb;
2505 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
2506 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2507 ndlp->nlp_DID, ELS_CMD_ADISC);
2511 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2513 /* For ADISC request, remainder of payload is service parameters */
2514 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
2515 pcmd += sizeof(uint32_t);
2517 /* Fill in ADISC payload */
2518 ap = (ADISC *) pcmd;
2519 ap->hardAL_PA = phba->fc_pref_ALPA;
2520 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2521 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
2522 ap->DID = be32_to_cpu(vport->fc_myDID);
2524 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2525 "Issue ADISC: did:x%x",
2526 ndlp->nlp_DID, 0, 0);
2528 phba->fc_stat.elsXmitADISC++;
2529 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
2530 spin_lock_irq(shost->host_lock);
2531 ndlp->nlp_flag |= NLP_ADISC_SND;
2532 spin_unlock_irq(shost->host_lock);
2533 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2535 spin_lock_irq(shost->host_lock);
2536 ndlp->nlp_flag &= ~NLP_ADISC_SND;
2537 spin_unlock_irq(shost->host_lock);
2538 lpfc_els_free_iocb(phba, elsiocb);
2545 * lpfc_cmpl_els_logo - Completion callback function for logo
2546 * @phba: pointer to lpfc hba data structure.
2547 * @cmdiocb: pointer to lpfc command iocb data structure.
2548 * @rspiocb: pointer to lpfc response iocb data structure.
2550 * This routine is the completion function for issuing the ELS Logout (LOGO)
2551 * command. If no error status was reported from the LOGO response, the
2552 * state machine of the associated ndlp shall be invoked for transition with
2553 * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
2554 * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
2557 lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2558 struct lpfc_iocbq *rspiocb)
2560 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2561 struct lpfc_vport *vport = ndlp->vport;
2562 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2564 struct lpfcMboxq *mbox;
2565 unsigned long flags;
2566 uint32_t skip_recovery = 0;
2568 /* we pass cmdiocb to state machine which needs rspiocb as well */
2569 cmdiocb->context_un.rsp_iocb = rspiocb;
2571 irsp = &(rspiocb->iocb);
2572 spin_lock_irq(shost->host_lock);
2573 ndlp->nlp_flag &= ~NLP_LOGO_SND;
2574 spin_unlock_irq(shost->host_lock);
2576 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2577 "LOGO cmpl: status:x%x/x%x did:x%x",
2578 irsp->ulpStatus, irsp->un.ulpWord[4],
2581 /* LOGO completes to NPort <nlp_DID> */
2582 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2583 "0105 LOGO completes to NPort x%x "
2584 "Data: x%x x%x x%x x%x\n",
2585 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2586 irsp->ulpTimeout, vport->num_disc_nodes);
2588 if (lpfc_els_chk_latt(vport)) {
2593 /* Check to see if link went down during discovery */
2594 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
2595 /* NLP_EVT_DEVICE_RM should unregister the RPI
2596 * which should abort all outstanding IOs.
2598 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2604 if (irsp->ulpStatus) {
2605 /* Check for retry */
2606 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2607 /* ELS command is being retried */
2612 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2613 "2756 LOGO failure DID:%06X Status:x%x/x%x\n",
2614 ndlp->nlp_DID, irsp->ulpStatus,
2615 irsp->un.ulpWord[4]);
2616 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2617 if (lpfc_error_lost_link(irsp)) {
2623 /* Call state machine. This will unregister the rpi if needed. */
2624 lpfc_disc_state_machine(vport, ndlp, cmdiocb, NLP_EVT_CMPL_LOGO);
2627 lpfc_els_free_iocb(phba, cmdiocb);
2628 /* If we are in pt2pt mode, we could rcv new S_ID on PLOGI */
2629 if ((vport->fc_flag & FC_PT2PT) &&
2630 !(vport->fc_flag & FC_PT2PT_PLOGI)) {
2631 phba->pport->fc_myDID = 0;
2633 if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
2634 (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
2635 if (phba->nvmet_support)
2636 lpfc_nvmet_update_targetport(phba);
2638 lpfc_nvme_update_localport(phba->pport);
2641 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2643 lpfc_config_link(phba, mbox);
2644 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
2645 mbox->vport = vport;
2646 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) ==
2648 mempool_free(mbox, phba->mbox_mem_pool);
2655 * If the node is a target, the handling attempts to recover the port.
2656 * For any other port type, the rpi is unregistered as an implicit
2659 if ((ndlp->nlp_type & NLP_FCP_TARGET) && (skip_recovery == 0)) {
2660 lpfc_cancel_retry_delay_tmo(vport, ndlp);
2661 spin_lock_irqsave(shost->host_lock, flags);
2662 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2663 spin_unlock_irqrestore(shost->host_lock, flags);
2665 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2666 "3187 LOGO completes to NPort x%x: Start "
2667 "Recovery Data: x%x x%x x%x x%x\n",
2668 ndlp->nlp_DID, irsp->ulpStatus,
2669 irsp->un.ulpWord[4], irsp->ulpTimeout,
2670 vport->num_disc_nodes);
2671 lpfc_disc_start(vport);
2677 * lpfc_issue_els_logo - Issue a logo to an node on a vport
2678 * @vport: pointer to a virtual N_Port data structure.
2679 * @ndlp: pointer to a node-list data structure.
2680 * @retry: number of retries to the command IOCB.
2682 * This routine constructs and issues an ELS Logout (LOGO) iocb command
2683 * to a remote node, referred by an @ndlp on a @vport. It constructs the
2684 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
2685 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
2687 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2688 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2689 * will be stored into the context1 field of the IOCB for the completion
2690 * callback function to the LOGO ELS command.
2693 * 0 - successfully issued logo
2694 * 1 - failed to issue logo
2697 lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2700 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2701 struct lpfc_hba *phba = vport->phba;
2702 struct lpfc_iocbq *elsiocb;
2707 spin_lock_irq(shost->host_lock);
2708 if (ndlp->nlp_flag & NLP_LOGO_SND) {
2709 spin_unlock_irq(shost->host_lock);
2712 spin_unlock_irq(shost->host_lock);
2714 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
2715 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2716 ndlp->nlp_DID, ELS_CMD_LOGO);
2720 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2721 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
2722 pcmd += sizeof(uint32_t);
2724 /* Fill in LOGO payload */
2725 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
2726 pcmd += sizeof(uint32_t);
2727 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
2729 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2730 "Issue LOGO: did:x%x",
2731 ndlp->nlp_DID, 0, 0);
2734 * If we are issuing a LOGO, we may try to recover the remote NPort
2735 * by issuing a PLOGI later. Even though we issue ELS cmds by the
2736 * VPI, if we have a valid RPI, and that RPI gets unreg'ed while
2737 * that ELS command is in-flight, the HBA returns a IOERR_INVALID_RPI
2738 * for that ELS cmd. To avoid this situation, lets get rid of the
2739 * RPI right now, before any ELS cmds are sent.
2741 spin_lock_irq(shost->host_lock);
2742 ndlp->nlp_flag |= NLP_ISSUE_LOGO;
2743 spin_unlock_irq(shost->host_lock);
2744 if (lpfc_unreg_rpi(vport, ndlp)) {
2745 lpfc_els_free_iocb(phba, elsiocb);
2749 phba->fc_stat.elsXmitLOGO++;
2750 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
2751 spin_lock_irq(shost->host_lock);
2752 ndlp->nlp_flag |= NLP_LOGO_SND;
2753 ndlp->nlp_flag &= ~NLP_ISSUE_LOGO;
2754 spin_unlock_irq(shost->host_lock);
2755 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
2757 if (rc == IOCB_ERROR) {
2758 spin_lock_irq(shost->host_lock);
2759 ndlp->nlp_flag &= ~NLP_LOGO_SND;
2760 spin_unlock_irq(shost->host_lock);
2761 lpfc_els_free_iocb(phba, elsiocb);
2768 * lpfc_cmpl_els_cmd - Completion callback function for generic els command
2769 * @phba: pointer to lpfc hba data structure.
2770 * @cmdiocb: pointer to lpfc command iocb data structure.
2771 * @rspiocb: pointer to lpfc response iocb data structure.
2773 * This routine is a generic completion callback function for ELS commands.
2774 * Specifically, it is the callback function which does not need to perform
2775 * any command specific operations. It is currently used by the ELS command
2776 * issuing routines for the ELS State Change Request (SCR),
2777 * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution
2778 * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than
2779 * certain debug loggings, this callback function simply invokes the
2780 * lpfc_els_chk_latt() routine to check whether link went down during the
2781 * discovery process.
2784 lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2785 struct lpfc_iocbq *rspiocb)
2787 struct lpfc_vport *vport = cmdiocb->vport;
2790 irsp = &rspiocb->iocb;
2792 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2793 "ELS cmd cmpl: status:x%x/x%x did:x%x",
2794 irsp->ulpStatus, irsp->un.ulpWord[4],
2795 irsp->un.elsreq64.remoteID);
2796 /* ELS cmd tag <ulpIoTag> completes */
2797 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2798 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
2799 irsp->ulpIoTag, irsp->ulpStatus,
2800 irsp->un.ulpWord[4], irsp->ulpTimeout);
2801 /* Check to see if link went down during discovery */
2802 lpfc_els_chk_latt(vport);
2803 lpfc_els_free_iocb(phba, cmdiocb);
2808 * lpfc_issue_els_scr - Issue a scr to an node on a vport
2809 * @vport: pointer to a host virtual N_Port data structure.
2810 * @nportid: N_Port identifier to the remote node.
2811 * @retry: number of retries to the command IOCB.
2813 * This routine issues a State Change Request (SCR) to a fabric node
2814 * on a @vport. The remote node @nportid is passed into the function. It
2815 * first search the @vport node list to find the matching ndlp. If no such
2816 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
2817 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
2818 * routine is invoked to send the SCR IOCB.
2820 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2821 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2822 * will be stored into the context1 field of the IOCB for the completion
2823 * callback function to the SCR ELS command.
2826 * 0 - Successfully issued scr command
2827 * 1 - Failed to issue scr command
2830 lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
2832 struct lpfc_hba *phba = vport->phba;
2833 struct lpfc_iocbq *elsiocb;
2836 struct lpfc_nodelist *ndlp;
2838 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
2840 ndlp = lpfc_findnode_did(vport, nportid);
2842 ndlp = lpfc_nlp_init(vport, nportid);
2845 lpfc_enqueue_node(vport, ndlp);
2846 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2847 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2852 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2853 ndlp->nlp_DID, ELS_CMD_SCR);
2856 /* This will trigger the release of the node just
2863 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2865 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
2866 pcmd += sizeof(uint32_t);
2868 /* For SCR, remainder of payload is SCR parameter page */
2869 memset(pcmd, 0, sizeof(SCR));
2870 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
2872 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2873 "Issue SCR: did:x%x",
2874 ndlp->nlp_DID, 0, 0);
2876 phba->fc_stat.elsXmitSCR++;
2877 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
2878 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2880 /* The additional lpfc_nlp_put will cause the following
2881 * lpfc_els_free_iocb routine to trigger the rlease of
2885 lpfc_els_free_iocb(phba, elsiocb);
2888 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2889 * trigger the release of node.
2897 * lpfc_issue_els_farpr - Issue a farp to an node on a vport
2898 * @vport: pointer to a host virtual N_Port data structure.
2899 * @nportid: N_Port identifier to the remote node.
2900 * @retry: number of retries to the command IOCB.
2902 * This routine issues a Fibre Channel Address Resolution Response
2903 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
2904 * is passed into the function. It first search the @vport node list to find
2905 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
2906 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
2907 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
2909 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2910 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2911 * will be stored into the context1 field of the IOCB for the completion
2912 * callback function to the PARPR ELS command.
2915 * 0 - Successfully issued farpr command
2916 * 1 - Failed to issue farpr command
2919 lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
2921 struct lpfc_hba *phba = vport->phba;
2922 struct lpfc_iocbq *elsiocb;
2927 struct lpfc_nodelist *ondlp;
2928 struct lpfc_nodelist *ndlp;
2930 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
2932 ndlp = lpfc_findnode_did(vport, nportid);
2934 ndlp = lpfc_nlp_init(vport, nportid);
2937 lpfc_enqueue_node(vport, ndlp);
2938 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2939 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2944 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2945 ndlp->nlp_DID, ELS_CMD_RNID);
2947 /* This will trigger the release of the node just
2954 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2956 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
2957 pcmd += sizeof(uint32_t);
2959 /* Fill in FARPR payload */
2960 fp = (FARP *) (pcmd);
2961 memset(fp, 0, sizeof(FARP));
2962 lp = (uint32_t *) pcmd;
2963 *lp++ = be32_to_cpu(nportid);
2964 *lp++ = be32_to_cpu(vport->fc_myDID);
2966 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
2968 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
2969 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
2970 ondlp = lpfc_findnode_did(vport, nportid);
2971 if (ondlp && NLP_CHK_NODE_ACT(ondlp)) {
2972 memcpy(&fp->OportName, &ondlp->nlp_portname,
2973 sizeof(struct lpfc_name));
2974 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
2975 sizeof(struct lpfc_name));
2978 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2979 "Issue FARPR: did:x%x",
2980 ndlp->nlp_DID, 0, 0);
2982 phba->fc_stat.elsXmitFARPR++;
2983 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
2984 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2986 /* The additional lpfc_nlp_put will cause the following
2987 * lpfc_els_free_iocb routine to trigger the release of
2991 lpfc_els_free_iocb(phba, elsiocb);
2994 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2995 * trigger the release of the node.
3002 * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
3003 * @vport: pointer to a host virtual N_Port data structure.
3004 * @nlp: pointer to a node-list data structure.
3006 * This routine cancels the timer with a delayed IOCB-command retry for
3007 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
3008 * removes the ELS retry event if it presents. In addition, if the
3009 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
3010 * commands are sent for the @vport's nodes that require issuing discovery
3014 lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
3016 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3017 struct lpfc_work_evt *evtp;
3019 if (!(nlp->nlp_flag & NLP_DELAY_TMO))
3021 spin_lock_irq(shost->host_lock);
3022 nlp->nlp_flag &= ~NLP_DELAY_TMO;
3023 spin_unlock_irq(shost->host_lock);
3024 del_timer_sync(&nlp->nlp_delayfunc);
3025 nlp->nlp_last_elscmd = 0;
3026 if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
3027 list_del_init(&nlp->els_retry_evt.evt_listp);
3028 /* Decrement nlp reference count held for the delayed retry */
3029 evtp = &nlp->els_retry_evt;
3030 lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
3032 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
3033 spin_lock_irq(shost->host_lock);
3034 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
3035 spin_unlock_irq(shost->host_lock);
3036 if (vport->num_disc_nodes) {
3037 if (vport->port_state < LPFC_VPORT_READY) {
3038 /* Check if there are more ADISCs to be sent */
3039 lpfc_more_adisc(vport);
3041 /* Check if there are more PLOGIs to be sent */
3042 lpfc_more_plogi(vport);
3043 if (vport->num_disc_nodes == 0) {
3044 spin_lock_irq(shost->host_lock);
3045 vport->fc_flag &= ~FC_NDISC_ACTIVE;
3046 spin_unlock_irq(shost->host_lock);
3047 lpfc_can_disctmo(vport);
3048 lpfc_end_rscn(vport);
3057 * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
3058 * @ptr: holder for the pointer to the timer function associated data (ndlp).
3060 * This routine is invoked by the ndlp delayed-function timer to check
3061 * whether there is any pending ELS retry event(s) with the node. If not, it
3062 * simply returns. Otherwise, if there is at least one ELS delayed event, it
3063 * adds the delayed events to the HBA work list and invokes the
3064 * lpfc_worker_wake_up() routine to wake up worker thread to process the
3065 * event. Note that lpfc_nlp_get() is called before posting the event to
3066 * the work list to hold reference count of ndlp so that it guarantees the
3067 * reference to ndlp will still be available when the worker thread gets
3068 * to the event associated with the ndlp.
3071 lpfc_els_retry_delay(unsigned long ptr)
3073 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr;
3074 struct lpfc_vport *vport = ndlp->vport;
3075 struct lpfc_hba *phba = vport->phba;
3076 unsigned long flags;
3077 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
3079 spin_lock_irqsave(&phba->hbalock, flags);
3080 if (!list_empty(&evtp->evt_listp)) {
3081 spin_unlock_irqrestore(&phba->hbalock, flags);
3085 /* We need to hold the node by incrementing the reference
3086 * count until the queued work is done
3088 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
3089 if (evtp->evt_arg1) {
3090 evtp->evt = LPFC_EVT_ELS_RETRY;
3091 list_add_tail(&evtp->evt_listp, &phba->work_list);
3092 lpfc_worker_wake_up(phba);
3094 spin_unlock_irqrestore(&phba->hbalock, flags);
3099 * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
3100 * @ndlp: pointer to a node-list data structure.
3102 * This routine is the worker-thread handler for processing the @ndlp delayed
3103 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
3104 * the last ELS command from the associated ndlp and invokes the proper ELS
3105 * function according to the delayed ELS command to retry the command.
3108 lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
3110 struct lpfc_vport *vport = ndlp->vport;
3111 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3112 uint32_t cmd, retry;
3114 spin_lock_irq(shost->host_lock);
3115 cmd = ndlp->nlp_last_elscmd;
3116 ndlp->nlp_last_elscmd = 0;
3118 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
3119 spin_unlock_irq(shost->host_lock);
3123 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
3124 spin_unlock_irq(shost->host_lock);
3126 * If a discovery event readded nlp_delayfunc after timer
3127 * firing and before processing the timer, cancel the
3130 del_timer_sync(&ndlp->nlp_delayfunc);
3131 retry = ndlp->nlp_retry;
3132 ndlp->nlp_retry = 0;
3136 lpfc_issue_els_flogi(vport, ndlp, retry);
3139 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
3140 ndlp->nlp_prev_state = ndlp->nlp_state;
3141 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
3145 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
3146 ndlp->nlp_prev_state = ndlp->nlp_state;
3147 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
3151 case ELS_CMD_NVMEPRLI:
3152 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
3153 ndlp->nlp_prev_state = ndlp->nlp_state;
3154 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
3158 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
3159 ndlp->nlp_prev_state = ndlp->nlp_state;
3160 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
3164 if (!(vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI))
3165 lpfc_issue_els_fdisc(vport, ndlp, retry);
3172 * lpfc_els_retry - Make retry decision on an els command iocb
3173 * @phba: pointer to lpfc hba data structure.
3174 * @cmdiocb: pointer to lpfc command iocb data structure.
3175 * @rspiocb: pointer to lpfc response iocb data structure.
3177 * This routine makes a retry decision on an ELS command IOCB, which has
3178 * failed. The following ELS IOCBs use this function for retrying the command
3179 * when previously issued command responsed with error status: FLOGI, PLOGI,
3180 * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
3181 * returned error status, it makes the decision whether a retry shall be
3182 * issued for the command, and whether a retry shall be made immediately or
3183 * delayed. In the former case, the corresponding ELS command issuing-function
3184 * is called to retry the command. In the later case, the ELS command shall
3185 * be posted to the ndlp delayed event and delayed function timer set to the
3186 * ndlp for the delayed command issusing.
3189 * 0 - No retry of els command is made
3190 * 1 - Immediate or delayed retry of els command is made
3193 lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3194 struct lpfc_iocbq *rspiocb)
3196 struct lpfc_vport *vport = cmdiocb->vport;
3197 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3198 IOCB_t *irsp = &rspiocb->iocb;
3199 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3200 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3203 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
3209 /* Note: context2 may be 0 for internal driver abort
3210 * of delays ELS command.
3213 if (pcmd && pcmd->virt) {
3214 elscmd = (uint32_t *) (pcmd->virt);
3218 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
3219 did = ndlp->nlp_DID;
3221 /* We should only hit this case for retrying PLOGI */
3222 did = irsp->un.elsreq64.remoteID;
3223 ndlp = lpfc_findnode_did(vport, did);
3224 if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp))
3225 && (cmd != ELS_CMD_PLOGI))
3229 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3230 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
3231 *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
3233 switch (irsp->ulpStatus) {
3234 case IOSTAT_FCP_RSP_ERROR:
3236 case IOSTAT_REMOTE_STOP:
3237 if (phba->sli_rev == LPFC_SLI_REV4) {
3238 /* This IO was aborted by the target, we don't
3239 * know the rxid and because we did not send the
3240 * ABTS we cannot generate and RRQ.
3242 lpfc_set_rrq_active(phba, ndlp,
3243 cmdiocb->sli4_lxritag, 0, 0);
3246 case IOSTAT_LOCAL_REJECT:
3247 switch ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK)) {
3248 case IOERR_LOOP_OPEN_FAILURE:
3249 if (cmd == ELS_CMD_FLOGI) {
3250 if (PCI_DEVICE_ID_HORNET ==
3251 phba->pcidev->device) {
3252 phba->fc_topology = LPFC_TOPOLOGY_LOOP;
3253 phba->pport->fc_myDID = 0;
3254 phba->alpa_map[0] = 0;
3255 phba->alpa_map[1] = 0;
3258 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
3263 case IOERR_ILLEGAL_COMMAND:
3264 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3265 "0124 Retry illegal cmd x%x "
3266 "retry:x%x delay:x%x\n",
3267 cmd, cmdiocb->retry, delay);
3269 /* All command's retry policy */
3271 if (cmdiocb->retry > 2)
3275 case IOERR_NO_RESOURCES:
3276 logerr = 1; /* HBA out of resources */
3278 if (cmdiocb->retry > 100)
3283 case IOERR_ILLEGAL_FRAME:
3288 case IOERR_SEQUENCE_TIMEOUT:
3289 case IOERR_INVALID_RPI:
3290 if (cmd == ELS_CMD_PLOGI &&
3291 did == NameServer_DID) {
3292 /* Continue forever if plogi to */
3293 /* the nameserver fails */
3302 case IOSTAT_NPORT_RJT:
3303 case IOSTAT_FABRIC_RJT:
3304 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
3310 case IOSTAT_NPORT_BSY:
3311 case IOSTAT_FABRIC_BSY:
3312 logerr = 1; /* Fabric / Remote NPort out of resources */
3317 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
3318 /* Added for Vendor specifc support
3319 * Just keep retrying for these Rsn / Exp codes
3321 switch (stat.un.b.lsRjtRsnCode) {
3322 case LSRJT_UNABLE_TPC:
3323 if (stat.un.b.lsRjtRsnCodeExp ==
3324 LSEXP_CMD_IN_PROGRESS) {
3325 if (cmd == ELS_CMD_PLOGI) {
3332 if (stat.un.b.lsRjtRsnCodeExp ==
3333 LSEXP_CANT_GIVE_DATA) {
3334 if (cmd == ELS_CMD_PLOGI) {
3341 if ((cmd == ELS_CMD_PLOGI) ||
3342 (cmd == ELS_CMD_PRLI) ||
3343 (cmd == ELS_CMD_NVMEPRLI)) {
3345 maxretry = lpfc_max_els_tries + 1;
3349 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
3350 (cmd == ELS_CMD_FDISC) &&
3351 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
3352 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3353 "0125 FDISC Failed (x%x). "
3354 "Fabric out of resources\n",
3355 stat.un.lsRjtError);
3356 lpfc_vport_set_state(vport,
3357 FC_VPORT_NO_FABRIC_RSCS);
3361 case LSRJT_LOGICAL_BSY:
3362 if ((cmd == ELS_CMD_PLOGI) ||
3363 (cmd == ELS_CMD_PRLI) ||
3364 (cmd == ELS_CMD_NVMEPRLI)) {
3367 } else if (cmd == ELS_CMD_FDISC) {
3368 /* FDISC retry policy */
3370 if (cmdiocb->retry >= 32)
3376 case LSRJT_LOGICAL_ERR:
3377 /* There are some cases where switches return this
3378 * error when they are not ready and should be returning
3379 * Logical Busy. We should delay every time.
3381 if (cmd == ELS_CMD_FDISC &&
3382 stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
3388 case LSRJT_PROTOCOL_ERR:
3389 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
3390 (cmd == ELS_CMD_FDISC) &&
3391 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
3392 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
3394 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3395 "0122 FDISC Failed (x%x). "
3396 "Fabric Detected Bad WWN\n",
3397 stat.un.lsRjtError);
3398 lpfc_vport_set_state(vport,
3399 FC_VPORT_FABRIC_REJ_WWN);
3402 case LSRJT_VENDOR_UNIQUE:
3403 if ((stat.un.b.vendorUnique == 0x45) &&
3404 (cmd == ELS_CMD_FLOGI)) {
3411 case IOSTAT_INTERMED_RSP:
3419 if (did == FDMI_DID)
3422 if ((cmd == ELS_CMD_FLOGI) &&
3423 (phba->fc_topology != LPFC_TOPOLOGY_LOOP) &&
3424 !lpfc_error_lost_link(irsp)) {
3425 /* FLOGI retry policy */
3427 /* retry FLOGI forever */
3428 if (phba->link_flag != LS_LOOPBACK_MODE)
3433 if (cmdiocb->retry >= 100)
3435 else if (cmdiocb->retry >= 32)
3437 } else if ((cmd == ELS_CMD_FDISC) && !lpfc_error_lost_link(irsp)) {
3438 /* retry FDISCs every second up to devloss */
3440 maxretry = vport->cfg_devloss_tmo;
3445 if (maxretry && (cmdiocb->retry >= maxretry)) {
3446 phba->fc_stat.elsRetryExceeded++;
3450 if ((vport->load_flag & FC_UNLOADING) != 0)
3455 if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) {
3456 /* Stop retrying PLOGI and FDISC if in FCF discovery */
3457 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
3458 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3459 "2849 Stop retry ELS command "
3460 "x%x to remote NPORT x%x, "
3461 "Data: x%x x%x\n", cmd, did,
3462 cmdiocb->retry, delay);
3467 /* Retry ELS command <elsCmd> to remote NPORT <did> */
3468 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3469 "0107 Retry ELS command x%x to remote "
3470 "NPORT x%x Data: x%x x%x\n",
3471 cmd, did, cmdiocb->retry, delay);
3473 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
3474 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
3475 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
3476 IOERR_NO_RESOURCES))) {
3477 /* Don't reset timer for no resources */
3479 /* If discovery / RSCN timer is running, reset it */
3480 if (timer_pending(&vport->fc_disctmo) ||
3481 (vport->fc_flag & FC_RSCN_MODE))
3482 lpfc_set_disctmo(vport);
3485 phba->fc_stat.elsXmitRetry++;
3486 if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) {
3487 phba->fc_stat.elsDelayRetry++;
3488 ndlp->nlp_retry = cmdiocb->retry;
3490 /* delay is specified in milliseconds */
3491 mod_timer(&ndlp->nlp_delayfunc,
3492 jiffies + msecs_to_jiffies(delay));
3493 spin_lock_irq(shost->host_lock);
3494 ndlp->nlp_flag |= NLP_DELAY_TMO;
3495 spin_unlock_irq(shost->host_lock);
3497 ndlp->nlp_prev_state = ndlp->nlp_state;
3498 if ((cmd == ELS_CMD_PRLI) ||
3499 (cmd == ELS_CMD_NVMEPRLI))
3500 lpfc_nlp_set_state(vport, ndlp,
3501 NLP_STE_PRLI_ISSUE);
3503 lpfc_nlp_set_state(vport, ndlp,
3505 ndlp->nlp_last_elscmd = cmd;
3511 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
3514 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
3517 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
3518 ndlp->nlp_prev_state = ndlp->nlp_state;
3519 lpfc_nlp_set_state(vport, ndlp,
3520 NLP_STE_PLOGI_ISSUE);
3522 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
3525 ndlp->nlp_prev_state = ndlp->nlp_state;
3526 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
3527 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
3530 case ELS_CMD_NVMEPRLI:
3531 ndlp->nlp_prev_state = ndlp->nlp_state;
3532 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
3533 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
3536 ndlp->nlp_prev_state = ndlp->nlp_state;
3537 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
3538 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
3542 /* No retry ELS command <elsCmd> to remote NPORT <did> */
3544 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3545 "0137 No retry ELS command x%x to remote "
3546 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
3547 cmd, did, irsp->ulpStatus,
3548 irsp->un.ulpWord[4]);
3551 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3552 "0108 No retry ELS command x%x to remote "
3553 "NPORT x%x Retried:%d Error:x%x/%x\n",
3554 cmd, did, cmdiocb->retry, irsp->ulpStatus,
3555 irsp->un.ulpWord[4]);
3561 * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
3562 * @phba: pointer to lpfc hba data structure.
3563 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
3565 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
3566 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
3567 * checks to see whether there is a lpfc DMA buffer associated with the
3568 * response of the command IOCB. If so, it will be released before releasing
3569 * the lpfc DMA buffer associated with the IOCB itself.
3572 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3575 lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
3577 struct lpfc_dmabuf *buf_ptr;
3579 /* Free the response before processing the command. */
3580 if (!list_empty(&buf_ptr1->list)) {
3581 list_remove_head(&buf_ptr1->list, buf_ptr,
3584 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3587 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
3593 * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
3594 * @phba: pointer to lpfc hba data structure.
3595 * @buf_ptr: pointer to the lpfc dma buffer data structure.
3597 * This routine releases the lpfc Direct Memory Access (DMA) buffer
3598 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
3602 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3605 lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
3607 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3613 * lpfc_els_free_iocb - Free a command iocb and its associated resources
3614 * @phba: pointer to lpfc hba data structure.
3615 * @elsiocb: pointer to lpfc els command iocb data structure.
3617 * This routine frees a command IOCB and its associated resources. The
3618 * command IOCB data structure contains the reference to various associated
3619 * resources, these fields must be set to NULL if the associated reference
3621 * context1 - reference to ndlp
3622 * context2 - reference to cmd
3623 * context2->next - reference to rsp
3624 * context3 - reference to bpl
3626 * It first properly decrements the reference count held on ndlp for the
3627 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
3628 * set, it invokes the lpfc_els_free_data() routine to release the Direct
3629 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
3630 * adds the DMA buffer the @phba data structure for the delayed release.
3631 * If reference to the Buffer Pointer List (BPL) is present, the
3632 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
3633 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
3634 * invoked to release the IOCB data structure back to @phba IOCBQ list.
3637 * 0 - Success (currently, always return 0)
3640 lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
3642 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
3643 struct lpfc_nodelist *ndlp;
3645 ndlp = (struct lpfc_nodelist *)elsiocb->context1;
3647 if (ndlp->nlp_flag & NLP_DEFER_RM) {
3650 /* If the ndlp is not being used by another discovery
3653 if (!lpfc_nlp_not_used(ndlp)) {
3654 /* If ndlp is being used by another discovery
3655 * thread, just clear NLP_DEFER_RM
3657 ndlp->nlp_flag &= ~NLP_DEFER_RM;
3662 elsiocb->context1 = NULL;
3664 /* context2 = cmd, context2->next = rsp, context3 = bpl */
3665 if (elsiocb->context2) {
3666 if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
3667 /* Firmware could still be in progress of DMAing
3668 * payload, so don't free data buffer till after
3671 elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
3672 buf_ptr = elsiocb->context2;
3673 elsiocb->context2 = NULL;
3676 spin_lock_irq(&phba->hbalock);
3677 if (!list_empty(&buf_ptr->list)) {
3678 list_remove_head(&buf_ptr->list,
3679 buf_ptr1, struct lpfc_dmabuf,
3681 INIT_LIST_HEAD(&buf_ptr1->list);
3682 list_add_tail(&buf_ptr1->list,
3686 INIT_LIST_HEAD(&buf_ptr->list);
3687 list_add_tail(&buf_ptr->list, &phba->elsbuf);
3689 spin_unlock_irq(&phba->hbalock);
3692 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
3693 lpfc_els_free_data(phba, buf_ptr1);
3694 elsiocb->context2 = NULL;
3698 if (elsiocb->context3) {
3699 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
3700 lpfc_els_free_bpl(phba, buf_ptr);
3701 elsiocb->context3 = NULL;
3703 lpfc_sli_release_iocbq(phba, elsiocb);
3708 * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
3709 * @phba: pointer to lpfc hba data structure.
3710 * @cmdiocb: pointer to lpfc command iocb data structure.
3711 * @rspiocb: pointer to lpfc response iocb data structure.
3713 * This routine is the completion callback function to the Logout (LOGO)
3714 * Accept (ACC) Response ELS command. This routine is invoked to indicate
3715 * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
3716 * release the ndlp if it has the last reference remaining (reference count
3717 * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
3718 * field to NULL to inform the following lpfc_els_free_iocb() routine no
3719 * ndlp reference count needs to be decremented. Otherwise, the ndlp
3720 * reference use-count shall be decremented by the lpfc_els_free_iocb()
3721 * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
3722 * IOCB data structure.
3725 lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3726 struct lpfc_iocbq *rspiocb)
3728 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3729 struct lpfc_vport *vport = cmdiocb->vport;
3732 irsp = &rspiocb->iocb;
3733 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3734 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
3735 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
3736 /* ACC to LOGO completes to NPort <nlp_DID> */
3737 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3738 "0109 ACC to LOGO completes to NPort x%x "
3739 "Data: x%x x%x x%x\n",
3740 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3743 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
3744 /* NPort Recovery mode or node is just allocated */
3745 if (!lpfc_nlp_not_used(ndlp)) {
3746 /* If the ndlp is being used by another discovery
3747 * thread, just unregister the RPI.
3749 lpfc_unreg_rpi(vport, ndlp);
3751 /* Indicate the node has already released, should
3752 * not reference to it from within lpfc_els_free_iocb.
3754 cmdiocb->context1 = NULL;
3759 * The driver received a LOGO from the rport and has ACK'd it.
3760 * At this point, the driver is done so release the IOCB
3762 lpfc_els_free_iocb(phba, cmdiocb);
3766 * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
3767 * @phba: pointer to lpfc hba data structure.
3768 * @pmb: pointer to the driver internal queue element for mailbox command.
3770 * This routine is the completion callback function for unregister default
3771 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
3772 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
3773 * decrements the ndlp reference count held for this completion callback
3774 * function. After that, it invokes the lpfc_nlp_not_used() to check
3775 * whether there is only one reference left on the ndlp. If so, it will
3776 * perform one more decrement and trigger the release of the ndlp.
3779 lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3781 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
3782 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
3784 pmb->context1 = NULL;
3785 pmb->context2 = NULL;
3787 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3789 mempool_free(pmb, phba->mbox_mem_pool);
3791 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
3792 "0006 rpi%x DID:%x flg:%x %d map:%x %p\n",
3793 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
3794 kref_read(&ndlp->kref),
3795 ndlp->nlp_usg_map, ndlp);
3796 if (NLP_CHK_NODE_ACT(ndlp)) {
3798 /* This is the end of the default RPI cleanup logic for
3799 * this ndlp. If no other discovery threads are using
3800 * this ndlp, free all resources associated with it.
3802 lpfc_nlp_not_used(ndlp);
3804 lpfc_drop_node(ndlp->vport, ndlp);
3812 * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
3813 * @phba: pointer to lpfc hba data structure.
3814 * @cmdiocb: pointer to lpfc command iocb data structure.
3815 * @rspiocb: pointer to lpfc response iocb data structure.
3817 * This routine is the completion callback function for ELS Response IOCB
3818 * command. In normal case, this callback function just properly sets the
3819 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
3820 * field in the command IOCB is not NULL, the referred mailbox command will
3821 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
3822 * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
3823 * link down event occurred during the discovery, the lpfc_nlp_not_used()
3824 * routine shall be invoked trying to release the ndlp if no other threads
3825 * are currently referring it.
3828 lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3829 struct lpfc_iocbq *rspiocb)
3831 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3832 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
3833 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
3836 LPFC_MBOXQ_t *mbox = NULL;
3837 struct lpfc_dmabuf *mp = NULL;
3838 uint32_t ls_rjt = 0;
3840 irsp = &rspiocb->iocb;
3842 if (cmdiocb->context_un.mbox)
3843 mbox = cmdiocb->context_un.mbox;
3845 /* First determine if this is a LS_RJT cmpl. Note, this callback
3846 * function can have cmdiocb->contest1 (ndlp) field set to NULL.
3848 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
3849 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3850 (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) {
3851 /* A LS_RJT associated with Default RPI cleanup has its own
3852 * separate code path.
3854 if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
3858 /* Check to see if link went down during discovery */
3859 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) {
3861 mp = (struct lpfc_dmabuf *) mbox->context1;
3863 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3866 mempool_free(mbox, phba->mbox_mem_pool);
3868 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3869 (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
3870 if (lpfc_nlp_not_used(ndlp)) {
3872 /* Indicate the node has already released,
3873 * should not reference to it from within
3874 * the routine lpfc_els_free_iocb.
3876 cmdiocb->context1 = NULL;
3881 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3882 "ELS rsp cmpl: status:x%x/x%x did:x%x",
3883 irsp->ulpStatus, irsp->un.ulpWord[4],
3884 cmdiocb->iocb.un.elsreq64.remoteID);
3885 /* ELS response tag <ulpIoTag> completes */
3886 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3887 "0110 ELS response tag x%x completes "
3888 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
3889 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
3890 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
3891 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3894 if ((rspiocb->iocb.ulpStatus == 0)
3895 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
3896 lpfc_unreg_rpi(vport, ndlp);
3897 /* Increment reference count to ndlp to hold the
3898 * reference to ndlp for the callback function.
3900 mbox->context2 = lpfc_nlp_get(ndlp);
3901 mbox->vport = vport;
3902 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
3903 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
3904 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
3907 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
3908 ndlp->nlp_prev_state = ndlp->nlp_state;
3909 lpfc_nlp_set_state(vport, ndlp,
3910 NLP_STE_REG_LOGIN_ISSUE);
3913 ndlp->nlp_flag |= NLP_REG_LOGIN_SEND;
3914 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
3915 != MBX_NOT_FINISHED)
3918 /* Decrement the ndlp reference count we
3919 * set for this failed mailbox command.
3922 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
3924 /* ELS rsp: Cannot issue reg_login for <NPortid> */
3925 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3926 "0138 ELS rsp: Cannot issue reg_login for x%x "
3927 "Data: x%x x%x x%x\n",
3928 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3931 if (lpfc_nlp_not_used(ndlp)) {
3933 /* Indicate node has already been released,
3934 * should not reference to it from within
3935 * the routine lpfc_els_free_iocb.
3937 cmdiocb->context1 = NULL;
3940 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
3941 if (!lpfc_error_lost_link(irsp) &&
3942 ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
3943 if (lpfc_nlp_not_used(ndlp)) {
3945 /* Indicate node has already been
3946 * released, should not reference
3947 * to it from within the routine
3948 * lpfc_els_free_iocb.
3950 cmdiocb->context1 = NULL;
3954 mp = (struct lpfc_dmabuf *) mbox->context1;
3956 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3959 mempool_free(mbox, phba->mbox_mem_pool);
3962 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
3963 spin_lock_irq(shost->host_lock);
3964 ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI);
3965 spin_unlock_irq(shost->host_lock);
3967 /* If the node is not being used by another discovery thread,
3968 * and we are sending a reject, we are done with it.
3969 * Release driver reference count here and free associated
3973 if (lpfc_nlp_not_used(ndlp))
3974 /* Indicate node has already been released,
3975 * should not reference to it from within
3976 * the routine lpfc_els_free_iocb.
3978 cmdiocb->context1 = NULL;
3982 lpfc_els_free_iocb(phba, cmdiocb);
3987 * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
3988 * @vport: pointer to a host virtual N_Port data structure.
3989 * @flag: the els command code to be accepted.
3990 * @oldiocb: pointer to the original lpfc command iocb data structure.
3991 * @ndlp: pointer to a node-list data structure.
3992 * @mbox: pointer to the driver internal queue element for mailbox command.
3994 * This routine prepares and issues an Accept (ACC) response IOCB
3995 * command. It uses the @flag to properly set up the IOCB field for the
3996 * specific ACC response command to be issued and invokes the
3997 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
3998 * @mbox pointer is passed in, it will be put into the context_un.mbox
3999 * field of the IOCB for the completion callback function to issue the
4000 * mailbox command to the HBA later when callback is invoked.
4002 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4003 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4004 * will be stored into the context1 field of the IOCB for the completion
4005 * callback function to the corresponding response ELS IOCB command.
4008 * 0 - Successfully issued acc response
4009 * 1 - Failed to issue acc response
4012 lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
4013 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
4016 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4017 struct lpfc_hba *phba = vport->phba;
4020 struct lpfc_iocbq *elsiocb;
4022 struct serv_parm *sp;
4025 ELS_PKT *els_pkt_ptr;
4027 oldcmd = &oldiocb->iocb;
4031 cmdsize = sizeof(uint32_t);
4032 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
4033 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
4035 spin_lock_irq(shost->host_lock);
4036 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
4037 spin_unlock_irq(shost->host_lock);
4041 icmd = &elsiocb->iocb;
4042 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4043 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4044 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4045 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4046 pcmd += sizeof(uint32_t);
4048 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4049 "Issue ACC: did:x%x flg:x%x",
4050 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4054 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
4055 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
4056 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
4060 icmd = &elsiocb->iocb;
4061 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4062 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4063 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4066 elsiocb->context_un.mbox = mbox;
4068 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4069 pcmd += sizeof(uint32_t);
4070 sp = (struct serv_parm *)pcmd;
4072 if (flag == ELS_CMD_FLOGI) {
4073 /* Copy the received service parameters back */
4074 memcpy(sp, &phba->fc_fabparam,
4075 sizeof(struct serv_parm));
4077 /* Clear the F_Port bit */
4080 /* Mark all class service parameters as invalid */
4081 sp->cls1.classValid = 0;
4082 sp->cls2.classValid = 0;
4083 sp->cls3.classValid = 0;
4084 sp->cls4.classValid = 0;
4086 /* Copy our worldwide names */
4087 memcpy(&sp->portName, &vport->fc_sparam.portName,
4088 sizeof(struct lpfc_name));
4089 memcpy(&sp->nodeName, &vport->fc_sparam.nodeName,
4090 sizeof(struct lpfc_name));
4092 memcpy(pcmd, &vport->fc_sparam,
4093 sizeof(struct serv_parm));
4095 sp->cmn.valid_vendor_ver_level = 0;
4096 memset(sp->un.vendorVersion, 0,
4097 sizeof(sp->un.vendorVersion));
4099 /* If our firmware supports this feature, convey that
4100 * info to the target using the vendor specific field.
4102 if (phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) {
4103 sp->cmn.valid_vendor_ver_level = 1;
4104 sp->un.vv.vid = cpu_to_be32(LPFC_VV_EMLX_ID);
4106 cpu_to_be32(LPFC_VV_SUPPRESS_RSP);
4110 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4111 "Issue ACC FLOGI/PLOGI: did:x%x flg:x%x",
4112 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4115 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
4116 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
4117 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
4121 icmd = &elsiocb->iocb;
4122 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4123 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4124 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4126 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
4127 sizeof(uint32_t) + sizeof(PRLO));
4128 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
4129 els_pkt_ptr = (ELS_PKT *) pcmd;
4130 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
4132 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4133 "Issue ACC PRLO: did:x%x flg:x%x",
4134 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4139 /* Xmit ELS ACC response tag <ulpIoTag> */
4140 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4141 "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
4142 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x "
4144 elsiocb->iotag, elsiocb->iocb.ulpContext,
4145 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4146 ndlp->nlp_rpi, vport->fc_flag);
4147 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
4148 spin_lock_irq(shost->host_lock);
4149 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED ||
4150 ndlp->nlp_flag & NLP_REG_LOGIN_SEND))
4151 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
4152 spin_unlock_irq(shost->host_lock);
4153 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
4155 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4158 phba->fc_stat.elsXmitACC++;
4159 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4160 if (rc == IOCB_ERROR) {
4161 lpfc_els_free_iocb(phba, elsiocb);
4168 * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command
4169 * @vport: pointer to a virtual N_Port data structure.
4171 * @oldiocb: pointer to the original lpfc command iocb data structure.
4172 * @ndlp: pointer to a node-list data structure.
4173 * @mbox: pointer to the driver internal queue element for mailbox command.
4175 * This routine prepares and issue an Reject (RJT) response IOCB
4176 * command. If a @mbox pointer is passed in, it will be put into the
4177 * context_un.mbox field of the IOCB for the completion callback function
4178 * to issue to the HBA later.
4180 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4181 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4182 * will be stored into the context1 field of the IOCB for the completion
4183 * callback function to the reject response ELS IOCB command.
4186 * 0 - Successfully issued reject response
4187 * 1 - Failed to issue reject response
4190 lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
4191 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
4194 struct lpfc_hba *phba = vport->phba;
4197 struct lpfc_iocbq *elsiocb;
4202 cmdsize = 2 * sizeof(uint32_t);
4203 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4204 ndlp->nlp_DID, ELS_CMD_LS_RJT);
4208 icmd = &elsiocb->iocb;
4209 oldcmd = &oldiocb->iocb;
4210 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4211 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4212 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4214 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
4215 pcmd += sizeof(uint32_t);
4216 *((uint32_t *) (pcmd)) = rejectError;
4219 elsiocb->context_un.mbox = mbox;
4221 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
4222 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4223 "0129 Xmit ELS RJT x%x response tag x%x "
4224 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
4226 rejectError, elsiocb->iotag,
4227 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
4228 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
4229 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4230 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
4231 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
4233 phba->fc_stat.elsXmitLSRJT++;
4234 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4235 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4237 if (rc == IOCB_ERROR) {
4238 lpfc_els_free_iocb(phba, elsiocb);
4245 * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
4246 * @vport: pointer to a virtual N_Port data structure.
4247 * @oldiocb: pointer to the original lpfc command iocb data structure.
4248 * @ndlp: pointer to a node-list data structure.
4250 * This routine prepares and issues an Accept (ACC) response to Address
4251 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
4252 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
4254 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4255 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4256 * will be stored into the context1 field of the IOCB for the completion
4257 * callback function to the ADISC Accept response ELS IOCB command.
4260 * 0 - Successfully issued acc adisc response
4261 * 1 - Failed to issue adisc acc response
4264 lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
4265 struct lpfc_nodelist *ndlp)
4267 struct lpfc_hba *phba = vport->phba;
4269 IOCB_t *icmd, *oldcmd;
4270 struct lpfc_iocbq *elsiocb;
4275 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
4276 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4277 ndlp->nlp_DID, ELS_CMD_ACC);
4281 icmd = &elsiocb->iocb;
4282 oldcmd = &oldiocb->iocb;
4283 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4284 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4286 /* Xmit ADISC ACC response tag <ulpIoTag> */
4287 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4288 "0130 Xmit ADISC ACC response iotag x%x xri: "
4289 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
4290 elsiocb->iotag, elsiocb->iocb.ulpContext,
4291 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4293 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4295 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4296 pcmd += sizeof(uint32_t);
4298 ap = (ADISC *) (pcmd);
4299 ap->hardAL_PA = phba->fc_pref_ALPA;
4300 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
4301 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
4302 ap->DID = be32_to_cpu(vport->fc_myDID);
4304 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4305 "Issue ACC ADISC: did:x%x flg:x%x",
4306 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4308 phba->fc_stat.elsXmitACC++;
4309 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4310 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4311 if (rc == IOCB_ERROR) {
4312 lpfc_els_free_iocb(phba, elsiocb);
4319 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
4320 * @vport: pointer to a virtual N_Port data structure.
4321 * @oldiocb: pointer to the original lpfc command iocb data structure.
4322 * @ndlp: pointer to a node-list data structure.
4324 * This routine prepares and issues an Accept (ACC) response to Process
4325 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
4326 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
4328 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4329 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4330 * will be stored into the context1 field of the IOCB for the completion
4331 * callback function to the PRLI Accept response ELS IOCB command.
4334 * 0 - Successfully issued acc prli response
4335 * 1 - Failed to issue acc prli response
4338 lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
4339 struct lpfc_nodelist *ndlp)
4341 struct lpfc_hba *phba = vport->phba;
4343 struct lpfc_nvme_prli *npr_nvme;
4347 struct lpfc_iocbq *elsiocb;
4350 uint32_t prli_fc4_req, *req_payload;
4351 struct lpfc_dmabuf *req_buf;
4355 /* Need the incoming PRLI payload to determine if the ACC is for an
4356 * FC4 or NVME PRLI type. The PRLI type is at word 1.
4358 req_buf = (struct lpfc_dmabuf *)oldiocb->context2;
4359 req_payload = (((uint32_t *)req_buf->virt) + 1);
4361 /* PRLI type payload is at byte 3 for FCP or NVME. */
4362 prli_fc4_req = be32_to_cpu(*req_payload);
4363 prli_fc4_req = (prli_fc4_req >> 24) & 0xff;
4364 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4365 "6127 PRLI_ACC: Req Type x%x, Word1 x%08x\n",
4366 prli_fc4_req, *((uint32_t *)req_payload));
4368 if (prli_fc4_req == PRLI_FCP_TYPE) {
4369 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
4370 elsrspcmd = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
4371 } else if (prli_fc4_req & PRLI_NVME_TYPE) {
4372 cmdsize = sizeof(uint32_t) + sizeof(struct lpfc_nvme_prli);
4373 elsrspcmd = (ELS_CMD_ACC | (ELS_CMD_NVMEPRLI & ~ELS_RSP_MASK));
4378 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4379 ndlp->nlp_DID, elsrspcmd);
4383 icmd = &elsiocb->iocb;
4384 oldcmd = &oldiocb->iocb;
4385 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4386 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4388 /* Xmit PRLI ACC response tag <ulpIoTag> */
4389 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4390 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
4391 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
4392 elsiocb->iotag, elsiocb->iocb.ulpContext,
4393 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4395 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4396 memset(pcmd, 0, cmdsize);
4398 *((uint32_t *)(pcmd)) = elsrspcmd;
4399 pcmd += sizeof(uint32_t);
4401 /* For PRLI, remainder of payload is PRLI parameter page */
4404 if (prli_fc4_req == PRLI_FCP_TYPE) {
4406 * If the remote port is a target and our firmware version
4407 * is 3.20 or later, set the following bits for FC-TAPE
4410 npr = (PRLI *) pcmd;
4411 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
4412 (vpd->rev.feaLevelHigh >= 0x02)) {
4413 npr->ConfmComplAllowed = 1;
4415 npr->TaskRetryIdReq = 1;
4417 npr->acceptRspCode = PRLI_REQ_EXECUTED;
4418 npr->estabImagePair = 1;
4419 npr->readXferRdyDis = 1;
4420 npr->ConfmComplAllowed = 1;
4421 npr->prliType = PRLI_FCP_TYPE;
4422 npr->initiatorFunc = 1;
4423 } else if (prli_fc4_req & PRLI_NVME_TYPE) {
4424 /* Respond with an NVME PRLI Type */
4425 npr_nvme = (struct lpfc_nvme_prli *) pcmd;
4426 bf_set(prli_type_code, npr_nvme, PRLI_NVME_TYPE);
4427 bf_set(prli_estabImagePair, npr_nvme, 0); /* Should be 0 */
4428 bf_set(prli_acc_rsp_code, npr_nvme, PRLI_REQ_EXECUTED);
4429 if (phba->nvmet_support) {
4430 bf_set(prli_tgt, npr_nvme, 1);
4431 bf_set(prli_disc, npr_nvme, 1);
4432 if (phba->cfg_nvme_enable_fb) {
4433 bf_set(prli_fba, npr_nvme, 1);
4435 /* TBD. Target mode needs to post buffers
4436 * that support the configured first burst
4439 bf_set(prli_fb_sz, npr_nvme,
4440 phba->cfg_nvmet_fb_size);
4443 bf_set(prli_init, npr_nvme, 1);
4446 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
4447 "6015 NVME issue PRLI ACC word1 x%08x "
4448 "word4 x%08x word5 x%08x flag x%x, "
4449 "fcp_info x%x nlp_type x%x\n",
4450 npr_nvme->word1, npr_nvme->word4,
4451 npr_nvme->word5, ndlp->nlp_flag,
4452 ndlp->nlp_fcp_info, ndlp->nlp_type);
4453 npr_nvme->word1 = cpu_to_be32(npr_nvme->word1);
4454 npr_nvme->word4 = cpu_to_be32(npr_nvme->word4);
4455 npr_nvme->word5 = cpu_to_be32(npr_nvme->word5);
4457 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4458 "6128 Unknown FC_TYPE x%x x%x ndlp x%06x\n",
4459 prli_fc4_req, ndlp->nlp_fc4_type,
4462 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4463 "Issue ACC PRLI: did:x%x flg:x%x",
4464 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4466 phba->fc_stat.elsXmitACC++;
4467 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4469 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4470 if (rc == IOCB_ERROR) {
4471 lpfc_els_free_iocb(phba, elsiocb);
4478 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
4479 * @vport: pointer to a virtual N_Port data structure.
4480 * @format: rnid command format.
4481 * @oldiocb: pointer to the original lpfc command iocb data structure.
4482 * @ndlp: pointer to a node-list data structure.
4484 * This routine issues a Request Node Identification Data (RNID) Accept
4485 * (ACC) response. It constructs the RNID ACC response command according to
4486 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
4487 * issue the response. Note that this command does not need to hold the ndlp
4488 * reference count for the callback. So, the ndlp reference count taken by
4489 * the lpfc_prep_els_iocb() routine is put back and the context1 field of
4490 * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
4491 * there is no ndlp reference available.
4493 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4494 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4495 * will be stored into the context1 field of the IOCB for the completion
4496 * callback function. However, for the RNID Accept Response ELS command,
4497 * this is undone later by this routine after the IOCB is allocated.
4500 * 0 - Successfully issued acc rnid response
4501 * 1 - Failed to issue acc rnid response
4504 lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
4505 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
4507 struct lpfc_hba *phba = vport->phba;
4509 IOCB_t *icmd, *oldcmd;
4510 struct lpfc_iocbq *elsiocb;
4515 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
4516 + (2 * sizeof(struct lpfc_name));
4518 cmdsize += sizeof(RNID_TOP_DISC);
4520 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4521 ndlp->nlp_DID, ELS_CMD_ACC);
4525 icmd = &elsiocb->iocb;
4526 oldcmd = &oldiocb->iocb;
4527 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4528 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4530 /* Xmit RNID ACC response tag <ulpIoTag> */
4531 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4532 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
4533 elsiocb->iotag, elsiocb->iocb.ulpContext);
4534 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4535 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4536 pcmd += sizeof(uint32_t);
4538 memset(pcmd, 0, sizeof(RNID));
4539 rn = (RNID *) (pcmd);
4540 rn->Format = format;
4541 rn->CommonLen = (2 * sizeof(struct lpfc_name));
4542 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
4543 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
4546 rn->SpecificLen = 0;
4548 case RNID_TOPOLOGY_DISC:
4549 rn->SpecificLen = sizeof(RNID_TOP_DISC);
4550 memcpy(&rn->un.topologyDisc.portName,
4551 &vport->fc_portname, sizeof(struct lpfc_name));
4552 rn->un.topologyDisc.unitType = RNID_HBA;
4553 rn->un.topologyDisc.physPort = 0;
4554 rn->un.topologyDisc.attachedNodes = 0;
4558 rn->SpecificLen = 0;
4562 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4563 "Issue ACC RNID: did:x%x flg:x%x",
4564 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4566 phba->fc_stat.elsXmitACC++;
4567 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4569 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4570 if (rc == IOCB_ERROR) {
4571 lpfc_els_free_iocb(phba, elsiocb);
4578 * lpfc_els_clear_rrq - Clear the rq that this rrq describes.
4579 * @vport: pointer to a virtual N_Port data structure.
4580 * @iocb: pointer to the lpfc command iocb data structure.
4581 * @ndlp: pointer to a node-list data structure.
4586 lpfc_els_clear_rrq(struct lpfc_vport *vport,
4587 struct lpfc_iocbq *iocb, struct lpfc_nodelist *ndlp)
4589 struct lpfc_hba *phba = vport->phba;
4594 struct lpfc_node_rrq *prrq;
4597 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) iocb->context2)->virt);
4598 pcmd += sizeof(uint32_t);
4599 rrq = (struct RRQ *)pcmd;
4600 rrq->rrq_exchg = be32_to_cpu(rrq->rrq_exchg);
4601 rxid = bf_get(rrq_rxid, rrq);
4603 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4604 "2883 Clear RRQ for SID:x%x OXID:x%x RXID:x%x"
4606 be32_to_cpu(bf_get(rrq_did, rrq)),
4607 bf_get(rrq_oxid, rrq),
4609 iocb->iotag, iocb->iocb.ulpContext);
4611 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4612 "Clear RRQ: did:x%x flg:x%x exchg:x%.08x",
4613 ndlp->nlp_DID, ndlp->nlp_flag, rrq->rrq_exchg);
4614 if (vport->fc_myDID == be32_to_cpu(bf_get(rrq_did, rrq)))
4615 xri = bf_get(rrq_oxid, rrq);
4618 prrq = lpfc_get_active_rrq(vport, xri, ndlp->nlp_DID);
4620 lpfc_clr_rrq_active(phba, xri, prrq);
4625 * lpfc_els_rsp_echo_acc - Issue echo acc response
4626 * @vport: pointer to a virtual N_Port data structure.
4627 * @data: pointer to echo data to return in the accept.
4628 * @oldiocb: pointer to the original lpfc command iocb data structure.
4629 * @ndlp: pointer to a node-list data structure.
4632 * 0 - Successfully issued acc echo response
4633 * 1 - Failed to issue acc echo response
4636 lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data,
4637 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
4639 struct lpfc_hba *phba = vport->phba;
4640 struct lpfc_iocbq *elsiocb;
4645 cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len;
4647 /* The accumulated length can exceed the BPL_SIZE. For
4648 * now, use this as the limit
4650 if (cmdsize > LPFC_BPL_SIZE)
4651 cmdsize = LPFC_BPL_SIZE;
4652 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4653 ndlp->nlp_DID, ELS_CMD_ACC);
4657 elsiocb->iocb.ulpContext = oldiocb->iocb.ulpContext; /* Xri / rx_id */
4658 elsiocb->iocb.unsli3.rcvsli3.ox_id = oldiocb->iocb.unsli3.rcvsli3.ox_id;
4660 /* Xmit ECHO ACC response tag <ulpIoTag> */
4661 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4662 "2876 Xmit ECHO ACC response tag x%x xri x%x\n",
4663 elsiocb->iotag, elsiocb->iocb.ulpContext);
4664 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4665 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4666 pcmd += sizeof(uint32_t);
4667 memcpy(pcmd, data, cmdsize - sizeof(uint32_t));
4669 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4670 "Issue ACC ECHO: did:x%x flg:x%x",
4671 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4673 phba->fc_stat.elsXmitACC++;
4674 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4676 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4677 if (rc == IOCB_ERROR) {
4678 lpfc_els_free_iocb(phba, elsiocb);
4685 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
4686 * @vport: pointer to a host virtual N_Port data structure.
4688 * This routine issues Address Discover (ADISC) ELS commands to those
4689 * N_Ports which are in node port recovery state and ADISC has not been issued
4690 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
4691 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
4692 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
4693 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
4694 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
4695 * IOCBs quit for later pick up. On the other hand, after walking through
4696 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
4697 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
4698 * no more ADISC need to be sent.
4701 * The number of N_Ports with adisc issued.
4704 lpfc_els_disc_adisc(struct lpfc_vport *vport)
4706 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4707 struct lpfc_nodelist *ndlp, *next_ndlp;
4710 /* go thru NPR nodes and issue any remaining ELS ADISCs */
4711 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
4712 if (!NLP_CHK_NODE_ACT(ndlp))
4714 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
4715 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
4716 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
4717 spin_lock_irq(shost->host_lock);
4718 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
4719 spin_unlock_irq(shost->host_lock);
4720 ndlp->nlp_prev_state = ndlp->nlp_state;
4721 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
4722 lpfc_issue_els_adisc(vport, ndlp, 0);
4724 vport->num_disc_nodes++;
4725 if (vport->num_disc_nodes >=
4726 vport->cfg_discovery_threads) {
4727 spin_lock_irq(shost->host_lock);
4728 vport->fc_flag |= FC_NLP_MORE;
4729 spin_unlock_irq(shost->host_lock);
4734 if (sentadisc == 0) {
4735 spin_lock_irq(shost->host_lock);
4736 vport->fc_flag &= ~FC_NLP_MORE;
4737 spin_unlock_irq(shost->host_lock);
4743 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
4744 * @vport: pointer to a host virtual N_Port data structure.
4746 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
4747 * which are in node port recovery state, with a @vport. Each time an ELS
4748 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
4749 * the per @vport number of discover count (num_disc_nodes) shall be
4750 * incremented. If the num_disc_nodes reaches a pre-configured threshold
4751 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
4752 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
4753 * later pick up. On the other hand, after walking through all the ndlps with
4754 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
4755 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
4756 * PLOGI need to be sent.
4759 * The number of N_Ports with plogi issued.
4762 lpfc_els_disc_plogi(struct lpfc_vport *vport)
4764 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4765 struct lpfc_nodelist *ndlp, *next_ndlp;
4768 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
4769 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
4770 if (!NLP_CHK_NODE_ACT(ndlp))
4772 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
4773 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
4774 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
4775 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
4776 ndlp->nlp_prev_state = ndlp->nlp_state;
4777 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
4778 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
4780 vport->num_disc_nodes++;
4781 if (vport->num_disc_nodes >=
4782 vport->cfg_discovery_threads) {
4783 spin_lock_irq(shost->host_lock);
4784 vport->fc_flag |= FC_NLP_MORE;
4785 spin_unlock_irq(shost->host_lock);
4791 lpfc_set_disctmo(vport);
4794 spin_lock_irq(shost->host_lock);
4795 vport->fc_flag &= ~FC_NLP_MORE;
4796 spin_unlock_irq(shost->host_lock);
4802 lpfc_rdp_res_link_service(struct fc_rdp_link_service_desc *desc,
4806 desc->tag = cpu_to_be32(RDP_LINK_SERVICE_DESC_TAG);
4807 desc->payload.els_req = word0;
4808 desc->length = cpu_to_be32(sizeof(desc->payload));
4810 return sizeof(struct fc_rdp_link_service_desc);
4814 lpfc_rdp_res_sfp_desc(struct fc_rdp_sfp_desc *desc,
4815 uint8_t *page_a0, uint8_t *page_a2)
4817 uint16_t wavelength;
4818 uint16_t temperature;
4824 struct sff_trasnceiver_codes_byte4 *trasn_code_byte4;
4825 struct sff_trasnceiver_codes_byte5 *trasn_code_byte5;
4827 desc->tag = cpu_to_be32(RDP_SFP_DESC_TAG);
4829 trasn_code_byte4 = (struct sff_trasnceiver_codes_byte4 *)
4830 &page_a0[SSF_TRANSCEIVER_CODE_B4];
4831 trasn_code_byte5 = (struct sff_trasnceiver_codes_byte5 *)
4832 &page_a0[SSF_TRANSCEIVER_CODE_B5];
4834 if ((trasn_code_byte4->fc_sw_laser) ||
4835 (trasn_code_byte5->fc_sw_laser_sl) ||
4836 (trasn_code_byte5->fc_sw_laser_sn)) { /* check if its short WL */
4837 flag |= (SFP_FLAG_PT_SWLASER << SFP_FLAG_PT_SHIFT);
4838 } else if (trasn_code_byte4->fc_lw_laser) {
4839 wavelength = (page_a0[SSF_WAVELENGTH_B1] << 8) |
4840 page_a0[SSF_WAVELENGTH_B0];
4841 if (wavelength == SFP_WAVELENGTH_LC1310)
4842 flag |= SFP_FLAG_PT_LWLASER_LC1310 << SFP_FLAG_PT_SHIFT;
4843 if (wavelength == SFP_WAVELENGTH_LL1550)
4844 flag |= SFP_FLAG_PT_LWLASER_LL1550 << SFP_FLAG_PT_SHIFT;
4846 /* check if its SFP+ */
4847 flag |= ((page_a0[SSF_IDENTIFIER] == SFF_PG0_IDENT_SFP) ?
4848 SFP_FLAG_CT_SFP_PLUS : SFP_FLAG_CT_UNKNOWN)
4849 << SFP_FLAG_CT_SHIFT;
4851 /* check if its OPTICAL */
4852 flag |= ((page_a0[SSF_CONNECTOR] == SFF_PG0_CONNECTOR_LC) ?
4853 SFP_FLAG_IS_OPTICAL_PORT : 0)
4854 << SFP_FLAG_IS_OPTICAL_SHIFT;
4856 temperature = (page_a2[SFF_TEMPERATURE_B1] << 8 |
4857 page_a2[SFF_TEMPERATURE_B0]);
4858 vcc = (page_a2[SFF_VCC_B1] << 8 |
4859 page_a2[SFF_VCC_B0]);
4860 tx_power = (page_a2[SFF_TXPOWER_B1] << 8 |
4861 page_a2[SFF_TXPOWER_B0]);
4862 tx_bias = (page_a2[SFF_TX_BIAS_CURRENT_B1] << 8 |
4863 page_a2[SFF_TX_BIAS_CURRENT_B0]);
4864 rx_power = (page_a2[SFF_RXPOWER_B1] << 8 |
4865 page_a2[SFF_RXPOWER_B0]);
4866 desc->sfp_info.temperature = cpu_to_be16(temperature);
4867 desc->sfp_info.rx_power = cpu_to_be16(rx_power);
4868 desc->sfp_info.tx_bias = cpu_to_be16(tx_bias);
4869 desc->sfp_info.tx_power = cpu_to_be16(tx_power);
4870 desc->sfp_info.vcc = cpu_to_be16(vcc);
4872 desc->sfp_info.flags = cpu_to_be16(flag);
4873 desc->length = cpu_to_be32(sizeof(desc->sfp_info));
4875 return sizeof(struct fc_rdp_sfp_desc);
4879 lpfc_rdp_res_link_error(struct fc_rdp_link_error_status_desc *desc,
4884 desc->tag = cpu_to_be32(RDP_LINK_ERROR_STATUS_DESC_TAG);
4886 type = VN_PT_PHY_PF_PORT << VN_PT_PHY_SHIFT;
4888 desc->info.port_type = cpu_to_be32(type);
4890 desc->info.link_status.link_failure_cnt =
4891 cpu_to_be32(stat->linkFailureCnt);
4892 desc->info.link_status.loss_of_synch_cnt =
4893 cpu_to_be32(stat->lossSyncCnt);
4894 desc->info.link_status.loss_of_signal_cnt =
4895 cpu_to_be32(stat->lossSignalCnt);
4896 desc->info.link_status.primitive_seq_proto_err =
4897 cpu_to_be32(stat->primSeqErrCnt);
4898 desc->info.link_status.invalid_trans_word =
4899 cpu_to_be32(stat->invalidXmitWord);
4900 desc->info.link_status.invalid_crc_cnt = cpu_to_be32(stat->crcCnt);
4902 desc->length = cpu_to_be32(sizeof(desc->info));
4904 return sizeof(struct fc_rdp_link_error_status_desc);
4908 lpfc_rdp_res_bbc_desc(struct fc_rdp_bbc_desc *desc, READ_LNK_VAR *stat,
4909 struct lpfc_vport *vport)
4913 desc->tag = cpu_to_be32(RDP_BBC_DESC_TAG);
4915 bbCredit = vport->fc_sparam.cmn.bbCreditLsb |
4916 (vport->fc_sparam.cmn.bbCreditMsb << 8);
4917 desc->bbc_info.port_bbc = cpu_to_be32(bbCredit);
4918 if (vport->phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
4919 bbCredit = vport->phba->fc_fabparam.cmn.bbCreditLsb |
4920 (vport->phba->fc_fabparam.cmn.bbCreditMsb << 8);
4921 desc->bbc_info.attached_port_bbc = cpu_to_be32(bbCredit);
4923 desc->bbc_info.attached_port_bbc = 0;
4926 desc->bbc_info.rtt = 0;
4927 desc->length = cpu_to_be32(sizeof(desc->bbc_info));
4929 return sizeof(struct fc_rdp_bbc_desc);
4933 lpfc_rdp_res_oed_temp_desc(struct lpfc_hba *phba,
4934 struct fc_rdp_oed_sfp_desc *desc, uint8_t *page_a2)
4938 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
4940 desc->oed_info.hi_alarm = page_a2[SSF_TEMP_HIGH_ALARM];
4941 desc->oed_info.lo_alarm = page_a2[SSF_TEMP_LOW_ALARM];
4942 desc->oed_info.hi_warning = page_a2[SSF_TEMP_HIGH_WARNING];
4943 desc->oed_info.lo_warning = page_a2[SSF_TEMP_LOW_WARNING];
4945 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TEMPERATURE)
4946 flags |= RDP_OET_HIGH_ALARM;
4947 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TEMPERATURE)
4948 flags |= RDP_OET_LOW_ALARM;
4949 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TEMPERATURE)
4950 flags |= RDP_OET_HIGH_WARNING;
4951 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TEMPERATURE)
4952 flags |= RDP_OET_LOW_WARNING;
4954 flags |= ((0xf & RDP_OED_TEMPERATURE) << RDP_OED_TYPE_SHIFT);
4955 desc->oed_info.function_flags = cpu_to_be32(flags);
4956 desc->length = cpu_to_be32(sizeof(desc->oed_info));
4957 return sizeof(struct fc_rdp_oed_sfp_desc);
4961 lpfc_rdp_res_oed_voltage_desc(struct lpfc_hba *phba,
4962 struct fc_rdp_oed_sfp_desc *desc,
4967 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
4969 desc->oed_info.hi_alarm = page_a2[SSF_VOLTAGE_HIGH_ALARM];
4970 desc->oed_info.lo_alarm = page_a2[SSF_VOLTAGE_LOW_ALARM];
4971 desc->oed_info.hi_warning = page_a2[SSF_VOLTAGE_HIGH_WARNING];
4972 desc->oed_info.lo_warning = page_a2[SSF_VOLTAGE_LOW_WARNING];
4974 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_VOLTAGE)
4975 flags |= RDP_OET_HIGH_ALARM;
4976 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_VOLTAGE)
4977 flags |= RDP_OET_LOW_ALARM;
4978 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_VOLTAGE)
4979 flags |= RDP_OET_HIGH_WARNING;
4980 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_VOLTAGE)
4981 flags |= RDP_OET_LOW_WARNING;
4983 flags |= ((0xf & RDP_OED_VOLTAGE) << RDP_OED_TYPE_SHIFT);
4984 desc->oed_info.function_flags = cpu_to_be32(flags);
4985 desc->length = cpu_to_be32(sizeof(desc->oed_info));
4986 return sizeof(struct fc_rdp_oed_sfp_desc);
4990 lpfc_rdp_res_oed_txbias_desc(struct lpfc_hba *phba,
4991 struct fc_rdp_oed_sfp_desc *desc,
4996 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
4998 desc->oed_info.hi_alarm = page_a2[SSF_BIAS_HIGH_ALARM];
4999 desc->oed_info.lo_alarm = page_a2[SSF_BIAS_LOW_ALARM];
5000 desc->oed_info.hi_warning = page_a2[SSF_BIAS_HIGH_WARNING];
5001 desc->oed_info.lo_warning = page_a2[SSF_BIAS_LOW_WARNING];
5003 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TXBIAS)
5004 flags |= RDP_OET_HIGH_ALARM;
5005 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TXBIAS)
5006 flags |= RDP_OET_LOW_ALARM;
5007 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TXBIAS)
5008 flags |= RDP_OET_HIGH_WARNING;
5009 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TXBIAS)
5010 flags |= RDP_OET_LOW_WARNING;
5012 flags |= ((0xf & RDP_OED_TXBIAS) << RDP_OED_TYPE_SHIFT);
5013 desc->oed_info.function_flags = cpu_to_be32(flags);
5014 desc->length = cpu_to_be32(sizeof(desc->oed_info));
5015 return sizeof(struct fc_rdp_oed_sfp_desc);
5019 lpfc_rdp_res_oed_txpower_desc(struct lpfc_hba *phba,
5020 struct fc_rdp_oed_sfp_desc *desc,
5025 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5027 desc->oed_info.hi_alarm = page_a2[SSF_TXPOWER_HIGH_ALARM];
5028 desc->oed_info.lo_alarm = page_a2[SSF_TXPOWER_LOW_ALARM];
5029 desc->oed_info.hi_warning = page_a2[SSF_TXPOWER_HIGH_WARNING];
5030 desc->oed_info.lo_warning = page_a2[SSF_TXPOWER_LOW_WARNING];
5032 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TXPOWER)
5033 flags |= RDP_OET_HIGH_ALARM;
5034 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TXPOWER)
5035 flags |= RDP_OET_LOW_ALARM;
5036 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TXPOWER)
5037 flags |= RDP_OET_HIGH_WARNING;
5038 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TXPOWER)
5039 flags |= RDP_OET_LOW_WARNING;
5041 flags |= ((0xf & RDP_OED_TXPOWER) << RDP_OED_TYPE_SHIFT);
5042 desc->oed_info.function_flags = cpu_to_be32(flags);
5043 desc->length = cpu_to_be32(sizeof(desc->oed_info));
5044 return sizeof(struct fc_rdp_oed_sfp_desc);
5049 lpfc_rdp_res_oed_rxpower_desc(struct lpfc_hba *phba,
5050 struct fc_rdp_oed_sfp_desc *desc,
5055 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5057 desc->oed_info.hi_alarm = page_a2[SSF_RXPOWER_HIGH_ALARM];
5058 desc->oed_info.lo_alarm = page_a2[SSF_RXPOWER_LOW_ALARM];
5059 desc->oed_info.hi_warning = page_a2[SSF_RXPOWER_HIGH_WARNING];
5060 desc->oed_info.lo_warning = page_a2[SSF_RXPOWER_LOW_WARNING];
5062 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_RXPOWER)
5063 flags |= RDP_OET_HIGH_ALARM;
5064 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_RXPOWER)
5065 flags |= RDP_OET_LOW_ALARM;
5066 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_RXPOWER)
5067 flags |= RDP_OET_HIGH_WARNING;
5068 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_RXPOWER)
5069 flags |= RDP_OET_LOW_WARNING;
5071 flags |= ((0xf & RDP_OED_RXPOWER) << RDP_OED_TYPE_SHIFT);
5072 desc->oed_info.function_flags = cpu_to_be32(flags);
5073 desc->length = cpu_to_be32(sizeof(desc->oed_info));
5074 return sizeof(struct fc_rdp_oed_sfp_desc);
5078 lpfc_rdp_res_opd_desc(struct fc_rdp_opd_sfp_desc *desc,
5079 uint8_t *page_a0, struct lpfc_vport *vport)
5081 desc->tag = cpu_to_be32(RDP_OPD_DESC_TAG);
5082 memcpy(desc->opd_info.vendor_name, &page_a0[SSF_VENDOR_NAME], 16);
5083 memcpy(desc->opd_info.model_number, &page_a0[SSF_VENDOR_PN], 16);
5084 memcpy(desc->opd_info.serial_number, &page_a0[SSF_VENDOR_SN], 16);
5085 memcpy(desc->opd_info.revision, &page_a0[SSF_VENDOR_REV], 4);
5086 memcpy(desc->opd_info.date, &page_a0[SSF_DATE_CODE], 8);
5087 desc->length = cpu_to_be32(sizeof(desc->opd_info));
5088 return sizeof(struct fc_rdp_opd_sfp_desc);
5092 lpfc_rdp_res_fec_desc(struct fc_fec_rdp_desc *desc, READ_LNK_VAR *stat)
5094 if (bf_get(lpfc_read_link_stat_gec2, stat) == 0)
5096 desc->tag = cpu_to_be32(RDP_FEC_DESC_TAG);
5098 desc->info.CorrectedBlocks =
5099 cpu_to_be32(stat->fecCorrBlkCount);
5100 desc->info.UncorrectableBlocks =
5101 cpu_to_be32(stat->fecUncorrBlkCount);
5103 desc->length = cpu_to_be32(sizeof(desc->info));
5105 return sizeof(struct fc_fec_rdp_desc);
5109 lpfc_rdp_res_speed(struct fc_rdp_port_speed_desc *desc, struct lpfc_hba *phba)
5111 uint16_t rdp_cap = 0;
5114 desc->tag = cpu_to_be32(RDP_PORT_SPEED_DESC_TAG);
5116 switch (phba->fc_linkspeed) {
5117 case LPFC_LINK_SPEED_1GHZ:
5118 rdp_speed = RDP_PS_1GB;
5120 case LPFC_LINK_SPEED_2GHZ:
5121 rdp_speed = RDP_PS_2GB;
5123 case LPFC_LINK_SPEED_4GHZ:
5124 rdp_speed = RDP_PS_4GB;
5126 case LPFC_LINK_SPEED_8GHZ:
5127 rdp_speed = RDP_PS_8GB;
5129 case LPFC_LINK_SPEED_10GHZ:
5130 rdp_speed = RDP_PS_10GB;
5132 case LPFC_LINK_SPEED_16GHZ:
5133 rdp_speed = RDP_PS_16GB;
5135 case LPFC_LINK_SPEED_32GHZ:
5136 rdp_speed = RDP_PS_32GB;
5139 rdp_speed = RDP_PS_UNKNOWN;
5143 desc->info.port_speed.speed = cpu_to_be16(rdp_speed);
5145 if (phba->lmt & LMT_32Gb)
5146 rdp_cap |= RDP_PS_32GB;
5147 if (phba->lmt & LMT_16Gb)
5148 rdp_cap |= RDP_PS_16GB;
5149 if (phba->lmt & LMT_10Gb)
5150 rdp_cap |= RDP_PS_10GB;
5151 if (phba->lmt & LMT_8Gb)
5152 rdp_cap |= RDP_PS_8GB;
5153 if (phba->lmt & LMT_4Gb)
5154 rdp_cap |= RDP_PS_4GB;
5155 if (phba->lmt & LMT_2Gb)
5156 rdp_cap |= RDP_PS_2GB;
5157 if (phba->lmt & LMT_1Gb)
5158 rdp_cap |= RDP_PS_1GB;
5161 rdp_cap = RDP_CAP_UNKNOWN;
5162 if (phba->cfg_link_speed != LPFC_USER_LINK_SPEED_AUTO)
5163 rdp_cap |= RDP_CAP_USER_CONFIGURED;
5165 desc->info.port_speed.capabilities = cpu_to_be16(rdp_cap);
5166 desc->length = cpu_to_be32(sizeof(desc->info));
5167 return sizeof(struct fc_rdp_port_speed_desc);
5171 lpfc_rdp_res_diag_port_names(struct fc_rdp_port_name_desc *desc,
5172 struct lpfc_vport *vport)
5175 desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG);
5177 memcpy(desc->port_names.wwnn, &vport->fc_nodename,
5178 sizeof(desc->port_names.wwnn));
5180 memcpy(desc->port_names.wwpn, &vport->fc_portname,
5181 sizeof(desc->port_names.wwpn));
5183 desc->length = cpu_to_be32(sizeof(desc->port_names));
5184 return sizeof(struct fc_rdp_port_name_desc);
5188 lpfc_rdp_res_attach_port_names(struct fc_rdp_port_name_desc *desc,
5189 struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
5192 desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG);
5193 if (vport->fc_flag & FC_FABRIC) {
5194 memcpy(desc->port_names.wwnn, &vport->fabric_nodename,
5195 sizeof(desc->port_names.wwnn));
5197 memcpy(desc->port_names.wwpn, &vport->fabric_portname,
5198 sizeof(desc->port_names.wwpn));
5199 } else { /* Point to Point */
5200 memcpy(desc->port_names.wwnn, &ndlp->nlp_nodename,
5201 sizeof(desc->port_names.wwnn));
5203 memcpy(desc->port_names.wwnn, &ndlp->nlp_portname,
5204 sizeof(desc->port_names.wwpn));
5207 desc->length = cpu_to_be32(sizeof(desc->port_names));
5208 return sizeof(struct fc_rdp_port_name_desc);
5212 lpfc_els_rdp_cmpl(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context,
5215 struct lpfc_nodelist *ndlp = rdp_context->ndlp;
5216 struct lpfc_vport *vport = ndlp->vport;
5217 struct lpfc_iocbq *elsiocb;
5218 struct ulp_bde64 *bpl;
5221 struct ls_rjt *stat;
5222 struct fc_rdp_res_frame *rdp_res;
5223 uint32_t cmdsize, len;
5227 if (status != SUCCESS)
5230 /* This will change once we know the true size of the RDP payload */
5231 cmdsize = sizeof(struct fc_rdp_res_frame);
5233 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize,
5234 lpfc_max_els_tries, rdp_context->ndlp,
5235 rdp_context->ndlp->nlp_DID, ELS_CMD_ACC);
5238 goto free_rdp_context;
5240 icmd = &elsiocb->iocb;
5241 icmd->ulpContext = rdp_context->rx_id;
5242 icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id;
5244 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5245 "2171 Xmit RDP response tag x%x xri x%x, "
5246 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x",
5247 elsiocb->iotag, elsiocb->iocb.ulpContext,
5248 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5250 rdp_res = (struct fc_rdp_res_frame *)
5251 (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5252 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5253 memset(pcmd, 0, sizeof(struct fc_rdp_res_frame));
5254 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5256 /* Update Alarm and Warning */
5257 flag_ptr = (uint16_t *)(rdp_context->page_a2 + SSF_ALARM_FLAGS);
5258 phba->sfp_alarm |= *flag_ptr;
5259 flag_ptr = (uint16_t *)(rdp_context->page_a2 + SSF_WARNING_FLAGS);
5260 phba->sfp_warning |= *flag_ptr;
5262 /* For RDP payload */
5264 len += lpfc_rdp_res_link_service((struct fc_rdp_link_service_desc *)
5265 (len + pcmd), ELS_CMD_RDP);
5267 len += lpfc_rdp_res_sfp_desc((struct fc_rdp_sfp_desc *)(len + pcmd),
5268 rdp_context->page_a0, rdp_context->page_a2);
5269 len += lpfc_rdp_res_speed((struct fc_rdp_port_speed_desc *)(len + pcmd),
5271 len += lpfc_rdp_res_link_error((struct fc_rdp_link_error_status_desc *)
5272 (len + pcmd), &rdp_context->link_stat);
5273 len += lpfc_rdp_res_diag_port_names((struct fc_rdp_port_name_desc *)
5274 (len + pcmd), vport);
5275 len += lpfc_rdp_res_attach_port_names((struct fc_rdp_port_name_desc *)
5276 (len + pcmd), vport, ndlp);
5277 len += lpfc_rdp_res_fec_desc((struct fc_fec_rdp_desc *)(len + pcmd),
5278 &rdp_context->link_stat);
5279 /* Check if nport is logged, BZ190632 */
5280 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED))
5281 goto lpfc_skip_descriptor;
5283 len += lpfc_rdp_res_bbc_desc((struct fc_rdp_bbc_desc *)(len + pcmd),
5284 &rdp_context->link_stat, vport);
5285 len += lpfc_rdp_res_oed_temp_desc(phba,
5286 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5287 rdp_context->page_a2);
5288 len += lpfc_rdp_res_oed_voltage_desc(phba,
5289 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5290 rdp_context->page_a2);
5291 len += lpfc_rdp_res_oed_txbias_desc(phba,
5292 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5293 rdp_context->page_a2);
5294 len += lpfc_rdp_res_oed_txpower_desc(phba,
5295 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5296 rdp_context->page_a2);
5297 len += lpfc_rdp_res_oed_rxpower_desc(phba,
5298 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5299 rdp_context->page_a2);
5300 len += lpfc_rdp_res_opd_desc((struct fc_rdp_opd_sfp_desc *)(len + pcmd),
5301 rdp_context->page_a0, vport);
5303 lpfc_skip_descriptor:
5304 rdp_res->length = cpu_to_be32(len - 8);
5305 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5307 /* Now that we know the true size of the payload, update the BPL */
5308 bpl = (struct ulp_bde64 *)
5309 (((struct lpfc_dmabuf *)(elsiocb->context3))->virt);
5310 bpl->tus.f.bdeSize = len;
5311 bpl->tus.f.bdeFlags = 0;
5312 bpl->tus.w = le32_to_cpu(bpl->tus.w);
5314 phba->fc_stat.elsXmitACC++;
5315 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5316 if (rc == IOCB_ERROR)
5317 lpfc_els_free_iocb(phba, elsiocb);
5323 cmdsize = 2 * sizeof(uint32_t);
5324 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, lpfc_max_els_tries,
5325 ndlp, ndlp->nlp_DID, ELS_CMD_LS_RJT);
5328 goto free_rdp_context;
5330 icmd = &elsiocb->iocb;
5331 icmd->ulpContext = rdp_context->rx_id;
5332 icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id;
5333 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5335 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
5336 stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t));
5337 stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5339 phba->fc_stat.elsXmitLSRJT++;
5340 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5341 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5343 if (rc == IOCB_ERROR)
5344 lpfc_els_free_iocb(phba, elsiocb);
5350 lpfc_get_rdp_info(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context)
5352 LPFC_MBOXQ_t *mbox = NULL;
5355 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5357 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_ELS,
5358 "7105 failed to allocate mailbox memory");
5362 if (lpfc_sli4_dump_page_a0(phba, mbox))
5363 goto prep_mbox_fail;
5364 mbox->vport = rdp_context->ndlp->vport;
5365 mbox->mbox_cmpl = lpfc_mbx_cmpl_rdp_page_a0;
5366 mbox->context2 = (struct lpfc_rdp_context *) rdp_context;
5367 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
5368 if (rc == MBX_NOT_FINISHED)
5369 goto issue_mbox_fail;
5375 mempool_free(mbox, phba->mbox_mem_pool);
5380 * lpfc_els_rcv_rdp - Process an unsolicited RDP ELS.
5381 * @vport: pointer to a host virtual N_Port data structure.
5382 * @cmdiocb: pointer to lpfc command iocb data structure.
5383 * @ndlp: pointer to a node-list data structure.
5385 * This routine processes an unsolicited RDP(Read Diagnostic Parameters)
5386 * IOCB. First, the payload of the unsolicited RDP is checked.
5387 * Then it will (1) send MBX_DUMP_MEMORY, Embedded DMP_LMSD sub command TYPE-3
5388 * for Page A0, (2) send MBX_DUMP_MEMORY, DMP_LMSD for Page A2,
5389 * (3) send MBX_READ_LNK_STAT to get link stat, (4) Call lpfc_els_rdp_cmpl
5390 * gather all data and send RDP response.
5393 * 0 - Sent the acc response
5394 * 1 - Sent the reject response.
5397 lpfc_els_rcv_rdp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5398 struct lpfc_nodelist *ndlp)
5400 struct lpfc_hba *phba = vport->phba;
5401 struct lpfc_dmabuf *pcmd;
5402 uint8_t rjt_err, rjt_expl = LSEXP_NOTHING_MORE;
5403 struct fc_rdp_req_frame *rdp_req;
5404 struct lpfc_rdp_context *rdp_context;
5408 if (phba->sli_rev < LPFC_SLI_REV4 ||
5409 bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
5410 LPFC_SLI_INTF_IF_TYPE_2) {
5411 rjt_err = LSRJT_UNABLE_TPC;
5412 rjt_expl = LSEXP_REQ_UNSUPPORTED;
5416 if (phba->sli_rev < LPFC_SLI_REV4 || (phba->hba_flag & HBA_FCOE_MODE)) {
5417 rjt_err = LSRJT_UNABLE_TPC;
5418 rjt_expl = LSEXP_REQ_UNSUPPORTED;
5422 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5423 rdp_req = (struct fc_rdp_req_frame *) pcmd->virt;
5426 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5427 "2422 ELS RDP Request "
5428 "dec len %d tag x%x port_id %d len %d\n",
5429 be32_to_cpu(rdp_req->rdp_des_length),
5430 be32_to_cpu(rdp_req->nport_id_desc.tag),
5431 be32_to_cpu(rdp_req->nport_id_desc.nport_id),
5432 be32_to_cpu(rdp_req->nport_id_desc.length));
5434 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED) &&
5435 !phba->cfg_enable_SmartSAN) {
5436 rjt_err = LSRJT_UNABLE_TPC;
5437 rjt_expl = LSEXP_PORT_LOGIN_REQ;
5440 if (sizeof(struct fc_rdp_nport_desc) !=
5441 be32_to_cpu(rdp_req->rdp_des_length))
5443 if (RDP_N_PORT_DESC_TAG != be32_to_cpu(rdp_req->nport_id_desc.tag))
5445 if (RDP_NPORT_ID_SIZE !=
5446 be32_to_cpu(rdp_req->nport_id_desc.length))
5448 rdp_context = kzalloc(sizeof(struct lpfc_rdp_context), GFP_KERNEL);
5450 rjt_err = LSRJT_UNABLE_TPC;
5454 cmd = &cmdiocb->iocb;
5455 rdp_context->ndlp = lpfc_nlp_get(ndlp);
5456 rdp_context->ox_id = cmd->unsli3.rcvsli3.ox_id;
5457 rdp_context->rx_id = cmd->ulpContext;
5458 rdp_context->cmpl = lpfc_els_rdp_cmpl;
5459 if (lpfc_get_rdp_info(phba, rdp_context)) {
5460 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_ELS,
5461 "2423 Unable to send mailbox");
5463 rjt_err = LSRJT_UNABLE_TPC;
5471 rjt_err = LSRJT_LOGICAL_ERR;
5474 memset(&stat, 0, sizeof(stat));
5475 stat.un.b.lsRjtRsnCode = rjt_err;
5476 stat.un.b.lsRjtRsnCodeExp = rjt_expl;
5477 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5483 lpfc_els_lcb_rsp(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
5488 struct lpfc_iocbq *elsiocb;
5489 struct lpfc_nodelist *ndlp;
5490 struct ls_rjt *stat;
5491 union lpfc_sli4_cfg_shdr *shdr;
5492 struct lpfc_lcb_context *lcb_context;
5493 struct fc_lcb_res_frame *lcb_res;
5494 uint32_t cmdsize, shdr_status, shdr_add_status;
5498 lcb_context = (struct lpfc_lcb_context *)pmb->context1;
5499 ndlp = lcb_context->ndlp;
5500 pmb->context1 = NULL;
5501 pmb->context2 = NULL;
5503 shdr = (union lpfc_sli4_cfg_shdr *)
5504 &pmb->u.mqe.un.beacon_config.header.cfg_shdr;
5505 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
5506 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
5508 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX,
5509 "0194 SET_BEACON_CONFIG mailbox "
5510 "completed with status x%x add_status x%x,"
5511 " mbx status x%x\n",
5512 shdr_status, shdr_add_status, mb->mbxStatus);
5514 if (mb->mbxStatus && !(shdr_status &&
5515 shdr_add_status == ADD_STATUS_OPERATION_ALREADY_ACTIVE)) {
5516 mempool_free(pmb, phba->mbox_mem_pool);
5520 mempool_free(pmb, phba->mbox_mem_pool);
5521 cmdsize = sizeof(struct fc_lcb_res_frame);
5522 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5523 lpfc_max_els_tries, ndlp,
5524 ndlp->nlp_DID, ELS_CMD_ACC);
5526 /* Decrement the ndlp reference count from previous mbox command */
5530 goto free_lcb_context;
5532 lcb_res = (struct fc_lcb_res_frame *)
5533 (((struct lpfc_dmabuf *)elsiocb->context2)->virt);
5535 icmd = &elsiocb->iocb;
5536 icmd->ulpContext = lcb_context->rx_id;
5537 icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id;
5539 pcmd = (uint8_t *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt);
5540 *((uint32_t *)(pcmd)) = ELS_CMD_ACC;
5541 lcb_res->lcb_sub_command = lcb_context->sub_command;
5542 lcb_res->lcb_type = lcb_context->type;
5543 lcb_res->lcb_frequency = lcb_context->frequency;
5544 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5545 phba->fc_stat.elsXmitACC++;
5546 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5547 if (rc == IOCB_ERROR)
5548 lpfc_els_free_iocb(phba, elsiocb);
5554 cmdsize = sizeof(struct fc_lcb_res_frame);
5555 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5556 lpfc_max_els_tries, ndlp,
5557 ndlp->nlp_DID, ELS_CMD_LS_RJT);
5560 goto free_lcb_context;
5562 icmd = &elsiocb->iocb;
5563 icmd->ulpContext = lcb_context->rx_id;
5564 icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id;
5565 pcmd = (uint8_t *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt);
5567 *((uint32_t *)(pcmd)) = ELS_CMD_LS_RJT;
5568 stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t));
5569 stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5571 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5572 phba->fc_stat.elsXmitLSRJT++;
5573 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5574 if (rc == IOCB_ERROR)
5575 lpfc_els_free_iocb(phba, elsiocb);
5581 lpfc_sli4_set_beacon(struct lpfc_vport *vport,
5582 struct lpfc_lcb_context *lcb_context,
5583 uint32_t beacon_state)
5585 struct lpfc_hba *phba = vport->phba;
5586 LPFC_MBOXQ_t *mbox = NULL;
5590 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5594 len = sizeof(struct lpfc_mbx_set_beacon_config) -
5595 sizeof(struct lpfc_sli4_cfg_mhdr);
5596 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
5597 LPFC_MBOX_OPCODE_SET_BEACON_CONFIG, len,
5598 LPFC_SLI4_MBX_EMBED);
5599 mbox->context1 = (void *)lcb_context;
5600 mbox->vport = phba->pport;
5601 mbox->mbox_cmpl = lpfc_els_lcb_rsp;
5602 bf_set(lpfc_mbx_set_beacon_port_num, &mbox->u.mqe.un.beacon_config,
5603 phba->sli4_hba.physical_port);
5604 bf_set(lpfc_mbx_set_beacon_state, &mbox->u.mqe.un.beacon_config,
5606 bf_set(lpfc_mbx_set_beacon_port_type, &mbox->u.mqe.un.beacon_config, 1);
5607 bf_set(lpfc_mbx_set_beacon_duration, &mbox->u.mqe.un.beacon_config, 0);
5608 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
5609 if (rc == MBX_NOT_FINISHED) {
5610 mempool_free(mbox, phba->mbox_mem_pool);
5619 * lpfc_els_rcv_lcb - Process an unsolicited LCB
5620 * @vport: pointer to a host virtual N_Port data structure.
5621 * @cmdiocb: pointer to lpfc command iocb data structure.
5622 * @ndlp: pointer to a node-list data structure.
5624 * This routine processes an unsolicited LCB(LINK CABLE BEACON) IOCB.
5625 * First, the payload of the unsolicited LCB is checked.
5626 * Then based on Subcommand beacon will either turn on or off.
5629 * 0 - Sent the acc response
5630 * 1 - Sent the reject response.
5633 lpfc_els_rcv_lcb(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5634 struct lpfc_nodelist *ndlp)
5636 struct lpfc_hba *phba = vport->phba;
5637 struct lpfc_dmabuf *pcmd;
5639 struct fc_lcb_request_frame *beacon;
5640 struct lpfc_lcb_context *lcb_context;
5641 uint8_t state, rjt_err;
5644 pcmd = (struct lpfc_dmabuf *)cmdiocb->context2;
5645 lp = (uint8_t *)pcmd->virt;
5646 beacon = (struct fc_lcb_request_frame *)pcmd->virt;
5648 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5649 "0192 ELS LCB Data x%x x%x x%x x%x sub x%x "
5650 "type x%x frequency %x duration x%x\n",
5651 lp[0], lp[1], lp[2],
5652 beacon->lcb_command,
5653 beacon->lcb_sub_command,
5655 beacon->lcb_frequency,
5656 be16_to_cpu(beacon->lcb_duration));
5658 if (phba->sli_rev < LPFC_SLI_REV4 ||
5659 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
5660 LPFC_SLI_INTF_IF_TYPE_2)) {
5661 rjt_err = LSRJT_CMD_UNSUPPORTED;
5665 if (phba->hba_flag & HBA_FCOE_MODE) {
5666 rjt_err = LSRJT_CMD_UNSUPPORTED;
5669 if (beacon->lcb_frequency == 0) {
5670 rjt_err = LSRJT_CMD_UNSUPPORTED;
5673 if ((beacon->lcb_type != LPFC_LCB_GREEN) &&
5674 (beacon->lcb_type != LPFC_LCB_AMBER)) {
5675 rjt_err = LSRJT_CMD_UNSUPPORTED;
5678 if ((beacon->lcb_sub_command != LPFC_LCB_ON) &&
5679 (beacon->lcb_sub_command != LPFC_LCB_OFF)) {
5680 rjt_err = LSRJT_CMD_UNSUPPORTED;
5683 if ((beacon->lcb_sub_command == LPFC_LCB_ON) &&
5684 (beacon->lcb_type != LPFC_LCB_GREEN) &&
5685 (beacon->lcb_type != LPFC_LCB_AMBER)) {
5686 rjt_err = LSRJT_CMD_UNSUPPORTED;
5689 if (be16_to_cpu(beacon->lcb_duration) != 0) {
5690 rjt_err = LSRJT_CMD_UNSUPPORTED;
5694 lcb_context = kmalloc(sizeof(*lcb_context), GFP_KERNEL);
5696 rjt_err = LSRJT_UNABLE_TPC;
5700 state = (beacon->lcb_sub_command == LPFC_LCB_ON) ? 1 : 0;
5701 lcb_context->sub_command = beacon->lcb_sub_command;
5702 lcb_context->type = beacon->lcb_type;
5703 lcb_context->frequency = beacon->lcb_frequency;
5704 lcb_context->ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id;
5705 lcb_context->rx_id = cmdiocb->iocb.ulpContext;
5706 lcb_context->ndlp = lpfc_nlp_get(ndlp);
5707 if (lpfc_sli4_set_beacon(vport, lcb_context, state)) {
5708 lpfc_printf_vlog(ndlp->vport, KERN_ERR,
5709 LOG_ELS, "0193 failed to send mail box");
5712 rjt_err = LSRJT_UNABLE_TPC;
5717 memset(&stat, 0, sizeof(stat));
5718 stat.un.b.lsRjtRsnCode = rjt_err;
5719 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5725 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
5726 * @vport: pointer to a host virtual N_Port data structure.
5728 * This routine cleans up any Registration State Change Notification
5729 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
5730 * @vport together with the host_lock is used to prevent multiple thread
5731 * trying to access the RSCN array on a same @vport at the same time.
5734 lpfc_els_flush_rscn(struct lpfc_vport *vport)
5736 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5737 struct lpfc_hba *phba = vport->phba;
5740 spin_lock_irq(shost->host_lock);
5741 if (vport->fc_rscn_flush) {
5742 /* Another thread is walking fc_rscn_id_list on this vport */
5743 spin_unlock_irq(shost->host_lock);
5746 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
5747 vport->fc_rscn_flush = 1;
5748 spin_unlock_irq(shost->host_lock);
5750 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
5751 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
5752 vport->fc_rscn_id_list[i] = NULL;
5754 spin_lock_irq(shost->host_lock);
5755 vport->fc_rscn_id_cnt = 0;
5756 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
5757 spin_unlock_irq(shost->host_lock);
5758 lpfc_can_disctmo(vport);
5759 /* Indicate we are done walking this fc_rscn_id_list */
5760 vport->fc_rscn_flush = 0;
5764 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
5765 * @vport: pointer to a host virtual N_Port data structure.
5766 * @did: remote destination port identifier.
5768 * This routine checks whether there is any pending Registration State
5769 * Configuration Notification (RSCN) to a @did on @vport.
5772 * None zero - The @did matched with a pending rscn
5773 * 0 - not able to match @did with a pending rscn
5776 lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
5781 uint32_t payload_len, i;
5782 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5784 ns_did.un.word = did;
5786 /* Never match fabric nodes for RSCNs */
5787 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
5790 /* If we are doing a FULL RSCN rediscovery, match everything */
5791 if (vport->fc_flag & FC_RSCN_DISCOVERY)
5794 spin_lock_irq(shost->host_lock);
5795 if (vport->fc_rscn_flush) {
5796 /* Another thread is walking fc_rscn_id_list on this vport */
5797 spin_unlock_irq(shost->host_lock);
5800 /* Indicate we are walking fc_rscn_id_list on this vport */
5801 vport->fc_rscn_flush = 1;
5802 spin_unlock_irq(shost->host_lock);
5803 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
5804 lp = vport->fc_rscn_id_list[i]->virt;
5805 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
5806 payload_len -= sizeof(uint32_t); /* take off word 0 */
5807 while (payload_len) {
5808 rscn_did.un.word = be32_to_cpu(*lp++);
5809 payload_len -= sizeof(uint32_t);
5810 switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) {
5811 case RSCN_ADDRESS_FORMAT_PORT:
5812 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
5813 && (ns_did.un.b.area == rscn_did.un.b.area)
5814 && (ns_did.un.b.id == rscn_did.un.b.id))
5815 goto return_did_out;
5817 case RSCN_ADDRESS_FORMAT_AREA:
5818 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
5819 && (ns_did.un.b.area == rscn_did.un.b.area))
5820 goto return_did_out;
5822 case RSCN_ADDRESS_FORMAT_DOMAIN:
5823 if (ns_did.un.b.domain == rscn_did.un.b.domain)
5824 goto return_did_out;
5826 case RSCN_ADDRESS_FORMAT_FABRIC:
5827 goto return_did_out;
5831 /* Indicate we are done with walking fc_rscn_id_list on this vport */
5832 vport->fc_rscn_flush = 0;
5835 /* Indicate we are done with walking fc_rscn_id_list on this vport */
5836 vport->fc_rscn_flush = 0;
5841 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
5842 * @vport: pointer to a host virtual N_Port data structure.
5844 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
5845 * state machine for a @vport's nodes that are with pending RSCN (Registration
5846 * State Change Notification).
5849 * 0 - Successful (currently alway return 0)
5852 lpfc_rscn_recovery_check(struct lpfc_vport *vport)
5854 struct lpfc_nodelist *ndlp = NULL;
5856 /* Move all affected nodes by pending RSCNs to NPR state. */
5857 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
5858 if (!NLP_CHK_NODE_ACT(ndlp) ||
5859 (ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
5860 !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
5862 if (vport->phba->nvmet_support)
5864 lpfc_disc_state_machine(vport, ndlp, NULL,
5865 NLP_EVT_DEVICE_RECOVERY);
5866 lpfc_cancel_retry_delay_tmo(vport, ndlp);
5872 * lpfc_send_rscn_event - Send an RSCN event to management application
5873 * @vport: pointer to a host virtual N_Port data structure.
5874 * @cmdiocb: pointer to lpfc command iocb data structure.
5876 * lpfc_send_rscn_event sends an RSCN netlink event to management
5880 lpfc_send_rscn_event(struct lpfc_vport *vport,
5881 struct lpfc_iocbq *cmdiocb)
5883 struct lpfc_dmabuf *pcmd;
5884 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5885 uint32_t *payload_ptr;
5886 uint32_t payload_len;
5887 struct lpfc_rscn_event_header *rscn_event_data;
5889 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5890 payload_ptr = (uint32_t *) pcmd->virt;
5891 payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK);
5893 rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) +
5894 payload_len, GFP_KERNEL);
5895 if (!rscn_event_data) {
5896 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5897 "0147 Failed to allocate memory for RSCN event\n");
5900 rscn_event_data->event_type = FC_REG_RSCN_EVENT;
5901 rscn_event_data->payload_length = payload_len;
5902 memcpy(rscn_event_data->rscn_payload, payload_ptr,
5905 fc_host_post_vendor_event(shost,
5906 fc_get_event_number(),
5907 sizeof(struct lpfc_rscn_event_header) + payload_len,
5908 (char *)rscn_event_data,
5911 kfree(rscn_event_data);
5915 * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
5916 * @vport: pointer to a host virtual N_Port data structure.
5917 * @cmdiocb: pointer to lpfc command iocb data structure.
5918 * @ndlp: pointer to a node-list data structure.
5920 * This routine processes an unsolicited RSCN (Registration State Change
5921 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
5922 * to invoke fc_host_post_event() routine to the FC transport layer. If the
5923 * discover state machine is about to begin discovery, it just accepts the
5924 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
5925 * contains N_Port IDs for other vports on this HBA, it just accepts the
5926 * RSCN and ignore processing it. If the state machine is in the recovery
5927 * state, the fc_rscn_id_list of this @vport is walked and the
5928 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
5929 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
5930 * routine is invoked to handle the RSCN event.
5933 * 0 - Just sent the acc response
5934 * 1 - Sent the acc response and waited for name server completion
5937 lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5938 struct lpfc_nodelist *ndlp)
5940 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5941 struct lpfc_hba *phba = vport->phba;
5942 struct lpfc_dmabuf *pcmd;
5943 uint32_t *lp, *datap;
5944 uint32_t payload_len, length, nportid, *cmd;
5946 int rscn_id = 0, hba_id = 0;
5949 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5950 lp = (uint32_t *) pcmd->virt;
5952 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
5953 payload_len -= sizeof(uint32_t); /* take off word 0 */
5955 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5956 "0214 RSCN received Data: x%x x%x x%x x%x\n",
5957 vport->fc_flag, payload_len, *lp,
5958 vport->fc_rscn_id_cnt);
5960 /* Send an RSCN event to the management application */
5961 lpfc_send_rscn_event(vport, cmdiocb);
5963 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
5964 fc_host_post_event(shost, fc_get_event_number(),
5965 FCH_EVT_RSCN, lp[i]);
5967 /* If we are about to begin discovery, just ACC the RSCN.
5968 * Discovery processing will satisfy it.
5970 if (vport->port_state <= LPFC_NS_QRY) {
5971 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5972 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
5973 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
5975 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
5979 /* If this RSCN just contains NPortIDs for other vports on this HBA,
5980 * just ACC and ignore it.
5982 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
5983 !(vport->cfg_peer_port_login)) {
5988 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
5989 i -= sizeof(uint32_t);
5991 if (lpfc_find_vport_by_did(phba, nportid))
5994 if (rscn_id == hba_id) {
5995 /* ALL NPortIDs in RSCN are on HBA */
5996 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5998 "Data: x%x x%x x%x x%x\n",
5999 vport->fc_flag, payload_len,
6000 *lp, vport->fc_rscn_id_cnt);
6001 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6002 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
6003 ndlp->nlp_DID, vport->port_state,
6006 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
6012 spin_lock_irq(shost->host_lock);
6013 if (vport->fc_rscn_flush) {
6014 /* Another thread is walking fc_rscn_id_list on this vport */
6015 vport->fc_flag |= FC_RSCN_DISCOVERY;
6016 spin_unlock_irq(shost->host_lock);
6018 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
6021 /* Indicate we are walking fc_rscn_id_list on this vport */
6022 vport->fc_rscn_flush = 1;
6023 spin_unlock_irq(shost->host_lock);
6024 /* Get the array count after successfully have the token */
6025 rscn_cnt = vport->fc_rscn_id_cnt;
6026 /* If we are already processing an RSCN, save the received
6027 * RSCN payload buffer, cmdiocb->context2 to process later.
6029 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
6030 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6031 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
6032 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
6034 spin_lock_irq(shost->host_lock);
6035 vport->fc_flag |= FC_RSCN_DEFERRED;
6036 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
6037 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
6038 vport->fc_flag |= FC_RSCN_MODE;
6039 spin_unlock_irq(shost->host_lock);
6041 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
6042 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
6045 (payload_len + length <= LPFC_BPL_SIZE)) {
6046 *cmd &= ELS_CMD_MASK;
6047 *cmd |= cpu_to_be32(payload_len + length);
6048 memcpy(((uint8_t *)cmd) + length, lp,
6051 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
6052 vport->fc_rscn_id_cnt++;
6053 /* If we zero, cmdiocb->context2, the calling
6054 * routine will not try to free it.
6056 cmdiocb->context2 = NULL;
6059 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6060 "0235 Deferred RSCN "
6061 "Data: x%x x%x x%x\n",
6062 vport->fc_rscn_id_cnt, vport->fc_flag,
6065 vport->fc_flag |= FC_RSCN_DISCOVERY;
6066 spin_unlock_irq(shost->host_lock);
6067 /* ReDiscovery RSCN */
6068 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6069 "0234 ReDiscovery RSCN "
6070 "Data: x%x x%x x%x\n",
6071 vport->fc_rscn_id_cnt, vport->fc_flag,
6074 /* Indicate we are done walking fc_rscn_id_list on this vport */
6075 vport->fc_rscn_flush = 0;
6077 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
6078 /* send RECOVERY event for ALL nodes that match RSCN payload */
6079 lpfc_rscn_recovery_check(vport);
6080 spin_lock_irq(shost->host_lock);
6081 vport->fc_flag &= ~FC_RSCN_DEFERRED;
6082 spin_unlock_irq(shost->host_lock);
6085 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6086 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
6087 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
6089 spin_lock_irq(shost->host_lock);
6090 vport->fc_flag |= FC_RSCN_MODE;
6091 spin_unlock_irq(shost->host_lock);
6092 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
6093 /* Indicate we are done walking fc_rscn_id_list on this vport */
6094 vport->fc_rscn_flush = 0;
6096 * If we zero, cmdiocb->context2, the calling routine will
6097 * not try to free it.
6099 cmdiocb->context2 = NULL;
6100 lpfc_set_disctmo(vport);
6102 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
6103 /* send RECOVERY event for ALL nodes that match RSCN payload */
6104 lpfc_rscn_recovery_check(vport);
6105 return lpfc_els_handle_rscn(vport);
6109 * lpfc_els_handle_rscn - Handle rscn for a vport
6110 * @vport: pointer to a host virtual N_Port data structure.
6112 * This routine handles the Registration State Configuration Notification
6113 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
6114 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
6115 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
6116 * NameServer shall be issued. If CT command to the NameServer fails to be
6117 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
6118 * RSCN activities with the @vport.
6121 * 0 - Cleaned up rscn on the @vport
6122 * 1 - Wait for plogi to name server before proceed
6125 lpfc_els_handle_rscn(struct lpfc_vport *vport)
6127 struct lpfc_nodelist *ndlp;
6129 /* Ignore RSCN if the port is being torn down. */
6130 if (vport->load_flag & FC_UNLOADING) {
6131 lpfc_els_flush_rscn(vport);
6135 /* Start timer for RSCN processing */
6136 lpfc_set_disctmo(vport);
6138 /* RSCN processed */
6139 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6140 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
6141 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
6144 /* To process RSCN, first compare RSCN data with NameServer */
6145 vport->fc_ns_retry = 0;
6146 vport->num_disc_nodes = 0;
6148 ndlp = lpfc_findnode_did(vport, NameServer_DID);
6149 if (ndlp && NLP_CHK_NODE_ACT(ndlp)
6150 && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
6151 /* Good ndlp, issue CT Request to NameServer */
6152 vport->gidft_inp = 0;
6153 if (lpfc_issue_gidft(vport) == 0)
6154 /* Wait for NameServer query cmpl before we can
6159 /* If login to NameServer does not exist, issue one */
6160 /* Good status, issue PLOGI to NameServer */
6161 ndlp = lpfc_findnode_did(vport, NameServer_DID);
6162 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
6163 /* Wait for NameServer login cmpl before we can
6168 ndlp = lpfc_enable_node(vport, ndlp,
6169 NLP_STE_PLOGI_ISSUE);
6171 lpfc_els_flush_rscn(vport);
6174 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
6176 ndlp = lpfc_nlp_init(vport, NameServer_DID);
6178 lpfc_els_flush_rscn(vport);
6181 ndlp->nlp_prev_state = ndlp->nlp_state;
6182 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
6184 ndlp->nlp_type |= NLP_FABRIC;
6185 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
6186 /* Wait for NameServer login cmpl before we can
6192 lpfc_els_flush_rscn(vport);
6197 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
6198 * @vport: pointer to a host virtual N_Port data structure.
6199 * @cmdiocb: pointer to lpfc command iocb data structure.
6200 * @ndlp: pointer to a node-list data structure.
6202 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
6203 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
6204 * point topology. As an unsolicited FLOGI should not be received in a loop
6205 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
6206 * lpfc_check_sparm() routine is invoked to check the parameters in the
6207 * unsolicited FLOGI. If parameters validation failed, the routine
6208 * lpfc_els_rsp_reject() shall be called with reject reason code set to
6209 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
6210 * FLOGI shall be compared with the Port WWN of the @vport to determine who
6211 * will initiate PLOGI. The higher lexicographical value party shall has
6212 * higher priority (as the winning port) and will initiate PLOGI and
6213 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
6214 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
6215 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
6218 * 0 - Successfully processed the unsolicited flogi
6219 * 1 - Failed to process the unsolicited flogi
6222 lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6223 struct lpfc_nodelist *ndlp)
6225 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6226 struct lpfc_hba *phba = vport->phba;
6227 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6228 uint32_t *lp = (uint32_t *) pcmd->virt;
6229 IOCB_t *icmd = &cmdiocb->iocb;
6230 struct serv_parm *sp;
6234 uint32_t fc_flag = 0;
6235 uint32_t port_state = 0;
6238 sp = (struct serv_parm *) lp;
6240 /* FLOGI received */
6242 lpfc_set_disctmo(vport);
6244 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
6245 /* We should never receive a FLOGI in loop mode, ignore it */
6246 did = icmd->un.elsreq64.remoteID;
6248 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
6250 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6251 "0113 An FLOGI ELS command x%x was "
6252 "received from DID x%x in Loop Mode\n",
6257 (void) lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1);
6260 * If our portname is greater than the remote portname,
6261 * then we initiate Nport login.
6264 rc = memcmp(&vport->fc_portname, &sp->portName,
6265 sizeof(struct lpfc_name));
6268 if (phba->sli_rev < LPFC_SLI_REV4) {
6269 mbox = mempool_alloc(phba->mbox_mem_pool,
6273 lpfc_linkdown(phba);
6274 lpfc_init_link(phba, mbox,
6276 phba->cfg_link_speed);
6277 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
6278 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
6279 mbox->vport = vport;
6280 rc = lpfc_sli_issue_mbox(phba, mbox,
6282 lpfc_set_loopback_flag(phba);
6283 if (rc == MBX_NOT_FINISHED)
6284 mempool_free(mbox, phba->mbox_mem_pool);
6288 /* abort the flogi coming back to ourselves
6289 * due to external loopback on the port.
6291 lpfc_els_abort_flogi(phba);
6294 } else if (rc > 0) { /* greater than */
6295 spin_lock_irq(shost->host_lock);
6296 vport->fc_flag |= FC_PT2PT_PLOGI;
6297 spin_unlock_irq(shost->host_lock);
6299 /* If we have the high WWPN we can assign our own
6300 * myDID; otherwise, we have to WAIT for a PLOGI
6301 * from the remote NPort to find out what it
6304 vport->fc_myDID = PT2PT_LocalID;
6306 vport->fc_myDID = PT2PT_RemoteID;
6310 * The vport state should go to LPFC_FLOGI only
6311 * AFTER we issue a FLOGI, not receive one.
6313 spin_lock_irq(shost->host_lock);
6314 fc_flag = vport->fc_flag;
6315 port_state = vport->port_state;
6316 vport->fc_flag |= FC_PT2PT;
6317 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
6318 spin_unlock_irq(shost->host_lock);
6319 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6320 "3311 Rcv Flogi PS x%x new PS x%x "
6321 "fc_flag x%x new fc_flag x%x\n",
6322 port_state, vport->port_state,
6323 fc_flag, vport->fc_flag);
6326 * We temporarily set fc_myDID to make it look like we are
6327 * a Fabric. This is done just so we end up with the right
6328 * did / sid on the FLOGI ACC rsp.
6330 did = vport->fc_myDID;
6331 vport->fc_myDID = Fabric_DID;
6333 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
6336 lpfc_els_rsp_acc(vport, ELS_CMD_FLOGI, cmdiocb, ndlp, NULL);
6338 /* Now lets put fc_myDID back to what its supposed to be */
6339 vport->fc_myDID = did;
6345 * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
6346 * @vport: pointer to a host virtual N_Port data structure.
6347 * @cmdiocb: pointer to lpfc command iocb data structure.
6348 * @ndlp: pointer to a node-list data structure.
6350 * This routine processes Request Node Identification Data (RNID) IOCB
6351 * received as an ELS unsolicited event. Only when the RNID specified format
6352 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
6353 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
6354 * Accept (ACC) the RNID ELS command. All the other RNID formats are
6355 * rejected by invoking the lpfc_els_rsp_reject() routine.
6358 * 0 - Successfully processed rnid iocb (currently always return 0)
6361 lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6362 struct lpfc_nodelist *ndlp)
6364 struct lpfc_dmabuf *pcmd;
6370 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6371 lp = (uint32_t *) pcmd->virt;
6378 switch (rn->Format) {
6380 case RNID_TOPOLOGY_DISC:
6382 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
6385 /* Reject this request because format not supported */
6386 stat.un.b.lsRjtRsvd0 = 0;
6387 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6388 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
6389 stat.un.b.vendorUnique = 0;
6390 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
6397 * lpfc_els_rcv_echo - Process an unsolicited echo iocb
6398 * @vport: pointer to a host virtual N_Port data structure.
6399 * @cmdiocb: pointer to lpfc command iocb data structure.
6400 * @ndlp: pointer to a node-list data structure.
6403 * 0 - Successfully processed echo iocb (currently always return 0)
6406 lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6407 struct lpfc_nodelist *ndlp)
6411 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
6413 /* skip over first word of echo command to find echo data */
6414 pcmd += sizeof(uint32_t);
6416 lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp);
6421 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
6422 * @vport: pointer to a host virtual N_Port data structure.
6423 * @cmdiocb: pointer to lpfc command iocb data structure.
6424 * @ndlp: pointer to a node-list data structure.
6426 * This routine processes a Link Incident Report Registration(LIRR) IOCB
6427 * received as an ELS unsolicited event. Currently, this function just invokes
6428 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
6431 * 0 - Successfully processed lirr iocb (currently always return 0)
6434 lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6435 struct lpfc_nodelist *ndlp)
6439 /* For now, unconditionally reject this command */
6440 stat.un.b.lsRjtRsvd0 = 0;
6441 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6442 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
6443 stat.un.b.vendorUnique = 0;
6444 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
6449 * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb
6450 * @vport: pointer to a host virtual N_Port data structure.
6451 * @cmdiocb: pointer to lpfc command iocb data structure.
6452 * @ndlp: pointer to a node-list data structure.
6454 * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB
6455 * received as an ELS unsolicited event. A request to RRQ shall only
6456 * be accepted if the Originator Nx_Port N_Port_ID or the Responder
6457 * Nx_Port N_Port_ID of the target Exchange is the same as the
6458 * N_Port_ID of the Nx_Port that makes the request. If the RRQ is
6459 * not accepted, an LS_RJT with reason code "Unable to perform
6460 * command request" and reason code explanation "Invalid Originator
6461 * S_ID" shall be returned. For now, we just unconditionally accept
6462 * RRQ from the target.
6465 lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6466 struct lpfc_nodelist *ndlp)
6468 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
6469 if (vport->phba->sli_rev == LPFC_SLI_REV4)
6470 lpfc_els_clear_rrq(vport, cmdiocb, ndlp);
6474 * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
6475 * @phba: pointer to lpfc hba data structure.
6476 * @pmb: pointer to the driver internal queue element for mailbox command.
6478 * This routine is the completion callback function for the MBX_READ_LNK_STAT
6479 * mailbox command. This callback function is to actually send the Accept
6480 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
6481 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
6482 * mailbox command, constructs the RPS response with the link statistics
6483 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
6484 * response to the RPS.
6486 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6487 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6488 * will be stored into the context1 field of the IOCB for the completion
6489 * callback function to the RPS Accept Response ELS IOCB command.
6493 lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
6497 struct RLS_RSP *rls_rsp;
6499 struct lpfc_iocbq *elsiocb;
6500 struct lpfc_nodelist *ndlp;
6507 ndlp = (struct lpfc_nodelist *) pmb->context2;
6508 rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff);
6509 oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff);
6510 pmb->context1 = NULL;
6511 pmb->context2 = NULL;
6513 if (mb->mbxStatus) {
6514 mempool_free(pmb, phba->mbox_mem_pool);
6518 cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t);
6519 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
6520 lpfc_max_els_tries, ndlp,
6521 ndlp->nlp_DID, ELS_CMD_ACC);
6523 /* Decrement the ndlp reference count from previous mbox command */
6527 mempool_free(pmb, phba->mbox_mem_pool);
6531 icmd = &elsiocb->iocb;
6532 icmd->ulpContext = rxid;
6533 icmd->unsli3.rcvsli3.ox_id = oxid;
6535 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6536 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
6537 pcmd += sizeof(uint32_t); /* Skip past command */
6538 rls_rsp = (struct RLS_RSP *)pcmd;
6540 rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
6541 rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
6542 rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
6543 rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
6544 rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
6545 rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
6546 mempool_free(pmb, phba->mbox_mem_pool);
6547 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
6548 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
6549 "2874 Xmit ELS RLS ACC response tag x%x xri x%x, "
6550 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
6551 elsiocb->iotag, elsiocb->iocb.ulpContext,
6552 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
6554 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
6555 phba->fc_stat.elsXmitACC++;
6556 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
6557 lpfc_els_free_iocb(phba, elsiocb);
6561 * lpfc_els_rsp_rps_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
6562 * @phba: pointer to lpfc hba data structure.
6563 * @pmb: pointer to the driver internal queue element for mailbox command.
6565 * This routine is the completion callback function for the MBX_READ_LNK_STAT
6566 * mailbox command. This callback function is to actually send the Accept
6567 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
6568 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
6569 * mailbox command, constructs the RPS response with the link statistics
6570 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
6571 * response to the RPS.
6573 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6574 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6575 * will be stored into the context1 field of the IOCB for the completion
6576 * callback function to the RPS Accept Response ELS IOCB command.
6580 lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
6586 struct lpfc_iocbq *elsiocb;
6587 struct lpfc_nodelist *ndlp;
6595 ndlp = (struct lpfc_nodelist *) pmb->context2;
6596 rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff);
6597 oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff);
6598 pmb->context1 = NULL;
6599 pmb->context2 = NULL;
6601 if (mb->mbxStatus) {
6602 mempool_free(pmb, phba->mbox_mem_pool);
6606 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
6607 mempool_free(pmb, phba->mbox_mem_pool);
6608 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
6609 lpfc_max_els_tries, ndlp,
6610 ndlp->nlp_DID, ELS_CMD_ACC);
6612 /* Decrement the ndlp reference count from previous mbox command */
6618 icmd = &elsiocb->iocb;
6619 icmd->ulpContext = rxid;
6620 icmd->unsli3.rcvsli3.ox_id = oxid;
6622 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6623 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
6624 pcmd += sizeof(uint32_t); /* Skip past command */
6625 rps_rsp = (RPS_RSP *)pcmd;
6627 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP)
6631 if (phba->pport->fc_flag & FC_FABRIC)
6635 rps_rsp->portStatus = cpu_to_be16(status);
6636 rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
6637 rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
6638 rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
6639 rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
6640 rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
6641 rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
6642 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
6643 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
6644 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
6645 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
6646 elsiocb->iotag, elsiocb->iocb.ulpContext,
6647 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
6649 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
6650 phba->fc_stat.elsXmitACC++;
6651 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
6652 lpfc_els_free_iocb(phba, elsiocb);
6657 * lpfc_els_rcv_rls - Process an unsolicited rls iocb
6658 * @vport: pointer to a host virtual N_Port data structure.
6659 * @cmdiocb: pointer to lpfc command iocb data structure.
6660 * @ndlp: pointer to a node-list data structure.
6662 * This routine processes Read Port Status (RPL) IOCB received as an
6663 * ELS unsolicited event. It first checks the remote port state. If the
6664 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
6665 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
6666 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
6667 * for reading the HBA link statistics. It is for the callback function,
6668 * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command
6669 * to actually sending out RPL Accept (ACC) response.
6672 * 0 - Successfully processed rls iocb (currently always return 0)
6675 lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6676 struct lpfc_nodelist *ndlp)
6678 struct lpfc_hba *phba = vport->phba;
6682 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
6683 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
6684 /* reject the unsolicited RPS request and done with it */
6687 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
6689 lpfc_read_lnk_stat(phba, mbox);
6690 mbox->context1 = (void *)((unsigned long)
6691 ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) |
6692 cmdiocb->iocb.ulpContext)); /* rx_id */
6693 mbox->context2 = lpfc_nlp_get(ndlp);
6694 mbox->vport = vport;
6695 mbox->mbox_cmpl = lpfc_els_rsp_rls_acc;
6696 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
6697 != MBX_NOT_FINISHED)
6698 /* Mbox completion will send ELS Response */
6700 /* Decrement reference count used for the failed mbox
6704 mempool_free(mbox, phba->mbox_mem_pool);
6707 /* issue rejection response */
6708 stat.un.b.lsRjtRsvd0 = 0;
6709 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6710 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
6711 stat.un.b.vendorUnique = 0;
6712 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
6717 * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb
6718 * @vport: pointer to a host virtual N_Port data structure.
6719 * @cmdiocb: pointer to lpfc command iocb data structure.
6720 * @ndlp: pointer to a node-list data structure.
6722 * This routine processes Read Timout Value (RTV) IOCB received as an
6723 * ELS unsolicited event. It first checks the remote port state. If the
6724 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
6725 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
6726 * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout
6727 * Value (RTV) unsolicited IOCB event.
6729 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6730 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6731 * will be stored into the context1 field of the IOCB for the completion
6732 * callback function to the RPS Accept Response ELS IOCB command.
6735 * 0 - Successfully processed rtv iocb (currently always return 0)
6738 lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6739 struct lpfc_nodelist *ndlp)
6741 struct lpfc_hba *phba = vport->phba;
6743 struct RTV_RSP *rtv_rsp;
6745 struct lpfc_iocbq *elsiocb;
6749 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
6750 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
6751 /* reject the unsolicited RPS request and done with it */
6754 cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t);
6755 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
6756 lpfc_max_els_tries, ndlp,
6757 ndlp->nlp_DID, ELS_CMD_ACC);
6762 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6763 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
6764 pcmd += sizeof(uint32_t); /* Skip past command */
6766 /* use the command's xri in the response */
6767 elsiocb->iocb.ulpContext = cmdiocb->iocb.ulpContext; /* Xri / rx_id */
6768 elsiocb->iocb.unsli3.rcvsli3.ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id;
6770 rtv_rsp = (struct RTV_RSP *)pcmd;
6772 /* populate RTV payload */
6773 rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000); /* report msecs */
6774 rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov);
6775 bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0);
6776 bf_set(qtov_rttov, rtv_rsp, 0); /* Field is for FC ONLY */
6777 rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov);
6779 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
6780 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
6781 "2875 Xmit ELS RTV ACC response tag x%x xri x%x, "
6782 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, "
6783 "Data: x%x x%x x%x\n",
6784 elsiocb->iotag, elsiocb->iocb.ulpContext,
6785 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
6787 rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov);
6788 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
6789 phba->fc_stat.elsXmitACC++;
6790 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
6791 lpfc_els_free_iocb(phba, elsiocb);
6795 /* issue rejection response */
6796 stat.un.b.lsRjtRsvd0 = 0;
6797 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6798 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
6799 stat.un.b.vendorUnique = 0;
6800 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
6804 /* lpfc_els_rcv_rps - Process an unsolicited rps iocb
6805 * @vport: pointer to a host virtual N_Port data structure.
6806 * @cmdiocb: pointer to lpfc command iocb data structure.
6807 * @ndlp: pointer to a node-list data structure.
6809 * This routine processes Read Port Status (RPS) IOCB received as an
6810 * ELS unsolicited event. It first checks the remote port state. If the
6811 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
6812 * state, it invokes the lpfc_els_rsp_reject() routine to send the reject
6813 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
6814 * for reading the HBA link statistics. It is for the callback function,
6815 * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command
6816 * to actually sending out RPS Accept (ACC) response.
6819 * 0 - Successfully processed rps iocb (currently always return 0)
6822 lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6823 struct lpfc_nodelist *ndlp)
6825 struct lpfc_hba *phba = vport->phba;
6829 struct lpfc_dmabuf *pcmd;
6833 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
6834 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
6835 /* reject the unsolicited RPS request and done with it */
6838 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6839 lp = (uint32_t *) pcmd->virt;
6840 flag = (be32_to_cpu(*lp++) & 0xf);
6844 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
6845 ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
6846 sizeof(struct lpfc_name)) == 0))) {
6848 printk("Fix me....\n");
6850 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
6852 lpfc_read_lnk_stat(phba, mbox);
6853 mbox->context1 = (void *)((unsigned long)
6854 ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) |
6855 cmdiocb->iocb.ulpContext)); /* rx_id */
6856 mbox->context2 = lpfc_nlp_get(ndlp);
6857 mbox->vport = vport;
6858 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
6859 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
6860 != MBX_NOT_FINISHED)
6861 /* Mbox completion will send ELS Response */
6863 /* Decrement reference count used for the failed mbox
6867 mempool_free(mbox, phba->mbox_mem_pool);
6872 /* issue rejection response */
6873 stat.un.b.lsRjtRsvd0 = 0;
6874 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6875 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
6876 stat.un.b.vendorUnique = 0;
6877 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
6881 /* lpfc_issue_els_rrq - Process an unsolicited rps iocb
6882 * @vport: pointer to a host virtual N_Port data structure.
6883 * @ndlp: pointer to a node-list data structure.
6884 * @did: DID of the target.
6885 * @rrq: Pointer to the rrq struct.
6887 * Build a ELS RRQ command and send it to the target. If the issue_iocb is
6888 * Successful the the completion handler will clear the RRQ.
6891 * 0 - Successfully sent rrq els iocb.
6892 * 1 - Failed to send rrq els iocb.
6895 lpfc_issue_els_rrq(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
6896 uint32_t did, struct lpfc_node_rrq *rrq)
6898 struct lpfc_hba *phba = vport->phba;
6899 struct RRQ *els_rrq;
6900 struct lpfc_iocbq *elsiocb;
6906 if (ndlp != rrq->ndlp)
6908 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
6911 /* If ndlp is not NULL, we will bump the reference count on it */
6912 cmdsize = (sizeof(uint32_t) + sizeof(struct RRQ));
6913 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, did,
6918 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6920 /* For RRQ request, remainder of payload is Exchange IDs */
6921 *((uint32_t *) (pcmd)) = ELS_CMD_RRQ;
6922 pcmd += sizeof(uint32_t);
6923 els_rrq = (struct RRQ *) pcmd;
6925 bf_set(rrq_oxid, els_rrq, phba->sli4_hba.xri_ids[rrq->xritag]);
6926 bf_set(rrq_rxid, els_rrq, rrq->rxid);
6927 bf_set(rrq_did, els_rrq, vport->fc_myDID);
6928 els_rrq->rrq = cpu_to_be32(els_rrq->rrq);
6929 els_rrq->rrq_exchg = cpu_to_be32(els_rrq->rrq_exchg);
6932 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6933 "Issue RRQ: did:x%x",
6934 did, rrq->xritag, rrq->rxid);
6935 elsiocb->context_un.rrq = rrq;
6936 elsiocb->iocb_cmpl = lpfc_cmpl_els_rrq;
6937 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
6939 if (ret == IOCB_ERROR) {
6940 lpfc_els_free_iocb(phba, elsiocb);
6947 * lpfc_send_rrq - Sends ELS RRQ if needed.
6948 * @phba: pointer to lpfc hba data structure.
6949 * @rrq: pointer to the active rrq.
6951 * This routine will call the lpfc_issue_els_rrq if the rrq is
6952 * still active for the xri. If this function returns a failure then
6953 * the caller needs to clean up the RRQ by calling lpfc_clr_active_rrq.
6955 * Returns 0 Success.
6959 lpfc_send_rrq(struct lpfc_hba *phba, struct lpfc_node_rrq *rrq)
6961 struct lpfc_nodelist *ndlp = lpfc_findnode_did(rrq->vport,
6963 if (lpfc_test_rrq_active(phba, ndlp, rrq->xritag))
6964 return lpfc_issue_els_rrq(rrq->vport, ndlp,
6971 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
6972 * @vport: pointer to a host virtual N_Port data structure.
6973 * @cmdsize: size of the ELS command.
6974 * @oldiocb: pointer to the original lpfc command iocb data structure.
6975 * @ndlp: pointer to a node-list data structure.
6977 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
6978 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
6980 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6981 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6982 * will be stored into the context1 field of the IOCB for the completion
6983 * callback function to the RPL Accept Response ELS command.
6986 * 0 - Successfully issued ACC RPL ELS command
6987 * 1 - Failed to issue ACC RPL ELS command
6990 lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
6991 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
6993 struct lpfc_hba *phba = vport->phba;
6994 IOCB_t *icmd, *oldcmd;
6996 struct lpfc_iocbq *elsiocb;
6999 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
7000 ndlp->nlp_DID, ELS_CMD_ACC);
7005 icmd = &elsiocb->iocb;
7006 oldcmd = &oldiocb->iocb;
7007 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
7008 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
7010 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7011 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
7012 pcmd += sizeof(uint16_t);
7013 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
7014 pcmd += sizeof(uint16_t);
7016 /* Setup the RPL ACC payload */
7017 rpl_rsp.listLen = be32_to_cpu(1);
7019 rpl_rsp.port_num_blk.portNum = 0;
7020 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
7021 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
7022 sizeof(struct lpfc_name));
7023 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
7024 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
7025 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7026 "0120 Xmit ELS RPL ACC response tag x%x "
7027 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
7029 elsiocb->iotag, elsiocb->iocb.ulpContext,
7030 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
7032 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
7033 phba->fc_stat.elsXmitACC++;
7034 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
7036 lpfc_els_free_iocb(phba, elsiocb);
7043 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
7044 * @vport: pointer to a host virtual N_Port data structure.
7045 * @cmdiocb: pointer to lpfc command iocb data structure.
7046 * @ndlp: pointer to a node-list data structure.
7048 * This routine processes Read Port List (RPL) IOCB received as an ELS
7049 * unsolicited event. It first checks the remote port state. If the remote
7050 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
7051 * invokes the lpfc_els_rsp_reject() routine to send reject response.
7052 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
7053 * to accept the RPL.
7056 * 0 - Successfully processed rpl iocb (currently always return 0)
7059 lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7060 struct lpfc_nodelist *ndlp)
7062 struct lpfc_dmabuf *pcmd;
7069 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
7070 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
7071 /* issue rejection response */
7072 stat.un.b.lsRjtRsvd0 = 0;
7073 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
7074 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
7075 stat.un.b.vendorUnique = 0;
7076 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
7078 /* rejected the unsolicited RPL request and done with it */
7082 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7083 lp = (uint32_t *) pcmd->virt;
7084 rpl = (RPL *) (lp + 1);
7085 maxsize = be32_to_cpu(rpl->maxsize);
7087 /* We support only one port */
7088 if ((rpl->index == 0) &&
7090 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
7091 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
7093 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
7095 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
7101 * lpfc_els_rcv_farp - Process an unsolicited farp request els command
7102 * @vport: pointer to a virtual N_Port data structure.
7103 * @cmdiocb: pointer to lpfc command iocb data structure.
7104 * @ndlp: pointer to a node-list data structure.
7106 * This routine processes Fibre Channel Address Resolution Protocol
7107 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
7108 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
7109 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
7110 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
7111 * remote PortName is compared against the FC PortName stored in the @vport
7112 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
7113 * compared against the FC NodeName stored in the @vport data structure.
7114 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
7115 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
7116 * invoked to send out FARP Response to the remote node. Before sending the
7117 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
7118 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
7119 * routine is invoked to log into the remote port first.
7122 * 0 - Either the FARP Match Mode not supported or successfully processed
7125 lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7126 struct lpfc_nodelist *ndlp)
7128 struct lpfc_dmabuf *pcmd;
7132 uint32_t cmd, cnt, did;
7134 icmd = &cmdiocb->iocb;
7135 did = icmd->un.elsreq64.remoteID;
7136 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7137 lp = (uint32_t *) pcmd->virt;
7141 /* FARP-REQ received from DID <did> */
7142 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7143 "0601 FARP-REQ received from DID x%x\n", did);
7144 /* We will only support match on WWPN or WWNN */
7145 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
7150 /* If this FARP command is searching for my portname */
7151 if (fp->Mflags & FARP_MATCH_PORT) {
7152 if (memcmp(&fp->RportName, &vport->fc_portname,
7153 sizeof(struct lpfc_name)) == 0)
7157 /* If this FARP command is searching for my nodename */
7158 if (fp->Mflags & FARP_MATCH_NODE) {
7159 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
7160 sizeof(struct lpfc_name)) == 0)
7165 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
7166 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
7167 /* Log back into the node before sending the FARP. */
7168 if (fp->Rflags & FARP_REQUEST_PLOGI) {
7169 ndlp->nlp_prev_state = ndlp->nlp_state;
7170 lpfc_nlp_set_state(vport, ndlp,
7171 NLP_STE_PLOGI_ISSUE);
7172 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
7175 /* Send a FARP response to that node */
7176 if (fp->Rflags & FARP_REQUEST_FARPR)
7177 lpfc_issue_els_farpr(vport, did, 0);
7184 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
7185 * @vport: pointer to a host virtual N_Port data structure.
7186 * @cmdiocb: pointer to lpfc command iocb data structure.
7187 * @ndlp: pointer to a node-list data structure.
7189 * This routine processes Fibre Channel Address Resolution Protocol
7190 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
7191 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
7192 * the FARP response request.
7195 * 0 - Successfully processed FARPR IOCB (currently always return 0)
7198 lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7199 struct lpfc_nodelist *ndlp)
7201 struct lpfc_dmabuf *pcmd;
7206 icmd = &cmdiocb->iocb;
7207 did = icmd->un.elsreq64.remoteID;
7208 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7209 lp = (uint32_t *) pcmd->virt;
7212 /* FARP-RSP received from DID <did> */
7213 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7214 "0600 FARP-RSP received from DID x%x\n", did);
7215 /* ACCEPT the Farp resp request */
7216 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
7222 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
7223 * @vport: pointer to a host virtual N_Port data structure.
7224 * @cmdiocb: pointer to lpfc command iocb data structure.
7225 * @fan_ndlp: pointer to a node-list data structure.
7227 * This routine processes a Fabric Address Notification (FAN) IOCB
7228 * command received as an ELS unsolicited event. The FAN ELS command will
7229 * only be processed on a physical port (i.e., the @vport represents the
7230 * physical port). The fabric NodeName and PortName from the FAN IOCB are
7231 * compared against those in the phba data structure. If any of those is
7232 * different, the lpfc_initial_flogi() routine is invoked to initialize
7233 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
7234 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
7235 * is invoked to register login to the fabric.
7238 * 0 - Successfully processed fan iocb (currently always return 0).
7241 lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7242 struct lpfc_nodelist *fan_ndlp)
7244 struct lpfc_hba *phba = vport->phba;
7248 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
7249 lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
7251 /* FAN received; Fan does not have a reply sequence */
7252 if ((vport == phba->pport) &&
7253 (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
7254 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
7255 sizeof(struct lpfc_name))) ||
7256 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
7257 sizeof(struct lpfc_name)))) {
7258 /* This port has switched fabrics. FLOGI is required */
7259 lpfc_issue_init_vfi(vport);
7261 /* FAN verified - skip FLOGI */
7262 vport->fc_myDID = vport->fc_prevDID;
7263 if (phba->sli_rev < LPFC_SLI_REV4)
7264 lpfc_issue_fabric_reglogin(vport);
7266 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7267 "3138 Need register VFI: (x%x/%x)\n",
7268 vport->fc_prevDID, vport->fc_myDID);
7269 lpfc_issue_reg_vfi(vport);
7277 * lpfc_els_timeout - Handler funciton to the els timer
7278 * @ptr: holder for the timer function associated data.
7280 * This routine is invoked by the ELS timer after timeout. It posts the ELS
7281 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
7282 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
7283 * up the worker thread. It is for the worker thread to invoke the routine
7284 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
7287 lpfc_els_timeout(unsigned long ptr)
7289 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
7290 struct lpfc_hba *phba = vport->phba;
7291 uint32_t tmo_posted;
7292 unsigned long iflag;
7294 spin_lock_irqsave(&vport->work_port_lock, iflag);
7295 tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
7296 if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING)))
7297 vport->work_port_events |= WORKER_ELS_TMO;
7298 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
7300 if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING)))
7301 lpfc_worker_wake_up(phba);
7307 * lpfc_els_timeout_handler - Process an els timeout event
7308 * @vport: pointer to a virtual N_Port data structure.
7310 * This routine is the actual handler function that processes an ELS timeout
7311 * event. It walks the ELS ring to get and abort all the IOCBs (except the
7312 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
7313 * invoking the lpfc_sli_issue_abort_iotag() routine.
7316 lpfc_els_timeout_handler(struct lpfc_vport *vport)
7318 struct lpfc_hba *phba = vport->phba;
7319 struct lpfc_sli_ring *pring;
7320 struct lpfc_iocbq *tmp_iocb, *piocb;
7322 struct lpfc_dmabuf *pcmd;
7323 uint32_t els_command = 0;
7325 uint32_t remote_ID = 0xffffffff;
7326 LIST_HEAD(abort_list);
7329 timeout = (uint32_t)(phba->fc_ratov << 1);
7331 pring = lpfc_phba_elsring(phba);
7333 if ((phba->pport->load_flag & FC_UNLOADING))
7335 spin_lock_irq(&phba->hbalock);
7336 if (phba->sli_rev == LPFC_SLI_REV4)
7337 spin_lock(&pring->ring_lock);
7339 if ((phba->pport->load_flag & FC_UNLOADING)) {
7340 if (phba->sli_rev == LPFC_SLI_REV4)
7341 spin_unlock(&pring->ring_lock);
7342 spin_unlock_irq(&phba->hbalock);
7346 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
7349 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
7350 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
7351 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
7354 if (piocb->vport != vport)
7357 pcmd = (struct lpfc_dmabuf *) piocb->context2;
7359 els_command = *(uint32_t *) (pcmd->virt);
7361 if (els_command == ELS_CMD_FARP ||
7362 els_command == ELS_CMD_FARPR ||
7363 els_command == ELS_CMD_FDISC)
7366 if (piocb->drvrTimeout > 0) {
7367 if (piocb->drvrTimeout >= timeout)
7368 piocb->drvrTimeout -= timeout;
7370 piocb->drvrTimeout = 0;
7374 remote_ID = 0xffffffff;
7375 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
7376 remote_ID = cmd->un.elsreq64.remoteID;
7378 struct lpfc_nodelist *ndlp;
7379 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
7380 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
7381 remote_ID = ndlp->nlp_DID;
7383 list_add_tail(&piocb->dlist, &abort_list);
7385 if (phba->sli_rev == LPFC_SLI_REV4)
7386 spin_unlock(&pring->ring_lock);
7387 spin_unlock_irq(&phba->hbalock);
7389 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
7391 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7392 "0127 ELS timeout Data: x%x x%x x%x "
7393 "x%x\n", els_command,
7394 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
7395 spin_lock_irq(&phba->hbalock);
7396 list_del_init(&piocb->dlist);
7397 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
7398 spin_unlock_irq(&phba->hbalock);
7401 if (!list_empty(&pring->txcmplq))
7402 if (!(phba->pport->load_flag & FC_UNLOADING))
7403 mod_timer(&vport->els_tmofunc,
7404 jiffies + msecs_to_jiffies(1000 * timeout));
7408 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
7409 * @vport: pointer to a host virtual N_Port data structure.
7411 * This routine is used to clean up all the outstanding ELS commands on a
7412 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
7413 * routine. After that, it walks the ELS transmit queue to remove all the
7414 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
7415 * the IOCBs with a non-NULL completion callback function, the callback
7416 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
7417 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
7418 * callback function, the IOCB will simply be released. Finally, it walks
7419 * the ELS transmit completion queue to issue an abort IOCB to any transmit
7420 * completion queue IOCB that is associated with the @vport and is not
7421 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
7422 * part of the discovery state machine) out to HBA by invoking the
7423 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
7424 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
7425 * the IOCBs are aborted when this function returns.
7428 lpfc_els_flush_cmd(struct lpfc_vport *vport)
7430 LIST_HEAD(abort_list);
7431 struct lpfc_hba *phba = vport->phba;
7432 struct lpfc_sli_ring *pring;
7433 struct lpfc_iocbq *tmp_iocb, *piocb;
7436 lpfc_fabric_abort_vport(vport);
7438 * For SLI3, only the hbalock is required. But SLI4 needs to coordinate
7439 * with the ring insert operation. Because lpfc_sli_issue_abort_iotag
7440 * ultimately grabs the ring_lock, the driver must splice the list into
7441 * a working list and release the locks before calling the abort.
7443 spin_lock_irq(&phba->hbalock);
7444 pring = lpfc_phba_elsring(phba);
7445 if (phba->sli_rev == LPFC_SLI_REV4)
7446 spin_lock(&pring->ring_lock);
7448 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
7449 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
7452 if (piocb->vport != vport)
7454 list_add_tail(&piocb->dlist, &abort_list);
7456 if (phba->sli_rev == LPFC_SLI_REV4)
7457 spin_unlock(&pring->ring_lock);
7458 spin_unlock_irq(&phba->hbalock);
7459 /* Abort each iocb on the aborted list and remove the dlist links. */
7460 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
7461 spin_lock_irq(&phba->hbalock);
7462 list_del_init(&piocb->dlist);
7463 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
7464 spin_unlock_irq(&phba->hbalock);
7466 if (!list_empty(&abort_list))
7467 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7468 "3387 abort list for txq not empty\n");
7469 INIT_LIST_HEAD(&abort_list);
7471 spin_lock_irq(&phba->hbalock);
7472 if (phba->sli_rev == LPFC_SLI_REV4)
7473 spin_lock(&pring->ring_lock);
7475 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
7478 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
7482 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
7483 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
7484 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
7485 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
7486 cmd->ulpCommand == CMD_ABORT_XRI_CN)
7489 if (piocb->vport != vport)
7492 list_del_init(&piocb->list);
7493 list_add_tail(&piocb->list, &abort_list);
7495 if (phba->sli_rev == LPFC_SLI_REV4)
7496 spin_unlock(&pring->ring_lock);
7497 spin_unlock_irq(&phba->hbalock);
7499 /* Cancell all the IOCBs from the completions list */
7500 lpfc_sli_cancel_iocbs(phba, &abort_list,
7501 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
7507 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
7508 * @phba: pointer to lpfc hba data structure.
7510 * This routine is used to clean up all the outstanding ELS commands on a
7511 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
7512 * routine. After that, it walks the ELS transmit queue to remove all the
7513 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
7514 * the IOCBs with the completion callback function associated, the callback
7515 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
7516 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
7517 * callback function associated, the IOCB will simply be released. Finally,
7518 * it walks the ELS transmit completion queue to issue an abort IOCB to any
7519 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
7520 * management plane IOCBs that are not part of the discovery state machine)
7521 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
7524 lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
7526 struct lpfc_vport *vport;
7527 list_for_each_entry(vport, &phba->port_list, listentry)
7528 lpfc_els_flush_cmd(vport);
7534 * lpfc_send_els_failure_event - Posts an ELS command failure event
7535 * @phba: Pointer to hba context object.
7536 * @cmdiocbp: Pointer to command iocb which reported error.
7537 * @rspiocbp: Pointer to response iocb which reported error.
7539 * This function sends an event when there is an ELS command
7543 lpfc_send_els_failure_event(struct lpfc_hba *phba,
7544 struct lpfc_iocbq *cmdiocbp,
7545 struct lpfc_iocbq *rspiocbp)
7547 struct lpfc_vport *vport = cmdiocbp->vport;
7548 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7549 struct lpfc_lsrjt_event lsrjt_event;
7550 struct lpfc_fabric_event_header fabric_event;
7552 struct lpfc_nodelist *ndlp;
7555 ndlp = cmdiocbp->context1;
7556 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
7559 if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) {
7560 lsrjt_event.header.event_type = FC_REG_ELS_EVENT;
7561 lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV;
7562 memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname,
7563 sizeof(struct lpfc_name));
7564 memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename,
7565 sizeof(struct lpfc_name));
7566 pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
7567 cmdiocbp->context2)->virt);
7568 lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0;
7569 stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]);
7570 lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode;
7571 lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp;
7572 fc_host_post_vendor_event(shost,
7573 fc_get_event_number(),
7574 sizeof(lsrjt_event),
7575 (char *)&lsrjt_event,
7579 if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) ||
7580 (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) {
7581 fabric_event.event_type = FC_REG_FABRIC_EVENT;
7582 if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY)
7583 fabric_event.subcategory = LPFC_EVENT_PORT_BUSY;
7585 fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY;
7586 memcpy(fabric_event.wwpn, &ndlp->nlp_portname,
7587 sizeof(struct lpfc_name));
7588 memcpy(fabric_event.wwnn, &ndlp->nlp_nodename,
7589 sizeof(struct lpfc_name));
7590 fc_host_post_vendor_event(shost,
7591 fc_get_event_number(),
7592 sizeof(fabric_event),
7593 (char *)&fabric_event,
7601 * lpfc_send_els_event - Posts unsolicited els event
7602 * @vport: Pointer to vport object.
7603 * @ndlp: Pointer FC node object.
7604 * @cmd: ELS command code.
7606 * This function posts an event when there is an incoming
7607 * unsolicited ELS command.
7610 lpfc_send_els_event(struct lpfc_vport *vport,
7611 struct lpfc_nodelist *ndlp,
7614 struct lpfc_els_event_header *els_data = NULL;
7615 struct lpfc_logo_event *logo_data = NULL;
7616 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7618 if (*payload == ELS_CMD_LOGO) {
7619 logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL);
7621 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7622 "0148 Failed to allocate memory "
7623 "for LOGO event\n");
7626 els_data = &logo_data->header;
7628 els_data = kmalloc(sizeof(struct lpfc_els_event_header),
7631 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7632 "0149 Failed to allocate memory "
7637 els_data->event_type = FC_REG_ELS_EVENT;
7640 els_data->subcategory = LPFC_EVENT_PLOGI_RCV;
7643 els_data->subcategory = LPFC_EVENT_PRLO_RCV;
7646 els_data->subcategory = LPFC_EVENT_ADISC_RCV;
7649 els_data->subcategory = LPFC_EVENT_LOGO_RCV;
7650 /* Copy the WWPN in the LOGO payload */
7651 memcpy(logo_data->logo_wwpn, &payload[2],
7652 sizeof(struct lpfc_name));
7658 memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name));
7659 memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name));
7660 if (*payload == ELS_CMD_LOGO) {
7661 fc_host_post_vendor_event(shost,
7662 fc_get_event_number(),
7663 sizeof(struct lpfc_logo_event),
7668 fc_host_post_vendor_event(shost,
7669 fc_get_event_number(),
7670 sizeof(struct lpfc_els_event_header),
7681 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
7682 * @phba: pointer to lpfc hba data structure.
7683 * @pring: pointer to a SLI ring.
7684 * @vport: pointer to a host virtual N_Port data structure.
7685 * @elsiocb: pointer to lpfc els command iocb data structure.
7687 * This routine is used for processing the IOCB associated with a unsolicited
7688 * event. It first determines whether there is an existing ndlp that matches
7689 * the DID from the unsolicited IOCB. If not, it will create a new one with
7690 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
7691 * IOCB is then used to invoke the proper routine and to set up proper state
7692 * of the discovery state machine.
7695 lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
7696 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
7698 struct Scsi_Host *shost;
7699 struct lpfc_nodelist *ndlp;
7702 uint32_t cmd, did, newnode;
7703 uint8_t rjt_exp, rjt_err = 0;
7704 IOCB_t *icmd = &elsiocb->iocb;
7706 if (!vport || !(elsiocb->context2))
7710 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
7712 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
7713 lpfc_post_buffer(phba, pring, 1);
7715 did = icmd->un.rcvels.remoteID;
7716 if (icmd->ulpStatus) {
7717 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7718 "RCV Unsol ELS: status:x%x/x%x did:x%x",
7719 icmd->ulpStatus, icmd->un.ulpWord[4], did);
7723 /* Check to see if link went down during discovery */
7724 if (lpfc_els_chk_latt(vport))
7727 /* Ignore traffic received during vport shutdown. */
7728 if (vport->load_flag & FC_UNLOADING)
7731 /* If NPort discovery is delayed drop incoming ELS */
7732 if ((vport->fc_flag & FC_DISC_DELAYED) &&
7733 (cmd != ELS_CMD_PLOGI))
7736 ndlp = lpfc_findnode_did(vport, did);
7738 /* Cannot find existing Fabric ndlp, so allocate a new one */
7739 ndlp = lpfc_nlp_init(vport, did);
7742 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
7744 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
7745 ndlp->nlp_type |= NLP_FABRIC;
7746 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
7747 ndlp = lpfc_enable_node(vport, ndlp,
7748 NLP_STE_UNUSED_NODE);
7751 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
7753 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
7754 ndlp->nlp_type |= NLP_FABRIC;
7755 } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
7756 /* This is similar to the new node path */
7757 ndlp = lpfc_nlp_get(ndlp);
7760 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
7764 phba->fc_stat.elsRcvFrame++;
7767 * Do not process any unsolicited ELS commands
7768 * if the ndlp is in DEV_LOSS
7770 shost = lpfc_shost_from_vport(vport);
7771 spin_lock_irq(shost->host_lock);
7772 if (ndlp->nlp_flag & NLP_IN_DEV_LOSS) {
7773 spin_unlock_irq(shost->host_lock);
7776 spin_unlock_irq(shost->host_lock);
7778 elsiocb->context1 = lpfc_nlp_get(ndlp);
7779 elsiocb->vport = vport;
7781 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
7782 cmd &= ELS_CMD_MASK;
7784 /* ELS command <elsCmd> received from NPORT <did> */
7785 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7786 "0112 ELS command x%x received from NPORT x%x "
7787 "Data: x%x x%x x%x x%x\n",
7788 cmd, did, vport->port_state, vport->fc_flag,
7789 vport->fc_myDID, vport->fc_prevDID);
7791 /* reject till our FLOGI completes */
7792 if ((vport->port_state < LPFC_FABRIC_CFG_LINK) &&
7793 (cmd != ELS_CMD_FLOGI)) {
7794 rjt_err = LSRJT_LOGICAL_BSY;
7795 rjt_exp = LSEXP_NOTHING_MORE;
7801 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7802 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
7803 did, vport->port_state, ndlp->nlp_flag);
7805 phba->fc_stat.elsRcvPLOGI++;
7806 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
7807 if (phba->sli_rev == LPFC_SLI_REV4 &&
7808 (phba->pport->fc_flag & FC_PT2PT)) {
7809 vport->fc_prevDID = vport->fc_myDID;
7810 /* Our DID needs to be updated before registering
7811 * the vfi. This is done in lpfc_rcv_plogi but
7812 * that is called after the reg_vfi.
7814 vport->fc_myDID = elsiocb->iocb.un.rcvels.parmRo;
7815 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7816 "3312 Remote port assigned DID x%x "
7817 "%x\n", vport->fc_myDID,
7821 lpfc_send_els_event(vport, ndlp, payload);
7823 /* If Nport discovery is delayed, reject PLOGIs */
7824 if (vport->fc_flag & FC_DISC_DELAYED) {
7825 rjt_err = LSRJT_UNABLE_TPC;
7826 rjt_exp = LSEXP_NOTHING_MORE;
7830 if (vport->port_state < LPFC_DISC_AUTH) {
7831 if (!(phba->pport->fc_flag & FC_PT2PT) ||
7832 (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
7833 rjt_err = LSRJT_UNABLE_TPC;
7834 rjt_exp = LSEXP_NOTHING_MORE;
7839 spin_lock_irq(shost->host_lock);
7840 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
7841 spin_unlock_irq(shost->host_lock);
7843 lpfc_disc_state_machine(vport, ndlp, elsiocb,
7848 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7849 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
7850 did, vport->port_state, ndlp->nlp_flag);
7852 phba->fc_stat.elsRcvFLOGI++;
7853 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
7858 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7859 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
7860 did, vport->port_state, ndlp->nlp_flag);
7862 phba->fc_stat.elsRcvLOGO++;
7863 lpfc_send_els_event(vport, ndlp, payload);
7864 if (vport->port_state < LPFC_DISC_AUTH) {
7865 rjt_err = LSRJT_UNABLE_TPC;
7866 rjt_exp = LSEXP_NOTHING_MORE;
7869 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
7872 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7873 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
7874 did, vport->port_state, ndlp->nlp_flag);
7876 phba->fc_stat.elsRcvPRLO++;
7877 lpfc_send_els_event(vport, ndlp, payload);
7878 if (vport->port_state < LPFC_DISC_AUTH) {
7879 rjt_err = LSRJT_UNABLE_TPC;
7880 rjt_exp = LSEXP_NOTHING_MORE;
7883 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
7886 phba->fc_stat.elsRcvLCB++;
7887 lpfc_els_rcv_lcb(vport, elsiocb, ndlp);
7890 phba->fc_stat.elsRcvRDP++;
7891 lpfc_els_rcv_rdp(vport, elsiocb, ndlp);
7894 phba->fc_stat.elsRcvRSCN++;
7895 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
7900 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7901 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
7902 did, vport->port_state, ndlp->nlp_flag);
7904 lpfc_send_els_event(vport, ndlp, payload);
7905 phba->fc_stat.elsRcvADISC++;
7906 if (vport->port_state < LPFC_DISC_AUTH) {
7907 rjt_err = LSRJT_UNABLE_TPC;
7908 rjt_exp = LSEXP_NOTHING_MORE;
7911 lpfc_disc_state_machine(vport, ndlp, elsiocb,
7915 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7916 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
7917 did, vport->port_state, ndlp->nlp_flag);
7919 phba->fc_stat.elsRcvPDISC++;
7920 if (vport->port_state < LPFC_DISC_AUTH) {
7921 rjt_err = LSRJT_UNABLE_TPC;
7922 rjt_exp = LSEXP_NOTHING_MORE;
7925 lpfc_disc_state_machine(vport, ndlp, elsiocb,
7929 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7930 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
7931 did, vport->port_state, ndlp->nlp_flag);
7933 phba->fc_stat.elsRcvFARPR++;
7934 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
7937 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7938 "RCV FARP: did:x%x/ste:x%x flg:x%x",
7939 did, vport->port_state, ndlp->nlp_flag);
7941 phba->fc_stat.elsRcvFARP++;
7942 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
7945 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7946 "RCV FAN: did:x%x/ste:x%x flg:x%x",
7947 did, vport->port_state, ndlp->nlp_flag);
7949 phba->fc_stat.elsRcvFAN++;
7950 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
7953 case ELS_CMD_NVMEPRLI:
7954 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7955 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
7956 did, vport->port_state, ndlp->nlp_flag);
7958 phba->fc_stat.elsRcvPRLI++;
7959 if (vport->port_state < LPFC_DISC_AUTH) {
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);
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);