1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2015 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. *
7 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
9 * This program is free software; you can redistribute it and/or *
10 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
20 *******************************************************************/
21 /* See Fibre Channel protocol T11 FC-LS for details */
22 #include <linux/blkdev.h>
23 #include <linux/pci.h>
24 #include <linux/slab.h>
25 #include <linux/interrupt.h>
27 #include <scsi/scsi.h>
28 #include <scsi/scsi_device.h>
29 #include <scsi/scsi_host.h>
30 #include <scsi/scsi_transport_fc.h>
36 #include "lpfc_sli4.h"
38 #include "lpfc_disc.h"
39 #include "lpfc_scsi.h"
41 #include "lpfc_logmsg.h"
42 #include "lpfc_crtn.h"
43 #include "lpfc_vport.h"
44 #include "lpfc_debugfs.h"
46 static int lpfc_els_retry(struct lpfc_hba *, struct lpfc_iocbq *,
48 static void lpfc_cmpl_fabric_iocb(struct lpfc_hba *, struct lpfc_iocbq *,
50 static void lpfc_fabric_abort_vport(struct lpfc_vport *vport);
51 static int lpfc_issue_els_fdisc(struct lpfc_vport *vport,
52 struct lpfc_nodelist *ndlp, uint8_t retry);
53 static int lpfc_issue_fabric_iocb(struct lpfc_hba *phba,
54 struct lpfc_iocbq *iocb);
56 static int lpfc_max_els_tries = 3;
59 * lpfc_els_chk_latt - Check host link attention event for a vport
60 * @vport: pointer to a host virtual N_Port data structure.
62 * This routine checks whether there is an outstanding host link
63 * attention event during the discovery process with the @vport. It is done
64 * by reading the HBA's Host Attention (HA) register. If there is any host
65 * link attention events during this @vport's discovery process, the @vport
66 * shall be marked as FC_ABORT_DISCOVERY, a host link attention clear shall
67 * be issued if the link state is not already in host link cleared state,
68 * and a return code shall indicate whether the host link attention event
71 * Note that, if either the host link is in state LPFC_LINK_DOWN or @vport
72 * state in LPFC_VPORT_READY, the request for checking host link attention
73 * event will be ignored and a return code shall indicate no host link
74 * attention event had happened.
77 * 0 - no host link attention event happened
78 * 1 - host link attention event happened
81 lpfc_els_chk_latt(struct lpfc_vport *vport)
83 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
84 struct lpfc_hba *phba = vport->phba;
87 if (vport->port_state >= LPFC_VPORT_READY ||
88 phba->link_state == LPFC_LINK_DOWN ||
89 phba->sli_rev > LPFC_SLI_REV3)
92 /* Read the HBA Host Attention Register */
93 if (lpfc_readl(phba->HAregaddr, &ha_copy))
96 if (!(ha_copy & HA_LATT))
99 /* Pending Link Event during Discovery */
100 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
101 "0237 Pending Link Event during "
102 "Discovery: State x%x\n",
103 phba->pport->port_state);
105 /* CLEAR_LA should re-enable link attention events and
106 * we should then immediately take a LATT event. The
107 * LATT processing should call lpfc_linkdown() which
108 * will cleanup any left over in-progress discovery
111 spin_lock_irq(shost->host_lock);
112 vport->fc_flag |= FC_ABORT_DISCOVERY;
113 spin_unlock_irq(shost->host_lock);
115 if (phba->link_state != LPFC_CLEAR_LA)
116 lpfc_issue_clear_la(phba, vport);
122 * lpfc_prep_els_iocb - Allocate and prepare a lpfc iocb data structure
123 * @vport: pointer to a host virtual N_Port data structure.
124 * @expectRsp: flag indicating whether response is expected.
125 * @cmdSize: size of the ELS command.
126 * @retry: number of retries to the command IOCB when it fails.
127 * @ndlp: pointer to a node-list data structure.
128 * @did: destination identifier.
129 * @elscmd: the ELS command code.
131 * This routine is used for allocating a lpfc-IOCB data structure from
132 * the driver lpfc-IOCB free-list and prepare the IOCB with the parameters
133 * passed into the routine for discovery state machine to issue an Extended
134 * Link Service (ELS) commands. It is a generic lpfc-IOCB allocation
135 * and preparation routine that is used by all the discovery state machine
136 * routines and the ELS command-specific fields will be later set up by
137 * the individual discovery machine routines after calling this routine
138 * allocating and preparing a generic IOCB data structure. It fills in the
139 * Buffer Descriptor Entries (BDEs), allocates buffers for both command
140 * payload and response payload (if expected). The reference count on the
141 * ndlp is incremented by 1 and the reference to the ndlp is put into
142 * context1 of the IOCB data structure for this IOCB to hold the ndlp
143 * reference for the command's callback function to access later.
146 * Pointer to the newly allocated/prepared els iocb data structure
147 * NULL - when els iocb data structure allocation/preparation failed
150 lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp,
151 uint16_t cmdSize, uint8_t retry,
152 struct lpfc_nodelist *ndlp, uint32_t did,
155 struct lpfc_hba *phba = vport->phba;
156 struct lpfc_iocbq *elsiocb;
157 struct lpfc_dmabuf *pcmd, *prsp, *pbuflist;
158 struct ulp_bde64 *bpl;
162 if (!lpfc_is_link_up(phba))
165 /* Allocate buffer for command iocb */
166 elsiocb = lpfc_sli_get_iocbq(phba);
172 * If this command is for fabric controller and HBA running
173 * in FIP mode send FLOGI, FDISC and LOGO as FIP frames.
175 if ((did == Fabric_DID) &&
176 (phba->hba_flag & HBA_FIP_SUPPORT) &&
177 ((elscmd == ELS_CMD_FLOGI) ||
178 (elscmd == ELS_CMD_FDISC) ||
179 (elscmd == ELS_CMD_LOGO)))
182 elsiocb->iocb_flag |=
183 ((LPFC_ELS_ID_FLOGI << LPFC_FIP_ELS_ID_SHIFT)
184 & LPFC_FIP_ELS_ID_MASK);
187 elsiocb->iocb_flag |=
188 ((LPFC_ELS_ID_FDISC << LPFC_FIP_ELS_ID_SHIFT)
189 & LPFC_FIP_ELS_ID_MASK);
192 elsiocb->iocb_flag |=
193 ((LPFC_ELS_ID_LOGO << LPFC_FIP_ELS_ID_SHIFT)
194 & LPFC_FIP_ELS_ID_MASK);
198 elsiocb->iocb_flag &= ~LPFC_FIP_ELS_ID_MASK;
200 icmd = &elsiocb->iocb;
202 /* fill in BDEs for command */
203 /* Allocate buffer for command payload */
204 pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
206 pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys);
207 if (!pcmd || !pcmd->virt)
208 goto els_iocb_free_pcmb_exit;
210 INIT_LIST_HEAD(&pcmd->list);
212 /* Allocate buffer for response payload */
214 prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
216 prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
218 if (!prsp || !prsp->virt)
219 goto els_iocb_free_prsp_exit;
220 INIT_LIST_HEAD(&prsp->list);
224 /* Allocate buffer for Buffer ptr list */
225 pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
227 pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
229 if (!pbuflist || !pbuflist->virt)
230 goto els_iocb_free_pbuf_exit;
232 INIT_LIST_HEAD(&pbuflist->list);
235 icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
236 icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
237 icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
238 icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64));
240 icmd->un.elsreq64.remoteID = did; /* DID */
241 icmd->ulpCommand = CMD_ELS_REQUEST64_CR;
242 if (elscmd == ELS_CMD_FLOGI)
243 icmd->ulpTimeout = FF_DEF_RATOV * 2;
245 icmd->ulpTimeout = phba->fc_ratov * 2;
247 icmd->un.xseq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
248 icmd->un.xseq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
249 icmd->un.xseq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
250 icmd->un.xseq64.bdl.bdeSize = sizeof(struct ulp_bde64);
251 icmd->un.xseq64.xmit_els_remoteID = did; /* DID */
252 icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX;
254 icmd->ulpBdeCount = 1;
256 icmd->ulpClass = CLASS3;
259 * If we have NPIV enabled, we want to send ELS traffic by VPI.
260 * For SLI4, since the driver controls VPIs we also want to include
261 * all ELS pt2pt protocol traffic as well.
263 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) ||
264 ((phba->sli_rev == LPFC_SLI_REV4) &&
265 (vport->fc_flag & FC_PT2PT))) {
268 icmd->un.elsreq64.myID = vport->fc_myDID;
270 /* For ELS_REQUEST64_CR, use the VPI by default */
271 icmd->ulpContext = phba->vpi_ids[vport->vpi];
275 /* The CT field must be 0=INVALID_RPI for the ECHO cmd */
276 if (elscmd == ELS_CMD_ECHO)
277 icmd->ulpCt_l = 0; /* context = invalid RPI */
279 icmd->ulpCt_l = 1; /* context = VPI */
282 bpl = (struct ulp_bde64 *) pbuflist->virt;
283 bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys));
284 bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys));
285 bpl->tus.f.bdeSize = cmdSize;
286 bpl->tus.f.bdeFlags = 0;
287 bpl->tus.w = le32_to_cpu(bpl->tus.w);
291 bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys));
292 bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys));
293 bpl->tus.f.bdeSize = FCELSSIZE;
294 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
295 bpl->tus.w = le32_to_cpu(bpl->tus.w);
298 /* prevent preparing iocb with NULL ndlp reference */
299 elsiocb->context1 = lpfc_nlp_get(ndlp);
300 if (!elsiocb->context1)
301 goto els_iocb_free_pbuf_exit;
302 elsiocb->context2 = pcmd;
303 elsiocb->context3 = pbuflist;
304 elsiocb->retry = retry;
305 elsiocb->vport = vport;
306 elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT;
309 list_add(&prsp->list, &pcmd->list);
312 /* Xmit ELS command <elsCmd> to remote NPORT <did> */
313 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
314 "0116 Xmit ELS command x%x to remote "
315 "NPORT x%x I/O tag: x%x, port state:x%x"
317 elscmd, did, elsiocb->iotag,
321 /* Xmit ELS response <elsCmd> to remote NPORT <did> */
322 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
323 "0117 Xmit ELS response x%x to remote "
324 "NPORT x%x I/O tag: x%x, size: x%x "
325 "port_state x%x fc_flag x%x\n",
326 elscmd, ndlp->nlp_DID, elsiocb->iotag,
327 cmdSize, vport->port_state,
332 els_iocb_free_pbuf_exit:
334 lpfc_mbuf_free(phba, prsp->virt, prsp->phys);
337 els_iocb_free_prsp_exit:
338 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
341 els_iocb_free_pcmb_exit:
343 lpfc_sli_release_iocbq(phba, elsiocb);
348 * lpfc_issue_fabric_reglogin - Issue fabric registration login for a vport
349 * @vport: pointer to a host virtual N_Port data structure.
351 * This routine issues a fabric registration login for a @vport. An
352 * active ndlp node with Fabric_DID must already exist for this @vport.
353 * The routine invokes two mailbox commands to carry out fabric registration
354 * login through the HBA firmware: the first mailbox command requests the
355 * HBA to perform link configuration for the @vport; and the second mailbox
356 * command requests the HBA to perform the actual fabric registration login
360 * 0 - successfully issued fabric registration login for @vport
361 * -ENXIO -- failed to issue fabric registration login for @vport
364 lpfc_issue_fabric_reglogin(struct lpfc_vport *vport)
366 struct lpfc_hba *phba = vport->phba;
368 struct lpfc_dmabuf *mp;
369 struct lpfc_nodelist *ndlp;
370 struct serv_parm *sp;
374 sp = &phba->fc_fabparam;
375 ndlp = lpfc_findnode_did(vport, Fabric_DID);
376 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
381 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
387 vport->port_state = LPFC_FABRIC_CFG_LINK;
388 lpfc_config_link(phba, mbox);
389 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
392 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
393 if (rc == MBX_NOT_FINISHED) {
398 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
403 rc = lpfc_reg_rpi(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox,
410 mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login;
412 /* increment the reference count on ndlp to hold reference
413 * for the callback routine.
415 mbox->context2 = lpfc_nlp_get(ndlp);
417 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
418 if (rc == MBX_NOT_FINISHED) {
420 goto fail_issue_reg_login;
425 fail_issue_reg_login:
426 /* decrement the reference count on ndlp just incremented
427 * for the failed mbox command.
430 mp = (struct lpfc_dmabuf *) mbox->context1;
431 lpfc_mbuf_free(phba, mp->virt, mp->phys);
434 mempool_free(mbox, phba->mbox_mem_pool);
437 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
438 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
439 "0249 Cannot issue Register Fabric login: Err %d\n", err);
444 * lpfc_issue_reg_vfi - Register VFI for this vport's fabric login
445 * @vport: pointer to a host virtual N_Port data structure.
447 * This routine issues a REG_VFI mailbox for the vfi, vpi, fcfi triplet for
448 * the @vport. This mailbox command is necessary for SLI4 port only.
451 * 0 - successfully issued REG_VFI for @vport
452 * A failure code otherwise.
455 lpfc_issue_reg_vfi(struct lpfc_vport *vport)
457 struct lpfc_hba *phba = vport->phba;
458 LPFC_MBOXQ_t *mboxq = NULL;
459 struct lpfc_nodelist *ndlp;
460 struct lpfc_dmabuf *dmabuf = NULL;
463 /* move forward in case of SLI4 FC port loopback test and pt2pt mode */
464 if ((phba->sli_rev == LPFC_SLI_REV4) &&
465 !(phba->link_flag & LS_LOOPBACK_MODE) &&
466 !(vport->fc_flag & FC_PT2PT)) {
467 ndlp = lpfc_findnode_did(vport, Fabric_DID);
468 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
474 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
480 /* Supply CSP's only if we are fabric connect or pt-to-pt connect */
481 if ((vport->fc_flag & FC_FABRIC) || (vport->fc_flag & FC_PT2PT)) {
482 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
487 dmabuf->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &dmabuf->phys);
492 memcpy(dmabuf->virt, &phba->fc_fabparam,
493 sizeof(struct serv_parm));
496 vport->port_state = LPFC_FABRIC_CFG_LINK;
498 lpfc_reg_vfi(mboxq, vport, dmabuf->phys);
500 lpfc_reg_vfi(mboxq, vport, 0);
502 mboxq->mbox_cmpl = lpfc_mbx_cmpl_reg_vfi;
503 mboxq->vport = vport;
504 mboxq->context1 = dmabuf;
505 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
506 if (rc == MBX_NOT_FINISHED) {
514 mempool_free(mboxq, phba->mbox_mem_pool);
517 lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys);
521 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
522 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
523 "0289 Issue Register VFI failed: Err %d\n", rc);
528 * lpfc_issue_unreg_vfi - Unregister VFI for this vport's fabric login
529 * @vport: pointer to a host virtual N_Port data structure.
531 * This routine issues a UNREG_VFI mailbox with the vfi, vpi, fcfi triplet for
532 * the @vport. This mailbox command is necessary for SLI4 port only.
535 * 0 - successfully issued REG_VFI for @vport
536 * A failure code otherwise.
539 lpfc_issue_unreg_vfi(struct lpfc_vport *vport)
541 struct lpfc_hba *phba = vport->phba;
542 struct Scsi_Host *shost;
546 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
548 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
549 "2556 UNREG_VFI mbox allocation failed"
550 "HBA state x%x\n", phba->pport->port_state);
554 lpfc_unreg_vfi(mboxq, vport);
555 mboxq->vport = vport;
556 mboxq->mbox_cmpl = lpfc_unregister_vfi_cmpl;
558 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
559 if (rc == MBX_NOT_FINISHED) {
560 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
561 "2557 UNREG_VFI issue mbox failed rc x%x "
563 rc, phba->pport->port_state);
564 mempool_free(mboxq, phba->mbox_mem_pool);
568 shost = lpfc_shost_from_vport(vport);
569 spin_lock_irq(shost->host_lock);
570 vport->fc_flag &= ~FC_VFI_REGISTERED;
571 spin_unlock_irq(shost->host_lock);
576 * lpfc_check_clean_addr_bit - Check whether assigned FCID is clean.
577 * @vport: pointer to a host virtual N_Port data structure.
578 * @sp: pointer to service parameter data structure.
580 * This routine is called from FLOGI/FDISC completion handler functions.
581 * lpfc_check_clean_addr_bit return 1 when FCID/Fabric portname/ Fabric
582 * node nodename is changed in the completion service parameter else return
583 * 0. This function also set flag in the vport data structure to delay
584 * NP_Port discovery after the FLOGI/FDISC completion if Clean address bit
585 * in FLOGI/FDISC response is cleared and FCID/Fabric portname/ Fabric
586 * node nodename is changed in the completion service parameter.
589 * 0 - FCID and Fabric Nodename and Fabric portname is not changed.
590 * 1 - FCID or Fabric Nodename or Fabric portname is changed.
594 lpfc_check_clean_addr_bit(struct lpfc_vport *vport,
595 struct serv_parm *sp)
597 uint8_t fabric_param_changed = 0;
598 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
600 if ((vport->fc_prevDID != vport->fc_myDID) ||
601 memcmp(&vport->fabric_portname, &sp->portName,
602 sizeof(struct lpfc_name)) ||
603 memcmp(&vport->fabric_nodename, &sp->nodeName,
604 sizeof(struct lpfc_name)))
605 fabric_param_changed = 1;
608 * Word 1 Bit 31 in common service parameter is overloaded.
609 * Word 1 Bit 31 in FLOGI request is multiple NPort request
610 * Word 1 Bit 31 in FLOGI response is clean address bit
612 * If fabric parameter is changed and clean address bit is
613 * cleared delay nport discovery if
614 * - vport->fc_prevDID != 0 (not initial discovery) OR
615 * - lpfc_delay_discovery module parameter is set.
617 if (fabric_param_changed && !sp->cmn.clean_address_bit &&
618 (vport->fc_prevDID || lpfc_delay_discovery)) {
619 spin_lock_irq(shost->host_lock);
620 vport->fc_flag |= FC_DISC_DELAYED;
621 spin_unlock_irq(shost->host_lock);
624 return fabric_param_changed;
629 * lpfc_cmpl_els_flogi_fabric - Completion function for flogi to a fabric port
630 * @vport: pointer to a host virtual N_Port data structure.
631 * @ndlp: pointer to a node-list data structure.
632 * @sp: pointer to service parameter data structure.
633 * @irsp: pointer to the IOCB within the lpfc response IOCB.
635 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
636 * function to handle the completion of a Fabric Login (FLOGI) into a fabric
637 * port in a fabric topology. It properly sets up the parameters to the @ndlp
638 * from the IOCB response. It also check the newly assigned N_Port ID to the
639 * @vport against the previously assigned N_Port ID. If it is different from
640 * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine
641 * is invoked on all the remaining nodes with the @vport to unregister the
642 * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin()
643 * is invoked to register login to the fabric.
646 * 0 - Success (currently, always return 0)
649 lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
650 struct serv_parm *sp, IOCB_t *irsp)
652 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
653 struct lpfc_hba *phba = vport->phba;
654 struct lpfc_nodelist *np;
655 struct lpfc_nodelist *next_np;
656 uint8_t fabric_param_changed;
658 spin_lock_irq(shost->host_lock);
659 vport->fc_flag |= FC_FABRIC;
660 spin_unlock_irq(shost->host_lock);
662 phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
663 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
664 phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
666 phba->fc_edtovResol = sp->cmn.edtovResolution;
667 phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
669 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
670 spin_lock_irq(shost->host_lock);
671 vport->fc_flag |= FC_PUBLIC_LOOP;
672 spin_unlock_irq(shost->host_lock);
675 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
676 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
677 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name));
678 ndlp->nlp_class_sup = 0;
679 if (sp->cls1.classValid)
680 ndlp->nlp_class_sup |= FC_COS_CLASS1;
681 if (sp->cls2.classValid)
682 ndlp->nlp_class_sup |= FC_COS_CLASS2;
683 if (sp->cls3.classValid)
684 ndlp->nlp_class_sup |= FC_COS_CLASS3;
685 if (sp->cls4.classValid)
686 ndlp->nlp_class_sup |= FC_COS_CLASS4;
687 ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
688 sp->cmn.bbRcvSizeLsb;
690 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
691 memcpy(&vport->fabric_portname, &sp->portName,
692 sizeof(struct lpfc_name));
693 memcpy(&vport->fabric_nodename, &sp->nodeName,
694 sizeof(struct lpfc_name));
695 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
697 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
698 if (sp->cmn.response_multiple_NPort) {
699 lpfc_printf_vlog(vport, KERN_WARNING,
701 "1816 FLOGI NPIV supported, "
702 "response data 0x%x\n",
703 sp->cmn.response_multiple_NPort);
704 spin_lock_irq(&phba->hbalock);
705 phba->link_flag |= LS_NPIV_FAB_SUPPORTED;
706 spin_unlock_irq(&phba->hbalock);
708 /* Because we asked f/w for NPIV it still expects us
709 to call reg_vnpid atleast for the physcial host */
710 lpfc_printf_vlog(vport, KERN_WARNING,
712 "1817 Fabric does not support NPIV "
713 "- configuring single port mode.\n");
714 spin_lock_irq(&phba->hbalock);
715 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
716 spin_unlock_irq(&phba->hbalock);
721 * For FC we need to do some special processing because of the SLI
722 * Port's default settings of the Common Service Parameters.
724 if ((phba->sli_rev == LPFC_SLI_REV4) &&
725 (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC)) {
726 /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */
727 if (fabric_param_changed)
728 lpfc_unregister_fcf_prep(phba);
730 /* This should just update the VFI CSPs*/
731 if (vport->fc_flag & FC_VFI_REGISTERED)
732 lpfc_issue_reg_vfi(vport);
735 if (fabric_param_changed &&
736 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
738 /* If our NportID changed, we need to ensure all
739 * remaining NPORTs get unreg_login'ed.
741 list_for_each_entry_safe(np, next_np,
742 &vport->fc_nodes, nlp_listp) {
743 if (!NLP_CHK_NODE_ACT(np))
745 if ((np->nlp_state != NLP_STE_NPR_NODE) ||
746 !(np->nlp_flag & NLP_NPR_ADISC))
748 spin_lock_irq(shost->host_lock);
749 np->nlp_flag &= ~NLP_NPR_ADISC;
750 spin_unlock_irq(shost->host_lock);
751 lpfc_unreg_rpi(vport, np);
753 lpfc_cleanup_pending_mbox(vport);
755 if (phba->sli_rev == LPFC_SLI_REV4) {
756 lpfc_sli4_unreg_all_rpis(vport);
757 lpfc_mbx_unreg_vpi(vport);
758 spin_lock_irq(shost->host_lock);
759 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
760 spin_unlock_irq(shost->host_lock);
764 * For SLI3 and SLI4, the VPI needs to be reregistered in
765 * response to this fabric parameter change event.
767 spin_lock_irq(shost->host_lock);
768 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
769 spin_unlock_irq(shost->host_lock);
770 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
771 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
773 * Driver needs to re-reg VPI in order for f/w
774 * to update the MAC address.
776 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
777 lpfc_register_new_vport(phba, vport, ndlp);
781 if (phba->sli_rev < LPFC_SLI_REV4) {
782 lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
783 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED &&
784 vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
785 lpfc_register_new_vport(phba, vport, ndlp);
787 lpfc_issue_fabric_reglogin(vport);
789 ndlp->nlp_type |= NLP_FABRIC;
790 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
791 if ((!(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) &&
792 (vport->vpi_state & LPFC_VPI_REGISTERED)) {
793 lpfc_start_fdiscs(phba);
794 lpfc_do_scr_ns_plogi(phba, vport);
795 } else if (vport->fc_flag & FC_VFI_REGISTERED)
796 lpfc_issue_init_vpi(vport);
798 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
799 "3135 Need register VFI: (x%x/%x)\n",
800 vport->fc_prevDID, vport->fc_myDID);
801 lpfc_issue_reg_vfi(vport);
808 * lpfc_cmpl_els_flogi_nport - Completion function for flogi to an N_Port
809 * @vport: pointer to a host virtual N_Port data structure.
810 * @ndlp: pointer to a node-list data structure.
811 * @sp: pointer to service parameter data structure.
813 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
814 * function to handle the completion of a Fabric Login (FLOGI) into an N_Port
815 * in a point-to-point topology. First, the @vport's N_Port Name is compared
816 * with the received N_Port Name: if the @vport's N_Port Name is greater than
817 * the received N_Port Name lexicographically, this node shall assign local
818 * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and
819 * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise,
820 * this node shall just wait for the remote node to issue PLOGI and assign
828 lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
829 struct serv_parm *sp)
831 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
832 struct lpfc_hba *phba = vport->phba;
836 spin_lock_irq(shost->host_lock);
837 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
838 vport->fc_flag |= FC_PT2PT;
839 spin_unlock_irq(shost->host_lock);
841 /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */
842 if ((phba->sli_rev == LPFC_SLI_REV4) && phba->fc_topology_changed) {
843 lpfc_unregister_fcf_prep(phba);
845 spin_lock_irq(shost->host_lock);
846 vport->fc_flag &= ~FC_VFI_REGISTERED;
847 spin_unlock_irq(shost->host_lock);
848 phba->fc_topology_changed = 0;
851 rc = memcmp(&vport->fc_portname, &sp->portName,
852 sizeof(vport->fc_portname));
855 /* This side will initiate the PLOGI */
856 spin_lock_irq(shost->host_lock);
857 vport->fc_flag |= FC_PT2PT_PLOGI;
858 spin_unlock_irq(shost->host_lock);
861 * N_Port ID cannot be 0, set our Id to LocalID
862 * the other side will be RemoteID.
867 vport->fc_myDID = PT2PT_LocalID;
869 /* Decrement ndlp reference count indicating that ndlp can be
870 * safely released when other references to it are done.
874 ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
877 * Cannot find existing Fabric ndlp, so allocate a
880 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
883 lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID);
884 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
885 ndlp = lpfc_enable_node(vport, ndlp,
886 NLP_STE_UNUSED_NODE);
891 memcpy(&ndlp->nlp_portname, &sp->portName,
892 sizeof(struct lpfc_name));
893 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
894 sizeof(struct lpfc_name));
895 /* Set state will put ndlp onto node list if not already done */
896 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
897 spin_lock_irq(shost->host_lock);
898 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
899 spin_unlock_irq(shost->host_lock);
901 /* This side will wait for the PLOGI, decrement ndlp reference
902 * count indicating that ndlp can be released when other
903 * references to it are done.
907 /* If we are pt2pt with another NPort, force NPIV off! */
908 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
910 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
914 lpfc_config_link(phba, mbox);
916 mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link;
918 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
919 if (rc == MBX_NOT_FINISHED) {
920 mempool_free(mbox, phba->mbox_mem_pool);
930 * lpfc_cmpl_els_flogi - Completion callback function for flogi
931 * @phba: pointer to lpfc hba data structure.
932 * @cmdiocb: pointer to lpfc command iocb data structure.
933 * @rspiocb: pointer to lpfc response iocb data structure.
935 * This routine is the top-level completion callback function for issuing
936 * a Fabric Login (FLOGI) command. If the response IOCB reported error,
937 * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If
938 * retry has been made (either immediately or delayed with lpfc_els_retry()
939 * returning 1), the command IOCB will be released and function returned.
940 * If the retry attempt has been given up (possibly reach the maximum
941 * number of retries), one additional decrement of ndlp reference shall be
942 * invoked before going out after releasing the command IOCB. This will
943 * actually release the remote node (Note, lpfc_els_free_iocb() will also
944 * invoke one decrement of ndlp reference count). If no error reported in
945 * the IOCB status, the command Port ID field is used to determine whether
946 * this is a point-to-point topology or a fabric topology: if the Port ID
947 * field is assigned, it is a fabric topology; otherwise, it is a
948 * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or
949 * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the
950 * specific topology completion conditions.
953 lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
954 struct lpfc_iocbq *rspiocb)
956 struct lpfc_vport *vport = cmdiocb->vport;
957 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
958 IOCB_t *irsp = &rspiocb->iocb;
959 struct lpfc_nodelist *ndlp = cmdiocb->context1;
960 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
961 struct serv_parm *sp;
965 /* Check to see if link went down during discovery */
966 if (lpfc_els_chk_latt(vport)) {
967 /* One additional decrement on node reference count to
968 * trigger the release of the node
974 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
975 "FLOGI cmpl: status:x%x/x%x state:x%x",
976 irsp->ulpStatus, irsp->un.ulpWord[4],
979 if (irsp->ulpStatus) {
981 * In case of FIP mode, perform roundrobin FCF failover
982 * due to new FCF discovery
984 if ((phba->hba_flag & HBA_FIP_SUPPORT) &&
985 (phba->fcf.fcf_flag & FCF_DISCOVERY)) {
986 if (phba->link_state < LPFC_LINK_UP)
987 goto stop_rr_fcf_flogi;
988 if ((phba->fcoe_cvl_eventtag_attn ==
989 phba->fcoe_cvl_eventtag) &&
990 (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
991 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
993 goto stop_rr_fcf_flogi;
995 phba->fcoe_cvl_eventtag_attn =
996 phba->fcoe_cvl_eventtag;
997 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
998 "2611 FLOGI failed on FCF (x%x), "
999 "status:x%x/x%x, tmo:x%x, perform "
1000 "roundrobin FCF failover\n",
1001 phba->fcf.current_rec.fcf_indx,
1002 irsp->ulpStatus, irsp->un.ulpWord[4],
1004 lpfc_sli4_set_fcf_flogi_fail(phba,
1005 phba->fcf.current_rec.fcf_indx);
1006 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
1007 rc = lpfc_sli4_fcf_rr_next_proc(vport, fcf_index);
1014 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1015 "2858 FLOGI failure Status:x%x/x%x TMO:x%x "
1017 irsp->ulpStatus, irsp->un.ulpWord[4],
1018 irsp->ulpTimeout, phba->hba_flag,
1019 phba->fcf.fcf_flag);
1021 /* Check for retry */
1022 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
1026 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1027 "0100 FLOGI failure Status:x%x/x%x TMO:x%x\n",
1028 irsp->ulpStatus, irsp->un.ulpWord[4],
1031 /* FLOGI failed, so there is no fabric */
1032 spin_lock_irq(shost->host_lock);
1033 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
1034 spin_unlock_irq(shost->host_lock);
1036 /* If private loop, then allow max outstanding els to be
1037 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
1038 * alpa map would take too long otherwise.
1040 if (phba->alpa_map[0] == 0)
1041 vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
1042 if ((phba->sli_rev == LPFC_SLI_REV4) &&
1043 (!(vport->fc_flag & FC_VFI_REGISTERED) ||
1044 (vport->fc_prevDID != vport->fc_myDID) ||
1045 phba->fc_topology_changed)) {
1046 if (vport->fc_flag & FC_VFI_REGISTERED) {
1047 if (phba->fc_topology_changed) {
1048 lpfc_unregister_fcf_prep(phba);
1049 spin_lock_irq(shost->host_lock);
1050 vport->fc_flag &= ~FC_VFI_REGISTERED;
1051 spin_unlock_irq(shost->host_lock);
1052 phba->fc_topology_changed = 0;
1054 lpfc_sli4_unreg_all_rpis(vport);
1057 lpfc_issue_reg_vfi(vport);
1063 spin_lock_irq(shost->host_lock);
1064 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
1065 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
1066 spin_unlock_irq(shost->host_lock);
1069 * The FLogI succeeded. Sync the data for the CPU before
1072 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
1075 sp = prsp->virt + sizeof(uint32_t);
1077 /* FLOGI completes successfully */
1078 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1079 "0101 FLOGI completes successfully, I/O tag:x%x, "
1080 "Data: x%x x%x x%x x%x x%x x%x\n", cmdiocb->iotag,
1081 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
1082 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution,
1083 vport->port_state, vport->fc_flag);
1085 if (vport->port_state == LPFC_FLOGI) {
1087 * If Common Service Parameters indicate Nport
1088 * we are point to point, if Fport we are Fabric.
1091 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
1092 else if (!(phba->hba_flag & HBA_FCOE_MODE))
1093 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
1095 lpfc_printf_vlog(vport, KERN_ERR,
1097 "2831 FLOGI response with cleared Fabric "
1098 "bit fcf_index 0x%x "
1099 "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x "
1101 "%02x%02x%02x%02x%02x%02x%02x%02x\n",
1102 phba->fcf.current_rec.fcf_indx,
1103 phba->fcf.current_rec.switch_name[0],
1104 phba->fcf.current_rec.switch_name[1],
1105 phba->fcf.current_rec.switch_name[2],
1106 phba->fcf.current_rec.switch_name[3],
1107 phba->fcf.current_rec.switch_name[4],
1108 phba->fcf.current_rec.switch_name[5],
1109 phba->fcf.current_rec.switch_name[6],
1110 phba->fcf.current_rec.switch_name[7],
1111 phba->fcf.current_rec.fabric_name[0],
1112 phba->fcf.current_rec.fabric_name[1],
1113 phba->fcf.current_rec.fabric_name[2],
1114 phba->fcf.current_rec.fabric_name[3],
1115 phba->fcf.current_rec.fabric_name[4],
1116 phba->fcf.current_rec.fabric_name[5],
1117 phba->fcf.current_rec.fabric_name[6],
1118 phba->fcf.current_rec.fabric_name[7]);
1120 spin_lock_irq(&phba->hbalock);
1121 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
1122 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
1123 spin_unlock_irq(&phba->hbalock);
1127 /* Mark the FCF discovery process done */
1128 if (phba->hba_flag & HBA_FIP_SUPPORT)
1129 lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP |
1131 "2769 FLOGI to FCF (x%x) "
1132 "completed successfully\n",
1133 phba->fcf.current_rec.fcf_indx);
1134 spin_lock_irq(&phba->hbalock);
1135 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
1136 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
1137 spin_unlock_irq(&phba->hbalock);
1143 spin_lock_irq(&phba->hbalock);
1144 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
1145 spin_unlock_irq(&phba->hbalock);
1149 if (!lpfc_error_lost_link(irsp)) {
1150 /* FLOGI failed, so just use loop map to make discovery list */
1151 lpfc_disc_list_loopmap(vport);
1153 /* Start discovery */
1154 lpfc_disc_start(vport);
1155 } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
1156 (((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
1157 IOERR_SLI_ABORTED) &&
1158 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
1159 IOERR_SLI_DOWN))) &&
1160 (phba->link_state != LPFC_CLEAR_LA)) {
1161 /* If FLOGI failed enable link interrupt. */
1162 lpfc_issue_clear_la(phba, vport);
1165 lpfc_els_free_iocb(phba, cmdiocb);
1169 * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport
1170 * @vport: pointer to a host virtual N_Port data structure.
1171 * @ndlp: pointer to a node-list data structure.
1172 * @retry: number of retries to the command IOCB.
1174 * This routine issues a Fabric Login (FLOGI) Request ELS command
1175 * for a @vport. The initiator service parameters are put into the payload
1176 * of the FLOGI Request IOCB and the top-level callback function pointer
1177 * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
1178 * function field. The lpfc_issue_fabric_iocb routine is invoked to send
1179 * out FLOGI ELS command with one outstanding fabric IOCB at a time.
1181 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1182 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1183 * will be stored into the context1 field of the IOCB for the completion
1184 * callback function to the FLOGI ELS command.
1187 * 0 - successfully issued flogi iocb for @vport
1188 * 1 - failed to issue flogi iocb for @vport
1191 lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1194 struct lpfc_hba *phba = vport->phba;
1195 struct serv_parm *sp;
1197 struct lpfc_iocbq *elsiocb;
1203 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
1204 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1205 ndlp->nlp_DID, ELS_CMD_FLOGI);
1210 icmd = &elsiocb->iocb;
1211 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1213 /* For FLOGI request, remainder of payload is service parameters */
1214 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
1215 pcmd += sizeof(uint32_t);
1216 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
1217 sp = (struct serv_parm *) pcmd;
1219 /* Setup CSPs accordingly for Fabric */
1220 sp->cmn.e_d_tov = 0;
1221 sp->cmn.w2.r_a_tov = 0;
1222 sp->cmn.virtual_fabric_support = 0;
1223 sp->cls1.classValid = 0;
1224 if (sp->cmn.fcphLow < FC_PH3)
1225 sp->cmn.fcphLow = FC_PH3;
1226 if (sp->cmn.fcphHigh < FC_PH3)
1227 sp->cmn.fcphHigh = FC_PH3;
1229 if (phba->sli_rev == LPFC_SLI_REV4) {
1230 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
1231 LPFC_SLI_INTF_IF_TYPE_0) {
1232 elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1);
1233 elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1);
1234 /* FLOGI needs to be 3 for WQE FCFI */
1235 /* Set the fcfi to the fcfi we registered with */
1236 elsiocb->iocb.ulpContext = phba->fcf.fcfi;
1238 /* Can't do SLI4 class2 without support sequence coalescing */
1239 sp->cls2.classValid = 0;
1240 sp->cls2.seqDelivery = 0;
1242 /* Historical, setting sequential-delivery bit for SLI3 */
1243 sp->cls2.seqDelivery = (sp->cls2.classValid) ? 1 : 0;
1244 sp->cls3.seqDelivery = (sp->cls3.classValid) ? 1 : 0;
1245 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
1246 sp->cmn.request_multiple_Nport = 1;
1247 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
1251 sp->cmn.request_multiple_Nport = 0;
1254 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
1255 icmd->un.elsreq64.myID = 0;
1256 icmd->un.elsreq64.fl = 1;
1259 tmo = phba->fc_ratov;
1260 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
1261 lpfc_set_disctmo(vport);
1262 phba->fc_ratov = tmo;
1264 phba->fc_stat.elsXmitFLOGI++;
1265 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
1267 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1268 "Issue FLOGI: opt:x%x",
1269 phba->sli3_options, 0, 0);
1271 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
1272 if (rc == IOCB_ERROR) {
1273 lpfc_els_free_iocb(phba, elsiocb);
1280 * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs
1281 * @phba: pointer to lpfc hba data structure.
1283 * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
1284 * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
1285 * list and issues an abort IOCB commond on each outstanding IOCB that
1286 * contains a active Fabric_DID ndlp. Note that this function is to issue
1287 * the abort IOCB command on all the outstanding IOCBs, thus when this
1288 * function returns, it does not guarantee all the IOCBs are actually aborted.
1291 * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0)
1294 lpfc_els_abort_flogi(struct lpfc_hba *phba)
1296 struct lpfc_sli_ring *pring;
1297 struct lpfc_iocbq *iocb, *next_iocb;
1298 struct lpfc_nodelist *ndlp;
1301 /* Abort outstanding I/O on NPort <nlp_DID> */
1302 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
1303 "0201 Abort outstanding I/O on NPort x%x\n",
1306 pring = &phba->sli.ring[LPFC_ELS_RING];
1309 * Check the txcmplq for an iocb that matches the nport the driver is
1312 spin_lock_irq(&phba->hbalock);
1313 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
1315 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR) {
1316 ndlp = (struct lpfc_nodelist *)(iocb->context1);
1317 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
1318 (ndlp->nlp_DID == Fabric_DID))
1319 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
1322 spin_unlock_irq(&phba->hbalock);
1328 * lpfc_initial_flogi - Issue an initial fabric login for a vport
1329 * @vport: pointer to a host virtual N_Port data structure.
1331 * This routine issues an initial Fabric Login (FLOGI) for the @vport
1332 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1333 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1334 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1335 * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
1336 * is then invoked with the @vport and the ndlp to perform the FLOGI for the
1340 * 0 - failed to issue initial flogi for @vport
1341 * 1 - successfully issued initial flogi for @vport
1344 lpfc_initial_flogi(struct lpfc_vport *vport)
1346 struct lpfc_hba *phba = vport->phba;
1347 struct lpfc_nodelist *ndlp;
1349 vport->port_state = LPFC_FLOGI;
1350 lpfc_set_disctmo(vport);
1352 /* First look for the Fabric ndlp */
1353 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1355 /* Cannot find existing Fabric ndlp, so allocate a new one */
1356 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1359 lpfc_nlp_init(vport, ndlp, Fabric_DID);
1360 /* Set the node type */
1361 ndlp->nlp_type |= NLP_FABRIC;
1362 /* Put ndlp onto node list */
1363 lpfc_enqueue_node(vport, ndlp);
1364 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1365 /* re-setup ndlp without removing from node list */
1366 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1371 if (lpfc_issue_els_flogi(vport, ndlp, 0)) {
1372 /* This decrement of reference count to node shall kick off
1373 * the release of the node.
1382 * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport
1383 * @vport: pointer to a host virtual N_Port data structure.
1385 * This routine issues an initial Fabric Discover (FDISC) for the @vport
1386 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1387 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1388 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1389 * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
1390 * is then invoked with the @vport and the ndlp to perform the FDISC for the
1394 * 0 - failed to issue initial fdisc for @vport
1395 * 1 - successfully issued initial fdisc for @vport
1398 lpfc_initial_fdisc(struct lpfc_vport *vport)
1400 struct lpfc_hba *phba = vport->phba;
1401 struct lpfc_nodelist *ndlp;
1403 /* First look for the Fabric ndlp */
1404 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1406 /* Cannot find existing Fabric ndlp, so allocate a new one */
1407 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1410 lpfc_nlp_init(vport, ndlp, Fabric_DID);
1411 /* Put ndlp onto node list */
1412 lpfc_enqueue_node(vport, ndlp);
1413 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1414 /* re-setup ndlp without removing from node list */
1415 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1420 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
1421 /* decrement node reference count to trigger the release of
1431 * lpfc_more_plogi - Check and issue remaining plogis for a vport
1432 * @vport: pointer to a host virtual N_Port data structure.
1434 * This routine checks whether there are more remaining Port Logins
1435 * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
1436 * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
1437 * to issue ELS PLOGIs up to the configured discover threads with the
1438 * @vport (@vport->cfg_discovery_threads). The function also decrement
1439 * the @vport's num_disc_node by 1 if it is not already 0.
1442 lpfc_more_plogi(struct lpfc_vport *vport)
1444 if (vport->num_disc_nodes)
1445 vport->num_disc_nodes--;
1447 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
1448 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1449 "0232 Continue discovery with %d PLOGIs to go "
1450 "Data: x%x x%x x%x\n",
1451 vport->num_disc_nodes, vport->fc_plogi_cnt,
1452 vport->fc_flag, vport->port_state);
1453 /* Check to see if there are more PLOGIs to be sent */
1454 if (vport->fc_flag & FC_NLP_MORE)
1455 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
1456 lpfc_els_disc_plogi(vport);
1462 * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp
1463 * @phba: pointer to lpfc hba data structure.
1464 * @prsp: pointer to response IOCB payload.
1465 * @ndlp: pointer to a node-list data structure.
1467 * This routine checks and indicates whether the WWPN of an N_Port, retrieved
1468 * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
1469 * The following cases are considered N_Port confirmed:
1470 * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
1471 * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
1472 * it does not have WWPN assigned either. If the WWPN is confirmed, the
1473 * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
1474 * 1) if there is a node on vport list other than the @ndlp with the same
1475 * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
1476 * on that node to release the RPI associated with the node; 2) if there is
1477 * no node found on vport list with the same WWPN of the N_Port PLOGI logged
1478 * into, a new node shall be allocated (or activated). In either case, the
1479 * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
1480 * be released and the new_ndlp shall be put on to the vport node list and
1481 * its pointer returned as the confirmed node.
1483 * Note that before the @ndlp got "released", the keepDID from not-matching
1484 * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
1485 * of the @ndlp. This is because the release of @ndlp is actually to put it
1486 * into an inactive state on the vport node list and the vport node list
1487 * management algorithm does not allow two node with a same DID.
1490 * pointer to the PLOGI N_Port @ndlp
1492 static struct lpfc_nodelist *
1493 lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
1494 struct lpfc_nodelist *ndlp)
1496 struct lpfc_vport *vport = ndlp->vport;
1497 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1498 struct lpfc_nodelist *new_ndlp;
1499 struct lpfc_rport_data *rdata;
1500 struct fc_rport *rport;
1501 struct serv_parm *sp;
1502 uint8_t name[sizeof(struct lpfc_name)];
1503 uint32_t rc, keepDID = 0, keep_nlp_flag = 0;
1504 uint16_t keep_nlp_state;
1507 unsigned long *active_rrqs_xri_bitmap = NULL;
1509 /* Fabric nodes can have the same WWPN so we don't bother searching
1510 * by WWPN. Just return the ndlp that was given to us.
1512 if (ndlp->nlp_type & NLP_FABRIC)
1515 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
1516 memset(name, 0, sizeof(struct lpfc_name));
1518 /* Now we find out if the NPort we are logging into, matches the WWPN
1519 * we have for that ndlp. If not, we have some work to do.
1521 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
1523 if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp))
1525 if (phba->sli_rev == LPFC_SLI_REV4) {
1526 active_rrqs_xri_bitmap = mempool_alloc(phba->active_rrq_pool,
1528 if (active_rrqs_xri_bitmap)
1529 memset(active_rrqs_xri_bitmap, 0,
1530 phba->cfg_rrq_xri_bitmap_sz);
1533 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1534 "3178 PLOGI confirm: ndlp %p x%x: new_ndlp %p\n",
1535 ndlp, ndlp->nlp_DID, new_ndlp);
1538 rc = memcmp(&ndlp->nlp_portname, name,
1539 sizeof(struct lpfc_name));
1541 if (active_rrqs_xri_bitmap)
1542 mempool_free(active_rrqs_xri_bitmap,
1543 phba->active_rrq_pool);
1546 new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
1548 if (active_rrqs_xri_bitmap)
1549 mempool_free(active_rrqs_xri_bitmap,
1550 phba->active_rrq_pool);
1553 lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID);
1554 } else if (!NLP_CHK_NODE_ACT(new_ndlp)) {
1555 rc = memcmp(&ndlp->nlp_portname, name,
1556 sizeof(struct lpfc_name));
1558 if (active_rrqs_xri_bitmap)
1559 mempool_free(active_rrqs_xri_bitmap,
1560 phba->active_rrq_pool);
1563 new_ndlp = lpfc_enable_node(vport, new_ndlp,
1564 NLP_STE_UNUSED_NODE);
1566 if (active_rrqs_xri_bitmap)
1567 mempool_free(active_rrqs_xri_bitmap,
1568 phba->active_rrq_pool);
1571 keepDID = new_ndlp->nlp_DID;
1572 if ((phba->sli_rev == LPFC_SLI_REV4) && active_rrqs_xri_bitmap)
1573 memcpy(active_rrqs_xri_bitmap,
1574 new_ndlp->active_rrqs_xri_bitmap,
1575 phba->cfg_rrq_xri_bitmap_sz);
1577 keepDID = new_ndlp->nlp_DID;
1578 if (phba->sli_rev == LPFC_SLI_REV4 &&
1579 active_rrqs_xri_bitmap)
1580 memcpy(active_rrqs_xri_bitmap,
1581 new_ndlp->active_rrqs_xri_bitmap,
1582 phba->cfg_rrq_xri_bitmap_sz);
1585 lpfc_unreg_rpi(vport, new_ndlp);
1586 new_ndlp->nlp_DID = ndlp->nlp_DID;
1587 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
1588 if (phba->sli_rev == LPFC_SLI_REV4)
1589 memcpy(new_ndlp->active_rrqs_xri_bitmap,
1590 ndlp->active_rrqs_xri_bitmap,
1591 phba->cfg_rrq_xri_bitmap_sz);
1593 spin_lock_irq(shost->host_lock);
1594 keep_nlp_flag = new_ndlp->nlp_flag;
1595 new_ndlp->nlp_flag = ndlp->nlp_flag;
1596 ndlp->nlp_flag = keep_nlp_flag;
1597 spin_unlock_irq(shost->host_lock);
1599 /* Set nlp_states accordingly */
1600 keep_nlp_state = new_ndlp->nlp_state;
1601 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
1603 /* Move this back to NPR state */
1604 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
1605 /* The new_ndlp is replacing ndlp totally, so we need
1606 * to put ndlp on UNUSED list and try to free it.
1608 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1609 "3179 PLOGI confirm NEW: %x %x\n",
1610 new_ndlp->nlp_DID, keepDID);
1612 /* Fix up the rport accordingly */
1613 rport = ndlp->rport;
1615 rdata = rport->dd_data;
1616 if (rdata->pnode == ndlp) {
1617 /* break the link before dropping the ref */
1620 rdata->pnode = lpfc_nlp_get(new_ndlp);
1621 new_ndlp->rport = rport;
1623 new_ndlp->nlp_type = ndlp->nlp_type;
1625 /* We shall actually free the ndlp with both nlp_DID and
1626 * nlp_portname fields equals 0 to avoid any ndlp on the
1627 * nodelist never to be used.
1629 if (ndlp->nlp_DID == 0) {
1630 spin_lock_irq(&phba->ndlp_lock);
1631 NLP_SET_FREE_REQ(ndlp);
1632 spin_unlock_irq(&phba->ndlp_lock);
1635 /* Two ndlps cannot have the same did on the nodelist */
1636 ndlp->nlp_DID = keepDID;
1637 if (phba->sli_rev == LPFC_SLI_REV4 &&
1638 active_rrqs_xri_bitmap)
1639 memcpy(ndlp->active_rrqs_xri_bitmap,
1640 active_rrqs_xri_bitmap,
1641 phba->cfg_rrq_xri_bitmap_sz);
1643 if (!NLP_CHK_NODE_ACT(ndlp))
1644 lpfc_drop_node(vport, ndlp);
1647 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1648 "3180 PLOGI confirm SWAP: %x %x\n",
1649 new_ndlp->nlp_DID, keepDID);
1651 lpfc_unreg_rpi(vport, ndlp);
1653 /* Two ndlps cannot have the same did */
1654 ndlp->nlp_DID = keepDID;
1655 if (phba->sli_rev == LPFC_SLI_REV4 &&
1656 active_rrqs_xri_bitmap)
1657 memcpy(ndlp->active_rrqs_xri_bitmap,
1658 active_rrqs_xri_bitmap,
1659 phba->cfg_rrq_xri_bitmap_sz);
1661 /* Since we are switching over to the new_ndlp,
1662 * reset the old ndlp state
1664 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
1665 (ndlp->nlp_state == NLP_STE_MAPPED_NODE))
1666 keep_nlp_state = NLP_STE_NPR_NODE;
1667 lpfc_nlp_set_state(vport, ndlp, keep_nlp_state);
1669 /* Fix up the rport accordingly */
1670 rport = ndlp->rport;
1672 rdata = rport->dd_data;
1673 put_node = rdata->pnode != NULL;
1674 put_rport = ndlp->rport != NULL;
1675 rdata->pnode = NULL;
1680 put_device(&rport->dev);
1683 if (phba->sli_rev == LPFC_SLI_REV4 &&
1684 active_rrqs_xri_bitmap)
1685 mempool_free(active_rrqs_xri_bitmap,
1686 phba->active_rrq_pool);
1691 * lpfc_end_rscn - Check and handle more rscn for a vport
1692 * @vport: pointer to a host virtual N_Port data structure.
1694 * This routine checks whether more Registration State Change
1695 * Notifications (RSCNs) came in while the discovery state machine was in
1696 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1697 * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1698 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1699 * handling the RSCNs.
1702 lpfc_end_rscn(struct lpfc_vport *vport)
1704 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1706 if (vport->fc_flag & FC_RSCN_MODE) {
1708 * Check to see if more RSCNs came in while we were
1709 * processing this one.
1711 if (vport->fc_rscn_id_cnt ||
1712 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
1713 lpfc_els_handle_rscn(vport);
1715 spin_lock_irq(shost->host_lock);
1716 vport->fc_flag &= ~FC_RSCN_MODE;
1717 spin_unlock_irq(shost->host_lock);
1723 * lpfc_cmpl_els_rrq - Completion handled for els RRQs.
1724 * @phba: pointer to lpfc hba data structure.
1725 * @cmdiocb: pointer to lpfc command iocb data structure.
1726 * @rspiocb: pointer to lpfc response iocb data structure.
1728 * This routine will call the clear rrq function to free the rrq and
1729 * clear the xri's bit in the ndlp's xri_bitmap. If the ndlp does not
1730 * exist then the clear_rrq is still called because the rrq needs to
1735 lpfc_cmpl_els_rrq(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1736 struct lpfc_iocbq *rspiocb)
1738 struct lpfc_vport *vport = cmdiocb->vport;
1740 struct lpfc_nodelist *ndlp;
1741 struct lpfc_node_rrq *rrq;
1743 /* we pass cmdiocb to state machine which needs rspiocb as well */
1744 rrq = cmdiocb->context_un.rrq;
1745 cmdiocb->context_un.rsp_iocb = rspiocb;
1747 irsp = &rspiocb->iocb;
1748 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1749 "RRQ cmpl: status:x%x/x%x did:x%x",
1750 irsp->ulpStatus, irsp->un.ulpWord[4],
1751 irsp->un.elsreq64.remoteID);
1753 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
1754 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || ndlp != rrq->ndlp) {
1755 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1756 "2882 RRQ completes to NPort x%x "
1757 "with no ndlp. Data: x%x x%x x%x\n",
1758 irsp->un.elsreq64.remoteID,
1759 irsp->ulpStatus, irsp->un.ulpWord[4],
1764 /* rrq completes to NPort <nlp_DID> */
1765 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1766 "2880 RRQ completes to NPort x%x "
1767 "Data: x%x x%x x%x x%x x%x\n",
1768 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1769 irsp->ulpTimeout, rrq->xritag, rrq->rxid);
1771 if (irsp->ulpStatus) {
1772 /* Check for retry */
1773 /* RRQ failed Don't print the vport to vport rjts */
1774 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1775 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1776 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1777 (phba)->pport->cfg_log_verbose & LOG_ELS)
1778 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1779 "2881 RRQ failure DID:%06X Status:x%x/x%x\n",
1780 ndlp->nlp_DID, irsp->ulpStatus,
1781 irsp->un.ulpWord[4]);
1785 lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
1786 lpfc_els_free_iocb(phba, cmdiocb);
1790 * lpfc_cmpl_els_plogi - Completion callback function for plogi
1791 * @phba: pointer to lpfc hba data structure.
1792 * @cmdiocb: pointer to lpfc command iocb data structure.
1793 * @rspiocb: pointer to lpfc response iocb data structure.
1795 * This routine is the completion callback function for issuing the Port
1796 * Login (PLOGI) command. For PLOGI completion, there must be an active
1797 * ndlp on the vport node list that matches the remote node ID from the
1798 * PLOGI response IOCB. If such ndlp does not exist, the PLOGI is simply
1799 * ignored and command IOCB released. The PLOGI response IOCB status is
1800 * checked for error conditons. If there is error status reported, PLOGI
1801 * retry shall be attempted by invoking the lpfc_els_retry() routine.
1802 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1803 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1804 * (DSM) is set for this PLOGI completion. Finally, it checks whether
1805 * there are additional N_Port nodes with the vport that need to perform
1806 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
1810 lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1811 struct lpfc_iocbq *rspiocb)
1813 struct lpfc_vport *vport = cmdiocb->vport;
1814 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1816 struct lpfc_nodelist *ndlp;
1817 struct lpfc_dmabuf *prsp;
1820 /* we pass cmdiocb to state machine which needs rspiocb as well */
1821 cmdiocb->context_un.rsp_iocb = rspiocb;
1823 irsp = &rspiocb->iocb;
1824 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1825 "PLOGI cmpl: status:x%x/x%x did:x%x",
1826 irsp->ulpStatus, irsp->un.ulpWord[4],
1827 irsp->un.elsreq64.remoteID);
1829 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
1830 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
1831 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1832 "0136 PLOGI completes to NPort x%x "
1833 "with no ndlp. Data: x%x x%x x%x\n",
1834 irsp->un.elsreq64.remoteID,
1835 irsp->ulpStatus, irsp->un.ulpWord[4],
1840 /* Since ndlp can be freed in the disc state machine, note if this node
1841 * is being used during discovery.
1843 spin_lock_irq(shost->host_lock);
1844 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
1845 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1846 spin_unlock_irq(shost->host_lock);
1849 /* PLOGI completes to NPort <nlp_DID> */
1850 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1851 "0102 PLOGI completes to NPort x%x "
1852 "Data: x%x x%x x%x x%x x%x\n",
1853 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1854 irsp->ulpTimeout, disc, vport->num_disc_nodes);
1855 /* Check to see if link went down during discovery */
1856 if (lpfc_els_chk_latt(vport)) {
1857 spin_lock_irq(shost->host_lock);
1858 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1859 spin_unlock_irq(shost->host_lock);
1863 if (irsp->ulpStatus) {
1864 /* Check for retry */
1865 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1866 /* ELS command is being retried */
1868 spin_lock_irq(shost->host_lock);
1869 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1870 spin_unlock_irq(shost->host_lock);
1874 /* PLOGI failed Don't print the vport to vport rjts */
1875 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1876 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1877 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1878 (phba)->pport->cfg_log_verbose & LOG_ELS)
1879 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1880 "2753 PLOGI failure DID:%06X Status:x%x/x%x\n",
1881 ndlp->nlp_DID, irsp->ulpStatus,
1882 irsp->un.ulpWord[4]);
1883 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1884 if (lpfc_error_lost_link(irsp))
1885 rc = NLP_STE_FREED_NODE;
1887 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1888 NLP_EVT_CMPL_PLOGI);
1890 /* Good status, call state machine */
1891 prsp = list_entry(((struct lpfc_dmabuf *)
1892 cmdiocb->context2)->list.next,
1893 struct lpfc_dmabuf, list);
1894 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
1895 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1896 NLP_EVT_CMPL_PLOGI);
1899 if (disc && vport->num_disc_nodes) {
1900 /* Check to see if there are more PLOGIs to be sent */
1901 lpfc_more_plogi(vport);
1903 if (vport->num_disc_nodes == 0) {
1904 spin_lock_irq(shost->host_lock);
1905 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1906 spin_unlock_irq(shost->host_lock);
1908 lpfc_can_disctmo(vport);
1909 lpfc_end_rscn(vport);
1914 lpfc_els_free_iocb(phba, cmdiocb);
1919 * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
1920 * @vport: pointer to a host virtual N_Port data structure.
1921 * @did: destination port identifier.
1922 * @retry: number of retries to the command IOCB.
1924 * This routine issues a Port Login (PLOGI) command to a remote N_Port
1925 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
1926 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
1927 * This routine constructs the proper feilds of the PLOGI IOCB and invokes
1928 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
1930 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1931 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1932 * will be stored into the context1 field of the IOCB for the completion
1933 * callback function to the PLOGI ELS command.
1936 * 0 - Successfully issued a plogi for @vport
1937 * 1 - failed to issue a plogi for @vport
1940 lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
1942 struct lpfc_hba *phba = vport->phba;
1943 struct serv_parm *sp;
1944 struct lpfc_nodelist *ndlp;
1945 struct lpfc_iocbq *elsiocb;
1950 ndlp = lpfc_findnode_did(vport, did);
1951 if (ndlp && !NLP_CHK_NODE_ACT(ndlp))
1954 /* If ndlp is not NULL, we will bump the reference count on it */
1955 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
1956 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
1961 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1963 /* For PLOGI request, remainder of payload is service parameters */
1964 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
1965 pcmd += sizeof(uint32_t);
1966 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
1967 sp = (struct serv_parm *) pcmd;
1970 * If we are a N-port connected to a Fabric, fix-up paramm's so logins
1971 * to device on remote loops work.
1973 if ((vport->fc_flag & FC_FABRIC) && !(vport->fc_flag & FC_PUBLIC_LOOP))
1974 sp->cmn.altBbCredit = 1;
1976 if (sp->cmn.fcphLow < FC_PH_4_3)
1977 sp->cmn.fcphLow = FC_PH_4_3;
1979 if (sp->cmn.fcphHigh < FC_PH3)
1980 sp->cmn.fcphHigh = FC_PH3;
1982 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1983 "Issue PLOGI: did:x%x",
1986 phba->fc_stat.elsXmitPLOGI++;
1987 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
1988 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
1990 if (ret == IOCB_ERROR) {
1991 lpfc_els_free_iocb(phba, elsiocb);
1998 * lpfc_cmpl_els_prli - Completion callback function for prli
1999 * @phba: pointer to lpfc hba data structure.
2000 * @cmdiocb: pointer to lpfc command iocb data structure.
2001 * @rspiocb: pointer to lpfc response iocb data structure.
2003 * This routine is the completion callback function for a Process Login
2004 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
2005 * status. If there is error status reported, PRLI retry shall be attempted
2006 * by invoking the lpfc_els_retry() routine. Otherwise, the state
2007 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
2008 * ndlp to mark the PRLI completion.
2011 lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2012 struct lpfc_iocbq *rspiocb)
2014 struct lpfc_vport *vport = cmdiocb->vport;
2015 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2017 struct lpfc_nodelist *ndlp;
2019 /* we pass cmdiocb to state machine which needs rspiocb as well */
2020 cmdiocb->context_un.rsp_iocb = rspiocb;
2022 irsp = &(rspiocb->iocb);
2023 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2024 spin_lock_irq(shost->host_lock);
2025 ndlp->nlp_flag &= ~NLP_PRLI_SND;
2026 spin_unlock_irq(shost->host_lock);
2028 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2029 "PRLI cmpl: status:x%x/x%x did:x%x",
2030 irsp->ulpStatus, irsp->un.ulpWord[4],
2032 /* PRLI completes to NPort <nlp_DID> */
2033 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2034 "0103 PRLI completes to NPort x%x "
2035 "Data: x%x x%x x%x x%x\n",
2036 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2037 irsp->ulpTimeout, vport->num_disc_nodes);
2039 vport->fc_prli_sent--;
2040 /* Check to see if link went down during discovery */
2041 if (lpfc_els_chk_latt(vport))
2044 if (irsp->ulpStatus) {
2045 /* Check for retry */
2046 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2047 /* ELS command is being retried */
2051 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2052 "2754 PRLI failure DID:%06X Status:x%x/x%x\n",
2053 ndlp->nlp_DID, irsp->ulpStatus,
2054 irsp->un.ulpWord[4]);
2055 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2056 if (lpfc_error_lost_link(irsp))
2059 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2062 /* Good status, call state machine */
2063 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2066 lpfc_els_free_iocb(phba, cmdiocb);
2071 * lpfc_issue_els_prli - Issue a prli iocb command for a vport
2072 * @vport: pointer to a host virtual N_Port data structure.
2073 * @ndlp: pointer to a node-list data structure.
2074 * @retry: number of retries to the command IOCB.
2076 * This routine issues a Process Login (PRLI) ELS command for the
2077 * @vport. The PRLI service parameters are set up in the payload of the
2078 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
2079 * is put to the IOCB completion callback func field before invoking the
2080 * routine lpfc_sli_issue_iocb() to send out PRLI command.
2082 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2083 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2084 * will be stored into the context1 field of the IOCB for the completion
2085 * callback function to the PRLI ELS command.
2088 * 0 - successfully issued prli iocb command for @vport
2089 * 1 - failed to issue prli iocb command for @vport
2092 lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2095 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2096 struct lpfc_hba *phba = vport->phba;
2098 struct lpfc_iocbq *elsiocb;
2102 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
2103 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2104 ndlp->nlp_DID, ELS_CMD_PRLI);
2108 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2110 /* For PRLI request, remainder of payload is service parameters */
2111 memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t)));
2112 *((uint32_t *) (pcmd)) = ELS_CMD_PRLI;
2113 pcmd += sizeof(uint32_t);
2115 /* For PRLI, remainder of payload is PRLI parameter page */
2116 npr = (PRLI *) pcmd;
2118 * If our firmware version is 3.20 or later,
2119 * set the following bits for FC-TAPE support.
2121 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
2122 npr->ConfmComplAllowed = 1;
2124 npr->TaskRetryIdReq = 1;
2126 npr->estabImagePair = 1;
2127 npr->readXferRdyDis = 1;
2128 if (vport->cfg_first_burst_size)
2129 npr->writeXferRdyDis = 1;
2131 /* For FCP support */
2132 npr->prliType = PRLI_FCP_TYPE;
2133 npr->initiatorFunc = 1;
2135 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2136 "Issue PRLI: did:x%x",
2137 ndlp->nlp_DID, 0, 0);
2139 phba->fc_stat.elsXmitPRLI++;
2140 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
2141 spin_lock_irq(shost->host_lock);
2142 ndlp->nlp_flag |= NLP_PRLI_SND;
2143 spin_unlock_irq(shost->host_lock);
2144 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2146 spin_lock_irq(shost->host_lock);
2147 ndlp->nlp_flag &= ~NLP_PRLI_SND;
2148 spin_unlock_irq(shost->host_lock);
2149 lpfc_els_free_iocb(phba, elsiocb);
2152 vport->fc_prli_sent++;
2157 * lpfc_rscn_disc - Perform rscn discovery for a vport
2158 * @vport: pointer to a host virtual N_Port data structure.
2160 * This routine performs Registration State Change Notification (RSCN)
2161 * discovery for a @vport. If the @vport's node port recovery count is not
2162 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
2163 * the nodes that need recovery. If none of the PLOGI were needed through
2164 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
2165 * invoked to check and handle possible more RSCN came in during the period
2166 * of processing the current ones.
2169 lpfc_rscn_disc(struct lpfc_vport *vport)
2171 lpfc_can_disctmo(vport);
2173 /* RSCN discovery */
2174 /* go thru NPR nodes and issue ELS PLOGIs */
2175 if (vport->fc_npr_cnt)
2176 if (lpfc_els_disc_plogi(vport))
2179 lpfc_end_rscn(vport);
2183 * lpfc_adisc_done - Complete the adisc phase of discovery
2184 * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
2186 * This function is called when the final ADISC is completed during discovery.
2187 * This function handles clearing link attention or issuing reg_vpi depending
2188 * on whether npiv is enabled. This function also kicks off the PLOGI phase of
2190 * This function is called with no locks held.
2193 lpfc_adisc_done(struct lpfc_vport *vport)
2195 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2196 struct lpfc_hba *phba = vport->phba;
2199 * For NPIV, cmpl_reg_vpi will set port_state to READY,
2200 * and continue discovery.
2202 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2203 !(vport->fc_flag & FC_RSCN_MODE) &&
2204 (phba->sli_rev < LPFC_SLI_REV4)) {
2205 /* The ADISCs are complete. Doesn't matter if they
2206 * succeeded or failed because the ADISC completion
2207 * routine guarantees to call the state machine and
2208 * the RPI is either unregistered (failed ADISC response)
2209 * or the RPI is still valid and the node is marked
2210 * mapped for a target. The exchanges should be in the
2211 * correct state. This code is specific to SLI3.
2213 lpfc_issue_clear_la(phba, vport);
2214 lpfc_issue_reg_vpi(phba, vport);
2218 * For SLI2, we need to set port_state to READY
2219 * and continue discovery.
2221 if (vport->port_state < LPFC_VPORT_READY) {
2222 /* If we get here, there is nothing to ADISC */
2223 lpfc_issue_clear_la(phba, vport);
2224 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
2225 vport->num_disc_nodes = 0;
2226 /* go thru NPR list, issue ELS PLOGIs */
2227 if (vport->fc_npr_cnt)
2228 lpfc_els_disc_plogi(vport);
2229 if (!vport->num_disc_nodes) {
2230 spin_lock_irq(shost->host_lock);
2231 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2232 spin_unlock_irq(shost->host_lock);
2233 lpfc_can_disctmo(vport);
2234 lpfc_end_rscn(vport);
2237 vport->port_state = LPFC_VPORT_READY;
2239 lpfc_rscn_disc(vport);
2243 * lpfc_more_adisc - Issue more adisc as needed
2244 * @vport: pointer to a host virtual N_Port data structure.
2246 * This routine determines whether there are more ndlps on a @vport
2247 * node list need to have Address Discover (ADISC) issued. If so, it will
2248 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
2249 * remaining nodes which need to have ADISC sent.
2252 lpfc_more_adisc(struct lpfc_vport *vport)
2254 if (vport->num_disc_nodes)
2255 vport->num_disc_nodes--;
2256 /* Continue discovery with <num_disc_nodes> ADISCs to go */
2257 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2258 "0210 Continue discovery with %d ADISCs to go "
2259 "Data: x%x x%x x%x\n",
2260 vport->num_disc_nodes, vport->fc_adisc_cnt,
2261 vport->fc_flag, vport->port_state);
2262 /* Check to see if there are more ADISCs to be sent */
2263 if (vport->fc_flag & FC_NLP_MORE) {
2264 lpfc_set_disctmo(vport);
2265 /* go thru NPR nodes and issue any remaining ELS ADISCs */
2266 lpfc_els_disc_adisc(vport);
2268 if (!vport->num_disc_nodes)
2269 lpfc_adisc_done(vport);
2274 * lpfc_cmpl_els_adisc - Completion callback function for adisc
2275 * @phba: pointer to lpfc hba data structure.
2276 * @cmdiocb: pointer to lpfc command iocb data structure.
2277 * @rspiocb: pointer to lpfc response iocb data structure.
2279 * This routine is the completion function for issuing the Address Discover
2280 * (ADISC) command. It first checks to see whether link went down during
2281 * the discovery process. If so, the node will be marked as node port
2282 * recovery for issuing discover IOCB by the link attention handler and
2283 * exit. Otherwise, the response status is checked. If error was reported
2284 * in the response status, the ADISC command shall be retried by invoking
2285 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
2286 * the response status, the state machine is invoked to set transition
2287 * with respect to NLP_EVT_CMPL_ADISC event.
2290 lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2291 struct lpfc_iocbq *rspiocb)
2293 struct lpfc_vport *vport = cmdiocb->vport;
2294 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2296 struct lpfc_nodelist *ndlp;
2299 /* we pass cmdiocb to state machine which needs rspiocb as well */
2300 cmdiocb->context_un.rsp_iocb = rspiocb;
2302 irsp = &(rspiocb->iocb);
2303 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2305 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2306 "ADISC cmpl: status:x%x/x%x did:x%x",
2307 irsp->ulpStatus, irsp->un.ulpWord[4],
2310 /* Since ndlp can be freed in the disc state machine, note if this node
2311 * is being used during discovery.
2313 spin_lock_irq(shost->host_lock);
2314 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
2315 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
2316 spin_unlock_irq(shost->host_lock);
2317 /* ADISC completes to NPort <nlp_DID> */
2318 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2319 "0104 ADISC completes to NPort x%x "
2320 "Data: x%x x%x x%x x%x x%x\n",
2321 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2322 irsp->ulpTimeout, disc, vport->num_disc_nodes);
2323 /* Check to see if link went down during discovery */
2324 if (lpfc_els_chk_latt(vport)) {
2325 spin_lock_irq(shost->host_lock);
2326 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2327 spin_unlock_irq(shost->host_lock);
2331 if (irsp->ulpStatus) {
2332 /* Check for retry */
2333 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2334 /* ELS command is being retried */
2336 spin_lock_irq(shost->host_lock);
2337 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2338 spin_unlock_irq(shost->host_lock);
2339 lpfc_set_disctmo(vport);
2344 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2345 "2755 ADISC failure DID:%06X Status:x%x/x%x\n",
2346 ndlp->nlp_DID, irsp->ulpStatus,
2347 irsp->un.ulpWord[4]);
2348 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2349 if (!lpfc_error_lost_link(irsp))
2350 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2351 NLP_EVT_CMPL_ADISC);
2353 /* Good status, call state machine */
2354 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2355 NLP_EVT_CMPL_ADISC);
2357 /* Check to see if there are more ADISCs to be sent */
2358 if (disc && vport->num_disc_nodes)
2359 lpfc_more_adisc(vport);
2361 lpfc_els_free_iocb(phba, cmdiocb);
2366 * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
2367 * @vport: pointer to a virtual N_Port data structure.
2368 * @ndlp: pointer to a node-list data structure.
2369 * @retry: number of retries to the command IOCB.
2371 * This routine issues an Address Discover (ADISC) for an @ndlp on a
2372 * @vport. It prepares the payload of the ADISC ELS command, updates the
2373 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
2374 * to issue the ADISC ELS command.
2376 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2377 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2378 * will be stored into the context1 field of the IOCB for the completion
2379 * callback function to the ADISC ELS command.
2382 * 0 - successfully issued adisc
2383 * 1 - failed to issue adisc
2386 lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2389 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2390 struct lpfc_hba *phba = vport->phba;
2392 struct lpfc_iocbq *elsiocb;
2396 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
2397 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2398 ndlp->nlp_DID, ELS_CMD_ADISC);
2402 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2404 /* For ADISC request, remainder of payload is service parameters */
2405 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
2406 pcmd += sizeof(uint32_t);
2408 /* Fill in ADISC payload */
2409 ap = (ADISC *) pcmd;
2410 ap->hardAL_PA = phba->fc_pref_ALPA;
2411 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2412 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
2413 ap->DID = be32_to_cpu(vport->fc_myDID);
2415 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2416 "Issue ADISC: did:x%x",
2417 ndlp->nlp_DID, 0, 0);
2419 phba->fc_stat.elsXmitADISC++;
2420 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
2421 spin_lock_irq(shost->host_lock);
2422 ndlp->nlp_flag |= NLP_ADISC_SND;
2423 spin_unlock_irq(shost->host_lock);
2424 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2426 spin_lock_irq(shost->host_lock);
2427 ndlp->nlp_flag &= ~NLP_ADISC_SND;
2428 spin_unlock_irq(shost->host_lock);
2429 lpfc_els_free_iocb(phba, elsiocb);
2436 * lpfc_cmpl_els_logo - Completion callback function for logo
2437 * @phba: pointer to lpfc hba data structure.
2438 * @cmdiocb: pointer to lpfc command iocb data structure.
2439 * @rspiocb: pointer to lpfc response iocb data structure.
2441 * This routine is the completion function for issuing the ELS Logout (LOGO)
2442 * command. If no error status was reported from the LOGO response, the
2443 * state machine of the associated ndlp shall be invoked for transition with
2444 * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
2445 * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
2448 lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2449 struct lpfc_iocbq *rspiocb)
2451 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2452 struct lpfc_vport *vport = ndlp->vport;
2453 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2455 struct lpfcMboxq *mbox;
2456 unsigned long flags;
2457 uint32_t skip_recovery = 0;
2459 /* we pass cmdiocb to state machine which needs rspiocb as well */
2460 cmdiocb->context_un.rsp_iocb = rspiocb;
2462 irsp = &(rspiocb->iocb);
2463 spin_lock_irq(shost->host_lock);
2464 ndlp->nlp_flag &= ~NLP_LOGO_SND;
2465 spin_unlock_irq(shost->host_lock);
2467 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2468 "LOGO cmpl: status:x%x/x%x did:x%x",
2469 irsp->ulpStatus, irsp->un.ulpWord[4],
2472 /* LOGO completes to NPort <nlp_DID> */
2473 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2474 "0105 LOGO completes to NPort x%x "
2475 "Data: x%x x%x x%x x%x\n",
2476 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2477 irsp->ulpTimeout, vport->num_disc_nodes);
2479 if (lpfc_els_chk_latt(vport)) {
2484 /* Check to see if link went down during discovery */
2485 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
2486 /* NLP_EVT_DEVICE_RM should unregister the RPI
2487 * which should abort all outstanding IOs.
2489 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2495 if (irsp->ulpStatus) {
2496 /* Check for retry */
2497 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2498 /* ELS command is being retried */
2503 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2504 "2756 LOGO failure DID:%06X Status:x%x/x%x\n",
2505 ndlp->nlp_DID, irsp->ulpStatus,
2506 irsp->un.ulpWord[4]);
2507 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2508 if (lpfc_error_lost_link(irsp)) {
2514 /* Call state machine. This will unregister the rpi if needed. */
2515 lpfc_disc_state_machine(vport, ndlp, cmdiocb, NLP_EVT_CMPL_LOGO);
2518 lpfc_els_free_iocb(phba, cmdiocb);
2519 /* If we are in pt2pt mode, we could rcv new S_ID on PLOGI */
2520 if ((vport->fc_flag & FC_PT2PT) &&
2521 !(vport->fc_flag & FC_PT2PT_PLOGI)) {
2522 phba->pport->fc_myDID = 0;
2523 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2525 lpfc_config_link(phba, mbox);
2526 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
2527 mbox->vport = vport;
2528 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) ==
2530 mempool_free(mbox, phba->mbox_mem_pool);
2537 * If the node is a target, the handling attempts to recover the port.
2538 * For any other port type, the rpi is unregistered as an implicit
2541 if ((ndlp->nlp_type & NLP_FCP_TARGET) && (skip_recovery == 0)) {
2542 lpfc_cancel_retry_delay_tmo(vport, ndlp);
2543 spin_lock_irqsave(shost->host_lock, flags);
2544 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2545 spin_unlock_irqrestore(shost->host_lock, flags);
2547 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2548 "3187 LOGO completes to NPort x%x: Start "
2549 "Recovery Data: x%x x%x x%x x%x\n",
2550 ndlp->nlp_DID, irsp->ulpStatus,
2551 irsp->un.ulpWord[4], irsp->ulpTimeout,
2552 vport->num_disc_nodes);
2553 lpfc_disc_start(vport);
2559 * lpfc_issue_els_logo - Issue a logo to an node on a vport
2560 * @vport: pointer to a virtual N_Port data structure.
2561 * @ndlp: pointer to a node-list data structure.
2562 * @retry: number of retries to the command IOCB.
2564 * This routine constructs and issues an ELS Logout (LOGO) iocb command
2565 * to a remote node, referred by an @ndlp on a @vport. It constructs the
2566 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
2567 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
2569 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2570 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2571 * will be stored into the context1 field of the IOCB for the completion
2572 * callback function to the LOGO ELS command.
2575 * 0 - successfully issued logo
2576 * 1 - failed to issue logo
2579 lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2582 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2583 struct lpfc_hba *phba = vport->phba;
2584 struct lpfc_iocbq *elsiocb;
2589 spin_lock_irq(shost->host_lock);
2590 if (ndlp->nlp_flag & NLP_LOGO_SND) {
2591 spin_unlock_irq(shost->host_lock);
2594 spin_unlock_irq(shost->host_lock);
2596 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
2597 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2598 ndlp->nlp_DID, ELS_CMD_LOGO);
2602 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2603 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
2604 pcmd += sizeof(uint32_t);
2606 /* Fill in LOGO payload */
2607 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
2608 pcmd += sizeof(uint32_t);
2609 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
2611 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2612 "Issue LOGO: did:x%x",
2613 ndlp->nlp_DID, 0, 0);
2616 * If we are issuing a LOGO, we may try to recover the remote NPort
2617 * by issuing a PLOGI later. Even though we issue ELS cmds by the
2618 * VPI, if we have a valid RPI, and that RPI gets unreg'ed while
2619 * that ELS command is in-flight, the HBA returns a IOERR_INVALID_RPI
2620 * for that ELS cmd. To avoid this situation, lets get rid of the
2621 * RPI right now, before any ELS cmds are sent.
2623 spin_lock_irq(shost->host_lock);
2624 ndlp->nlp_flag |= NLP_ISSUE_LOGO;
2625 spin_unlock_irq(shost->host_lock);
2626 if (lpfc_unreg_rpi(vport, ndlp)) {
2627 lpfc_els_free_iocb(phba, elsiocb);
2631 phba->fc_stat.elsXmitLOGO++;
2632 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
2633 spin_lock_irq(shost->host_lock);
2634 ndlp->nlp_flag |= NLP_LOGO_SND;
2635 ndlp->nlp_flag &= ~NLP_ISSUE_LOGO;
2636 spin_unlock_irq(shost->host_lock);
2637 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
2639 if (rc == IOCB_ERROR) {
2640 spin_lock_irq(shost->host_lock);
2641 ndlp->nlp_flag &= ~NLP_LOGO_SND;
2642 spin_unlock_irq(shost->host_lock);
2643 lpfc_els_free_iocb(phba, elsiocb);
2650 * lpfc_cmpl_els_cmd - Completion callback function for generic els command
2651 * @phba: pointer to lpfc hba data structure.
2652 * @cmdiocb: pointer to lpfc command iocb data structure.
2653 * @rspiocb: pointer to lpfc response iocb data structure.
2655 * This routine is a generic completion callback function for ELS commands.
2656 * Specifically, it is the callback function which does not need to perform
2657 * any command specific operations. It is currently used by the ELS command
2658 * issuing routines for the ELS State Change Request (SCR),
2659 * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution
2660 * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than
2661 * certain debug loggings, this callback function simply invokes the
2662 * lpfc_els_chk_latt() routine to check whether link went down during the
2663 * discovery process.
2666 lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2667 struct lpfc_iocbq *rspiocb)
2669 struct lpfc_vport *vport = cmdiocb->vport;
2672 irsp = &rspiocb->iocb;
2674 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2675 "ELS cmd cmpl: status:x%x/x%x did:x%x",
2676 irsp->ulpStatus, irsp->un.ulpWord[4],
2677 irsp->un.elsreq64.remoteID);
2678 /* ELS cmd tag <ulpIoTag> completes */
2679 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2680 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
2681 irsp->ulpIoTag, irsp->ulpStatus,
2682 irsp->un.ulpWord[4], irsp->ulpTimeout);
2683 /* Check to see if link went down during discovery */
2684 lpfc_els_chk_latt(vport);
2685 lpfc_els_free_iocb(phba, cmdiocb);
2690 * lpfc_issue_els_scr - Issue a scr to an node on a vport
2691 * @vport: pointer to a host virtual N_Port data structure.
2692 * @nportid: N_Port identifier to the remote node.
2693 * @retry: number of retries to the command IOCB.
2695 * This routine issues a State Change Request (SCR) to a fabric node
2696 * on a @vport. The remote node @nportid is passed into the function. It
2697 * first search the @vport node list to find the matching ndlp. If no such
2698 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
2699 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
2700 * routine is invoked to send the SCR IOCB.
2702 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2703 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2704 * will be stored into the context1 field of the IOCB for the completion
2705 * callback function to the SCR ELS command.
2708 * 0 - Successfully issued scr command
2709 * 1 - Failed to issue scr command
2712 lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
2714 struct lpfc_hba *phba = vport->phba;
2715 struct lpfc_iocbq *elsiocb;
2718 struct lpfc_nodelist *ndlp;
2720 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
2722 ndlp = lpfc_findnode_did(vport, nportid);
2724 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2727 lpfc_nlp_init(vport, ndlp, nportid);
2728 lpfc_enqueue_node(vport, ndlp);
2729 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2730 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2735 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2736 ndlp->nlp_DID, ELS_CMD_SCR);
2739 /* This will trigger the release of the node just
2746 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2748 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
2749 pcmd += sizeof(uint32_t);
2751 /* For SCR, remainder of payload is SCR parameter page */
2752 memset(pcmd, 0, sizeof(SCR));
2753 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
2755 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2756 "Issue SCR: did:x%x",
2757 ndlp->nlp_DID, 0, 0);
2759 phba->fc_stat.elsXmitSCR++;
2760 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
2761 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2763 /* The additional lpfc_nlp_put will cause the following
2764 * lpfc_els_free_iocb routine to trigger the rlease of
2768 lpfc_els_free_iocb(phba, elsiocb);
2771 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2772 * trigger the release of node.
2780 * lpfc_issue_els_farpr - Issue a farp to an node on a vport
2781 * @vport: pointer to a host virtual N_Port data structure.
2782 * @nportid: N_Port identifier to the remote node.
2783 * @retry: number of retries to the command IOCB.
2785 * This routine issues a Fibre Channel Address Resolution Response
2786 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
2787 * is passed into the function. It first search the @vport node list to find
2788 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
2789 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
2790 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
2792 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2793 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2794 * will be stored into the context1 field of the IOCB for the completion
2795 * callback function to the PARPR ELS command.
2798 * 0 - Successfully issued farpr command
2799 * 1 - Failed to issue farpr command
2802 lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
2804 struct lpfc_hba *phba = vport->phba;
2805 struct lpfc_iocbq *elsiocb;
2810 struct lpfc_nodelist *ondlp;
2811 struct lpfc_nodelist *ndlp;
2813 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
2815 ndlp = lpfc_findnode_did(vport, nportid);
2817 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2820 lpfc_nlp_init(vport, ndlp, nportid);
2821 lpfc_enqueue_node(vport, ndlp);
2822 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2823 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2828 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2829 ndlp->nlp_DID, ELS_CMD_RNID);
2831 /* This will trigger the release of the node just
2838 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2840 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
2841 pcmd += sizeof(uint32_t);
2843 /* Fill in FARPR payload */
2844 fp = (FARP *) (pcmd);
2845 memset(fp, 0, sizeof(FARP));
2846 lp = (uint32_t *) pcmd;
2847 *lp++ = be32_to_cpu(nportid);
2848 *lp++ = be32_to_cpu(vport->fc_myDID);
2850 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
2852 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
2853 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
2854 ondlp = lpfc_findnode_did(vport, nportid);
2855 if (ondlp && NLP_CHK_NODE_ACT(ondlp)) {
2856 memcpy(&fp->OportName, &ondlp->nlp_portname,
2857 sizeof(struct lpfc_name));
2858 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
2859 sizeof(struct lpfc_name));
2862 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2863 "Issue FARPR: did:x%x",
2864 ndlp->nlp_DID, 0, 0);
2866 phba->fc_stat.elsXmitFARPR++;
2867 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
2868 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2870 /* The additional lpfc_nlp_put will cause the following
2871 * lpfc_els_free_iocb routine to trigger the release of
2875 lpfc_els_free_iocb(phba, elsiocb);
2878 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2879 * trigger the release of the node.
2886 * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
2887 * @vport: pointer to a host virtual N_Port data structure.
2888 * @nlp: pointer to a node-list data structure.
2890 * This routine cancels the timer with a delayed IOCB-command retry for
2891 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
2892 * removes the ELS retry event if it presents. In addition, if the
2893 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
2894 * commands are sent for the @vport's nodes that require issuing discovery
2898 lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
2900 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2901 struct lpfc_work_evt *evtp;
2903 if (!(nlp->nlp_flag & NLP_DELAY_TMO))
2905 spin_lock_irq(shost->host_lock);
2906 nlp->nlp_flag &= ~NLP_DELAY_TMO;
2907 spin_unlock_irq(shost->host_lock);
2908 del_timer_sync(&nlp->nlp_delayfunc);
2909 nlp->nlp_last_elscmd = 0;
2910 if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
2911 list_del_init(&nlp->els_retry_evt.evt_listp);
2912 /* Decrement nlp reference count held for the delayed retry */
2913 evtp = &nlp->els_retry_evt;
2914 lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
2916 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
2917 spin_lock_irq(shost->host_lock);
2918 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
2919 spin_unlock_irq(shost->host_lock);
2920 if (vport->num_disc_nodes) {
2921 if (vport->port_state < LPFC_VPORT_READY) {
2922 /* Check if there are more ADISCs to be sent */
2923 lpfc_more_adisc(vport);
2925 /* Check if there are more PLOGIs to be sent */
2926 lpfc_more_plogi(vport);
2927 if (vport->num_disc_nodes == 0) {
2928 spin_lock_irq(shost->host_lock);
2929 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2930 spin_unlock_irq(shost->host_lock);
2931 lpfc_can_disctmo(vport);
2932 lpfc_end_rscn(vport);
2941 * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
2942 * @ptr: holder for the pointer to the timer function associated data (ndlp).
2944 * This routine is invoked by the ndlp delayed-function timer to check
2945 * whether there is any pending ELS retry event(s) with the node. If not, it
2946 * simply returns. Otherwise, if there is at least one ELS delayed event, it
2947 * adds the delayed events to the HBA work list and invokes the
2948 * lpfc_worker_wake_up() routine to wake up worker thread to process the
2949 * event. Note that lpfc_nlp_get() is called before posting the event to
2950 * the work list to hold reference count of ndlp so that it guarantees the
2951 * reference to ndlp will still be available when the worker thread gets
2952 * to the event associated with the ndlp.
2955 lpfc_els_retry_delay(unsigned long ptr)
2957 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr;
2958 struct lpfc_vport *vport = ndlp->vport;
2959 struct lpfc_hba *phba = vport->phba;
2960 unsigned long flags;
2961 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
2963 spin_lock_irqsave(&phba->hbalock, flags);
2964 if (!list_empty(&evtp->evt_listp)) {
2965 spin_unlock_irqrestore(&phba->hbalock, flags);
2969 /* We need to hold the node by incrementing the reference
2970 * count until the queued work is done
2972 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
2973 if (evtp->evt_arg1) {
2974 evtp->evt = LPFC_EVT_ELS_RETRY;
2975 list_add_tail(&evtp->evt_listp, &phba->work_list);
2976 lpfc_worker_wake_up(phba);
2978 spin_unlock_irqrestore(&phba->hbalock, flags);
2983 * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
2984 * @ndlp: pointer to a node-list data structure.
2986 * This routine is the worker-thread handler for processing the @ndlp delayed
2987 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
2988 * the last ELS command from the associated ndlp and invokes the proper ELS
2989 * function according to the delayed ELS command to retry the command.
2992 lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
2994 struct lpfc_vport *vport = ndlp->vport;
2995 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2996 uint32_t cmd, retry;
2998 spin_lock_irq(shost->host_lock);
2999 cmd = ndlp->nlp_last_elscmd;
3000 ndlp->nlp_last_elscmd = 0;
3002 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
3003 spin_unlock_irq(shost->host_lock);
3007 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
3008 spin_unlock_irq(shost->host_lock);
3010 * If a discovery event readded nlp_delayfunc after timer
3011 * firing and before processing the timer, cancel the
3014 del_timer_sync(&ndlp->nlp_delayfunc);
3015 retry = ndlp->nlp_retry;
3016 ndlp->nlp_retry = 0;
3020 lpfc_issue_els_flogi(vport, ndlp, retry);
3023 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
3024 ndlp->nlp_prev_state = ndlp->nlp_state;
3025 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
3029 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
3030 ndlp->nlp_prev_state = ndlp->nlp_state;
3031 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
3035 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
3036 ndlp->nlp_prev_state = ndlp->nlp_state;
3037 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
3041 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
3042 ndlp->nlp_prev_state = ndlp->nlp_state;
3043 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
3047 if (!(vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI))
3048 lpfc_issue_els_fdisc(vport, ndlp, retry);
3055 * lpfc_els_retry - Make retry decision on an els command iocb
3056 * @phba: pointer to lpfc hba data structure.
3057 * @cmdiocb: pointer to lpfc command iocb data structure.
3058 * @rspiocb: pointer to lpfc response iocb data structure.
3060 * This routine makes a retry decision on an ELS command IOCB, which has
3061 * failed. The following ELS IOCBs use this function for retrying the command
3062 * when previously issued command responsed with error status: FLOGI, PLOGI,
3063 * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
3064 * returned error status, it makes the decision whether a retry shall be
3065 * issued for the command, and whether a retry shall be made immediately or
3066 * delayed. In the former case, the corresponding ELS command issuing-function
3067 * is called to retry the command. In the later case, the ELS command shall
3068 * be posted to the ndlp delayed event and delayed function timer set to the
3069 * ndlp for the delayed command issusing.
3072 * 0 - No retry of els command is made
3073 * 1 - Immediate or delayed retry of els command is made
3076 lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3077 struct lpfc_iocbq *rspiocb)
3079 struct lpfc_vport *vport = cmdiocb->vport;
3080 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3081 IOCB_t *irsp = &rspiocb->iocb;
3082 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3083 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3086 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
3092 /* Note: context2 may be 0 for internal driver abort
3093 * of delays ELS command.
3096 if (pcmd && pcmd->virt) {
3097 elscmd = (uint32_t *) (pcmd->virt);
3101 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
3102 did = ndlp->nlp_DID;
3104 /* We should only hit this case for retrying PLOGI */
3105 did = irsp->un.elsreq64.remoteID;
3106 ndlp = lpfc_findnode_did(vport, did);
3107 if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp))
3108 && (cmd != ELS_CMD_PLOGI))
3112 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3113 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
3114 *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
3116 switch (irsp->ulpStatus) {
3117 case IOSTAT_FCP_RSP_ERROR:
3119 case IOSTAT_REMOTE_STOP:
3120 if (phba->sli_rev == LPFC_SLI_REV4) {
3121 /* This IO was aborted by the target, we don't
3122 * know the rxid and because we did not send the
3123 * ABTS we cannot generate and RRQ.
3125 lpfc_set_rrq_active(phba, ndlp,
3126 cmdiocb->sli4_lxritag, 0, 0);
3129 case IOSTAT_LOCAL_REJECT:
3130 switch ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK)) {
3131 case IOERR_LOOP_OPEN_FAILURE:
3132 if (cmd == ELS_CMD_FLOGI) {
3133 if (PCI_DEVICE_ID_HORNET ==
3134 phba->pcidev->device) {
3135 phba->fc_topology = LPFC_TOPOLOGY_LOOP;
3136 phba->pport->fc_myDID = 0;
3137 phba->alpa_map[0] = 0;
3138 phba->alpa_map[1] = 0;
3141 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
3146 case IOERR_ILLEGAL_COMMAND:
3147 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3148 "0124 Retry illegal cmd x%x "
3149 "retry:x%x delay:x%x\n",
3150 cmd, cmdiocb->retry, delay);
3152 /* All command's retry policy */
3154 if (cmdiocb->retry > 2)
3158 case IOERR_NO_RESOURCES:
3159 logerr = 1; /* HBA out of resources */
3161 if (cmdiocb->retry > 100)
3166 case IOERR_ILLEGAL_FRAME:
3171 case IOERR_SEQUENCE_TIMEOUT:
3172 case IOERR_INVALID_RPI:
3173 if (cmd == ELS_CMD_PLOGI &&
3174 did == NameServer_DID) {
3175 /* Continue forever if plogi to */
3176 /* the nameserver fails */
3185 case IOSTAT_NPORT_RJT:
3186 case IOSTAT_FABRIC_RJT:
3187 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
3193 case IOSTAT_NPORT_BSY:
3194 case IOSTAT_FABRIC_BSY:
3195 logerr = 1; /* Fabric / Remote NPort out of resources */
3200 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
3201 /* Added for Vendor specifc support
3202 * Just keep retrying for these Rsn / Exp codes
3204 switch (stat.un.b.lsRjtRsnCode) {
3205 case LSRJT_UNABLE_TPC:
3206 if (stat.un.b.lsRjtRsnCodeExp ==
3207 LSEXP_CMD_IN_PROGRESS) {
3208 if (cmd == ELS_CMD_PLOGI) {
3215 if (stat.un.b.lsRjtRsnCodeExp ==
3216 LSEXP_CANT_GIVE_DATA) {
3217 if (cmd == ELS_CMD_PLOGI) {
3224 if ((cmd == ELS_CMD_PLOGI) ||
3225 (cmd == ELS_CMD_PRLI)) {
3227 maxretry = lpfc_max_els_tries + 1;
3231 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
3232 (cmd == ELS_CMD_FDISC) &&
3233 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
3234 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3235 "0125 FDISC Failed (x%x). "
3236 "Fabric out of resources\n",
3237 stat.un.lsRjtError);
3238 lpfc_vport_set_state(vport,
3239 FC_VPORT_NO_FABRIC_RSCS);
3243 case LSRJT_LOGICAL_BSY:
3244 if ((cmd == ELS_CMD_PLOGI) ||
3245 (cmd == ELS_CMD_PRLI)) {
3248 } else if (cmd == ELS_CMD_FDISC) {
3249 /* FDISC retry policy */
3251 if (cmdiocb->retry >= 32)
3257 case LSRJT_LOGICAL_ERR:
3258 /* There are some cases where switches return this
3259 * error when they are not ready and should be returning
3260 * Logical Busy. We should delay every time.
3262 if (cmd == ELS_CMD_FDISC &&
3263 stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
3269 case LSRJT_PROTOCOL_ERR:
3270 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
3271 (cmd == ELS_CMD_FDISC) &&
3272 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
3273 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
3275 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3276 "0122 FDISC Failed (x%x). "
3277 "Fabric Detected Bad WWN\n",
3278 stat.un.lsRjtError);
3279 lpfc_vport_set_state(vport,
3280 FC_VPORT_FABRIC_REJ_WWN);
3286 case IOSTAT_INTERMED_RSP:
3294 if (did == FDMI_DID)
3297 if ((cmd == ELS_CMD_FLOGI) &&
3298 (phba->fc_topology != LPFC_TOPOLOGY_LOOP) &&
3299 !lpfc_error_lost_link(irsp)) {
3300 /* FLOGI retry policy */
3302 /* retry FLOGI forever */
3303 if (phba->link_flag != LS_LOOPBACK_MODE)
3308 if (cmdiocb->retry >= 100)
3310 else if (cmdiocb->retry >= 32)
3312 } else if ((cmd == ELS_CMD_FDISC) && !lpfc_error_lost_link(irsp)) {
3313 /* retry FDISCs every second up to devloss */
3315 maxretry = vport->cfg_devloss_tmo;
3320 if (maxretry && (cmdiocb->retry >= maxretry)) {
3321 phba->fc_stat.elsRetryExceeded++;
3325 if ((vport->load_flag & FC_UNLOADING) != 0)
3329 if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) {
3330 /* Stop retrying PLOGI and FDISC if in FCF discovery */
3331 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
3332 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3333 "2849 Stop retry ELS command "
3334 "x%x to remote NPORT x%x, "
3335 "Data: x%x x%x\n", cmd, did,
3336 cmdiocb->retry, delay);
3341 /* Retry ELS command <elsCmd> to remote NPORT <did> */
3342 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3343 "0107 Retry ELS command x%x to remote "
3344 "NPORT x%x Data: x%x x%x\n",
3345 cmd, did, cmdiocb->retry, delay);
3347 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
3348 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
3349 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
3350 IOERR_NO_RESOURCES))) {
3351 /* Don't reset timer for no resources */
3353 /* If discovery / RSCN timer is running, reset it */
3354 if (timer_pending(&vport->fc_disctmo) ||
3355 (vport->fc_flag & FC_RSCN_MODE))
3356 lpfc_set_disctmo(vport);
3359 phba->fc_stat.elsXmitRetry++;
3360 if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) {
3361 phba->fc_stat.elsDelayRetry++;
3362 ndlp->nlp_retry = cmdiocb->retry;
3364 /* delay is specified in milliseconds */
3365 mod_timer(&ndlp->nlp_delayfunc,
3366 jiffies + msecs_to_jiffies(delay));
3367 spin_lock_irq(shost->host_lock);
3368 ndlp->nlp_flag |= NLP_DELAY_TMO;
3369 spin_unlock_irq(shost->host_lock);
3371 ndlp->nlp_prev_state = ndlp->nlp_state;
3372 if (cmd == ELS_CMD_PRLI)
3373 lpfc_nlp_set_state(vport, ndlp,
3374 NLP_STE_PRLI_ISSUE);
3376 lpfc_nlp_set_state(vport, ndlp,
3378 ndlp->nlp_last_elscmd = cmd;
3384 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
3387 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
3390 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
3391 ndlp->nlp_prev_state = ndlp->nlp_state;
3392 lpfc_nlp_set_state(vport, ndlp,
3393 NLP_STE_PLOGI_ISSUE);
3395 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
3398 ndlp->nlp_prev_state = ndlp->nlp_state;
3399 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
3400 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
3403 ndlp->nlp_prev_state = ndlp->nlp_state;
3404 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
3405 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
3408 ndlp->nlp_prev_state = ndlp->nlp_state;
3409 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
3410 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
3414 /* No retry ELS command <elsCmd> to remote NPORT <did> */
3416 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3417 "0137 No retry ELS command x%x to remote "
3418 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
3419 cmd, did, irsp->ulpStatus,
3420 irsp->un.ulpWord[4]);
3423 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3424 "0108 No retry ELS command x%x to remote "
3425 "NPORT x%x Retried:%d Error:x%x/%x\n",
3426 cmd, did, cmdiocb->retry, irsp->ulpStatus,
3427 irsp->un.ulpWord[4]);
3433 * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
3434 * @phba: pointer to lpfc hba data structure.
3435 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
3437 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
3438 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
3439 * checks to see whether there is a lpfc DMA buffer associated with the
3440 * response of the command IOCB. If so, it will be released before releasing
3441 * the lpfc DMA buffer associated with the IOCB itself.
3444 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3447 lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
3449 struct lpfc_dmabuf *buf_ptr;
3451 /* Free the response before processing the command. */
3452 if (!list_empty(&buf_ptr1->list)) {
3453 list_remove_head(&buf_ptr1->list, buf_ptr,
3456 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3459 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
3465 * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
3466 * @phba: pointer to lpfc hba data structure.
3467 * @buf_ptr: pointer to the lpfc dma buffer data structure.
3469 * This routine releases the lpfc Direct Memory Access (DMA) buffer
3470 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
3474 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3477 lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
3479 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3485 * lpfc_els_free_iocb - Free a command iocb and its associated resources
3486 * @phba: pointer to lpfc hba data structure.
3487 * @elsiocb: pointer to lpfc els command iocb data structure.
3489 * This routine frees a command IOCB and its associated resources. The
3490 * command IOCB data structure contains the reference to various associated
3491 * resources, these fields must be set to NULL if the associated reference
3493 * context1 - reference to ndlp
3494 * context2 - reference to cmd
3495 * context2->next - reference to rsp
3496 * context3 - reference to bpl
3498 * It first properly decrements the reference count held on ndlp for the
3499 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
3500 * set, it invokes the lpfc_els_free_data() routine to release the Direct
3501 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
3502 * adds the DMA buffer the @phba data structure for the delayed release.
3503 * If reference to the Buffer Pointer List (BPL) is present, the
3504 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
3505 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
3506 * invoked to release the IOCB data structure back to @phba IOCBQ list.
3509 * 0 - Success (currently, always return 0)
3512 lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
3514 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
3515 struct lpfc_nodelist *ndlp;
3517 ndlp = (struct lpfc_nodelist *)elsiocb->context1;
3519 if (ndlp->nlp_flag & NLP_DEFER_RM) {
3522 /* If the ndlp is not being used by another discovery
3525 if (!lpfc_nlp_not_used(ndlp)) {
3526 /* If ndlp is being used by another discovery
3527 * thread, just clear NLP_DEFER_RM
3529 ndlp->nlp_flag &= ~NLP_DEFER_RM;
3534 elsiocb->context1 = NULL;
3536 /* context2 = cmd, context2->next = rsp, context3 = bpl */
3537 if (elsiocb->context2) {
3538 if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
3539 /* Firmware could still be in progress of DMAing
3540 * payload, so don't free data buffer till after
3543 elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
3544 buf_ptr = elsiocb->context2;
3545 elsiocb->context2 = NULL;
3548 spin_lock_irq(&phba->hbalock);
3549 if (!list_empty(&buf_ptr->list)) {
3550 list_remove_head(&buf_ptr->list,
3551 buf_ptr1, struct lpfc_dmabuf,
3553 INIT_LIST_HEAD(&buf_ptr1->list);
3554 list_add_tail(&buf_ptr1->list,
3558 INIT_LIST_HEAD(&buf_ptr->list);
3559 list_add_tail(&buf_ptr->list, &phba->elsbuf);
3561 spin_unlock_irq(&phba->hbalock);
3564 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
3565 lpfc_els_free_data(phba, buf_ptr1);
3569 if (elsiocb->context3) {
3570 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
3571 lpfc_els_free_bpl(phba, buf_ptr);
3573 lpfc_sli_release_iocbq(phba, elsiocb);
3578 * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
3579 * @phba: pointer to lpfc hba data structure.
3580 * @cmdiocb: pointer to lpfc command iocb data structure.
3581 * @rspiocb: pointer to lpfc response iocb data structure.
3583 * This routine is the completion callback function to the Logout (LOGO)
3584 * Accept (ACC) Response ELS command. This routine is invoked to indicate
3585 * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
3586 * release the ndlp if it has the last reference remaining (reference count
3587 * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
3588 * field to NULL to inform the following lpfc_els_free_iocb() routine no
3589 * ndlp reference count needs to be decremented. Otherwise, the ndlp
3590 * reference use-count shall be decremented by the lpfc_els_free_iocb()
3591 * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
3592 * IOCB data structure.
3595 lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3596 struct lpfc_iocbq *rspiocb)
3598 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3599 struct lpfc_vport *vport = cmdiocb->vport;
3602 irsp = &rspiocb->iocb;
3603 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3604 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
3605 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
3606 /* ACC to LOGO completes to NPort <nlp_DID> */
3607 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3608 "0109 ACC to LOGO completes to NPort x%x "
3609 "Data: x%x x%x x%x\n",
3610 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3613 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
3614 /* NPort Recovery mode or node is just allocated */
3615 if (!lpfc_nlp_not_used(ndlp)) {
3616 /* If the ndlp is being used by another discovery
3617 * thread, just unregister the RPI.
3619 lpfc_unreg_rpi(vport, ndlp);
3621 /* Indicate the node has already released, should
3622 * not reference to it from within lpfc_els_free_iocb.
3624 cmdiocb->context1 = NULL;
3629 * The driver received a LOGO from the rport and has ACK'd it.
3630 * At this point, the driver is done so release the IOCB
3632 lpfc_els_free_iocb(phba, cmdiocb);
3636 * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
3637 * @phba: pointer to lpfc hba data structure.
3638 * @pmb: pointer to the driver internal queue element for mailbox command.
3640 * This routine is the completion callback function for unregister default
3641 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
3642 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
3643 * decrements the ndlp reference count held for this completion callback
3644 * function. After that, it invokes the lpfc_nlp_not_used() to check
3645 * whether there is only one reference left on the ndlp. If so, it will
3646 * perform one more decrement and trigger the release of the ndlp.
3649 lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3651 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
3652 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
3654 pmb->context1 = NULL;
3655 pmb->context2 = NULL;
3657 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3659 mempool_free(pmb, phba->mbox_mem_pool);
3661 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
3662 "0006 rpi%x DID:%x flg:%x %d map:%x %p\n",
3663 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
3664 atomic_read(&ndlp->kref.refcount),
3665 ndlp->nlp_usg_map, ndlp);
3666 if (NLP_CHK_NODE_ACT(ndlp)) {
3668 /* This is the end of the default RPI cleanup logic for
3669 * this ndlp. If no other discovery threads are using
3670 * this ndlp, free all resources associated with it.
3672 lpfc_nlp_not_used(ndlp);
3674 lpfc_drop_node(ndlp->vport, ndlp);
3682 * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
3683 * @phba: pointer to lpfc hba data structure.
3684 * @cmdiocb: pointer to lpfc command iocb data structure.
3685 * @rspiocb: pointer to lpfc response iocb data structure.
3687 * This routine is the completion callback function for ELS Response IOCB
3688 * command. In normal case, this callback function just properly sets the
3689 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
3690 * field in the command IOCB is not NULL, the referred mailbox command will
3691 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
3692 * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
3693 * link down event occurred during the discovery, the lpfc_nlp_not_used()
3694 * routine shall be invoked trying to release the ndlp if no other threads
3695 * are currently referring it.
3698 lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3699 struct lpfc_iocbq *rspiocb)
3701 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3702 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
3703 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
3706 LPFC_MBOXQ_t *mbox = NULL;
3707 struct lpfc_dmabuf *mp = NULL;
3708 uint32_t ls_rjt = 0;
3710 irsp = &rspiocb->iocb;
3712 if (cmdiocb->context_un.mbox)
3713 mbox = cmdiocb->context_un.mbox;
3715 /* First determine if this is a LS_RJT cmpl. Note, this callback
3716 * function can have cmdiocb->contest1 (ndlp) field set to NULL.
3718 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
3719 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3720 (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) {
3721 /* A LS_RJT associated with Default RPI cleanup has its own
3722 * separate code path.
3724 if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
3728 /* Check to see if link went down during discovery */
3729 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) {
3731 mp = (struct lpfc_dmabuf *) mbox->context1;
3733 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3736 mempool_free(mbox, phba->mbox_mem_pool);
3738 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3739 (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
3740 if (lpfc_nlp_not_used(ndlp)) {
3742 /* Indicate the node has already released,
3743 * should not reference to it from within
3744 * the routine lpfc_els_free_iocb.
3746 cmdiocb->context1 = NULL;
3751 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3752 "ELS rsp cmpl: status:x%x/x%x did:x%x",
3753 irsp->ulpStatus, irsp->un.ulpWord[4],
3754 cmdiocb->iocb.un.elsreq64.remoteID);
3755 /* ELS response tag <ulpIoTag> completes */
3756 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3757 "0110 ELS response tag x%x completes "
3758 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
3759 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
3760 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
3761 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3764 if ((rspiocb->iocb.ulpStatus == 0)
3765 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
3766 lpfc_unreg_rpi(vport, ndlp);
3767 /* Increment reference count to ndlp to hold the
3768 * reference to ndlp for the callback function.
3770 mbox->context2 = lpfc_nlp_get(ndlp);
3771 mbox->vport = vport;
3772 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
3773 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
3774 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
3777 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
3778 ndlp->nlp_prev_state = ndlp->nlp_state;
3779 lpfc_nlp_set_state(vport, ndlp,
3780 NLP_STE_REG_LOGIN_ISSUE);
3783 ndlp->nlp_flag |= NLP_REG_LOGIN_SEND;
3784 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
3785 != MBX_NOT_FINISHED)
3788 /* Decrement the ndlp reference count we
3789 * set for this failed mailbox command.
3792 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
3794 /* ELS rsp: Cannot issue reg_login for <NPortid> */
3795 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3796 "0138 ELS rsp: Cannot issue reg_login for x%x "
3797 "Data: x%x x%x x%x\n",
3798 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3801 if (lpfc_nlp_not_used(ndlp)) {
3803 /* Indicate node has already been released,
3804 * should not reference to it from within
3805 * the routine lpfc_els_free_iocb.
3807 cmdiocb->context1 = NULL;
3810 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
3811 if (!lpfc_error_lost_link(irsp) &&
3812 ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
3813 if (lpfc_nlp_not_used(ndlp)) {
3815 /* Indicate node has already been
3816 * released, should not reference
3817 * to it from within the routine
3818 * lpfc_els_free_iocb.
3820 cmdiocb->context1 = NULL;
3824 mp = (struct lpfc_dmabuf *) mbox->context1;
3826 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3829 mempool_free(mbox, phba->mbox_mem_pool);
3832 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
3833 spin_lock_irq(shost->host_lock);
3834 ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI);
3835 spin_unlock_irq(shost->host_lock);
3837 /* If the node is not being used by another discovery thread,
3838 * and we are sending a reject, we are done with it.
3839 * Release driver reference count here and free associated
3843 if (lpfc_nlp_not_used(ndlp))
3844 /* Indicate node has already been released,
3845 * should not reference to it from within
3846 * the routine lpfc_els_free_iocb.
3848 cmdiocb->context1 = NULL;
3852 lpfc_els_free_iocb(phba, cmdiocb);
3857 * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
3858 * @vport: pointer to a host virtual N_Port data structure.
3859 * @flag: the els command code to be accepted.
3860 * @oldiocb: pointer to the original lpfc command iocb data structure.
3861 * @ndlp: pointer to a node-list data structure.
3862 * @mbox: pointer to the driver internal queue element for mailbox command.
3864 * This routine prepares and issues an Accept (ACC) response IOCB
3865 * command. It uses the @flag to properly set up the IOCB field for the
3866 * specific ACC response command to be issued and invokes the
3867 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
3868 * @mbox pointer is passed in, it will be put into the context_un.mbox
3869 * field of the IOCB for the completion callback function to issue the
3870 * mailbox command to the HBA later when callback is invoked.
3872 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3873 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3874 * will be stored into the context1 field of the IOCB for the completion
3875 * callback function to the corresponding response ELS IOCB command.
3878 * 0 - Successfully issued acc response
3879 * 1 - Failed to issue acc response
3882 lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
3883 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
3886 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3887 struct lpfc_hba *phba = vport->phba;
3890 struct lpfc_iocbq *elsiocb;
3892 struct serv_parm *sp;
3895 ELS_PKT *els_pkt_ptr;
3897 oldcmd = &oldiocb->iocb;
3901 cmdsize = sizeof(uint32_t);
3902 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3903 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
3905 spin_lock_irq(shost->host_lock);
3906 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
3907 spin_unlock_irq(shost->host_lock);
3911 icmd = &elsiocb->iocb;
3912 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
3913 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
3914 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3915 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
3916 pcmd += sizeof(uint32_t);
3918 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3919 "Issue ACC: did:x%x flg:x%x",
3920 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3924 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
3925 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3926 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
3930 icmd = &elsiocb->iocb;
3931 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
3932 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
3933 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3936 elsiocb->context_un.mbox = mbox;
3938 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
3939 pcmd += sizeof(uint32_t);
3940 sp = (struct serv_parm *)pcmd;
3942 if (flag == ELS_CMD_FLOGI) {
3943 /* Copy the received service parameters back */
3944 memcpy(sp, &phba->fc_fabparam,
3945 sizeof(struct serv_parm));
3947 /* Clear the F_Port bit */
3950 /* Mark all class service parameters as invalid */
3951 sp->cls1.classValid = 0;
3952 sp->cls2.classValid = 0;
3953 sp->cls3.classValid = 0;
3954 sp->cls4.classValid = 0;
3956 /* Copy our worldwide names */
3957 memcpy(&sp->portName, &vport->fc_sparam.portName,
3958 sizeof(struct lpfc_name));
3959 memcpy(&sp->nodeName, &vport->fc_sparam.nodeName,
3960 sizeof(struct lpfc_name));
3962 memcpy(pcmd, &vport->fc_sparam,
3963 sizeof(struct serv_parm));
3966 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3967 "Issue ACC FLOGI/PLOGI: did:x%x flg:x%x",
3968 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3971 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
3972 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3973 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
3977 icmd = &elsiocb->iocb;
3978 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
3979 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
3980 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3982 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
3983 sizeof(uint32_t) + sizeof(PRLO));
3984 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
3985 els_pkt_ptr = (ELS_PKT *) pcmd;
3986 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
3988 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3989 "Issue ACC PRLO: did:x%x flg:x%x",
3990 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3995 /* Xmit ELS ACC response tag <ulpIoTag> */
3996 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3997 "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
3998 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x "
4000 elsiocb->iotag, elsiocb->iocb.ulpContext,
4001 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4002 ndlp->nlp_rpi, vport->fc_flag);
4003 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
4004 spin_lock_irq(shost->host_lock);
4005 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED ||
4006 ndlp->nlp_flag & NLP_REG_LOGIN_SEND))
4007 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
4008 spin_unlock_irq(shost->host_lock);
4009 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
4011 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4014 phba->fc_stat.elsXmitACC++;
4015 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4016 if (rc == IOCB_ERROR) {
4017 lpfc_els_free_iocb(phba, elsiocb);
4024 * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command
4025 * @vport: pointer to a virtual N_Port data structure.
4027 * @oldiocb: pointer to the original lpfc command iocb data structure.
4028 * @ndlp: pointer to a node-list data structure.
4029 * @mbox: pointer to the driver internal queue element for mailbox command.
4031 * This routine prepares and issue an Reject (RJT) response IOCB
4032 * command. If a @mbox pointer is passed in, it will be put into the
4033 * context_un.mbox field of the IOCB for the completion callback function
4034 * to issue to the HBA later.
4036 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4037 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4038 * will be stored into the context1 field of the IOCB for the completion
4039 * callback function to the reject response ELS IOCB command.
4042 * 0 - Successfully issued reject response
4043 * 1 - Failed to issue reject response
4046 lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
4047 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
4050 struct lpfc_hba *phba = vport->phba;
4053 struct lpfc_iocbq *elsiocb;
4058 cmdsize = 2 * sizeof(uint32_t);
4059 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4060 ndlp->nlp_DID, ELS_CMD_LS_RJT);
4064 icmd = &elsiocb->iocb;
4065 oldcmd = &oldiocb->iocb;
4066 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4067 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4068 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4070 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
4071 pcmd += sizeof(uint32_t);
4072 *((uint32_t *) (pcmd)) = rejectError;
4075 elsiocb->context_un.mbox = mbox;
4077 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
4078 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4079 "0129 Xmit ELS RJT x%x response tag x%x "
4080 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
4082 rejectError, elsiocb->iotag,
4083 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
4084 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
4085 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4086 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
4087 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
4089 phba->fc_stat.elsXmitLSRJT++;
4090 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4091 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4093 if (rc == IOCB_ERROR) {
4094 lpfc_els_free_iocb(phba, elsiocb);
4101 * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
4102 * @vport: pointer to a virtual N_Port data structure.
4103 * @oldiocb: pointer to the original lpfc command iocb data structure.
4104 * @ndlp: pointer to a node-list data structure.
4106 * This routine prepares and issues an Accept (ACC) response to Address
4107 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
4108 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
4110 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4111 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4112 * will be stored into the context1 field of the IOCB for the completion
4113 * callback function to the ADISC Accept response ELS IOCB command.
4116 * 0 - Successfully issued acc adisc response
4117 * 1 - Failed to issue adisc acc response
4120 lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
4121 struct lpfc_nodelist *ndlp)
4123 struct lpfc_hba *phba = vport->phba;
4125 IOCB_t *icmd, *oldcmd;
4126 struct lpfc_iocbq *elsiocb;
4131 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
4132 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4133 ndlp->nlp_DID, ELS_CMD_ACC);
4137 icmd = &elsiocb->iocb;
4138 oldcmd = &oldiocb->iocb;
4139 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4140 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4142 /* Xmit ADISC ACC response tag <ulpIoTag> */
4143 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4144 "0130 Xmit ADISC ACC response iotag x%x xri: "
4145 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
4146 elsiocb->iotag, elsiocb->iocb.ulpContext,
4147 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4149 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4151 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4152 pcmd += sizeof(uint32_t);
4154 ap = (ADISC *) (pcmd);
4155 ap->hardAL_PA = phba->fc_pref_ALPA;
4156 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
4157 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
4158 ap->DID = be32_to_cpu(vport->fc_myDID);
4160 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4161 "Issue ACC ADISC: did:x%x flg:x%x",
4162 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4164 phba->fc_stat.elsXmitACC++;
4165 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4166 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4167 if (rc == IOCB_ERROR) {
4168 lpfc_els_free_iocb(phba, elsiocb);
4175 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
4176 * @vport: pointer to a virtual N_Port data structure.
4177 * @oldiocb: pointer to the original lpfc command iocb data structure.
4178 * @ndlp: pointer to a node-list data structure.
4180 * This routine prepares and issues an Accept (ACC) response to Process
4181 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
4182 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
4184 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4185 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4186 * will be stored into the context1 field of the IOCB for the completion
4187 * callback function to the PRLI Accept response ELS IOCB command.
4190 * 0 - Successfully issued acc prli response
4191 * 1 - Failed to issue acc prli response
4194 lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
4195 struct lpfc_nodelist *ndlp)
4197 struct lpfc_hba *phba = vport->phba;
4202 struct lpfc_iocbq *elsiocb;
4207 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
4208 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4209 ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)));
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;
4218 /* Xmit PRLI ACC response tag <ulpIoTag> */
4219 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4220 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
4221 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
4222 elsiocb->iotag, elsiocb->iocb.ulpContext,
4223 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4225 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4227 *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
4228 pcmd += sizeof(uint32_t);
4230 /* For PRLI, remainder of payload is PRLI parameter page */
4231 memset(pcmd, 0, sizeof(PRLI));
4233 npr = (PRLI *) pcmd;
4236 * If the remote port is a target and our firmware version is 3.20 or
4237 * later, set the following bits for FC-TAPE support.
4239 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
4240 (vpd->rev.feaLevelHigh >= 0x02)) {
4241 npr->ConfmComplAllowed = 1;
4243 npr->TaskRetryIdReq = 1;
4246 npr->acceptRspCode = PRLI_REQ_EXECUTED;
4247 npr->estabImagePair = 1;
4248 npr->readXferRdyDis = 1;
4249 npr->ConfmComplAllowed = 1;
4251 npr->prliType = PRLI_FCP_TYPE;
4252 npr->initiatorFunc = 1;
4254 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4255 "Issue ACC PRLI: did:x%x flg:x%x",
4256 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4258 phba->fc_stat.elsXmitACC++;
4259 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4261 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4262 if (rc == IOCB_ERROR) {
4263 lpfc_els_free_iocb(phba, elsiocb);
4270 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
4271 * @vport: pointer to a virtual N_Port data structure.
4272 * @format: rnid command format.
4273 * @oldiocb: pointer to the original lpfc command iocb data structure.
4274 * @ndlp: pointer to a node-list data structure.
4276 * This routine issues a Request Node Identification Data (RNID) Accept
4277 * (ACC) response. It constructs the RNID ACC response command according to
4278 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
4279 * issue the response. Note that this command does not need to hold the ndlp
4280 * reference count for the callback. So, the ndlp reference count taken by
4281 * the lpfc_prep_els_iocb() routine is put back and the context1 field of
4282 * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
4283 * there is no ndlp reference available.
4285 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4286 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4287 * will be stored into the context1 field of the IOCB for the completion
4288 * callback function. However, for the RNID Accept Response ELS command,
4289 * this is undone later by this routine after the IOCB is allocated.
4292 * 0 - Successfully issued acc rnid response
4293 * 1 - Failed to issue acc rnid response
4296 lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
4297 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
4299 struct lpfc_hba *phba = vport->phba;
4301 IOCB_t *icmd, *oldcmd;
4302 struct lpfc_iocbq *elsiocb;
4307 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
4308 + (2 * sizeof(struct lpfc_name));
4310 cmdsize += sizeof(RNID_TOP_DISC);
4312 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4313 ndlp->nlp_DID, ELS_CMD_ACC);
4317 icmd = &elsiocb->iocb;
4318 oldcmd = &oldiocb->iocb;
4319 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4320 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4322 /* Xmit RNID ACC response tag <ulpIoTag> */
4323 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4324 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
4325 elsiocb->iotag, elsiocb->iocb.ulpContext);
4326 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4327 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4328 pcmd += sizeof(uint32_t);
4330 memset(pcmd, 0, sizeof(RNID));
4331 rn = (RNID *) (pcmd);
4332 rn->Format = format;
4333 rn->CommonLen = (2 * sizeof(struct lpfc_name));
4334 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
4335 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
4338 rn->SpecificLen = 0;
4340 case RNID_TOPOLOGY_DISC:
4341 rn->SpecificLen = sizeof(RNID_TOP_DISC);
4342 memcpy(&rn->un.topologyDisc.portName,
4343 &vport->fc_portname, sizeof(struct lpfc_name));
4344 rn->un.topologyDisc.unitType = RNID_HBA;
4345 rn->un.topologyDisc.physPort = 0;
4346 rn->un.topologyDisc.attachedNodes = 0;
4350 rn->SpecificLen = 0;
4354 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4355 "Issue ACC RNID: did:x%x flg:x%x",
4356 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4358 phba->fc_stat.elsXmitACC++;
4359 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4361 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4362 if (rc == IOCB_ERROR) {
4363 lpfc_els_free_iocb(phba, elsiocb);
4370 * lpfc_els_clear_rrq - Clear the rq that this rrq describes.
4371 * @vport: pointer to a virtual N_Port data structure.
4372 * @iocb: pointer to the lpfc command iocb data structure.
4373 * @ndlp: pointer to a node-list data structure.
4378 lpfc_els_clear_rrq(struct lpfc_vport *vport,
4379 struct lpfc_iocbq *iocb, struct lpfc_nodelist *ndlp)
4381 struct lpfc_hba *phba = vport->phba;
4386 struct lpfc_node_rrq *prrq;
4389 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) iocb->context2)->virt);
4390 pcmd += sizeof(uint32_t);
4391 rrq = (struct RRQ *)pcmd;
4392 rrq->rrq_exchg = be32_to_cpu(rrq->rrq_exchg);
4393 rxid = bf_get(rrq_rxid, rrq);
4395 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4396 "2883 Clear RRQ for SID:x%x OXID:x%x RXID:x%x"
4398 be32_to_cpu(bf_get(rrq_did, rrq)),
4399 bf_get(rrq_oxid, rrq),
4401 iocb->iotag, iocb->iocb.ulpContext);
4403 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4404 "Clear RRQ: did:x%x flg:x%x exchg:x%.08x",
4405 ndlp->nlp_DID, ndlp->nlp_flag, rrq->rrq_exchg);
4406 if (vport->fc_myDID == be32_to_cpu(bf_get(rrq_did, rrq)))
4407 xri = bf_get(rrq_oxid, rrq);
4410 prrq = lpfc_get_active_rrq(vport, xri, ndlp->nlp_DID);
4412 lpfc_clr_rrq_active(phba, xri, prrq);
4417 * lpfc_els_rsp_echo_acc - Issue echo acc response
4418 * @vport: pointer to a virtual N_Port data structure.
4419 * @data: pointer to echo data to return in the accept.
4420 * @oldiocb: pointer to the original lpfc command iocb data structure.
4421 * @ndlp: pointer to a node-list data structure.
4424 * 0 - Successfully issued acc echo response
4425 * 1 - Failed to issue acc echo response
4428 lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data,
4429 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
4431 struct lpfc_hba *phba = vport->phba;
4432 struct lpfc_iocbq *elsiocb;
4437 cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len;
4439 /* The accumulated length can exceed the BPL_SIZE. For
4440 * now, use this as the limit
4442 if (cmdsize > LPFC_BPL_SIZE)
4443 cmdsize = LPFC_BPL_SIZE;
4444 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4445 ndlp->nlp_DID, ELS_CMD_ACC);
4449 elsiocb->iocb.ulpContext = oldiocb->iocb.ulpContext; /* Xri / rx_id */
4450 elsiocb->iocb.unsli3.rcvsli3.ox_id = oldiocb->iocb.unsli3.rcvsli3.ox_id;
4452 /* Xmit ECHO ACC response tag <ulpIoTag> */
4453 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4454 "2876 Xmit ECHO ACC response tag x%x xri x%x\n",
4455 elsiocb->iotag, elsiocb->iocb.ulpContext);
4456 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4457 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4458 pcmd += sizeof(uint32_t);
4459 memcpy(pcmd, data, cmdsize - sizeof(uint32_t));
4461 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4462 "Issue ACC ECHO: did:x%x flg:x%x",
4463 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4465 phba->fc_stat.elsXmitACC++;
4466 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4468 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4469 if (rc == IOCB_ERROR) {
4470 lpfc_els_free_iocb(phba, elsiocb);
4477 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
4478 * @vport: pointer to a host virtual N_Port data structure.
4480 * This routine issues Address Discover (ADISC) ELS commands to those
4481 * N_Ports which are in node port recovery state and ADISC has not been issued
4482 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
4483 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
4484 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
4485 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
4486 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
4487 * IOCBs quit for later pick up. On the other hand, after walking through
4488 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
4489 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
4490 * no more ADISC need to be sent.
4493 * The number of N_Ports with adisc issued.
4496 lpfc_els_disc_adisc(struct lpfc_vport *vport)
4498 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4499 struct lpfc_nodelist *ndlp, *next_ndlp;
4502 /* go thru NPR nodes and issue any remaining ELS ADISCs */
4503 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
4504 if (!NLP_CHK_NODE_ACT(ndlp))
4506 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
4507 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
4508 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
4509 spin_lock_irq(shost->host_lock);
4510 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
4511 spin_unlock_irq(shost->host_lock);
4512 ndlp->nlp_prev_state = ndlp->nlp_state;
4513 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
4514 lpfc_issue_els_adisc(vport, ndlp, 0);
4516 vport->num_disc_nodes++;
4517 if (vport->num_disc_nodes >=
4518 vport->cfg_discovery_threads) {
4519 spin_lock_irq(shost->host_lock);
4520 vport->fc_flag |= FC_NLP_MORE;
4521 spin_unlock_irq(shost->host_lock);
4526 if (sentadisc == 0) {
4527 spin_lock_irq(shost->host_lock);
4528 vport->fc_flag &= ~FC_NLP_MORE;
4529 spin_unlock_irq(shost->host_lock);
4535 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
4536 * @vport: pointer to a host virtual N_Port data structure.
4538 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
4539 * which are in node port recovery state, with a @vport. Each time an ELS
4540 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
4541 * the per @vport number of discover count (num_disc_nodes) shall be
4542 * incremented. If the num_disc_nodes reaches a pre-configured threshold
4543 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
4544 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
4545 * later pick up. On the other hand, after walking through all the ndlps with
4546 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
4547 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
4548 * PLOGI need to be sent.
4551 * The number of N_Ports with plogi issued.
4554 lpfc_els_disc_plogi(struct lpfc_vport *vport)
4556 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4557 struct lpfc_nodelist *ndlp, *next_ndlp;
4560 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
4561 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
4562 if (!NLP_CHK_NODE_ACT(ndlp))
4564 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
4565 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
4566 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
4567 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
4568 ndlp->nlp_prev_state = ndlp->nlp_state;
4569 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
4570 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
4572 vport->num_disc_nodes++;
4573 if (vport->num_disc_nodes >=
4574 vport->cfg_discovery_threads) {
4575 spin_lock_irq(shost->host_lock);
4576 vport->fc_flag |= FC_NLP_MORE;
4577 spin_unlock_irq(shost->host_lock);
4583 lpfc_set_disctmo(vport);
4586 spin_lock_irq(shost->host_lock);
4587 vport->fc_flag &= ~FC_NLP_MORE;
4588 spin_unlock_irq(shost->host_lock);
4594 lpfc_rdp_res_link_service(struct fc_rdp_link_service_desc *desc,
4598 desc->tag = cpu_to_be32(RDP_LINK_SERVICE_DESC_TAG);
4599 desc->payload.els_req = word0;
4600 desc->length = cpu_to_be32(sizeof(desc->payload));
4604 lpfc_rdp_res_sfp_desc(struct fc_rdp_sfp_desc *desc,
4605 uint8_t *page_a0, uint8_t *page_a2)
4607 uint16_t wavelength;
4608 uint16_t temperature;
4614 struct sff_trasnceiver_codes_byte4 *trasn_code_byte4;
4615 struct sff_trasnceiver_codes_byte5 *trasn_code_byte5;
4617 desc->tag = cpu_to_be32(RDP_SFP_DESC_TAG);
4619 trasn_code_byte4 = (struct sff_trasnceiver_codes_byte4 *)
4620 &page_a0[SSF_TRANSCEIVER_CODE_B4];
4621 trasn_code_byte5 = (struct sff_trasnceiver_codes_byte5 *)
4622 &page_a0[SSF_TRANSCEIVER_CODE_B5];
4624 if ((trasn_code_byte4->fc_sw_laser) ||
4625 (trasn_code_byte5->fc_sw_laser_sl) ||
4626 (trasn_code_byte5->fc_sw_laser_sn)) { /* check if its short WL */
4627 flag |= (SFP_FLAG_PT_SWLASER << SFP_FLAG_PT_SHIFT);
4628 } else if (trasn_code_byte4->fc_lw_laser) {
4629 wavelength = (page_a0[SSF_WAVELENGTH_B1] << 8) |
4630 page_a0[SSF_WAVELENGTH_B0];
4631 if (wavelength == SFP_WAVELENGTH_LC1310)
4632 flag |= SFP_FLAG_PT_LWLASER_LC1310 << SFP_FLAG_PT_SHIFT;
4633 if (wavelength == SFP_WAVELENGTH_LL1550)
4634 flag |= SFP_FLAG_PT_LWLASER_LL1550 << SFP_FLAG_PT_SHIFT;
4636 /* check if its SFP+ */
4637 flag |= ((page_a0[SSF_IDENTIFIER] == SFF_PG0_IDENT_SFP) ?
4638 SFP_FLAG_CT_SFP_PLUS : SFP_FLAG_CT_UNKNOWN)
4639 << SFP_FLAG_CT_SHIFT;
4641 /* check if its OPTICAL */
4642 flag |= ((page_a0[SSF_CONNECTOR] == SFF_PG0_CONNECTOR_LC) ?
4643 SFP_FLAG_IS_OPTICAL_PORT : 0)
4644 << SFP_FLAG_IS_OPTICAL_SHIFT;
4646 temperature = (page_a2[SFF_TEMPERATURE_B1] << 8 |
4647 page_a2[SFF_TEMPERATURE_B0]);
4648 vcc = (page_a2[SFF_VCC_B1] << 8 |
4649 page_a2[SFF_VCC_B0]);
4650 tx_power = (page_a2[SFF_TXPOWER_B1] << 8 |
4651 page_a2[SFF_TXPOWER_B0]);
4652 tx_bias = (page_a2[SFF_TX_BIAS_CURRENT_B1] << 8 |
4653 page_a2[SFF_TX_BIAS_CURRENT_B0]);
4654 rx_power = (page_a2[SFF_RXPOWER_B1] << 8 |
4655 page_a2[SFF_RXPOWER_B0]);
4656 desc->sfp_info.temperature = cpu_to_be16(temperature);
4657 desc->sfp_info.rx_power = cpu_to_be16(rx_power);
4658 desc->sfp_info.tx_bias = cpu_to_be16(tx_bias);
4659 desc->sfp_info.tx_power = cpu_to_be16(tx_power);
4660 desc->sfp_info.vcc = cpu_to_be16(vcc);
4662 desc->sfp_info.flags = cpu_to_be16(flag);
4663 desc->length = cpu_to_be32(sizeof(desc->sfp_info));
4667 lpfc_rdp_res_link_error(struct fc_rdp_link_error_status_desc *desc,
4672 desc->tag = cpu_to_be32(RDP_LINK_ERROR_STATUS_DESC_TAG);
4674 type = VN_PT_PHY_PF_PORT << VN_PT_PHY_SHIFT;
4676 desc->info.port_type = cpu_to_be32(type);
4678 desc->info.link_status.link_failure_cnt =
4679 cpu_to_be32(stat->linkFailureCnt);
4680 desc->info.link_status.loss_of_synch_cnt =
4681 cpu_to_be32(stat->lossSyncCnt);
4682 desc->info.link_status.loss_of_signal_cnt =
4683 cpu_to_be32(stat->lossSignalCnt);
4684 desc->info.link_status.primitive_seq_proto_err =
4685 cpu_to_be32(stat->primSeqErrCnt);
4686 desc->info.link_status.invalid_trans_word =
4687 cpu_to_be32(stat->invalidXmitWord);
4688 desc->info.link_status.invalid_crc_cnt = cpu_to_be32(stat->crcCnt);
4690 desc->length = cpu_to_be32(sizeof(desc->info));
4694 lpfc_rdp_res_speed(struct fc_rdp_port_speed_desc *desc, struct lpfc_hba *phba)
4696 uint16_t rdp_cap = 0;
4699 desc->tag = cpu_to_be32(RDP_PORT_SPEED_DESC_TAG);
4701 switch (phba->fc_linkspeed) {
4702 case LPFC_LINK_SPEED_1GHZ:
4703 rdp_speed = RDP_PS_1GB;
4705 case LPFC_LINK_SPEED_2GHZ:
4706 rdp_speed = RDP_PS_2GB;
4708 case LPFC_LINK_SPEED_4GHZ:
4709 rdp_speed = RDP_PS_4GB;
4711 case LPFC_LINK_SPEED_8GHZ:
4712 rdp_speed = RDP_PS_8GB;
4714 case LPFC_LINK_SPEED_10GHZ:
4715 rdp_speed = RDP_PS_10GB;
4717 case LPFC_LINK_SPEED_16GHZ:
4718 rdp_speed = RDP_PS_16GB;
4721 rdp_speed = RDP_PS_UNKNOWN;
4725 desc->info.port_speed.speed = cpu_to_be16(rdp_speed);
4727 if (phba->lmt & LMT_32Gb)
4728 rdp_cap |= RDP_PS_32GB;
4729 if (phba->lmt & LMT_16Gb)
4730 rdp_cap |= RDP_PS_16GB;
4731 if (phba->lmt & LMT_10Gb)
4732 rdp_cap |= RDP_PS_10GB;
4733 if (phba->lmt & LMT_8Gb)
4734 rdp_cap |= RDP_PS_8GB;
4735 if (phba->lmt & LMT_4Gb)
4736 rdp_cap |= RDP_PS_4GB;
4737 if (phba->lmt & LMT_2Gb)
4738 rdp_cap |= RDP_PS_2GB;
4739 if (phba->lmt & LMT_1Gb)
4740 rdp_cap |= RDP_PS_1GB;
4743 rdp_cap = RDP_CAP_UNKNOWN;
4745 desc->info.port_speed.capabilities = cpu_to_be16(rdp_cap);
4746 desc->length = cpu_to_be32(sizeof(desc->info));
4750 lpfc_rdp_res_diag_port_names(struct fc_rdp_port_name_desc *desc,
4751 struct lpfc_hba *phba)
4754 desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG);
4756 memcpy(desc->port_names.wwnn, phba->wwnn,
4757 sizeof(desc->port_names.wwnn));
4759 memcpy(desc->port_names.wwpn, &phba->wwpn,
4760 sizeof(desc->port_names.wwpn));
4762 desc->length = cpu_to_be32(sizeof(desc->port_names));
4766 lpfc_rdp_res_attach_port_names(struct fc_rdp_port_name_desc *desc,
4767 struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4770 desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG);
4771 if (vport->fc_flag & FC_FABRIC) {
4772 memcpy(desc->port_names.wwnn, &vport->fabric_nodename,
4773 sizeof(desc->port_names.wwnn));
4775 memcpy(desc->port_names.wwpn, &vport->fabric_portname,
4776 sizeof(desc->port_names.wwpn));
4777 } else { /* Point to Point */
4778 memcpy(desc->port_names.wwnn, &ndlp->nlp_nodename,
4779 sizeof(desc->port_names.wwnn));
4781 memcpy(desc->port_names.wwnn, &ndlp->nlp_portname,
4782 sizeof(desc->port_names.wwpn));
4785 desc->length = cpu_to_be32(sizeof(desc->port_names));
4789 lpfc_els_rdp_cmpl(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context,
4792 struct lpfc_nodelist *ndlp = rdp_context->ndlp;
4793 struct lpfc_vport *vport = ndlp->vport;
4794 struct lpfc_iocbq *elsiocb;
4797 struct ls_rjt *stat;
4798 struct fc_rdp_res_frame *rdp_res;
4802 if (status != SUCCESS)
4804 cmdsize = sizeof(struct fc_rdp_res_frame);
4806 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize,
4807 lpfc_max_els_tries, rdp_context->ndlp,
4808 rdp_context->ndlp->nlp_DID, ELS_CMD_ACC);
4811 goto free_rdp_context;
4813 icmd = &elsiocb->iocb;
4814 icmd->ulpContext = rdp_context->rx_id;
4815 icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id;
4817 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4818 "2171 Xmit RDP response tag x%x xri x%x, "
4819 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x",
4820 elsiocb->iotag, elsiocb->iocb.ulpContext,
4821 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4823 rdp_res = (struct fc_rdp_res_frame *)
4824 (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4825 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4826 memset(pcmd, 0, sizeof(struct fc_rdp_res_frame));
4827 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4829 /* For RDP payload */
4830 lpfc_rdp_res_link_service(&rdp_res->link_service_desc, ELS_CMD_RDP);
4832 lpfc_rdp_res_sfp_desc(&rdp_res->sfp_desc,
4833 rdp_context->page_a0, rdp_context->page_a2);
4834 lpfc_rdp_res_speed(&rdp_res->portspeed_desc, phba);
4835 lpfc_rdp_res_link_error(&rdp_res->link_error_desc,
4836 &rdp_context->link_stat);
4837 lpfc_rdp_res_diag_port_names(&rdp_res->diag_port_names_desc, phba);
4838 lpfc_rdp_res_attach_port_names(&rdp_res->attached_port_names_desc,
4840 rdp_res->length = cpu_to_be32(RDP_DESC_PAYLOAD_SIZE);
4842 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4844 phba->fc_stat.elsXmitACC++;
4845 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4846 if (rc == IOCB_ERROR)
4847 lpfc_els_free_iocb(phba, elsiocb);
4853 cmdsize = 2 * sizeof(uint32_t);
4854 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, lpfc_max_els_tries,
4855 ndlp, ndlp->nlp_DID, ELS_CMD_LS_RJT);
4858 goto free_rdp_context;
4860 icmd = &elsiocb->iocb;
4861 icmd->ulpContext = rdp_context->rx_id;
4862 icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id;
4863 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4865 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
4866 stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t));
4867 stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4869 phba->fc_stat.elsXmitLSRJT++;
4870 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4871 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4873 if (rc == IOCB_ERROR)
4874 lpfc_els_free_iocb(phba, elsiocb);
4880 lpfc_get_rdp_info(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context)
4882 LPFC_MBOXQ_t *mbox = NULL;
4885 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4887 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_ELS,
4888 "7105 failed to allocate mailbox memory");
4892 if (lpfc_sli4_dump_page_a0(phba, mbox))
4893 goto prep_mbox_fail;
4894 mbox->vport = rdp_context->ndlp->vport;
4895 mbox->mbox_cmpl = lpfc_mbx_cmpl_rdp_page_a0;
4896 mbox->context2 = (struct lpfc_rdp_context *) rdp_context;
4897 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
4898 if (rc == MBX_NOT_FINISHED)
4899 goto issue_mbox_fail;
4905 mempool_free(mbox, phba->mbox_mem_pool);
4910 * lpfc_els_rcv_rdp - Process an unsolicited RDP ELS.
4911 * @vport: pointer to a host virtual N_Port data structure.
4912 * @cmdiocb: pointer to lpfc command iocb data structure.
4913 * @ndlp: pointer to a node-list data structure.
4915 * This routine processes an unsolicited RDP(Read Diagnostic Parameters)
4916 * IOCB. First, the payload of the unsolicited RDP is checked.
4917 * Then it will (1) send MBX_DUMP_MEMORY, Embedded DMP_LMSD sub command TYPE-3
4918 * for Page A0, (2) send MBX_DUMP_MEMORY, DMP_LMSD for Page A2,
4919 * (3) send MBX_READ_LNK_STAT to get link stat, (4) Call lpfc_els_rdp_cmpl
4920 * gather all data and send RDP response.
4923 * 0 - Sent the acc response
4924 * 1 - Sent the reject response.
4927 lpfc_els_rcv_rdp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4928 struct lpfc_nodelist *ndlp)
4930 struct lpfc_hba *phba = vport->phba;
4931 struct lpfc_dmabuf *pcmd;
4932 uint8_t rjt_err, rjt_expl = LSEXP_NOTHING_MORE;
4933 struct fc_rdp_req_frame *rdp_req;
4934 struct lpfc_rdp_context *rdp_context;
4938 if (phba->sli_rev < LPFC_SLI_REV4 ||
4939 (bf_get(lpfc_sli_intf_if_type,
4940 &phba->sli4_hba.sli_intf) !=
4941 LPFC_SLI_INTF_IF_TYPE_2)) {
4942 rjt_err = LSRJT_UNABLE_TPC;
4943 rjt_expl = LSEXP_REQ_UNSUPPORTED;
4947 if (phba->sli_rev < LPFC_SLI_REV4 || (phba->hba_flag & HBA_FCOE_MODE)) {
4948 rjt_err = LSRJT_UNABLE_TPC;
4949 rjt_expl = LSEXP_REQ_UNSUPPORTED;
4953 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4954 rdp_req = (struct fc_rdp_req_frame *) pcmd->virt;
4957 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4958 "2422 ELS RDP Request "
4959 "dec len %d tag x%x port_id %d len %d\n",
4960 be32_to_cpu(rdp_req->rdp_des_length),
4961 be32_to_cpu(rdp_req->nport_id_desc.tag),
4962 be32_to_cpu(rdp_req->nport_id_desc.nport_id),
4963 be32_to_cpu(rdp_req->nport_id_desc.length));
4965 if (sizeof(struct fc_rdp_nport_desc) !=
4966 be32_to_cpu(rdp_req->rdp_des_length))
4968 if (RDP_N_PORT_DESC_TAG != be32_to_cpu(rdp_req->nport_id_desc.tag))
4970 if (RDP_NPORT_ID_SIZE !=
4971 be32_to_cpu(rdp_req->nport_id_desc.length))
4973 rdp_context = kmalloc(sizeof(struct lpfc_rdp_context), GFP_KERNEL);
4975 rjt_err = LSRJT_UNABLE_TPC;
4979 memset(rdp_context, 0, sizeof(struct lpfc_rdp_context));
4980 cmd = &cmdiocb->iocb;
4981 rdp_context->ndlp = lpfc_nlp_get(ndlp);
4982 rdp_context->ox_id = cmd->unsli3.rcvsli3.ox_id;
4983 rdp_context->rx_id = cmd->ulpContext;
4984 rdp_context->cmpl = lpfc_els_rdp_cmpl;
4985 if (lpfc_get_rdp_info(phba, rdp_context)) {
4986 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_ELS,
4987 "2423 Unable to send mailbox");
4989 rjt_err = LSRJT_UNABLE_TPC;
4997 rjt_err = LSRJT_LOGICAL_ERR;
5000 memset(&stat, 0, sizeof(stat));
5001 stat.un.b.lsRjtRsnCode = rjt_err;
5002 stat.un.b.lsRjtRsnCodeExp = rjt_expl;
5003 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5009 lpfc_els_lcb_rsp(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
5014 struct lpfc_iocbq *elsiocb;
5015 struct lpfc_nodelist *ndlp;
5016 struct ls_rjt *stat;
5017 union lpfc_sli4_cfg_shdr *shdr;
5018 struct lpfc_lcb_context *lcb_context;
5019 struct fc_lcb_res_frame *lcb_res;
5020 uint32_t cmdsize, shdr_status, shdr_add_status;
5024 lcb_context = (struct lpfc_lcb_context *)pmb->context1;
5025 ndlp = lcb_context->ndlp;
5026 pmb->context1 = NULL;
5027 pmb->context2 = NULL;
5029 shdr = (union lpfc_sli4_cfg_shdr *)
5030 &pmb->u.mqe.un.beacon_config.header.cfg_shdr;
5031 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
5032 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
5034 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX,
5035 "0194 SET_BEACON_CONFIG mailbox "
5036 "completed with status x%x add_status x%x,"
5037 " mbx status x%x\n",
5038 shdr_status, shdr_add_status, mb->mbxStatus);
5040 if (mb->mbxStatus && !(shdr_status &&
5041 shdr_add_status == ADD_STATUS_OPERATION_ALREADY_ACTIVE)) {
5042 mempool_free(pmb, phba->mbox_mem_pool);
5046 mempool_free(pmb, phba->mbox_mem_pool);
5047 cmdsize = sizeof(struct fc_lcb_res_frame);
5048 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5049 lpfc_max_els_tries, ndlp,
5050 ndlp->nlp_DID, ELS_CMD_ACC);
5052 /* Decrement the ndlp reference count from previous mbox command */
5056 goto free_lcb_context;
5058 lcb_res = (struct fc_lcb_res_frame *)
5059 (((struct lpfc_dmabuf *)elsiocb->context2)->virt);
5061 icmd = &elsiocb->iocb;
5062 icmd->ulpContext = lcb_context->rx_id;
5063 icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id;
5065 pcmd = (uint8_t *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt);
5066 *((uint32_t *)(pcmd)) = ELS_CMD_ACC;
5067 lcb_res->lcb_sub_command = lcb_context->sub_command;
5068 lcb_res->lcb_type = lcb_context->type;
5069 lcb_res->lcb_frequency = lcb_context->frequency;
5070 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5071 phba->fc_stat.elsXmitACC++;
5072 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5073 if (rc == IOCB_ERROR)
5074 lpfc_els_free_iocb(phba, elsiocb);
5080 cmdsize = sizeof(struct fc_lcb_res_frame);
5081 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5082 lpfc_max_els_tries, ndlp,
5083 ndlp->nlp_DID, ELS_CMD_LS_RJT);
5086 goto free_lcb_context;
5088 icmd = &elsiocb->iocb;
5089 icmd->ulpContext = lcb_context->rx_id;
5090 icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id;
5091 pcmd = (uint8_t *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt);
5093 *((uint32_t *)(pcmd)) = ELS_CMD_LS_RJT;
5094 stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t));
5095 stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5097 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5098 phba->fc_stat.elsXmitLSRJT++;
5099 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5100 if (rc == IOCB_ERROR)
5101 lpfc_els_free_iocb(phba, elsiocb);
5107 lpfc_sli4_set_beacon(struct lpfc_vport *vport,
5108 struct lpfc_lcb_context *lcb_context,
5109 uint32_t beacon_state)
5111 struct lpfc_hba *phba = vport->phba;
5112 LPFC_MBOXQ_t *mbox = NULL;
5116 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5120 len = sizeof(struct lpfc_mbx_set_beacon_config) -
5121 sizeof(struct lpfc_sli4_cfg_mhdr);
5122 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
5123 LPFC_MBOX_OPCODE_SET_BEACON_CONFIG, len,
5124 LPFC_SLI4_MBX_EMBED);
5125 mbox->context1 = (void *)lcb_context;
5126 mbox->vport = phba->pport;
5127 mbox->mbox_cmpl = lpfc_els_lcb_rsp;
5128 bf_set(lpfc_mbx_set_beacon_port_num, &mbox->u.mqe.un.beacon_config,
5129 phba->sli4_hba.physical_port);
5130 bf_set(lpfc_mbx_set_beacon_state, &mbox->u.mqe.un.beacon_config,
5132 bf_set(lpfc_mbx_set_beacon_port_type, &mbox->u.mqe.un.beacon_config, 1);
5133 bf_set(lpfc_mbx_set_beacon_duration, &mbox->u.mqe.un.beacon_config, 0);
5134 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
5135 if (rc == MBX_NOT_FINISHED) {
5136 mempool_free(mbox, phba->mbox_mem_pool);
5145 * lpfc_els_rcv_lcb - Process an unsolicited LCB
5146 * @vport: pointer to a host virtual N_Port data structure.
5147 * @cmdiocb: pointer to lpfc command iocb data structure.
5148 * @ndlp: pointer to a node-list data structure.
5150 * This routine processes an unsolicited LCB(LINK CABLE BEACON) IOCB.
5151 * First, the payload of the unsolicited LCB is checked.
5152 * Then based on Subcommand beacon will either turn on or off.
5155 * 0 - Sent the acc response
5156 * 1 - Sent the reject response.
5159 lpfc_els_rcv_lcb(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5160 struct lpfc_nodelist *ndlp)
5162 struct lpfc_hba *phba = vport->phba;
5163 struct lpfc_dmabuf *pcmd;
5165 struct fc_lcb_request_frame *beacon;
5166 struct lpfc_lcb_context *lcb_context;
5167 uint8_t state, rjt_err;
5170 pcmd = (struct lpfc_dmabuf *)cmdiocb->context2;
5171 lp = (uint8_t *)pcmd->virt;
5172 beacon = (struct fc_lcb_request_frame *)pcmd->virt;
5174 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5175 "0192 ELS LCB Data x%x x%x x%x x%x sub x%x "
5176 "type x%x frequency %x duration x%x\n",
5177 lp[0], lp[1], lp[2],
5178 beacon->lcb_command,
5179 beacon->lcb_sub_command,
5181 beacon->lcb_frequency,
5182 be16_to_cpu(beacon->lcb_duration));
5184 if (phba->sli_rev < LPFC_SLI_REV4 ||
5185 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
5186 LPFC_SLI_INTF_IF_TYPE_2)) {
5187 rjt_err = LSRJT_CMD_UNSUPPORTED;
5191 if (phba->hba_flag & HBA_FCOE_MODE) {
5192 rjt_err = LSRJT_CMD_UNSUPPORTED;
5195 if (beacon->lcb_frequency == 0) {
5196 rjt_err = LSRJT_CMD_UNSUPPORTED;
5199 if ((beacon->lcb_type != LPFC_LCB_GREEN) &&
5200 (beacon->lcb_type != LPFC_LCB_AMBER)) {
5201 rjt_err = LSRJT_CMD_UNSUPPORTED;
5204 if ((beacon->lcb_sub_command != LPFC_LCB_ON) &&
5205 (beacon->lcb_sub_command != LPFC_LCB_OFF)) {
5206 rjt_err = LSRJT_CMD_UNSUPPORTED;
5209 if ((beacon->lcb_sub_command == LPFC_LCB_ON) &&
5210 (beacon->lcb_type != LPFC_LCB_GREEN) &&
5211 (beacon->lcb_type != LPFC_LCB_AMBER)) {
5212 rjt_err = LSRJT_CMD_UNSUPPORTED;
5215 if (be16_to_cpu(beacon->lcb_duration) != 0) {
5216 rjt_err = LSRJT_CMD_UNSUPPORTED;
5220 lcb_context = kmalloc(sizeof(*lcb_context), GFP_KERNEL);
5222 rjt_err = LSRJT_UNABLE_TPC;
5226 state = (beacon->lcb_sub_command == LPFC_LCB_ON) ? 1 : 0;
5227 lcb_context->sub_command = beacon->lcb_sub_command;
5228 lcb_context->type = beacon->lcb_type;
5229 lcb_context->frequency = beacon->lcb_frequency;
5230 lcb_context->ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id;
5231 lcb_context->rx_id = cmdiocb->iocb.ulpContext;
5232 lcb_context->ndlp = lpfc_nlp_get(ndlp);
5233 if (lpfc_sli4_set_beacon(vport, lcb_context, state)) {
5234 lpfc_printf_vlog(ndlp->vport, KERN_ERR,
5235 LOG_ELS, "0193 failed to send mail box");
5238 rjt_err = LSRJT_UNABLE_TPC;
5243 memset(&stat, 0, sizeof(stat));
5244 stat.un.b.lsRjtRsnCode = rjt_err;
5245 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5251 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
5252 * @vport: pointer to a host virtual N_Port data structure.
5254 * This routine cleans up any Registration State Change Notification
5255 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
5256 * @vport together with the host_lock is used to prevent multiple thread
5257 * trying to access the RSCN array on a same @vport at the same time.
5260 lpfc_els_flush_rscn(struct lpfc_vport *vport)
5262 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5263 struct lpfc_hba *phba = vport->phba;
5266 spin_lock_irq(shost->host_lock);
5267 if (vport->fc_rscn_flush) {
5268 /* Another thread is walking fc_rscn_id_list on this vport */
5269 spin_unlock_irq(shost->host_lock);
5272 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
5273 vport->fc_rscn_flush = 1;
5274 spin_unlock_irq(shost->host_lock);
5276 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
5277 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
5278 vport->fc_rscn_id_list[i] = NULL;
5280 spin_lock_irq(shost->host_lock);
5281 vport->fc_rscn_id_cnt = 0;
5282 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
5283 spin_unlock_irq(shost->host_lock);
5284 lpfc_can_disctmo(vport);
5285 /* Indicate we are done walking this fc_rscn_id_list */
5286 vport->fc_rscn_flush = 0;
5290 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
5291 * @vport: pointer to a host virtual N_Port data structure.
5292 * @did: remote destination port identifier.
5294 * This routine checks whether there is any pending Registration State
5295 * Configuration Notification (RSCN) to a @did on @vport.
5298 * None zero - The @did matched with a pending rscn
5299 * 0 - not able to match @did with a pending rscn
5302 lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
5307 uint32_t payload_len, i;
5308 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5310 ns_did.un.word = did;
5312 /* Never match fabric nodes for RSCNs */
5313 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
5316 /* If we are doing a FULL RSCN rediscovery, match everything */
5317 if (vport->fc_flag & FC_RSCN_DISCOVERY)
5320 spin_lock_irq(shost->host_lock);
5321 if (vport->fc_rscn_flush) {
5322 /* Another thread is walking fc_rscn_id_list on this vport */
5323 spin_unlock_irq(shost->host_lock);
5326 /* Indicate we are walking fc_rscn_id_list on this vport */
5327 vport->fc_rscn_flush = 1;
5328 spin_unlock_irq(shost->host_lock);
5329 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
5330 lp = vport->fc_rscn_id_list[i]->virt;
5331 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
5332 payload_len -= sizeof(uint32_t); /* take off word 0 */
5333 while (payload_len) {
5334 rscn_did.un.word = be32_to_cpu(*lp++);
5335 payload_len -= sizeof(uint32_t);
5336 switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) {
5337 case RSCN_ADDRESS_FORMAT_PORT:
5338 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
5339 && (ns_did.un.b.area == rscn_did.un.b.area)
5340 && (ns_did.un.b.id == rscn_did.un.b.id))
5341 goto return_did_out;
5343 case RSCN_ADDRESS_FORMAT_AREA:
5344 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
5345 && (ns_did.un.b.area == rscn_did.un.b.area))
5346 goto return_did_out;
5348 case RSCN_ADDRESS_FORMAT_DOMAIN:
5349 if (ns_did.un.b.domain == rscn_did.un.b.domain)
5350 goto return_did_out;
5352 case RSCN_ADDRESS_FORMAT_FABRIC:
5353 goto return_did_out;
5357 /* Indicate we are done with walking fc_rscn_id_list on this vport */
5358 vport->fc_rscn_flush = 0;
5361 /* Indicate we are done with walking fc_rscn_id_list on this vport */
5362 vport->fc_rscn_flush = 0;
5367 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
5368 * @vport: pointer to a host virtual N_Port data structure.
5370 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
5371 * state machine for a @vport's nodes that are with pending RSCN (Registration
5372 * State Change Notification).
5375 * 0 - Successful (currently alway return 0)
5378 lpfc_rscn_recovery_check(struct lpfc_vport *vport)
5380 struct lpfc_nodelist *ndlp = NULL;
5382 /* Move all affected nodes by pending RSCNs to NPR state. */
5383 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
5384 if (!NLP_CHK_NODE_ACT(ndlp) ||
5385 (ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
5386 !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
5388 lpfc_disc_state_machine(vport, ndlp, NULL,
5389 NLP_EVT_DEVICE_RECOVERY);
5390 lpfc_cancel_retry_delay_tmo(vport, ndlp);
5396 * lpfc_send_rscn_event - Send an RSCN event to management application
5397 * @vport: pointer to a host virtual N_Port data structure.
5398 * @cmdiocb: pointer to lpfc command iocb data structure.
5400 * lpfc_send_rscn_event sends an RSCN netlink event to management
5404 lpfc_send_rscn_event(struct lpfc_vport *vport,
5405 struct lpfc_iocbq *cmdiocb)
5407 struct lpfc_dmabuf *pcmd;
5408 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5409 uint32_t *payload_ptr;
5410 uint32_t payload_len;
5411 struct lpfc_rscn_event_header *rscn_event_data;
5413 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5414 payload_ptr = (uint32_t *) pcmd->virt;
5415 payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK);
5417 rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) +
5418 payload_len, GFP_KERNEL);
5419 if (!rscn_event_data) {
5420 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5421 "0147 Failed to allocate memory for RSCN event\n");
5424 rscn_event_data->event_type = FC_REG_RSCN_EVENT;
5425 rscn_event_data->payload_length = payload_len;
5426 memcpy(rscn_event_data->rscn_payload, payload_ptr,
5429 fc_host_post_vendor_event(shost,
5430 fc_get_event_number(),
5431 sizeof(struct lpfc_rscn_event_header) + payload_len,
5432 (char *)rscn_event_data,
5435 kfree(rscn_event_data);
5439 * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
5440 * @vport: pointer to a host virtual N_Port data structure.
5441 * @cmdiocb: pointer to lpfc command iocb data structure.
5442 * @ndlp: pointer to a node-list data structure.
5444 * This routine processes an unsolicited RSCN (Registration State Change
5445 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
5446 * to invoke fc_host_post_event() routine to the FC transport layer. If the
5447 * discover state machine is about to begin discovery, it just accepts the
5448 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
5449 * contains N_Port IDs for other vports on this HBA, it just accepts the
5450 * RSCN and ignore processing it. If the state machine is in the recovery
5451 * state, the fc_rscn_id_list of this @vport is walked and the
5452 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
5453 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
5454 * routine is invoked to handle the RSCN event.
5457 * 0 - Just sent the acc response
5458 * 1 - Sent the acc response and waited for name server completion
5461 lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5462 struct lpfc_nodelist *ndlp)
5464 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5465 struct lpfc_hba *phba = vport->phba;
5466 struct lpfc_dmabuf *pcmd;
5467 uint32_t *lp, *datap;
5468 uint32_t payload_len, length, nportid, *cmd;
5470 int rscn_id = 0, hba_id = 0;
5473 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5474 lp = (uint32_t *) pcmd->virt;
5476 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
5477 payload_len -= sizeof(uint32_t); /* take off word 0 */
5479 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5480 "0214 RSCN received Data: x%x x%x x%x x%x\n",
5481 vport->fc_flag, payload_len, *lp,
5482 vport->fc_rscn_id_cnt);
5484 /* Send an RSCN event to the management application */
5485 lpfc_send_rscn_event(vport, cmdiocb);
5487 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
5488 fc_host_post_event(shost, fc_get_event_number(),
5489 FCH_EVT_RSCN, lp[i]);
5491 /* If we are about to begin discovery, just ACC the RSCN.
5492 * Discovery processing will satisfy it.
5494 if (vport->port_state <= LPFC_NS_QRY) {
5495 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5496 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
5497 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
5499 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
5503 /* If this RSCN just contains NPortIDs for other vports on this HBA,
5504 * just ACC and ignore it.
5506 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
5507 !(vport->cfg_peer_port_login)) {
5512 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
5513 i -= sizeof(uint32_t);
5515 if (lpfc_find_vport_by_did(phba, nportid))
5518 if (rscn_id == hba_id) {
5519 /* ALL NPortIDs in RSCN are on HBA */
5520 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5522 "Data: x%x x%x x%x x%x\n",
5523 vport->fc_flag, payload_len,
5524 *lp, vport->fc_rscn_id_cnt);
5525 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5526 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
5527 ndlp->nlp_DID, vport->port_state,
5530 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
5536 spin_lock_irq(shost->host_lock);
5537 if (vport->fc_rscn_flush) {
5538 /* Another thread is walking fc_rscn_id_list on this vport */
5539 vport->fc_flag |= FC_RSCN_DISCOVERY;
5540 spin_unlock_irq(shost->host_lock);
5542 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
5545 /* Indicate we are walking fc_rscn_id_list on this vport */
5546 vport->fc_rscn_flush = 1;
5547 spin_unlock_irq(shost->host_lock);
5548 /* Get the array count after successfully have the token */
5549 rscn_cnt = vport->fc_rscn_id_cnt;
5550 /* If we are already processing an RSCN, save the received
5551 * RSCN payload buffer, cmdiocb->context2 to process later.
5553 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
5554 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5555 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
5556 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
5558 spin_lock_irq(shost->host_lock);
5559 vport->fc_flag |= FC_RSCN_DEFERRED;
5560 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
5561 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
5562 vport->fc_flag |= FC_RSCN_MODE;
5563 spin_unlock_irq(shost->host_lock);
5565 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
5566 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
5569 (payload_len + length <= LPFC_BPL_SIZE)) {
5570 *cmd &= ELS_CMD_MASK;
5571 *cmd |= cpu_to_be32(payload_len + length);
5572 memcpy(((uint8_t *)cmd) + length, lp,
5575 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
5576 vport->fc_rscn_id_cnt++;
5577 /* If we zero, cmdiocb->context2, the calling
5578 * routine will not try to free it.
5580 cmdiocb->context2 = NULL;
5583 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5584 "0235 Deferred RSCN "
5585 "Data: x%x x%x x%x\n",
5586 vport->fc_rscn_id_cnt, vport->fc_flag,
5589 vport->fc_flag |= FC_RSCN_DISCOVERY;
5590 spin_unlock_irq(shost->host_lock);
5591 /* ReDiscovery RSCN */
5592 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5593 "0234 ReDiscovery RSCN "
5594 "Data: x%x x%x x%x\n",
5595 vport->fc_rscn_id_cnt, vport->fc_flag,
5598 /* Indicate we are done walking fc_rscn_id_list on this vport */
5599 vport->fc_rscn_flush = 0;
5601 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
5602 /* send RECOVERY event for ALL nodes that match RSCN payload */
5603 lpfc_rscn_recovery_check(vport);
5604 spin_lock_irq(shost->host_lock);
5605 vport->fc_flag &= ~FC_RSCN_DEFERRED;
5606 spin_unlock_irq(shost->host_lock);
5609 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5610 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
5611 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
5613 spin_lock_irq(shost->host_lock);
5614 vport->fc_flag |= FC_RSCN_MODE;
5615 spin_unlock_irq(shost->host_lock);
5616 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
5617 /* Indicate we are done walking fc_rscn_id_list on this vport */
5618 vport->fc_rscn_flush = 0;
5620 * If we zero, cmdiocb->context2, the calling routine will
5621 * not try to free it.
5623 cmdiocb->context2 = NULL;
5624 lpfc_set_disctmo(vport);
5626 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
5627 /* send RECOVERY event for ALL nodes that match RSCN payload */
5628 lpfc_rscn_recovery_check(vport);
5629 return lpfc_els_handle_rscn(vport);
5633 * lpfc_els_handle_rscn - Handle rscn for a vport
5634 * @vport: pointer to a host virtual N_Port data structure.
5636 * This routine handles the Registration State Configuration Notification
5637 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
5638 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
5639 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
5640 * NameServer shall be issued. If CT command to the NameServer fails to be
5641 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
5642 * RSCN activities with the @vport.
5645 * 0 - Cleaned up rscn on the @vport
5646 * 1 - Wait for plogi to name server before proceed
5649 lpfc_els_handle_rscn(struct lpfc_vport *vport)
5651 struct lpfc_nodelist *ndlp;
5652 struct lpfc_hba *phba = vport->phba;
5654 /* Ignore RSCN if the port is being torn down. */
5655 if (vport->load_flag & FC_UNLOADING) {
5656 lpfc_els_flush_rscn(vport);
5660 /* Start timer for RSCN processing */
5661 lpfc_set_disctmo(vport);
5663 /* RSCN processed */
5664 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5665 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
5666 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
5669 /* To process RSCN, first compare RSCN data with NameServer */
5670 vport->fc_ns_retry = 0;
5671 vport->num_disc_nodes = 0;
5673 ndlp = lpfc_findnode_did(vport, NameServer_DID);
5674 if (ndlp && NLP_CHK_NODE_ACT(ndlp)
5675 && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
5676 /* Good ndlp, issue CT Request to NameServer */
5677 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0)
5678 /* Wait for NameServer query cmpl before we can
5682 /* If login to NameServer does not exist, issue one */
5683 /* Good status, issue PLOGI to NameServer */
5684 ndlp = lpfc_findnode_did(vport, NameServer_DID);
5685 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
5686 /* Wait for NameServer login cmpl before we can
5691 ndlp = lpfc_enable_node(vport, ndlp,
5692 NLP_STE_PLOGI_ISSUE);
5694 lpfc_els_flush_rscn(vport);
5697 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
5699 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
5701 lpfc_els_flush_rscn(vport);
5704 lpfc_nlp_init(vport, ndlp, NameServer_DID);
5705 ndlp->nlp_prev_state = ndlp->nlp_state;
5706 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
5708 ndlp->nlp_type |= NLP_FABRIC;
5709 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
5710 /* Wait for NameServer login cmpl before we can
5716 lpfc_els_flush_rscn(vport);
5721 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
5722 * @vport: pointer to a host virtual N_Port data structure.
5723 * @cmdiocb: pointer to lpfc command iocb data structure.
5724 * @ndlp: pointer to a node-list data structure.
5726 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
5727 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
5728 * point topology. As an unsolicited FLOGI should not be received in a loop
5729 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
5730 * lpfc_check_sparm() routine is invoked to check the parameters in the
5731 * unsolicited FLOGI. If parameters validation failed, the routine
5732 * lpfc_els_rsp_reject() shall be called with reject reason code set to
5733 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
5734 * FLOGI shall be compared with the Port WWN of the @vport to determine who
5735 * will initiate PLOGI. The higher lexicographical value party shall has
5736 * higher priority (as the winning port) and will initiate PLOGI and
5737 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
5738 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
5739 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
5742 * 0 - Successfully processed the unsolicited flogi
5743 * 1 - Failed to process the unsolicited flogi
5746 lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5747 struct lpfc_nodelist *ndlp)
5749 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5750 struct lpfc_hba *phba = vport->phba;
5751 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5752 uint32_t *lp = (uint32_t *) pcmd->virt;
5753 IOCB_t *icmd = &cmdiocb->iocb;
5754 struct serv_parm *sp;
5758 uint32_t fc_flag = 0;
5759 uint32_t port_state = 0;
5762 sp = (struct serv_parm *) lp;
5764 /* FLOGI received */
5766 lpfc_set_disctmo(vport);
5768 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
5769 /* We should never receive a FLOGI in loop mode, ignore it */
5770 did = icmd->un.elsreq64.remoteID;
5772 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
5774 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5775 "0113 An FLOGI ELS command x%x was "
5776 "received from DID x%x in Loop Mode\n",
5781 (void) lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1);
5785 * If our portname is greater than the remote portname,
5786 * then we initiate Nport login.
5789 rc = memcmp(&vport->fc_portname, &sp->portName,
5790 sizeof(struct lpfc_name));
5793 if (phba->sli_rev < LPFC_SLI_REV4) {
5794 mbox = mempool_alloc(phba->mbox_mem_pool,
5798 lpfc_linkdown(phba);
5799 lpfc_init_link(phba, mbox,
5801 phba->cfg_link_speed);
5802 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
5803 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5804 mbox->vport = vport;
5805 rc = lpfc_sli_issue_mbox(phba, mbox,
5807 lpfc_set_loopback_flag(phba);
5808 if (rc == MBX_NOT_FINISHED)
5809 mempool_free(mbox, phba->mbox_mem_pool);
5813 /* abort the flogi coming back to ourselves
5814 * due to external loopback on the port.
5816 lpfc_els_abort_flogi(phba);
5819 } else if (rc > 0) { /* greater than */
5820 spin_lock_irq(shost->host_lock);
5821 vport->fc_flag |= FC_PT2PT_PLOGI;
5822 spin_unlock_irq(shost->host_lock);
5824 /* If we have the high WWPN we can assign our own
5825 * myDID; otherwise, we have to WAIT for a PLOGI
5826 * from the remote NPort to find out what it
5829 vport->fc_myDID = PT2PT_LocalID;
5831 vport->fc_myDID = PT2PT_RemoteID;
5835 * The vport state should go to LPFC_FLOGI only
5836 * AFTER we issue a FLOGI, not receive one.
5838 spin_lock_irq(shost->host_lock);
5839 fc_flag = vport->fc_flag;
5840 port_state = vport->port_state;
5841 vport->fc_flag |= FC_PT2PT;
5842 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
5843 spin_unlock_irq(shost->host_lock);
5844 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5845 "3311 Rcv Flogi PS x%x new PS x%x "
5846 "fc_flag x%x new fc_flag x%x\n",
5847 port_state, vport->port_state,
5848 fc_flag, vport->fc_flag);
5851 * We temporarily set fc_myDID to make it look like we are
5852 * a Fabric. This is done just so we end up with the right
5853 * did / sid on the FLOGI ACC rsp.
5855 did = vport->fc_myDID;
5856 vport->fc_myDID = Fabric_DID;
5858 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
5861 lpfc_els_rsp_acc(vport, ELS_CMD_FLOGI, cmdiocb, ndlp, NULL);
5863 /* Now lets put fc_myDID back to what its supposed to be */
5864 vport->fc_myDID = did;
5870 * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
5871 * @vport: pointer to a host virtual N_Port data structure.
5872 * @cmdiocb: pointer to lpfc command iocb data structure.
5873 * @ndlp: pointer to a node-list data structure.
5875 * This routine processes Request Node Identification Data (RNID) IOCB
5876 * received as an ELS unsolicited event. Only when the RNID specified format
5877 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
5878 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
5879 * Accept (ACC) the RNID ELS command. All the other RNID formats are
5880 * rejected by invoking the lpfc_els_rsp_reject() routine.
5883 * 0 - Successfully processed rnid iocb (currently always return 0)
5886 lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5887 struct lpfc_nodelist *ndlp)
5889 struct lpfc_dmabuf *pcmd;
5895 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5896 lp = (uint32_t *) pcmd->virt;
5903 switch (rn->Format) {
5905 case RNID_TOPOLOGY_DISC:
5907 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
5910 /* Reject this request because format not supported */
5911 stat.un.b.lsRjtRsvd0 = 0;
5912 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5913 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5914 stat.un.b.vendorUnique = 0;
5915 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
5922 * lpfc_els_rcv_echo - Process an unsolicited echo iocb
5923 * @vport: pointer to a host virtual N_Port data structure.
5924 * @cmdiocb: pointer to lpfc command iocb data structure.
5925 * @ndlp: pointer to a node-list data structure.
5928 * 0 - Successfully processed echo iocb (currently always return 0)
5931 lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5932 struct lpfc_nodelist *ndlp)
5936 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
5938 /* skip over first word of echo command to find echo data */
5939 pcmd += sizeof(uint32_t);
5941 lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp);
5946 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
5947 * @vport: pointer to a host virtual N_Port data structure.
5948 * @cmdiocb: pointer to lpfc command iocb data structure.
5949 * @ndlp: pointer to a node-list data structure.
5951 * This routine processes a Link Incident Report Registration(LIRR) IOCB
5952 * received as an ELS unsolicited event. Currently, this function just invokes
5953 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
5956 * 0 - Successfully processed lirr iocb (currently always return 0)
5959 lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5960 struct lpfc_nodelist *ndlp)
5964 /* For now, unconditionally reject this command */
5965 stat.un.b.lsRjtRsvd0 = 0;
5966 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5967 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5968 stat.un.b.vendorUnique = 0;
5969 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5974 * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb
5975 * @vport: pointer to a host virtual N_Port data structure.
5976 * @cmdiocb: pointer to lpfc command iocb data structure.
5977 * @ndlp: pointer to a node-list data structure.
5979 * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB
5980 * received as an ELS unsolicited event. A request to RRQ shall only
5981 * be accepted if the Originator Nx_Port N_Port_ID or the Responder
5982 * Nx_Port N_Port_ID of the target Exchange is the same as the
5983 * N_Port_ID of the Nx_Port that makes the request. If the RRQ is
5984 * not accepted, an LS_RJT with reason code "Unable to perform
5985 * command request" and reason code explanation "Invalid Originator
5986 * S_ID" shall be returned. For now, we just unconditionally accept
5987 * RRQ from the target.
5990 lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5991 struct lpfc_nodelist *ndlp)
5993 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
5994 if (vport->phba->sli_rev == LPFC_SLI_REV4)
5995 lpfc_els_clear_rrq(vport, cmdiocb, ndlp);
5999 * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
6000 * @phba: pointer to lpfc hba data structure.
6001 * @pmb: pointer to the driver internal queue element for mailbox command.
6003 * This routine is the completion callback function for the MBX_READ_LNK_STAT
6004 * mailbox command. This callback function is to actually send the Accept
6005 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
6006 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
6007 * mailbox command, constructs the RPS response with the link statistics
6008 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
6009 * response to the RPS.
6011 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6012 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6013 * will be stored into the context1 field of the IOCB for the completion
6014 * callback function to the RPS Accept Response ELS IOCB command.
6018 lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
6022 struct RLS_RSP *rls_rsp;
6024 struct lpfc_iocbq *elsiocb;
6025 struct lpfc_nodelist *ndlp;
6032 ndlp = (struct lpfc_nodelist *) pmb->context2;
6033 rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff);
6034 oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff);
6035 pmb->context1 = NULL;
6036 pmb->context2 = NULL;
6038 if (mb->mbxStatus) {
6039 mempool_free(pmb, phba->mbox_mem_pool);
6043 cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t);
6044 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
6045 lpfc_max_els_tries, ndlp,
6046 ndlp->nlp_DID, ELS_CMD_ACC);
6048 /* Decrement the ndlp reference count from previous mbox command */
6052 mempool_free(pmb, phba->mbox_mem_pool);
6056 icmd = &elsiocb->iocb;
6057 icmd->ulpContext = rxid;
6058 icmd->unsli3.rcvsli3.ox_id = oxid;
6060 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6061 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
6062 pcmd += sizeof(uint32_t); /* Skip past command */
6063 rls_rsp = (struct RLS_RSP *)pcmd;
6065 rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
6066 rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
6067 rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
6068 rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
6069 rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
6070 rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
6071 mempool_free(pmb, phba->mbox_mem_pool);
6072 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
6073 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
6074 "2874 Xmit ELS RLS ACC response tag x%x xri x%x, "
6075 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
6076 elsiocb->iotag, elsiocb->iocb.ulpContext,
6077 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
6079 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
6080 phba->fc_stat.elsXmitACC++;
6081 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
6082 lpfc_els_free_iocb(phba, elsiocb);
6086 * lpfc_els_rsp_rps_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
6087 * @phba: pointer to lpfc hba data structure.
6088 * @pmb: pointer to the driver internal queue element for mailbox command.
6090 * This routine is the completion callback function for the MBX_READ_LNK_STAT
6091 * mailbox command. This callback function is to actually send the Accept
6092 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
6093 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
6094 * mailbox command, constructs the RPS response with the link statistics
6095 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
6096 * response to the RPS.
6098 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6099 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6100 * will be stored into the context1 field of the IOCB for the completion
6101 * callback function to the RPS Accept Response ELS IOCB command.
6105 lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
6111 struct lpfc_iocbq *elsiocb;
6112 struct lpfc_nodelist *ndlp;
6120 ndlp = (struct lpfc_nodelist *) pmb->context2;
6121 rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff);
6122 oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff);
6123 pmb->context1 = NULL;
6124 pmb->context2 = NULL;
6126 if (mb->mbxStatus) {
6127 mempool_free(pmb, phba->mbox_mem_pool);
6131 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
6132 mempool_free(pmb, phba->mbox_mem_pool);
6133 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
6134 lpfc_max_els_tries, ndlp,
6135 ndlp->nlp_DID, ELS_CMD_ACC);
6137 /* Decrement the ndlp reference count from previous mbox command */
6143 icmd = &elsiocb->iocb;
6144 icmd->ulpContext = rxid;
6145 icmd->unsli3.rcvsli3.ox_id = oxid;
6147 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6148 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
6149 pcmd += sizeof(uint32_t); /* Skip past command */
6150 rps_rsp = (RPS_RSP *)pcmd;
6152 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP)
6156 if (phba->pport->fc_flag & FC_FABRIC)
6160 rps_rsp->portStatus = cpu_to_be16(status);
6161 rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
6162 rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
6163 rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
6164 rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
6165 rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
6166 rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
6167 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
6168 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
6169 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
6170 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
6171 elsiocb->iotag, elsiocb->iocb.ulpContext,
6172 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
6174 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
6175 phba->fc_stat.elsXmitACC++;
6176 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
6177 lpfc_els_free_iocb(phba, elsiocb);
6182 * lpfc_els_rcv_rls - Process an unsolicited rls iocb
6183 * @vport: pointer to a host virtual N_Port data structure.
6184 * @cmdiocb: pointer to lpfc command iocb data structure.
6185 * @ndlp: pointer to a node-list data structure.
6187 * This routine processes Read Port Status (RPL) IOCB received as an
6188 * ELS unsolicited event. It first checks the remote port state. If the
6189 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
6190 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
6191 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
6192 * for reading the HBA link statistics. It is for the callback function,
6193 * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command
6194 * to actually sending out RPL Accept (ACC) response.
6197 * 0 - Successfully processed rls iocb (currently always return 0)
6200 lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6201 struct lpfc_nodelist *ndlp)
6203 struct lpfc_hba *phba = vport->phba;
6207 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
6208 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
6209 /* reject the unsolicited RPS request and done with it */
6212 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
6214 lpfc_read_lnk_stat(phba, mbox);
6215 mbox->context1 = (void *)((unsigned long)
6216 ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) |
6217 cmdiocb->iocb.ulpContext)); /* rx_id */
6218 mbox->context2 = lpfc_nlp_get(ndlp);
6219 mbox->vport = vport;
6220 mbox->mbox_cmpl = lpfc_els_rsp_rls_acc;
6221 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
6222 != MBX_NOT_FINISHED)
6223 /* Mbox completion will send ELS Response */
6225 /* Decrement reference count used for the failed mbox
6229 mempool_free(mbox, phba->mbox_mem_pool);
6232 /* issue rejection response */
6233 stat.un.b.lsRjtRsvd0 = 0;
6234 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6235 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
6236 stat.un.b.vendorUnique = 0;
6237 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
6242 * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb
6243 * @vport: pointer to a host virtual N_Port data structure.
6244 * @cmdiocb: pointer to lpfc command iocb data structure.
6245 * @ndlp: pointer to a node-list data structure.
6247 * This routine processes Read Timout Value (RTV) IOCB received as an
6248 * ELS unsolicited event. It first checks the remote port state. If the
6249 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
6250 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
6251 * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout
6252 * Value (RTV) unsolicited IOCB event.
6254 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6255 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6256 * will be stored into the context1 field of the IOCB for the completion
6257 * callback function to the RPS Accept Response ELS IOCB command.
6260 * 0 - Successfully processed rtv iocb (currently always return 0)
6263 lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6264 struct lpfc_nodelist *ndlp)
6266 struct lpfc_hba *phba = vport->phba;
6268 struct RTV_RSP *rtv_rsp;
6270 struct lpfc_iocbq *elsiocb;
6274 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
6275 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
6276 /* reject the unsolicited RPS request and done with it */
6279 cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t);
6280 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
6281 lpfc_max_els_tries, ndlp,
6282 ndlp->nlp_DID, ELS_CMD_ACC);
6287 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6288 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
6289 pcmd += sizeof(uint32_t); /* Skip past command */
6291 /* use the command's xri in the response */
6292 elsiocb->iocb.ulpContext = cmdiocb->iocb.ulpContext; /* Xri / rx_id */
6293 elsiocb->iocb.unsli3.rcvsli3.ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id;
6295 rtv_rsp = (struct RTV_RSP *)pcmd;
6297 /* populate RTV payload */
6298 rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000); /* report msecs */
6299 rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov);
6300 bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0);
6301 bf_set(qtov_rttov, rtv_rsp, 0); /* Field is for FC ONLY */
6302 rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov);
6304 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
6305 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
6306 "2875 Xmit ELS RTV ACC response tag x%x xri x%x, "
6307 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, "
6308 "Data: x%x x%x x%x\n",
6309 elsiocb->iotag, elsiocb->iocb.ulpContext,
6310 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
6312 rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov);
6313 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
6314 phba->fc_stat.elsXmitACC++;
6315 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
6316 lpfc_els_free_iocb(phba, elsiocb);
6320 /* issue rejection response */
6321 stat.un.b.lsRjtRsvd0 = 0;
6322 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6323 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
6324 stat.un.b.vendorUnique = 0;
6325 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
6329 /* lpfc_els_rcv_rps - Process an unsolicited rps iocb
6330 * @vport: pointer to a host virtual N_Port data structure.
6331 * @cmdiocb: pointer to lpfc command iocb data structure.
6332 * @ndlp: pointer to a node-list data structure.
6334 * This routine processes Read Port Status (RPS) IOCB received as an
6335 * ELS unsolicited event. It first checks the remote port state. If the
6336 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
6337 * state, it invokes the lpfc_els_rsp_reject() routine to send the reject
6338 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
6339 * for reading the HBA link statistics. It is for the callback function,
6340 * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command
6341 * to actually sending out RPS Accept (ACC) response.
6344 * 0 - Successfully processed rps iocb (currently always return 0)
6347 lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6348 struct lpfc_nodelist *ndlp)
6350 struct lpfc_hba *phba = vport->phba;
6354 struct lpfc_dmabuf *pcmd;
6358 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
6359 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
6360 /* reject the unsolicited RPS request and done with it */
6363 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6364 lp = (uint32_t *) pcmd->virt;
6365 flag = (be32_to_cpu(*lp++) & 0xf);
6369 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
6370 ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
6371 sizeof(struct lpfc_name)) == 0))) {
6373 printk("Fix me....\n");
6375 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
6377 lpfc_read_lnk_stat(phba, mbox);
6378 mbox->context1 = (void *)((unsigned long)
6379 ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) |
6380 cmdiocb->iocb.ulpContext)); /* rx_id */
6381 mbox->context2 = lpfc_nlp_get(ndlp);
6382 mbox->vport = vport;
6383 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
6384 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
6385 != MBX_NOT_FINISHED)
6386 /* Mbox completion will send ELS Response */
6388 /* Decrement reference count used for the failed mbox
6392 mempool_free(mbox, phba->mbox_mem_pool);
6397 /* issue rejection response */
6398 stat.un.b.lsRjtRsvd0 = 0;
6399 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6400 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
6401 stat.un.b.vendorUnique = 0;
6402 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
6406 /* lpfc_issue_els_rrq - Process an unsolicited rps iocb
6407 * @vport: pointer to a host virtual N_Port data structure.
6408 * @ndlp: pointer to a node-list data structure.
6409 * @did: DID of the target.
6410 * @rrq: Pointer to the rrq struct.
6412 * Build a ELS RRQ command and send it to the target. If the issue_iocb is
6413 * Successful the the completion handler will clear the RRQ.
6416 * 0 - Successfully sent rrq els iocb.
6417 * 1 - Failed to send rrq els iocb.
6420 lpfc_issue_els_rrq(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
6421 uint32_t did, struct lpfc_node_rrq *rrq)
6423 struct lpfc_hba *phba = vport->phba;
6424 struct RRQ *els_rrq;
6425 struct lpfc_iocbq *elsiocb;
6431 if (ndlp != rrq->ndlp)
6433 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
6436 /* If ndlp is not NULL, we will bump the reference count on it */
6437 cmdsize = (sizeof(uint32_t) + sizeof(struct RRQ));
6438 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, did,
6443 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6445 /* For RRQ request, remainder of payload is Exchange IDs */
6446 *((uint32_t *) (pcmd)) = ELS_CMD_RRQ;
6447 pcmd += sizeof(uint32_t);
6448 els_rrq = (struct RRQ *) pcmd;
6450 bf_set(rrq_oxid, els_rrq, phba->sli4_hba.xri_ids[rrq->xritag]);
6451 bf_set(rrq_rxid, els_rrq, rrq->rxid);
6452 bf_set(rrq_did, els_rrq, vport->fc_myDID);
6453 els_rrq->rrq = cpu_to_be32(els_rrq->rrq);
6454 els_rrq->rrq_exchg = cpu_to_be32(els_rrq->rrq_exchg);
6457 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6458 "Issue RRQ: did:x%x",
6459 did, rrq->xritag, rrq->rxid);
6460 elsiocb->context_un.rrq = rrq;
6461 elsiocb->iocb_cmpl = lpfc_cmpl_els_rrq;
6462 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
6464 if (ret == IOCB_ERROR) {
6465 lpfc_els_free_iocb(phba, elsiocb);
6472 * lpfc_send_rrq - Sends ELS RRQ if needed.
6473 * @phba: pointer to lpfc hba data structure.
6474 * @rrq: pointer to the active rrq.
6476 * This routine will call the lpfc_issue_els_rrq if the rrq is
6477 * still active for the xri. If this function returns a failure then
6478 * the caller needs to clean up the RRQ by calling lpfc_clr_active_rrq.
6480 * Returns 0 Success.
6484 lpfc_send_rrq(struct lpfc_hba *phba, struct lpfc_node_rrq *rrq)
6486 struct lpfc_nodelist *ndlp = lpfc_findnode_did(rrq->vport,
6488 if (lpfc_test_rrq_active(phba, ndlp, rrq->xritag))
6489 return lpfc_issue_els_rrq(rrq->vport, ndlp,
6496 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
6497 * @vport: pointer to a host virtual N_Port data structure.
6498 * @cmdsize: size of the ELS command.
6499 * @oldiocb: pointer to the original lpfc command iocb data structure.
6500 * @ndlp: pointer to a node-list data structure.
6502 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
6503 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
6505 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6506 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6507 * will be stored into the context1 field of the IOCB for the completion
6508 * callback function to the RPL Accept Response ELS command.
6511 * 0 - Successfully issued ACC RPL ELS command
6512 * 1 - Failed to issue ACC RPL ELS command
6515 lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
6516 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
6518 struct lpfc_hba *phba = vport->phba;
6519 IOCB_t *icmd, *oldcmd;
6521 struct lpfc_iocbq *elsiocb;
6524 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
6525 ndlp->nlp_DID, ELS_CMD_ACC);
6530 icmd = &elsiocb->iocb;
6531 oldcmd = &oldiocb->iocb;
6532 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
6533 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
6535 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6536 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
6537 pcmd += sizeof(uint16_t);
6538 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
6539 pcmd += sizeof(uint16_t);
6541 /* Setup the RPL ACC payload */
6542 rpl_rsp.listLen = be32_to_cpu(1);
6544 rpl_rsp.port_num_blk.portNum = 0;
6545 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
6546 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
6547 sizeof(struct lpfc_name));
6548 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
6549 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
6550 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6551 "0120 Xmit ELS RPL ACC response tag x%x "
6552 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
6554 elsiocb->iotag, elsiocb->iocb.ulpContext,
6555 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
6557 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
6558 phba->fc_stat.elsXmitACC++;
6559 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
6561 lpfc_els_free_iocb(phba, elsiocb);
6568 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
6569 * @vport: pointer to a host virtual N_Port data structure.
6570 * @cmdiocb: pointer to lpfc command iocb data structure.
6571 * @ndlp: pointer to a node-list data structure.
6573 * This routine processes Read Port List (RPL) IOCB received as an ELS
6574 * unsolicited event. It first checks the remote port state. If the remote
6575 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
6576 * invokes the lpfc_els_rsp_reject() routine to send reject response.
6577 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
6578 * to accept the RPL.
6581 * 0 - Successfully processed rpl iocb (currently always return 0)
6584 lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6585 struct lpfc_nodelist *ndlp)
6587 struct lpfc_dmabuf *pcmd;
6594 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
6595 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
6596 /* issue rejection response */
6597 stat.un.b.lsRjtRsvd0 = 0;
6598 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6599 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
6600 stat.un.b.vendorUnique = 0;
6601 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
6603 /* rejected the unsolicited RPL request and done with it */
6607 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6608 lp = (uint32_t *) pcmd->virt;
6609 rpl = (RPL *) (lp + 1);
6610 maxsize = be32_to_cpu(rpl->maxsize);
6612 /* We support only one port */
6613 if ((rpl->index == 0) &&
6615 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
6616 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
6618 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
6620 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
6626 * lpfc_els_rcv_farp - Process an unsolicited farp request els command
6627 * @vport: pointer to a virtual N_Port data structure.
6628 * @cmdiocb: pointer to lpfc command iocb data structure.
6629 * @ndlp: pointer to a node-list data structure.
6631 * This routine processes Fibre Channel Address Resolution Protocol
6632 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
6633 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
6634 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
6635 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
6636 * remote PortName is compared against the FC PortName stored in the @vport
6637 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
6638 * compared against the FC NodeName stored in the @vport data structure.
6639 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
6640 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
6641 * invoked to send out FARP Response to the remote node. Before sending the
6642 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
6643 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
6644 * routine is invoked to log into the remote port first.
6647 * 0 - Either the FARP Match Mode not supported or successfully processed
6650 lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6651 struct lpfc_nodelist *ndlp)
6653 struct lpfc_dmabuf *pcmd;
6657 uint32_t cmd, cnt, did;
6659 icmd = &cmdiocb->iocb;
6660 did = icmd->un.elsreq64.remoteID;
6661 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6662 lp = (uint32_t *) pcmd->virt;
6666 /* FARP-REQ received from DID <did> */
6667 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6668 "0601 FARP-REQ received from DID x%x\n", did);
6669 /* We will only support match on WWPN or WWNN */
6670 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
6675 /* If this FARP command is searching for my portname */
6676 if (fp->Mflags & FARP_MATCH_PORT) {
6677 if (memcmp(&fp->RportName, &vport->fc_portname,
6678 sizeof(struct lpfc_name)) == 0)
6682 /* If this FARP command is searching for my nodename */
6683 if (fp->Mflags & FARP_MATCH_NODE) {
6684 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
6685 sizeof(struct lpfc_name)) == 0)
6690 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
6691 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
6692 /* Log back into the node before sending the FARP. */
6693 if (fp->Rflags & FARP_REQUEST_PLOGI) {
6694 ndlp->nlp_prev_state = ndlp->nlp_state;
6695 lpfc_nlp_set_state(vport, ndlp,
6696 NLP_STE_PLOGI_ISSUE);
6697 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
6700 /* Send a FARP response to that node */
6701 if (fp->Rflags & FARP_REQUEST_FARPR)
6702 lpfc_issue_els_farpr(vport, did, 0);
6709 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
6710 * @vport: pointer to a host virtual N_Port data structure.
6711 * @cmdiocb: pointer to lpfc command iocb data structure.
6712 * @ndlp: pointer to a node-list data structure.
6714 * This routine processes Fibre Channel Address Resolution Protocol
6715 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
6716 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
6717 * the FARP response request.
6720 * 0 - Successfully processed FARPR IOCB (currently always return 0)
6723 lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6724 struct lpfc_nodelist *ndlp)
6726 struct lpfc_dmabuf *pcmd;
6731 icmd = &cmdiocb->iocb;
6732 did = icmd->un.elsreq64.remoteID;
6733 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6734 lp = (uint32_t *) pcmd->virt;
6737 /* FARP-RSP received from DID <did> */
6738 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6739 "0600 FARP-RSP received from DID x%x\n", did);
6740 /* ACCEPT the Farp resp request */
6741 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
6747 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
6748 * @vport: pointer to a host virtual N_Port data structure.
6749 * @cmdiocb: pointer to lpfc command iocb data structure.
6750 * @fan_ndlp: pointer to a node-list data structure.
6752 * This routine processes a Fabric Address Notification (FAN) IOCB
6753 * command received as an ELS unsolicited event. The FAN ELS command will
6754 * only be processed on a physical port (i.e., the @vport represents the
6755 * physical port). The fabric NodeName and PortName from the FAN IOCB are
6756 * compared against those in the phba data structure. If any of those is
6757 * different, the lpfc_initial_flogi() routine is invoked to initialize
6758 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
6759 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
6760 * is invoked to register login to the fabric.
6763 * 0 - Successfully processed fan iocb (currently always return 0).
6766 lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6767 struct lpfc_nodelist *fan_ndlp)
6769 struct lpfc_hba *phba = vport->phba;
6773 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
6774 lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
6776 /* FAN received; Fan does not have a reply sequence */
6777 if ((vport == phba->pport) &&
6778 (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
6779 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
6780 sizeof(struct lpfc_name))) ||
6781 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
6782 sizeof(struct lpfc_name)))) {
6783 /* This port has switched fabrics. FLOGI is required */
6784 lpfc_issue_init_vfi(vport);
6786 /* FAN verified - skip FLOGI */
6787 vport->fc_myDID = vport->fc_prevDID;
6788 if (phba->sli_rev < LPFC_SLI_REV4)
6789 lpfc_issue_fabric_reglogin(vport);
6791 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6792 "3138 Need register VFI: (x%x/%x)\n",
6793 vport->fc_prevDID, vport->fc_myDID);
6794 lpfc_issue_reg_vfi(vport);
6802 * lpfc_els_timeout - Handler funciton to the els timer
6803 * @ptr: holder for the timer function associated data.
6805 * This routine is invoked by the ELS timer after timeout. It posts the ELS
6806 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
6807 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
6808 * up the worker thread. It is for the worker thread to invoke the routine
6809 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
6812 lpfc_els_timeout(unsigned long ptr)
6814 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
6815 struct lpfc_hba *phba = vport->phba;
6816 uint32_t tmo_posted;
6817 unsigned long iflag;
6819 spin_lock_irqsave(&vport->work_port_lock, iflag);
6820 tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
6821 if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING)))
6822 vport->work_port_events |= WORKER_ELS_TMO;
6823 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
6825 if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING)))
6826 lpfc_worker_wake_up(phba);
6832 * lpfc_els_timeout_handler - Process an els timeout event
6833 * @vport: pointer to a virtual N_Port data structure.
6835 * This routine is the actual handler function that processes an ELS timeout
6836 * event. It walks the ELS ring to get and abort all the IOCBs (except the
6837 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
6838 * invoking the lpfc_sli_issue_abort_iotag() routine.
6841 lpfc_els_timeout_handler(struct lpfc_vport *vport)
6843 struct lpfc_hba *phba = vport->phba;
6844 struct lpfc_sli_ring *pring;
6845 struct lpfc_iocbq *tmp_iocb, *piocb;
6847 struct lpfc_dmabuf *pcmd;
6848 uint32_t els_command = 0;
6850 uint32_t remote_ID = 0xffffffff;
6851 LIST_HEAD(abort_list);
6854 timeout = (uint32_t)(phba->fc_ratov << 1);
6856 pring = &phba->sli.ring[LPFC_ELS_RING];
6857 if ((phba->pport->load_flag & FC_UNLOADING))
6859 spin_lock_irq(&phba->hbalock);
6860 if (phba->sli_rev == LPFC_SLI_REV4)
6861 spin_lock(&pring->ring_lock);
6863 if ((phba->pport->load_flag & FC_UNLOADING)) {
6864 if (phba->sli_rev == LPFC_SLI_REV4)
6865 spin_unlock(&pring->ring_lock);
6866 spin_unlock_irq(&phba->hbalock);
6870 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
6873 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
6874 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
6875 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
6878 if (piocb->vport != vport)
6881 pcmd = (struct lpfc_dmabuf *) piocb->context2;
6883 els_command = *(uint32_t *) (pcmd->virt);
6885 if (els_command == ELS_CMD_FARP ||
6886 els_command == ELS_CMD_FARPR ||
6887 els_command == ELS_CMD_FDISC)
6890 if (piocb->drvrTimeout > 0) {
6891 if (piocb->drvrTimeout >= timeout)
6892 piocb->drvrTimeout -= timeout;
6894 piocb->drvrTimeout = 0;
6898 remote_ID = 0xffffffff;
6899 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
6900 remote_ID = cmd->un.elsreq64.remoteID;
6902 struct lpfc_nodelist *ndlp;
6903 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
6904 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
6905 remote_ID = ndlp->nlp_DID;
6907 list_add_tail(&piocb->dlist, &abort_list);
6909 if (phba->sli_rev == LPFC_SLI_REV4)
6910 spin_unlock(&pring->ring_lock);
6911 spin_unlock_irq(&phba->hbalock);
6913 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
6915 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6916 "0127 ELS timeout Data: x%x x%x x%x "
6917 "x%x\n", els_command,
6918 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
6919 spin_lock_irq(&phba->hbalock);
6920 list_del_init(&piocb->dlist);
6921 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
6922 spin_unlock_irq(&phba->hbalock);
6925 if (!list_empty(&phba->sli.ring[LPFC_ELS_RING].txcmplq))
6926 if (!(phba->pport->load_flag & FC_UNLOADING))
6927 mod_timer(&vport->els_tmofunc,
6928 jiffies + msecs_to_jiffies(1000 * timeout));
6932 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
6933 * @vport: pointer to a host virtual N_Port data structure.
6935 * This routine is used to clean up all the outstanding ELS commands on a
6936 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
6937 * routine. After that, it walks the ELS transmit queue to remove all the
6938 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
6939 * the IOCBs with a non-NULL completion callback function, the callback
6940 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
6941 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
6942 * callback function, the IOCB will simply be released. Finally, it walks
6943 * the ELS transmit completion queue to issue an abort IOCB to any transmit
6944 * completion queue IOCB that is associated with the @vport and is not
6945 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
6946 * part of the discovery state machine) out to HBA by invoking the
6947 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
6948 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
6949 * the IOCBs are aborted when this function returns.
6952 lpfc_els_flush_cmd(struct lpfc_vport *vport)
6954 LIST_HEAD(abort_list);
6955 struct lpfc_hba *phba = vport->phba;
6956 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
6957 struct lpfc_iocbq *tmp_iocb, *piocb;
6960 lpfc_fabric_abort_vport(vport);
6962 * For SLI3, only the hbalock is required. But SLI4 needs to coordinate
6963 * with the ring insert operation. Because lpfc_sli_issue_abort_iotag
6964 * ultimately grabs the ring_lock, the driver must splice the list into
6965 * a working list and release the locks before calling the abort.
6967 spin_lock_irq(&phba->hbalock);
6968 if (phba->sli_rev == LPFC_SLI_REV4)
6969 spin_lock(&pring->ring_lock);
6971 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
6972 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
6975 if (piocb->vport != vport)
6977 list_add_tail(&piocb->dlist, &abort_list);
6979 if (phba->sli_rev == LPFC_SLI_REV4)
6980 spin_unlock(&pring->ring_lock);
6981 spin_unlock_irq(&phba->hbalock);
6982 /* Abort each iocb on the aborted list and remove the dlist links. */
6983 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
6984 spin_lock_irq(&phba->hbalock);
6985 list_del_init(&piocb->dlist);
6986 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
6987 spin_unlock_irq(&phba->hbalock);
6989 if (!list_empty(&abort_list))
6990 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6991 "3387 abort list for txq not empty\n");
6992 INIT_LIST_HEAD(&abort_list);
6994 spin_lock_irq(&phba->hbalock);
6995 if (phba->sli_rev == LPFC_SLI_REV4)
6996 spin_lock(&pring->ring_lock);
6998 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
7001 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
7005 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
7006 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
7007 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
7008 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
7009 cmd->ulpCommand == CMD_ABORT_XRI_CN)
7012 if (piocb->vport != vport)
7015 list_del_init(&piocb->list);
7016 list_add_tail(&piocb->list, &abort_list);
7018 if (phba->sli_rev == LPFC_SLI_REV4)
7019 spin_unlock(&pring->ring_lock);
7020 spin_unlock_irq(&phba->hbalock);
7022 /* Cancell all the IOCBs from the completions list */
7023 lpfc_sli_cancel_iocbs(phba, &abort_list,
7024 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
7030 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
7031 * @phba: pointer to lpfc hba data structure.
7033 * This routine is used to clean up all the outstanding ELS commands on a
7034 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
7035 * routine. After that, it walks the ELS transmit queue to remove all the
7036 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
7037 * the IOCBs with the completion callback function associated, the callback
7038 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
7039 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
7040 * callback function associated, the IOCB will simply be released. Finally,
7041 * it walks the ELS transmit completion queue to issue an abort IOCB to any
7042 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
7043 * management plane IOCBs that are not part of the discovery state machine)
7044 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
7047 lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
7049 struct lpfc_vport *vport;
7050 list_for_each_entry(vport, &phba->port_list, listentry)
7051 lpfc_els_flush_cmd(vport);
7057 * lpfc_send_els_failure_event - Posts an ELS command failure event
7058 * @phba: Pointer to hba context object.
7059 * @cmdiocbp: Pointer to command iocb which reported error.
7060 * @rspiocbp: Pointer to response iocb which reported error.
7062 * This function sends an event when there is an ELS command
7066 lpfc_send_els_failure_event(struct lpfc_hba *phba,
7067 struct lpfc_iocbq *cmdiocbp,
7068 struct lpfc_iocbq *rspiocbp)
7070 struct lpfc_vport *vport = cmdiocbp->vport;
7071 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7072 struct lpfc_lsrjt_event lsrjt_event;
7073 struct lpfc_fabric_event_header fabric_event;
7075 struct lpfc_nodelist *ndlp;
7078 ndlp = cmdiocbp->context1;
7079 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
7082 if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) {
7083 lsrjt_event.header.event_type = FC_REG_ELS_EVENT;
7084 lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV;
7085 memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname,
7086 sizeof(struct lpfc_name));
7087 memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename,
7088 sizeof(struct lpfc_name));
7089 pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
7090 cmdiocbp->context2)->virt);
7091 lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0;
7092 stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]);
7093 lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode;
7094 lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp;
7095 fc_host_post_vendor_event(shost,
7096 fc_get_event_number(),
7097 sizeof(lsrjt_event),
7098 (char *)&lsrjt_event,
7102 if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) ||
7103 (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) {
7104 fabric_event.event_type = FC_REG_FABRIC_EVENT;
7105 if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY)
7106 fabric_event.subcategory = LPFC_EVENT_PORT_BUSY;
7108 fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY;
7109 memcpy(fabric_event.wwpn, &ndlp->nlp_portname,
7110 sizeof(struct lpfc_name));
7111 memcpy(fabric_event.wwnn, &ndlp->nlp_nodename,
7112 sizeof(struct lpfc_name));
7113 fc_host_post_vendor_event(shost,
7114 fc_get_event_number(),
7115 sizeof(fabric_event),
7116 (char *)&fabric_event,
7124 * lpfc_send_els_event - Posts unsolicited els event
7125 * @vport: Pointer to vport object.
7126 * @ndlp: Pointer FC node object.
7127 * @cmd: ELS command code.
7129 * This function posts an event when there is an incoming
7130 * unsolicited ELS command.
7133 lpfc_send_els_event(struct lpfc_vport *vport,
7134 struct lpfc_nodelist *ndlp,
7137 struct lpfc_els_event_header *els_data = NULL;
7138 struct lpfc_logo_event *logo_data = NULL;
7139 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7141 if (*payload == ELS_CMD_LOGO) {
7142 logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL);
7144 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7145 "0148 Failed to allocate memory "
7146 "for LOGO event\n");
7149 els_data = &logo_data->header;
7151 els_data = kmalloc(sizeof(struct lpfc_els_event_header),
7154 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7155 "0149 Failed to allocate memory "
7160 els_data->event_type = FC_REG_ELS_EVENT;
7163 els_data->subcategory = LPFC_EVENT_PLOGI_RCV;
7166 els_data->subcategory = LPFC_EVENT_PRLO_RCV;
7169 els_data->subcategory = LPFC_EVENT_ADISC_RCV;
7172 els_data->subcategory = LPFC_EVENT_LOGO_RCV;
7173 /* Copy the WWPN in the LOGO payload */
7174 memcpy(logo_data->logo_wwpn, &payload[2],
7175 sizeof(struct lpfc_name));
7181 memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name));
7182 memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name));
7183 if (*payload == ELS_CMD_LOGO) {
7184 fc_host_post_vendor_event(shost,
7185 fc_get_event_number(),
7186 sizeof(struct lpfc_logo_event),
7191 fc_host_post_vendor_event(shost,
7192 fc_get_event_number(),
7193 sizeof(struct lpfc_els_event_header),
7204 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
7205 * @phba: pointer to lpfc hba data structure.
7206 * @pring: pointer to a SLI ring.
7207 * @vport: pointer to a host virtual N_Port data structure.
7208 * @elsiocb: pointer to lpfc els command iocb data structure.
7210 * This routine is used for processing the IOCB associated with a unsolicited
7211 * event. It first determines whether there is an existing ndlp that matches
7212 * the DID from the unsolicited IOCB. If not, it will create a new one with
7213 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
7214 * IOCB is then used to invoke the proper routine and to set up proper state
7215 * of the discovery state machine.
7218 lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
7219 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
7221 struct Scsi_Host *shost;
7222 struct lpfc_nodelist *ndlp;
7225 uint32_t cmd, did, newnode;
7226 uint8_t rjt_exp, rjt_err = 0;
7227 IOCB_t *icmd = &elsiocb->iocb;
7229 if (!vport || !(elsiocb->context2))
7233 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
7235 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
7236 lpfc_post_buffer(phba, pring, 1);
7238 did = icmd->un.rcvels.remoteID;
7239 if (icmd->ulpStatus) {
7240 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7241 "RCV Unsol ELS: status:x%x/x%x did:x%x",
7242 icmd->ulpStatus, icmd->un.ulpWord[4], did);
7246 /* Check to see if link went down during discovery */
7247 if (lpfc_els_chk_latt(vport))
7250 /* Ignore traffic received during vport shutdown. */
7251 if (vport->load_flag & FC_UNLOADING)
7254 /* If NPort discovery is delayed drop incoming ELS */
7255 if ((vport->fc_flag & FC_DISC_DELAYED) &&
7256 (cmd != ELS_CMD_PLOGI))
7259 ndlp = lpfc_findnode_did(vport, did);
7261 /* Cannot find existing Fabric ndlp, so allocate a new one */
7262 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
7266 lpfc_nlp_init(vport, ndlp, did);
7267 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
7269 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
7270 ndlp->nlp_type |= NLP_FABRIC;
7271 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
7272 ndlp = lpfc_enable_node(vport, ndlp,
7273 NLP_STE_UNUSED_NODE);
7276 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
7278 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
7279 ndlp->nlp_type |= NLP_FABRIC;
7280 } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
7281 /* This is similar to the new node path */
7282 ndlp = lpfc_nlp_get(ndlp);
7285 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
7289 phba->fc_stat.elsRcvFrame++;
7292 * Do not process any unsolicited ELS commands
7293 * if the ndlp is in DEV_LOSS
7295 shost = lpfc_shost_from_vport(vport);
7296 spin_lock_irq(shost->host_lock);
7297 if (ndlp->nlp_flag & NLP_IN_DEV_LOSS) {
7298 spin_unlock_irq(shost->host_lock);
7301 spin_unlock_irq(shost->host_lock);
7303 elsiocb->context1 = lpfc_nlp_get(ndlp);
7304 elsiocb->vport = vport;
7306 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
7307 cmd &= ELS_CMD_MASK;
7309 /* ELS command <elsCmd> received from NPORT <did> */
7310 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7311 "0112 ELS command x%x received from NPORT x%x "
7312 "Data: x%x x%x x%x x%x\n",
7313 cmd, did, vport->port_state, vport->fc_flag,
7314 vport->fc_myDID, vport->fc_prevDID);
7316 /* reject till our FLOGI completes */
7317 if ((vport->port_state < LPFC_FABRIC_CFG_LINK) &&
7318 (cmd != ELS_CMD_FLOGI)) {
7319 rjt_err = LSRJT_UNABLE_TPC;
7320 rjt_exp = LSEXP_NOTHING_MORE;
7326 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7327 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
7328 did, vport->port_state, ndlp->nlp_flag);
7330 phba->fc_stat.elsRcvPLOGI++;
7331 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
7332 if (phba->sli_rev == LPFC_SLI_REV4 &&
7333 (phba->pport->fc_flag & FC_PT2PT)) {
7334 vport->fc_prevDID = vport->fc_myDID;
7335 /* Our DID needs to be updated before registering
7336 * the vfi. This is done in lpfc_rcv_plogi but
7337 * that is called after the reg_vfi.
7339 vport->fc_myDID = elsiocb->iocb.un.rcvels.parmRo;
7340 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7341 "3312 Remote port assigned DID x%x "
7342 "%x\n", vport->fc_myDID,
7346 lpfc_send_els_event(vport, ndlp, payload);
7348 /* If Nport discovery is delayed, reject PLOGIs */
7349 if (vport->fc_flag & FC_DISC_DELAYED) {
7350 rjt_err = LSRJT_UNABLE_TPC;
7351 rjt_exp = LSEXP_NOTHING_MORE;
7355 if (vport->port_state < LPFC_DISC_AUTH) {
7356 if (!(phba->pport->fc_flag & FC_PT2PT) ||
7357 (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
7358 rjt_err = LSRJT_UNABLE_TPC;
7359 rjt_exp = LSEXP_NOTHING_MORE;
7364 spin_lock_irq(shost->host_lock);
7365 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
7366 spin_unlock_irq(shost->host_lock);
7368 lpfc_disc_state_machine(vport, ndlp, elsiocb,
7373 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7374 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
7375 did, vport->port_state, ndlp->nlp_flag);
7377 phba->fc_stat.elsRcvFLOGI++;
7378 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
7383 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7384 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
7385 did, vport->port_state, ndlp->nlp_flag);
7387 phba->fc_stat.elsRcvLOGO++;
7388 lpfc_send_els_event(vport, ndlp, payload);
7389 if (vport->port_state < LPFC_DISC_AUTH) {
7390 rjt_err = LSRJT_UNABLE_TPC;
7391 rjt_exp = LSEXP_NOTHING_MORE;
7394 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
7397 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7398 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
7399 did, vport->port_state, ndlp->nlp_flag);
7401 phba->fc_stat.elsRcvPRLO++;
7402 lpfc_send_els_event(vport, ndlp, payload);
7403 if (vport->port_state < LPFC_DISC_AUTH) {
7404 rjt_err = LSRJT_UNABLE_TPC;
7405 rjt_exp = LSEXP_NOTHING_MORE;
7408 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
7411 phba->fc_stat.elsRcvLCB++;
7412 lpfc_els_rcv_lcb(vport, elsiocb, ndlp);
7415 phba->fc_stat.elsRcvRDP++;
7416 lpfc_els_rcv_rdp(vport, elsiocb, ndlp);
7419 phba->fc_stat.elsRcvRSCN++;
7420 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
7425 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7426 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
7427 did, vport->port_state, ndlp->nlp_flag);
7429 lpfc_send_els_event(vport, ndlp, payload);
7430 phba->fc_stat.elsRcvADISC++;
7431 if (vport->port_state < LPFC_DISC_AUTH) {
7432 rjt_err = LSRJT_UNABLE_TPC;
7433 rjt_exp = LSEXP_NOTHING_MORE;
7436 lpfc_disc_state_machine(vport, ndlp, elsiocb,
7440 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7441 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
7442 did, vport->port_state, ndlp->nlp_flag);
7444 phba->fc_stat.elsRcvPDISC++;
7445 if (vport->port_state < LPFC_DISC_AUTH) {
7446 rjt_err = LSRJT_UNABLE_TPC;
7447 rjt_exp = LSEXP_NOTHING_MORE;
7450 lpfc_disc_state_machine(vport, ndlp, elsiocb,
7454 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7455 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
7456 did, vport->port_state, ndlp->nlp_flag);
7458 phba->fc_stat.elsRcvFARPR++;
7459 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
7462 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7463 "RCV FARP: did:x%x/ste:x%x flg:x%x",
7464 did, vport->port_state, ndlp->nlp_flag);
7466 phba->fc_stat.elsRcvFARP++;
7467 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
7470 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7471 "RCV FAN: did:x%x/ste:x%x flg:x%x",
7472 did, vport->port_state, ndlp->nlp_flag);
7474 phba->fc_stat.elsRcvFAN++;
7475 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
7478 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7479 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
7480 did, vport->port_state, ndlp->nlp_flag);
7482 phba->fc_stat.elsRcvPRLI++;
7483 if (vport->port_state < LPFC_DISC_AUTH) {
7484 rjt_err = LSRJT_UNABLE_TPC;
7485 rjt_exp = LSEXP_NOTHING_MORE;
7488 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
7491 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7492 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
7493 did, vport->port_state, ndlp->nlp_flag);
7495 phba->fc_stat.elsRcvLIRR++;
7496 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
7501 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7502 "RCV RLS: did:x%x/ste:x%x flg:x%x",
7503 did, vport->port_state, ndlp->nlp_flag);
7505 phba->fc_stat.elsRcvRLS++;
7506 lpfc_els_rcv_rls(vport, elsiocb, ndlp);
7511 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7512 "RCV RPS: did:x%x/ste:x%x flg:x%x",
7513 did, vport->port_state, ndlp->nlp_flag);
7515 phba->fc_stat.elsRcvRPS++;
7516 lpfc_els_rcv_rps(vport, elsiocb, ndlp);
7521 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7522 "RCV RPL: did:x%x/ste:x%x flg:x%x",
7523 did, vport->port_state, ndlp->nlp_flag);
7525 phba->fc_stat.elsRcvRPL++;
7526 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
7531 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7532 "RCV RNID: did:x%x/ste:x%x flg:x%x",
7533 did, vport->port_state, ndlp->nlp_flag);
7535 phba->fc_stat.elsRcvRNID++;
7536 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
7541 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7542 "RCV RTV: did:x%x/ste:x%x flg:x%x",
7543 did, vport->port_state, ndlp->nlp_flag);
7544 phba->fc_stat.elsRcvRTV++;
7545 lpfc_els_rcv_rtv(vport, elsiocb, ndlp);
7550 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7551 "RCV RRQ: did:x%x/ste:x%x flg:x%x",
7552 did, vport->port_state, ndlp->nlp_flag);
7554 phba->fc_stat.elsRcvRRQ++;
7555 lpfc_els_rcv_rrq(vport, elsiocb, ndlp);
7560 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7561 "RCV ECHO: did:x%x/ste:x%x flg:x%x",
7562 did, vport->port_state, ndlp->nlp_flag);
7564 phba->fc_stat.elsRcvECHO++;
7565 lpfc_els_rcv_echo(vport, elsiocb, ndlp);
7570 /* receive this due to exchange closed */
7571 rjt_err = LSRJT_UNABLE_TPC;
7572 rjt_exp = LSEXP_INVALID_OX_RX;
7575 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7576 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
7577 cmd, did, vport->port_state);
7579 /* Unsupported ELS command, reject */
7580 rjt_err = LSRJT_CMD_UNSUPPORTED;
7581 rjt_exp = LSEXP_NOTHING_MORE;
7583 /* Unknown ELS command <elsCmd> received from NPORT <did> */
7584 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7585 "0115 Unknown ELS command x%x "
7586 "received from NPORT x%x\n", cmd, did);
7593 /* check if need to LS_RJT received ELS cmd */
7595 memset(&stat, 0, sizeof(stat));
7596 stat.un.b.lsRjtRsnCode = rjt_err;
7597 stat.un.b.lsRjtRsnCodeExp = rjt_exp;
7598 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
7602 lpfc_nlp_put(elsiocb->context1);
7603 elsiocb->context1 = NULL;
7607 if (vport && !(vport->load_flag & FC_UNLOADING))
7608 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7609 "0111 Dropping received ELS cmd "
7610 "Data: x%x x%x x%x\n",
7611 icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout);
7612 phba->fc_stat.elsRcvDrop++;
7616 * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
7617 * @phba: pointer to lpfc hba data structure.
7618 * @pring: pointer to a SLI ring.
7619 * @elsiocb: pointer to lpfc els iocb data structure.
7621 * This routine is used to process an unsolicited event received from a SLI
7622 * (Service Level Interface) ring. The actual processing of the data buffer
7623 * associated with the unsolicited event is done by invoking the routine
7624 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
7625 * SLI ring on which the unsolicited event was received.
7628 lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
7629 struct lpfc_iocbq *elsiocb)
7631 struct lpfc_vport *vport = phba->pport;
7632 IOCB_t *icmd = &elsiocb->iocb;
7634 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
7635 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
7637 elsiocb->context1 = NULL;
7638 elsiocb->context2 = NULL;
7639 elsiocb->context3 = NULL;
7641 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
7642 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
7643 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
7644 (icmd->un.ulpWord[4] & IOERR_PARAM_MASK) ==
7645 IOERR_RCV_BUFFER_WAITING) {
7646 phba->fc_stat.NoRcvBuf++;
7647 /* Not enough posted buffers; Try posting more buffers */
7648 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
7649 lpfc_post_buffer(phba, pring, 0);
7653 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
7654 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
7655 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
7656 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
7657 vport = phba->pport;
7659 vport = lpfc_find_vport_by_vpid(phba,
7660 icmd->unsli3.rcvsli3.vpi);
7663 /* If there are no BDEs associated
7664 * with this IOCB, there is nothing to do.
7666 if (icmd->ulpBdeCount == 0)
7669 /* type of ELS cmd is first 32bit word
7672 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
7673 elsiocb->context2 = bdeBuf1;
7675 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
7676 icmd->un.cont64[0].addrLow);
7677 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
7681 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
7683 * The different unsolicited event handlers would tell us
7684 * if they are done with "mp" by setting context2 to NULL.
7686 if (elsiocb->context2) {
7687 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
7688 elsiocb->context2 = NULL;
7691 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
7692 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
7693 icmd->ulpBdeCount == 2) {
7694 elsiocb->context2 = bdeBuf2;
7695 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
7696 /* free mp if we are done with it */
7697 if (elsiocb->context2) {
7698 lpfc_in_buf_free(phba, elsiocb->context2);
7699 elsiocb->context2 = NULL;
7705 * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
7706 * @phba: pointer to lpfc hba data structure.
7707 * @vport: pointer to a virtual N_Port data structure.
7709 * This routine issues a Port Login (PLOGI) to the Name Server with
7710 * State Change Request (SCR) for a @vport. This routine will create an
7711 * ndlp for the Name Server associated to the @vport if such node does
7712 * not already exist. The PLOGI to Name Server is issued by invoking the
7713 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
7714 * (FDMI) is configured to the @vport, a FDMI node will be created and
7715 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
7718 lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
7720 struct lpfc_nodelist *ndlp, *ndlp_fdmi;
7721 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7724 * If lpfc_delay_discovery parameter is set and the clean address
7725 * bit is cleared and fc fabric parameters chenged, delay FC NPort
7728 spin_lock_irq(shost->host_lock);
7729 if (vport->fc_flag & FC_DISC_DELAYED) {
7730 spin_unlock_irq(shost->host_lock);
7731 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
7732 "3334 Delay fc port discovery for %d seconds\n",
7734 mod_timer(&vport->delayed_disc_tmo,
7735 jiffies + msecs_to_jiffies(1000 * phba->fc_ratov));
7738 spin_unlock_irq(shost->host_lock);
7740 ndlp = lpfc_findnode_did(vport, NameServer_DID);
7742 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
7744 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
7745 lpfc_disc_start(vport);
7748 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
7749 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7750 "0251 NameServer login: no memory\n");
7753 lpfc_nlp_init(vport, ndlp, NameServer_DID);
7754 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
7755 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
7757 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
7758 lpfc_disc_start(vport);
7761 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
7762 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7763 "0348 NameServer login: node freed\n");
7767 ndlp->nlp_type |= NLP_FABRIC;
7769 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
7771 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
7772 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
7773 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7774 "0252 Cannot issue NameServer login\n");
7778 if (vport->cfg_fdmi_on & LPFC_FDMI_SUPPORT) {
7779 /* If this is the first time, allocate an ndlp and initialize
7780 * it. Otherwise, make sure the node is enabled and then do the
7783 ndlp_fdmi = lpfc_findnode_did(vport, FDMI_DID);
7785 ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
7788 lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID);
7789 ndlp_fdmi->nlp_type |= NLP_FABRIC;
7793 if (!NLP_CHK_NODE_ACT(ndlp_fdmi))
7794 ndlp_fdmi = lpfc_enable_node(vport,
7799 lpfc_nlp_set_state(vport, ndlp_fdmi,
7800 NLP_STE_PLOGI_ISSUE);
7801 lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID, 0);
7807 * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
7808 * @phba: pointer to lpfc hba data structure.
7809 * @pmb: pointer to the driver internal queue element for mailbox command.
7811 * This routine is the completion callback function to register new vport
7812 * mailbox command. If the new vport mailbox command completes successfully,
7813 * the fabric registration login shall be performed on physical port (the
7814 * new vport created is actually a physical port, with VPI 0) or the port
7815 * login to Name Server for State Change Request (SCR) will be performed
7816 * on virtual port (real virtual port, with VPI greater than 0).
7819 lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
7821 struct lpfc_vport *vport = pmb->vport;
7822 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7823 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
7824 MAILBOX_t *mb = &pmb->u.mb;
7827 spin_lock_irq(shost->host_lock);
7828 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
7829 spin_unlock_irq(shost->host_lock);
7831 if (mb->mbxStatus) {
7832 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
7833 "0915 Register VPI failed : Status: x%x"
7834 " upd bit: x%x \n", mb->mbxStatus,
7835 mb->un.varRegVpi.upd);
7836 if (phba->sli_rev == LPFC_SLI_REV4 &&
7837 mb->un.varRegVpi.upd)
7838 goto mbox_err_exit ;
7840 switch (mb->mbxStatus) {
7841 case 0x11: /* unsupported feature */
7842 case 0x9603: /* max_vpi exceeded */
7843 case 0x9602: /* Link event since CLEAR_LA */
7844 /* giving up on vport registration */
7845 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
7846 spin_lock_irq(shost->host_lock);
7847 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
7848 spin_unlock_irq(shost->host_lock);
7849 lpfc_can_disctmo(vport);
7851 /* If reg_vpi fail with invalid VPI status, re-init VPI */
7853 spin_lock_irq(shost->host_lock);
7854 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
7855 spin_unlock_irq(shost->host_lock);
7856 lpfc_init_vpi(phba, pmb, vport->vpi);
7858 pmb->mbox_cmpl = lpfc_init_vpi_cmpl;
7859 rc = lpfc_sli_issue_mbox(phba, pmb,
7861 if (rc == MBX_NOT_FINISHED) {
7862 lpfc_printf_vlog(vport,
7864 "2732 Failed to issue INIT_VPI"
7865 " mailbox command\n");
7872 /* Try to recover from this error */
7873 if (phba->sli_rev == LPFC_SLI_REV4)
7874 lpfc_sli4_unreg_all_rpis(vport);
7875 lpfc_mbx_unreg_vpi(vport);
7876 spin_lock_irq(shost->host_lock);
7877 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
7878 spin_unlock_irq(shost->host_lock);
7879 if (vport->port_type == LPFC_PHYSICAL_PORT
7880 && !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG))
7881 lpfc_issue_init_vfi(vport);
7883 lpfc_initial_fdisc(vport);
7887 spin_lock_irq(shost->host_lock);
7888 vport->vpi_state |= LPFC_VPI_REGISTERED;
7889 spin_unlock_irq(shost->host_lock);
7890 if (vport == phba->pport) {
7891 if (phba->sli_rev < LPFC_SLI_REV4)
7892 lpfc_issue_fabric_reglogin(vport);
7895 * If the physical port is instantiated using
7896 * FDISC, do not start vport discovery.
7898 if (vport->port_state != LPFC_FDISC)
7899 lpfc_start_fdiscs(phba);
7900 lpfc_do_scr_ns_plogi(phba, vport);
7903 lpfc_do_scr_ns_plogi(phba, vport);
7906 /* Now, we decrement the ndlp reference count held for this
7911 mempool_free(pmb, phba->mbox_mem_pool);
7916 * lpfc_register_new_vport - Register a new vport with a HBA
7917 * @phba: pointer to lpfc hba data structure.
7918 * @vport: pointer to a host virtual N_Port data structure.
7919 * @ndlp: pointer to a node-list data structure.
7921 * This routine registers the @vport as a new virtual port with a HBA.
7922 * It is done through a registering vpi mailbox command.
7925 lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
7926 struct lpfc_nodelist *ndlp)
7928 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7931 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
7933 lpfc_reg_vpi(vport, mbox);
7934 mbox->vport = vport;
7935 mbox->context2 = lpfc_nlp_get(ndlp);
7936 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
7937 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
7938 == MBX_NOT_FINISHED) {
7939 /* mailbox command not success, decrement ndlp
7940 * reference count for this command
7943 mempool_free(mbox, phba->mbox_mem_pool);
7945 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
7946 "0253 Register VPI: Can't send mbox\n");
7950 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
7951 "0254 Register VPI: no memory\n");
7957 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
7958 spin_lock_irq(shost->host_lock);
7959 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
7960 spin_unlock_irq(shost->host_lock);
7965 * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer
7966 * @phba: pointer to lpfc hba data structure.
7968 * This routine cancels the retry delay timers to all the vports.
7971 lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba)
7973 struct lpfc_vport **vports;
7974 struct lpfc_nodelist *ndlp;
7975 uint32_t link_state;
7978 /* Treat this failure as linkdown for all vports */
7979 link_state = phba->link_state;
7980 lpfc_linkdown(phba);
7981 phba->link_state = link_state;
7983 vports = lpfc_create_vport_work_array(phba);
7986 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
7987 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
7989 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
7990 lpfc_els_flush_cmd(vports[i]);
7992 lpfc_destroy_vport_work_array(phba, vports);
7997 * lpfc_retry_pport_discovery - Start timer to retry FLOGI.
7998 * @phba: pointer to lpfc hba data structure.
8000 * This routine abort all pending discovery commands and
8001 * start a timer to retry FLOGI for the physical port
8005 lpfc_retry_pport_discovery(struct lpfc_hba *phba)
8007 struct lpfc_nodelist *ndlp;
8008 struct Scsi_Host *shost;
8010 /* Cancel the all vports retry delay retry timers */
8011 lpfc_cancel_all_vport_retry_delay_timer(phba);
8013 /* If fabric require FLOGI, then re-instantiate physical login */
8014 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
8018 shost = lpfc_shost_from_vport(phba->pport);
8019 mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000));
8020 spin_lock_irq(shost->host_lock);
8021 ndlp->nlp_flag |= NLP_DELAY_TMO;
8022 spin_unlock_irq(shost->host_lock);
8023 ndlp->nlp_last_elscmd = ELS_CMD_FLOGI;
8024 phba->pport->port_state = LPFC_FLOGI;
8029 * lpfc_fabric_login_reqd - Check if FLOGI required.
8030 * @phba: pointer to lpfc hba data structure.
8031 * @cmdiocb: pointer to FDISC command iocb.
8032 * @rspiocb: pointer to FDISC response iocb.
8034 * This routine checks if a FLOGI is reguired for FDISC
8038 lpfc_fabric_login_reqd(struct lpfc_hba *phba,
8039 struct lpfc_iocbq *cmdiocb,
8040 struct lpfc_iocbq *rspiocb)
8043 if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) ||
8044 (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED))
8051 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
8052 * @phba: pointer to lpfc hba data structure.
8053 * @cmdiocb: pointer to lpfc command iocb data structure.
8054 * @rspiocb: pointer to lpfc response iocb data structure.
8056 * This routine is the completion callback function to a Fabric Discover
8057 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
8058 * single threaded, each FDISC completion callback function will reset
8059 * the discovery timer for all vports such that the timers will not get
8060 * unnecessary timeout. The function checks the FDISC IOCB status. If error
8061 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
8062 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
8063 * assigned to the vport has been changed with the completion of the FDISC
8064 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
8065 * are unregistered from the HBA, and then the lpfc_register_new_vport()
8066 * routine is invoked to register new vport with the HBA. Otherwise, the
8067 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
8068 * Server for State Change Request (SCR).
8071 lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
8072 struct lpfc_iocbq *rspiocb)
8074 struct lpfc_vport *vport = cmdiocb->vport;
8075 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8076 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
8077 struct lpfc_nodelist *np;
8078 struct lpfc_nodelist *next_np;
8079 IOCB_t *irsp = &rspiocb->iocb;
8080 struct lpfc_iocbq *piocb;
8081 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
8082 struct serv_parm *sp;
8083 uint8_t fabric_param_changed;
8085 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
8086 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
8087 irsp->ulpStatus, irsp->un.ulpWord[4],
8089 /* Since all FDISCs are being single threaded, we
8090 * must reset the discovery timer for ALL vports
8091 * waiting to send FDISC when one completes.
8093 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
8094 lpfc_set_disctmo(piocb->vport);
8097 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
8098 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
8099 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
8101 if (irsp->ulpStatus) {
8103 if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) {
8104 lpfc_retry_pport_discovery(phba);
8108 /* Check for retry */
8109 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
8112 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8113 "0126 FDISC failed. (x%x/x%x)\n",
8114 irsp->ulpStatus, irsp->un.ulpWord[4]);
8117 spin_lock_irq(shost->host_lock);
8118 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
8119 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
8120 vport->fc_flag |= FC_FABRIC;
8121 if (vport->phba->fc_topology == LPFC_TOPOLOGY_LOOP)
8122 vport->fc_flag |= FC_PUBLIC_LOOP;
8123 spin_unlock_irq(shost->host_lock);
8125 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
8126 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
8127 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
8130 sp = prsp->virt + sizeof(uint32_t);
8131 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
8132 memcpy(&vport->fabric_portname, &sp->portName,
8133 sizeof(struct lpfc_name));
8134 memcpy(&vport->fabric_nodename, &sp->nodeName,
8135 sizeof(struct lpfc_name));
8136 if (fabric_param_changed &&
8137 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
8138 /* If our NportID changed, we need to ensure all
8139 * remaining NPORTs get unreg_login'ed so we can
8142 list_for_each_entry_safe(np, next_np,
8143 &vport->fc_nodes, nlp_listp) {
8144 if (!NLP_CHK_NODE_ACT(ndlp) ||
8145 (np->nlp_state != NLP_STE_NPR_NODE) ||
8146 !(np->nlp_flag & NLP_NPR_ADISC))
8148 spin_lock_irq(shost->host_lock);
8149 np->nlp_flag &= ~NLP_NPR_ADISC;
8150 spin_unlock_irq(shost->host_lock);
8151 lpfc_unreg_rpi(vport, np);
8153 lpfc_cleanup_pending_mbox(vport);
8155 if (phba->sli_rev == LPFC_SLI_REV4)
8156 lpfc_sli4_unreg_all_rpis(vport);
8158 lpfc_mbx_unreg_vpi(vport);
8159 spin_lock_irq(shost->host_lock);
8160 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
8161 if (phba->sli_rev == LPFC_SLI_REV4)
8162 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
8164 vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG;
8165 spin_unlock_irq(shost->host_lock);
8166 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
8167 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
8169 * Driver needs to re-reg VPI in order for f/w
8170 * to update the MAC address.
8172 lpfc_register_new_vport(phba, vport, ndlp);
8176 if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)
8177 lpfc_issue_init_vpi(vport);
8178 else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
8179 lpfc_register_new_vport(phba, vport, ndlp);
8181 lpfc_do_scr_ns_plogi(phba, vport);
8184 if (vport->fc_vport->vport_state != FC_VPORT_NO_FABRIC_RSCS)
8185 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
8186 /* Cancel discovery timer */
8187 lpfc_can_disctmo(vport);
8190 lpfc_els_free_iocb(phba, cmdiocb);
8194 * lpfc_issue_els_fdisc - Issue a fdisc iocb command
8195 * @vport: pointer to a virtual N_Port data structure.
8196 * @ndlp: pointer to a node-list data structure.
8197 * @retry: number of retries to the command IOCB.
8199 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
8200 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
8201 * routine to issue the IOCB, which makes sure only one outstanding fabric
8202 * IOCB will be sent off HBA at any given time.
8204 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
8205 * will be incremented by 1 for holding the ndlp and the reference to ndlp
8206 * will be stored into the context1 field of the IOCB for the completion
8207 * callback function to the FDISC ELS command.
8210 * 0 - Successfully issued fdisc iocb command
8211 * 1 - Failed to issue fdisc iocb command
8214 lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
8217 struct lpfc_hba *phba = vport->phba;
8219 struct lpfc_iocbq *elsiocb;
8220 struct serv_parm *sp;
8223 int did = ndlp->nlp_DID;
8226 vport->port_state = LPFC_FDISC;
8227 vport->fc_myDID = 0;
8228 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
8229 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
8232 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
8233 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8234 "0255 Issue FDISC: no IOCB\n");
8238 icmd = &elsiocb->iocb;
8239 icmd->un.elsreq64.myID = 0;
8240 icmd->un.elsreq64.fl = 1;
8243 * SLI3 ports require a different context type value than SLI4.
8244 * Catch SLI3 ports here and override the prep.
8246 if (phba->sli_rev == LPFC_SLI_REV3) {
8251 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
8252 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
8253 pcmd += sizeof(uint32_t); /* CSP Word 1 */
8254 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
8255 sp = (struct serv_parm *) pcmd;
8256 /* Setup CSPs accordingly for Fabric */
8257 sp->cmn.e_d_tov = 0;
8258 sp->cmn.w2.r_a_tov = 0;
8259 sp->cmn.virtual_fabric_support = 0;
8260 sp->cls1.classValid = 0;
8261 sp->cls2.seqDelivery = 1;
8262 sp->cls3.seqDelivery = 1;
8264 pcmd += sizeof(uint32_t); /* CSP Word 2 */
8265 pcmd += sizeof(uint32_t); /* CSP Word 3 */
8266 pcmd += sizeof(uint32_t); /* CSP Word 4 */
8267 pcmd += sizeof(uint32_t); /* Port Name */
8268 memcpy(pcmd, &vport->fc_portname, 8);
8269 pcmd += sizeof(uint32_t); /* Node Name */
8270 pcmd += sizeof(uint32_t); /* Node Name */
8271 memcpy(pcmd, &vport->fc_nodename, 8);
8273 lpfc_set_disctmo(vport);
8275 phba->fc_stat.elsXmitFDISC++;
8276 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
8278 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
8279 "Issue FDISC: did:x%x",
8282 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
8283 if (rc == IOCB_ERROR) {
8284 lpfc_els_free_iocb(phba, elsiocb);
8285 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
8286 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8287 "0256 Issue FDISC: Cannot send IOCB\n");
8290 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
8295 * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
8296 * @phba: pointer to lpfc hba data structure.
8297 * @cmdiocb: pointer to lpfc command iocb data structure.
8298 * @rspiocb: pointer to lpfc response iocb data structure.
8300 * This routine is the completion callback function to the issuing of a LOGO
8301 * ELS command off a vport. It frees the command IOCB and then decrement the
8302 * reference count held on ndlp for this completion function, indicating that
8303 * the reference to the ndlp is no long needed. Note that the
8304 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
8305 * callback function and an additional explicit ndlp reference decrementation
8306 * will trigger the actual release of the ndlp.
8309 lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
8310 struct lpfc_iocbq *rspiocb)
8312 struct lpfc_vport *vport = cmdiocb->vport;
8314 struct lpfc_nodelist *ndlp;
8315 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8317 ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
8318 irsp = &rspiocb->iocb;
8319 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
8320 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
8321 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
8323 lpfc_els_free_iocb(phba, cmdiocb);
8324 vport->unreg_vpi_cmpl = VPORT_ERROR;
8326 /* Trigger the release of the ndlp after logo */
8329 /* NPIV LOGO completes to NPort <nlp_DID> */
8330 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
8331 "2928 NPIV LOGO completes to NPort x%x "
8332 "Data: x%x x%x x%x x%x\n",
8333 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
8334 irsp->ulpTimeout, vport->num_disc_nodes);
8336 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
8337 spin_lock_irq(shost->host_lock);
8338 vport->fc_flag &= ~FC_NDISC_ACTIVE;
8339 vport->fc_flag &= ~FC_FABRIC;
8340 spin_unlock_irq(shost->host_lock);
8341 lpfc_can_disctmo(vport);
8346 * lpfc_issue_els_npiv_logo - Issue a logo off a vport
8347 * @vport: pointer to a virtual N_Port data structure.
8348 * @ndlp: pointer to a node-list data structure.
8350 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
8352 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
8353 * will be incremented by 1 for holding the ndlp and the reference to ndlp
8354 * will be stored into the context1 field of the IOCB for the completion
8355 * callback function to the LOGO ELS command.
8358 * 0 - Successfully issued logo off the @vport
8359 * 1 - Failed to issue logo off the @vport
8362 lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
8364 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8365 struct lpfc_hba *phba = vport->phba;
8366 struct lpfc_iocbq *elsiocb;
8370 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
8371 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
8376 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
8377 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
8378 pcmd += sizeof(uint32_t);
8380 /* Fill in LOGO payload */
8381 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
8382 pcmd += sizeof(uint32_t);
8383 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
8385 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
8386 "Issue LOGO npiv did:x%x flg:x%x",
8387 ndlp->nlp_DID, ndlp->nlp_flag, 0);
8389 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
8390 spin_lock_irq(shost->host_lock);
8391 ndlp->nlp_flag |= NLP_LOGO_SND;
8392 spin_unlock_irq(shost->host_lock);
8393 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
8395 spin_lock_irq(shost->host_lock);
8396 ndlp->nlp_flag &= ~NLP_LOGO_SND;
8397 spin_unlock_irq(shost->host_lock);
8398 lpfc_els_free_iocb(phba, elsiocb);
8405 * lpfc_fabric_block_timeout - Handler function to the fabric block timer
8406 * @ptr: holder for the timer function associated data.
8408 * This routine is invoked by the fabric iocb block timer after
8409 * timeout. It posts the fabric iocb block timeout event by setting the
8410 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
8411 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
8412 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
8413 * posted event WORKER_FABRIC_BLOCK_TMO.
8416 lpfc_fabric_block_timeout(unsigned long ptr)
8418 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
8419 unsigned long iflags;
8420 uint32_t tmo_posted;
8422 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
8423 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
8425 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
8426 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
8429 lpfc_worker_wake_up(phba);
8434 * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
8435 * @phba: pointer to lpfc hba data structure.
8437 * This routine issues one fabric iocb from the driver internal list to
8438 * the HBA. It first checks whether it's ready to issue one fabric iocb to
8439 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
8440 * remove one pending fabric iocb from the driver internal list and invokes
8441 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
8444 lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
8446 struct lpfc_iocbq *iocb;
8447 unsigned long iflags;
8453 spin_lock_irqsave(&phba->hbalock, iflags);
8454 /* Post any pending iocb to the SLI layer */
8455 if (atomic_read(&phba->fabric_iocb_count) == 0) {
8456 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
8459 /* Increment fabric iocb count to hold the position */
8460 atomic_inc(&phba->fabric_iocb_count);
8462 spin_unlock_irqrestore(&phba->hbalock, iflags);
8464 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
8465 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
8466 iocb->iocb_flag |= LPFC_IO_FABRIC;
8468 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
8469 "Fabric sched1: ste:x%x",
8470 iocb->vport->port_state, 0, 0);
8472 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
8474 if (ret == IOCB_ERROR) {
8475 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
8476 iocb->fabric_iocb_cmpl = NULL;
8477 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
8479 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
8480 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
8481 iocb->iocb_cmpl(phba, iocb, iocb);
8483 atomic_dec(&phba->fabric_iocb_count);
8492 * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
8493 * @phba: pointer to lpfc hba data structure.
8495 * This routine unblocks the issuing fabric iocb command. The function
8496 * will clear the fabric iocb block bit and then invoke the routine
8497 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
8498 * from the driver internal fabric iocb list.
8501 lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
8503 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
8505 lpfc_resume_fabric_iocbs(phba);
8510 * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
8511 * @phba: pointer to lpfc hba data structure.
8513 * This routine blocks the issuing fabric iocb for a specified amount of
8514 * time (currently 100 ms). This is done by set the fabric iocb block bit
8515 * and set up a timeout timer for 100ms. When the block bit is set, no more
8516 * fabric iocb will be issued out of the HBA.
8519 lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
8523 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
8524 /* Start a timer to unblock fabric iocbs after 100ms */
8526 mod_timer(&phba->fabric_block_timer,
8527 jiffies + msecs_to_jiffies(100));
8533 * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
8534 * @phba: pointer to lpfc hba data structure.
8535 * @cmdiocb: pointer to lpfc command iocb data structure.
8536 * @rspiocb: pointer to lpfc response iocb data structure.
8538 * This routine is the callback function that is put to the fabric iocb's
8539 * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
8540 * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
8541 * function first restores and invokes the original iocb's callback function
8542 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
8543 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
8546 lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
8547 struct lpfc_iocbq *rspiocb)
8551 if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC)
8554 switch (rspiocb->iocb.ulpStatus) {
8555 case IOSTAT_NPORT_RJT:
8556 case IOSTAT_FABRIC_RJT:
8557 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
8558 lpfc_block_fabric_iocbs(phba);
8562 case IOSTAT_NPORT_BSY:
8563 case IOSTAT_FABRIC_BSY:
8564 lpfc_block_fabric_iocbs(phba);
8568 stat.un.lsRjtError =
8569 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
8570 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
8571 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
8572 lpfc_block_fabric_iocbs(phba);
8576 if (atomic_read(&phba->fabric_iocb_count) == 0)
8579 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
8580 cmdiocb->fabric_iocb_cmpl = NULL;
8581 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
8582 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
8584 atomic_dec(&phba->fabric_iocb_count);
8585 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
8586 /* Post any pending iocbs to HBA */
8587 lpfc_resume_fabric_iocbs(phba);
8592 * lpfc_issue_fabric_iocb - Issue a fabric iocb command
8593 * @phba: pointer to lpfc hba data structure.
8594 * @iocb: pointer to lpfc command iocb data structure.
8596 * This routine is used as the top-level API for issuing a fabric iocb command
8597 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
8598 * function makes sure that only one fabric bound iocb will be outstanding at
8599 * any given time. As such, this function will first check to see whether there
8600 * is already an outstanding fabric iocb on the wire. If so, it will put the
8601 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
8602 * issued later. Otherwise, it will issue the iocb on the wire and update the
8603 * fabric iocb count it indicate that there is one fabric iocb on the wire.
8605 * Note, this implementation has a potential sending out fabric IOCBs out of
8606 * order. The problem is caused by the construction of the "ready" boolen does
8607 * not include the condition that the internal fabric IOCB list is empty. As
8608 * such, it is possible a fabric IOCB issued by this routine might be "jump"
8609 * ahead of the fabric IOCBs in the internal list.
8612 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
8613 * IOCB_ERROR - failed to issue fabric iocb
8616 lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
8618 unsigned long iflags;
8622 if (atomic_read(&phba->fabric_iocb_count) > 1)
8625 spin_lock_irqsave(&phba->hbalock, iflags);
8626 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
8627 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
8630 /* Increment fabric iocb count to hold the position */
8631 atomic_inc(&phba->fabric_iocb_count);
8632 spin_unlock_irqrestore(&phba->hbalock, iflags);
8634 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
8635 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
8636 iocb->iocb_flag |= LPFC_IO_FABRIC;
8638 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
8639 "Fabric sched2: ste:x%x",
8640 iocb->vport->port_state, 0, 0);
8642 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
8644 if (ret == IOCB_ERROR) {
8645 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
8646 iocb->fabric_iocb_cmpl = NULL;
8647 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
8648 atomic_dec(&phba->fabric_iocb_count);
8651 spin_lock_irqsave(&phba->hbalock, iflags);
8652 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
8653 spin_unlock_irqrestore(&phba->hbalock, iflags);
8660 * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
8661 * @vport: pointer to a virtual N_Port data structure.
8663 * This routine aborts all the IOCBs associated with a @vport from the
8664 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
8665 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
8666 * list, removes each IOCB associated with the @vport off the list, set the
8667 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
8668 * associated with the IOCB.
8670 static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
8672 LIST_HEAD(completions);
8673 struct lpfc_hba *phba = vport->phba;
8674 struct lpfc_iocbq *tmp_iocb, *piocb;
8676 spin_lock_irq(&phba->hbalock);
8677 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
8680 if (piocb->vport != vport)
8683 list_move_tail(&piocb->list, &completions);
8685 spin_unlock_irq(&phba->hbalock);
8687 /* Cancel all the IOCBs from the completions list */
8688 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
8693 * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
8694 * @ndlp: pointer to a node-list data structure.
8696 * This routine aborts all the IOCBs associated with an @ndlp from the
8697 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
8698 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
8699 * list, removes each IOCB associated with the @ndlp off the list, set the
8700 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
8701 * associated with the IOCB.
8703 void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
8705 LIST_HEAD(completions);
8706 struct lpfc_hba *phba = ndlp->phba;
8707 struct lpfc_iocbq *tmp_iocb, *piocb;
8708 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
8710 spin_lock_irq(&phba->hbalock);
8711 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
8713 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
8715 list_move_tail(&piocb->list, &completions);
8718 spin_unlock_irq(&phba->hbalock);
8720 /* Cancel all the IOCBs from the completions list */
8721 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
8726 * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
8727 * @phba: pointer to lpfc hba data structure.
8729 * This routine aborts all the IOCBs currently on the driver internal
8730 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
8731 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
8732 * list, removes IOCBs off the list, set the status feild to
8733 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
8736 void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
8738 LIST_HEAD(completions);
8740 spin_lock_irq(&phba->hbalock);
8741 list_splice_init(&phba->fabric_iocb_list, &completions);
8742 spin_unlock_irq(&phba->hbalock);
8744 /* Cancel all the IOCBs from the completions list */
8745 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
8750 * lpfc_sli4_vport_delete_els_xri_aborted -Remove all ndlp references for vport
8751 * @vport: pointer to lpfc vport data structure.
8753 * This routine is invoked by the vport cleanup for deletions and the cleanup
8754 * for an ndlp on removal.
8757 lpfc_sli4_vport_delete_els_xri_aborted(struct lpfc_vport *vport)
8759 struct lpfc_hba *phba = vport->phba;
8760 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
8761 unsigned long iflag = 0;
8763 spin_lock_irqsave(&phba->hbalock, iflag);
8764 spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
8765 list_for_each_entry_safe(sglq_entry, sglq_next,
8766 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
8767 if (sglq_entry->ndlp && sglq_entry->ndlp->vport == vport)
8768 sglq_entry->ndlp = NULL;
8770 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
8771 spin_unlock_irqrestore(&phba->hbalock, iflag);
8776 * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
8777 * @phba: pointer to lpfc hba data structure.
8778 * @axri: pointer to the els xri abort wcqe structure.
8780 * This routine is invoked by the worker thread to process a SLI4 slow-path
8784 lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba,
8785 struct sli4_wcqe_xri_aborted *axri)
8787 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
8788 uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri);
8791 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
8792 unsigned long iflag = 0;
8793 struct lpfc_nodelist *ndlp;
8794 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
8796 spin_lock_irqsave(&phba->hbalock, iflag);
8797 spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
8798 list_for_each_entry_safe(sglq_entry, sglq_next,
8799 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
8800 if (sglq_entry->sli4_xritag == xri) {
8801 list_del(&sglq_entry->list);
8802 ndlp = sglq_entry->ndlp;
8803 sglq_entry->ndlp = NULL;
8804 spin_lock(&pring->ring_lock);
8805 list_add_tail(&sglq_entry->list,
8806 &phba->sli4_hba.lpfc_sgl_list);
8807 sglq_entry->state = SGL_FREED;
8808 spin_unlock(&pring->ring_lock);
8809 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
8810 spin_unlock_irqrestore(&phba->hbalock, iflag);
8811 lpfc_set_rrq_active(phba, ndlp,
8812 sglq_entry->sli4_lxritag,
8815 /* Check if TXQ queue needs to be serviced */
8816 if (!(list_empty(&pring->txq)))
8817 lpfc_worker_wake_up(phba);
8821 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
8822 lxri = lpfc_sli4_xri_inrange(phba, xri);
8823 if (lxri == NO_XRI) {
8824 spin_unlock_irqrestore(&phba->hbalock, iflag);
8827 spin_lock(&pring->ring_lock);
8828 sglq_entry = __lpfc_get_active_sglq(phba, lxri);
8829 if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) {
8830 spin_unlock(&pring->ring_lock);
8831 spin_unlock_irqrestore(&phba->hbalock, iflag);
8834 sglq_entry->state = SGL_XRI_ABORTED;
8835 spin_unlock(&pring->ring_lock);
8836 spin_unlock_irqrestore(&phba->hbalock, iflag);
8840 /* lpfc_sli_abts_recover_port - Recover a port that failed a BLS_ABORT req.
8841 * @vport: pointer to virtual port object.
8842 * @ndlp: nodelist pointer for the impacted node.
8844 * The driver calls this routine in response to an SLI4 XRI ABORT CQE
8845 * or an SLI3 ASYNC_STATUS_CN event from the port. For either event,
8846 * the driver is required to send a LOGO to the remote node before it
8847 * attempts to recover its login to the remote node.
8850 lpfc_sli_abts_recover_port(struct lpfc_vport *vport,
8851 struct lpfc_nodelist *ndlp)
8853 struct Scsi_Host *shost;
8854 struct lpfc_hba *phba;
8855 unsigned long flags = 0;
8857 shost = lpfc_shost_from_vport(vport);
8859 if (ndlp->nlp_state != NLP_STE_MAPPED_NODE) {
8860 lpfc_printf_log(phba, KERN_INFO,
8861 LOG_SLI, "3093 No rport recovery needed. "
8862 "rport in state 0x%x\n", ndlp->nlp_state);
8865 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
8866 "3094 Start rport recovery on shost id 0x%x "
8867 "fc_id 0x%06x vpi 0x%x rpi 0x%x state 0x%x "
8869 shost->host_no, ndlp->nlp_DID,
8870 vport->vpi, ndlp->nlp_rpi, ndlp->nlp_state,
8873 * The rport is not responding. Remove the FCP-2 flag to prevent
8874 * an ADISC in the follow-up recovery code.
8876 spin_lock_irqsave(shost->host_lock, flags);
8877 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
8878 spin_unlock_irqrestore(shost->host_lock, flags);
8879 lpfc_issue_els_logo(vport, ndlp, 0);
8880 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);