1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2017 Broadcom. All Rights Reserved. The term *
5 * “Broadcom” refers to Broadcom Limited and/or its subsidiaries. *
6 * Copyright (C) 2004-2016 Emulex. All rights reserved. *
7 * EMULEX and SLI are trademarks of Emulex. *
9 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
11 * This program is free software; you can redistribute it and/or *
12 * modify it under the terms of version 2 of the GNU General *
13 * Public License as published by the Free Software Foundation. *
14 * This program is distributed in the hope that it will be useful. *
15 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
16 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
17 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
18 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
19 * TO BE LEGALLY INVALID. See the GNU General Public License for *
20 * more details, a copy of which can be found in the file COPYING *
21 * included with this package. *
22 *******************************************************************/
23 /* See Fibre Channel protocol T11 FC-LS for details */
24 #include <linux/blkdev.h>
25 #include <linux/pci.h>
26 #include <linux/slab.h>
27 #include <linux/interrupt.h>
29 #include <scsi/scsi.h>
30 #include <scsi/scsi_device.h>
31 #include <scsi/scsi_host.h>
32 #include <scsi/scsi_transport_fc.h>
37 #include "lpfc_sli4.h"
39 #include "lpfc_disc.h"
40 #include "lpfc_scsi.h"
42 #include "lpfc_logmsg.h"
43 #include "lpfc_crtn.h"
44 #include "lpfc_vport.h"
45 #include "lpfc_debugfs.h"
47 static int lpfc_els_retry(struct lpfc_hba *, struct lpfc_iocbq *,
49 static void lpfc_cmpl_fabric_iocb(struct lpfc_hba *, struct lpfc_iocbq *,
51 static void lpfc_fabric_abort_vport(struct lpfc_vport *vport);
52 static int lpfc_issue_els_fdisc(struct lpfc_vport *vport,
53 struct lpfc_nodelist *ndlp, uint8_t retry);
54 static int lpfc_issue_fabric_iocb(struct lpfc_hba *phba,
55 struct lpfc_iocbq *iocb);
57 static int lpfc_max_els_tries = 3;
60 * lpfc_els_chk_latt - Check host link attention event for a vport
61 * @vport: pointer to a host virtual N_Port data structure.
63 * This routine checks whether there is an outstanding host link
64 * attention event during the discovery process with the @vport. It is done
65 * by reading the HBA's Host Attention (HA) register. If there is any host
66 * link attention events during this @vport's discovery process, the @vport
67 * shall be marked as FC_ABORT_DISCOVERY, a host link attention clear shall
68 * be issued if the link state is not already in host link cleared state,
69 * and a return code shall indicate whether the host link attention event
72 * Note that, if either the host link is in state LPFC_LINK_DOWN or @vport
73 * state in LPFC_VPORT_READY, the request for checking host link attention
74 * event will be ignored and a return code shall indicate no host link
75 * attention event had happened.
78 * 0 - no host link attention event happened
79 * 1 - host link attention event happened
82 lpfc_els_chk_latt(struct lpfc_vport *vport)
84 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
85 struct lpfc_hba *phba = vport->phba;
88 if (vport->port_state >= LPFC_VPORT_READY ||
89 phba->link_state == LPFC_LINK_DOWN ||
90 phba->sli_rev > LPFC_SLI_REV3)
93 /* Read the HBA Host Attention Register */
94 if (lpfc_readl(phba->HAregaddr, &ha_copy))
97 if (!(ha_copy & HA_LATT))
100 /* Pending Link Event during Discovery */
101 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
102 "0237 Pending Link Event during "
103 "Discovery: State x%x\n",
104 phba->pport->port_state);
106 /* CLEAR_LA should re-enable link attention events and
107 * we should then immediately take a LATT event. The
108 * LATT processing should call lpfc_linkdown() which
109 * will cleanup any left over in-progress discovery
112 spin_lock_irq(shost->host_lock);
113 vport->fc_flag |= FC_ABORT_DISCOVERY;
114 spin_unlock_irq(shost->host_lock);
116 if (phba->link_state != LPFC_CLEAR_LA)
117 lpfc_issue_clear_la(phba, vport);
123 * lpfc_prep_els_iocb - Allocate and prepare a lpfc iocb data structure
124 * @vport: pointer to a host virtual N_Port data structure.
125 * @expectRsp: flag indicating whether response is expected.
126 * @cmdSize: size of the ELS command.
127 * @retry: number of retries to the command IOCB when it fails.
128 * @ndlp: pointer to a node-list data structure.
129 * @did: destination identifier.
130 * @elscmd: the ELS command code.
132 * This routine is used for allocating a lpfc-IOCB data structure from
133 * the driver lpfc-IOCB free-list and prepare the IOCB with the parameters
134 * passed into the routine for discovery state machine to issue an Extended
135 * Link Service (ELS) commands. It is a generic lpfc-IOCB allocation
136 * and preparation routine that is used by all the discovery state machine
137 * routines and the ELS command-specific fields will be later set up by
138 * the individual discovery machine routines after calling this routine
139 * allocating and preparing a generic IOCB data structure. It fills in the
140 * Buffer Descriptor Entries (BDEs), allocates buffers for both command
141 * payload and response payload (if expected). The reference count on the
142 * ndlp is incremented by 1 and the reference to the ndlp is put into
143 * context1 of the IOCB data structure for this IOCB to hold the ndlp
144 * reference for the command's callback function to access later.
147 * Pointer to the newly allocated/prepared els iocb data structure
148 * NULL - when els iocb data structure allocation/preparation failed
151 lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp,
152 uint16_t cmdSize, uint8_t retry,
153 struct lpfc_nodelist *ndlp, uint32_t did,
156 struct lpfc_hba *phba = vport->phba;
157 struct lpfc_iocbq *elsiocb;
158 struct lpfc_dmabuf *pcmd, *prsp, *pbuflist;
159 struct ulp_bde64 *bpl;
163 if (!lpfc_is_link_up(phba))
166 /* Allocate buffer for command iocb */
167 elsiocb = lpfc_sli_get_iocbq(phba);
173 * If this command is for fabric controller and HBA running
174 * in FIP mode send FLOGI, FDISC and LOGO as FIP frames.
176 if ((did == Fabric_DID) &&
177 (phba->hba_flag & HBA_FIP_SUPPORT) &&
178 ((elscmd == ELS_CMD_FLOGI) ||
179 (elscmd == ELS_CMD_FDISC) ||
180 (elscmd == ELS_CMD_LOGO)))
183 elsiocb->iocb_flag |=
184 ((LPFC_ELS_ID_FLOGI << LPFC_FIP_ELS_ID_SHIFT)
185 & LPFC_FIP_ELS_ID_MASK);
188 elsiocb->iocb_flag |=
189 ((LPFC_ELS_ID_FDISC << LPFC_FIP_ELS_ID_SHIFT)
190 & LPFC_FIP_ELS_ID_MASK);
193 elsiocb->iocb_flag |=
194 ((LPFC_ELS_ID_LOGO << LPFC_FIP_ELS_ID_SHIFT)
195 & LPFC_FIP_ELS_ID_MASK);
199 elsiocb->iocb_flag &= ~LPFC_FIP_ELS_ID_MASK;
201 icmd = &elsiocb->iocb;
203 /* fill in BDEs for command */
204 /* Allocate buffer for command payload */
205 pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
207 pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys);
208 if (!pcmd || !pcmd->virt)
209 goto els_iocb_free_pcmb_exit;
211 INIT_LIST_HEAD(&pcmd->list);
213 /* Allocate buffer for response payload */
215 prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
217 prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
219 if (!prsp || !prsp->virt)
220 goto els_iocb_free_prsp_exit;
221 INIT_LIST_HEAD(&prsp->list);
225 /* Allocate buffer for Buffer ptr list */
226 pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
228 pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
230 if (!pbuflist || !pbuflist->virt)
231 goto els_iocb_free_pbuf_exit;
233 INIT_LIST_HEAD(&pbuflist->list);
236 icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
237 icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
238 icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
239 icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64));
241 icmd->un.elsreq64.remoteID = did; /* DID */
242 icmd->ulpCommand = CMD_ELS_REQUEST64_CR;
243 if (elscmd == ELS_CMD_FLOGI)
244 icmd->ulpTimeout = FF_DEF_RATOV * 2;
246 icmd->ulpTimeout = phba->fc_ratov * 2;
248 icmd->un.xseq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
249 icmd->un.xseq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
250 icmd->un.xseq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
251 icmd->un.xseq64.bdl.bdeSize = sizeof(struct ulp_bde64);
252 icmd->un.xseq64.xmit_els_remoteID = did; /* DID */
253 icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX;
255 icmd->ulpBdeCount = 1;
257 icmd->ulpClass = CLASS3;
260 * If we have NPIV enabled, we want to send ELS traffic by VPI.
261 * For SLI4, since the driver controls VPIs we also want to include
262 * all ELS pt2pt protocol traffic as well.
264 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) ||
265 ((phba->sli_rev == LPFC_SLI_REV4) &&
266 (vport->fc_flag & FC_PT2PT))) {
269 icmd->un.elsreq64.myID = vport->fc_myDID;
271 /* For ELS_REQUEST64_CR, use the VPI by default */
272 icmd->ulpContext = phba->vpi_ids[vport->vpi];
276 /* The CT field must be 0=INVALID_RPI for the ECHO cmd */
277 if (elscmd == ELS_CMD_ECHO)
278 icmd->ulpCt_l = 0; /* context = invalid RPI */
280 icmd->ulpCt_l = 1; /* context = VPI */
283 bpl = (struct ulp_bde64 *) pbuflist->virt;
284 bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys));
285 bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys));
286 bpl->tus.f.bdeSize = cmdSize;
287 bpl->tus.f.bdeFlags = 0;
288 bpl->tus.w = le32_to_cpu(bpl->tus.w);
292 bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys));
293 bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys));
294 bpl->tus.f.bdeSize = FCELSSIZE;
295 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
296 bpl->tus.w = le32_to_cpu(bpl->tus.w);
299 /* prevent preparing iocb with NULL ndlp reference */
300 elsiocb->context1 = lpfc_nlp_get(ndlp);
301 if (!elsiocb->context1)
302 goto els_iocb_free_pbuf_exit;
303 elsiocb->context2 = pcmd;
304 elsiocb->context3 = pbuflist;
305 elsiocb->retry = retry;
306 elsiocb->vport = vport;
307 elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT;
310 list_add(&prsp->list, &pcmd->list);
313 /* Xmit ELS command <elsCmd> to remote NPORT <did> */
314 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
315 "0116 Xmit ELS command x%x to remote "
316 "NPORT x%x I/O tag: x%x, port state:x%x"
318 elscmd, did, elsiocb->iotag,
322 /* Xmit ELS response <elsCmd> to remote NPORT <did> */
323 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
324 "0117 Xmit ELS response x%x to remote "
325 "NPORT x%x I/O tag: x%x, size: x%x "
326 "port_state x%x fc_flag x%x\n",
327 elscmd, ndlp->nlp_DID, elsiocb->iotag,
328 cmdSize, vport->port_state,
333 els_iocb_free_pbuf_exit:
335 lpfc_mbuf_free(phba, prsp->virt, prsp->phys);
338 els_iocb_free_prsp_exit:
339 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
342 els_iocb_free_pcmb_exit:
344 lpfc_sli_release_iocbq(phba, elsiocb);
349 * lpfc_issue_fabric_reglogin - Issue fabric registration login for a vport
350 * @vport: pointer to a host virtual N_Port data structure.
352 * This routine issues a fabric registration login for a @vport. An
353 * active ndlp node with Fabric_DID must already exist for this @vport.
354 * The routine invokes two mailbox commands to carry out fabric registration
355 * login through the HBA firmware: the first mailbox command requests the
356 * HBA to perform link configuration for the @vport; and the second mailbox
357 * command requests the HBA to perform the actual fabric registration login
361 * 0 - successfully issued fabric registration login for @vport
362 * -ENXIO -- failed to issue fabric registration login for @vport
365 lpfc_issue_fabric_reglogin(struct lpfc_vport *vport)
367 struct lpfc_hba *phba = vport->phba;
369 struct lpfc_dmabuf *mp;
370 struct lpfc_nodelist *ndlp;
371 struct serv_parm *sp;
375 sp = &phba->fc_fabparam;
376 ndlp = lpfc_findnode_did(vport, Fabric_DID);
377 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
382 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
388 vport->port_state = LPFC_FABRIC_CFG_LINK;
389 lpfc_config_link(phba, mbox);
390 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
393 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
394 if (rc == MBX_NOT_FINISHED) {
399 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
404 rc = lpfc_reg_rpi(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox,
411 mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login;
413 /* increment the reference count on ndlp to hold reference
414 * for the callback routine.
416 mbox->context2 = lpfc_nlp_get(ndlp);
418 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
419 if (rc == MBX_NOT_FINISHED) {
421 goto fail_issue_reg_login;
426 fail_issue_reg_login:
427 /* decrement the reference count on ndlp just incremented
428 * for the failed mbox command.
431 mp = (struct lpfc_dmabuf *) mbox->context1;
432 lpfc_mbuf_free(phba, mp->virt, mp->phys);
435 mempool_free(mbox, phba->mbox_mem_pool);
438 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
439 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
440 "0249 Cannot issue Register Fabric login: Err %d\n", err);
445 * lpfc_issue_reg_vfi - Register VFI for this vport's fabric login
446 * @vport: pointer to a host virtual N_Port data structure.
448 * This routine issues a REG_VFI mailbox for the vfi, vpi, fcfi triplet for
449 * the @vport. This mailbox command is necessary for SLI4 port only.
452 * 0 - successfully issued REG_VFI for @vport
453 * A failure code otherwise.
456 lpfc_issue_reg_vfi(struct lpfc_vport *vport)
458 struct lpfc_hba *phba = vport->phba;
459 LPFC_MBOXQ_t *mboxq = NULL;
460 struct lpfc_nodelist *ndlp;
461 struct lpfc_dmabuf *dmabuf = NULL;
464 /* move forward in case of SLI4 FC port loopback test and pt2pt mode */
465 if ((phba->sli_rev == LPFC_SLI_REV4) &&
466 !(phba->link_flag & LS_LOOPBACK_MODE) &&
467 !(vport->fc_flag & FC_PT2PT)) {
468 ndlp = lpfc_findnode_did(vport, Fabric_DID);
469 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
475 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
481 /* Supply CSP's only if we are fabric connect or pt-to-pt connect */
482 if ((vport->fc_flag & FC_FABRIC) || (vport->fc_flag & FC_PT2PT)) {
483 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
488 dmabuf->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &dmabuf->phys);
493 memcpy(dmabuf->virt, &phba->fc_fabparam,
494 sizeof(struct serv_parm));
497 vport->port_state = LPFC_FABRIC_CFG_LINK;
499 lpfc_reg_vfi(mboxq, vport, dmabuf->phys);
501 lpfc_reg_vfi(mboxq, vport, 0);
503 mboxq->mbox_cmpl = lpfc_mbx_cmpl_reg_vfi;
504 mboxq->vport = vport;
505 mboxq->context1 = dmabuf;
506 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
507 if (rc == MBX_NOT_FINISHED) {
515 mempool_free(mboxq, phba->mbox_mem_pool);
518 lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys);
522 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
523 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
524 "0289 Issue Register VFI failed: Err %d\n", rc);
529 * lpfc_issue_unreg_vfi - Unregister VFI for this vport's fabric login
530 * @vport: pointer to a host virtual N_Port data structure.
532 * This routine issues a UNREG_VFI mailbox with the vfi, vpi, fcfi triplet for
533 * the @vport. This mailbox command is necessary for SLI4 port only.
536 * 0 - successfully issued REG_VFI for @vport
537 * A failure code otherwise.
540 lpfc_issue_unreg_vfi(struct lpfc_vport *vport)
542 struct lpfc_hba *phba = vport->phba;
543 struct Scsi_Host *shost;
547 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
549 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
550 "2556 UNREG_VFI mbox allocation failed"
551 "HBA state x%x\n", phba->pport->port_state);
555 lpfc_unreg_vfi(mboxq, vport);
556 mboxq->vport = vport;
557 mboxq->mbox_cmpl = lpfc_unregister_vfi_cmpl;
559 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
560 if (rc == MBX_NOT_FINISHED) {
561 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
562 "2557 UNREG_VFI issue mbox failed rc x%x "
564 rc, phba->pport->port_state);
565 mempool_free(mboxq, phba->mbox_mem_pool);
569 shost = lpfc_shost_from_vport(vport);
570 spin_lock_irq(shost->host_lock);
571 vport->fc_flag &= ~FC_VFI_REGISTERED;
572 spin_unlock_irq(shost->host_lock);
577 * lpfc_check_clean_addr_bit - Check whether assigned FCID is clean.
578 * @vport: pointer to a host virtual N_Port data structure.
579 * @sp: pointer to service parameter data structure.
581 * This routine is called from FLOGI/FDISC completion handler functions.
582 * lpfc_check_clean_addr_bit return 1 when FCID/Fabric portname/ Fabric
583 * node nodename is changed in the completion service parameter else return
584 * 0. This function also set flag in the vport data structure to delay
585 * NP_Port discovery after the FLOGI/FDISC completion if Clean address bit
586 * in FLOGI/FDISC response is cleared and FCID/Fabric portname/ Fabric
587 * node nodename is changed in the completion service parameter.
590 * 0 - FCID and Fabric Nodename and Fabric portname is not changed.
591 * 1 - FCID or Fabric Nodename or Fabric portname is changed.
595 lpfc_check_clean_addr_bit(struct lpfc_vport *vport,
596 struct serv_parm *sp)
598 struct lpfc_hba *phba = vport->phba;
599 uint8_t fabric_param_changed = 0;
600 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
602 if ((vport->fc_prevDID != vport->fc_myDID) ||
603 memcmp(&vport->fabric_portname, &sp->portName,
604 sizeof(struct lpfc_name)) ||
605 memcmp(&vport->fabric_nodename, &sp->nodeName,
606 sizeof(struct lpfc_name)) ||
607 (vport->vport_flag & FAWWPN_PARAM_CHG)) {
608 fabric_param_changed = 1;
609 vport->vport_flag &= ~FAWWPN_PARAM_CHG;
612 * Word 1 Bit 31 in common service parameter is overloaded.
613 * Word 1 Bit 31 in FLOGI request is multiple NPort request
614 * Word 1 Bit 31 in FLOGI response is clean address bit
616 * If fabric parameter is changed and clean address bit is
617 * cleared delay nport discovery if
618 * - vport->fc_prevDID != 0 (not initial discovery) OR
619 * - lpfc_delay_discovery module parameter is set.
621 if (fabric_param_changed && !sp->cmn.clean_address_bit &&
622 (vport->fc_prevDID || phba->cfg_delay_discovery)) {
623 spin_lock_irq(shost->host_lock);
624 vport->fc_flag |= FC_DISC_DELAYED;
625 spin_unlock_irq(shost->host_lock);
628 return fabric_param_changed;
633 * lpfc_cmpl_els_flogi_fabric - Completion function for flogi to a fabric port
634 * @vport: pointer to a host virtual N_Port data structure.
635 * @ndlp: pointer to a node-list data structure.
636 * @sp: pointer to service parameter data structure.
637 * @irsp: pointer to the IOCB within the lpfc response IOCB.
639 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
640 * function to handle the completion of a Fabric Login (FLOGI) into a fabric
641 * port in a fabric topology. It properly sets up the parameters to the @ndlp
642 * from the IOCB response. It also check the newly assigned N_Port ID to the
643 * @vport against the previously assigned N_Port ID. If it is different from
644 * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine
645 * is invoked on all the remaining nodes with the @vport to unregister the
646 * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin()
647 * is invoked to register login to the fabric.
650 * 0 - Success (currently, always return 0)
653 lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
654 struct serv_parm *sp, IOCB_t *irsp)
656 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
657 struct lpfc_hba *phba = vport->phba;
658 struct lpfc_nodelist *np;
659 struct lpfc_nodelist *next_np;
660 uint8_t fabric_param_changed;
662 spin_lock_irq(shost->host_lock);
663 vport->fc_flag |= FC_FABRIC;
664 spin_unlock_irq(shost->host_lock);
666 phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
667 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
668 phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
670 phba->fc_edtovResol = sp->cmn.edtovResolution;
671 phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
673 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
674 spin_lock_irq(shost->host_lock);
675 vport->fc_flag |= FC_PUBLIC_LOOP;
676 spin_unlock_irq(shost->host_lock);
679 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
680 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
681 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name));
682 ndlp->nlp_class_sup = 0;
683 if (sp->cls1.classValid)
684 ndlp->nlp_class_sup |= FC_COS_CLASS1;
685 if (sp->cls2.classValid)
686 ndlp->nlp_class_sup |= FC_COS_CLASS2;
687 if (sp->cls3.classValid)
688 ndlp->nlp_class_sup |= FC_COS_CLASS3;
689 if (sp->cls4.classValid)
690 ndlp->nlp_class_sup |= FC_COS_CLASS4;
691 ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
692 sp->cmn.bbRcvSizeLsb;
694 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
695 if (fabric_param_changed) {
696 /* Reset FDMI attribute masks based on config parameter */
697 if (phba->cfg_enable_SmartSAN ||
698 (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) {
699 /* Setup appropriate attribute masks */
700 vport->fdmi_hba_mask = LPFC_FDMI2_HBA_ATTR;
701 if (phba->cfg_enable_SmartSAN)
702 vport->fdmi_port_mask = LPFC_FDMI2_SMART_ATTR;
704 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
706 vport->fdmi_hba_mask = 0;
707 vport->fdmi_port_mask = 0;
711 memcpy(&vport->fabric_portname, &sp->portName,
712 sizeof(struct lpfc_name));
713 memcpy(&vport->fabric_nodename, &sp->nodeName,
714 sizeof(struct lpfc_name));
715 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
717 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
718 if (sp->cmn.response_multiple_NPort) {
719 lpfc_printf_vlog(vport, KERN_WARNING,
721 "1816 FLOGI NPIV supported, "
722 "response data 0x%x\n",
723 sp->cmn.response_multiple_NPort);
724 spin_lock_irq(&phba->hbalock);
725 phba->link_flag |= LS_NPIV_FAB_SUPPORTED;
726 spin_unlock_irq(&phba->hbalock);
728 /* Because we asked f/w for NPIV it still expects us
729 to call reg_vnpid atleast for the physcial host */
730 lpfc_printf_vlog(vport, KERN_WARNING,
732 "1817 Fabric does not support NPIV "
733 "- configuring single port mode.\n");
734 spin_lock_irq(&phba->hbalock);
735 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
736 spin_unlock_irq(&phba->hbalock);
741 * For FC we need to do some special processing because of the SLI
742 * Port's default settings of the Common Service Parameters.
744 if ((phba->sli_rev == LPFC_SLI_REV4) &&
745 (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC)) {
746 /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */
747 if (fabric_param_changed)
748 lpfc_unregister_fcf_prep(phba);
750 /* This should just update the VFI CSPs*/
751 if (vport->fc_flag & FC_VFI_REGISTERED)
752 lpfc_issue_reg_vfi(vport);
755 if (fabric_param_changed &&
756 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
758 /* If our NportID changed, we need to ensure all
759 * remaining NPORTs get unreg_login'ed.
761 list_for_each_entry_safe(np, next_np,
762 &vport->fc_nodes, nlp_listp) {
763 if (!NLP_CHK_NODE_ACT(np))
765 if ((np->nlp_state != NLP_STE_NPR_NODE) ||
766 !(np->nlp_flag & NLP_NPR_ADISC))
768 spin_lock_irq(shost->host_lock);
769 np->nlp_flag &= ~NLP_NPR_ADISC;
770 spin_unlock_irq(shost->host_lock);
771 lpfc_unreg_rpi(vport, np);
773 lpfc_cleanup_pending_mbox(vport);
775 if (phba->sli_rev == LPFC_SLI_REV4) {
776 lpfc_sli4_unreg_all_rpis(vport);
777 lpfc_mbx_unreg_vpi(vport);
778 spin_lock_irq(shost->host_lock);
779 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
780 spin_unlock_irq(shost->host_lock);
784 * For SLI3 and SLI4, the VPI needs to be reregistered in
785 * response to this fabric parameter change event.
787 spin_lock_irq(shost->host_lock);
788 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
789 spin_unlock_irq(shost->host_lock);
790 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
791 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
793 * Driver needs to re-reg VPI in order for f/w
794 * to update the MAC address.
796 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
797 lpfc_register_new_vport(phba, vport, ndlp);
801 if (phba->sli_rev < LPFC_SLI_REV4) {
802 lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
803 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED &&
804 vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
805 lpfc_register_new_vport(phba, vport, ndlp);
807 lpfc_issue_fabric_reglogin(vport);
809 ndlp->nlp_type |= NLP_FABRIC;
810 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
811 if ((!(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) &&
812 (vport->vpi_state & LPFC_VPI_REGISTERED)) {
813 lpfc_start_fdiscs(phba);
814 lpfc_do_scr_ns_plogi(phba, vport);
815 } else if (vport->fc_flag & FC_VFI_REGISTERED)
816 lpfc_issue_init_vpi(vport);
818 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
819 "3135 Need register VFI: (x%x/%x)\n",
820 vport->fc_prevDID, vport->fc_myDID);
821 lpfc_issue_reg_vfi(vport);
828 * lpfc_cmpl_els_flogi_nport - Completion function for flogi to an N_Port
829 * @vport: pointer to a host virtual N_Port data structure.
830 * @ndlp: pointer to a node-list data structure.
831 * @sp: pointer to service parameter data structure.
833 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
834 * function to handle the completion of a Fabric Login (FLOGI) into an N_Port
835 * in a point-to-point topology. First, the @vport's N_Port Name is compared
836 * with the received N_Port Name: if the @vport's N_Port Name is greater than
837 * the received N_Port Name lexicographically, this node shall assign local
838 * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and
839 * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise,
840 * this node shall just wait for the remote node to issue PLOGI and assign
848 lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
849 struct serv_parm *sp)
851 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
852 struct lpfc_hba *phba = vport->phba;
856 spin_lock_irq(shost->host_lock);
857 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
858 vport->fc_flag |= FC_PT2PT;
859 spin_unlock_irq(shost->host_lock);
861 /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */
862 if ((phba->sli_rev == LPFC_SLI_REV4) && phba->fc_topology_changed) {
863 lpfc_unregister_fcf_prep(phba);
865 spin_lock_irq(shost->host_lock);
866 vport->fc_flag &= ~FC_VFI_REGISTERED;
867 spin_unlock_irq(shost->host_lock);
868 phba->fc_topology_changed = 0;
871 rc = memcmp(&vport->fc_portname, &sp->portName,
872 sizeof(vport->fc_portname));
875 /* This side will initiate the PLOGI */
876 spin_lock_irq(shost->host_lock);
877 vport->fc_flag |= FC_PT2PT_PLOGI;
878 spin_unlock_irq(shost->host_lock);
881 * N_Port ID cannot be 0, set our Id to LocalID
882 * the other side will be RemoteID.
887 vport->fc_myDID = PT2PT_LocalID;
889 /* Decrement ndlp reference count indicating that ndlp can be
890 * safely released when other references to it are done.
894 ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
897 * Cannot find existing Fabric ndlp, so allocate a
900 ndlp = lpfc_nlp_init(vport, PT2PT_RemoteID);
903 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
904 ndlp = lpfc_enable_node(vport, ndlp,
905 NLP_STE_UNUSED_NODE);
910 memcpy(&ndlp->nlp_portname, &sp->portName,
911 sizeof(struct lpfc_name));
912 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
913 sizeof(struct lpfc_name));
914 /* Set state will put ndlp onto node list if not already done */
915 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
916 spin_lock_irq(shost->host_lock);
917 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
918 spin_unlock_irq(shost->host_lock);
920 /* This side will wait for the PLOGI, decrement ndlp reference
921 * count indicating that ndlp can be released when other
922 * references to it are done.
926 /* If we are pt2pt with another NPort, force NPIV off! */
927 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
929 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
933 lpfc_config_link(phba, mbox);
935 mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link;
937 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
938 if (rc == MBX_NOT_FINISHED) {
939 mempool_free(mbox, phba->mbox_mem_pool);
949 * lpfc_cmpl_els_flogi - Completion callback function for flogi
950 * @phba: pointer to lpfc hba data structure.
951 * @cmdiocb: pointer to lpfc command iocb data structure.
952 * @rspiocb: pointer to lpfc response iocb data structure.
954 * This routine is the top-level completion callback function for issuing
955 * a Fabric Login (FLOGI) command. If the response IOCB reported error,
956 * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If
957 * retry has been made (either immediately or delayed with lpfc_els_retry()
958 * returning 1), the command IOCB will be released and function returned.
959 * If the retry attempt has been given up (possibly reach the maximum
960 * number of retries), one additional decrement of ndlp reference shall be
961 * invoked before going out after releasing the command IOCB. This will
962 * actually release the remote node (Note, lpfc_els_free_iocb() will also
963 * invoke one decrement of ndlp reference count). If no error reported in
964 * the IOCB status, the command Port ID field is used to determine whether
965 * this is a point-to-point topology or a fabric topology: if the Port ID
966 * field is assigned, it is a fabric topology; otherwise, it is a
967 * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or
968 * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the
969 * specific topology completion conditions.
972 lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
973 struct lpfc_iocbq *rspiocb)
975 struct lpfc_vport *vport = cmdiocb->vport;
976 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
977 IOCB_t *irsp = &rspiocb->iocb;
978 struct lpfc_nodelist *ndlp = cmdiocb->context1;
979 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
980 struct serv_parm *sp;
984 /* Check to see if link went down during discovery */
985 if (lpfc_els_chk_latt(vport)) {
986 /* One additional decrement on node reference count to
987 * trigger the release of the node
993 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
994 "FLOGI cmpl: status:x%x/x%x state:x%x",
995 irsp->ulpStatus, irsp->un.ulpWord[4],
998 if (irsp->ulpStatus) {
1000 * In case of FIP mode, perform roundrobin FCF failover
1001 * due to new FCF discovery
1003 if ((phba->hba_flag & HBA_FIP_SUPPORT) &&
1004 (phba->fcf.fcf_flag & FCF_DISCOVERY)) {
1005 if (phba->link_state < LPFC_LINK_UP)
1006 goto stop_rr_fcf_flogi;
1007 if ((phba->fcoe_cvl_eventtag_attn ==
1008 phba->fcoe_cvl_eventtag) &&
1009 (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
1010 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1012 goto stop_rr_fcf_flogi;
1014 phba->fcoe_cvl_eventtag_attn =
1015 phba->fcoe_cvl_eventtag;
1016 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
1017 "2611 FLOGI failed on FCF (x%x), "
1018 "status:x%x/x%x, tmo:x%x, perform "
1019 "roundrobin FCF failover\n",
1020 phba->fcf.current_rec.fcf_indx,
1021 irsp->ulpStatus, irsp->un.ulpWord[4],
1023 lpfc_sli4_set_fcf_flogi_fail(phba,
1024 phba->fcf.current_rec.fcf_indx);
1025 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
1026 rc = lpfc_sli4_fcf_rr_next_proc(vport, fcf_index);
1033 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1034 "2858 FLOGI failure Status:x%x/x%x TMO:x%x "
1036 irsp->ulpStatus, irsp->un.ulpWord[4],
1037 irsp->ulpTimeout, phba->hba_flag,
1038 phba->fcf.fcf_flag);
1040 /* Check for retry */
1041 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
1045 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1046 "0100 FLOGI failure Status:x%x/x%x TMO:x%x\n",
1047 irsp->ulpStatus, irsp->un.ulpWord[4],
1050 /* FLOGI failed, so there is no fabric */
1051 spin_lock_irq(shost->host_lock);
1052 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
1053 spin_unlock_irq(shost->host_lock);
1055 /* If private loop, then allow max outstanding els to be
1056 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
1057 * alpa map would take too long otherwise.
1059 if (phba->alpa_map[0] == 0)
1060 vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
1061 if ((phba->sli_rev == LPFC_SLI_REV4) &&
1062 (!(vport->fc_flag & FC_VFI_REGISTERED) ||
1063 (vport->fc_prevDID != vport->fc_myDID) ||
1064 phba->fc_topology_changed)) {
1065 if (vport->fc_flag & FC_VFI_REGISTERED) {
1066 if (phba->fc_topology_changed) {
1067 lpfc_unregister_fcf_prep(phba);
1068 spin_lock_irq(shost->host_lock);
1069 vport->fc_flag &= ~FC_VFI_REGISTERED;
1070 spin_unlock_irq(shost->host_lock);
1071 phba->fc_topology_changed = 0;
1073 lpfc_sli4_unreg_all_rpis(vport);
1077 /* Do not register VFI if the driver aborted FLOGI */
1078 if (!lpfc_error_lost_link(irsp))
1079 lpfc_issue_reg_vfi(vport);
1085 spin_lock_irq(shost->host_lock);
1086 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
1087 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
1088 spin_unlock_irq(shost->host_lock);
1091 * The FLogI succeeded. Sync the data for the CPU before
1094 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
1097 sp = prsp->virt + sizeof(uint32_t);
1099 /* FLOGI completes successfully */
1100 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1101 "0101 FLOGI completes successfully, I/O tag:x%x, "
1102 "Data: x%x x%x x%x x%x x%x x%x\n", cmdiocb->iotag,
1103 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
1104 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution,
1105 vport->port_state, vport->fc_flag);
1107 if (vport->port_state == LPFC_FLOGI) {
1109 * If Common Service Parameters indicate Nport
1110 * we are point to point, if Fport we are Fabric.
1113 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
1114 else if (!(phba->hba_flag & HBA_FCOE_MODE))
1115 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
1117 lpfc_printf_vlog(vport, KERN_ERR,
1119 "2831 FLOGI response with cleared Fabric "
1120 "bit fcf_index 0x%x "
1121 "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x "
1123 "%02x%02x%02x%02x%02x%02x%02x%02x\n",
1124 phba->fcf.current_rec.fcf_indx,
1125 phba->fcf.current_rec.switch_name[0],
1126 phba->fcf.current_rec.switch_name[1],
1127 phba->fcf.current_rec.switch_name[2],
1128 phba->fcf.current_rec.switch_name[3],
1129 phba->fcf.current_rec.switch_name[4],
1130 phba->fcf.current_rec.switch_name[5],
1131 phba->fcf.current_rec.switch_name[6],
1132 phba->fcf.current_rec.switch_name[7],
1133 phba->fcf.current_rec.fabric_name[0],
1134 phba->fcf.current_rec.fabric_name[1],
1135 phba->fcf.current_rec.fabric_name[2],
1136 phba->fcf.current_rec.fabric_name[3],
1137 phba->fcf.current_rec.fabric_name[4],
1138 phba->fcf.current_rec.fabric_name[5],
1139 phba->fcf.current_rec.fabric_name[6],
1140 phba->fcf.current_rec.fabric_name[7]);
1142 spin_lock_irq(&phba->hbalock);
1143 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
1144 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
1145 spin_unlock_irq(&phba->hbalock);
1149 /* Mark the FCF discovery process done */
1150 if (phba->hba_flag & HBA_FIP_SUPPORT)
1151 lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP |
1153 "2769 FLOGI to FCF (x%x) "
1154 "completed successfully\n",
1155 phba->fcf.current_rec.fcf_indx);
1156 spin_lock_irq(&phba->hbalock);
1157 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
1158 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
1159 spin_unlock_irq(&phba->hbalock);
1165 spin_lock_irq(&phba->hbalock);
1166 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
1167 spin_unlock_irq(&phba->hbalock);
1171 if (!lpfc_error_lost_link(irsp)) {
1172 /* FLOGI failed, so just use loop map to make discovery list */
1173 lpfc_disc_list_loopmap(vport);
1175 /* Start discovery */
1176 lpfc_disc_start(vport);
1177 } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
1178 (((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
1179 IOERR_SLI_ABORTED) &&
1180 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
1181 IOERR_SLI_DOWN))) &&
1182 (phba->link_state != LPFC_CLEAR_LA)) {
1183 /* If FLOGI failed enable link interrupt. */
1184 lpfc_issue_clear_la(phba, vport);
1187 lpfc_els_free_iocb(phba, cmdiocb);
1191 * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport
1192 * @vport: pointer to a host virtual N_Port data structure.
1193 * @ndlp: pointer to a node-list data structure.
1194 * @retry: number of retries to the command IOCB.
1196 * This routine issues a Fabric Login (FLOGI) Request ELS command
1197 * for a @vport. The initiator service parameters are put into the payload
1198 * of the FLOGI Request IOCB and the top-level callback function pointer
1199 * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
1200 * function field. The lpfc_issue_fabric_iocb routine is invoked to send
1201 * out FLOGI ELS command with one outstanding fabric IOCB at a time.
1203 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1204 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1205 * will be stored into the context1 field of the IOCB for the completion
1206 * callback function to the FLOGI ELS command.
1209 * 0 - successfully issued flogi iocb for @vport
1210 * 1 - failed to issue flogi iocb for @vport
1213 lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1216 struct lpfc_hba *phba = vport->phba;
1217 struct serv_parm *sp;
1219 struct lpfc_iocbq *elsiocb;
1225 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
1226 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1227 ndlp->nlp_DID, ELS_CMD_FLOGI);
1232 icmd = &elsiocb->iocb;
1233 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1235 /* For FLOGI request, remainder of payload is service parameters */
1236 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
1237 pcmd += sizeof(uint32_t);
1238 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
1239 sp = (struct serv_parm *) pcmd;
1241 /* Setup CSPs accordingly for Fabric */
1242 sp->cmn.e_d_tov = 0;
1243 sp->cmn.w2.r_a_tov = 0;
1244 sp->cmn.virtual_fabric_support = 0;
1245 sp->cls1.classValid = 0;
1246 if (sp->cmn.fcphLow < FC_PH3)
1247 sp->cmn.fcphLow = FC_PH3;
1248 if (sp->cmn.fcphHigh < FC_PH3)
1249 sp->cmn.fcphHigh = FC_PH3;
1251 if (phba->sli_rev == LPFC_SLI_REV4) {
1252 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
1253 LPFC_SLI_INTF_IF_TYPE_0) {
1254 elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1);
1255 elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1);
1256 /* FLOGI needs to be 3 for WQE FCFI */
1257 /* Set the fcfi to the fcfi we registered with */
1258 elsiocb->iocb.ulpContext = phba->fcf.fcfi;
1260 /* Can't do SLI4 class2 without support sequence coalescing */
1261 sp->cls2.classValid = 0;
1262 sp->cls2.seqDelivery = 0;
1264 /* Historical, setting sequential-delivery bit for SLI3 */
1265 sp->cls2.seqDelivery = (sp->cls2.classValid) ? 1 : 0;
1266 sp->cls3.seqDelivery = (sp->cls3.classValid) ? 1 : 0;
1267 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
1268 sp->cmn.request_multiple_Nport = 1;
1269 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
1273 sp->cmn.request_multiple_Nport = 0;
1276 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
1277 icmd->un.elsreq64.myID = 0;
1278 icmd->un.elsreq64.fl = 1;
1281 tmo = phba->fc_ratov;
1282 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
1283 lpfc_set_disctmo(vport);
1284 phba->fc_ratov = tmo;
1286 phba->fc_stat.elsXmitFLOGI++;
1287 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
1289 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1290 "Issue FLOGI: opt:x%x",
1291 phba->sli3_options, 0, 0);
1293 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
1294 if (rc == IOCB_ERROR) {
1295 lpfc_els_free_iocb(phba, elsiocb);
1302 * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs
1303 * @phba: pointer to lpfc hba data structure.
1305 * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
1306 * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
1307 * list and issues an abort IOCB commond on each outstanding IOCB that
1308 * contains a active Fabric_DID ndlp. Note that this function is to issue
1309 * the abort IOCB command on all the outstanding IOCBs, thus when this
1310 * function returns, it does not guarantee all the IOCBs are actually aborted.
1313 * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0)
1316 lpfc_els_abort_flogi(struct lpfc_hba *phba)
1318 struct lpfc_sli_ring *pring;
1319 struct lpfc_iocbq *iocb, *next_iocb;
1320 struct lpfc_nodelist *ndlp;
1323 /* Abort outstanding I/O on NPort <nlp_DID> */
1324 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
1325 "0201 Abort outstanding I/O on NPort x%x\n",
1328 pring = lpfc_phba_elsring(phba);
1331 * Check the txcmplq for an iocb that matches the nport the driver is
1334 spin_lock_irq(&phba->hbalock);
1335 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
1337 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR) {
1338 ndlp = (struct lpfc_nodelist *)(iocb->context1);
1339 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
1340 (ndlp->nlp_DID == Fabric_DID))
1341 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
1344 spin_unlock_irq(&phba->hbalock);
1350 * lpfc_initial_flogi - Issue an initial fabric login for a vport
1351 * @vport: pointer to a host virtual N_Port data structure.
1353 * This routine issues an initial Fabric Login (FLOGI) for the @vport
1354 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1355 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1356 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1357 * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
1358 * is then invoked with the @vport and the ndlp to perform the FLOGI for the
1362 * 0 - failed to issue initial flogi for @vport
1363 * 1 - successfully issued initial flogi for @vport
1366 lpfc_initial_flogi(struct lpfc_vport *vport)
1368 struct lpfc_nodelist *ndlp;
1370 vport->port_state = LPFC_FLOGI;
1371 lpfc_set_disctmo(vport);
1373 /* First look for the Fabric ndlp */
1374 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1376 /* Cannot find existing Fabric ndlp, so allocate a new one */
1377 ndlp = lpfc_nlp_init(vport, Fabric_DID);
1380 /* Set the node type */
1381 ndlp->nlp_type |= NLP_FABRIC;
1382 /* Put ndlp onto node list */
1383 lpfc_enqueue_node(vport, ndlp);
1384 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1385 /* re-setup ndlp without removing from node list */
1386 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1391 if (lpfc_issue_els_flogi(vport, ndlp, 0)) {
1392 /* This decrement of reference count to node shall kick off
1393 * the release of the node.
1402 * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport
1403 * @vport: pointer to a host virtual N_Port data structure.
1405 * This routine issues an initial Fabric Discover (FDISC) for the @vport
1406 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1407 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1408 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1409 * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
1410 * is then invoked with the @vport and the ndlp to perform the FDISC for the
1414 * 0 - failed to issue initial fdisc for @vport
1415 * 1 - successfully issued initial fdisc for @vport
1418 lpfc_initial_fdisc(struct lpfc_vport *vport)
1420 struct lpfc_nodelist *ndlp;
1422 /* First look for the Fabric ndlp */
1423 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1425 /* Cannot find existing Fabric ndlp, so allocate a new one */
1426 ndlp = lpfc_nlp_init(vport, Fabric_DID);
1429 /* Put ndlp onto node list */
1430 lpfc_enqueue_node(vport, ndlp);
1431 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1432 /* re-setup ndlp without removing from node list */
1433 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1438 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
1439 /* decrement node reference count to trigger the release of
1449 * lpfc_more_plogi - Check and issue remaining plogis for a vport
1450 * @vport: pointer to a host virtual N_Port data structure.
1452 * This routine checks whether there are more remaining Port Logins
1453 * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
1454 * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
1455 * to issue ELS PLOGIs up to the configured discover threads with the
1456 * @vport (@vport->cfg_discovery_threads). The function also decrement
1457 * the @vport's num_disc_node by 1 if it is not already 0.
1460 lpfc_more_plogi(struct lpfc_vport *vport)
1462 if (vport->num_disc_nodes)
1463 vport->num_disc_nodes--;
1465 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
1466 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1467 "0232 Continue discovery with %d PLOGIs to go "
1468 "Data: x%x x%x x%x\n",
1469 vport->num_disc_nodes, vport->fc_plogi_cnt,
1470 vport->fc_flag, vport->port_state);
1471 /* Check to see if there are more PLOGIs to be sent */
1472 if (vport->fc_flag & FC_NLP_MORE)
1473 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
1474 lpfc_els_disc_plogi(vport);
1480 * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp
1481 * @phba: pointer to lpfc hba data structure.
1482 * @prsp: pointer to response IOCB payload.
1483 * @ndlp: pointer to a node-list data structure.
1485 * This routine checks and indicates whether the WWPN of an N_Port, retrieved
1486 * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
1487 * The following cases are considered N_Port confirmed:
1488 * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
1489 * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
1490 * it does not have WWPN assigned either. If the WWPN is confirmed, the
1491 * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
1492 * 1) if there is a node on vport list other than the @ndlp with the same
1493 * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
1494 * on that node to release the RPI associated with the node; 2) if there is
1495 * no node found on vport list with the same WWPN of the N_Port PLOGI logged
1496 * into, a new node shall be allocated (or activated). In either case, the
1497 * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
1498 * be released and the new_ndlp shall be put on to the vport node list and
1499 * its pointer returned as the confirmed node.
1501 * Note that before the @ndlp got "released", the keepDID from not-matching
1502 * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
1503 * of the @ndlp. This is because the release of @ndlp is actually to put it
1504 * into an inactive state on the vport node list and the vport node list
1505 * management algorithm does not allow two node with a same DID.
1508 * pointer to the PLOGI N_Port @ndlp
1510 static struct lpfc_nodelist *
1511 lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
1512 struct lpfc_nodelist *ndlp)
1514 struct lpfc_vport *vport = ndlp->vport;
1515 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1516 struct lpfc_nodelist *new_ndlp;
1517 struct lpfc_rport_data *rdata;
1518 struct fc_rport *rport;
1519 struct serv_parm *sp;
1520 uint8_t name[sizeof(struct lpfc_name)];
1521 uint32_t rc, keepDID = 0, keep_nlp_flag = 0;
1522 uint16_t keep_nlp_state;
1525 unsigned long *active_rrqs_xri_bitmap = NULL;
1527 /* Fabric nodes can have the same WWPN so we don't bother searching
1528 * by WWPN. Just return the ndlp that was given to us.
1530 if (ndlp->nlp_type & NLP_FABRIC)
1533 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
1534 memset(name, 0, sizeof(struct lpfc_name));
1536 /* Now we find out if the NPort we are logging into, matches the WWPN
1537 * we have for that ndlp. If not, we have some work to do.
1539 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
1541 if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp))
1543 if (phba->sli_rev == LPFC_SLI_REV4) {
1544 active_rrqs_xri_bitmap = mempool_alloc(phba->active_rrq_pool,
1546 if (active_rrqs_xri_bitmap)
1547 memset(active_rrqs_xri_bitmap, 0,
1548 phba->cfg_rrq_xri_bitmap_sz);
1551 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1552 "3178 PLOGI confirm: ndlp %p x%x: new_ndlp %p\n",
1553 ndlp, ndlp->nlp_DID, new_ndlp);
1556 rc = memcmp(&ndlp->nlp_portname, name,
1557 sizeof(struct lpfc_name));
1559 if (active_rrqs_xri_bitmap)
1560 mempool_free(active_rrqs_xri_bitmap,
1561 phba->active_rrq_pool);
1564 new_ndlp = lpfc_nlp_init(vport, ndlp->nlp_DID);
1566 if (active_rrqs_xri_bitmap)
1567 mempool_free(active_rrqs_xri_bitmap,
1568 phba->active_rrq_pool);
1571 } else if (!NLP_CHK_NODE_ACT(new_ndlp)) {
1572 rc = memcmp(&ndlp->nlp_portname, name,
1573 sizeof(struct lpfc_name));
1575 if (active_rrqs_xri_bitmap)
1576 mempool_free(active_rrqs_xri_bitmap,
1577 phba->active_rrq_pool);
1580 new_ndlp = lpfc_enable_node(vport, new_ndlp,
1581 NLP_STE_UNUSED_NODE);
1583 if (active_rrqs_xri_bitmap)
1584 mempool_free(active_rrqs_xri_bitmap,
1585 phba->active_rrq_pool);
1588 keepDID = new_ndlp->nlp_DID;
1589 if ((phba->sli_rev == LPFC_SLI_REV4) && active_rrqs_xri_bitmap)
1590 memcpy(active_rrqs_xri_bitmap,
1591 new_ndlp->active_rrqs_xri_bitmap,
1592 phba->cfg_rrq_xri_bitmap_sz);
1594 keepDID = new_ndlp->nlp_DID;
1595 if (phba->sli_rev == LPFC_SLI_REV4 &&
1596 active_rrqs_xri_bitmap)
1597 memcpy(active_rrqs_xri_bitmap,
1598 new_ndlp->active_rrqs_xri_bitmap,
1599 phba->cfg_rrq_xri_bitmap_sz);
1602 lpfc_unreg_rpi(vport, new_ndlp);
1603 new_ndlp->nlp_DID = ndlp->nlp_DID;
1604 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
1605 if (phba->sli_rev == LPFC_SLI_REV4)
1606 memcpy(new_ndlp->active_rrqs_xri_bitmap,
1607 ndlp->active_rrqs_xri_bitmap,
1608 phba->cfg_rrq_xri_bitmap_sz);
1610 spin_lock_irq(shost->host_lock);
1611 keep_nlp_flag = new_ndlp->nlp_flag;
1612 new_ndlp->nlp_flag = ndlp->nlp_flag;
1613 ndlp->nlp_flag = keep_nlp_flag;
1614 spin_unlock_irq(shost->host_lock);
1616 /* Set nlp_states accordingly */
1617 keep_nlp_state = new_ndlp->nlp_state;
1618 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
1620 /* Move this back to NPR state */
1621 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
1622 /* The new_ndlp is replacing ndlp totally, so we need
1623 * to put ndlp on UNUSED list and try to free it.
1625 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1626 "3179 PLOGI confirm NEW: %x %x\n",
1627 new_ndlp->nlp_DID, keepDID);
1629 /* Fix up the rport accordingly */
1630 rport = ndlp->rport;
1632 rdata = rport->dd_data;
1633 if (rdata->pnode == ndlp) {
1634 /* break the link before dropping the ref */
1637 rdata->pnode = lpfc_nlp_get(new_ndlp);
1638 new_ndlp->rport = rport;
1640 new_ndlp->nlp_type = ndlp->nlp_type;
1642 /* We shall actually free the ndlp with both nlp_DID and
1643 * nlp_portname fields equals 0 to avoid any ndlp on the
1644 * nodelist never to be used.
1646 if (ndlp->nlp_DID == 0) {
1647 spin_lock_irq(&phba->ndlp_lock);
1648 NLP_SET_FREE_REQ(ndlp);
1649 spin_unlock_irq(&phba->ndlp_lock);
1652 /* Two ndlps cannot have the same did on the nodelist */
1653 ndlp->nlp_DID = keepDID;
1654 if (phba->sli_rev == LPFC_SLI_REV4 &&
1655 active_rrqs_xri_bitmap)
1656 memcpy(ndlp->active_rrqs_xri_bitmap,
1657 active_rrqs_xri_bitmap,
1658 phba->cfg_rrq_xri_bitmap_sz);
1660 if (!NLP_CHK_NODE_ACT(ndlp))
1661 lpfc_drop_node(vport, ndlp);
1664 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1665 "3180 PLOGI confirm SWAP: %x %x\n",
1666 new_ndlp->nlp_DID, keepDID);
1668 lpfc_unreg_rpi(vport, ndlp);
1670 /* Two ndlps cannot have the same did */
1671 ndlp->nlp_DID = keepDID;
1672 if (phba->sli_rev == LPFC_SLI_REV4 &&
1673 active_rrqs_xri_bitmap)
1674 memcpy(ndlp->active_rrqs_xri_bitmap,
1675 active_rrqs_xri_bitmap,
1676 phba->cfg_rrq_xri_bitmap_sz);
1678 /* Since we are switching over to the new_ndlp,
1679 * reset the old ndlp state
1681 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
1682 (ndlp->nlp_state == NLP_STE_MAPPED_NODE))
1683 keep_nlp_state = NLP_STE_NPR_NODE;
1684 lpfc_nlp_set_state(vport, ndlp, keep_nlp_state);
1686 /* Fix up the rport accordingly */
1687 rport = ndlp->rport;
1689 rdata = rport->dd_data;
1690 put_node = rdata->pnode != NULL;
1691 put_rport = ndlp->rport != NULL;
1692 rdata->pnode = NULL;
1697 put_device(&rport->dev);
1700 if (phba->sli_rev == LPFC_SLI_REV4 &&
1701 active_rrqs_xri_bitmap)
1702 mempool_free(active_rrqs_xri_bitmap,
1703 phba->active_rrq_pool);
1708 * lpfc_end_rscn - Check and handle more rscn for a vport
1709 * @vport: pointer to a host virtual N_Port data structure.
1711 * This routine checks whether more Registration State Change
1712 * Notifications (RSCNs) came in while the discovery state machine was in
1713 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1714 * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1715 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1716 * handling the RSCNs.
1719 lpfc_end_rscn(struct lpfc_vport *vport)
1721 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1723 if (vport->fc_flag & FC_RSCN_MODE) {
1725 * Check to see if more RSCNs came in while we were
1726 * processing this one.
1728 if (vport->fc_rscn_id_cnt ||
1729 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
1730 lpfc_els_handle_rscn(vport);
1732 spin_lock_irq(shost->host_lock);
1733 vport->fc_flag &= ~FC_RSCN_MODE;
1734 spin_unlock_irq(shost->host_lock);
1740 * lpfc_cmpl_els_rrq - Completion handled for els RRQs.
1741 * @phba: pointer to lpfc hba data structure.
1742 * @cmdiocb: pointer to lpfc command iocb data structure.
1743 * @rspiocb: pointer to lpfc response iocb data structure.
1745 * This routine will call the clear rrq function to free the rrq and
1746 * clear the xri's bit in the ndlp's xri_bitmap. If the ndlp does not
1747 * exist then the clear_rrq is still called because the rrq needs to
1752 lpfc_cmpl_els_rrq(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1753 struct lpfc_iocbq *rspiocb)
1755 struct lpfc_vport *vport = cmdiocb->vport;
1757 struct lpfc_nodelist *ndlp;
1758 struct lpfc_node_rrq *rrq;
1760 /* we pass cmdiocb to state machine which needs rspiocb as well */
1761 rrq = cmdiocb->context_un.rrq;
1762 cmdiocb->context_un.rsp_iocb = rspiocb;
1764 irsp = &rspiocb->iocb;
1765 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1766 "RRQ cmpl: status:x%x/x%x did:x%x",
1767 irsp->ulpStatus, irsp->un.ulpWord[4],
1768 irsp->un.elsreq64.remoteID);
1770 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
1771 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || ndlp != rrq->ndlp) {
1772 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1773 "2882 RRQ completes to NPort x%x "
1774 "with no ndlp. Data: x%x x%x x%x\n",
1775 irsp->un.elsreq64.remoteID,
1776 irsp->ulpStatus, irsp->un.ulpWord[4],
1781 /* rrq completes to NPort <nlp_DID> */
1782 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1783 "2880 RRQ completes to NPort x%x "
1784 "Data: x%x x%x x%x x%x x%x\n",
1785 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1786 irsp->ulpTimeout, rrq->xritag, rrq->rxid);
1788 if (irsp->ulpStatus) {
1789 /* Check for retry */
1790 /* RRQ failed Don't print the vport to vport rjts */
1791 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1792 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1793 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1794 (phba)->pport->cfg_log_verbose & LOG_ELS)
1795 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1796 "2881 RRQ failure DID:%06X Status:x%x/x%x\n",
1797 ndlp->nlp_DID, irsp->ulpStatus,
1798 irsp->un.ulpWord[4]);
1802 lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
1803 lpfc_els_free_iocb(phba, cmdiocb);
1807 * lpfc_cmpl_els_plogi - Completion callback function for plogi
1808 * @phba: pointer to lpfc hba data structure.
1809 * @cmdiocb: pointer to lpfc command iocb data structure.
1810 * @rspiocb: pointer to lpfc response iocb data structure.
1812 * This routine is the completion callback function for issuing the Port
1813 * Login (PLOGI) command. For PLOGI completion, there must be an active
1814 * ndlp on the vport node list that matches the remote node ID from the
1815 * PLOGI response IOCB. If such ndlp does not exist, the PLOGI is simply
1816 * ignored and command IOCB released. The PLOGI response IOCB status is
1817 * checked for error conditons. If there is error status reported, PLOGI
1818 * retry shall be attempted by invoking the lpfc_els_retry() routine.
1819 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1820 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1821 * (DSM) is set for this PLOGI completion. Finally, it checks whether
1822 * there are additional N_Port nodes with the vport that need to perform
1823 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
1827 lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1828 struct lpfc_iocbq *rspiocb)
1830 struct lpfc_vport *vport = cmdiocb->vport;
1831 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1833 struct lpfc_nodelist *ndlp;
1834 struct lpfc_dmabuf *prsp;
1837 /* we pass cmdiocb to state machine which needs rspiocb as well */
1838 cmdiocb->context_un.rsp_iocb = rspiocb;
1840 irsp = &rspiocb->iocb;
1841 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1842 "PLOGI cmpl: status:x%x/x%x did:x%x",
1843 irsp->ulpStatus, irsp->un.ulpWord[4],
1844 irsp->un.elsreq64.remoteID);
1846 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
1847 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
1848 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1849 "0136 PLOGI completes to NPort x%x "
1850 "with no ndlp. Data: x%x x%x x%x\n",
1851 irsp->un.elsreq64.remoteID,
1852 irsp->ulpStatus, irsp->un.ulpWord[4],
1857 /* Since ndlp can be freed in the disc state machine, note if this node
1858 * is being used during discovery.
1860 spin_lock_irq(shost->host_lock);
1861 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
1862 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1863 spin_unlock_irq(shost->host_lock);
1866 /* PLOGI completes to NPort <nlp_DID> */
1867 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1868 "0102 PLOGI completes to NPort x%06x "
1869 "Data: x%x x%x x%x x%x x%x\n",
1870 ndlp->nlp_DID, ndlp->nlp_fc4_type,
1871 irsp->ulpStatus, irsp->un.ulpWord[4],
1872 disc, vport->num_disc_nodes);
1874 /* Check to see if link went down during discovery */
1875 if (lpfc_els_chk_latt(vport)) {
1876 spin_lock_irq(shost->host_lock);
1877 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1878 spin_unlock_irq(shost->host_lock);
1882 if (irsp->ulpStatus) {
1883 /* Check for retry */
1884 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1885 /* ELS command is being retried */
1887 spin_lock_irq(shost->host_lock);
1888 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1889 spin_unlock_irq(shost->host_lock);
1893 /* PLOGI failed Don't print the vport to vport rjts */
1894 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1895 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1896 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1897 (phba)->pport->cfg_log_verbose & LOG_ELS)
1898 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1899 "2753 PLOGI failure DID:%06X Status:x%x/x%x\n",
1900 ndlp->nlp_DID, irsp->ulpStatus,
1901 irsp->un.ulpWord[4]);
1902 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1903 if (lpfc_error_lost_link(irsp))
1904 rc = NLP_STE_FREED_NODE;
1906 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1907 NLP_EVT_CMPL_PLOGI);
1909 /* Good status, call state machine */
1910 prsp = list_entry(((struct lpfc_dmabuf *)
1911 cmdiocb->context2)->list.next,
1912 struct lpfc_dmabuf, list);
1913 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
1914 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1915 NLP_EVT_CMPL_PLOGI);
1918 if (disc && vport->num_disc_nodes) {
1919 /* Check to see if there are more PLOGIs to be sent */
1920 lpfc_more_plogi(vport);
1922 if (vport->num_disc_nodes == 0) {
1923 spin_lock_irq(shost->host_lock);
1924 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1925 spin_unlock_irq(shost->host_lock);
1927 lpfc_can_disctmo(vport);
1928 lpfc_end_rscn(vport);
1933 lpfc_els_free_iocb(phba, cmdiocb);
1938 * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
1939 * @vport: pointer to a host virtual N_Port data structure.
1940 * @did: destination port identifier.
1941 * @retry: number of retries to the command IOCB.
1943 * This routine issues a Port Login (PLOGI) command to a remote N_Port
1944 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
1945 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
1946 * This routine constructs the proper feilds of the PLOGI IOCB and invokes
1947 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
1949 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1950 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1951 * will be stored into the context1 field of the IOCB for the completion
1952 * callback function to the PLOGI ELS command.
1955 * 0 - Successfully issued a plogi for @vport
1956 * 1 - failed to issue a plogi for @vport
1959 lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
1961 struct lpfc_hba *phba = vport->phba;
1962 struct serv_parm *sp;
1963 struct lpfc_nodelist *ndlp;
1964 struct lpfc_iocbq *elsiocb;
1969 ndlp = lpfc_findnode_did(vport, did);
1970 if (ndlp && !NLP_CHK_NODE_ACT(ndlp))
1973 /* If ndlp is not NULL, we will bump the reference count on it */
1974 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
1975 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
1980 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1982 /* For PLOGI request, remainder of payload is service parameters */
1983 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
1984 pcmd += sizeof(uint32_t);
1985 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
1986 sp = (struct serv_parm *) pcmd;
1989 * If we are a N-port connected to a Fabric, fix-up paramm's so logins
1990 * to device on remote loops work.
1992 if ((vport->fc_flag & FC_FABRIC) && !(vport->fc_flag & FC_PUBLIC_LOOP))
1993 sp->cmn.altBbCredit = 1;
1995 if (sp->cmn.fcphLow < FC_PH_4_3)
1996 sp->cmn.fcphLow = FC_PH_4_3;
1998 if (sp->cmn.fcphHigh < FC_PH3)
1999 sp->cmn.fcphHigh = FC_PH3;
2001 sp->cmn.valid_vendor_ver_level = 0;
2002 memset(sp->un.vendorVersion, 0, sizeof(sp->un.vendorVersion));
2004 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2005 "Issue PLOGI: did:x%x",
2008 /* If our firmware supports this feature, convey that
2009 * information to the target using the vendor specific field.
2011 if (phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) {
2012 sp->cmn.valid_vendor_ver_level = 1;
2013 sp->un.vv.vid = cpu_to_be32(LPFC_VV_EMLX_ID);
2014 sp->un.vv.flags = cpu_to_be32(LPFC_VV_SUPPRESS_RSP);
2017 phba->fc_stat.elsXmitPLOGI++;
2018 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
2019 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
2021 if (ret == IOCB_ERROR) {
2022 lpfc_els_free_iocb(phba, elsiocb);
2029 * lpfc_cmpl_els_prli - Completion callback function for prli
2030 * @phba: pointer to lpfc hba data structure.
2031 * @cmdiocb: pointer to lpfc command iocb data structure.
2032 * @rspiocb: pointer to lpfc response iocb data structure.
2034 * This routine is the completion callback function for a Process Login
2035 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
2036 * status. If there is error status reported, PRLI retry shall be attempted
2037 * by invoking the lpfc_els_retry() routine. Otherwise, the state
2038 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
2039 * ndlp to mark the PRLI completion.
2042 lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2043 struct lpfc_iocbq *rspiocb)
2045 struct lpfc_vport *vport = cmdiocb->vport;
2046 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2048 struct lpfc_nodelist *ndlp;
2050 /* we pass cmdiocb to state machine which needs rspiocb as well */
2051 cmdiocb->context_un.rsp_iocb = rspiocb;
2053 irsp = &(rspiocb->iocb);
2054 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2055 spin_lock_irq(shost->host_lock);
2056 ndlp->nlp_flag &= ~NLP_PRLI_SND;
2057 spin_unlock_irq(shost->host_lock);
2059 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2060 "PRLI cmpl: status:x%x/x%x did:x%x",
2061 irsp->ulpStatus, irsp->un.ulpWord[4],
2064 /* Ddriver supports multiple FC4 types. Counters matter. */
2065 vport->fc_prli_sent--;
2067 /* PRLI completes to NPort <nlp_DID> */
2068 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2069 "0103 PRLI completes to NPort x%06x "
2070 "Data: x%x x%x x%x x%x\n",
2071 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2072 vport->num_disc_nodes, ndlp->fc4_prli_sent);
2074 /* Check to see if link went down during discovery */
2075 if (lpfc_els_chk_latt(vport))
2078 if (irsp->ulpStatus) {
2079 /* Check for retry */
2080 ndlp->fc4_prli_sent--;
2081 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2082 /* ELS command is being retried */
2087 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2088 "2754 PRLI failure DID:%06X Status:x%x/x%x, "
2090 ndlp->nlp_DID, irsp->ulpStatus,
2091 irsp->un.ulpWord[4], ndlp->fc4_prli_sent);
2093 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2094 if (lpfc_error_lost_link(irsp))
2097 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2100 /* Good status, call state machine. However, if another
2101 * PRLI is outstanding, don't call the state machine
2102 * because final disposition to Mapped or Unmapped is
2105 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2109 lpfc_els_free_iocb(phba, cmdiocb);
2114 * lpfc_issue_els_prli - Issue a prli iocb command for a vport
2115 * @vport: pointer to a host virtual N_Port data structure.
2116 * @ndlp: pointer to a node-list data structure.
2117 * @retry: number of retries to the command IOCB.
2119 * This routine issues a Process Login (PRLI) ELS command for the
2120 * @vport. The PRLI service parameters are set up in the payload of the
2121 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
2122 * is put to the IOCB completion callback func field before invoking the
2123 * routine lpfc_sli_issue_iocb() to send out PRLI command.
2125 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2126 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2127 * will be stored into the context1 field of the IOCB for the completion
2128 * callback function to the PRLI ELS command.
2131 * 0 - successfully issued prli iocb command for @vport
2132 * 1 - failed to issue prli iocb command for @vport
2135 lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2138 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2139 struct lpfc_hba *phba = vport->phba;
2141 struct lpfc_nvme_prli *npr_nvme;
2142 struct lpfc_iocbq *elsiocb;
2145 u32 local_nlp_type, elscmd;
2147 local_nlp_type = ndlp->nlp_fc4_type;
2150 if (local_nlp_type & NLP_FC4_FCP) {
2151 /* Payload is 4 + 16 = 20 x14 bytes. */
2152 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
2153 elscmd = ELS_CMD_PRLI;
2154 } else if (local_nlp_type & NLP_FC4_NVME) {
2155 /* Payload is 4 + 20 = 24 x18 bytes. */
2156 cmdsize = (sizeof(uint32_t) + sizeof(struct lpfc_nvme_prli));
2157 elscmd = ELS_CMD_NVMEPRLI;
2159 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2160 "3083 Unknown FC_TYPE x%x ndlp x%06x\n",
2161 ndlp->nlp_fc4_type, ndlp->nlp_DID);
2164 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2165 ndlp->nlp_DID, elscmd);
2169 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2171 /* For PRLI request, remainder of payload is service parameters */
2172 memset(pcmd, 0, cmdsize);
2174 if (local_nlp_type & NLP_FC4_FCP) {
2175 /* Remainder of payload is FCP PRLI parameter page.
2176 * Note: this data structure is defined as
2177 * BE/LE in the structure definition so no
2178 * byte swap call is made.
2180 *((uint32_t *)(pcmd)) = ELS_CMD_PRLI;
2181 pcmd += sizeof(uint32_t);
2185 * If our firmware version is 3.20 or later,
2186 * set the following bits for FC-TAPE support.
2188 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
2189 npr->ConfmComplAllowed = 1;
2191 npr->TaskRetryIdReq = 1;
2193 npr->estabImagePair = 1;
2194 npr->readXferRdyDis = 1;
2195 if (vport->cfg_first_burst_size)
2196 npr->writeXferRdyDis = 1;
2198 /* For FCP support */
2199 npr->prliType = PRLI_FCP_TYPE;
2200 npr->initiatorFunc = 1;
2201 elsiocb->iocb_flag |= LPFC_PRLI_FCP_REQ;
2203 /* Remove FCP type - processed. */
2204 local_nlp_type &= ~NLP_FC4_FCP;
2205 } else if (local_nlp_type & NLP_FC4_NVME) {
2206 /* Remainder of payload is NVME PRLI parameter page.
2207 * This data structure is the newer definition that
2208 * uses bf macros so a byte swap is required.
2210 *((uint32_t *)(pcmd)) = ELS_CMD_NVMEPRLI;
2211 pcmd += sizeof(uint32_t);
2212 npr_nvme = (struct lpfc_nvme_prli *)pcmd;
2213 bf_set(prli_type_code, npr_nvme, PRLI_NVME_TYPE);
2214 bf_set(prli_estabImagePair, npr_nvme, 0); /* Should be 0 */
2216 /* Only initiators request first burst. */
2217 if ((phba->cfg_nvme_enable_fb) &&
2218 !phba->nvmet_support)
2219 bf_set(prli_fba, npr_nvme, 1);
2221 if (phba->nvmet_support) {
2222 bf_set(prli_tgt, npr_nvme, 1);
2223 bf_set(prli_disc, npr_nvme, 1);
2226 bf_set(prli_init, npr_nvme, 1);
2228 npr_nvme->word1 = cpu_to_be32(npr_nvme->word1);
2229 npr_nvme->word4 = cpu_to_be32(npr_nvme->word4);
2230 elsiocb->iocb_flag |= LPFC_PRLI_NVME_REQ;
2232 /* Remove NVME type - processed. */
2233 local_nlp_type &= ~NLP_FC4_NVME;
2236 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2237 "Issue PRLI: did:x%x",
2238 ndlp->nlp_DID, 0, 0);
2240 phba->fc_stat.elsXmitPRLI++;
2241 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
2242 spin_lock_irq(shost->host_lock);
2243 ndlp->nlp_flag |= NLP_PRLI_SND;
2244 spin_unlock_irq(shost->host_lock);
2245 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2247 spin_lock_irq(shost->host_lock);
2248 ndlp->nlp_flag &= ~NLP_PRLI_SND;
2249 spin_unlock_irq(shost->host_lock);
2250 lpfc_els_free_iocb(phba, elsiocb);
2254 /* The vport counters are used for lpfc_scan_finished, but
2255 * the ndlp is used to track outstanding PRLIs for different
2258 vport->fc_prli_sent++;
2259 ndlp->fc4_prli_sent++;
2261 /* The driver supports 2 FC4 types. Make sure
2262 * a PRLI is issued for all types before exiting.
2264 if (local_nlp_type & (NLP_FC4_FCP | NLP_FC4_NVME))
2265 goto send_next_prli;
2271 * lpfc_rscn_disc - Perform rscn discovery for a vport
2272 * @vport: pointer to a host virtual N_Port data structure.
2274 * This routine performs Registration State Change Notification (RSCN)
2275 * discovery for a @vport. If the @vport's node port recovery count is not
2276 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
2277 * the nodes that need recovery. If none of the PLOGI were needed through
2278 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
2279 * invoked to check and handle possible more RSCN came in during the period
2280 * of processing the current ones.
2283 lpfc_rscn_disc(struct lpfc_vport *vport)
2285 lpfc_can_disctmo(vport);
2287 /* RSCN discovery */
2288 /* go thru NPR nodes and issue ELS PLOGIs */
2289 if (vport->fc_npr_cnt)
2290 if (lpfc_els_disc_plogi(vport))
2293 lpfc_end_rscn(vport);
2297 * lpfc_adisc_done - Complete the adisc phase of discovery
2298 * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
2300 * This function is called when the final ADISC is completed during discovery.
2301 * This function handles clearing link attention or issuing reg_vpi depending
2302 * on whether npiv is enabled. This function also kicks off the PLOGI phase of
2304 * This function is called with no locks held.
2307 lpfc_adisc_done(struct lpfc_vport *vport)
2309 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2310 struct lpfc_hba *phba = vport->phba;
2313 * For NPIV, cmpl_reg_vpi will set port_state to READY,
2314 * and continue discovery.
2316 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2317 !(vport->fc_flag & FC_RSCN_MODE) &&
2318 (phba->sli_rev < LPFC_SLI_REV4)) {
2319 /* The ADISCs are complete. Doesn't matter if they
2320 * succeeded or failed because the ADISC completion
2321 * routine guarantees to call the state machine and
2322 * the RPI is either unregistered (failed ADISC response)
2323 * or the RPI is still valid and the node is marked
2324 * mapped for a target. The exchanges should be in the
2325 * correct state. This code is specific to SLI3.
2327 lpfc_issue_clear_la(phba, vport);
2328 lpfc_issue_reg_vpi(phba, vport);
2332 * For SLI2, we need to set port_state to READY
2333 * and continue discovery.
2335 if (vport->port_state < LPFC_VPORT_READY) {
2336 /* If we get here, there is nothing to ADISC */
2337 lpfc_issue_clear_la(phba, vport);
2338 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
2339 vport->num_disc_nodes = 0;
2340 /* go thru NPR list, issue ELS PLOGIs */
2341 if (vport->fc_npr_cnt)
2342 lpfc_els_disc_plogi(vport);
2343 if (!vport->num_disc_nodes) {
2344 spin_lock_irq(shost->host_lock);
2345 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2346 spin_unlock_irq(shost->host_lock);
2347 lpfc_can_disctmo(vport);
2348 lpfc_end_rscn(vport);
2351 vport->port_state = LPFC_VPORT_READY;
2353 lpfc_rscn_disc(vport);
2357 * lpfc_more_adisc - Issue more adisc as needed
2358 * @vport: pointer to a host virtual N_Port data structure.
2360 * This routine determines whether there are more ndlps on a @vport
2361 * node list need to have Address Discover (ADISC) issued. If so, it will
2362 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
2363 * remaining nodes which need to have ADISC sent.
2366 lpfc_more_adisc(struct lpfc_vport *vport)
2368 if (vport->num_disc_nodes)
2369 vport->num_disc_nodes--;
2370 /* Continue discovery with <num_disc_nodes> ADISCs to go */
2371 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2372 "0210 Continue discovery with %d ADISCs to go "
2373 "Data: x%x x%x x%x\n",
2374 vport->num_disc_nodes, vport->fc_adisc_cnt,
2375 vport->fc_flag, vport->port_state);
2376 /* Check to see if there are more ADISCs to be sent */
2377 if (vport->fc_flag & FC_NLP_MORE) {
2378 lpfc_set_disctmo(vport);
2379 /* go thru NPR nodes and issue any remaining ELS ADISCs */
2380 lpfc_els_disc_adisc(vport);
2382 if (!vport->num_disc_nodes)
2383 lpfc_adisc_done(vport);
2388 * lpfc_cmpl_els_adisc - Completion callback function for adisc
2389 * @phba: pointer to lpfc hba data structure.
2390 * @cmdiocb: pointer to lpfc command iocb data structure.
2391 * @rspiocb: pointer to lpfc response iocb data structure.
2393 * This routine is the completion function for issuing the Address Discover
2394 * (ADISC) command. It first checks to see whether link went down during
2395 * the discovery process. If so, the node will be marked as node port
2396 * recovery for issuing discover IOCB by the link attention handler and
2397 * exit. Otherwise, the response status is checked. If error was reported
2398 * in the response status, the ADISC command shall be retried by invoking
2399 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
2400 * the response status, the state machine is invoked to set transition
2401 * with respect to NLP_EVT_CMPL_ADISC event.
2404 lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2405 struct lpfc_iocbq *rspiocb)
2407 struct lpfc_vport *vport = cmdiocb->vport;
2408 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2410 struct lpfc_nodelist *ndlp;
2413 /* we pass cmdiocb to state machine which needs rspiocb as well */
2414 cmdiocb->context_un.rsp_iocb = rspiocb;
2416 irsp = &(rspiocb->iocb);
2417 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2419 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2420 "ADISC cmpl: status:x%x/x%x did:x%x",
2421 irsp->ulpStatus, irsp->un.ulpWord[4],
2424 /* Since ndlp can be freed in the disc state machine, note if this node
2425 * is being used during discovery.
2427 spin_lock_irq(shost->host_lock);
2428 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
2429 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
2430 spin_unlock_irq(shost->host_lock);
2431 /* ADISC completes to NPort <nlp_DID> */
2432 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2433 "0104 ADISC completes to NPort x%x "
2434 "Data: x%x x%x x%x x%x x%x\n",
2435 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2436 irsp->ulpTimeout, disc, vport->num_disc_nodes);
2437 /* Check to see if link went down during discovery */
2438 if (lpfc_els_chk_latt(vport)) {
2439 spin_lock_irq(shost->host_lock);
2440 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2441 spin_unlock_irq(shost->host_lock);
2445 if (irsp->ulpStatus) {
2446 /* Check for retry */
2447 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2448 /* ELS command is being retried */
2450 spin_lock_irq(shost->host_lock);
2451 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2452 spin_unlock_irq(shost->host_lock);
2453 lpfc_set_disctmo(vport);
2458 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2459 "2755 ADISC failure DID:%06X Status:x%x/x%x\n",
2460 ndlp->nlp_DID, irsp->ulpStatus,
2461 irsp->un.ulpWord[4]);
2462 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2463 if (!lpfc_error_lost_link(irsp))
2464 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2465 NLP_EVT_CMPL_ADISC);
2467 /* Good status, call state machine */
2468 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2469 NLP_EVT_CMPL_ADISC);
2471 /* Check to see if there are more ADISCs to be sent */
2472 if (disc && vport->num_disc_nodes)
2473 lpfc_more_adisc(vport);
2475 lpfc_els_free_iocb(phba, cmdiocb);
2480 * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
2481 * @vport: pointer to a virtual N_Port data structure.
2482 * @ndlp: pointer to a node-list data structure.
2483 * @retry: number of retries to the command IOCB.
2485 * This routine issues an Address Discover (ADISC) for an @ndlp on a
2486 * @vport. It prepares the payload of the ADISC ELS command, updates the
2487 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
2488 * to issue the ADISC ELS command.
2490 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2491 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2492 * will be stored into the context1 field of the IOCB for the completion
2493 * callback function to the ADISC ELS command.
2496 * 0 - successfully issued adisc
2497 * 1 - failed to issue adisc
2500 lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2503 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2504 struct lpfc_hba *phba = vport->phba;
2506 struct lpfc_iocbq *elsiocb;
2510 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
2511 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2512 ndlp->nlp_DID, ELS_CMD_ADISC);
2516 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2518 /* For ADISC request, remainder of payload is service parameters */
2519 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
2520 pcmd += sizeof(uint32_t);
2522 /* Fill in ADISC payload */
2523 ap = (ADISC *) pcmd;
2524 ap->hardAL_PA = phba->fc_pref_ALPA;
2525 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2526 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
2527 ap->DID = be32_to_cpu(vport->fc_myDID);
2529 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2530 "Issue ADISC: did:x%x",
2531 ndlp->nlp_DID, 0, 0);
2533 phba->fc_stat.elsXmitADISC++;
2534 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
2535 spin_lock_irq(shost->host_lock);
2536 ndlp->nlp_flag |= NLP_ADISC_SND;
2537 spin_unlock_irq(shost->host_lock);
2538 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2540 spin_lock_irq(shost->host_lock);
2541 ndlp->nlp_flag &= ~NLP_ADISC_SND;
2542 spin_unlock_irq(shost->host_lock);
2543 lpfc_els_free_iocb(phba, elsiocb);
2550 * lpfc_cmpl_els_logo - Completion callback function for logo
2551 * @phba: pointer to lpfc hba data structure.
2552 * @cmdiocb: pointer to lpfc command iocb data structure.
2553 * @rspiocb: pointer to lpfc response iocb data structure.
2555 * This routine is the completion function for issuing the ELS Logout (LOGO)
2556 * command. If no error status was reported from the LOGO response, the
2557 * state machine of the associated ndlp shall be invoked for transition with
2558 * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
2559 * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
2562 lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2563 struct lpfc_iocbq *rspiocb)
2565 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2566 struct lpfc_vport *vport = ndlp->vport;
2567 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2569 struct lpfcMboxq *mbox;
2570 unsigned long flags;
2571 uint32_t skip_recovery = 0;
2573 /* we pass cmdiocb to state machine which needs rspiocb as well */
2574 cmdiocb->context_un.rsp_iocb = rspiocb;
2576 irsp = &(rspiocb->iocb);
2577 spin_lock_irq(shost->host_lock);
2578 ndlp->nlp_flag &= ~NLP_LOGO_SND;
2579 spin_unlock_irq(shost->host_lock);
2581 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2582 "LOGO cmpl: status:x%x/x%x did:x%x",
2583 irsp->ulpStatus, irsp->un.ulpWord[4],
2586 /* LOGO completes to NPort <nlp_DID> */
2587 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2588 "0105 LOGO completes to NPort x%x "
2589 "Data: x%x x%x x%x x%x\n",
2590 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2591 irsp->ulpTimeout, vport->num_disc_nodes);
2593 if (lpfc_els_chk_latt(vport)) {
2598 /* Check to see if link went down during discovery */
2599 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
2600 /* NLP_EVT_DEVICE_RM should unregister the RPI
2601 * which should abort all outstanding IOs.
2603 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2609 if (irsp->ulpStatus) {
2610 /* Check for retry */
2611 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2612 /* ELS command is being retried */
2617 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2618 "2756 LOGO failure DID:%06X Status:x%x/x%x\n",
2619 ndlp->nlp_DID, irsp->ulpStatus,
2620 irsp->un.ulpWord[4]);
2621 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2622 if (lpfc_error_lost_link(irsp)) {
2628 /* Call state machine. This will unregister the rpi if needed. */
2629 lpfc_disc_state_machine(vport, ndlp, cmdiocb, NLP_EVT_CMPL_LOGO);
2632 lpfc_els_free_iocb(phba, cmdiocb);
2633 /* If we are in pt2pt mode, we could rcv new S_ID on PLOGI */
2634 if ((vport->fc_flag & FC_PT2PT) &&
2635 !(vport->fc_flag & FC_PT2PT_PLOGI)) {
2636 phba->pport->fc_myDID = 0;
2638 if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
2639 (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
2640 if (phba->nvmet_support)
2641 lpfc_nvmet_update_targetport(phba);
2643 lpfc_nvme_update_localport(phba->pport);
2646 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2648 lpfc_config_link(phba, mbox);
2649 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
2650 mbox->vport = vport;
2651 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) ==
2653 mempool_free(mbox, phba->mbox_mem_pool);
2660 * If the node is a target, the handling attempts to recover the port.
2661 * For any other port type, the rpi is unregistered as an implicit
2664 if ((ndlp->nlp_type & NLP_FCP_TARGET) && (skip_recovery == 0)) {
2665 lpfc_cancel_retry_delay_tmo(vport, ndlp);
2666 spin_lock_irqsave(shost->host_lock, flags);
2667 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2668 spin_unlock_irqrestore(shost->host_lock, flags);
2670 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2671 "3187 LOGO completes to NPort x%x: Start "
2672 "Recovery Data: x%x x%x x%x x%x\n",
2673 ndlp->nlp_DID, irsp->ulpStatus,
2674 irsp->un.ulpWord[4], irsp->ulpTimeout,
2675 vport->num_disc_nodes);
2676 lpfc_disc_start(vport);
2682 * lpfc_issue_els_logo - Issue a logo to an node on a vport
2683 * @vport: pointer to a virtual N_Port data structure.
2684 * @ndlp: pointer to a node-list data structure.
2685 * @retry: number of retries to the command IOCB.
2687 * This routine constructs and issues an ELS Logout (LOGO) iocb command
2688 * to a remote node, referred by an @ndlp on a @vport. It constructs the
2689 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
2690 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
2692 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2693 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2694 * will be stored into the context1 field of the IOCB for the completion
2695 * callback function to the LOGO ELS command.
2698 * 0 - successfully issued logo
2699 * 1 - failed to issue logo
2702 lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2705 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2706 struct lpfc_hba *phba = vport->phba;
2707 struct lpfc_iocbq *elsiocb;
2712 spin_lock_irq(shost->host_lock);
2713 if (ndlp->nlp_flag & NLP_LOGO_SND) {
2714 spin_unlock_irq(shost->host_lock);
2717 spin_unlock_irq(shost->host_lock);
2719 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
2720 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2721 ndlp->nlp_DID, ELS_CMD_LOGO);
2725 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2726 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
2727 pcmd += sizeof(uint32_t);
2729 /* Fill in LOGO payload */
2730 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
2731 pcmd += sizeof(uint32_t);
2732 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
2734 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2735 "Issue LOGO: did:x%x",
2736 ndlp->nlp_DID, 0, 0);
2739 * If we are issuing a LOGO, we may try to recover the remote NPort
2740 * by issuing a PLOGI later. Even though we issue ELS cmds by the
2741 * VPI, if we have a valid RPI, and that RPI gets unreg'ed while
2742 * that ELS command is in-flight, the HBA returns a IOERR_INVALID_RPI
2743 * for that ELS cmd. To avoid this situation, lets get rid of the
2744 * RPI right now, before any ELS cmds are sent.
2746 spin_lock_irq(shost->host_lock);
2747 ndlp->nlp_flag |= NLP_ISSUE_LOGO;
2748 spin_unlock_irq(shost->host_lock);
2749 if (lpfc_unreg_rpi(vport, ndlp)) {
2750 lpfc_els_free_iocb(phba, elsiocb);
2754 phba->fc_stat.elsXmitLOGO++;
2755 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
2756 spin_lock_irq(shost->host_lock);
2757 ndlp->nlp_flag |= NLP_LOGO_SND;
2758 ndlp->nlp_flag &= ~NLP_ISSUE_LOGO;
2759 spin_unlock_irq(shost->host_lock);
2760 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
2762 if (rc == IOCB_ERROR) {
2763 spin_lock_irq(shost->host_lock);
2764 ndlp->nlp_flag &= ~NLP_LOGO_SND;
2765 spin_unlock_irq(shost->host_lock);
2766 lpfc_els_free_iocb(phba, elsiocb);
2773 * lpfc_cmpl_els_cmd - Completion callback function for generic els command
2774 * @phba: pointer to lpfc hba data structure.
2775 * @cmdiocb: pointer to lpfc command iocb data structure.
2776 * @rspiocb: pointer to lpfc response iocb data structure.
2778 * This routine is a generic completion callback function for ELS commands.
2779 * Specifically, it is the callback function which does not need to perform
2780 * any command specific operations. It is currently used by the ELS command
2781 * issuing routines for the ELS State Change Request (SCR),
2782 * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution
2783 * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than
2784 * certain debug loggings, this callback function simply invokes the
2785 * lpfc_els_chk_latt() routine to check whether link went down during the
2786 * discovery process.
2789 lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2790 struct lpfc_iocbq *rspiocb)
2792 struct lpfc_vport *vport = cmdiocb->vport;
2795 irsp = &rspiocb->iocb;
2797 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2798 "ELS cmd cmpl: status:x%x/x%x did:x%x",
2799 irsp->ulpStatus, irsp->un.ulpWord[4],
2800 irsp->un.elsreq64.remoteID);
2801 /* ELS cmd tag <ulpIoTag> completes */
2802 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2803 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
2804 irsp->ulpIoTag, irsp->ulpStatus,
2805 irsp->un.ulpWord[4], irsp->ulpTimeout);
2806 /* Check to see if link went down during discovery */
2807 lpfc_els_chk_latt(vport);
2808 lpfc_els_free_iocb(phba, cmdiocb);
2813 * lpfc_issue_els_scr - Issue a scr to an node on a vport
2814 * @vport: pointer to a host virtual N_Port data structure.
2815 * @nportid: N_Port identifier to the remote node.
2816 * @retry: number of retries to the command IOCB.
2818 * This routine issues a State Change Request (SCR) to a fabric node
2819 * on a @vport. The remote node @nportid is passed into the function. It
2820 * first search the @vport node list to find the matching ndlp. If no such
2821 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
2822 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
2823 * routine is invoked to send the SCR IOCB.
2825 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2826 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2827 * will be stored into the context1 field of the IOCB for the completion
2828 * callback function to the SCR ELS command.
2831 * 0 - Successfully issued scr command
2832 * 1 - Failed to issue scr command
2835 lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
2837 struct lpfc_hba *phba = vport->phba;
2838 struct lpfc_iocbq *elsiocb;
2841 struct lpfc_nodelist *ndlp;
2843 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
2845 ndlp = lpfc_findnode_did(vport, nportid);
2847 ndlp = lpfc_nlp_init(vport, nportid);
2850 lpfc_enqueue_node(vport, ndlp);
2851 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2852 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2857 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2858 ndlp->nlp_DID, ELS_CMD_SCR);
2861 /* This will trigger the release of the node just
2868 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2870 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
2871 pcmd += sizeof(uint32_t);
2873 /* For SCR, remainder of payload is SCR parameter page */
2874 memset(pcmd, 0, sizeof(SCR));
2875 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
2877 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2878 "Issue SCR: did:x%x",
2879 ndlp->nlp_DID, 0, 0);
2881 phba->fc_stat.elsXmitSCR++;
2882 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
2883 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2885 /* The additional lpfc_nlp_put will cause the following
2886 * lpfc_els_free_iocb routine to trigger the rlease of
2890 lpfc_els_free_iocb(phba, elsiocb);
2893 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2894 * trigger the release of node.
2902 * lpfc_issue_els_farpr - Issue a farp to an node on a vport
2903 * @vport: pointer to a host virtual N_Port data structure.
2904 * @nportid: N_Port identifier to the remote node.
2905 * @retry: number of retries to the command IOCB.
2907 * This routine issues a Fibre Channel Address Resolution Response
2908 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
2909 * is passed into the function. It first search the @vport node list to find
2910 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
2911 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
2912 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
2914 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2915 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2916 * will be stored into the context1 field of the IOCB for the completion
2917 * callback function to the PARPR ELS command.
2920 * 0 - Successfully issued farpr command
2921 * 1 - Failed to issue farpr command
2924 lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
2926 struct lpfc_hba *phba = vport->phba;
2927 struct lpfc_iocbq *elsiocb;
2932 struct lpfc_nodelist *ondlp;
2933 struct lpfc_nodelist *ndlp;
2935 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
2937 ndlp = lpfc_findnode_did(vport, nportid);
2939 ndlp = lpfc_nlp_init(vport, nportid);
2942 lpfc_enqueue_node(vport, ndlp);
2943 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2944 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2949 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2950 ndlp->nlp_DID, ELS_CMD_RNID);
2952 /* This will trigger the release of the node just
2959 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2961 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
2962 pcmd += sizeof(uint32_t);
2964 /* Fill in FARPR payload */
2965 fp = (FARP *) (pcmd);
2966 memset(fp, 0, sizeof(FARP));
2967 lp = (uint32_t *) pcmd;
2968 *lp++ = be32_to_cpu(nportid);
2969 *lp++ = be32_to_cpu(vport->fc_myDID);
2971 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
2973 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
2974 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
2975 ondlp = lpfc_findnode_did(vport, nportid);
2976 if (ondlp && NLP_CHK_NODE_ACT(ondlp)) {
2977 memcpy(&fp->OportName, &ondlp->nlp_portname,
2978 sizeof(struct lpfc_name));
2979 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
2980 sizeof(struct lpfc_name));
2983 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2984 "Issue FARPR: did:x%x",
2985 ndlp->nlp_DID, 0, 0);
2987 phba->fc_stat.elsXmitFARPR++;
2988 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
2989 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2991 /* The additional lpfc_nlp_put will cause the following
2992 * lpfc_els_free_iocb routine to trigger the release of
2996 lpfc_els_free_iocb(phba, elsiocb);
2999 /* This will cause the callback-function lpfc_cmpl_els_cmd to
3000 * trigger the release of the node.
3007 * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
3008 * @vport: pointer to a host virtual N_Port data structure.
3009 * @nlp: pointer to a node-list data structure.
3011 * This routine cancels the timer with a delayed IOCB-command retry for
3012 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
3013 * removes the ELS retry event if it presents. In addition, if the
3014 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
3015 * commands are sent for the @vport's nodes that require issuing discovery
3019 lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
3021 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3022 struct lpfc_work_evt *evtp;
3024 if (!(nlp->nlp_flag & NLP_DELAY_TMO))
3026 spin_lock_irq(shost->host_lock);
3027 nlp->nlp_flag &= ~NLP_DELAY_TMO;
3028 spin_unlock_irq(shost->host_lock);
3029 del_timer_sync(&nlp->nlp_delayfunc);
3030 nlp->nlp_last_elscmd = 0;
3031 if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
3032 list_del_init(&nlp->els_retry_evt.evt_listp);
3033 /* Decrement nlp reference count held for the delayed retry */
3034 evtp = &nlp->els_retry_evt;
3035 lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
3037 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
3038 spin_lock_irq(shost->host_lock);
3039 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
3040 spin_unlock_irq(shost->host_lock);
3041 if (vport->num_disc_nodes) {
3042 if (vport->port_state < LPFC_VPORT_READY) {
3043 /* Check if there are more ADISCs to be sent */
3044 lpfc_more_adisc(vport);
3046 /* Check if there are more PLOGIs to be sent */
3047 lpfc_more_plogi(vport);
3048 if (vport->num_disc_nodes == 0) {
3049 spin_lock_irq(shost->host_lock);
3050 vport->fc_flag &= ~FC_NDISC_ACTIVE;
3051 spin_unlock_irq(shost->host_lock);
3052 lpfc_can_disctmo(vport);
3053 lpfc_end_rscn(vport);
3062 * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
3063 * @ptr: holder for the pointer to the timer function associated data (ndlp).
3065 * This routine is invoked by the ndlp delayed-function timer to check
3066 * whether there is any pending ELS retry event(s) with the node. If not, it
3067 * simply returns. Otherwise, if there is at least one ELS delayed event, it
3068 * adds the delayed events to the HBA work list and invokes the
3069 * lpfc_worker_wake_up() routine to wake up worker thread to process the
3070 * event. Note that lpfc_nlp_get() is called before posting the event to
3071 * the work list to hold reference count of ndlp so that it guarantees the
3072 * reference to ndlp will still be available when the worker thread gets
3073 * to the event associated with the ndlp.
3076 lpfc_els_retry_delay(unsigned long ptr)
3078 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr;
3079 struct lpfc_vport *vport = ndlp->vport;
3080 struct lpfc_hba *phba = vport->phba;
3081 unsigned long flags;
3082 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
3084 spin_lock_irqsave(&phba->hbalock, flags);
3085 if (!list_empty(&evtp->evt_listp)) {
3086 spin_unlock_irqrestore(&phba->hbalock, flags);
3090 /* We need to hold the node by incrementing the reference
3091 * count until the queued work is done
3093 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
3094 if (evtp->evt_arg1) {
3095 evtp->evt = LPFC_EVT_ELS_RETRY;
3096 list_add_tail(&evtp->evt_listp, &phba->work_list);
3097 lpfc_worker_wake_up(phba);
3099 spin_unlock_irqrestore(&phba->hbalock, flags);
3104 * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
3105 * @ndlp: pointer to a node-list data structure.
3107 * This routine is the worker-thread handler for processing the @ndlp delayed
3108 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
3109 * the last ELS command from the associated ndlp and invokes the proper ELS
3110 * function according to the delayed ELS command to retry the command.
3113 lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
3115 struct lpfc_vport *vport = ndlp->vport;
3116 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3117 uint32_t cmd, retry;
3119 spin_lock_irq(shost->host_lock);
3120 cmd = ndlp->nlp_last_elscmd;
3121 ndlp->nlp_last_elscmd = 0;
3123 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
3124 spin_unlock_irq(shost->host_lock);
3128 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
3129 spin_unlock_irq(shost->host_lock);
3131 * If a discovery event readded nlp_delayfunc after timer
3132 * firing and before processing the timer, cancel the
3135 del_timer_sync(&ndlp->nlp_delayfunc);
3136 retry = ndlp->nlp_retry;
3137 ndlp->nlp_retry = 0;
3141 lpfc_issue_els_flogi(vport, ndlp, retry);
3144 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
3145 ndlp->nlp_prev_state = ndlp->nlp_state;
3146 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
3150 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
3151 ndlp->nlp_prev_state = ndlp->nlp_state;
3152 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
3156 case ELS_CMD_NVMEPRLI:
3157 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
3158 ndlp->nlp_prev_state = ndlp->nlp_state;
3159 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
3163 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
3164 ndlp->nlp_prev_state = ndlp->nlp_state;
3165 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
3169 if (!(vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI))
3170 lpfc_issue_els_fdisc(vport, ndlp, retry);
3177 * lpfc_els_retry - Make retry decision on an els command iocb
3178 * @phba: pointer to lpfc hba data structure.
3179 * @cmdiocb: pointer to lpfc command iocb data structure.
3180 * @rspiocb: pointer to lpfc response iocb data structure.
3182 * This routine makes a retry decision on an ELS command IOCB, which has
3183 * failed. The following ELS IOCBs use this function for retrying the command
3184 * when previously issued command responsed with error status: FLOGI, PLOGI,
3185 * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
3186 * returned error status, it makes the decision whether a retry shall be
3187 * issued for the command, and whether a retry shall be made immediately or
3188 * delayed. In the former case, the corresponding ELS command issuing-function
3189 * is called to retry the command. In the later case, the ELS command shall
3190 * be posted to the ndlp delayed event and delayed function timer set to the
3191 * ndlp for the delayed command issusing.
3194 * 0 - No retry of els command is made
3195 * 1 - Immediate or delayed retry of els command is made
3198 lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3199 struct lpfc_iocbq *rspiocb)
3201 struct lpfc_vport *vport = cmdiocb->vport;
3202 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3203 IOCB_t *irsp = &rspiocb->iocb;
3204 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3205 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3208 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
3214 /* Note: context2 may be 0 for internal driver abort
3215 * of delays ELS command.
3218 if (pcmd && pcmd->virt) {
3219 elscmd = (uint32_t *) (pcmd->virt);
3223 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
3224 did = ndlp->nlp_DID;
3226 /* We should only hit this case for retrying PLOGI */
3227 did = irsp->un.elsreq64.remoteID;
3228 ndlp = lpfc_findnode_did(vport, did);
3229 if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp))
3230 && (cmd != ELS_CMD_PLOGI))
3234 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3235 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
3236 *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
3238 switch (irsp->ulpStatus) {
3239 case IOSTAT_FCP_RSP_ERROR:
3241 case IOSTAT_REMOTE_STOP:
3242 if (phba->sli_rev == LPFC_SLI_REV4) {
3243 /* This IO was aborted by the target, we don't
3244 * know the rxid and because we did not send the
3245 * ABTS we cannot generate and RRQ.
3247 lpfc_set_rrq_active(phba, ndlp,
3248 cmdiocb->sli4_lxritag, 0, 0);
3251 case IOSTAT_LOCAL_REJECT:
3252 switch ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK)) {
3253 case IOERR_LOOP_OPEN_FAILURE:
3254 if (cmd == ELS_CMD_FLOGI) {
3255 if (PCI_DEVICE_ID_HORNET ==
3256 phba->pcidev->device) {
3257 phba->fc_topology = LPFC_TOPOLOGY_LOOP;
3258 phba->pport->fc_myDID = 0;
3259 phba->alpa_map[0] = 0;
3260 phba->alpa_map[1] = 0;
3263 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
3268 case IOERR_ILLEGAL_COMMAND:
3269 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3270 "0124 Retry illegal cmd x%x "
3271 "retry:x%x delay:x%x\n",
3272 cmd, cmdiocb->retry, delay);
3274 /* All command's retry policy */
3276 if (cmdiocb->retry > 2)
3280 case IOERR_NO_RESOURCES:
3281 logerr = 1; /* HBA out of resources */
3283 if (cmdiocb->retry > 100)
3288 case IOERR_ILLEGAL_FRAME:
3293 case IOERR_SEQUENCE_TIMEOUT:
3294 case IOERR_INVALID_RPI:
3295 if (cmd == ELS_CMD_PLOGI &&
3296 did == NameServer_DID) {
3297 /* Continue forever if plogi to */
3298 /* the nameserver fails */
3307 case IOSTAT_NPORT_RJT:
3308 case IOSTAT_FABRIC_RJT:
3309 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
3315 case IOSTAT_NPORT_BSY:
3316 case IOSTAT_FABRIC_BSY:
3317 logerr = 1; /* Fabric / Remote NPort out of resources */
3322 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
3323 /* Added for Vendor specifc support
3324 * Just keep retrying for these Rsn / Exp codes
3326 switch (stat.un.b.lsRjtRsnCode) {
3327 case LSRJT_UNABLE_TPC:
3328 if (stat.un.b.lsRjtRsnCodeExp ==
3329 LSEXP_CMD_IN_PROGRESS) {
3330 if (cmd == ELS_CMD_PLOGI) {
3337 if (stat.un.b.lsRjtRsnCodeExp ==
3338 LSEXP_CANT_GIVE_DATA) {
3339 if (cmd == ELS_CMD_PLOGI) {
3346 if ((cmd == ELS_CMD_PLOGI) ||
3347 (cmd == ELS_CMD_PRLI) ||
3348 (cmd == ELS_CMD_NVMEPRLI)) {
3350 maxretry = lpfc_max_els_tries + 1;
3354 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
3355 (cmd == ELS_CMD_FDISC) &&
3356 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
3357 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3358 "0125 FDISC Failed (x%x). "
3359 "Fabric out of resources\n",
3360 stat.un.lsRjtError);
3361 lpfc_vport_set_state(vport,
3362 FC_VPORT_NO_FABRIC_RSCS);
3366 case LSRJT_LOGICAL_BSY:
3367 if ((cmd == ELS_CMD_PLOGI) ||
3368 (cmd == ELS_CMD_PRLI) ||
3369 (cmd == ELS_CMD_NVMEPRLI)) {
3372 } else if (cmd == ELS_CMD_FDISC) {
3373 /* FDISC retry policy */
3375 if (cmdiocb->retry >= 32)
3381 case LSRJT_LOGICAL_ERR:
3382 /* There are some cases where switches return this
3383 * error when they are not ready and should be returning
3384 * Logical Busy. We should delay every time.
3386 if (cmd == ELS_CMD_FDISC &&
3387 stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
3393 case LSRJT_PROTOCOL_ERR:
3394 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
3395 (cmd == ELS_CMD_FDISC) &&
3396 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
3397 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
3399 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3400 "0122 FDISC Failed (x%x). "
3401 "Fabric Detected Bad WWN\n",
3402 stat.un.lsRjtError);
3403 lpfc_vport_set_state(vport,
3404 FC_VPORT_FABRIC_REJ_WWN);
3407 case LSRJT_VENDOR_UNIQUE:
3408 if ((stat.un.b.vendorUnique == 0x45) &&
3409 (cmd == ELS_CMD_FLOGI)) {
3416 case IOSTAT_INTERMED_RSP:
3424 if (did == FDMI_DID)
3427 if ((cmd == ELS_CMD_FLOGI) &&
3428 (phba->fc_topology != LPFC_TOPOLOGY_LOOP) &&
3429 !lpfc_error_lost_link(irsp)) {
3430 /* FLOGI retry policy */
3432 /* retry FLOGI forever */
3433 if (phba->link_flag != LS_LOOPBACK_MODE)
3438 if (cmdiocb->retry >= 100)
3440 else if (cmdiocb->retry >= 32)
3442 } else if ((cmd == ELS_CMD_FDISC) && !lpfc_error_lost_link(irsp)) {
3443 /* retry FDISCs every second up to devloss */
3445 maxretry = vport->cfg_devloss_tmo;
3450 if (maxretry && (cmdiocb->retry >= maxretry)) {
3451 phba->fc_stat.elsRetryExceeded++;
3455 if ((vport->load_flag & FC_UNLOADING) != 0)
3460 if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) {
3461 /* Stop retrying PLOGI and FDISC if in FCF discovery */
3462 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
3463 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3464 "2849 Stop retry ELS command "
3465 "x%x to remote NPORT x%x, "
3466 "Data: x%x x%x\n", cmd, did,
3467 cmdiocb->retry, delay);
3472 /* Retry ELS command <elsCmd> to remote NPORT <did> */
3473 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3474 "0107 Retry ELS command x%x to remote "
3475 "NPORT x%x Data: x%x x%x\n",
3476 cmd, did, cmdiocb->retry, delay);
3478 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
3479 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
3480 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
3481 IOERR_NO_RESOURCES))) {
3482 /* Don't reset timer for no resources */
3484 /* If discovery / RSCN timer is running, reset it */
3485 if (timer_pending(&vport->fc_disctmo) ||
3486 (vport->fc_flag & FC_RSCN_MODE))
3487 lpfc_set_disctmo(vport);
3490 phba->fc_stat.elsXmitRetry++;
3491 if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) {
3492 phba->fc_stat.elsDelayRetry++;
3493 ndlp->nlp_retry = cmdiocb->retry;
3495 /* delay is specified in milliseconds */
3496 mod_timer(&ndlp->nlp_delayfunc,
3497 jiffies + msecs_to_jiffies(delay));
3498 spin_lock_irq(shost->host_lock);
3499 ndlp->nlp_flag |= NLP_DELAY_TMO;
3500 spin_unlock_irq(shost->host_lock);
3502 ndlp->nlp_prev_state = ndlp->nlp_state;
3503 if ((cmd == ELS_CMD_PRLI) ||
3504 (cmd == ELS_CMD_NVMEPRLI))
3505 lpfc_nlp_set_state(vport, ndlp,
3506 NLP_STE_PRLI_ISSUE);
3508 lpfc_nlp_set_state(vport, ndlp,
3510 ndlp->nlp_last_elscmd = cmd;
3516 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
3519 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
3522 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
3523 ndlp->nlp_prev_state = ndlp->nlp_state;
3524 lpfc_nlp_set_state(vport, ndlp,
3525 NLP_STE_PLOGI_ISSUE);
3527 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
3530 ndlp->nlp_prev_state = ndlp->nlp_state;
3531 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
3532 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
3535 case ELS_CMD_NVMEPRLI:
3536 ndlp->nlp_prev_state = ndlp->nlp_state;
3537 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
3538 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
3541 ndlp->nlp_prev_state = ndlp->nlp_state;
3542 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
3543 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
3547 /* No retry ELS command <elsCmd> to remote NPORT <did> */
3549 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3550 "0137 No retry ELS command x%x to remote "
3551 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
3552 cmd, did, irsp->ulpStatus,
3553 irsp->un.ulpWord[4]);
3556 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3557 "0108 No retry ELS command x%x to remote "
3558 "NPORT x%x Retried:%d Error:x%x/%x\n",
3559 cmd, did, cmdiocb->retry, irsp->ulpStatus,
3560 irsp->un.ulpWord[4]);
3566 * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
3567 * @phba: pointer to lpfc hba data structure.
3568 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
3570 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
3571 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
3572 * checks to see whether there is a lpfc DMA buffer associated with the
3573 * response of the command IOCB. If so, it will be released before releasing
3574 * the lpfc DMA buffer associated with the IOCB itself.
3577 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3580 lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
3582 struct lpfc_dmabuf *buf_ptr;
3584 /* Free the response before processing the command. */
3585 if (!list_empty(&buf_ptr1->list)) {
3586 list_remove_head(&buf_ptr1->list, buf_ptr,
3589 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3592 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
3598 * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
3599 * @phba: pointer to lpfc hba data structure.
3600 * @buf_ptr: pointer to the lpfc dma buffer data structure.
3602 * This routine releases the lpfc Direct Memory Access (DMA) buffer
3603 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
3607 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3610 lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
3612 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3618 * lpfc_els_free_iocb - Free a command iocb and its associated resources
3619 * @phba: pointer to lpfc hba data structure.
3620 * @elsiocb: pointer to lpfc els command iocb data structure.
3622 * This routine frees a command IOCB and its associated resources. The
3623 * command IOCB data structure contains the reference to various associated
3624 * resources, these fields must be set to NULL if the associated reference
3626 * context1 - reference to ndlp
3627 * context2 - reference to cmd
3628 * context2->next - reference to rsp
3629 * context3 - reference to bpl
3631 * It first properly decrements the reference count held on ndlp for the
3632 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
3633 * set, it invokes the lpfc_els_free_data() routine to release the Direct
3634 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
3635 * adds the DMA buffer the @phba data structure for the delayed release.
3636 * If reference to the Buffer Pointer List (BPL) is present, the
3637 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
3638 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
3639 * invoked to release the IOCB data structure back to @phba IOCBQ list.
3642 * 0 - Success (currently, always return 0)
3645 lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
3647 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
3648 struct lpfc_nodelist *ndlp;
3650 ndlp = (struct lpfc_nodelist *)elsiocb->context1;
3652 if (ndlp->nlp_flag & NLP_DEFER_RM) {
3655 /* If the ndlp is not being used by another discovery
3658 if (!lpfc_nlp_not_used(ndlp)) {
3659 /* If ndlp is being used by another discovery
3660 * thread, just clear NLP_DEFER_RM
3662 ndlp->nlp_flag &= ~NLP_DEFER_RM;
3667 elsiocb->context1 = NULL;
3669 /* context2 = cmd, context2->next = rsp, context3 = bpl */
3670 if (elsiocb->context2) {
3671 if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
3672 /* Firmware could still be in progress of DMAing
3673 * payload, so don't free data buffer till after
3676 elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
3677 buf_ptr = elsiocb->context2;
3678 elsiocb->context2 = NULL;
3681 spin_lock_irq(&phba->hbalock);
3682 if (!list_empty(&buf_ptr->list)) {
3683 list_remove_head(&buf_ptr->list,
3684 buf_ptr1, struct lpfc_dmabuf,
3686 INIT_LIST_HEAD(&buf_ptr1->list);
3687 list_add_tail(&buf_ptr1->list,
3691 INIT_LIST_HEAD(&buf_ptr->list);
3692 list_add_tail(&buf_ptr->list, &phba->elsbuf);
3694 spin_unlock_irq(&phba->hbalock);
3697 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
3698 lpfc_els_free_data(phba, buf_ptr1);
3699 elsiocb->context2 = NULL;
3703 if (elsiocb->context3) {
3704 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
3705 lpfc_els_free_bpl(phba, buf_ptr);
3706 elsiocb->context3 = NULL;
3708 lpfc_sli_release_iocbq(phba, elsiocb);
3713 * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
3714 * @phba: pointer to lpfc hba data structure.
3715 * @cmdiocb: pointer to lpfc command iocb data structure.
3716 * @rspiocb: pointer to lpfc response iocb data structure.
3718 * This routine is the completion callback function to the Logout (LOGO)
3719 * Accept (ACC) Response ELS command. This routine is invoked to indicate
3720 * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
3721 * release the ndlp if it has the last reference remaining (reference count
3722 * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
3723 * field to NULL to inform the following lpfc_els_free_iocb() routine no
3724 * ndlp reference count needs to be decremented. Otherwise, the ndlp
3725 * reference use-count shall be decremented by the lpfc_els_free_iocb()
3726 * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
3727 * IOCB data structure.
3730 lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3731 struct lpfc_iocbq *rspiocb)
3733 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3734 struct lpfc_vport *vport = cmdiocb->vport;
3737 irsp = &rspiocb->iocb;
3738 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3739 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
3740 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
3741 /* ACC to LOGO completes to NPort <nlp_DID> */
3742 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3743 "0109 ACC to LOGO completes to NPort x%x "
3744 "Data: x%x x%x x%x\n",
3745 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3748 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
3749 /* NPort Recovery mode or node is just allocated */
3750 if (!lpfc_nlp_not_used(ndlp)) {
3751 /* If the ndlp is being used by another discovery
3752 * thread, just unregister the RPI.
3754 lpfc_unreg_rpi(vport, ndlp);
3756 /* Indicate the node has already released, should
3757 * not reference to it from within lpfc_els_free_iocb.
3759 cmdiocb->context1 = NULL;
3764 * The driver received a LOGO from the rport and has ACK'd it.
3765 * At this point, the driver is done so release the IOCB
3767 lpfc_els_free_iocb(phba, cmdiocb);
3771 * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
3772 * @phba: pointer to lpfc hba data structure.
3773 * @pmb: pointer to the driver internal queue element for mailbox command.
3775 * This routine is the completion callback function for unregister default
3776 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
3777 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
3778 * decrements the ndlp reference count held for this completion callback
3779 * function. After that, it invokes the lpfc_nlp_not_used() to check
3780 * whether there is only one reference left on the ndlp. If so, it will
3781 * perform one more decrement and trigger the release of the ndlp.
3784 lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3786 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
3787 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
3789 pmb->context1 = NULL;
3790 pmb->context2 = NULL;
3792 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3794 mempool_free(pmb, phba->mbox_mem_pool);
3796 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
3797 "0006 rpi%x DID:%x flg:%x %d map:%x %p\n",
3798 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
3799 kref_read(&ndlp->kref),
3800 ndlp->nlp_usg_map, ndlp);
3801 if (NLP_CHK_NODE_ACT(ndlp)) {
3803 /* This is the end of the default RPI cleanup logic for
3804 * this ndlp. If no other discovery threads are using
3805 * this ndlp, free all resources associated with it.
3807 lpfc_nlp_not_used(ndlp);
3809 lpfc_drop_node(ndlp->vport, ndlp);
3817 * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
3818 * @phba: pointer to lpfc hba data structure.
3819 * @cmdiocb: pointer to lpfc command iocb data structure.
3820 * @rspiocb: pointer to lpfc response iocb data structure.
3822 * This routine is the completion callback function for ELS Response IOCB
3823 * command. In normal case, this callback function just properly sets the
3824 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
3825 * field in the command IOCB is not NULL, the referred mailbox command will
3826 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
3827 * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
3828 * link down event occurred during the discovery, the lpfc_nlp_not_used()
3829 * routine shall be invoked trying to release the ndlp if no other threads
3830 * are currently referring it.
3833 lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3834 struct lpfc_iocbq *rspiocb)
3836 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3837 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
3838 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
3841 LPFC_MBOXQ_t *mbox = NULL;
3842 struct lpfc_dmabuf *mp = NULL;
3843 uint32_t ls_rjt = 0;
3845 irsp = &rspiocb->iocb;
3847 if (cmdiocb->context_un.mbox)
3848 mbox = cmdiocb->context_un.mbox;
3850 /* First determine if this is a LS_RJT cmpl. Note, this callback
3851 * function can have cmdiocb->contest1 (ndlp) field set to NULL.
3853 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
3854 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3855 (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) {
3856 /* A LS_RJT associated with Default RPI cleanup has its own
3857 * separate code path.
3859 if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
3863 /* Check to see if link went down during discovery */
3864 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) {
3866 mp = (struct lpfc_dmabuf *) mbox->context1;
3868 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3871 mempool_free(mbox, phba->mbox_mem_pool);
3873 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3874 (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
3875 if (lpfc_nlp_not_used(ndlp)) {
3877 /* Indicate the node has already released,
3878 * should not reference to it from within
3879 * the routine lpfc_els_free_iocb.
3881 cmdiocb->context1 = NULL;
3886 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3887 "ELS rsp cmpl: status:x%x/x%x did:x%x",
3888 irsp->ulpStatus, irsp->un.ulpWord[4],
3889 cmdiocb->iocb.un.elsreq64.remoteID);
3890 /* ELS response tag <ulpIoTag> completes */
3891 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3892 "0110 ELS response tag x%x completes "
3893 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
3894 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
3895 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
3896 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3899 if ((rspiocb->iocb.ulpStatus == 0)
3900 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
3901 lpfc_unreg_rpi(vport, ndlp);
3902 /* Increment reference count to ndlp to hold the
3903 * reference to ndlp for the callback function.
3905 mbox->context2 = lpfc_nlp_get(ndlp);
3906 mbox->vport = vport;
3907 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
3908 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
3909 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
3912 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
3913 ndlp->nlp_prev_state = ndlp->nlp_state;
3914 lpfc_nlp_set_state(vport, ndlp,
3915 NLP_STE_REG_LOGIN_ISSUE);
3918 ndlp->nlp_flag |= NLP_REG_LOGIN_SEND;
3919 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
3920 != MBX_NOT_FINISHED)
3923 /* Decrement the ndlp reference count we
3924 * set for this failed mailbox command.
3927 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
3929 /* ELS rsp: Cannot issue reg_login for <NPortid> */
3930 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3931 "0138 ELS rsp: Cannot issue reg_login for x%x "
3932 "Data: x%x x%x x%x\n",
3933 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3936 if (lpfc_nlp_not_used(ndlp)) {
3938 /* Indicate node has already been released,
3939 * should not reference to it from within
3940 * the routine lpfc_els_free_iocb.
3942 cmdiocb->context1 = NULL;
3945 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
3946 if (!lpfc_error_lost_link(irsp) &&
3947 ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
3948 if (lpfc_nlp_not_used(ndlp)) {
3950 /* Indicate node has already been
3951 * released, should not reference
3952 * to it from within the routine
3953 * lpfc_els_free_iocb.
3955 cmdiocb->context1 = NULL;
3959 mp = (struct lpfc_dmabuf *) mbox->context1;
3961 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3964 mempool_free(mbox, phba->mbox_mem_pool);
3967 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
3968 spin_lock_irq(shost->host_lock);
3969 ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI);
3970 spin_unlock_irq(shost->host_lock);
3972 /* If the node is not being used by another discovery thread,
3973 * and we are sending a reject, we are done with it.
3974 * Release driver reference count here and free associated
3978 if (lpfc_nlp_not_used(ndlp))
3979 /* Indicate node has already been released,
3980 * should not reference to it from within
3981 * the routine lpfc_els_free_iocb.
3983 cmdiocb->context1 = NULL;
3987 lpfc_els_free_iocb(phba, cmdiocb);
3992 * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
3993 * @vport: pointer to a host virtual N_Port data structure.
3994 * @flag: the els command code to be accepted.
3995 * @oldiocb: pointer to the original lpfc command iocb data structure.
3996 * @ndlp: pointer to a node-list data structure.
3997 * @mbox: pointer to the driver internal queue element for mailbox command.
3999 * This routine prepares and issues an Accept (ACC) response IOCB
4000 * command. It uses the @flag to properly set up the IOCB field for the
4001 * specific ACC response command to be issued and invokes the
4002 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
4003 * @mbox pointer is passed in, it will be put into the context_un.mbox
4004 * field of the IOCB for the completion callback function to issue the
4005 * mailbox command to the HBA later when callback is invoked.
4007 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4008 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4009 * will be stored into the context1 field of the IOCB for the completion
4010 * callback function to the corresponding response ELS IOCB command.
4013 * 0 - Successfully issued acc response
4014 * 1 - Failed to issue acc response
4017 lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
4018 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
4021 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4022 struct lpfc_hba *phba = vport->phba;
4025 struct lpfc_iocbq *elsiocb;
4027 struct serv_parm *sp;
4030 ELS_PKT *els_pkt_ptr;
4032 oldcmd = &oldiocb->iocb;
4036 cmdsize = sizeof(uint32_t);
4037 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
4038 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
4040 spin_lock_irq(shost->host_lock);
4041 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
4042 spin_unlock_irq(shost->host_lock);
4046 icmd = &elsiocb->iocb;
4047 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4048 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4049 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4050 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4051 pcmd += sizeof(uint32_t);
4053 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4054 "Issue ACC: did:x%x flg:x%x",
4055 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4059 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
4060 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
4061 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
4065 icmd = &elsiocb->iocb;
4066 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4067 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4068 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4071 elsiocb->context_un.mbox = mbox;
4073 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4074 pcmd += sizeof(uint32_t);
4075 sp = (struct serv_parm *)pcmd;
4077 if (flag == ELS_CMD_FLOGI) {
4078 /* Copy the received service parameters back */
4079 memcpy(sp, &phba->fc_fabparam,
4080 sizeof(struct serv_parm));
4082 /* Clear the F_Port bit */
4085 /* Mark all class service parameters as invalid */
4086 sp->cls1.classValid = 0;
4087 sp->cls2.classValid = 0;
4088 sp->cls3.classValid = 0;
4089 sp->cls4.classValid = 0;
4091 /* Copy our worldwide names */
4092 memcpy(&sp->portName, &vport->fc_sparam.portName,
4093 sizeof(struct lpfc_name));
4094 memcpy(&sp->nodeName, &vport->fc_sparam.nodeName,
4095 sizeof(struct lpfc_name));
4097 memcpy(pcmd, &vport->fc_sparam,
4098 sizeof(struct serv_parm));
4100 sp->cmn.valid_vendor_ver_level = 0;
4101 memset(sp->un.vendorVersion, 0,
4102 sizeof(sp->un.vendorVersion));
4104 /* If our firmware supports this feature, convey that
4105 * info to the target using the vendor specific field.
4107 if (phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) {
4108 sp->cmn.valid_vendor_ver_level = 1;
4109 sp->un.vv.vid = cpu_to_be32(LPFC_VV_EMLX_ID);
4111 cpu_to_be32(LPFC_VV_SUPPRESS_RSP);
4115 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4116 "Issue ACC FLOGI/PLOGI: did:x%x flg:x%x",
4117 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4120 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
4121 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
4122 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
4126 icmd = &elsiocb->iocb;
4127 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4128 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4129 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4131 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
4132 sizeof(uint32_t) + sizeof(PRLO));
4133 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
4134 els_pkt_ptr = (ELS_PKT *) pcmd;
4135 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
4137 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4138 "Issue ACC PRLO: did:x%x flg:x%x",
4139 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4144 /* Xmit ELS ACC response tag <ulpIoTag> */
4145 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4146 "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
4147 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x "
4149 elsiocb->iotag, elsiocb->iocb.ulpContext,
4150 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4151 ndlp->nlp_rpi, vport->fc_flag);
4152 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
4153 spin_lock_irq(shost->host_lock);
4154 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED ||
4155 ndlp->nlp_flag & NLP_REG_LOGIN_SEND))
4156 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
4157 spin_unlock_irq(shost->host_lock);
4158 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
4160 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4163 phba->fc_stat.elsXmitACC++;
4164 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4165 if (rc == IOCB_ERROR) {
4166 lpfc_els_free_iocb(phba, elsiocb);
4173 * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command
4174 * @vport: pointer to a virtual N_Port data structure.
4176 * @oldiocb: pointer to the original lpfc command iocb data structure.
4177 * @ndlp: pointer to a node-list data structure.
4178 * @mbox: pointer to the driver internal queue element for mailbox command.
4180 * This routine prepares and issue an Reject (RJT) response IOCB
4181 * command. If a @mbox pointer is passed in, it will be put into the
4182 * context_un.mbox field of the IOCB for the completion callback function
4183 * to issue to the HBA later.
4185 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4186 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4187 * will be stored into the context1 field of the IOCB for the completion
4188 * callback function to the reject response ELS IOCB command.
4191 * 0 - Successfully issued reject response
4192 * 1 - Failed to issue reject response
4195 lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
4196 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
4199 struct lpfc_hba *phba = vport->phba;
4202 struct lpfc_iocbq *elsiocb;
4207 cmdsize = 2 * sizeof(uint32_t);
4208 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4209 ndlp->nlp_DID, ELS_CMD_LS_RJT);
4213 icmd = &elsiocb->iocb;
4214 oldcmd = &oldiocb->iocb;
4215 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4216 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4217 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4219 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
4220 pcmd += sizeof(uint32_t);
4221 *((uint32_t *) (pcmd)) = rejectError;
4224 elsiocb->context_un.mbox = mbox;
4226 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
4227 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4228 "0129 Xmit ELS RJT x%x response tag x%x "
4229 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
4231 rejectError, elsiocb->iotag,
4232 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
4233 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
4234 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4235 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
4236 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
4238 phba->fc_stat.elsXmitLSRJT++;
4239 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4240 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4242 if (rc == IOCB_ERROR) {
4243 lpfc_els_free_iocb(phba, elsiocb);
4250 * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
4251 * @vport: pointer to a virtual N_Port data structure.
4252 * @oldiocb: pointer to the original lpfc command iocb data structure.
4253 * @ndlp: pointer to a node-list data structure.
4255 * This routine prepares and issues an Accept (ACC) response to Address
4256 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
4257 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
4259 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4260 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4261 * will be stored into the context1 field of the IOCB for the completion
4262 * callback function to the ADISC Accept response ELS IOCB command.
4265 * 0 - Successfully issued acc adisc response
4266 * 1 - Failed to issue adisc acc response
4269 lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
4270 struct lpfc_nodelist *ndlp)
4272 struct lpfc_hba *phba = vport->phba;
4274 IOCB_t *icmd, *oldcmd;
4275 struct lpfc_iocbq *elsiocb;
4280 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
4281 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4282 ndlp->nlp_DID, ELS_CMD_ACC);
4286 icmd = &elsiocb->iocb;
4287 oldcmd = &oldiocb->iocb;
4288 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4289 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4291 /* Xmit ADISC ACC response tag <ulpIoTag> */
4292 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4293 "0130 Xmit ADISC ACC response iotag x%x xri: "
4294 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
4295 elsiocb->iotag, elsiocb->iocb.ulpContext,
4296 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4298 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4300 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4301 pcmd += sizeof(uint32_t);
4303 ap = (ADISC *) (pcmd);
4304 ap->hardAL_PA = phba->fc_pref_ALPA;
4305 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
4306 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
4307 ap->DID = be32_to_cpu(vport->fc_myDID);
4309 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4310 "Issue ACC ADISC: did:x%x flg:x%x",
4311 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4313 phba->fc_stat.elsXmitACC++;
4314 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4315 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4316 if (rc == IOCB_ERROR) {
4317 lpfc_els_free_iocb(phba, elsiocb);
4324 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
4325 * @vport: pointer to a virtual N_Port data structure.
4326 * @oldiocb: pointer to the original lpfc command iocb data structure.
4327 * @ndlp: pointer to a node-list data structure.
4329 * This routine prepares and issues an Accept (ACC) response to Process
4330 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
4331 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
4333 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4334 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4335 * will be stored into the context1 field of the IOCB for the completion
4336 * callback function to the PRLI Accept response ELS IOCB command.
4339 * 0 - Successfully issued acc prli response
4340 * 1 - Failed to issue acc prli response
4343 lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
4344 struct lpfc_nodelist *ndlp)
4346 struct lpfc_hba *phba = vport->phba;
4348 struct lpfc_nvme_prli *npr_nvme;
4352 struct lpfc_iocbq *elsiocb;
4355 uint32_t prli_fc4_req, *req_payload;
4356 struct lpfc_dmabuf *req_buf;
4360 /* Need the incoming PRLI payload to determine if the ACC is for an
4361 * FC4 or NVME PRLI type. The PRLI type is at word 1.
4363 req_buf = (struct lpfc_dmabuf *)oldiocb->context2;
4364 req_payload = (((uint32_t *)req_buf->virt) + 1);
4366 /* PRLI type payload is at byte 3 for FCP or NVME. */
4367 prli_fc4_req = be32_to_cpu(*req_payload);
4368 prli_fc4_req = (prli_fc4_req >> 24) & 0xff;
4369 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4370 "6127 PRLI_ACC: Req Type x%x, Word1 x%08x\n",
4371 prli_fc4_req, *((uint32_t *)req_payload));
4373 if (prli_fc4_req == PRLI_FCP_TYPE) {
4374 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
4375 elsrspcmd = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
4376 } else if (prli_fc4_req & PRLI_NVME_TYPE) {
4377 cmdsize = sizeof(uint32_t) + sizeof(struct lpfc_nvme_prli);
4378 elsrspcmd = (ELS_CMD_ACC | (ELS_CMD_NVMEPRLI & ~ELS_RSP_MASK));
4383 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4384 ndlp->nlp_DID, elsrspcmd);
4388 icmd = &elsiocb->iocb;
4389 oldcmd = &oldiocb->iocb;
4390 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4391 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4393 /* Xmit PRLI ACC response tag <ulpIoTag> */
4394 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4395 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
4396 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
4397 elsiocb->iotag, elsiocb->iocb.ulpContext,
4398 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4400 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4401 memset(pcmd, 0, cmdsize);
4403 *((uint32_t *)(pcmd)) = elsrspcmd;
4404 pcmd += sizeof(uint32_t);
4406 /* For PRLI, remainder of payload is PRLI parameter page */
4409 if (prli_fc4_req == PRLI_FCP_TYPE) {
4411 * If the remote port is a target and our firmware version
4412 * is 3.20 or later, set the following bits for FC-TAPE
4415 npr = (PRLI *) pcmd;
4416 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
4417 (vpd->rev.feaLevelHigh >= 0x02)) {
4418 npr->ConfmComplAllowed = 1;
4420 npr->TaskRetryIdReq = 1;
4422 npr->acceptRspCode = PRLI_REQ_EXECUTED;
4423 npr->estabImagePair = 1;
4424 npr->readXferRdyDis = 1;
4425 npr->ConfmComplAllowed = 1;
4426 npr->prliType = PRLI_FCP_TYPE;
4427 npr->initiatorFunc = 1;
4428 } else if (prli_fc4_req & PRLI_NVME_TYPE) {
4429 /* Respond with an NVME PRLI Type */
4430 npr_nvme = (struct lpfc_nvme_prli *) pcmd;
4431 bf_set(prli_type_code, npr_nvme, PRLI_NVME_TYPE);
4432 bf_set(prli_estabImagePair, npr_nvme, 0); /* Should be 0 */
4433 bf_set(prli_acc_rsp_code, npr_nvme, PRLI_REQ_EXECUTED);
4434 if (phba->nvmet_support) {
4435 bf_set(prli_tgt, npr_nvme, 1);
4436 bf_set(prli_disc, npr_nvme, 1);
4437 if (phba->cfg_nvme_enable_fb) {
4438 bf_set(prli_fba, npr_nvme, 1);
4440 /* TBD. Target mode needs to post buffers
4441 * that support the configured first burst
4444 bf_set(prli_fb_sz, npr_nvme,
4445 phba->cfg_nvmet_fb_size);
4448 bf_set(prli_init, npr_nvme, 1);
4451 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
4452 "6015 NVME issue PRLI ACC word1 x%08x "
4453 "word4 x%08x word5 x%08x flag x%x, "
4454 "fcp_info x%x nlp_type x%x\n",
4455 npr_nvme->word1, npr_nvme->word4,
4456 npr_nvme->word5, ndlp->nlp_flag,
4457 ndlp->nlp_fcp_info, ndlp->nlp_type);
4458 npr_nvme->word1 = cpu_to_be32(npr_nvme->word1);
4459 npr_nvme->word4 = cpu_to_be32(npr_nvme->word4);
4460 npr_nvme->word5 = cpu_to_be32(npr_nvme->word5);
4462 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4463 "6128 Unknown FC_TYPE x%x x%x ndlp x%06x\n",
4464 prli_fc4_req, ndlp->nlp_fc4_type,
4467 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4468 "Issue ACC PRLI: did:x%x flg:x%x",
4469 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4471 phba->fc_stat.elsXmitACC++;
4472 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4474 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4475 if (rc == IOCB_ERROR) {
4476 lpfc_els_free_iocb(phba, elsiocb);
4483 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
4484 * @vport: pointer to a virtual N_Port data structure.
4485 * @format: rnid command format.
4486 * @oldiocb: pointer to the original lpfc command iocb data structure.
4487 * @ndlp: pointer to a node-list data structure.
4489 * This routine issues a Request Node Identification Data (RNID) Accept
4490 * (ACC) response. It constructs the RNID ACC response command according to
4491 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
4492 * issue the response. Note that this command does not need to hold the ndlp
4493 * reference count for the callback. So, the ndlp reference count taken by
4494 * the lpfc_prep_els_iocb() routine is put back and the context1 field of
4495 * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
4496 * there is no ndlp reference available.
4498 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4499 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4500 * will be stored into the context1 field of the IOCB for the completion
4501 * callback function. However, for the RNID Accept Response ELS command,
4502 * this is undone later by this routine after the IOCB is allocated.
4505 * 0 - Successfully issued acc rnid response
4506 * 1 - Failed to issue acc rnid response
4509 lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
4510 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
4512 struct lpfc_hba *phba = vport->phba;
4514 IOCB_t *icmd, *oldcmd;
4515 struct lpfc_iocbq *elsiocb;
4520 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
4521 + (2 * sizeof(struct lpfc_name));
4523 cmdsize += sizeof(RNID_TOP_DISC);
4525 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4526 ndlp->nlp_DID, ELS_CMD_ACC);
4530 icmd = &elsiocb->iocb;
4531 oldcmd = &oldiocb->iocb;
4532 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4533 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4535 /* Xmit RNID ACC response tag <ulpIoTag> */
4536 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4537 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
4538 elsiocb->iotag, elsiocb->iocb.ulpContext);
4539 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4540 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4541 pcmd += sizeof(uint32_t);
4543 memset(pcmd, 0, sizeof(RNID));
4544 rn = (RNID *) (pcmd);
4545 rn->Format = format;
4546 rn->CommonLen = (2 * sizeof(struct lpfc_name));
4547 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
4548 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
4551 rn->SpecificLen = 0;
4553 case RNID_TOPOLOGY_DISC:
4554 rn->SpecificLen = sizeof(RNID_TOP_DISC);
4555 memcpy(&rn->un.topologyDisc.portName,
4556 &vport->fc_portname, sizeof(struct lpfc_name));
4557 rn->un.topologyDisc.unitType = RNID_HBA;
4558 rn->un.topologyDisc.physPort = 0;
4559 rn->un.topologyDisc.attachedNodes = 0;
4563 rn->SpecificLen = 0;
4567 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4568 "Issue ACC RNID: did:x%x flg:x%x",
4569 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4571 phba->fc_stat.elsXmitACC++;
4572 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4574 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4575 if (rc == IOCB_ERROR) {
4576 lpfc_els_free_iocb(phba, elsiocb);
4583 * lpfc_els_clear_rrq - Clear the rq that this rrq describes.
4584 * @vport: pointer to a virtual N_Port data structure.
4585 * @iocb: pointer to the lpfc command iocb data structure.
4586 * @ndlp: pointer to a node-list data structure.
4591 lpfc_els_clear_rrq(struct lpfc_vport *vport,
4592 struct lpfc_iocbq *iocb, struct lpfc_nodelist *ndlp)
4594 struct lpfc_hba *phba = vport->phba;
4599 struct lpfc_node_rrq *prrq;
4602 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) iocb->context2)->virt);
4603 pcmd += sizeof(uint32_t);
4604 rrq = (struct RRQ *)pcmd;
4605 rrq->rrq_exchg = be32_to_cpu(rrq->rrq_exchg);
4606 rxid = bf_get(rrq_rxid, rrq);
4608 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4609 "2883 Clear RRQ for SID:x%x OXID:x%x RXID:x%x"
4611 be32_to_cpu(bf_get(rrq_did, rrq)),
4612 bf_get(rrq_oxid, rrq),
4614 iocb->iotag, iocb->iocb.ulpContext);
4616 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4617 "Clear RRQ: did:x%x flg:x%x exchg:x%.08x",
4618 ndlp->nlp_DID, ndlp->nlp_flag, rrq->rrq_exchg);
4619 if (vport->fc_myDID == be32_to_cpu(bf_get(rrq_did, rrq)))
4620 xri = bf_get(rrq_oxid, rrq);
4623 prrq = lpfc_get_active_rrq(vport, xri, ndlp->nlp_DID);
4625 lpfc_clr_rrq_active(phba, xri, prrq);
4630 * lpfc_els_rsp_echo_acc - Issue echo acc response
4631 * @vport: pointer to a virtual N_Port data structure.
4632 * @data: pointer to echo data to return in the accept.
4633 * @oldiocb: pointer to the original lpfc command iocb data structure.
4634 * @ndlp: pointer to a node-list data structure.
4637 * 0 - Successfully issued acc echo response
4638 * 1 - Failed to issue acc echo response
4641 lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data,
4642 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
4644 struct lpfc_hba *phba = vport->phba;
4645 struct lpfc_iocbq *elsiocb;
4650 cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len;
4652 /* The accumulated length can exceed the BPL_SIZE. For
4653 * now, use this as the limit
4655 if (cmdsize > LPFC_BPL_SIZE)
4656 cmdsize = LPFC_BPL_SIZE;
4657 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4658 ndlp->nlp_DID, ELS_CMD_ACC);
4662 elsiocb->iocb.ulpContext = oldiocb->iocb.ulpContext; /* Xri / rx_id */
4663 elsiocb->iocb.unsli3.rcvsli3.ox_id = oldiocb->iocb.unsli3.rcvsli3.ox_id;
4665 /* Xmit ECHO ACC response tag <ulpIoTag> */
4666 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4667 "2876 Xmit ECHO ACC response tag x%x xri x%x\n",
4668 elsiocb->iotag, elsiocb->iocb.ulpContext);
4669 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4670 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4671 pcmd += sizeof(uint32_t);
4672 memcpy(pcmd, data, cmdsize - sizeof(uint32_t));
4674 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4675 "Issue ACC ECHO: did:x%x flg:x%x",
4676 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4678 phba->fc_stat.elsXmitACC++;
4679 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4681 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4682 if (rc == IOCB_ERROR) {
4683 lpfc_els_free_iocb(phba, elsiocb);
4690 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
4691 * @vport: pointer to a host virtual N_Port data structure.
4693 * This routine issues Address Discover (ADISC) ELS commands to those
4694 * N_Ports which are in node port recovery state and ADISC has not been issued
4695 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
4696 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
4697 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
4698 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
4699 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
4700 * IOCBs quit for later pick up. On the other hand, after walking through
4701 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
4702 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
4703 * no more ADISC need to be sent.
4706 * The number of N_Ports with adisc issued.
4709 lpfc_els_disc_adisc(struct lpfc_vport *vport)
4711 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4712 struct lpfc_nodelist *ndlp, *next_ndlp;
4715 /* go thru NPR nodes and issue any remaining ELS ADISCs */
4716 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
4717 if (!NLP_CHK_NODE_ACT(ndlp))
4719 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
4720 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
4721 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
4722 spin_lock_irq(shost->host_lock);
4723 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
4724 spin_unlock_irq(shost->host_lock);
4725 ndlp->nlp_prev_state = ndlp->nlp_state;
4726 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
4727 lpfc_issue_els_adisc(vport, ndlp, 0);
4729 vport->num_disc_nodes++;
4730 if (vport->num_disc_nodes >=
4731 vport->cfg_discovery_threads) {
4732 spin_lock_irq(shost->host_lock);
4733 vport->fc_flag |= FC_NLP_MORE;
4734 spin_unlock_irq(shost->host_lock);
4739 if (sentadisc == 0) {
4740 spin_lock_irq(shost->host_lock);
4741 vport->fc_flag &= ~FC_NLP_MORE;
4742 spin_unlock_irq(shost->host_lock);
4748 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
4749 * @vport: pointer to a host virtual N_Port data structure.
4751 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
4752 * which are in node port recovery state, with a @vport. Each time an ELS
4753 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
4754 * the per @vport number of discover count (num_disc_nodes) shall be
4755 * incremented. If the num_disc_nodes reaches a pre-configured threshold
4756 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
4757 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
4758 * later pick up. On the other hand, after walking through all the ndlps with
4759 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
4760 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
4761 * PLOGI need to be sent.
4764 * The number of N_Ports with plogi issued.
4767 lpfc_els_disc_plogi(struct lpfc_vport *vport)
4769 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4770 struct lpfc_nodelist *ndlp, *next_ndlp;
4773 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
4774 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
4775 if (!NLP_CHK_NODE_ACT(ndlp))
4777 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
4778 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
4779 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
4780 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
4781 ndlp->nlp_prev_state = ndlp->nlp_state;
4782 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
4783 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
4785 vport->num_disc_nodes++;
4786 if (vport->num_disc_nodes >=
4787 vport->cfg_discovery_threads) {
4788 spin_lock_irq(shost->host_lock);
4789 vport->fc_flag |= FC_NLP_MORE;
4790 spin_unlock_irq(shost->host_lock);
4796 lpfc_set_disctmo(vport);
4799 spin_lock_irq(shost->host_lock);
4800 vport->fc_flag &= ~FC_NLP_MORE;
4801 spin_unlock_irq(shost->host_lock);
4807 lpfc_rdp_res_link_service(struct fc_rdp_link_service_desc *desc,
4811 desc->tag = cpu_to_be32(RDP_LINK_SERVICE_DESC_TAG);
4812 desc->payload.els_req = word0;
4813 desc->length = cpu_to_be32(sizeof(desc->payload));
4815 return sizeof(struct fc_rdp_link_service_desc);
4819 lpfc_rdp_res_sfp_desc(struct fc_rdp_sfp_desc *desc,
4820 uint8_t *page_a0, uint8_t *page_a2)
4822 uint16_t wavelength;
4823 uint16_t temperature;
4829 struct sff_trasnceiver_codes_byte4 *trasn_code_byte4;
4830 struct sff_trasnceiver_codes_byte5 *trasn_code_byte5;
4832 desc->tag = cpu_to_be32(RDP_SFP_DESC_TAG);
4834 trasn_code_byte4 = (struct sff_trasnceiver_codes_byte4 *)
4835 &page_a0[SSF_TRANSCEIVER_CODE_B4];
4836 trasn_code_byte5 = (struct sff_trasnceiver_codes_byte5 *)
4837 &page_a0[SSF_TRANSCEIVER_CODE_B5];
4839 if ((trasn_code_byte4->fc_sw_laser) ||
4840 (trasn_code_byte5->fc_sw_laser_sl) ||
4841 (trasn_code_byte5->fc_sw_laser_sn)) { /* check if its short WL */
4842 flag |= (SFP_FLAG_PT_SWLASER << SFP_FLAG_PT_SHIFT);
4843 } else if (trasn_code_byte4->fc_lw_laser) {
4844 wavelength = (page_a0[SSF_WAVELENGTH_B1] << 8) |
4845 page_a0[SSF_WAVELENGTH_B0];
4846 if (wavelength == SFP_WAVELENGTH_LC1310)
4847 flag |= SFP_FLAG_PT_LWLASER_LC1310 << SFP_FLAG_PT_SHIFT;
4848 if (wavelength == SFP_WAVELENGTH_LL1550)
4849 flag |= SFP_FLAG_PT_LWLASER_LL1550 << SFP_FLAG_PT_SHIFT;
4851 /* check if its SFP+ */
4852 flag |= ((page_a0[SSF_IDENTIFIER] == SFF_PG0_IDENT_SFP) ?
4853 SFP_FLAG_CT_SFP_PLUS : SFP_FLAG_CT_UNKNOWN)
4854 << SFP_FLAG_CT_SHIFT;
4856 /* check if its OPTICAL */
4857 flag |= ((page_a0[SSF_CONNECTOR] == SFF_PG0_CONNECTOR_LC) ?
4858 SFP_FLAG_IS_OPTICAL_PORT : 0)
4859 << SFP_FLAG_IS_OPTICAL_SHIFT;
4861 temperature = (page_a2[SFF_TEMPERATURE_B1] << 8 |
4862 page_a2[SFF_TEMPERATURE_B0]);
4863 vcc = (page_a2[SFF_VCC_B1] << 8 |
4864 page_a2[SFF_VCC_B0]);
4865 tx_power = (page_a2[SFF_TXPOWER_B1] << 8 |
4866 page_a2[SFF_TXPOWER_B0]);
4867 tx_bias = (page_a2[SFF_TX_BIAS_CURRENT_B1] << 8 |
4868 page_a2[SFF_TX_BIAS_CURRENT_B0]);
4869 rx_power = (page_a2[SFF_RXPOWER_B1] << 8 |
4870 page_a2[SFF_RXPOWER_B0]);
4871 desc->sfp_info.temperature = cpu_to_be16(temperature);
4872 desc->sfp_info.rx_power = cpu_to_be16(rx_power);
4873 desc->sfp_info.tx_bias = cpu_to_be16(tx_bias);
4874 desc->sfp_info.tx_power = cpu_to_be16(tx_power);
4875 desc->sfp_info.vcc = cpu_to_be16(vcc);
4877 desc->sfp_info.flags = cpu_to_be16(flag);
4878 desc->length = cpu_to_be32(sizeof(desc->sfp_info));
4880 return sizeof(struct fc_rdp_sfp_desc);
4884 lpfc_rdp_res_link_error(struct fc_rdp_link_error_status_desc *desc,
4889 desc->tag = cpu_to_be32(RDP_LINK_ERROR_STATUS_DESC_TAG);
4891 type = VN_PT_PHY_PF_PORT << VN_PT_PHY_SHIFT;
4893 desc->info.port_type = cpu_to_be32(type);
4895 desc->info.link_status.link_failure_cnt =
4896 cpu_to_be32(stat->linkFailureCnt);
4897 desc->info.link_status.loss_of_synch_cnt =
4898 cpu_to_be32(stat->lossSyncCnt);
4899 desc->info.link_status.loss_of_signal_cnt =
4900 cpu_to_be32(stat->lossSignalCnt);
4901 desc->info.link_status.primitive_seq_proto_err =
4902 cpu_to_be32(stat->primSeqErrCnt);
4903 desc->info.link_status.invalid_trans_word =
4904 cpu_to_be32(stat->invalidXmitWord);
4905 desc->info.link_status.invalid_crc_cnt = cpu_to_be32(stat->crcCnt);
4907 desc->length = cpu_to_be32(sizeof(desc->info));
4909 return sizeof(struct fc_rdp_link_error_status_desc);
4913 lpfc_rdp_res_bbc_desc(struct fc_rdp_bbc_desc *desc, READ_LNK_VAR *stat,
4914 struct lpfc_vport *vport)
4918 desc->tag = cpu_to_be32(RDP_BBC_DESC_TAG);
4920 bbCredit = vport->fc_sparam.cmn.bbCreditLsb |
4921 (vport->fc_sparam.cmn.bbCreditMsb << 8);
4922 desc->bbc_info.port_bbc = cpu_to_be32(bbCredit);
4923 if (vport->phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
4924 bbCredit = vport->phba->fc_fabparam.cmn.bbCreditLsb |
4925 (vport->phba->fc_fabparam.cmn.bbCreditMsb << 8);
4926 desc->bbc_info.attached_port_bbc = cpu_to_be32(bbCredit);
4928 desc->bbc_info.attached_port_bbc = 0;
4931 desc->bbc_info.rtt = 0;
4932 desc->length = cpu_to_be32(sizeof(desc->bbc_info));
4934 return sizeof(struct fc_rdp_bbc_desc);
4938 lpfc_rdp_res_oed_temp_desc(struct lpfc_hba *phba,
4939 struct fc_rdp_oed_sfp_desc *desc, uint8_t *page_a2)
4943 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
4945 desc->oed_info.hi_alarm = page_a2[SSF_TEMP_HIGH_ALARM];
4946 desc->oed_info.lo_alarm = page_a2[SSF_TEMP_LOW_ALARM];
4947 desc->oed_info.hi_warning = page_a2[SSF_TEMP_HIGH_WARNING];
4948 desc->oed_info.lo_warning = page_a2[SSF_TEMP_LOW_WARNING];
4950 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TEMPERATURE)
4951 flags |= RDP_OET_HIGH_ALARM;
4952 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TEMPERATURE)
4953 flags |= RDP_OET_LOW_ALARM;
4954 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TEMPERATURE)
4955 flags |= RDP_OET_HIGH_WARNING;
4956 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TEMPERATURE)
4957 flags |= RDP_OET_LOW_WARNING;
4959 flags |= ((0xf & RDP_OED_TEMPERATURE) << RDP_OED_TYPE_SHIFT);
4960 desc->oed_info.function_flags = cpu_to_be32(flags);
4961 desc->length = cpu_to_be32(sizeof(desc->oed_info));
4962 return sizeof(struct fc_rdp_oed_sfp_desc);
4966 lpfc_rdp_res_oed_voltage_desc(struct lpfc_hba *phba,
4967 struct fc_rdp_oed_sfp_desc *desc,
4972 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
4974 desc->oed_info.hi_alarm = page_a2[SSF_VOLTAGE_HIGH_ALARM];
4975 desc->oed_info.lo_alarm = page_a2[SSF_VOLTAGE_LOW_ALARM];
4976 desc->oed_info.hi_warning = page_a2[SSF_VOLTAGE_HIGH_WARNING];
4977 desc->oed_info.lo_warning = page_a2[SSF_VOLTAGE_LOW_WARNING];
4979 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_VOLTAGE)
4980 flags |= RDP_OET_HIGH_ALARM;
4981 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_VOLTAGE)
4982 flags |= RDP_OET_LOW_ALARM;
4983 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_VOLTAGE)
4984 flags |= RDP_OET_HIGH_WARNING;
4985 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_VOLTAGE)
4986 flags |= RDP_OET_LOW_WARNING;
4988 flags |= ((0xf & RDP_OED_VOLTAGE) << RDP_OED_TYPE_SHIFT);
4989 desc->oed_info.function_flags = cpu_to_be32(flags);
4990 desc->length = cpu_to_be32(sizeof(desc->oed_info));
4991 return sizeof(struct fc_rdp_oed_sfp_desc);
4995 lpfc_rdp_res_oed_txbias_desc(struct lpfc_hba *phba,
4996 struct fc_rdp_oed_sfp_desc *desc,
5001 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5003 desc->oed_info.hi_alarm = page_a2[SSF_BIAS_HIGH_ALARM];
5004 desc->oed_info.lo_alarm = page_a2[SSF_BIAS_LOW_ALARM];
5005 desc->oed_info.hi_warning = page_a2[SSF_BIAS_HIGH_WARNING];
5006 desc->oed_info.lo_warning = page_a2[SSF_BIAS_LOW_WARNING];
5008 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TXBIAS)
5009 flags |= RDP_OET_HIGH_ALARM;
5010 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TXBIAS)
5011 flags |= RDP_OET_LOW_ALARM;
5012 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TXBIAS)
5013 flags |= RDP_OET_HIGH_WARNING;
5014 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TXBIAS)
5015 flags |= RDP_OET_LOW_WARNING;
5017 flags |= ((0xf & RDP_OED_TXBIAS) << RDP_OED_TYPE_SHIFT);
5018 desc->oed_info.function_flags = cpu_to_be32(flags);
5019 desc->length = cpu_to_be32(sizeof(desc->oed_info));
5020 return sizeof(struct fc_rdp_oed_sfp_desc);
5024 lpfc_rdp_res_oed_txpower_desc(struct lpfc_hba *phba,
5025 struct fc_rdp_oed_sfp_desc *desc,
5030 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5032 desc->oed_info.hi_alarm = page_a2[SSF_TXPOWER_HIGH_ALARM];
5033 desc->oed_info.lo_alarm = page_a2[SSF_TXPOWER_LOW_ALARM];
5034 desc->oed_info.hi_warning = page_a2[SSF_TXPOWER_HIGH_WARNING];
5035 desc->oed_info.lo_warning = page_a2[SSF_TXPOWER_LOW_WARNING];
5037 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TXPOWER)
5038 flags |= RDP_OET_HIGH_ALARM;
5039 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TXPOWER)
5040 flags |= RDP_OET_LOW_ALARM;
5041 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TXPOWER)
5042 flags |= RDP_OET_HIGH_WARNING;
5043 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TXPOWER)
5044 flags |= RDP_OET_LOW_WARNING;
5046 flags |= ((0xf & RDP_OED_TXPOWER) << RDP_OED_TYPE_SHIFT);
5047 desc->oed_info.function_flags = cpu_to_be32(flags);
5048 desc->length = cpu_to_be32(sizeof(desc->oed_info));
5049 return sizeof(struct fc_rdp_oed_sfp_desc);
5054 lpfc_rdp_res_oed_rxpower_desc(struct lpfc_hba *phba,
5055 struct fc_rdp_oed_sfp_desc *desc,
5060 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5062 desc->oed_info.hi_alarm = page_a2[SSF_RXPOWER_HIGH_ALARM];
5063 desc->oed_info.lo_alarm = page_a2[SSF_RXPOWER_LOW_ALARM];
5064 desc->oed_info.hi_warning = page_a2[SSF_RXPOWER_HIGH_WARNING];
5065 desc->oed_info.lo_warning = page_a2[SSF_RXPOWER_LOW_WARNING];
5067 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_RXPOWER)
5068 flags |= RDP_OET_HIGH_ALARM;
5069 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_RXPOWER)
5070 flags |= RDP_OET_LOW_ALARM;
5071 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_RXPOWER)
5072 flags |= RDP_OET_HIGH_WARNING;
5073 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_RXPOWER)
5074 flags |= RDP_OET_LOW_WARNING;
5076 flags |= ((0xf & RDP_OED_RXPOWER) << RDP_OED_TYPE_SHIFT);
5077 desc->oed_info.function_flags = cpu_to_be32(flags);
5078 desc->length = cpu_to_be32(sizeof(desc->oed_info));
5079 return sizeof(struct fc_rdp_oed_sfp_desc);
5083 lpfc_rdp_res_opd_desc(struct fc_rdp_opd_sfp_desc *desc,
5084 uint8_t *page_a0, struct lpfc_vport *vport)
5086 desc->tag = cpu_to_be32(RDP_OPD_DESC_TAG);
5087 memcpy(desc->opd_info.vendor_name, &page_a0[SSF_VENDOR_NAME], 16);
5088 memcpy(desc->opd_info.model_number, &page_a0[SSF_VENDOR_PN], 16);
5089 memcpy(desc->opd_info.serial_number, &page_a0[SSF_VENDOR_SN], 16);
5090 memcpy(desc->opd_info.revision, &page_a0[SSF_VENDOR_REV], 4);
5091 memcpy(desc->opd_info.date, &page_a0[SSF_DATE_CODE], 8);
5092 desc->length = cpu_to_be32(sizeof(desc->opd_info));
5093 return sizeof(struct fc_rdp_opd_sfp_desc);
5097 lpfc_rdp_res_fec_desc(struct fc_fec_rdp_desc *desc, READ_LNK_VAR *stat)
5099 if (bf_get(lpfc_read_link_stat_gec2, stat) == 0)
5101 desc->tag = cpu_to_be32(RDP_FEC_DESC_TAG);
5103 desc->info.CorrectedBlocks =
5104 cpu_to_be32(stat->fecCorrBlkCount);
5105 desc->info.UncorrectableBlocks =
5106 cpu_to_be32(stat->fecUncorrBlkCount);
5108 desc->length = cpu_to_be32(sizeof(desc->info));
5110 return sizeof(struct fc_fec_rdp_desc);
5114 lpfc_rdp_res_speed(struct fc_rdp_port_speed_desc *desc, struct lpfc_hba *phba)
5116 uint16_t rdp_cap = 0;
5119 desc->tag = cpu_to_be32(RDP_PORT_SPEED_DESC_TAG);
5121 switch (phba->fc_linkspeed) {
5122 case LPFC_LINK_SPEED_1GHZ:
5123 rdp_speed = RDP_PS_1GB;
5125 case LPFC_LINK_SPEED_2GHZ:
5126 rdp_speed = RDP_PS_2GB;
5128 case LPFC_LINK_SPEED_4GHZ:
5129 rdp_speed = RDP_PS_4GB;
5131 case LPFC_LINK_SPEED_8GHZ:
5132 rdp_speed = RDP_PS_8GB;
5134 case LPFC_LINK_SPEED_10GHZ:
5135 rdp_speed = RDP_PS_10GB;
5137 case LPFC_LINK_SPEED_16GHZ:
5138 rdp_speed = RDP_PS_16GB;
5140 case LPFC_LINK_SPEED_32GHZ:
5141 rdp_speed = RDP_PS_32GB;
5144 rdp_speed = RDP_PS_UNKNOWN;
5148 desc->info.port_speed.speed = cpu_to_be16(rdp_speed);
5150 if (phba->lmt & LMT_32Gb)
5151 rdp_cap |= RDP_PS_32GB;
5152 if (phba->lmt & LMT_16Gb)
5153 rdp_cap |= RDP_PS_16GB;
5154 if (phba->lmt & LMT_10Gb)
5155 rdp_cap |= RDP_PS_10GB;
5156 if (phba->lmt & LMT_8Gb)
5157 rdp_cap |= RDP_PS_8GB;
5158 if (phba->lmt & LMT_4Gb)
5159 rdp_cap |= RDP_PS_4GB;
5160 if (phba->lmt & LMT_2Gb)
5161 rdp_cap |= RDP_PS_2GB;
5162 if (phba->lmt & LMT_1Gb)
5163 rdp_cap |= RDP_PS_1GB;
5166 rdp_cap = RDP_CAP_UNKNOWN;
5167 if (phba->cfg_link_speed != LPFC_USER_LINK_SPEED_AUTO)
5168 rdp_cap |= RDP_CAP_USER_CONFIGURED;
5170 desc->info.port_speed.capabilities = cpu_to_be16(rdp_cap);
5171 desc->length = cpu_to_be32(sizeof(desc->info));
5172 return sizeof(struct fc_rdp_port_speed_desc);
5176 lpfc_rdp_res_diag_port_names(struct fc_rdp_port_name_desc *desc,
5177 struct lpfc_vport *vport)
5180 desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG);
5182 memcpy(desc->port_names.wwnn, &vport->fc_nodename,
5183 sizeof(desc->port_names.wwnn));
5185 memcpy(desc->port_names.wwpn, &vport->fc_portname,
5186 sizeof(desc->port_names.wwpn));
5188 desc->length = cpu_to_be32(sizeof(desc->port_names));
5189 return sizeof(struct fc_rdp_port_name_desc);
5193 lpfc_rdp_res_attach_port_names(struct fc_rdp_port_name_desc *desc,
5194 struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
5197 desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG);
5198 if (vport->fc_flag & FC_FABRIC) {
5199 memcpy(desc->port_names.wwnn, &vport->fabric_nodename,
5200 sizeof(desc->port_names.wwnn));
5202 memcpy(desc->port_names.wwpn, &vport->fabric_portname,
5203 sizeof(desc->port_names.wwpn));
5204 } else { /* Point to Point */
5205 memcpy(desc->port_names.wwnn, &ndlp->nlp_nodename,
5206 sizeof(desc->port_names.wwnn));
5208 memcpy(desc->port_names.wwnn, &ndlp->nlp_portname,
5209 sizeof(desc->port_names.wwpn));
5212 desc->length = cpu_to_be32(sizeof(desc->port_names));
5213 return sizeof(struct fc_rdp_port_name_desc);
5217 lpfc_els_rdp_cmpl(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context,
5220 struct lpfc_nodelist *ndlp = rdp_context->ndlp;
5221 struct lpfc_vport *vport = ndlp->vport;
5222 struct lpfc_iocbq *elsiocb;
5223 struct ulp_bde64 *bpl;
5226 struct ls_rjt *stat;
5227 struct fc_rdp_res_frame *rdp_res;
5228 uint32_t cmdsize, len;
5232 if (status != SUCCESS)
5235 /* This will change once we know the true size of the RDP payload */
5236 cmdsize = sizeof(struct fc_rdp_res_frame);
5238 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize,
5239 lpfc_max_els_tries, rdp_context->ndlp,
5240 rdp_context->ndlp->nlp_DID, ELS_CMD_ACC);
5243 goto free_rdp_context;
5245 icmd = &elsiocb->iocb;
5246 icmd->ulpContext = rdp_context->rx_id;
5247 icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id;
5249 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5250 "2171 Xmit RDP response tag x%x xri x%x, "
5251 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x",
5252 elsiocb->iotag, elsiocb->iocb.ulpContext,
5253 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5255 rdp_res = (struct fc_rdp_res_frame *)
5256 (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5257 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5258 memset(pcmd, 0, sizeof(struct fc_rdp_res_frame));
5259 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5261 /* Update Alarm and Warning */
5262 flag_ptr = (uint16_t *)(rdp_context->page_a2 + SSF_ALARM_FLAGS);
5263 phba->sfp_alarm |= *flag_ptr;
5264 flag_ptr = (uint16_t *)(rdp_context->page_a2 + SSF_WARNING_FLAGS);
5265 phba->sfp_warning |= *flag_ptr;
5267 /* For RDP payload */
5269 len += lpfc_rdp_res_link_service((struct fc_rdp_link_service_desc *)
5270 (len + pcmd), ELS_CMD_RDP);
5272 len += lpfc_rdp_res_sfp_desc((struct fc_rdp_sfp_desc *)(len + pcmd),
5273 rdp_context->page_a0, rdp_context->page_a2);
5274 len += lpfc_rdp_res_speed((struct fc_rdp_port_speed_desc *)(len + pcmd),
5276 len += lpfc_rdp_res_link_error((struct fc_rdp_link_error_status_desc *)
5277 (len + pcmd), &rdp_context->link_stat);
5278 len += lpfc_rdp_res_diag_port_names((struct fc_rdp_port_name_desc *)
5279 (len + pcmd), vport);
5280 len += lpfc_rdp_res_attach_port_names((struct fc_rdp_port_name_desc *)
5281 (len + pcmd), vport, ndlp);
5282 len += lpfc_rdp_res_fec_desc((struct fc_fec_rdp_desc *)(len + pcmd),
5283 &rdp_context->link_stat);
5284 /* Check if nport is logged, BZ190632 */
5285 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED))
5286 goto lpfc_skip_descriptor;
5288 len += lpfc_rdp_res_bbc_desc((struct fc_rdp_bbc_desc *)(len + pcmd),
5289 &rdp_context->link_stat, vport);
5290 len += lpfc_rdp_res_oed_temp_desc(phba,
5291 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5292 rdp_context->page_a2);
5293 len += lpfc_rdp_res_oed_voltage_desc(phba,
5294 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5295 rdp_context->page_a2);
5296 len += lpfc_rdp_res_oed_txbias_desc(phba,
5297 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5298 rdp_context->page_a2);
5299 len += lpfc_rdp_res_oed_txpower_desc(phba,
5300 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5301 rdp_context->page_a2);
5302 len += lpfc_rdp_res_oed_rxpower_desc(phba,
5303 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5304 rdp_context->page_a2);
5305 len += lpfc_rdp_res_opd_desc((struct fc_rdp_opd_sfp_desc *)(len + pcmd),
5306 rdp_context->page_a0, vport);
5308 lpfc_skip_descriptor:
5309 rdp_res->length = cpu_to_be32(len - 8);
5310 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5312 /* Now that we know the true size of the payload, update the BPL */
5313 bpl = (struct ulp_bde64 *)
5314 (((struct lpfc_dmabuf *)(elsiocb->context3))->virt);
5315 bpl->tus.f.bdeSize = len;
5316 bpl->tus.f.bdeFlags = 0;
5317 bpl->tus.w = le32_to_cpu(bpl->tus.w);
5319 phba->fc_stat.elsXmitACC++;
5320 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5321 if (rc == IOCB_ERROR)
5322 lpfc_els_free_iocb(phba, elsiocb);
5328 cmdsize = 2 * sizeof(uint32_t);
5329 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, lpfc_max_els_tries,
5330 ndlp, ndlp->nlp_DID, ELS_CMD_LS_RJT);
5333 goto free_rdp_context;
5335 icmd = &elsiocb->iocb;
5336 icmd->ulpContext = rdp_context->rx_id;
5337 icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id;
5338 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5340 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
5341 stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t));
5342 stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5344 phba->fc_stat.elsXmitLSRJT++;
5345 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5346 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5348 if (rc == IOCB_ERROR)
5349 lpfc_els_free_iocb(phba, elsiocb);
5355 lpfc_get_rdp_info(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context)
5357 LPFC_MBOXQ_t *mbox = NULL;
5360 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5362 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_ELS,
5363 "7105 failed to allocate mailbox memory");
5367 if (lpfc_sli4_dump_page_a0(phba, mbox))
5368 goto prep_mbox_fail;
5369 mbox->vport = rdp_context->ndlp->vport;
5370 mbox->mbox_cmpl = lpfc_mbx_cmpl_rdp_page_a0;
5371 mbox->context2 = (struct lpfc_rdp_context *) rdp_context;
5372 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
5373 if (rc == MBX_NOT_FINISHED)
5374 goto issue_mbox_fail;
5380 mempool_free(mbox, phba->mbox_mem_pool);
5385 * lpfc_els_rcv_rdp - Process an unsolicited RDP ELS.
5386 * @vport: pointer to a host virtual N_Port data structure.
5387 * @cmdiocb: pointer to lpfc command iocb data structure.
5388 * @ndlp: pointer to a node-list data structure.
5390 * This routine processes an unsolicited RDP(Read Diagnostic Parameters)
5391 * IOCB. First, the payload of the unsolicited RDP is checked.
5392 * Then it will (1) send MBX_DUMP_MEMORY, Embedded DMP_LMSD sub command TYPE-3
5393 * for Page A0, (2) send MBX_DUMP_MEMORY, DMP_LMSD for Page A2,
5394 * (3) send MBX_READ_LNK_STAT to get link stat, (4) Call lpfc_els_rdp_cmpl
5395 * gather all data and send RDP response.
5398 * 0 - Sent the acc response
5399 * 1 - Sent the reject response.
5402 lpfc_els_rcv_rdp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5403 struct lpfc_nodelist *ndlp)
5405 struct lpfc_hba *phba = vport->phba;
5406 struct lpfc_dmabuf *pcmd;
5407 uint8_t rjt_err, rjt_expl = LSEXP_NOTHING_MORE;
5408 struct fc_rdp_req_frame *rdp_req;
5409 struct lpfc_rdp_context *rdp_context;
5413 if (phba->sli_rev < LPFC_SLI_REV4 ||
5414 bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
5415 LPFC_SLI_INTF_IF_TYPE_2) {
5416 rjt_err = LSRJT_UNABLE_TPC;
5417 rjt_expl = LSEXP_REQ_UNSUPPORTED;
5421 if (phba->sli_rev < LPFC_SLI_REV4 || (phba->hba_flag & HBA_FCOE_MODE)) {
5422 rjt_err = LSRJT_UNABLE_TPC;
5423 rjt_expl = LSEXP_REQ_UNSUPPORTED;
5427 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5428 rdp_req = (struct fc_rdp_req_frame *) pcmd->virt;
5431 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5432 "2422 ELS RDP Request "
5433 "dec len %d tag x%x port_id %d len %d\n",
5434 be32_to_cpu(rdp_req->rdp_des_length),
5435 be32_to_cpu(rdp_req->nport_id_desc.tag),
5436 be32_to_cpu(rdp_req->nport_id_desc.nport_id),
5437 be32_to_cpu(rdp_req->nport_id_desc.length));
5439 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED) &&
5440 !phba->cfg_enable_SmartSAN) {
5441 rjt_err = LSRJT_UNABLE_TPC;
5442 rjt_expl = LSEXP_PORT_LOGIN_REQ;
5445 if (sizeof(struct fc_rdp_nport_desc) !=
5446 be32_to_cpu(rdp_req->rdp_des_length))
5448 if (RDP_N_PORT_DESC_TAG != be32_to_cpu(rdp_req->nport_id_desc.tag))
5450 if (RDP_NPORT_ID_SIZE !=
5451 be32_to_cpu(rdp_req->nport_id_desc.length))
5453 rdp_context = kzalloc(sizeof(struct lpfc_rdp_context), GFP_KERNEL);
5455 rjt_err = LSRJT_UNABLE_TPC;
5459 cmd = &cmdiocb->iocb;
5460 rdp_context->ndlp = lpfc_nlp_get(ndlp);
5461 rdp_context->ox_id = cmd->unsli3.rcvsli3.ox_id;
5462 rdp_context->rx_id = cmd->ulpContext;
5463 rdp_context->cmpl = lpfc_els_rdp_cmpl;
5464 if (lpfc_get_rdp_info(phba, rdp_context)) {
5465 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_ELS,
5466 "2423 Unable to send mailbox");
5468 rjt_err = LSRJT_UNABLE_TPC;
5476 rjt_err = LSRJT_LOGICAL_ERR;
5479 memset(&stat, 0, sizeof(stat));
5480 stat.un.b.lsRjtRsnCode = rjt_err;
5481 stat.un.b.lsRjtRsnCodeExp = rjt_expl;
5482 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5488 lpfc_els_lcb_rsp(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
5493 struct lpfc_iocbq *elsiocb;
5494 struct lpfc_nodelist *ndlp;
5495 struct ls_rjt *stat;
5496 union lpfc_sli4_cfg_shdr *shdr;
5497 struct lpfc_lcb_context *lcb_context;
5498 struct fc_lcb_res_frame *lcb_res;
5499 uint32_t cmdsize, shdr_status, shdr_add_status;
5503 lcb_context = (struct lpfc_lcb_context *)pmb->context1;
5504 ndlp = lcb_context->ndlp;
5505 pmb->context1 = NULL;
5506 pmb->context2 = NULL;
5508 shdr = (union lpfc_sli4_cfg_shdr *)
5509 &pmb->u.mqe.un.beacon_config.header.cfg_shdr;
5510 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
5511 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
5513 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX,
5514 "0194 SET_BEACON_CONFIG mailbox "
5515 "completed with status x%x add_status x%x,"
5516 " mbx status x%x\n",
5517 shdr_status, shdr_add_status, mb->mbxStatus);
5519 if (mb->mbxStatus && !(shdr_status &&
5520 shdr_add_status == ADD_STATUS_OPERATION_ALREADY_ACTIVE)) {
5521 mempool_free(pmb, phba->mbox_mem_pool);
5525 mempool_free(pmb, phba->mbox_mem_pool);
5526 cmdsize = sizeof(struct fc_lcb_res_frame);
5527 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5528 lpfc_max_els_tries, ndlp,
5529 ndlp->nlp_DID, ELS_CMD_ACC);
5531 /* Decrement the ndlp reference count from previous mbox command */
5535 goto free_lcb_context;
5537 lcb_res = (struct fc_lcb_res_frame *)
5538 (((struct lpfc_dmabuf *)elsiocb->context2)->virt);
5540 icmd = &elsiocb->iocb;
5541 icmd->ulpContext = lcb_context->rx_id;
5542 icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id;
5544 pcmd = (uint8_t *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt);
5545 *((uint32_t *)(pcmd)) = ELS_CMD_ACC;
5546 lcb_res->lcb_sub_command = lcb_context->sub_command;
5547 lcb_res->lcb_type = lcb_context->type;
5548 lcb_res->lcb_frequency = lcb_context->frequency;
5549 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5550 phba->fc_stat.elsXmitACC++;
5551 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5552 if (rc == IOCB_ERROR)
5553 lpfc_els_free_iocb(phba, elsiocb);
5559 cmdsize = sizeof(struct fc_lcb_res_frame);
5560 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5561 lpfc_max_els_tries, ndlp,
5562 ndlp->nlp_DID, ELS_CMD_LS_RJT);
5565 goto free_lcb_context;
5567 icmd = &elsiocb->iocb;
5568 icmd->ulpContext = lcb_context->rx_id;
5569 icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id;
5570 pcmd = (uint8_t *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt);
5572 *((uint32_t *)(pcmd)) = ELS_CMD_LS_RJT;
5573 stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t));
5574 stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5576 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5577 phba->fc_stat.elsXmitLSRJT++;
5578 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5579 if (rc == IOCB_ERROR)
5580 lpfc_els_free_iocb(phba, elsiocb);
5586 lpfc_sli4_set_beacon(struct lpfc_vport *vport,
5587 struct lpfc_lcb_context *lcb_context,
5588 uint32_t beacon_state)
5590 struct lpfc_hba *phba = vport->phba;
5591 LPFC_MBOXQ_t *mbox = NULL;
5595 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5599 len = sizeof(struct lpfc_mbx_set_beacon_config) -
5600 sizeof(struct lpfc_sli4_cfg_mhdr);
5601 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
5602 LPFC_MBOX_OPCODE_SET_BEACON_CONFIG, len,
5603 LPFC_SLI4_MBX_EMBED);
5604 mbox->context1 = (void *)lcb_context;
5605 mbox->vport = phba->pport;
5606 mbox->mbox_cmpl = lpfc_els_lcb_rsp;
5607 bf_set(lpfc_mbx_set_beacon_port_num, &mbox->u.mqe.un.beacon_config,
5608 phba->sli4_hba.physical_port);
5609 bf_set(lpfc_mbx_set_beacon_state, &mbox->u.mqe.un.beacon_config,
5611 bf_set(lpfc_mbx_set_beacon_port_type, &mbox->u.mqe.un.beacon_config, 1);
5612 bf_set(lpfc_mbx_set_beacon_duration, &mbox->u.mqe.un.beacon_config, 0);
5613 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
5614 if (rc == MBX_NOT_FINISHED) {
5615 mempool_free(mbox, phba->mbox_mem_pool);
5624 * lpfc_els_rcv_lcb - Process an unsolicited LCB
5625 * @vport: pointer to a host virtual N_Port data structure.
5626 * @cmdiocb: pointer to lpfc command iocb data structure.
5627 * @ndlp: pointer to a node-list data structure.
5629 * This routine processes an unsolicited LCB(LINK CABLE BEACON) IOCB.
5630 * First, the payload of the unsolicited LCB is checked.
5631 * Then based on Subcommand beacon will either turn on or off.
5634 * 0 - Sent the acc response
5635 * 1 - Sent the reject response.
5638 lpfc_els_rcv_lcb(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5639 struct lpfc_nodelist *ndlp)
5641 struct lpfc_hba *phba = vport->phba;
5642 struct lpfc_dmabuf *pcmd;
5644 struct fc_lcb_request_frame *beacon;
5645 struct lpfc_lcb_context *lcb_context;
5646 uint8_t state, rjt_err;
5649 pcmd = (struct lpfc_dmabuf *)cmdiocb->context2;
5650 lp = (uint8_t *)pcmd->virt;
5651 beacon = (struct fc_lcb_request_frame *)pcmd->virt;
5653 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5654 "0192 ELS LCB Data x%x x%x x%x x%x sub x%x "
5655 "type x%x frequency %x duration x%x\n",
5656 lp[0], lp[1], lp[2],
5657 beacon->lcb_command,
5658 beacon->lcb_sub_command,
5660 beacon->lcb_frequency,
5661 be16_to_cpu(beacon->lcb_duration));
5663 if (phba->sli_rev < LPFC_SLI_REV4 ||
5664 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
5665 LPFC_SLI_INTF_IF_TYPE_2)) {
5666 rjt_err = LSRJT_CMD_UNSUPPORTED;
5670 if (phba->hba_flag & HBA_FCOE_MODE) {
5671 rjt_err = LSRJT_CMD_UNSUPPORTED;
5674 if (beacon->lcb_frequency == 0) {
5675 rjt_err = LSRJT_CMD_UNSUPPORTED;
5678 if ((beacon->lcb_type != LPFC_LCB_GREEN) &&
5679 (beacon->lcb_type != LPFC_LCB_AMBER)) {
5680 rjt_err = LSRJT_CMD_UNSUPPORTED;
5683 if ((beacon->lcb_sub_command != LPFC_LCB_ON) &&
5684 (beacon->lcb_sub_command != LPFC_LCB_OFF)) {
5685 rjt_err = LSRJT_CMD_UNSUPPORTED;
5688 if ((beacon->lcb_sub_command == LPFC_LCB_ON) &&
5689 (beacon->lcb_type != LPFC_LCB_GREEN) &&
5690 (beacon->lcb_type != LPFC_LCB_AMBER)) {
5691 rjt_err = LSRJT_CMD_UNSUPPORTED;
5694 if (be16_to_cpu(beacon->lcb_duration) != 0) {
5695 rjt_err = LSRJT_CMD_UNSUPPORTED;
5699 lcb_context = kmalloc(sizeof(*lcb_context), GFP_KERNEL);
5701 rjt_err = LSRJT_UNABLE_TPC;
5705 state = (beacon->lcb_sub_command == LPFC_LCB_ON) ? 1 : 0;
5706 lcb_context->sub_command = beacon->lcb_sub_command;
5707 lcb_context->type = beacon->lcb_type;
5708 lcb_context->frequency = beacon->lcb_frequency;
5709 lcb_context->ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id;
5710 lcb_context->rx_id = cmdiocb->iocb.ulpContext;
5711 lcb_context->ndlp = lpfc_nlp_get(ndlp);
5712 if (lpfc_sli4_set_beacon(vport, lcb_context, state)) {
5713 lpfc_printf_vlog(ndlp->vport, KERN_ERR,
5714 LOG_ELS, "0193 failed to send mail box");
5717 rjt_err = LSRJT_UNABLE_TPC;
5722 memset(&stat, 0, sizeof(stat));
5723 stat.un.b.lsRjtRsnCode = rjt_err;
5724 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5730 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
5731 * @vport: pointer to a host virtual N_Port data structure.
5733 * This routine cleans up any Registration State Change Notification
5734 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
5735 * @vport together with the host_lock is used to prevent multiple thread
5736 * trying to access the RSCN array on a same @vport at the same time.
5739 lpfc_els_flush_rscn(struct lpfc_vport *vport)
5741 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5742 struct lpfc_hba *phba = vport->phba;
5745 spin_lock_irq(shost->host_lock);
5746 if (vport->fc_rscn_flush) {
5747 /* Another thread is walking fc_rscn_id_list on this vport */
5748 spin_unlock_irq(shost->host_lock);
5751 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
5752 vport->fc_rscn_flush = 1;
5753 spin_unlock_irq(shost->host_lock);
5755 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
5756 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
5757 vport->fc_rscn_id_list[i] = NULL;
5759 spin_lock_irq(shost->host_lock);
5760 vport->fc_rscn_id_cnt = 0;
5761 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
5762 spin_unlock_irq(shost->host_lock);
5763 lpfc_can_disctmo(vport);
5764 /* Indicate we are done walking this fc_rscn_id_list */
5765 vport->fc_rscn_flush = 0;
5769 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
5770 * @vport: pointer to a host virtual N_Port data structure.
5771 * @did: remote destination port identifier.
5773 * This routine checks whether there is any pending Registration State
5774 * Configuration Notification (RSCN) to a @did on @vport.
5777 * None zero - The @did matched with a pending rscn
5778 * 0 - not able to match @did with a pending rscn
5781 lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
5786 uint32_t payload_len, i;
5787 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5789 ns_did.un.word = did;
5791 /* Never match fabric nodes for RSCNs */
5792 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
5795 /* If we are doing a FULL RSCN rediscovery, match everything */
5796 if (vport->fc_flag & FC_RSCN_DISCOVERY)
5799 spin_lock_irq(shost->host_lock);
5800 if (vport->fc_rscn_flush) {
5801 /* Another thread is walking fc_rscn_id_list on this vport */
5802 spin_unlock_irq(shost->host_lock);
5805 /* Indicate we are walking fc_rscn_id_list on this vport */
5806 vport->fc_rscn_flush = 1;
5807 spin_unlock_irq(shost->host_lock);
5808 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
5809 lp = vport->fc_rscn_id_list[i]->virt;
5810 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
5811 payload_len -= sizeof(uint32_t); /* take off word 0 */
5812 while (payload_len) {
5813 rscn_did.un.word = be32_to_cpu(*lp++);
5814 payload_len -= sizeof(uint32_t);
5815 switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) {
5816 case RSCN_ADDRESS_FORMAT_PORT:
5817 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
5818 && (ns_did.un.b.area == rscn_did.un.b.area)
5819 && (ns_did.un.b.id == rscn_did.un.b.id))
5820 goto return_did_out;
5822 case RSCN_ADDRESS_FORMAT_AREA:
5823 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
5824 && (ns_did.un.b.area == rscn_did.un.b.area))
5825 goto return_did_out;
5827 case RSCN_ADDRESS_FORMAT_DOMAIN:
5828 if (ns_did.un.b.domain == rscn_did.un.b.domain)
5829 goto return_did_out;
5831 case RSCN_ADDRESS_FORMAT_FABRIC:
5832 goto return_did_out;
5836 /* Indicate we are done with walking fc_rscn_id_list on this vport */
5837 vport->fc_rscn_flush = 0;
5840 /* Indicate we are done with walking fc_rscn_id_list on this vport */
5841 vport->fc_rscn_flush = 0;
5846 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
5847 * @vport: pointer to a host virtual N_Port data structure.
5849 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
5850 * state machine for a @vport's nodes that are with pending RSCN (Registration
5851 * State Change Notification).
5854 * 0 - Successful (currently alway return 0)
5857 lpfc_rscn_recovery_check(struct lpfc_vport *vport)
5859 struct lpfc_nodelist *ndlp = NULL;
5861 /* Move all affected nodes by pending RSCNs to NPR state. */
5862 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
5863 if (!NLP_CHK_NODE_ACT(ndlp) ||
5864 (ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
5865 !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
5868 /* NVME Target mode does not do RSCN Recovery. */
5869 if (vport->phba->nvmet_support)
5872 lpfc_disc_state_machine(vport, ndlp, NULL,
5873 NLP_EVT_DEVICE_RECOVERY);
5874 lpfc_cancel_retry_delay_tmo(vport, ndlp);
5880 * lpfc_send_rscn_event - Send an RSCN event to management application
5881 * @vport: pointer to a host virtual N_Port data structure.
5882 * @cmdiocb: pointer to lpfc command iocb data structure.
5884 * lpfc_send_rscn_event sends an RSCN netlink event to management
5888 lpfc_send_rscn_event(struct lpfc_vport *vport,
5889 struct lpfc_iocbq *cmdiocb)
5891 struct lpfc_dmabuf *pcmd;
5892 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5893 uint32_t *payload_ptr;
5894 uint32_t payload_len;
5895 struct lpfc_rscn_event_header *rscn_event_data;
5897 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5898 payload_ptr = (uint32_t *) pcmd->virt;
5899 payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK);
5901 rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) +
5902 payload_len, GFP_KERNEL);
5903 if (!rscn_event_data) {
5904 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5905 "0147 Failed to allocate memory for RSCN event\n");
5908 rscn_event_data->event_type = FC_REG_RSCN_EVENT;
5909 rscn_event_data->payload_length = payload_len;
5910 memcpy(rscn_event_data->rscn_payload, payload_ptr,
5913 fc_host_post_vendor_event(shost,
5914 fc_get_event_number(),
5915 sizeof(struct lpfc_rscn_event_header) + payload_len,
5916 (char *)rscn_event_data,
5919 kfree(rscn_event_data);
5923 * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
5924 * @vport: pointer to a host virtual N_Port data structure.
5925 * @cmdiocb: pointer to lpfc command iocb data structure.
5926 * @ndlp: pointer to a node-list data structure.
5928 * This routine processes an unsolicited RSCN (Registration State Change
5929 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
5930 * to invoke fc_host_post_event() routine to the FC transport layer. If the
5931 * discover state machine is about to begin discovery, it just accepts the
5932 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
5933 * contains N_Port IDs for other vports on this HBA, it just accepts the
5934 * RSCN and ignore processing it. If the state machine is in the recovery
5935 * state, the fc_rscn_id_list of this @vport is walked and the
5936 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
5937 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
5938 * routine is invoked to handle the RSCN event.
5941 * 0 - Just sent the acc response
5942 * 1 - Sent the acc response and waited for name server completion
5945 lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5946 struct lpfc_nodelist *ndlp)
5948 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5949 struct lpfc_hba *phba = vport->phba;
5950 struct lpfc_dmabuf *pcmd;
5951 uint32_t *lp, *datap;
5952 uint32_t payload_len, length, nportid, *cmd;
5954 int rscn_id = 0, hba_id = 0;
5957 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5958 lp = (uint32_t *) pcmd->virt;
5960 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
5961 payload_len -= sizeof(uint32_t); /* take off word 0 */
5963 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5964 "0214 RSCN received Data: x%x x%x x%x x%x\n",
5965 vport->fc_flag, payload_len, *lp,
5966 vport->fc_rscn_id_cnt);
5968 /* Send an RSCN event to the management application */
5969 lpfc_send_rscn_event(vport, cmdiocb);
5971 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
5972 fc_host_post_event(shost, fc_get_event_number(),
5973 FCH_EVT_RSCN, lp[i]);
5975 /* If we are about to begin discovery, just ACC the RSCN.
5976 * Discovery processing will satisfy it.
5978 if (vport->port_state <= LPFC_NS_QRY) {
5979 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5980 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
5981 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
5983 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
5987 /* If this RSCN just contains NPortIDs for other vports on this HBA,
5988 * just ACC and ignore it.
5990 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
5991 !(vport->cfg_peer_port_login)) {
5996 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
5997 i -= sizeof(uint32_t);
5999 if (lpfc_find_vport_by_did(phba, nportid))
6002 if (rscn_id == hba_id) {
6003 /* ALL NPortIDs in RSCN are on HBA */
6004 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6006 "Data: x%x x%x x%x x%x\n",
6007 vport->fc_flag, payload_len,
6008 *lp, vport->fc_rscn_id_cnt);
6009 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6010 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
6011 ndlp->nlp_DID, vport->port_state,
6014 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
6020 spin_lock_irq(shost->host_lock);
6021 if (vport->fc_rscn_flush) {
6022 /* Another thread is walking fc_rscn_id_list on this vport */
6023 vport->fc_flag |= FC_RSCN_DISCOVERY;
6024 spin_unlock_irq(shost->host_lock);
6026 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
6029 /* Indicate we are walking fc_rscn_id_list on this vport */
6030 vport->fc_rscn_flush = 1;
6031 spin_unlock_irq(shost->host_lock);
6032 /* Get the array count after successfully have the token */
6033 rscn_cnt = vport->fc_rscn_id_cnt;
6034 /* If we are already processing an RSCN, save the received
6035 * RSCN payload buffer, cmdiocb->context2 to process later.
6037 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
6038 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6039 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
6040 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
6042 spin_lock_irq(shost->host_lock);
6043 vport->fc_flag |= FC_RSCN_DEFERRED;
6044 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
6045 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
6046 vport->fc_flag |= FC_RSCN_MODE;
6047 spin_unlock_irq(shost->host_lock);
6049 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
6050 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
6053 (payload_len + length <= LPFC_BPL_SIZE)) {
6054 *cmd &= ELS_CMD_MASK;
6055 *cmd |= cpu_to_be32(payload_len + length);
6056 memcpy(((uint8_t *)cmd) + length, lp,
6059 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
6060 vport->fc_rscn_id_cnt++;
6061 /* If we zero, cmdiocb->context2, the calling
6062 * routine will not try to free it.
6064 cmdiocb->context2 = NULL;
6067 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6068 "0235 Deferred RSCN "
6069 "Data: x%x x%x x%x\n",
6070 vport->fc_rscn_id_cnt, vport->fc_flag,
6073 vport->fc_flag |= FC_RSCN_DISCOVERY;
6074 spin_unlock_irq(shost->host_lock);
6075 /* ReDiscovery RSCN */
6076 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6077 "0234 ReDiscovery RSCN "
6078 "Data: x%x x%x x%x\n",
6079 vport->fc_rscn_id_cnt, vport->fc_flag,
6082 /* Indicate we are done walking fc_rscn_id_list on this vport */
6083 vport->fc_rscn_flush = 0;
6085 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
6086 /* send RECOVERY event for ALL nodes that match RSCN payload */
6087 lpfc_rscn_recovery_check(vport);
6088 spin_lock_irq(shost->host_lock);
6089 vport->fc_flag &= ~FC_RSCN_DEFERRED;
6090 spin_unlock_irq(shost->host_lock);
6093 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6094 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
6095 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
6097 spin_lock_irq(shost->host_lock);
6098 vport->fc_flag |= FC_RSCN_MODE;
6099 spin_unlock_irq(shost->host_lock);
6100 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
6101 /* Indicate we are done walking fc_rscn_id_list on this vport */
6102 vport->fc_rscn_flush = 0;
6104 * If we zero, cmdiocb->context2, the calling routine will
6105 * not try to free it.
6107 cmdiocb->context2 = NULL;
6108 lpfc_set_disctmo(vport);
6110 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
6111 /* send RECOVERY event for ALL nodes that match RSCN payload */
6112 lpfc_rscn_recovery_check(vport);
6113 return lpfc_els_handle_rscn(vport);
6117 * lpfc_els_handle_rscn - Handle rscn for a vport
6118 * @vport: pointer to a host virtual N_Port data structure.
6120 * This routine handles the Registration State Configuration Notification
6121 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
6122 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
6123 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
6124 * NameServer shall be issued. If CT command to the NameServer fails to be
6125 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
6126 * RSCN activities with the @vport.
6129 * 0 - Cleaned up rscn on the @vport
6130 * 1 - Wait for plogi to name server before proceed
6133 lpfc_els_handle_rscn(struct lpfc_vport *vport)
6135 struct lpfc_nodelist *ndlp;
6137 /* Ignore RSCN if the port is being torn down. */
6138 if (vport->load_flag & FC_UNLOADING) {
6139 lpfc_els_flush_rscn(vport);
6143 /* Start timer for RSCN processing */
6144 lpfc_set_disctmo(vport);
6146 /* RSCN processed */
6147 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6148 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
6149 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
6152 /* To process RSCN, first compare RSCN data with NameServer */
6153 vport->fc_ns_retry = 0;
6154 vport->num_disc_nodes = 0;
6156 ndlp = lpfc_findnode_did(vport, NameServer_DID);
6157 if (ndlp && NLP_CHK_NODE_ACT(ndlp)
6158 && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
6159 /* Good ndlp, issue CT Request to NameServer. Need to
6160 * know how many gidfts were issued. If none, then just
6161 * flush the RSCN. Otherwise, the outstanding requests
6164 vport->gidft_inp = 0;
6165 if (lpfc_issue_gidft(vport) > 0)
6168 /* Nameserver login in question. Revalidate. */
6170 ndlp = lpfc_enable_node(vport, ndlp,
6171 NLP_STE_PLOGI_ISSUE);
6173 lpfc_els_flush_rscn(vport);
6176 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
6178 ndlp = lpfc_nlp_init(vport, NameServer_DID);
6180 lpfc_els_flush_rscn(vport);
6183 ndlp->nlp_prev_state = ndlp->nlp_state;
6184 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
6186 ndlp->nlp_type |= NLP_FABRIC;
6187 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
6188 /* Wait for NameServer login cmpl before we can
6194 lpfc_els_flush_rscn(vport);
6199 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
6200 * @vport: pointer to a host virtual N_Port data structure.
6201 * @cmdiocb: pointer to lpfc command iocb data structure.
6202 * @ndlp: pointer to a node-list data structure.
6204 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
6205 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
6206 * point topology. As an unsolicited FLOGI should not be received in a loop
6207 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
6208 * lpfc_check_sparm() routine is invoked to check the parameters in the
6209 * unsolicited FLOGI. If parameters validation failed, the routine
6210 * lpfc_els_rsp_reject() shall be called with reject reason code set to
6211 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
6212 * FLOGI shall be compared with the Port WWN of the @vport to determine who
6213 * will initiate PLOGI. The higher lexicographical value party shall has
6214 * higher priority (as the winning port) and will initiate PLOGI and
6215 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
6216 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
6217 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
6220 * 0 - Successfully processed the unsolicited flogi
6221 * 1 - Failed to process the unsolicited flogi
6224 lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6225 struct lpfc_nodelist *ndlp)
6227 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6228 struct lpfc_hba *phba = vport->phba;
6229 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6230 uint32_t *lp = (uint32_t *) pcmd->virt;
6231 IOCB_t *icmd = &cmdiocb->iocb;
6232 struct serv_parm *sp;
6236 uint32_t fc_flag = 0;
6237 uint32_t port_state = 0;
6240 sp = (struct serv_parm *) lp;
6242 /* FLOGI received */
6244 lpfc_set_disctmo(vport);
6246 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
6247 /* We should never receive a FLOGI in loop mode, ignore it */
6248 did = icmd->un.elsreq64.remoteID;
6250 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
6252 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6253 "0113 An FLOGI ELS command x%x was "
6254 "received from DID x%x in Loop Mode\n",
6259 (void) lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1);
6262 * If our portname is greater than the remote portname,
6263 * then we initiate Nport login.
6266 rc = memcmp(&vport->fc_portname, &sp->portName,
6267 sizeof(struct lpfc_name));
6270 if (phba->sli_rev < LPFC_SLI_REV4) {
6271 mbox = mempool_alloc(phba->mbox_mem_pool,
6275 lpfc_linkdown(phba);
6276 lpfc_init_link(phba, mbox,
6278 phba->cfg_link_speed);
6279 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
6280 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
6281 mbox->vport = vport;
6282 rc = lpfc_sli_issue_mbox(phba, mbox,
6284 lpfc_set_loopback_flag(phba);
6285 if (rc == MBX_NOT_FINISHED)
6286 mempool_free(mbox, phba->mbox_mem_pool);
6290 /* abort the flogi coming back to ourselves
6291 * due to external loopback on the port.
6293 lpfc_els_abort_flogi(phba);
6296 } else if (rc > 0) { /* greater than */
6297 spin_lock_irq(shost->host_lock);
6298 vport->fc_flag |= FC_PT2PT_PLOGI;
6299 spin_unlock_irq(shost->host_lock);
6301 /* If we have the high WWPN we can assign our own
6302 * myDID; otherwise, we have to WAIT for a PLOGI
6303 * from the remote NPort to find out what it
6306 vport->fc_myDID = PT2PT_LocalID;
6308 vport->fc_myDID = PT2PT_RemoteID;
6312 * The vport state should go to LPFC_FLOGI only
6313 * AFTER we issue a FLOGI, not receive one.
6315 spin_lock_irq(shost->host_lock);
6316 fc_flag = vport->fc_flag;
6317 port_state = vport->port_state;
6318 vport->fc_flag |= FC_PT2PT;
6319 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
6320 spin_unlock_irq(shost->host_lock);
6321 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6322 "3311 Rcv Flogi PS x%x new PS x%x "
6323 "fc_flag x%x new fc_flag x%x\n",
6324 port_state, vport->port_state,
6325 fc_flag, vport->fc_flag);
6328 * We temporarily set fc_myDID to make it look like we are
6329 * a Fabric. This is done just so we end up with the right
6330 * did / sid on the FLOGI ACC rsp.
6332 did = vport->fc_myDID;
6333 vport->fc_myDID = Fabric_DID;
6335 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
6338 lpfc_els_rsp_acc(vport, ELS_CMD_FLOGI, cmdiocb, ndlp, NULL);
6340 /* Now lets put fc_myDID back to what its supposed to be */
6341 vport->fc_myDID = did;
6347 * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
6348 * @vport: pointer to a host virtual N_Port data structure.
6349 * @cmdiocb: pointer to lpfc command iocb data structure.
6350 * @ndlp: pointer to a node-list data structure.
6352 * This routine processes Request Node Identification Data (RNID) IOCB
6353 * received as an ELS unsolicited event. Only when the RNID specified format
6354 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
6355 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
6356 * Accept (ACC) the RNID ELS command. All the other RNID formats are
6357 * rejected by invoking the lpfc_els_rsp_reject() routine.
6360 * 0 - Successfully processed rnid iocb (currently always return 0)
6363 lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6364 struct lpfc_nodelist *ndlp)
6366 struct lpfc_dmabuf *pcmd;
6372 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6373 lp = (uint32_t *) pcmd->virt;
6380 switch (rn->Format) {
6382 case RNID_TOPOLOGY_DISC:
6384 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
6387 /* Reject this request because format not supported */
6388 stat.un.b.lsRjtRsvd0 = 0;
6389 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6390 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
6391 stat.un.b.vendorUnique = 0;
6392 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
6399 * lpfc_els_rcv_echo - Process an unsolicited echo iocb
6400 * @vport: pointer to a host virtual N_Port data structure.
6401 * @cmdiocb: pointer to lpfc command iocb data structure.
6402 * @ndlp: pointer to a node-list data structure.
6405 * 0 - Successfully processed echo iocb (currently always return 0)
6408 lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6409 struct lpfc_nodelist *ndlp)
6413 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
6415 /* skip over first word of echo command to find echo data */
6416 pcmd += sizeof(uint32_t);
6418 lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp);
6423 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
6424 * @vport: pointer to a host virtual N_Port data structure.
6425 * @cmdiocb: pointer to lpfc command iocb data structure.
6426 * @ndlp: pointer to a node-list data structure.
6428 * This routine processes a Link Incident Report Registration(LIRR) IOCB
6429 * received as an ELS unsolicited event. Currently, this function just invokes
6430 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
6433 * 0 - Successfully processed lirr iocb (currently always return 0)
6436 lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6437 struct lpfc_nodelist *ndlp)
6441 /* For now, unconditionally reject this command */
6442 stat.un.b.lsRjtRsvd0 = 0;
6443 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6444 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
6445 stat.un.b.vendorUnique = 0;
6446 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
6451 * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb
6452 * @vport: pointer to a host virtual N_Port data structure.
6453 * @cmdiocb: pointer to lpfc command iocb data structure.
6454 * @ndlp: pointer to a node-list data structure.
6456 * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB
6457 * received as an ELS unsolicited event. A request to RRQ shall only
6458 * be accepted if the Originator Nx_Port N_Port_ID or the Responder
6459 * Nx_Port N_Port_ID of the target Exchange is the same as the
6460 * N_Port_ID of the Nx_Port that makes the request. If the RRQ is
6461 * not accepted, an LS_RJT with reason code "Unable to perform
6462 * command request" and reason code explanation "Invalid Originator
6463 * S_ID" shall be returned. For now, we just unconditionally accept
6464 * RRQ from the target.
6467 lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6468 struct lpfc_nodelist *ndlp)
6470 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
6471 if (vport->phba->sli_rev == LPFC_SLI_REV4)
6472 lpfc_els_clear_rrq(vport, cmdiocb, ndlp);
6476 * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
6477 * @phba: pointer to lpfc hba data structure.
6478 * @pmb: pointer to the driver internal queue element for mailbox command.
6480 * This routine is the completion callback function for the MBX_READ_LNK_STAT
6481 * mailbox command. This callback function is to actually send the Accept
6482 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
6483 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
6484 * mailbox command, constructs the RPS response with the link statistics
6485 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
6486 * response to the RPS.
6488 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6489 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6490 * will be stored into the context1 field of the IOCB for the completion
6491 * callback function to the RPS Accept Response ELS IOCB command.
6495 lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
6499 struct RLS_RSP *rls_rsp;
6501 struct lpfc_iocbq *elsiocb;
6502 struct lpfc_nodelist *ndlp;
6509 ndlp = (struct lpfc_nodelist *) pmb->context2;
6510 rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff);
6511 oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff);
6512 pmb->context1 = NULL;
6513 pmb->context2 = NULL;
6515 if (mb->mbxStatus) {
6516 mempool_free(pmb, phba->mbox_mem_pool);
6520 cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t);
6521 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
6522 lpfc_max_els_tries, ndlp,
6523 ndlp->nlp_DID, ELS_CMD_ACC);
6525 /* Decrement the ndlp reference count from previous mbox command */
6529 mempool_free(pmb, phba->mbox_mem_pool);
6533 icmd = &elsiocb->iocb;
6534 icmd->ulpContext = rxid;
6535 icmd->unsli3.rcvsli3.ox_id = oxid;
6537 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6538 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
6539 pcmd += sizeof(uint32_t); /* Skip past command */
6540 rls_rsp = (struct RLS_RSP *)pcmd;
6542 rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
6543 rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
6544 rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
6545 rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
6546 rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
6547 rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
6548 mempool_free(pmb, phba->mbox_mem_pool);
6549 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
6550 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
6551 "2874 Xmit ELS RLS ACC response tag x%x xri x%x, "
6552 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
6553 elsiocb->iotag, elsiocb->iocb.ulpContext,
6554 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
6556 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
6557 phba->fc_stat.elsXmitACC++;
6558 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
6559 lpfc_els_free_iocb(phba, elsiocb);
6563 * lpfc_els_rsp_rps_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
6564 * @phba: pointer to lpfc hba data structure.
6565 * @pmb: pointer to the driver internal queue element for mailbox command.
6567 * This routine is the completion callback function for the MBX_READ_LNK_STAT
6568 * mailbox command. This callback function is to actually send the Accept
6569 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
6570 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
6571 * mailbox command, constructs the RPS response with the link statistics
6572 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
6573 * response to the RPS.
6575 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6576 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6577 * will be stored into the context1 field of the IOCB for the completion
6578 * callback function to the RPS Accept Response ELS IOCB command.
6582 lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
6588 struct lpfc_iocbq *elsiocb;
6589 struct lpfc_nodelist *ndlp;
6597 ndlp = (struct lpfc_nodelist *) pmb->context2;
6598 rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff);
6599 oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff);
6600 pmb->context1 = NULL;
6601 pmb->context2 = NULL;
6603 if (mb->mbxStatus) {
6604 mempool_free(pmb, phba->mbox_mem_pool);
6608 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
6609 mempool_free(pmb, phba->mbox_mem_pool);
6610 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
6611 lpfc_max_els_tries, ndlp,
6612 ndlp->nlp_DID, ELS_CMD_ACC);
6614 /* Decrement the ndlp reference count from previous mbox command */
6620 icmd = &elsiocb->iocb;
6621 icmd->ulpContext = rxid;
6622 icmd->unsli3.rcvsli3.ox_id = oxid;
6624 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6625 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
6626 pcmd += sizeof(uint32_t); /* Skip past command */
6627 rps_rsp = (RPS_RSP *)pcmd;
6629 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP)
6633 if (phba->pport->fc_flag & FC_FABRIC)
6637 rps_rsp->portStatus = cpu_to_be16(status);
6638 rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
6639 rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
6640 rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
6641 rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
6642 rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
6643 rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
6644 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
6645 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
6646 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
6647 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
6648 elsiocb->iotag, elsiocb->iocb.ulpContext,
6649 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
6651 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
6652 phba->fc_stat.elsXmitACC++;
6653 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
6654 lpfc_els_free_iocb(phba, elsiocb);
6659 * lpfc_els_rcv_rls - Process an unsolicited rls iocb
6660 * @vport: pointer to a host virtual N_Port data structure.
6661 * @cmdiocb: pointer to lpfc command iocb data structure.
6662 * @ndlp: pointer to a node-list data structure.
6664 * This routine processes Read Port Status (RPL) IOCB received as an
6665 * ELS unsolicited event. It first checks the remote port state. If the
6666 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
6667 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
6668 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
6669 * for reading the HBA link statistics. It is for the callback function,
6670 * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command
6671 * to actually sending out RPL Accept (ACC) response.
6674 * 0 - Successfully processed rls iocb (currently always return 0)
6677 lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6678 struct lpfc_nodelist *ndlp)
6680 struct lpfc_hba *phba = vport->phba;
6684 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
6685 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
6686 /* reject the unsolicited RPS request and done with it */
6689 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
6691 lpfc_read_lnk_stat(phba, mbox);
6692 mbox->context1 = (void *)((unsigned long)
6693 ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) |
6694 cmdiocb->iocb.ulpContext)); /* rx_id */
6695 mbox->context2 = lpfc_nlp_get(ndlp);
6696 mbox->vport = vport;
6697 mbox->mbox_cmpl = lpfc_els_rsp_rls_acc;
6698 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
6699 != MBX_NOT_FINISHED)
6700 /* Mbox completion will send ELS Response */
6702 /* Decrement reference count used for the failed mbox
6706 mempool_free(mbox, phba->mbox_mem_pool);
6709 /* issue rejection response */
6710 stat.un.b.lsRjtRsvd0 = 0;
6711 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6712 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
6713 stat.un.b.vendorUnique = 0;
6714 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
6719 * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb
6720 * @vport: pointer to a host virtual N_Port data structure.
6721 * @cmdiocb: pointer to lpfc command iocb data structure.
6722 * @ndlp: pointer to a node-list data structure.
6724 * This routine processes Read Timout Value (RTV) IOCB received as an
6725 * ELS unsolicited event. It first checks the remote port state. If the
6726 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
6727 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
6728 * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout
6729 * Value (RTV) unsolicited IOCB event.
6731 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6732 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6733 * will be stored into the context1 field of the IOCB for the completion
6734 * callback function to the RPS Accept Response ELS IOCB command.
6737 * 0 - Successfully processed rtv iocb (currently always return 0)
6740 lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6741 struct lpfc_nodelist *ndlp)
6743 struct lpfc_hba *phba = vport->phba;
6745 struct RTV_RSP *rtv_rsp;
6747 struct lpfc_iocbq *elsiocb;
6751 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
6752 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
6753 /* reject the unsolicited RPS request and done with it */
6756 cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t);
6757 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
6758 lpfc_max_els_tries, ndlp,
6759 ndlp->nlp_DID, ELS_CMD_ACC);
6764 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6765 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
6766 pcmd += sizeof(uint32_t); /* Skip past command */
6768 /* use the command's xri in the response */
6769 elsiocb->iocb.ulpContext = cmdiocb->iocb.ulpContext; /* Xri / rx_id */
6770 elsiocb->iocb.unsli3.rcvsli3.ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id;
6772 rtv_rsp = (struct RTV_RSP *)pcmd;
6774 /* populate RTV payload */
6775 rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000); /* report msecs */
6776 rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov);
6777 bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0);
6778 bf_set(qtov_rttov, rtv_rsp, 0); /* Field is for FC ONLY */
6779 rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov);
6781 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
6782 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
6783 "2875 Xmit ELS RTV ACC response tag x%x xri x%x, "
6784 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, "
6785 "Data: x%x x%x x%x\n",
6786 elsiocb->iotag, elsiocb->iocb.ulpContext,
6787 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
6789 rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov);
6790 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
6791 phba->fc_stat.elsXmitACC++;
6792 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
6793 lpfc_els_free_iocb(phba, elsiocb);
6797 /* issue rejection response */
6798 stat.un.b.lsRjtRsvd0 = 0;
6799 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6800 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
6801 stat.un.b.vendorUnique = 0;
6802 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
6806 /* lpfc_els_rcv_rps - Process an unsolicited rps iocb
6807 * @vport: pointer to a host virtual N_Port data structure.
6808 * @cmdiocb: pointer to lpfc command iocb data structure.
6809 * @ndlp: pointer to a node-list data structure.
6811 * This routine processes Read Port Status (RPS) IOCB received as an
6812 * ELS unsolicited event. It first checks the remote port state. If the
6813 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
6814 * state, it invokes the lpfc_els_rsp_reject() routine to send the reject
6815 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
6816 * for reading the HBA link statistics. It is for the callback function,
6817 * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command
6818 * to actually sending out RPS Accept (ACC) response.
6821 * 0 - Successfully processed rps iocb (currently always return 0)
6824 lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6825 struct lpfc_nodelist *ndlp)
6827 struct lpfc_hba *phba = vport->phba;
6831 struct lpfc_dmabuf *pcmd;
6835 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
6836 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
6837 /* reject the unsolicited RPS request and done with it */
6840 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6841 lp = (uint32_t *) pcmd->virt;
6842 flag = (be32_to_cpu(*lp++) & 0xf);
6846 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
6847 ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
6848 sizeof(struct lpfc_name)) == 0))) {
6850 printk("Fix me....\n");
6852 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
6854 lpfc_read_lnk_stat(phba, mbox);
6855 mbox->context1 = (void *)((unsigned long)
6856 ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) |
6857 cmdiocb->iocb.ulpContext)); /* rx_id */
6858 mbox->context2 = lpfc_nlp_get(ndlp);
6859 mbox->vport = vport;
6860 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
6861 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
6862 != MBX_NOT_FINISHED)
6863 /* Mbox completion will send ELS Response */
6865 /* Decrement reference count used for the failed mbox
6869 mempool_free(mbox, phba->mbox_mem_pool);
6874 /* issue rejection response */
6875 stat.un.b.lsRjtRsvd0 = 0;
6876 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6877 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
6878 stat.un.b.vendorUnique = 0;
6879 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
6883 /* lpfc_issue_els_rrq - Process an unsolicited rps iocb
6884 * @vport: pointer to a host virtual N_Port data structure.
6885 * @ndlp: pointer to a node-list data structure.
6886 * @did: DID of the target.
6887 * @rrq: Pointer to the rrq struct.
6889 * Build a ELS RRQ command and send it to the target. If the issue_iocb is
6890 * Successful the the completion handler will clear the RRQ.
6893 * 0 - Successfully sent rrq els iocb.
6894 * 1 - Failed to send rrq els iocb.
6897 lpfc_issue_els_rrq(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
6898 uint32_t did, struct lpfc_node_rrq *rrq)
6900 struct lpfc_hba *phba = vport->phba;
6901 struct RRQ *els_rrq;
6902 struct lpfc_iocbq *elsiocb;
6908 if (ndlp != rrq->ndlp)
6910 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
6913 /* If ndlp is not NULL, we will bump the reference count on it */
6914 cmdsize = (sizeof(uint32_t) + sizeof(struct RRQ));
6915 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, did,
6920 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6922 /* For RRQ request, remainder of payload is Exchange IDs */
6923 *((uint32_t *) (pcmd)) = ELS_CMD_RRQ;
6924 pcmd += sizeof(uint32_t);
6925 els_rrq = (struct RRQ *) pcmd;
6927 bf_set(rrq_oxid, els_rrq, phba->sli4_hba.xri_ids[rrq->xritag]);
6928 bf_set(rrq_rxid, els_rrq, rrq->rxid);
6929 bf_set(rrq_did, els_rrq, vport->fc_myDID);
6930 els_rrq->rrq = cpu_to_be32(els_rrq->rrq);
6931 els_rrq->rrq_exchg = cpu_to_be32(els_rrq->rrq_exchg);
6934 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6935 "Issue RRQ: did:x%x",
6936 did, rrq->xritag, rrq->rxid);
6937 elsiocb->context_un.rrq = rrq;
6938 elsiocb->iocb_cmpl = lpfc_cmpl_els_rrq;
6939 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
6941 if (ret == IOCB_ERROR) {
6942 lpfc_els_free_iocb(phba, elsiocb);
6949 * lpfc_send_rrq - Sends ELS RRQ if needed.
6950 * @phba: pointer to lpfc hba data structure.
6951 * @rrq: pointer to the active rrq.
6953 * This routine will call the lpfc_issue_els_rrq if the rrq is
6954 * still active for the xri. If this function returns a failure then
6955 * the caller needs to clean up the RRQ by calling lpfc_clr_active_rrq.
6957 * Returns 0 Success.
6961 lpfc_send_rrq(struct lpfc_hba *phba, struct lpfc_node_rrq *rrq)
6963 struct lpfc_nodelist *ndlp = lpfc_findnode_did(rrq->vport,
6965 if (lpfc_test_rrq_active(phba, ndlp, rrq->xritag))
6966 return lpfc_issue_els_rrq(rrq->vport, ndlp,
6973 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
6974 * @vport: pointer to a host virtual N_Port data structure.
6975 * @cmdsize: size of the ELS command.
6976 * @oldiocb: pointer to the original lpfc command iocb data structure.
6977 * @ndlp: pointer to a node-list data structure.
6979 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
6980 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
6982 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6983 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6984 * will be stored into the context1 field of the IOCB for the completion
6985 * callback function to the RPL Accept Response ELS command.
6988 * 0 - Successfully issued ACC RPL ELS command
6989 * 1 - Failed to issue ACC RPL ELS command
6992 lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
6993 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
6995 struct lpfc_hba *phba = vport->phba;
6996 IOCB_t *icmd, *oldcmd;
6998 struct lpfc_iocbq *elsiocb;
7001 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
7002 ndlp->nlp_DID, ELS_CMD_ACC);
7007 icmd = &elsiocb->iocb;
7008 oldcmd = &oldiocb->iocb;
7009 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
7010 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
7012 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7013 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
7014 pcmd += sizeof(uint16_t);
7015 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
7016 pcmd += sizeof(uint16_t);
7018 /* Setup the RPL ACC payload */
7019 rpl_rsp.listLen = be32_to_cpu(1);
7021 rpl_rsp.port_num_blk.portNum = 0;
7022 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
7023 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
7024 sizeof(struct lpfc_name));
7025 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
7026 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
7027 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7028 "0120 Xmit ELS RPL ACC response tag x%x "
7029 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
7031 elsiocb->iotag, elsiocb->iocb.ulpContext,
7032 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
7034 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
7035 phba->fc_stat.elsXmitACC++;
7036 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
7038 lpfc_els_free_iocb(phba, elsiocb);
7045 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
7046 * @vport: pointer to a host virtual N_Port data structure.
7047 * @cmdiocb: pointer to lpfc command iocb data structure.
7048 * @ndlp: pointer to a node-list data structure.
7050 * This routine processes Read Port List (RPL) IOCB received as an ELS
7051 * unsolicited event. It first checks the remote port state. If the remote
7052 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
7053 * invokes the lpfc_els_rsp_reject() routine to send reject response.
7054 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
7055 * to accept the RPL.
7058 * 0 - Successfully processed rpl iocb (currently always return 0)
7061 lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7062 struct lpfc_nodelist *ndlp)
7064 struct lpfc_dmabuf *pcmd;
7071 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
7072 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
7073 /* issue rejection response */
7074 stat.un.b.lsRjtRsvd0 = 0;
7075 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
7076 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
7077 stat.un.b.vendorUnique = 0;
7078 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
7080 /* rejected the unsolicited RPL request and done with it */
7084 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7085 lp = (uint32_t *) pcmd->virt;
7086 rpl = (RPL *) (lp + 1);
7087 maxsize = be32_to_cpu(rpl->maxsize);
7089 /* We support only one port */
7090 if ((rpl->index == 0) &&
7092 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
7093 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
7095 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
7097 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
7103 * lpfc_els_rcv_farp - Process an unsolicited farp request els command
7104 * @vport: pointer to a virtual N_Port data structure.
7105 * @cmdiocb: pointer to lpfc command iocb data structure.
7106 * @ndlp: pointer to a node-list data structure.
7108 * This routine processes Fibre Channel Address Resolution Protocol
7109 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
7110 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
7111 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
7112 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
7113 * remote PortName is compared against the FC PortName stored in the @vport
7114 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
7115 * compared against the FC NodeName stored in the @vport data structure.
7116 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
7117 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
7118 * invoked to send out FARP Response to the remote node. Before sending the
7119 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
7120 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
7121 * routine is invoked to log into the remote port first.
7124 * 0 - Either the FARP Match Mode not supported or successfully processed
7127 lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7128 struct lpfc_nodelist *ndlp)
7130 struct lpfc_dmabuf *pcmd;
7134 uint32_t cmd, cnt, did;
7136 icmd = &cmdiocb->iocb;
7137 did = icmd->un.elsreq64.remoteID;
7138 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7139 lp = (uint32_t *) pcmd->virt;
7143 /* FARP-REQ received from DID <did> */
7144 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7145 "0601 FARP-REQ received from DID x%x\n", did);
7146 /* We will only support match on WWPN or WWNN */
7147 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
7152 /* If this FARP command is searching for my portname */
7153 if (fp->Mflags & FARP_MATCH_PORT) {
7154 if (memcmp(&fp->RportName, &vport->fc_portname,
7155 sizeof(struct lpfc_name)) == 0)
7159 /* If this FARP command is searching for my nodename */
7160 if (fp->Mflags & FARP_MATCH_NODE) {
7161 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
7162 sizeof(struct lpfc_name)) == 0)
7167 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
7168 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
7169 /* Log back into the node before sending the FARP. */
7170 if (fp->Rflags & FARP_REQUEST_PLOGI) {
7171 ndlp->nlp_prev_state = ndlp->nlp_state;
7172 lpfc_nlp_set_state(vport, ndlp,
7173 NLP_STE_PLOGI_ISSUE);
7174 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
7177 /* Send a FARP response to that node */
7178 if (fp->Rflags & FARP_REQUEST_FARPR)
7179 lpfc_issue_els_farpr(vport, did, 0);
7186 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
7187 * @vport: pointer to a host virtual N_Port data structure.
7188 * @cmdiocb: pointer to lpfc command iocb data structure.
7189 * @ndlp: pointer to a node-list data structure.
7191 * This routine processes Fibre Channel Address Resolution Protocol
7192 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
7193 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
7194 * the FARP response request.
7197 * 0 - Successfully processed FARPR IOCB (currently always return 0)
7200 lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7201 struct lpfc_nodelist *ndlp)
7203 struct lpfc_dmabuf *pcmd;
7208 icmd = &cmdiocb->iocb;
7209 did = icmd->un.elsreq64.remoteID;
7210 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7211 lp = (uint32_t *) pcmd->virt;
7214 /* FARP-RSP received from DID <did> */
7215 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7216 "0600 FARP-RSP received from DID x%x\n", did);
7217 /* ACCEPT the Farp resp request */
7218 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
7224 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
7225 * @vport: pointer to a host virtual N_Port data structure.
7226 * @cmdiocb: pointer to lpfc command iocb data structure.
7227 * @fan_ndlp: pointer to a node-list data structure.
7229 * This routine processes a Fabric Address Notification (FAN) IOCB
7230 * command received as an ELS unsolicited event. The FAN ELS command will
7231 * only be processed on a physical port (i.e., the @vport represents the
7232 * physical port). The fabric NodeName and PortName from the FAN IOCB are
7233 * compared against those in the phba data structure. If any of those is
7234 * different, the lpfc_initial_flogi() routine is invoked to initialize
7235 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
7236 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
7237 * is invoked to register login to the fabric.
7240 * 0 - Successfully processed fan iocb (currently always return 0).
7243 lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7244 struct lpfc_nodelist *fan_ndlp)
7246 struct lpfc_hba *phba = vport->phba;
7250 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
7251 lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
7253 /* FAN received; Fan does not have a reply sequence */
7254 if ((vport == phba->pport) &&
7255 (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
7256 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
7257 sizeof(struct lpfc_name))) ||
7258 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
7259 sizeof(struct lpfc_name)))) {
7260 /* This port has switched fabrics. FLOGI is required */
7261 lpfc_issue_init_vfi(vport);
7263 /* FAN verified - skip FLOGI */
7264 vport->fc_myDID = vport->fc_prevDID;
7265 if (phba->sli_rev < LPFC_SLI_REV4)
7266 lpfc_issue_fabric_reglogin(vport);
7268 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7269 "3138 Need register VFI: (x%x/%x)\n",
7270 vport->fc_prevDID, vport->fc_myDID);
7271 lpfc_issue_reg_vfi(vport);
7279 * lpfc_els_timeout - Handler funciton to the els timer
7280 * @ptr: holder for the timer function associated data.
7282 * This routine is invoked by the ELS timer after timeout. It posts the ELS
7283 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
7284 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
7285 * up the worker thread. It is for the worker thread to invoke the routine
7286 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
7289 lpfc_els_timeout(unsigned long ptr)
7291 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
7292 struct lpfc_hba *phba = vport->phba;
7293 uint32_t tmo_posted;
7294 unsigned long iflag;
7296 spin_lock_irqsave(&vport->work_port_lock, iflag);
7297 tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
7298 if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING)))
7299 vport->work_port_events |= WORKER_ELS_TMO;
7300 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
7302 if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING)))
7303 lpfc_worker_wake_up(phba);
7309 * lpfc_els_timeout_handler - Process an els timeout event
7310 * @vport: pointer to a virtual N_Port data structure.
7312 * This routine is the actual handler function that processes an ELS timeout
7313 * event. It walks the ELS ring to get and abort all the IOCBs (except the
7314 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
7315 * invoking the lpfc_sli_issue_abort_iotag() routine.
7318 lpfc_els_timeout_handler(struct lpfc_vport *vport)
7320 struct lpfc_hba *phba = vport->phba;
7321 struct lpfc_sli_ring *pring;
7322 struct lpfc_iocbq *tmp_iocb, *piocb;
7324 struct lpfc_dmabuf *pcmd;
7325 uint32_t els_command = 0;
7327 uint32_t remote_ID = 0xffffffff;
7328 LIST_HEAD(abort_list);
7331 timeout = (uint32_t)(phba->fc_ratov << 1);
7333 pring = lpfc_phba_elsring(phba);
7335 if ((phba->pport->load_flag & FC_UNLOADING))
7337 spin_lock_irq(&phba->hbalock);
7338 if (phba->sli_rev == LPFC_SLI_REV4)
7339 spin_lock(&pring->ring_lock);
7341 if ((phba->pport->load_flag & FC_UNLOADING)) {
7342 if (phba->sli_rev == LPFC_SLI_REV4)
7343 spin_unlock(&pring->ring_lock);
7344 spin_unlock_irq(&phba->hbalock);
7348 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
7351 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
7352 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
7353 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
7356 if (piocb->vport != vport)
7359 pcmd = (struct lpfc_dmabuf *) piocb->context2;
7361 els_command = *(uint32_t *) (pcmd->virt);
7363 if (els_command == ELS_CMD_FARP ||
7364 els_command == ELS_CMD_FARPR ||
7365 els_command == ELS_CMD_FDISC)
7368 if (piocb->drvrTimeout > 0) {
7369 if (piocb->drvrTimeout >= timeout)
7370 piocb->drvrTimeout -= timeout;
7372 piocb->drvrTimeout = 0;
7376 remote_ID = 0xffffffff;
7377 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
7378 remote_ID = cmd->un.elsreq64.remoteID;
7380 struct lpfc_nodelist *ndlp;
7381 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
7382 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
7383 remote_ID = ndlp->nlp_DID;
7385 list_add_tail(&piocb->dlist, &abort_list);
7387 if (phba->sli_rev == LPFC_SLI_REV4)
7388 spin_unlock(&pring->ring_lock);
7389 spin_unlock_irq(&phba->hbalock);
7391 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
7393 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7394 "0127 ELS timeout Data: x%x x%x x%x "
7395 "x%x\n", els_command,
7396 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
7397 spin_lock_irq(&phba->hbalock);
7398 list_del_init(&piocb->dlist);
7399 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
7400 spin_unlock_irq(&phba->hbalock);
7403 if (!list_empty(&pring->txcmplq))
7404 if (!(phba->pport->load_flag & FC_UNLOADING))
7405 mod_timer(&vport->els_tmofunc,
7406 jiffies + msecs_to_jiffies(1000 * timeout));
7410 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
7411 * @vport: pointer to a host virtual N_Port data structure.
7413 * This routine is used to clean up all the outstanding ELS commands on a
7414 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
7415 * routine. After that, it walks the ELS transmit queue to remove all the
7416 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
7417 * the IOCBs with a non-NULL completion callback function, the callback
7418 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
7419 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
7420 * callback function, the IOCB will simply be released. Finally, it walks
7421 * the ELS transmit completion queue to issue an abort IOCB to any transmit
7422 * completion queue IOCB that is associated with the @vport and is not
7423 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
7424 * part of the discovery state machine) out to HBA by invoking the
7425 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
7426 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
7427 * the IOCBs are aborted when this function returns.
7430 lpfc_els_flush_cmd(struct lpfc_vport *vport)
7432 LIST_HEAD(abort_list);
7433 struct lpfc_hba *phba = vport->phba;
7434 struct lpfc_sli_ring *pring;
7435 struct lpfc_iocbq *tmp_iocb, *piocb;
7438 lpfc_fabric_abort_vport(vport);
7440 * For SLI3, only the hbalock is required. But SLI4 needs to coordinate
7441 * with the ring insert operation. Because lpfc_sli_issue_abort_iotag
7442 * ultimately grabs the ring_lock, the driver must splice the list into
7443 * a working list and release the locks before calling the abort.
7445 spin_lock_irq(&phba->hbalock);
7446 pring = lpfc_phba_elsring(phba);
7447 if (phba->sli_rev == LPFC_SLI_REV4)
7448 spin_lock(&pring->ring_lock);
7450 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
7451 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
7454 if (piocb->vport != vport)
7456 list_add_tail(&piocb->dlist, &abort_list);
7458 if (phba->sli_rev == LPFC_SLI_REV4)
7459 spin_unlock(&pring->ring_lock);
7460 spin_unlock_irq(&phba->hbalock);
7461 /* Abort each iocb on the aborted list and remove the dlist links. */
7462 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
7463 spin_lock_irq(&phba->hbalock);
7464 list_del_init(&piocb->dlist);
7465 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
7466 spin_unlock_irq(&phba->hbalock);
7468 if (!list_empty(&abort_list))
7469 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7470 "3387 abort list for txq not empty\n");
7471 INIT_LIST_HEAD(&abort_list);
7473 spin_lock_irq(&phba->hbalock);
7474 if (phba->sli_rev == LPFC_SLI_REV4)
7475 spin_lock(&pring->ring_lock);
7477 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
7480 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
7484 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
7485 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
7486 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
7487 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
7488 cmd->ulpCommand == CMD_ABORT_XRI_CN)
7491 if (piocb->vport != vport)
7494 list_del_init(&piocb->list);
7495 list_add_tail(&piocb->list, &abort_list);
7497 if (phba->sli_rev == LPFC_SLI_REV4)
7498 spin_unlock(&pring->ring_lock);
7499 spin_unlock_irq(&phba->hbalock);
7501 /* Cancell all the IOCBs from the completions list */
7502 lpfc_sli_cancel_iocbs(phba, &abort_list,
7503 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
7509 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
7510 * @phba: pointer to lpfc hba data structure.
7512 * This routine is used to clean up all the outstanding ELS commands on a
7513 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
7514 * routine. After that, it walks the ELS transmit queue to remove all the
7515 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
7516 * the IOCBs with the completion callback function associated, the callback
7517 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
7518 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
7519 * callback function associated, the IOCB will simply be released. Finally,
7520 * it walks the ELS transmit completion queue to issue an abort IOCB to any
7521 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
7522 * management plane IOCBs that are not part of the discovery state machine)
7523 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
7526 lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
7528 struct lpfc_vport *vport;
7529 list_for_each_entry(vport, &phba->port_list, listentry)
7530 lpfc_els_flush_cmd(vport);
7536 * lpfc_send_els_failure_event - Posts an ELS command failure event
7537 * @phba: Pointer to hba context object.
7538 * @cmdiocbp: Pointer to command iocb which reported error.
7539 * @rspiocbp: Pointer to response iocb which reported error.
7541 * This function sends an event when there is an ELS command
7545 lpfc_send_els_failure_event(struct lpfc_hba *phba,
7546 struct lpfc_iocbq *cmdiocbp,
7547 struct lpfc_iocbq *rspiocbp)
7549 struct lpfc_vport *vport = cmdiocbp->vport;
7550 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7551 struct lpfc_lsrjt_event lsrjt_event;
7552 struct lpfc_fabric_event_header fabric_event;
7554 struct lpfc_nodelist *ndlp;
7557 ndlp = cmdiocbp->context1;
7558 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
7561 if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) {
7562 lsrjt_event.header.event_type = FC_REG_ELS_EVENT;
7563 lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV;
7564 memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname,
7565 sizeof(struct lpfc_name));
7566 memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename,
7567 sizeof(struct lpfc_name));
7568 pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
7569 cmdiocbp->context2)->virt);
7570 lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0;
7571 stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]);
7572 lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode;
7573 lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp;
7574 fc_host_post_vendor_event(shost,
7575 fc_get_event_number(),
7576 sizeof(lsrjt_event),
7577 (char *)&lsrjt_event,
7581 if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) ||
7582 (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) {
7583 fabric_event.event_type = FC_REG_FABRIC_EVENT;
7584 if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY)
7585 fabric_event.subcategory = LPFC_EVENT_PORT_BUSY;
7587 fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY;
7588 memcpy(fabric_event.wwpn, &ndlp->nlp_portname,
7589 sizeof(struct lpfc_name));
7590 memcpy(fabric_event.wwnn, &ndlp->nlp_nodename,
7591 sizeof(struct lpfc_name));
7592 fc_host_post_vendor_event(shost,
7593 fc_get_event_number(),
7594 sizeof(fabric_event),
7595 (char *)&fabric_event,
7603 * lpfc_send_els_event - Posts unsolicited els event
7604 * @vport: Pointer to vport object.
7605 * @ndlp: Pointer FC node object.
7606 * @cmd: ELS command code.
7608 * This function posts an event when there is an incoming
7609 * unsolicited ELS command.
7612 lpfc_send_els_event(struct lpfc_vport *vport,
7613 struct lpfc_nodelist *ndlp,
7616 struct lpfc_els_event_header *els_data = NULL;
7617 struct lpfc_logo_event *logo_data = NULL;
7618 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7620 if (*payload == ELS_CMD_LOGO) {
7621 logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL);
7623 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7624 "0148 Failed to allocate memory "
7625 "for LOGO event\n");
7628 els_data = &logo_data->header;
7630 els_data = kmalloc(sizeof(struct lpfc_els_event_header),
7633 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7634 "0149 Failed to allocate memory "
7639 els_data->event_type = FC_REG_ELS_EVENT;
7642 els_data->subcategory = LPFC_EVENT_PLOGI_RCV;
7645 els_data->subcategory = LPFC_EVENT_PRLO_RCV;
7648 els_data->subcategory = LPFC_EVENT_ADISC_RCV;
7651 els_data->subcategory = LPFC_EVENT_LOGO_RCV;
7652 /* Copy the WWPN in the LOGO payload */
7653 memcpy(logo_data->logo_wwpn, &payload[2],
7654 sizeof(struct lpfc_name));
7660 memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name));
7661 memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name));
7662 if (*payload == ELS_CMD_LOGO) {
7663 fc_host_post_vendor_event(shost,
7664 fc_get_event_number(),
7665 sizeof(struct lpfc_logo_event),
7670 fc_host_post_vendor_event(shost,
7671 fc_get_event_number(),
7672 sizeof(struct lpfc_els_event_header),
7683 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
7684 * @phba: pointer to lpfc hba data structure.
7685 * @pring: pointer to a SLI ring.
7686 * @vport: pointer to a host virtual N_Port data structure.
7687 * @elsiocb: pointer to lpfc els command iocb data structure.
7689 * This routine is used for processing the IOCB associated with a unsolicited
7690 * event. It first determines whether there is an existing ndlp that matches
7691 * the DID from the unsolicited IOCB. If not, it will create a new one with
7692 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
7693 * IOCB is then used to invoke the proper routine and to set up proper state
7694 * of the discovery state machine.
7697 lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
7698 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
7700 struct Scsi_Host *shost;
7701 struct lpfc_nodelist *ndlp;
7704 uint32_t cmd, did, newnode;
7705 uint8_t rjt_exp, rjt_err = 0;
7706 IOCB_t *icmd = &elsiocb->iocb;
7708 if (!vport || !(elsiocb->context2))
7712 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
7714 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
7715 lpfc_post_buffer(phba, pring, 1);
7717 did = icmd->un.rcvels.remoteID;
7718 if (icmd->ulpStatus) {
7719 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7720 "RCV Unsol ELS: status:x%x/x%x did:x%x",
7721 icmd->ulpStatus, icmd->un.ulpWord[4], did);
7725 /* Check to see if link went down during discovery */
7726 if (lpfc_els_chk_latt(vport))
7729 /* Ignore traffic received during vport shutdown. */
7730 if (vport->load_flag & FC_UNLOADING)
7733 /* If NPort discovery is delayed drop incoming ELS */
7734 if ((vport->fc_flag & FC_DISC_DELAYED) &&
7735 (cmd != ELS_CMD_PLOGI))
7738 ndlp = lpfc_findnode_did(vport, did);
7740 /* Cannot find existing Fabric ndlp, so allocate a new one */
7741 ndlp = lpfc_nlp_init(vport, did);
7744 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
7746 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
7747 ndlp->nlp_type |= NLP_FABRIC;
7748 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
7749 ndlp = lpfc_enable_node(vport, ndlp,
7750 NLP_STE_UNUSED_NODE);
7753 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
7755 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
7756 ndlp->nlp_type |= NLP_FABRIC;
7757 } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
7758 /* This is similar to the new node path */
7759 ndlp = lpfc_nlp_get(ndlp);
7762 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
7766 phba->fc_stat.elsRcvFrame++;
7769 * Do not process any unsolicited ELS commands
7770 * if the ndlp is in DEV_LOSS
7772 shost = lpfc_shost_from_vport(vport);
7773 spin_lock_irq(shost->host_lock);
7774 if (ndlp->nlp_flag & NLP_IN_DEV_LOSS) {
7775 spin_unlock_irq(shost->host_lock);
7778 spin_unlock_irq(shost->host_lock);
7780 elsiocb->context1 = lpfc_nlp_get(ndlp);
7781 elsiocb->vport = vport;
7783 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
7784 cmd &= ELS_CMD_MASK;
7786 /* ELS command <elsCmd> received from NPORT <did> */
7787 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7788 "0112 ELS command x%x received from NPORT x%x "
7789 "Data: x%x x%x x%x x%x\n",
7790 cmd, did, vport->port_state, vport->fc_flag,
7791 vport->fc_myDID, vport->fc_prevDID);
7793 /* reject till our FLOGI completes */
7794 if ((vport->port_state < LPFC_FABRIC_CFG_LINK) &&
7795 (cmd != ELS_CMD_FLOGI)) {
7796 rjt_err = LSRJT_LOGICAL_BSY;
7797 rjt_exp = LSEXP_NOTHING_MORE;
7803 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7804 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
7805 did, vport->port_state, ndlp->nlp_flag);
7807 phba->fc_stat.elsRcvPLOGI++;
7808 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
7809 if (phba->sli_rev == LPFC_SLI_REV4 &&
7810 (phba->pport->fc_flag & FC_PT2PT)) {
7811 vport->fc_prevDID = vport->fc_myDID;
7812 /* Our DID needs to be updated before registering
7813 * the vfi. This is done in lpfc_rcv_plogi but
7814 * that is called after the reg_vfi.
7816 vport->fc_myDID = elsiocb->iocb.un.rcvels.parmRo;
7817 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7818 "3312 Remote port assigned DID x%x "
7819 "%x\n", vport->fc_myDID,
7823 lpfc_send_els_event(vport, ndlp, payload);
7825 /* If Nport discovery is delayed, reject PLOGIs */
7826 if (vport->fc_flag & FC_DISC_DELAYED) {
7827 rjt_err = LSRJT_UNABLE_TPC;
7828 rjt_exp = LSEXP_NOTHING_MORE;
7832 if (vport->port_state < LPFC_DISC_AUTH) {
7833 if (!(phba->pport->fc_flag & FC_PT2PT) ||
7834 (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
7835 rjt_err = LSRJT_UNABLE_TPC;
7836 rjt_exp = LSEXP_NOTHING_MORE;
7841 spin_lock_irq(shost->host_lock);
7842 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
7843 spin_unlock_irq(shost->host_lock);
7845 lpfc_disc_state_machine(vport, ndlp, elsiocb,
7850 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7851 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
7852 did, vport->port_state, ndlp->nlp_flag);
7854 phba->fc_stat.elsRcvFLOGI++;
7855 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
7860 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7861 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
7862 did, vport->port_state, ndlp->nlp_flag);
7864 phba->fc_stat.elsRcvLOGO++;
7865 lpfc_send_els_event(vport, ndlp, payload);
7866 if (vport->port_state < LPFC_DISC_AUTH) {
7867 rjt_err = LSRJT_UNABLE_TPC;
7868 rjt_exp = LSEXP_NOTHING_MORE;
7871 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
7874 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7875 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
7876 did, vport->port_state, ndlp->nlp_flag);
7878 phba->fc_stat.elsRcvPRLO++;
7879 lpfc_send_els_event(vport, ndlp, payload);
7880 if (vport->port_state < LPFC_DISC_AUTH) {
7881 rjt_err = LSRJT_UNABLE_TPC;
7882 rjt_exp = LSEXP_NOTHING_MORE;
7885 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
7888 phba->fc_stat.elsRcvLCB++;
7889 lpfc_els_rcv_lcb(vport, elsiocb, ndlp);
7892 phba->fc_stat.elsRcvRDP++;
7893 lpfc_els_rcv_rdp(vport, elsiocb, ndlp);
7896 phba->fc_stat.elsRcvRSCN++;
7897 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
7902 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7903 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
7904 did, vport->port_state, ndlp->nlp_flag);
7906 lpfc_send_els_event(vport, ndlp, payload);
7907 phba->fc_stat.elsRcvADISC++;
7908 if (vport->port_state < LPFC_DISC_AUTH) {
7909 rjt_err = LSRJT_UNABLE_TPC;
7910 rjt_exp = LSEXP_NOTHING_MORE;
7913 lpfc_disc_state_machine(vport, ndlp, elsiocb,
7917 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7918 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
7919 did, vport->port_state, ndlp->nlp_flag);
7921 phba->fc_stat.elsRcvPDISC++;
7922 if (vport->port_state < LPFC_DISC_AUTH) {
7923 rjt_err = LSRJT_UNABLE_TPC;
7924 rjt_exp = LSEXP_NOTHING_MORE;
7927 lpfc_disc_state_machine(vport, ndlp, elsiocb,
7931 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7932 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
7933 did, vport->port_state, ndlp->nlp_flag);
7935 phba->fc_stat.elsRcvFARPR++;
7936 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
7939 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7940 "RCV FARP: did:x%x/ste:x%x flg:x%x",
7941 did, vport->port_state, ndlp->nlp_flag);
7943 phba->fc_stat.elsRcvFARP++;
7944 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
7947 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7948 "RCV FAN: did:x%x/ste:x%x flg:x%x",
7949 did, vport->port_state, ndlp->nlp_flag);
7951 phba->fc_stat.elsRcvFAN++;
7952 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
7955 case ELS_CMD_NVMEPRLI:
7956 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7957 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
7958 did, vport->port_state, ndlp->nlp_flag);
7960 phba->fc_stat.elsRcvPRLI++;
7961 if ((vport->port_state < LPFC_DISC_AUTH) &&
7962 (vport->fc_flag & FC_FABRIC)) {
7963 rjt_err = LSRJT_UNABLE_TPC;
7964 rjt_exp = LSEXP_NOTHING_MORE;
7967 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
7970 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7971 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
7972 did, vport->port_state, ndlp->nlp_flag);
7974 phba->fc_stat.elsRcvLIRR++;
7975 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
7980 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7981 "RCV RLS: did:x%x/ste:x%x flg:x%x",
7982 did, vport->port_state, ndlp->nlp_flag);
7984 phba->fc_stat.elsRcvRLS++;
7985 lpfc_els_rcv_rls(vport, elsiocb, ndlp);
7990 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7991 "RCV RPS: did:x%x/ste:x%x flg:x%x",
7992 did, vport->port_state, ndlp->nlp_flag);
7994 phba->fc_stat.elsRcvRPS++;
7995 lpfc_els_rcv_rps(vport, elsiocb, ndlp);
8000 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8001 "RCV RPL: did:x%x/ste:x%x flg:x%x",
8002 did, vport->port_state, ndlp->nlp_flag);
8004 phba->fc_stat.elsRcvRPL++;
8005 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
8010 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8011 "RCV RNID: did:x%x/ste:x%x flg:x%x",
8012 did, vport->port_state, ndlp->nlp_flag);
8014 phba->fc_stat.elsRcvRNID++;
8015 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
8020 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8021 "RCV RTV: did:x%x/ste:x%x flg:x%x",
8022 did, vport->port_state, ndlp->nlp_flag);
8023 phba->fc_stat.elsRcvRTV++;
8024 lpfc_els_rcv_rtv(vport, elsiocb, ndlp);
8029 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8030 "RCV RRQ: did:x%x/ste:x%x flg:x%x",
8031 did, vport->port_state, ndlp->nlp_flag);
8033 phba->fc_stat.elsRcvRRQ++;
8034 lpfc_els_rcv_rrq(vport, elsiocb, ndlp);
8039 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8040 "RCV ECHO: did:x%x/ste:x%x flg:x%x",
8041 did, vport->port_state, ndlp->nlp_flag);
8043 phba->fc_stat.elsRcvECHO++;
8044 lpfc_els_rcv_echo(vport, elsiocb, ndlp);
8049 /* receive this due to exchange closed */
8050 rjt_err = LSRJT_UNABLE_TPC;
8051 rjt_exp = LSEXP_INVALID_OX_RX;
8054 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8055 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
8056 cmd, did, vport->port_state);
8058 /* Unsupported ELS command, reject */
8059 rjt_err = LSRJT_CMD_UNSUPPORTED;
8060 rjt_exp = LSEXP_NOTHING_MORE;
8062 /* Unknown ELS command <elsCmd> received from NPORT <did> */
8063 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8064 "0115 Unknown ELS command x%x "
8065 "received from NPORT x%x\n", cmd, did);
8072 /* check if need to LS_RJT received ELS cmd */
8074 memset(&stat, 0, sizeof(stat));
8075 stat.un.b.lsRjtRsnCode = rjt_err;
8076 stat.un.b.lsRjtRsnCodeExp = rjt_exp;
8077 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
8081 lpfc_nlp_put(elsiocb->context1);
8082 elsiocb->context1 = NULL;
8086 if (vport && !(vport->load_flag & FC_UNLOADING))
8087 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8088 "0111 Dropping received ELS cmd "
8089 "Data: x%x x%x x%x\n",
8090 icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout);
8091 phba->fc_stat.elsRcvDrop++;
8095 * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
8096 * @phba: pointer to lpfc hba data structure.
8097 * @pring: pointer to a SLI ring.
8098 * @elsiocb: pointer to lpfc els iocb data structure.
8100 * This routine is used to process an unsolicited event received from a SLI
8101 * (Service Level Interface) ring. The actual processing of the data buffer
8102 * associated with the unsolicited event is done by invoking the routine
8103 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
8104 * SLI ring on which the unsolicited event was received.
8107 lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
8108 struct lpfc_iocbq *elsiocb)
8110 struct lpfc_vport *vport = phba->pport;
8111 IOCB_t *icmd = &elsiocb->iocb;
8113 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
8114 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
8116 elsiocb->context1 = NULL;
8117 elsiocb->context2 = NULL;
8118 elsiocb->context3 = NULL;
8120 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
8121 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
8122 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
8123 (icmd->un.ulpWord[4] & IOERR_PARAM_MASK) ==
8124 IOERR_RCV_BUFFER_WAITING) {
8125 phba->fc_stat.NoRcvBuf++;
8126 /* Not enough posted buffers; Try posting more buffers */
8127 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
8128 lpfc_post_buffer(phba, pring, 0);
8132 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
8133 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
8134 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
8135 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
8136 vport = phba->pport;
8138 vport = lpfc_find_vport_by_vpid(phba,
8139 icmd->unsli3.rcvsli3.vpi);
8142 /* If there are no BDEs associated
8143 * with this IOCB, there is nothing to do.
8145 if (icmd->ulpBdeCount == 0)
8148 /* type of ELS cmd is first 32bit word
8151 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
8152 elsiocb->context2 = bdeBuf1;
8154 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
8155 icmd->un.cont64[0].addrLow);
8156 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
8160 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
8162 * The different unsolicited event handlers would tell us
8163 * if they are done with "mp" by setting context2 to NULL.
8165 if (elsiocb->context2) {
8166 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
8167 elsiocb->context2 = NULL;
8170 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
8171 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
8172 icmd->ulpBdeCount == 2) {
8173 elsiocb->context2 = bdeBuf2;
8174 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
8175 /* free mp if we are done with it */
8176 if (elsiocb->context2) {
8177 lpfc_in_buf_free(phba, elsiocb->context2);
8178 elsiocb->context2 = NULL;
8184 lpfc_start_fdmi(struct lpfc_vport *vport)
8186 struct lpfc_nodelist *ndlp;
8188 /* If this is the first time, allocate an ndlp and initialize
8189 * it. Otherwise, make sure the node is enabled and then do the
8192 ndlp = lpfc_findnode_did(vport, FDMI_DID);
8194 ndlp = lpfc_nlp_init(vport, FDMI_DID);
8196 ndlp->nlp_type |= NLP_FABRIC;
8201 if (!NLP_CHK_NODE_ACT(ndlp))
8202 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_NPR_NODE);
8205 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
8206 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
8211 * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
8212 * @phba: pointer to lpfc hba data structure.
8213 * @vport: pointer to a virtual N_Port data structure.
8215 * This routine issues a Port Login (PLOGI) to the Name Server with
8216 * State Change Request (SCR) for a @vport. This routine will create an
8217 * ndlp for the Name Server associated to the @vport if such node does
8218 * not already exist. The PLOGI to Name Server is issued by invoking the
8219 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
8220 * (FDMI) is configured to the @vport, a FDMI node will be created and
8221 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
8224 lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
8226 struct lpfc_nodelist *ndlp;
8227 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8230 * If lpfc_delay_discovery parameter is set and the clean address
8231 * bit is cleared and fc fabric parameters chenged, delay FC NPort
8234 spin_lock_irq(shost->host_lock);
8235 if (vport->fc_flag & FC_DISC_DELAYED) {
8236 spin_unlock_irq(shost->host_lock);
8237 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
8238 "3334 Delay fc port discovery for %d seconds\n",
8240 mod_timer(&vport->delayed_disc_tmo,
8241 jiffies + msecs_to_jiffies(1000 * phba->fc_ratov));
8244 spin_unlock_irq(shost->host_lock);
8246 ndlp = lpfc_findnode_did(vport, NameServer_DID);
8248 ndlp = lpfc_nlp_init(vport, NameServer_DID);
8250 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
8251 lpfc_disc_start(vport);
8254 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
8255 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8256 "0251 NameServer login: no memory\n");
8259 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
8260 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
8262 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
8263 lpfc_disc_start(vport);
8266 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
8267 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8268 "0348 NameServer login: node freed\n");
8272 ndlp->nlp_type |= NLP_FABRIC;
8274 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
8276 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
8277 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
8278 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8279 "0252 Cannot issue NameServer login\n");
8283 if ((phba->cfg_enable_SmartSAN ||
8284 (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) &&
8285 (vport->load_flag & FC_ALLOW_FDMI))
8286 lpfc_start_fdmi(vport);
8290 * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
8291 * @phba: pointer to lpfc hba data structure.
8292 * @pmb: pointer to the driver internal queue element for mailbox command.
8294 * This routine is the completion callback function to register new vport
8295 * mailbox command. If the new vport mailbox command completes successfully,
8296 * the fabric registration login shall be performed on physical port (the
8297 * new vport created is actually a physical port, with VPI 0) or the port
8298 * login to Name Server for State Change Request (SCR) will be performed
8299 * on virtual port (real virtual port, with VPI greater than 0).
8302 lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
8304 struct lpfc_vport *vport = pmb->vport;
8305 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8306 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
8307 MAILBOX_t *mb = &pmb->u.mb;
8310 spin_lock_irq(shost->host_lock);
8311 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
8312 spin_unlock_irq(shost->host_lock);
8314 if (mb->mbxStatus) {
8315 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
8316 "0915 Register VPI failed : Status: x%x"
8317 " upd bit: x%x \n", mb->mbxStatus,
8318 mb->un.varRegVpi.upd);
8319 if (phba->sli_rev == LPFC_SLI_REV4 &&
8320 mb->un.varRegVpi.upd)
8321 goto mbox_err_exit ;
8323 switch (mb->mbxStatus) {
8324 case 0x11: /* unsupported feature */
8325 case 0x9603: /* max_vpi exceeded */
8326 case 0x9602: /* Link event since CLEAR_LA */
8327 /* giving up on vport registration */
8328 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
8329 spin_lock_irq(shost->host_lock);
8330 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
8331 spin_unlock_irq(shost->host_lock);
8332 lpfc_can_disctmo(vport);
8334 /* If reg_vpi fail with invalid VPI status, re-init VPI */
8336 spin_lock_irq(shost->host_lock);
8337 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
8338 spin_unlock_irq(shost->host_lock);
8339 lpfc_init_vpi(phba, pmb, vport->vpi);
8341 pmb->mbox_cmpl = lpfc_init_vpi_cmpl;
8342 rc = lpfc_sli_issue_mbox(phba, pmb,
8344 if (rc == MBX_NOT_FINISHED) {
8345 lpfc_printf_vlog(vport,
8347 "2732 Failed to issue INIT_VPI"
8348 " mailbox command\n");
8355 /* Try to recover from this error */
8356 if (phba->sli_rev == LPFC_SLI_REV4)
8357 lpfc_sli4_unreg_all_rpis(vport);
8358 lpfc_mbx_unreg_vpi(vport);
8359 spin_lock_irq(shost->host_lock);
8360 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
8361 spin_unlock_irq(shost->host_lock);
8362 if (mb->mbxStatus == MBX_NOT_FINISHED)
8364 if ((vport->port_type == LPFC_PHYSICAL_PORT) &&
8365 !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG)) {
8366 if (phba->sli_rev == LPFC_SLI_REV4)
8367 lpfc_issue_init_vfi(vport);
8369 lpfc_initial_flogi(vport);
8371 lpfc_initial_fdisc(vport);
8376 spin_lock_irq(shost->host_lock);
8377 vport->vpi_state |= LPFC_VPI_REGISTERED;
8378 spin_unlock_irq(shost->host_lock);
8379 if (vport == phba->pport) {
8380 if (phba->sli_rev < LPFC_SLI_REV4)
8381 lpfc_issue_fabric_reglogin(vport);
8384 * If the physical port is instantiated using
8385 * FDISC, do not start vport discovery.
8387 if (vport->port_state != LPFC_FDISC)
8388 lpfc_start_fdiscs(phba);
8389 lpfc_do_scr_ns_plogi(phba, vport);
8392 lpfc_do_scr_ns_plogi(phba, vport);
8395 /* Now, we decrement the ndlp reference count held for this
8400 mempool_free(pmb, phba->mbox_mem_pool);
8405 * lpfc_register_new_vport - Register a new vport with a HBA
8406 * @phba: pointer to lpfc hba data structure.
8407 * @vport: pointer to a host virtual N_Port data structure.
8408 * @ndlp: pointer to a node-list data structure.
8410 * This routine registers the @vport as a new virtual port with a HBA.
8411 * It is done through a registering vpi mailbox command.
8414 lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
8415 struct lpfc_nodelist *ndlp)
8417 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8420 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
8422 lpfc_reg_vpi(vport, mbox);
8423 mbox->vport = vport;
8424 mbox->context2 = lpfc_nlp_get(ndlp);
8425 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
8426 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
8427 == MBX_NOT_FINISHED) {
8428 /* mailbox command not success, decrement ndlp
8429 * reference count for this command
8432 mempool_free(mbox, phba->mbox_mem_pool);
8434 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
8435 "0253 Register VPI: Can't send mbox\n");
8439 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
8440 "0254 Register VPI: no memory\n");
8446 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
8447 spin_lock_irq(shost->host_lock);
8448 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
8449 spin_unlock_irq(shost->host_lock);
8454 * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer
8455 * @phba: pointer to lpfc hba data structure.
8457 * This routine cancels the retry delay timers to all the vports.
8460 lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba)
8462 struct lpfc_vport **vports;
8463 struct lpfc_nodelist *ndlp;
8464 uint32_t link_state;
8467 /* Treat this failure as linkdown for all vports */
8468 link_state = phba->link_state;
8469 lpfc_linkdown(phba);
8470 phba->link_state = link_state;
8472 vports = lpfc_create_vport_work_array(phba);
8475 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
8476 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
8478 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
8479 lpfc_els_flush_cmd(vports[i]);
8481 lpfc_destroy_vport_work_array(phba, vports);
8486 * lpfc_retry_pport_discovery - Start timer to retry FLOGI.
8487 * @phba: pointer to lpfc hba data structure.
8489 * This routine abort all pending discovery commands and
8490 * start a timer to retry FLOGI for the physical port
8494 lpfc_retry_pport_discovery(struct lpfc_hba *phba)
8496 struct lpfc_nodelist *ndlp;
8497 struct Scsi_Host *shost;
8499 /* Cancel the all vports retry delay retry timers */
8500 lpfc_cancel_all_vport_retry_delay_timer(phba);
8502 /* If fabric require FLOGI, then re-instantiate physical login */
8503 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
8507 shost = lpfc_shost_from_vport(phba->pport);
8508 mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000));
8509 spin_lock_irq(shost->host_lock);
8510 ndlp->nlp_flag |= NLP_DELAY_TMO;
8511 spin_unlock_irq(shost->host_lock);
8512 ndlp->nlp_last_elscmd = ELS_CMD_FLOGI;
8513 phba->pport->port_state = LPFC_FLOGI;
8518 * lpfc_fabric_login_reqd - Check if FLOGI required.
8519 * @phba: pointer to lpfc hba data structure.
8520 * @cmdiocb: pointer to FDISC command iocb.
8521 * @rspiocb: pointer to FDISC response iocb.
8523 * This routine checks if a FLOGI is reguired for FDISC
8527 lpfc_fabric_login_reqd(struct lpfc_hba *phba,
8528 struct lpfc_iocbq *cmdiocb,
8529 struct lpfc_iocbq *rspiocb)
8532 if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) ||
8533 (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED))
8540 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
8541 * @phba: pointer to lpfc hba data structure.
8542 * @cmdiocb: pointer to lpfc command iocb data structure.
8543 * @rspiocb: pointer to lpfc response iocb data structure.
8545 * This routine is the completion callback function to a Fabric Discover
8546 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
8547 * single threaded, each FDISC completion callback function will reset
8548 * the discovery timer for all vports such that the timers will not get
8549 * unnecessary timeout. The function checks the FDISC IOCB status. If error
8550 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
8551 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
8552 * assigned to the vport has been changed with the completion of the FDISC
8553 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
8554 * are unregistered from the HBA, and then the lpfc_register_new_vport()
8555 * routine is invoked to register new vport with the HBA. Otherwise, the
8556 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
8557 * Server for State Change Request (SCR).
8560 lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
8561 struct lpfc_iocbq *rspiocb)
8563 struct lpfc_vport *vport = cmdiocb->vport;
8564 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8565 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
8566 struct lpfc_nodelist *np;
8567 struct lpfc_nodelist *next_np;
8568 IOCB_t *irsp = &rspiocb->iocb;
8569 struct lpfc_iocbq *piocb;
8570 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
8571 struct serv_parm *sp;
8572 uint8_t fabric_param_changed;
8574 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
8575 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
8576 irsp->ulpStatus, irsp->un.ulpWord[4],
8578 /* Since all FDISCs are being single threaded, we
8579 * must reset the discovery timer for ALL vports
8580 * waiting to send FDISC when one completes.
8582 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
8583 lpfc_set_disctmo(piocb->vport);
8586 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
8587 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
8588 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
8590 if (irsp->ulpStatus) {
8592 if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) {
8593 lpfc_retry_pport_discovery(phba);
8597 /* Check for retry */
8598 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
8601 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8602 "0126 FDISC failed. (x%x/x%x)\n",
8603 irsp->ulpStatus, irsp->un.ulpWord[4]);
8606 spin_lock_irq(shost->host_lock);
8607 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
8608 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
8609 vport->fc_flag |= FC_FABRIC;
8610 if (vport->phba->fc_topology == LPFC_TOPOLOGY_LOOP)
8611 vport->fc_flag |= FC_PUBLIC_LOOP;
8612 spin_unlock_irq(shost->host_lock);
8614 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
8615 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
8616 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
8619 sp = prsp->virt + sizeof(uint32_t);
8620 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
8621 memcpy(&vport->fabric_portname, &sp->portName,
8622 sizeof(struct lpfc_name));
8623 memcpy(&vport->fabric_nodename, &sp->nodeName,
8624 sizeof(struct lpfc_name));
8625 if (fabric_param_changed &&
8626 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
8627 /* If our NportID changed, we need to ensure all
8628 * remaining NPORTs get unreg_login'ed so we can
8631 list_for_each_entry_safe(np, next_np,
8632 &vport->fc_nodes, nlp_listp) {
8633 if (!NLP_CHK_NODE_ACT(ndlp) ||
8634 (np->nlp_state != NLP_STE_NPR_NODE) ||
8635 !(np->nlp_flag & NLP_NPR_ADISC))
8637 spin_lock_irq(shost->host_lock);
8638 np->nlp_flag &= ~NLP_NPR_ADISC;
8639 spin_unlock_irq(shost->host_lock);
8640 lpfc_unreg_rpi(vport, np);
8642 lpfc_cleanup_pending_mbox(vport);
8644 if (phba->sli_rev == LPFC_SLI_REV4)
8645 lpfc_sli4_unreg_all_rpis(vport);
8647 lpfc_mbx_unreg_vpi(vport);
8648 spin_lock_irq(shost->host_lock);
8649 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
8650 if (phba->sli_rev == LPFC_SLI_REV4)
8651 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
8653 vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG;
8654 spin_unlock_irq(shost->host_lock);
8655 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
8656 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
8658 * Driver needs to re-reg VPI in order for f/w
8659 * to update the MAC address.
8661 lpfc_register_new_vport(phba, vport, ndlp);
8665 if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)
8666 lpfc_issue_init_vpi(vport);
8667 else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
8668 lpfc_register_new_vport(phba, vport, ndlp);
8670 lpfc_do_scr_ns_plogi(phba, vport);
8673 if (vport->fc_vport &&
8674 (vport->fc_vport->vport_state != FC_VPORT_NO_FABRIC_RSCS))
8675 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
8676 /* Cancel discovery timer */
8677 lpfc_can_disctmo(vport);
8680 lpfc_els_free_iocb(phba, cmdiocb);
8684 * lpfc_issue_els_fdisc - Issue a fdisc iocb command
8685 * @vport: pointer to a virtual N_Port data structure.
8686 * @ndlp: pointer to a node-list data structure.
8687 * @retry: number of retries to the command IOCB.
8689 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
8690 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
8691 * routine to issue the IOCB, which makes sure only one outstanding fabric
8692 * IOCB will be sent off HBA at any given time.
8694 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
8695 * will be incremented by 1 for holding the ndlp and the reference to ndlp
8696 * will be stored into the context1 field of the IOCB for the completion
8697 * callback function to the FDISC ELS command.
8700 * 0 - Successfully issued fdisc iocb command
8701 * 1 - Failed to issue fdisc iocb command
8704 lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
8707 struct lpfc_hba *phba = vport->phba;
8709 struct lpfc_iocbq *elsiocb;
8710 struct serv_parm *sp;
8713 int did = ndlp->nlp_DID;
8716 vport->port_state = LPFC_FDISC;
8717 vport->fc_myDID = 0;
8718 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
8719 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
8722 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
8723 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8724 "0255 Issue FDISC: no IOCB\n");
8728 icmd = &elsiocb->iocb;
8729 icmd->un.elsreq64.myID = 0;
8730 icmd->un.elsreq64.fl = 1;
8733 * SLI3 ports require a different context type value than SLI4.
8734 * Catch SLI3 ports here and override the prep.
8736 if (phba->sli_rev == LPFC_SLI_REV3) {
8741 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
8742 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
8743 pcmd += sizeof(uint32_t); /* CSP Word 1 */
8744 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
8745 sp = (struct serv_parm *) pcmd;
8746 /* Setup CSPs accordingly for Fabric */
8747 sp->cmn.e_d_tov = 0;
8748 sp->cmn.w2.r_a_tov = 0;
8749 sp->cmn.virtual_fabric_support = 0;
8750 sp->cls1.classValid = 0;
8751 sp->cls2.seqDelivery = 1;
8752 sp->cls3.seqDelivery = 1;
8754 pcmd += sizeof(uint32_t); /* CSP Word 2 */
8755 pcmd += sizeof(uint32_t); /* CSP Word 3 */
8756 pcmd += sizeof(uint32_t); /* CSP Word 4 */
8757 pcmd += sizeof(uint32_t); /* Port Name */
8758 memcpy(pcmd, &vport->fc_portname, 8);
8759 pcmd += sizeof(uint32_t); /* Node Name */
8760 pcmd += sizeof(uint32_t); /* Node Name */
8761 memcpy(pcmd, &vport->fc_nodename, 8);
8762 memset(sp->un.vendorVersion, 0, sizeof(sp->un.vendorVersion));
8763 lpfc_set_disctmo(vport);
8765 phba->fc_stat.elsXmitFDISC++;
8766 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
8768 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
8769 "Issue FDISC: did:x%x",
8772 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
8773 if (rc == IOCB_ERROR) {
8774 lpfc_els_free_iocb(phba, elsiocb);
8775 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
8776 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8777 "0256 Issue FDISC: Cannot send IOCB\n");
8780 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
8785 * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
8786 * @phba: pointer to lpfc hba data structure.
8787 * @cmdiocb: pointer to lpfc command iocb data structure.
8788 * @rspiocb: pointer to lpfc response iocb data structure.
8790 * This routine is the completion callback function to the issuing of a LOGO
8791 * ELS command off a vport. It frees the command IOCB and then decrement the
8792 * reference count held on ndlp for this completion function, indicating that
8793 * the reference to the ndlp is no long needed. Note that the
8794 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
8795 * callback function and an additional explicit ndlp reference decrementation
8796 * will trigger the actual release of the ndlp.
8799 lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
8800 struct lpfc_iocbq *rspiocb)
8802 struct lpfc_vport *vport = cmdiocb->vport;
8804 struct lpfc_nodelist *ndlp;
8805 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8807 ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
8808 irsp = &rspiocb->iocb;
8809 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
8810 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
8811 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
8813 lpfc_els_free_iocb(phba, cmdiocb);
8814 vport->unreg_vpi_cmpl = VPORT_ERROR;
8816 /* Trigger the release of the ndlp after logo */
8819 /* NPIV LOGO completes to NPort <nlp_DID> */
8820 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
8821 "2928 NPIV LOGO completes to NPort x%x "
8822 "Data: x%x x%x x%x x%x\n",
8823 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
8824 irsp->ulpTimeout, vport->num_disc_nodes);
8826 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
8827 spin_lock_irq(shost->host_lock);
8828 vport->fc_flag &= ~FC_NDISC_ACTIVE;
8829 vport->fc_flag &= ~FC_FABRIC;
8830 spin_unlock_irq(shost->host_lock);
8831 lpfc_can_disctmo(vport);
8836 * lpfc_issue_els_npiv_logo - Issue a logo off a vport
8837 * @vport: pointer to a virtual N_Port data structure.
8838 * @ndlp: pointer to a node-list data structure.
8840 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
8842 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
8843 * will be incremented by 1 for holding the ndlp and the reference to ndlp
8844 * will be stored into the context1 field of the IOCB for the completion
8845 * callback function to the LOGO ELS command.
8848 * 0 - Successfully issued logo off the @vport
8849 * 1 - Failed to issue logo off the @vport
8852 lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
8854 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8855 struct lpfc_hba *phba = vport->phba;
8856 struct lpfc_iocbq *elsiocb;
8860 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
8861 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
8866 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
8867 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
8868 pcmd += sizeof(uint32_t);
8870 /* Fill in LOGO payload */
8871 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
8872 pcmd += sizeof(uint32_t);
8873 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
8875 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
8876 "Issue LOGO npiv did:x%x flg:x%x",
8877 ndlp->nlp_DID, ndlp->nlp_flag, 0);
8879 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
8880 spin_lock_irq(shost->host_lock);
8881 ndlp->nlp_flag |= NLP_LOGO_SND;
8882 spin_unlock_irq(shost->host_lock);
8883 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
8885 spin_lock_irq(shost->host_lock);
8886 ndlp->nlp_flag &= ~NLP_LOGO_SND;
8887 spin_unlock_irq(shost->host_lock);
8888 lpfc_els_free_iocb(phba, elsiocb);
8895 * lpfc_fabric_block_timeout - Handler function to the fabric block timer
8896 * @ptr: holder for the timer function associated data.
8898 * This routine is invoked by the fabric iocb block timer after
8899 * timeout. It posts the fabric iocb block timeout event by setting the
8900 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
8901 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
8902 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
8903 * posted event WORKER_FABRIC_BLOCK_TMO.
8906 lpfc_fabric_block_timeout(unsigned long ptr)
8908 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
8909 unsigned long iflags;
8910 uint32_t tmo_posted;
8912 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
8913 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
8915 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
8916 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
8919 lpfc_worker_wake_up(phba);
8924 * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
8925 * @phba: pointer to lpfc hba data structure.
8927 * This routine issues one fabric iocb from the driver internal list to
8928 * the HBA. It first checks whether it's ready to issue one fabric iocb to
8929 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
8930 * remove one pending fabric iocb from the driver internal list and invokes
8931 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
8934 lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
8936 struct lpfc_iocbq *iocb;
8937 unsigned long iflags;
8943 spin_lock_irqsave(&phba->hbalock, iflags);
8944 /* Post any pending iocb to the SLI layer */
8945 if (atomic_read(&phba->fabric_iocb_count) == 0) {
8946 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
8949 /* Increment fabric iocb count to hold the position */
8950 atomic_inc(&phba->fabric_iocb_count);
8952 spin_unlock_irqrestore(&phba->hbalock, iflags);
8954 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
8955 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
8956 iocb->iocb_flag |= LPFC_IO_FABRIC;
8958 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
8959 "Fabric sched1: ste:x%x",
8960 iocb->vport->port_state, 0, 0);
8962 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
8964 if (ret == IOCB_ERROR) {
8965 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
8966 iocb->fabric_iocb_cmpl = NULL;
8967 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
8969 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
8970 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
8971 iocb->iocb_cmpl(phba, iocb, iocb);
8973 atomic_dec(&phba->fabric_iocb_count);
8982 * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
8983 * @phba: pointer to lpfc hba data structure.
8985 * This routine unblocks the issuing fabric iocb command. The function
8986 * will clear the fabric iocb block bit and then invoke the routine
8987 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
8988 * from the driver internal fabric iocb list.
8991 lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
8993 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
8995 lpfc_resume_fabric_iocbs(phba);
9000 * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
9001 * @phba: pointer to lpfc hba data structure.
9003 * This routine blocks the issuing fabric iocb for a specified amount of
9004 * time (currently 100 ms). This is done by set the fabric iocb block bit
9005 * and set up a timeout timer for 100ms. When the block bit is set, no more
9006 * fabric iocb will be issued out of the HBA.
9009 lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
9013 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
9014 /* Start a timer to unblock fabric iocbs after 100ms */
9016 mod_timer(&phba->fabric_block_timer,
9017 jiffies + msecs_to_jiffies(100));
9023 * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
9024 * @phba: pointer to lpfc hba data structure.
9025 * @cmdiocb: pointer to lpfc command iocb data structure.
9026 * @rspiocb: pointer to lpfc response iocb data structure.
9028 * This routine is the callback function that is put to the fabric iocb's
9029 * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
9030 * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
9031 * function first restores and invokes the original iocb's callback function
9032 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
9033 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
9036 lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
9037 struct lpfc_iocbq *rspiocb)
9041 BUG_ON((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC);
9043 switch (rspiocb->iocb.ulpStatus) {
9044 case IOSTAT_NPORT_RJT:
9045 case IOSTAT_FABRIC_RJT:
9046 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
9047 lpfc_block_fabric_iocbs(phba);
9051 case IOSTAT_NPORT_BSY:
9052 case IOSTAT_FABRIC_BSY:
9053 lpfc_block_fabric_iocbs(phba);
9057 stat.un.lsRjtError =
9058 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
9059 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
9060 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
9061 lpfc_block_fabric_iocbs(phba);
9065 BUG_ON(atomic_read(&phba->fabric_iocb_count) == 0);
9067 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
9068 cmdiocb->fabric_iocb_cmpl = NULL;
9069 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
9070 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
9072 atomic_dec(&phba->fabric_iocb_count);
9073 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
9074 /* Post any pending iocbs to HBA */
9075 lpfc_resume_fabric_iocbs(phba);
9080 * lpfc_issue_fabric_iocb - Issue a fabric iocb command
9081 * @phba: pointer to lpfc hba data structure.
9082 * @iocb: pointer to lpfc command iocb data structure.
9084 * This routine is used as the top-level API for issuing a fabric iocb command
9085 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
9086 * function makes sure that only one fabric bound iocb will be outstanding at
9087 * any given time. As such, this function will first check to see whether there
9088 * is already an outstanding fabric iocb on the wire. If so, it will put the
9089 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
9090 * issued later. Otherwise, it will issue the iocb on the wire and update the
9091 * fabric iocb count it indicate that there is one fabric iocb on the wire.
9093 * Note, this implementation has a potential sending out fabric IOCBs out of
9094 * order. The problem is caused by the construction of the "ready" boolen does
9095 * not include the condition that the internal fabric IOCB list is empty. As
9096 * such, it is possible a fabric IOCB issued by this routine might be "jump"
9097 * ahead of the fabric IOCBs in the internal list.
9100 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
9101 * IOCB_ERROR - failed to issue fabric iocb
9104 lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
9106 unsigned long iflags;
9110 BUG_ON(atomic_read(&phba->fabric_iocb_count) > 1);
9112 spin_lock_irqsave(&phba->hbalock, iflags);
9113 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
9114 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
9117 /* Increment fabric iocb count to hold the position */
9118 atomic_inc(&phba->fabric_iocb_count);
9119 spin_unlock_irqrestore(&phba->hbalock, iflags);
9121 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
9122 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
9123 iocb->iocb_flag |= LPFC_IO_FABRIC;
9125 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
9126 "Fabric sched2: ste:x%x",
9127 iocb->vport->port_state, 0, 0);
9129 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
9131 if (ret == IOCB_ERROR) {
9132 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
9133 iocb->fabric_iocb_cmpl = NULL;
9134 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
9135 atomic_dec(&phba->fabric_iocb_count);
9138 spin_lock_irqsave(&phba->hbalock, iflags);
9139 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
9140 spin_unlock_irqrestore(&phba->hbalock, iflags);
9147 * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
9148 * @vport: pointer to a virtual N_Port data structure.
9150 * This routine aborts all the IOCBs associated with a @vport from the
9151 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
9152 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
9153 * list, removes each IOCB associated with the @vport off the list, set the
9154 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
9155 * associated with the IOCB.
9157 static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
9159 LIST_HEAD(completions);
9160 struct lpfc_hba *phba = vport->phba;
9161 struct lpfc_iocbq *tmp_iocb, *piocb;
9163 spin_lock_irq(&phba->hbalock);
9164 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
9167 if (piocb->vport != vport)
9170 list_move_tail(&piocb->list, &completions);
9172 spin_unlock_irq(&phba->hbalock);
9174 /* Cancel all the IOCBs from the completions list */
9175 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
9180 * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
9181 * @ndlp: pointer to a node-list data structure.
9183 * This routine aborts all the IOCBs associated with an @ndlp from the
9184 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
9185 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
9186 * list, removes each IOCB associated with the @ndlp off the list, set the
9187 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
9188 * associated with the IOCB.
9190 void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
9192 LIST_HEAD(completions);
9193 struct lpfc_hba *phba = ndlp->phba;
9194 struct lpfc_iocbq *tmp_iocb, *piocb;
9195 struct lpfc_sli_ring *pring;
9197 pring = lpfc_phba_elsring(phba);
9199 spin_lock_irq(&phba->hbalock);
9200 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
9202 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
9204 list_move_tail(&piocb->list, &completions);
9207 spin_unlock_irq(&phba->hbalock);
9209 /* Cancel all the IOCBs from the completions list */
9210 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
9215 * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
9216 * @phba: pointer to lpfc hba data structure.
9218 * This routine aborts all the IOCBs currently on the driver internal
9219 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
9220 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
9221 * list, removes IOCBs off the list, set the status feild to
9222 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
9225 void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
9227 LIST_HEAD(completions);
9229 spin_lock_irq(&phba->hbalock);
9230 list_splice_init(&phba->fabric_iocb_list, &completions);
9231 spin_unlock_irq(&phba->hbalock);
9233 /* Cancel all the IOCBs from the completions list */
9234 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
9239 * lpfc_sli4_vport_delete_els_xri_aborted -Remove all ndlp references for vport
9240 * @vport: pointer to lpfc vport data structure.
9242 * This routine is invoked by the vport cleanup for deletions and the cleanup
9243 * for an ndlp on removal.
9246 lpfc_sli4_vport_delete_els_xri_aborted(struct lpfc_vport *vport)
9248 struct lpfc_hba *phba = vport->phba;
9249 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
9250 unsigned long iflag = 0;
9252 spin_lock_irqsave(&phba->hbalock, iflag);
9253 spin_lock(&phba->sli4_hba.sgl_list_lock);
9254 list_for_each_entry_safe(sglq_entry, sglq_next,
9255 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
9256 if (sglq_entry->ndlp && sglq_entry->ndlp->vport == vport)
9257 sglq_entry->ndlp = NULL;
9259 spin_unlock(&phba->sli4_hba.sgl_list_lock);
9260 spin_unlock_irqrestore(&phba->hbalock, iflag);
9265 * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
9266 * @phba: pointer to lpfc hba data structure.
9267 * @axri: pointer to the els xri abort wcqe structure.
9269 * This routine is invoked by the worker thread to process a SLI4 slow-path
9273 lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba,
9274 struct sli4_wcqe_xri_aborted *axri)
9276 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
9277 uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri);
9280 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
9281 unsigned long iflag = 0;
9282 struct lpfc_nodelist *ndlp;
9283 struct lpfc_sli_ring *pring;
9285 pring = lpfc_phba_elsring(phba);
9287 spin_lock_irqsave(&phba->hbalock, iflag);
9288 spin_lock(&phba->sli4_hba.sgl_list_lock);
9289 list_for_each_entry_safe(sglq_entry, sglq_next,
9290 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
9291 if (sglq_entry->sli4_xritag == xri) {
9292 list_del(&sglq_entry->list);
9293 ndlp = sglq_entry->ndlp;
9294 sglq_entry->ndlp = NULL;
9295 list_add_tail(&sglq_entry->list,
9296 &phba->sli4_hba.lpfc_els_sgl_list);
9297 sglq_entry->state = SGL_FREED;
9298 spin_unlock(&phba->sli4_hba.sgl_list_lock);
9299 spin_unlock_irqrestore(&phba->hbalock, iflag);
9300 lpfc_set_rrq_active(phba, ndlp,
9301 sglq_entry->sli4_lxritag,
9304 /* Check if TXQ queue needs to be serviced */
9305 if (!(list_empty(&pring->txq)))
9306 lpfc_worker_wake_up(phba);
9310 spin_unlock(&phba->sli4_hba.sgl_list_lock);
9311 lxri = lpfc_sli4_xri_inrange(phba, xri);
9312 if (lxri == NO_XRI) {
9313 spin_unlock_irqrestore(&phba->hbalock, iflag);
9316 spin_lock(&phba->sli4_hba.sgl_list_lock);
9317 sglq_entry = __lpfc_get_active_sglq(phba, lxri);
9318 if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) {
9319 spin_unlock(&phba->sli4_hba.sgl_list_lock);
9320 spin_unlock_irqrestore(&phba->hbalock, iflag);
9323 sglq_entry->state = SGL_XRI_ABORTED;
9324 spin_unlock(&phba->sli4_hba.sgl_list_lock);
9325 spin_unlock_irqrestore(&phba->hbalock, iflag);
9329 /* lpfc_sli_abts_recover_port - Recover a port that failed a BLS_ABORT req.
9330 * @vport: pointer to virtual port object.
9331 * @ndlp: nodelist pointer for the impacted node.
9333 * The driver calls this routine in response to an SLI4 XRI ABORT CQE
9334 * or an SLI3 ASYNC_STATUS_CN event from the port. For either event,
9335 * the driver is required to send a LOGO to the remote node before it
9336 * attempts to recover its login to the remote node.
9339 lpfc_sli_abts_recover_port(struct lpfc_vport *vport,
9340 struct lpfc_nodelist *ndlp)
9342 struct Scsi_Host *shost;
9343 struct lpfc_hba *phba;
9344 unsigned long flags = 0;
9346 shost = lpfc_shost_from_vport(vport);
9348 if (ndlp->nlp_state != NLP_STE_MAPPED_NODE) {
9349 lpfc_printf_log(phba, KERN_INFO,
9350 LOG_SLI, "3093 No rport recovery needed. "
9351 "rport in state 0x%x\n", ndlp->nlp_state);
9354 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
9355 "3094 Start rport recovery on shost id 0x%x "
9356 "fc_id 0x%06x vpi 0x%x rpi 0x%x state 0x%x "
9358 shost->host_no, ndlp->nlp_DID,
9359 vport->vpi, ndlp->nlp_rpi, ndlp->nlp_state,
9362 * The rport is not responding. Remove the FCP-2 flag to prevent
9363 * an ADISC in the follow-up recovery code.
9365 spin_lock_irqsave(shost->host_lock, flags);
9366 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
9367 spin_unlock_irqrestore(shost->host_lock, flags);
9368 lpfc_issue_els_logo(vport, ndlp, 0);
9369 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);