1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2017-2019 Broadcom. All Rights Reserved. The term *
5 * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. *
6 * Copyright (C) 2004-2016 Emulex. All rights reserved. *
7 * EMULEX and SLI are trademarks of Emulex. *
9 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
11 * This program is free software; you can redistribute it and/or *
12 * modify it under the terms of version 2 of the GNU General *
13 * Public License as published by the Free Software Foundation. *
14 * This program is distributed in the hope that it will be useful. *
15 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
16 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
17 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
18 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
19 * TO BE LEGALLY INVALID. See the GNU General Public License for *
20 * more details, a copy of which can be found in the file COPYING *
21 * included with this package. *
22 *******************************************************************/
23 /* See Fibre Channel protocol T11 FC-LS for details */
24 #include <linux/blkdev.h>
25 #include <linux/pci.h>
26 #include <linux/slab.h>
27 #include <linux/interrupt.h>
29 #include <scsi/scsi.h>
30 #include <scsi/scsi_device.h>
31 #include <scsi/scsi_host.h>
32 #include <scsi/scsi_transport_fc.h>
37 #include "lpfc_sli4.h"
39 #include "lpfc_disc.h"
40 #include "lpfc_scsi.h"
42 #include "lpfc_logmsg.h"
43 #include "lpfc_crtn.h"
44 #include "lpfc_vport.h"
45 #include "lpfc_debugfs.h"
47 static int lpfc_els_retry(struct lpfc_hba *, struct lpfc_iocbq *,
49 static void lpfc_cmpl_fabric_iocb(struct lpfc_hba *, struct lpfc_iocbq *,
51 static void lpfc_fabric_abort_vport(struct lpfc_vport *vport);
52 static int lpfc_issue_els_fdisc(struct lpfc_vport *vport,
53 struct lpfc_nodelist *ndlp, uint8_t retry);
54 static int lpfc_issue_fabric_iocb(struct lpfc_hba *phba,
55 struct lpfc_iocbq *iocb);
57 static int lpfc_max_els_tries = 3;
60 * lpfc_els_chk_latt - Check host link attention event for a vport
61 * @vport: pointer to a host virtual N_Port data structure.
63 * This routine checks whether there is an outstanding host link
64 * attention event during the discovery process with the @vport. It is done
65 * by reading the HBA's Host Attention (HA) register. If there is any host
66 * link attention events during this @vport's discovery process, the @vport
67 * shall be marked as FC_ABORT_DISCOVERY, a host link attention clear shall
68 * be issued if the link state is not already in host link cleared state,
69 * and a return code shall indicate whether the host link attention event
72 * Note that, if either the host link is in state LPFC_LINK_DOWN or @vport
73 * state in LPFC_VPORT_READY, the request for checking host link attention
74 * event will be ignored and a return code shall indicate no host link
75 * attention event had happened.
78 * 0 - no host link attention event happened
79 * 1 - host link attention event happened
82 lpfc_els_chk_latt(struct lpfc_vport *vport)
84 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
85 struct lpfc_hba *phba = vport->phba;
88 if (vport->port_state >= LPFC_VPORT_READY ||
89 phba->link_state == LPFC_LINK_DOWN ||
90 phba->sli_rev > LPFC_SLI_REV3)
93 /* Read the HBA Host Attention Register */
94 if (lpfc_readl(phba->HAregaddr, &ha_copy))
97 if (!(ha_copy & HA_LATT))
100 /* Pending Link Event during Discovery */
101 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
102 "0237 Pending Link Event during "
103 "Discovery: State x%x\n",
104 phba->pport->port_state);
106 /* CLEAR_LA should re-enable link attention events and
107 * we should then immediately take a LATT event. The
108 * LATT processing should call lpfc_linkdown() which
109 * will cleanup any left over in-progress discovery
112 spin_lock_irq(shost->host_lock);
113 vport->fc_flag |= FC_ABORT_DISCOVERY;
114 spin_unlock_irq(shost->host_lock);
116 if (phba->link_state != LPFC_CLEAR_LA)
117 lpfc_issue_clear_la(phba, vport);
123 * lpfc_prep_els_iocb - Allocate and prepare a lpfc iocb data structure
124 * @vport: pointer to a host virtual N_Port data structure.
125 * @expectRsp: flag indicating whether response is expected.
126 * @cmdSize: size of the ELS command.
127 * @retry: number of retries to the command IOCB when it fails.
128 * @ndlp: pointer to a node-list data structure.
129 * @did: destination identifier.
130 * @elscmd: the ELS command code.
132 * This routine is used for allocating a lpfc-IOCB data structure from
133 * the driver lpfc-IOCB free-list and prepare the IOCB with the parameters
134 * passed into the routine for discovery state machine to issue an Extended
135 * Link Service (ELS) commands. It is a generic lpfc-IOCB allocation
136 * and preparation routine that is used by all the discovery state machine
137 * routines and the ELS command-specific fields will be later set up by
138 * the individual discovery machine routines after calling this routine
139 * allocating and preparing a generic IOCB data structure. It fills in the
140 * Buffer Descriptor Entries (BDEs), allocates buffers for both command
141 * payload and response payload (if expected). The reference count on the
142 * ndlp is incremented by 1 and the reference to the ndlp is put into
143 * context1 of the IOCB data structure for this IOCB to hold the ndlp
144 * reference for the command's callback function to access later.
147 * Pointer to the newly allocated/prepared els iocb data structure
148 * NULL - when els iocb data structure allocation/preparation failed
151 lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp,
152 uint16_t cmdSize, uint8_t retry,
153 struct lpfc_nodelist *ndlp, uint32_t did,
156 struct lpfc_hba *phba = vport->phba;
157 struct lpfc_iocbq *elsiocb;
158 struct lpfc_dmabuf *pcmd, *prsp, *pbuflist;
159 struct ulp_bde64 *bpl;
163 if (!lpfc_is_link_up(phba))
166 /* Allocate buffer for command iocb */
167 elsiocb = lpfc_sli_get_iocbq(phba);
173 * If this command is for fabric controller and HBA running
174 * in FIP mode send FLOGI, FDISC and LOGO as FIP frames.
176 if ((did == Fabric_DID) &&
177 (phba->hba_flag & HBA_FIP_SUPPORT) &&
178 ((elscmd == ELS_CMD_FLOGI) ||
179 (elscmd == ELS_CMD_FDISC) ||
180 (elscmd == ELS_CMD_LOGO)))
183 elsiocb->iocb_flag |=
184 ((LPFC_ELS_ID_FLOGI << LPFC_FIP_ELS_ID_SHIFT)
185 & LPFC_FIP_ELS_ID_MASK);
188 elsiocb->iocb_flag |=
189 ((LPFC_ELS_ID_FDISC << LPFC_FIP_ELS_ID_SHIFT)
190 & LPFC_FIP_ELS_ID_MASK);
193 elsiocb->iocb_flag |=
194 ((LPFC_ELS_ID_LOGO << LPFC_FIP_ELS_ID_SHIFT)
195 & LPFC_FIP_ELS_ID_MASK);
199 elsiocb->iocb_flag &= ~LPFC_FIP_ELS_ID_MASK;
201 icmd = &elsiocb->iocb;
203 /* fill in BDEs for command */
204 /* Allocate buffer for command payload */
205 pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
207 pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys);
208 if (!pcmd || !pcmd->virt)
209 goto els_iocb_free_pcmb_exit;
211 INIT_LIST_HEAD(&pcmd->list);
213 /* Allocate buffer for response payload */
215 prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
217 prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
219 if (!prsp || !prsp->virt)
220 goto els_iocb_free_prsp_exit;
221 INIT_LIST_HEAD(&prsp->list);
225 /* Allocate buffer for Buffer ptr list */
226 pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
228 pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
230 if (!pbuflist || !pbuflist->virt)
231 goto els_iocb_free_pbuf_exit;
233 INIT_LIST_HEAD(&pbuflist->list);
236 icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
237 icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
238 icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
239 icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64));
241 icmd->un.elsreq64.remoteID = did; /* DID */
242 icmd->ulpCommand = CMD_ELS_REQUEST64_CR;
243 if (elscmd == ELS_CMD_FLOGI)
244 icmd->ulpTimeout = FF_DEF_RATOV * 2;
245 else if (elscmd == ELS_CMD_LOGO)
246 icmd->ulpTimeout = phba->fc_ratov;
248 icmd->ulpTimeout = phba->fc_ratov * 2;
250 icmd->un.xseq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
251 icmd->un.xseq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
252 icmd->un.xseq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
253 icmd->un.xseq64.bdl.bdeSize = sizeof(struct ulp_bde64);
254 icmd->un.xseq64.xmit_els_remoteID = did; /* DID */
255 icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX;
257 icmd->ulpBdeCount = 1;
259 icmd->ulpClass = CLASS3;
262 * If we have NPIV enabled, we want to send ELS traffic by VPI.
263 * For SLI4, since the driver controls VPIs we also want to include
264 * all ELS pt2pt protocol traffic as well.
266 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) ||
267 ((phba->sli_rev == LPFC_SLI_REV4) &&
268 (vport->fc_flag & FC_PT2PT))) {
271 icmd->un.elsreq64.myID = vport->fc_myDID;
273 /* For ELS_REQUEST64_CR, use the VPI by default */
274 icmd->ulpContext = phba->vpi_ids[vport->vpi];
278 /* The CT field must be 0=INVALID_RPI for the ECHO cmd */
279 if (elscmd == ELS_CMD_ECHO)
280 icmd->ulpCt_l = 0; /* context = invalid RPI */
282 icmd->ulpCt_l = 1; /* context = VPI */
285 bpl = (struct ulp_bde64 *) pbuflist->virt;
286 bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys));
287 bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys));
288 bpl->tus.f.bdeSize = cmdSize;
289 bpl->tus.f.bdeFlags = 0;
290 bpl->tus.w = le32_to_cpu(bpl->tus.w);
294 bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys));
295 bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys));
296 bpl->tus.f.bdeSize = FCELSSIZE;
297 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
298 bpl->tus.w = le32_to_cpu(bpl->tus.w);
301 /* prevent preparing iocb with NULL ndlp reference */
302 elsiocb->context1 = lpfc_nlp_get(ndlp);
303 if (!elsiocb->context1)
304 goto els_iocb_free_pbuf_exit;
305 elsiocb->context2 = pcmd;
306 elsiocb->context3 = pbuflist;
307 elsiocb->retry = retry;
308 elsiocb->vport = vport;
309 elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT;
312 list_add(&prsp->list, &pcmd->list);
315 /* Xmit ELS command <elsCmd> to remote NPORT <did> */
316 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
317 "0116 Xmit ELS command x%x to remote "
318 "NPORT x%x I/O tag: x%x, port state:x%x "
319 "rpi x%x fc_flag:x%x\n",
320 elscmd, did, elsiocb->iotag,
321 vport->port_state, ndlp->nlp_rpi,
324 /* Xmit ELS response <elsCmd> to remote NPORT <did> */
325 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
326 "0117 Xmit ELS response x%x to remote "
327 "NPORT x%x I/O tag: x%x, size: x%x "
328 "port_state x%x rpi x%x fc_flag x%x\n",
329 elscmd, ndlp->nlp_DID, elsiocb->iotag,
330 cmdSize, vport->port_state,
331 ndlp->nlp_rpi, vport->fc_flag);
335 els_iocb_free_pbuf_exit:
337 lpfc_mbuf_free(phba, prsp->virt, prsp->phys);
340 els_iocb_free_prsp_exit:
341 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
344 els_iocb_free_pcmb_exit:
346 lpfc_sli_release_iocbq(phba, elsiocb);
351 * lpfc_issue_fabric_reglogin - Issue fabric registration login for a vport
352 * @vport: pointer to a host virtual N_Port data structure.
354 * This routine issues a fabric registration login for a @vport. An
355 * active ndlp node with Fabric_DID must already exist for this @vport.
356 * The routine invokes two mailbox commands to carry out fabric registration
357 * login through the HBA firmware: the first mailbox command requests the
358 * HBA to perform link configuration for the @vport; and the second mailbox
359 * command requests the HBA to perform the actual fabric registration login
363 * 0 - successfully issued fabric registration login for @vport
364 * -ENXIO -- failed to issue fabric registration login for @vport
367 lpfc_issue_fabric_reglogin(struct lpfc_vport *vport)
369 struct lpfc_hba *phba = vport->phba;
371 struct lpfc_dmabuf *mp;
372 struct lpfc_nodelist *ndlp;
373 struct serv_parm *sp;
377 sp = &phba->fc_fabparam;
378 ndlp = lpfc_findnode_did(vport, Fabric_DID);
379 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
384 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
390 vport->port_state = LPFC_FABRIC_CFG_LINK;
391 lpfc_config_link(phba, mbox);
392 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
395 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
396 if (rc == MBX_NOT_FINISHED) {
401 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
406 rc = lpfc_reg_rpi(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox,
413 mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login;
415 /* increment the reference count on ndlp to hold reference
416 * for the callback routine.
418 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
420 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
421 if (rc == MBX_NOT_FINISHED) {
423 goto fail_issue_reg_login;
428 fail_issue_reg_login:
429 /* decrement the reference count on ndlp just incremented
430 * for the failed mbox command.
433 mp = (struct lpfc_dmabuf *)mbox->ctx_buf;
434 lpfc_mbuf_free(phba, mp->virt, mp->phys);
437 mempool_free(mbox, phba->mbox_mem_pool);
440 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
441 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
442 "0249 Cannot issue Register Fabric login: Err %d\n", err);
447 * lpfc_issue_reg_vfi - Register VFI for this vport's fabric login
448 * @vport: pointer to a host virtual N_Port data structure.
450 * This routine issues a REG_VFI mailbox for the vfi, vpi, fcfi triplet for
451 * the @vport. This mailbox command is necessary for SLI4 port only.
454 * 0 - successfully issued REG_VFI for @vport
455 * A failure code otherwise.
458 lpfc_issue_reg_vfi(struct lpfc_vport *vport)
460 struct lpfc_hba *phba = vport->phba;
461 LPFC_MBOXQ_t *mboxq = NULL;
462 struct lpfc_nodelist *ndlp;
463 struct lpfc_dmabuf *dmabuf = NULL;
466 /* move forward in case of SLI4 FC port loopback test and pt2pt mode */
467 if ((phba->sli_rev == LPFC_SLI_REV4) &&
468 !(phba->link_flag & LS_LOOPBACK_MODE) &&
469 !(vport->fc_flag & FC_PT2PT)) {
470 ndlp = lpfc_findnode_did(vport, Fabric_DID);
471 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
477 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
483 /* Supply CSP's only if we are fabric connect or pt-to-pt connect */
484 if ((vport->fc_flag & FC_FABRIC) || (vport->fc_flag & FC_PT2PT)) {
485 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
490 dmabuf->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &dmabuf->phys);
495 memcpy(dmabuf->virt, &phba->fc_fabparam,
496 sizeof(struct serv_parm));
499 vport->port_state = LPFC_FABRIC_CFG_LINK;
501 lpfc_reg_vfi(mboxq, vport, dmabuf->phys);
503 lpfc_reg_vfi(mboxq, vport, 0);
505 mboxq->mbox_cmpl = lpfc_mbx_cmpl_reg_vfi;
506 mboxq->vport = vport;
507 mboxq->ctx_buf = dmabuf;
508 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
509 if (rc == MBX_NOT_FINISHED) {
517 mempool_free(mboxq, phba->mbox_mem_pool);
520 lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys);
524 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
525 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
526 "0289 Issue Register VFI failed: Err %d\n", rc);
531 * lpfc_issue_unreg_vfi - Unregister VFI for this vport's fabric login
532 * @vport: pointer to a host virtual N_Port data structure.
534 * This routine issues a UNREG_VFI mailbox with the vfi, vpi, fcfi triplet for
535 * the @vport. This mailbox command is necessary for SLI4 port only.
538 * 0 - successfully issued REG_VFI for @vport
539 * A failure code otherwise.
542 lpfc_issue_unreg_vfi(struct lpfc_vport *vport)
544 struct lpfc_hba *phba = vport->phba;
545 struct Scsi_Host *shost;
549 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
551 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
552 "2556 UNREG_VFI mbox allocation failed"
553 "HBA state x%x\n", phba->pport->port_state);
557 lpfc_unreg_vfi(mboxq, vport);
558 mboxq->vport = vport;
559 mboxq->mbox_cmpl = lpfc_unregister_vfi_cmpl;
561 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
562 if (rc == MBX_NOT_FINISHED) {
563 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
564 "2557 UNREG_VFI issue mbox failed rc x%x "
566 rc, phba->pport->port_state);
567 mempool_free(mboxq, phba->mbox_mem_pool);
571 shost = lpfc_shost_from_vport(vport);
572 spin_lock_irq(shost->host_lock);
573 vport->fc_flag &= ~FC_VFI_REGISTERED;
574 spin_unlock_irq(shost->host_lock);
579 * lpfc_check_clean_addr_bit - Check whether assigned FCID is clean.
580 * @vport: pointer to a host virtual N_Port data structure.
581 * @sp: pointer to service parameter data structure.
583 * This routine is called from FLOGI/FDISC completion handler functions.
584 * lpfc_check_clean_addr_bit return 1 when FCID/Fabric portname/ Fabric
585 * node nodename is changed in the completion service parameter else return
586 * 0. This function also set flag in the vport data structure to delay
587 * NP_Port discovery after the FLOGI/FDISC completion if Clean address bit
588 * in FLOGI/FDISC response is cleared and FCID/Fabric portname/ Fabric
589 * node nodename is changed in the completion service parameter.
592 * 0 - FCID and Fabric Nodename and Fabric portname is not changed.
593 * 1 - FCID or Fabric Nodename or Fabric portname is changed.
597 lpfc_check_clean_addr_bit(struct lpfc_vport *vport,
598 struct serv_parm *sp)
600 struct lpfc_hba *phba = vport->phba;
601 uint8_t fabric_param_changed = 0;
602 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
604 if ((vport->fc_prevDID != vport->fc_myDID) ||
605 memcmp(&vport->fabric_portname, &sp->portName,
606 sizeof(struct lpfc_name)) ||
607 memcmp(&vport->fabric_nodename, &sp->nodeName,
608 sizeof(struct lpfc_name)) ||
609 (vport->vport_flag & FAWWPN_PARAM_CHG)) {
610 fabric_param_changed = 1;
611 vport->vport_flag &= ~FAWWPN_PARAM_CHG;
614 * Word 1 Bit 31 in common service parameter is overloaded.
615 * Word 1 Bit 31 in FLOGI request is multiple NPort request
616 * Word 1 Bit 31 in FLOGI response is clean address bit
618 * If fabric parameter is changed and clean address bit is
619 * cleared delay nport discovery if
620 * - vport->fc_prevDID != 0 (not initial discovery) OR
621 * - lpfc_delay_discovery module parameter is set.
623 if (fabric_param_changed && !sp->cmn.clean_address_bit &&
624 (vport->fc_prevDID || phba->cfg_delay_discovery)) {
625 spin_lock_irq(shost->host_lock);
626 vport->fc_flag |= FC_DISC_DELAYED;
627 spin_unlock_irq(shost->host_lock);
630 return fabric_param_changed;
635 * lpfc_cmpl_els_flogi_fabric - Completion function for flogi to a fabric port
636 * @vport: pointer to a host virtual N_Port data structure.
637 * @ndlp: pointer to a node-list data structure.
638 * @sp: pointer to service parameter data structure.
639 * @irsp: pointer to the IOCB within the lpfc response IOCB.
641 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
642 * function to handle the completion of a Fabric Login (FLOGI) into a fabric
643 * port in a fabric topology. It properly sets up the parameters to the @ndlp
644 * from the IOCB response. It also check the newly assigned N_Port ID to the
645 * @vport against the previously assigned N_Port ID. If it is different from
646 * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine
647 * is invoked on all the remaining nodes with the @vport to unregister the
648 * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin()
649 * is invoked to register login to the fabric.
652 * 0 - Success (currently, always return 0)
655 lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
656 struct serv_parm *sp, IOCB_t *irsp)
658 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
659 struct lpfc_hba *phba = vport->phba;
660 struct lpfc_nodelist *np;
661 struct lpfc_nodelist *next_np;
662 uint8_t fabric_param_changed;
664 spin_lock_irq(shost->host_lock);
665 vport->fc_flag |= FC_FABRIC;
666 spin_unlock_irq(shost->host_lock);
668 phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
669 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
670 phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
672 phba->fc_edtovResol = sp->cmn.edtovResolution;
673 phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
675 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
676 spin_lock_irq(shost->host_lock);
677 vport->fc_flag |= FC_PUBLIC_LOOP;
678 spin_unlock_irq(shost->host_lock);
681 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
682 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
683 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name));
684 ndlp->nlp_class_sup = 0;
685 if (sp->cls1.classValid)
686 ndlp->nlp_class_sup |= FC_COS_CLASS1;
687 if (sp->cls2.classValid)
688 ndlp->nlp_class_sup |= FC_COS_CLASS2;
689 if (sp->cls3.classValid)
690 ndlp->nlp_class_sup |= FC_COS_CLASS3;
691 if (sp->cls4.classValid)
692 ndlp->nlp_class_sup |= FC_COS_CLASS4;
693 ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
694 sp->cmn.bbRcvSizeLsb;
696 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
697 if (fabric_param_changed) {
698 /* Reset FDMI attribute masks based on config parameter */
699 if (phba->cfg_enable_SmartSAN ||
700 (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) {
701 /* Setup appropriate attribute masks */
702 vport->fdmi_hba_mask = LPFC_FDMI2_HBA_ATTR;
703 if (phba->cfg_enable_SmartSAN)
704 vport->fdmi_port_mask = LPFC_FDMI2_SMART_ATTR;
706 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
708 vport->fdmi_hba_mask = 0;
709 vport->fdmi_port_mask = 0;
713 memcpy(&vport->fabric_portname, &sp->portName,
714 sizeof(struct lpfc_name));
715 memcpy(&vport->fabric_nodename, &sp->nodeName,
716 sizeof(struct lpfc_name));
717 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
719 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
720 if (sp->cmn.response_multiple_NPort) {
721 lpfc_printf_vlog(vport, KERN_WARNING,
723 "1816 FLOGI NPIV supported, "
724 "response data 0x%x\n",
725 sp->cmn.response_multiple_NPort);
726 spin_lock_irq(&phba->hbalock);
727 phba->link_flag |= LS_NPIV_FAB_SUPPORTED;
728 spin_unlock_irq(&phba->hbalock);
730 /* Because we asked f/w for NPIV it still expects us
731 to call reg_vnpid atleast for the physcial host */
732 lpfc_printf_vlog(vport, KERN_WARNING,
734 "1817 Fabric does not support NPIV "
735 "- configuring single port mode.\n");
736 spin_lock_irq(&phba->hbalock);
737 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
738 spin_unlock_irq(&phba->hbalock);
743 * For FC we need to do some special processing because of the SLI
744 * Port's default settings of the Common Service Parameters.
746 if ((phba->sli_rev == LPFC_SLI_REV4) &&
747 (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC)) {
748 /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */
749 if (fabric_param_changed)
750 lpfc_unregister_fcf_prep(phba);
752 /* This should just update the VFI CSPs*/
753 if (vport->fc_flag & FC_VFI_REGISTERED)
754 lpfc_issue_reg_vfi(vport);
757 if (fabric_param_changed &&
758 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
760 /* If our NportID changed, we need to ensure all
761 * remaining NPORTs get unreg_login'ed.
763 list_for_each_entry_safe(np, next_np,
764 &vport->fc_nodes, nlp_listp) {
765 if (!NLP_CHK_NODE_ACT(np))
767 if ((np->nlp_state != NLP_STE_NPR_NODE) ||
768 !(np->nlp_flag & NLP_NPR_ADISC))
770 spin_lock_irq(shost->host_lock);
771 np->nlp_flag &= ~NLP_NPR_ADISC;
772 spin_unlock_irq(shost->host_lock);
773 lpfc_unreg_rpi(vport, np);
775 lpfc_cleanup_pending_mbox(vport);
777 if (phba->sli_rev == LPFC_SLI_REV4) {
778 lpfc_sli4_unreg_all_rpis(vport);
779 lpfc_mbx_unreg_vpi(vport);
780 spin_lock_irq(shost->host_lock);
781 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
782 spin_unlock_irq(shost->host_lock);
786 * For SLI3 and SLI4, the VPI needs to be reregistered in
787 * response to this fabric parameter change event.
789 spin_lock_irq(shost->host_lock);
790 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
791 spin_unlock_irq(shost->host_lock);
792 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
793 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
795 * Driver needs to re-reg VPI in order for f/w
796 * to update the MAC address.
798 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
799 lpfc_register_new_vport(phba, vport, ndlp);
803 if (phba->sli_rev < LPFC_SLI_REV4) {
804 lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
805 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED &&
806 vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
807 lpfc_register_new_vport(phba, vport, ndlp);
809 lpfc_issue_fabric_reglogin(vport);
811 ndlp->nlp_type |= NLP_FABRIC;
812 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
813 if ((!(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) &&
814 (vport->vpi_state & LPFC_VPI_REGISTERED)) {
815 lpfc_start_fdiscs(phba);
816 lpfc_do_scr_ns_plogi(phba, vport);
817 } else if (vport->fc_flag & FC_VFI_REGISTERED)
818 lpfc_issue_init_vpi(vport);
820 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
821 "3135 Need register VFI: (x%x/%x)\n",
822 vport->fc_prevDID, vport->fc_myDID);
823 lpfc_issue_reg_vfi(vport);
830 * lpfc_cmpl_els_flogi_nport - Completion function for flogi to an N_Port
831 * @vport: pointer to a host virtual N_Port data structure.
832 * @ndlp: pointer to a node-list data structure.
833 * @sp: pointer to service parameter data structure.
835 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
836 * function to handle the completion of a Fabric Login (FLOGI) into an N_Port
837 * in a point-to-point topology. First, the @vport's N_Port Name is compared
838 * with the received N_Port Name: if the @vport's N_Port Name is greater than
839 * the received N_Port Name lexicographically, this node shall assign local
840 * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and
841 * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise,
842 * this node shall just wait for the remote node to issue PLOGI and assign
850 lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
851 struct serv_parm *sp)
853 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
854 struct lpfc_hba *phba = vport->phba;
858 spin_lock_irq(shost->host_lock);
859 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
860 vport->fc_flag |= FC_PT2PT;
861 spin_unlock_irq(shost->host_lock);
863 /* If we are pt2pt with another NPort, force NPIV off! */
864 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
866 /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */
867 if ((phba->sli_rev == LPFC_SLI_REV4) && phba->fc_topology_changed) {
868 lpfc_unregister_fcf_prep(phba);
870 spin_lock_irq(shost->host_lock);
871 vport->fc_flag &= ~FC_VFI_REGISTERED;
872 spin_unlock_irq(shost->host_lock);
873 phba->fc_topology_changed = 0;
876 rc = memcmp(&vport->fc_portname, &sp->portName,
877 sizeof(vport->fc_portname));
880 /* This side will initiate the PLOGI */
881 spin_lock_irq(shost->host_lock);
882 vport->fc_flag |= FC_PT2PT_PLOGI;
883 spin_unlock_irq(shost->host_lock);
886 * N_Port ID cannot be 0, set our Id to LocalID
887 * the other side will be RemoteID.
892 vport->fc_myDID = PT2PT_LocalID;
894 /* Decrement ndlp reference count indicating that ndlp can be
895 * safely released when other references to it are done.
899 ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
902 * Cannot find existing Fabric ndlp, so allocate a
905 ndlp = lpfc_nlp_init(vport, PT2PT_RemoteID);
908 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
909 ndlp = lpfc_enable_node(vport, ndlp,
910 NLP_STE_UNUSED_NODE);
915 memcpy(&ndlp->nlp_portname, &sp->portName,
916 sizeof(struct lpfc_name));
917 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
918 sizeof(struct lpfc_name));
919 /* Set state will put ndlp onto node list if not already done */
920 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
921 spin_lock_irq(shost->host_lock);
922 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
923 spin_unlock_irq(shost->host_lock);
925 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
929 lpfc_config_link(phba, mbox);
931 mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link;
933 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
934 if (rc == MBX_NOT_FINISHED) {
935 mempool_free(mbox, phba->mbox_mem_pool);
939 /* This side will wait for the PLOGI, decrement ndlp reference
940 * count indicating that ndlp can be released when other
941 * references to it are done.
945 /* Start discovery - this should just do CLEAR_LA */
946 lpfc_disc_start(vport);
955 * lpfc_cmpl_els_flogi - Completion callback function for flogi
956 * @phba: pointer to lpfc hba data structure.
957 * @cmdiocb: pointer to lpfc command iocb data structure.
958 * @rspiocb: pointer to lpfc response iocb data structure.
960 * This routine is the top-level completion callback function for issuing
961 * a Fabric Login (FLOGI) command. If the response IOCB reported error,
962 * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If
963 * retry has been made (either immediately or delayed with lpfc_els_retry()
964 * returning 1), the command IOCB will be released and function returned.
965 * If the retry attempt has been given up (possibly reach the maximum
966 * number of retries), one additional decrement of ndlp reference shall be
967 * invoked before going out after releasing the command IOCB. This will
968 * actually release the remote node (Note, lpfc_els_free_iocb() will also
969 * invoke one decrement of ndlp reference count). If no error reported in
970 * the IOCB status, the command Port ID field is used to determine whether
971 * this is a point-to-point topology or a fabric topology: if the Port ID
972 * field is assigned, it is a fabric topology; otherwise, it is a
973 * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or
974 * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the
975 * specific topology completion conditions.
978 lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
979 struct lpfc_iocbq *rspiocb)
981 struct lpfc_vport *vport = cmdiocb->vport;
982 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
983 IOCB_t *irsp = &rspiocb->iocb;
984 struct lpfc_nodelist *ndlp = cmdiocb->context1;
985 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
986 struct serv_parm *sp;
990 /* Check to see if link went down during discovery */
991 if (lpfc_els_chk_latt(vport)) {
992 /* One additional decrement on node reference count to
993 * trigger the release of the node
999 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1000 "FLOGI cmpl: status:x%x/x%x state:x%x",
1001 irsp->ulpStatus, irsp->un.ulpWord[4],
1004 if (irsp->ulpStatus) {
1006 * In case of FIP mode, perform roundrobin FCF failover
1007 * due to new FCF discovery
1009 if ((phba->hba_flag & HBA_FIP_SUPPORT) &&
1010 (phba->fcf.fcf_flag & FCF_DISCOVERY)) {
1011 if (phba->link_state < LPFC_LINK_UP)
1012 goto stop_rr_fcf_flogi;
1013 if ((phba->fcoe_cvl_eventtag_attn ==
1014 phba->fcoe_cvl_eventtag) &&
1015 (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
1016 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1018 goto stop_rr_fcf_flogi;
1020 phba->fcoe_cvl_eventtag_attn =
1021 phba->fcoe_cvl_eventtag;
1022 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
1023 "2611 FLOGI failed on FCF (x%x), "
1024 "status:x%x/x%x, tmo:x%x, perform "
1025 "roundrobin FCF failover\n",
1026 phba->fcf.current_rec.fcf_indx,
1027 irsp->ulpStatus, irsp->un.ulpWord[4],
1029 lpfc_sli4_set_fcf_flogi_fail(phba,
1030 phba->fcf.current_rec.fcf_indx);
1031 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
1032 rc = lpfc_sli4_fcf_rr_next_proc(vport, fcf_index);
1039 if (!(irsp->ulpStatus == IOSTAT_LOCAL_REJECT &&
1040 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1041 IOERR_LOOP_OPEN_FAILURE)))
1042 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1043 "2858 FLOGI failure Status:x%x/x%x "
1044 "TMO:x%x Data x%x x%x\n",
1045 irsp->ulpStatus, irsp->un.ulpWord[4],
1046 irsp->ulpTimeout, phba->hba_flag,
1047 phba->fcf.fcf_flag);
1049 /* Check for retry */
1050 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
1053 /* If this is not a loop open failure, bail out */
1054 if (!(irsp->ulpStatus == IOSTAT_LOCAL_REJECT &&
1055 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1056 IOERR_LOOP_OPEN_FAILURE)))
1059 lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS,
1060 "0150 FLOGI failure Status:x%x/x%x xri x%x TMO:x%x\n",
1061 irsp->ulpStatus, irsp->un.ulpWord[4],
1062 cmdiocb->sli4_xritag, irsp->ulpTimeout);
1064 /* FLOGI failed, so there is no fabric */
1065 spin_lock_irq(shost->host_lock);
1066 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
1067 spin_unlock_irq(shost->host_lock);
1069 /* If private loop, then allow max outstanding els to be
1070 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
1071 * alpa map would take too long otherwise.
1073 if (phba->alpa_map[0] == 0)
1074 vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
1075 if ((phba->sli_rev == LPFC_SLI_REV4) &&
1076 (!(vport->fc_flag & FC_VFI_REGISTERED) ||
1077 (vport->fc_prevDID != vport->fc_myDID) ||
1078 phba->fc_topology_changed)) {
1079 if (vport->fc_flag & FC_VFI_REGISTERED) {
1080 if (phba->fc_topology_changed) {
1081 lpfc_unregister_fcf_prep(phba);
1082 spin_lock_irq(shost->host_lock);
1083 vport->fc_flag &= ~FC_VFI_REGISTERED;
1084 spin_unlock_irq(shost->host_lock);
1085 phba->fc_topology_changed = 0;
1087 lpfc_sli4_unreg_all_rpis(vport);
1091 /* Do not register VFI if the driver aborted FLOGI */
1092 if (!lpfc_error_lost_link(irsp))
1093 lpfc_issue_reg_vfi(vport);
1099 spin_lock_irq(shost->host_lock);
1100 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
1101 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
1102 spin_unlock_irq(shost->host_lock);
1105 * The FLogI succeeded. Sync the data for the CPU before
1108 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
1111 sp = prsp->virt + sizeof(uint32_t);
1113 /* FLOGI completes successfully */
1114 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1115 "0101 FLOGI completes successfully, I/O tag:x%x, "
1116 "xri x%x Data: x%x x%x x%x x%x x%x %x\n",
1117 cmdiocb->iotag, cmdiocb->sli4_xritag,
1118 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
1119 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution,
1120 vport->port_state, vport->fc_flag);
1122 if (vport->port_state == LPFC_FLOGI) {
1124 * If Common Service Parameters indicate Nport
1125 * we are point to point, if Fport we are Fabric.
1128 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
1129 else if (!(phba->hba_flag & HBA_FCOE_MODE))
1130 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
1132 lpfc_printf_vlog(vport, KERN_ERR,
1134 "2831 FLOGI response with cleared Fabric "
1135 "bit fcf_index 0x%x "
1136 "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x "
1138 "%02x%02x%02x%02x%02x%02x%02x%02x\n",
1139 phba->fcf.current_rec.fcf_indx,
1140 phba->fcf.current_rec.switch_name[0],
1141 phba->fcf.current_rec.switch_name[1],
1142 phba->fcf.current_rec.switch_name[2],
1143 phba->fcf.current_rec.switch_name[3],
1144 phba->fcf.current_rec.switch_name[4],
1145 phba->fcf.current_rec.switch_name[5],
1146 phba->fcf.current_rec.switch_name[6],
1147 phba->fcf.current_rec.switch_name[7],
1148 phba->fcf.current_rec.fabric_name[0],
1149 phba->fcf.current_rec.fabric_name[1],
1150 phba->fcf.current_rec.fabric_name[2],
1151 phba->fcf.current_rec.fabric_name[3],
1152 phba->fcf.current_rec.fabric_name[4],
1153 phba->fcf.current_rec.fabric_name[5],
1154 phba->fcf.current_rec.fabric_name[6],
1155 phba->fcf.current_rec.fabric_name[7]);
1157 spin_lock_irq(&phba->hbalock);
1158 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
1159 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
1160 spin_unlock_irq(&phba->hbalock);
1161 phba->fcf.fcf_redisc_attempted = 0; /* reset */
1165 /* Mark the FCF discovery process done */
1166 if (phba->hba_flag & HBA_FIP_SUPPORT)
1167 lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP |
1169 "2769 FLOGI to FCF (x%x) "
1170 "completed successfully\n",
1171 phba->fcf.current_rec.fcf_indx);
1172 spin_lock_irq(&phba->hbalock);
1173 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
1174 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
1175 spin_unlock_irq(&phba->hbalock);
1176 phba->fcf.fcf_redisc_attempted = 0; /* reset */
1182 spin_lock_irq(&phba->hbalock);
1183 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
1184 spin_unlock_irq(&phba->hbalock);
1188 if (!lpfc_error_lost_link(irsp)) {
1189 /* FLOGI failed, so just use loop map to make discovery list */
1190 lpfc_disc_list_loopmap(vport);
1192 /* Start discovery */
1193 lpfc_disc_start(vport);
1194 } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
1195 (((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
1196 IOERR_SLI_ABORTED) &&
1197 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
1198 IOERR_SLI_DOWN))) &&
1199 (phba->link_state != LPFC_CLEAR_LA)) {
1200 /* If FLOGI failed enable link interrupt. */
1201 lpfc_issue_clear_la(phba, vport);
1204 lpfc_els_free_iocb(phba, cmdiocb);
1208 * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport
1209 * @vport: pointer to a host virtual N_Port data structure.
1210 * @ndlp: pointer to a node-list data structure.
1211 * @retry: number of retries to the command IOCB.
1213 * This routine issues a Fabric Login (FLOGI) Request ELS command
1214 * for a @vport. The initiator service parameters are put into the payload
1215 * of the FLOGI Request IOCB and the top-level callback function pointer
1216 * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
1217 * function field. The lpfc_issue_fabric_iocb routine is invoked to send
1218 * out FLOGI ELS command with one outstanding fabric IOCB at a time.
1220 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1221 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1222 * will be stored into the context1 field of the IOCB for the completion
1223 * callback function to the FLOGI ELS command.
1226 * 0 - successfully issued flogi iocb for @vport
1227 * 1 - failed to issue flogi iocb for @vport
1230 lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1233 struct lpfc_hba *phba = vport->phba;
1234 struct serv_parm *sp;
1236 struct lpfc_iocbq *elsiocb;
1237 struct lpfc_iocbq defer_flogi_acc;
1243 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
1244 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1245 ndlp->nlp_DID, ELS_CMD_FLOGI);
1250 icmd = &elsiocb->iocb;
1251 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1253 /* For FLOGI request, remainder of payload is service parameters */
1254 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
1255 pcmd += sizeof(uint32_t);
1256 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
1257 sp = (struct serv_parm *) pcmd;
1259 /* Setup CSPs accordingly for Fabric */
1260 sp->cmn.e_d_tov = 0;
1261 sp->cmn.w2.r_a_tov = 0;
1262 sp->cmn.virtual_fabric_support = 0;
1263 sp->cls1.classValid = 0;
1264 if (sp->cmn.fcphLow < FC_PH3)
1265 sp->cmn.fcphLow = FC_PH3;
1266 if (sp->cmn.fcphHigh < FC_PH3)
1267 sp->cmn.fcphHigh = FC_PH3;
1269 if (phba->sli_rev == LPFC_SLI_REV4) {
1270 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
1271 LPFC_SLI_INTF_IF_TYPE_0) {
1272 elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1);
1273 elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1);
1274 /* FLOGI needs to be 3 for WQE FCFI */
1275 /* Set the fcfi to the fcfi we registered with */
1276 elsiocb->iocb.ulpContext = phba->fcf.fcfi;
1278 /* Can't do SLI4 class2 without support sequence coalescing */
1279 sp->cls2.classValid = 0;
1280 sp->cls2.seqDelivery = 0;
1282 /* Historical, setting sequential-delivery bit for SLI3 */
1283 sp->cls2.seqDelivery = (sp->cls2.classValid) ? 1 : 0;
1284 sp->cls3.seqDelivery = (sp->cls3.classValid) ? 1 : 0;
1285 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
1286 sp->cmn.request_multiple_Nport = 1;
1287 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
1291 sp->cmn.request_multiple_Nport = 0;
1294 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
1295 icmd->un.elsreq64.myID = 0;
1296 icmd->un.elsreq64.fl = 1;
1299 tmo = phba->fc_ratov;
1300 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
1301 lpfc_set_disctmo(vport);
1302 phba->fc_ratov = tmo;
1304 phba->fc_stat.elsXmitFLOGI++;
1305 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
1307 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1308 "Issue FLOGI: opt:x%x",
1309 phba->sli3_options, 0, 0);
1311 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
1313 phba->hba_flag |= HBA_FLOGI_ISSUED;
1315 /* Check for a deferred FLOGI ACC condition */
1316 if (phba->defer_flogi_acc_flag) {
1317 did = vport->fc_myDID;
1318 vport->fc_myDID = Fabric_DID;
1320 memset(&defer_flogi_acc, 0, sizeof(struct lpfc_iocbq));
1322 defer_flogi_acc.iocb.ulpContext = phba->defer_flogi_acc_rx_id;
1323 defer_flogi_acc.iocb.unsli3.rcvsli3.ox_id =
1324 phba->defer_flogi_acc_ox_id;
1326 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1327 "3354 Xmit deferred FLOGI ACC: rx_id: x%x,"
1328 " ox_id: x%x, hba_flag x%x\n",
1329 phba->defer_flogi_acc_rx_id,
1330 phba->defer_flogi_acc_ox_id, phba->hba_flag);
1332 /* Send deferred FLOGI ACC */
1333 lpfc_els_rsp_acc(vport, ELS_CMD_FLOGI, &defer_flogi_acc,
1336 phba->defer_flogi_acc_flag = false;
1338 vport->fc_myDID = did;
1341 if (rc == IOCB_ERROR) {
1342 lpfc_els_free_iocb(phba, elsiocb);
1349 * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs
1350 * @phba: pointer to lpfc hba data structure.
1352 * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
1353 * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
1354 * list and issues an abort IOCB commond on each outstanding IOCB that
1355 * contains a active Fabric_DID ndlp. Note that this function is to issue
1356 * the abort IOCB command on all the outstanding IOCBs, thus when this
1357 * function returns, it does not guarantee all the IOCBs are actually aborted.
1360 * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0)
1363 lpfc_els_abort_flogi(struct lpfc_hba *phba)
1365 struct lpfc_sli_ring *pring;
1366 struct lpfc_iocbq *iocb, *next_iocb;
1367 struct lpfc_nodelist *ndlp;
1370 /* Abort outstanding I/O on NPort <nlp_DID> */
1371 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
1372 "0201 Abort outstanding I/O on NPort x%x\n",
1375 pring = lpfc_phba_elsring(phba);
1376 if (unlikely(!pring))
1380 * Check the txcmplq for an iocb that matches the nport the driver is
1383 spin_lock_irq(&phba->hbalock);
1384 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
1386 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR) {
1387 ndlp = (struct lpfc_nodelist *)(iocb->context1);
1388 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
1389 (ndlp->nlp_DID == Fabric_DID))
1390 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
1393 spin_unlock_irq(&phba->hbalock);
1399 * lpfc_initial_flogi - Issue an initial fabric login for a vport
1400 * @vport: pointer to a host virtual N_Port data structure.
1402 * This routine issues an initial Fabric Login (FLOGI) for the @vport
1403 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1404 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1405 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1406 * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
1407 * is then invoked with the @vport and the ndlp to perform the FLOGI for the
1411 * 0 - failed to issue initial flogi for @vport
1412 * 1 - successfully issued initial flogi for @vport
1415 lpfc_initial_flogi(struct lpfc_vport *vport)
1417 struct lpfc_nodelist *ndlp;
1419 vport->port_state = LPFC_FLOGI;
1420 lpfc_set_disctmo(vport);
1422 /* First look for the Fabric ndlp */
1423 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1425 /* Cannot find existing Fabric ndlp, so allocate a new one */
1426 ndlp = lpfc_nlp_init(vport, Fabric_DID);
1429 /* Set the node type */
1430 ndlp->nlp_type |= NLP_FABRIC;
1431 /* Put ndlp onto node list */
1432 lpfc_enqueue_node(vport, ndlp);
1433 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1434 /* re-setup ndlp without removing from node list */
1435 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1440 if (lpfc_issue_els_flogi(vport, ndlp, 0)) {
1441 /* This decrement of reference count to node shall kick off
1442 * the release of the node.
1451 * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport
1452 * @vport: pointer to a host virtual N_Port data structure.
1454 * This routine issues an initial Fabric Discover (FDISC) for the @vport
1455 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1456 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1457 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1458 * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
1459 * is then invoked with the @vport and the ndlp to perform the FDISC for the
1463 * 0 - failed to issue initial fdisc for @vport
1464 * 1 - successfully issued initial fdisc for @vport
1467 lpfc_initial_fdisc(struct lpfc_vport *vport)
1469 struct lpfc_nodelist *ndlp;
1471 /* First look for the Fabric ndlp */
1472 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1474 /* Cannot find existing Fabric ndlp, so allocate a new one */
1475 ndlp = lpfc_nlp_init(vport, Fabric_DID);
1478 /* Put ndlp onto node list */
1479 lpfc_enqueue_node(vport, ndlp);
1480 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1481 /* re-setup ndlp without removing from node list */
1482 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1487 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
1488 /* decrement node reference count to trigger the release of
1498 * lpfc_more_plogi - Check and issue remaining plogis for a vport
1499 * @vport: pointer to a host virtual N_Port data structure.
1501 * This routine checks whether there are more remaining Port Logins
1502 * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
1503 * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
1504 * to issue ELS PLOGIs up to the configured discover threads with the
1505 * @vport (@vport->cfg_discovery_threads). The function also decrement
1506 * the @vport's num_disc_node by 1 if it is not already 0.
1509 lpfc_more_plogi(struct lpfc_vport *vport)
1511 if (vport->num_disc_nodes)
1512 vport->num_disc_nodes--;
1514 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
1515 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1516 "0232 Continue discovery with %d PLOGIs to go "
1517 "Data: x%x x%x x%x\n",
1518 vport->num_disc_nodes, vport->fc_plogi_cnt,
1519 vport->fc_flag, vport->port_state);
1520 /* Check to see if there are more PLOGIs to be sent */
1521 if (vport->fc_flag & FC_NLP_MORE)
1522 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
1523 lpfc_els_disc_plogi(vport);
1529 * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp
1530 * @phba: pointer to lpfc hba data structure.
1531 * @prsp: pointer to response IOCB payload.
1532 * @ndlp: pointer to a node-list data structure.
1534 * This routine checks and indicates whether the WWPN of an N_Port, retrieved
1535 * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
1536 * The following cases are considered N_Port confirmed:
1537 * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
1538 * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
1539 * it does not have WWPN assigned either. If the WWPN is confirmed, the
1540 * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
1541 * 1) if there is a node on vport list other than the @ndlp with the same
1542 * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
1543 * on that node to release the RPI associated with the node; 2) if there is
1544 * no node found on vport list with the same WWPN of the N_Port PLOGI logged
1545 * into, a new node shall be allocated (or activated). In either case, the
1546 * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
1547 * be released and the new_ndlp shall be put on to the vport node list and
1548 * its pointer returned as the confirmed node.
1550 * Note that before the @ndlp got "released", the keepDID from not-matching
1551 * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
1552 * of the @ndlp. This is because the release of @ndlp is actually to put it
1553 * into an inactive state on the vport node list and the vport node list
1554 * management algorithm does not allow two node with a same DID.
1557 * pointer to the PLOGI N_Port @ndlp
1559 static struct lpfc_nodelist *
1560 lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
1561 struct lpfc_nodelist *ndlp)
1563 struct lpfc_vport *vport = ndlp->vport;
1564 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1565 struct lpfc_nodelist *new_ndlp;
1566 struct lpfc_rport_data *rdata;
1567 struct fc_rport *rport;
1568 struct serv_parm *sp;
1569 uint8_t name[sizeof(struct lpfc_name)];
1570 uint32_t rc, keepDID = 0, keep_nlp_flag = 0;
1571 uint32_t keep_new_nlp_flag = 0;
1572 uint16_t keep_nlp_state;
1573 u32 keep_nlp_fc4_type = 0;
1574 struct lpfc_nvme_rport *keep_nrport = NULL;
1577 unsigned long *active_rrqs_xri_bitmap = NULL;
1579 /* Fabric nodes can have the same WWPN so we don't bother searching
1580 * by WWPN. Just return the ndlp that was given to us.
1582 if (ndlp->nlp_type & NLP_FABRIC)
1585 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
1586 memset(name, 0, sizeof(struct lpfc_name));
1588 /* Now we find out if the NPort we are logging into, matches the WWPN
1589 * we have for that ndlp. If not, we have some work to do.
1591 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
1593 /* return immediately if the WWPN matches ndlp */
1594 if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp))
1597 if (phba->sli_rev == LPFC_SLI_REV4) {
1598 active_rrqs_xri_bitmap = mempool_alloc(phba->active_rrq_pool,
1600 if (active_rrqs_xri_bitmap)
1601 memset(active_rrqs_xri_bitmap, 0,
1602 phba->cfg_rrq_xri_bitmap_sz);
1605 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_NODE,
1606 "3178 PLOGI confirm: ndlp x%x x%x x%x: "
1607 "new_ndlp x%x x%x x%x\n",
1608 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_fc4_type,
1609 (new_ndlp ? new_ndlp->nlp_DID : 0),
1610 (new_ndlp ? new_ndlp->nlp_flag : 0),
1611 (new_ndlp ? new_ndlp->nlp_fc4_type : 0));
1614 rc = memcmp(&ndlp->nlp_portname, name,
1615 sizeof(struct lpfc_name));
1617 if (active_rrqs_xri_bitmap)
1618 mempool_free(active_rrqs_xri_bitmap,
1619 phba->active_rrq_pool);
1622 new_ndlp = lpfc_nlp_init(vport, ndlp->nlp_DID);
1624 if (active_rrqs_xri_bitmap)
1625 mempool_free(active_rrqs_xri_bitmap,
1626 phba->active_rrq_pool);
1629 } else if (!NLP_CHK_NODE_ACT(new_ndlp)) {
1630 rc = memcmp(&ndlp->nlp_portname, name,
1631 sizeof(struct lpfc_name));
1633 if (active_rrqs_xri_bitmap)
1634 mempool_free(active_rrqs_xri_bitmap,
1635 phba->active_rrq_pool);
1638 new_ndlp = lpfc_enable_node(vport, new_ndlp,
1639 NLP_STE_UNUSED_NODE);
1641 if (active_rrqs_xri_bitmap)
1642 mempool_free(active_rrqs_xri_bitmap,
1643 phba->active_rrq_pool);
1646 keepDID = new_ndlp->nlp_DID;
1647 if ((phba->sli_rev == LPFC_SLI_REV4) && active_rrqs_xri_bitmap)
1648 memcpy(active_rrqs_xri_bitmap,
1649 new_ndlp->active_rrqs_xri_bitmap,
1650 phba->cfg_rrq_xri_bitmap_sz);
1652 keepDID = new_ndlp->nlp_DID;
1653 if (phba->sli_rev == LPFC_SLI_REV4 &&
1654 active_rrqs_xri_bitmap)
1655 memcpy(active_rrqs_xri_bitmap,
1656 new_ndlp->active_rrqs_xri_bitmap,
1657 phba->cfg_rrq_xri_bitmap_sz);
1660 /* At this point in this routine, we know new_ndlp will be
1661 * returned. however, any previous GID_FTs that were done
1662 * would have updated nlp_fc4_type in ndlp, so we must ensure
1663 * new_ndlp has the right value.
1665 if (vport->fc_flag & FC_FABRIC) {
1666 keep_nlp_fc4_type = new_ndlp->nlp_fc4_type;
1667 new_ndlp->nlp_fc4_type = ndlp->nlp_fc4_type;
1670 lpfc_unreg_rpi(vport, new_ndlp);
1671 new_ndlp->nlp_DID = ndlp->nlp_DID;
1672 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
1673 if (phba->sli_rev == LPFC_SLI_REV4)
1674 memcpy(new_ndlp->active_rrqs_xri_bitmap,
1675 ndlp->active_rrqs_xri_bitmap,
1676 phba->cfg_rrq_xri_bitmap_sz);
1678 spin_lock_irq(shost->host_lock);
1679 keep_new_nlp_flag = new_ndlp->nlp_flag;
1680 keep_nlp_flag = ndlp->nlp_flag;
1681 new_ndlp->nlp_flag = ndlp->nlp_flag;
1683 /* if new_ndlp had NLP_UNREG_INP set, keep it */
1684 if (keep_new_nlp_flag & NLP_UNREG_INP)
1685 new_ndlp->nlp_flag |= NLP_UNREG_INP;
1687 new_ndlp->nlp_flag &= ~NLP_UNREG_INP;
1689 /* if new_ndlp had NLP_RPI_REGISTERED set, keep it */
1690 if (keep_new_nlp_flag & NLP_RPI_REGISTERED)
1691 new_ndlp->nlp_flag |= NLP_RPI_REGISTERED;
1693 new_ndlp->nlp_flag &= ~NLP_RPI_REGISTERED;
1695 ndlp->nlp_flag = keep_new_nlp_flag;
1697 /* if ndlp had NLP_UNREG_INP set, keep it */
1698 if (keep_nlp_flag & NLP_UNREG_INP)
1699 ndlp->nlp_flag |= NLP_UNREG_INP;
1701 ndlp->nlp_flag &= ~NLP_UNREG_INP;
1703 /* if ndlp had NLP_RPI_REGISTERED set, keep it */
1704 if (keep_nlp_flag & NLP_RPI_REGISTERED)
1705 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
1707 ndlp->nlp_flag &= ~NLP_RPI_REGISTERED;
1709 spin_unlock_irq(shost->host_lock);
1711 /* Set nlp_states accordingly */
1712 keep_nlp_state = new_ndlp->nlp_state;
1713 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
1715 /* interchange the nvme remoteport structs */
1716 keep_nrport = new_ndlp->nrport;
1717 new_ndlp->nrport = ndlp->nrport;
1719 /* Move this back to NPR state */
1720 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
1721 /* The new_ndlp is replacing ndlp totally, so we need
1722 * to put ndlp on UNUSED list and try to free it.
1724 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1725 "3179 PLOGI confirm NEW: %x %x\n",
1726 new_ndlp->nlp_DID, keepDID);
1728 /* Fix up the rport accordingly */
1729 rport = ndlp->rport;
1731 rdata = rport->dd_data;
1732 if (rdata->pnode == ndlp) {
1733 /* break the link before dropping the ref */
1736 rdata->pnode = lpfc_nlp_get(new_ndlp);
1737 new_ndlp->rport = rport;
1739 new_ndlp->nlp_type = ndlp->nlp_type;
1742 /* Fix up the nvme rport */
1744 ndlp->nrport = NULL;
1748 /* We shall actually free the ndlp with both nlp_DID and
1749 * nlp_portname fields equals 0 to avoid any ndlp on the
1750 * nodelist never to be used.
1752 if (ndlp->nlp_DID == 0) {
1753 spin_lock_irq(&phba->ndlp_lock);
1754 NLP_SET_FREE_REQ(ndlp);
1755 spin_unlock_irq(&phba->ndlp_lock);
1758 /* Two ndlps cannot have the same did on the nodelist.
1759 * Note: for this case, ndlp has a NULL WWPN so setting
1760 * the nlp_fc4_type isn't required.
1762 ndlp->nlp_DID = keepDID;
1763 lpfc_nlp_set_state(vport, ndlp, keep_nlp_state);
1764 if (phba->sli_rev == LPFC_SLI_REV4 &&
1765 active_rrqs_xri_bitmap)
1766 memcpy(ndlp->active_rrqs_xri_bitmap,
1767 active_rrqs_xri_bitmap,
1768 phba->cfg_rrq_xri_bitmap_sz);
1770 if (!NLP_CHK_NODE_ACT(ndlp))
1771 lpfc_drop_node(vport, ndlp);
1774 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1775 "3180 PLOGI confirm SWAP: %x %x\n",
1776 new_ndlp->nlp_DID, keepDID);
1778 lpfc_unreg_rpi(vport, ndlp);
1780 /* Two ndlps cannot have the same did and the fc4
1781 * type must be transferred because the ndlp is in
1784 ndlp->nlp_DID = keepDID;
1785 ndlp->nlp_fc4_type = keep_nlp_fc4_type;
1787 if (phba->sli_rev == LPFC_SLI_REV4 &&
1788 active_rrqs_xri_bitmap)
1789 memcpy(ndlp->active_rrqs_xri_bitmap,
1790 active_rrqs_xri_bitmap,
1791 phba->cfg_rrq_xri_bitmap_sz);
1793 /* Since we are switching over to the new_ndlp,
1794 * reset the old ndlp state
1796 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
1797 (ndlp->nlp_state == NLP_STE_MAPPED_NODE))
1798 keep_nlp_state = NLP_STE_NPR_NODE;
1799 lpfc_nlp_set_state(vport, ndlp, keep_nlp_state);
1801 /* Previous ndlp no longer active with nvme host transport.
1802 * Remove reference from earlier registration unless the
1803 * nvme host took care of it.
1807 ndlp->nrport = keep_nrport;
1809 /* Fix up the rport accordingly */
1810 rport = ndlp->rport;
1812 rdata = rport->dd_data;
1813 put_node = rdata->pnode != NULL;
1814 put_rport = ndlp->rport != NULL;
1815 rdata->pnode = NULL;
1820 put_device(&rport->dev);
1823 if (phba->sli_rev == LPFC_SLI_REV4 &&
1824 active_rrqs_xri_bitmap)
1825 mempool_free(active_rrqs_xri_bitmap,
1826 phba->active_rrq_pool);
1828 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_NODE,
1829 "3173 PLOGI confirm exit: new_ndlp x%x x%x x%x\n",
1830 new_ndlp->nlp_DID, new_ndlp->nlp_flag,
1831 new_ndlp->nlp_fc4_type);
1837 * lpfc_end_rscn - Check and handle more rscn for a vport
1838 * @vport: pointer to a host virtual N_Port data structure.
1840 * This routine checks whether more Registration State Change
1841 * Notifications (RSCNs) came in while the discovery state machine was in
1842 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1843 * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1844 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1845 * handling the RSCNs.
1848 lpfc_end_rscn(struct lpfc_vport *vport)
1850 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1852 if (vport->fc_flag & FC_RSCN_MODE) {
1854 * Check to see if more RSCNs came in while we were
1855 * processing this one.
1857 if (vport->fc_rscn_id_cnt ||
1858 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
1859 lpfc_els_handle_rscn(vport);
1861 spin_lock_irq(shost->host_lock);
1862 vport->fc_flag &= ~FC_RSCN_MODE;
1863 spin_unlock_irq(shost->host_lock);
1869 * lpfc_cmpl_els_rrq - Completion handled for els RRQs.
1870 * @phba: pointer to lpfc hba data structure.
1871 * @cmdiocb: pointer to lpfc command iocb data structure.
1872 * @rspiocb: pointer to lpfc response iocb data structure.
1874 * This routine will call the clear rrq function to free the rrq and
1875 * clear the xri's bit in the ndlp's xri_bitmap. If the ndlp does not
1876 * exist then the clear_rrq is still called because the rrq needs to
1881 lpfc_cmpl_els_rrq(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1882 struct lpfc_iocbq *rspiocb)
1884 struct lpfc_vport *vport = cmdiocb->vport;
1886 struct lpfc_nodelist *ndlp;
1887 struct lpfc_node_rrq *rrq;
1889 /* we pass cmdiocb to state machine which needs rspiocb as well */
1890 rrq = cmdiocb->context_un.rrq;
1891 cmdiocb->context_un.rsp_iocb = rspiocb;
1893 irsp = &rspiocb->iocb;
1894 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1895 "RRQ cmpl: status:x%x/x%x did:x%x",
1896 irsp->ulpStatus, irsp->un.ulpWord[4],
1897 irsp->un.elsreq64.remoteID);
1899 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
1900 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || ndlp != rrq->ndlp) {
1901 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1902 "2882 RRQ completes to NPort x%x "
1903 "with no ndlp. Data: x%x x%x x%x\n",
1904 irsp->un.elsreq64.remoteID,
1905 irsp->ulpStatus, irsp->un.ulpWord[4],
1910 /* rrq completes to NPort <nlp_DID> */
1911 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1912 "2880 RRQ completes to NPort x%x "
1913 "Data: x%x x%x x%x x%x x%x\n",
1914 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1915 irsp->ulpTimeout, rrq->xritag, rrq->rxid);
1917 if (irsp->ulpStatus) {
1918 /* Check for retry */
1919 /* RRQ failed Don't print the vport to vport rjts */
1920 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1921 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1922 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1923 (phba)->pport->cfg_log_verbose & LOG_ELS)
1924 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1925 "2881 RRQ failure DID:%06X Status:x%x/x%x\n",
1926 ndlp->nlp_DID, irsp->ulpStatus,
1927 irsp->un.ulpWord[4]);
1931 lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
1932 lpfc_els_free_iocb(phba, cmdiocb);
1936 * lpfc_cmpl_els_plogi - Completion callback function for plogi
1937 * @phba: pointer to lpfc hba data structure.
1938 * @cmdiocb: pointer to lpfc command iocb data structure.
1939 * @rspiocb: pointer to lpfc response iocb data structure.
1941 * This routine is the completion callback function for issuing the Port
1942 * Login (PLOGI) command. For PLOGI completion, there must be an active
1943 * ndlp on the vport node list that matches the remote node ID from the
1944 * PLOGI response IOCB. If such ndlp does not exist, the PLOGI is simply
1945 * ignored and command IOCB released. The PLOGI response IOCB status is
1946 * checked for error conditons. If there is error status reported, PLOGI
1947 * retry shall be attempted by invoking the lpfc_els_retry() routine.
1948 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1949 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1950 * (DSM) is set for this PLOGI completion. Finally, it checks whether
1951 * there are additional N_Port nodes with the vport that need to perform
1952 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
1956 lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1957 struct lpfc_iocbq *rspiocb)
1959 struct lpfc_vport *vport = cmdiocb->vport;
1960 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1962 struct lpfc_nodelist *ndlp;
1963 struct lpfc_dmabuf *prsp;
1966 /* we pass cmdiocb to state machine which needs rspiocb as well */
1967 cmdiocb->context_un.rsp_iocb = rspiocb;
1969 irsp = &rspiocb->iocb;
1970 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1971 "PLOGI cmpl: status:x%x/x%x did:x%x",
1972 irsp->ulpStatus, irsp->un.ulpWord[4],
1973 irsp->un.elsreq64.remoteID);
1975 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
1976 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
1977 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1978 "0136 PLOGI completes to NPort x%x "
1979 "with no ndlp. Data: x%x x%x x%x\n",
1980 irsp->un.elsreq64.remoteID,
1981 irsp->ulpStatus, irsp->un.ulpWord[4],
1986 /* Since ndlp can be freed in the disc state machine, note if this node
1987 * is being used during discovery.
1989 spin_lock_irq(shost->host_lock);
1990 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
1991 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1992 spin_unlock_irq(shost->host_lock);
1995 /* PLOGI completes to NPort <nlp_DID> */
1996 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1997 "0102 PLOGI completes to NPort x%06x "
1998 "Data: x%x x%x x%x x%x x%x\n",
1999 ndlp->nlp_DID, ndlp->nlp_fc4_type,
2000 irsp->ulpStatus, irsp->un.ulpWord[4],
2001 disc, vport->num_disc_nodes);
2003 /* Check to see if link went down during discovery */
2004 if (lpfc_els_chk_latt(vport)) {
2005 spin_lock_irq(shost->host_lock);
2006 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2007 spin_unlock_irq(shost->host_lock);
2011 if (irsp->ulpStatus) {
2012 /* Check for retry */
2013 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2014 /* ELS command is being retried */
2016 spin_lock_irq(shost->host_lock);
2017 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2018 spin_unlock_irq(shost->host_lock);
2022 /* PLOGI failed Don't print the vport to vport rjts */
2023 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
2024 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
2025 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
2026 (phba)->pport->cfg_log_verbose & LOG_ELS)
2027 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2028 "2753 PLOGI failure DID:%06X Status:x%x/x%x\n",
2029 ndlp->nlp_DID, irsp->ulpStatus,
2030 irsp->un.ulpWord[4]);
2031 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2032 if (lpfc_error_lost_link(irsp))
2033 rc = NLP_STE_FREED_NODE;
2035 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2036 NLP_EVT_CMPL_PLOGI);
2038 /* Good status, call state machine */
2039 prsp = list_entry(((struct lpfc_dmabuf *)
2040 cmdiocb->context2)->list.next,
2041 struct lpfc_dmabuf, list);
2042 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
2043 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2044 NLP_EVT_CMPL_PLOGI);
2047 if (disc && vport->num_disc_nodes) {
2048 /* Check to see if there are more PLOGIs to be sent */
2049 lpfc_more_plogi(vport);
2051 if (vport->num_disc_nodes == 0) {
2052 spin_lock_irq(shost->host_lock);
2053 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2054 spin_unlock_irq(shost->host_lock);
2056 lpfc_can_disctmo(vport);
2057 lpfc_end_rscn(vport);
2062 lpfc_els_free_iocb(phba, cmdiocb);
2067 * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
2068 * @vport: pointer to a host virtual N_Port data structure.
2069 * @did: destination port identifier.
2070 * @retry: number of retries to the command IOCB.
2072 * This routine issues a Port Login (PLOGI) command to a remote N_Port
2073 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
2074 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
2075 * This routine constructs the proper feilds of the PLOGI IOCB and invokes
2076 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
2078 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2079 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2080 * will be stored into the context1 field of the IOCB for the completion
2081 * callback function to the PLOGI ELS command.
2084 * 0 - Successfully issued a plogi for @vport
2085 * 1 - failed to issue a plogi for @vport
2088 lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
2090 struct lpfc_hba *phba = vport->phba;
2091 struct Scsi_Host *shost;
2092 struct serv_parm *sp;
2093 struct lpfc_nodelist *ndlp;
2094 struct lpfc_iocbq *elsiocb;
2099 ndlp = lpfc_findnode_did(vport, did);
2102 /* Defer the processing of the issue PLOGI until after the
2103 * outstanding UNREG_RPI mbox command completes, unless we
2104 * are going offline. This logic does not apply for Fabric DIDs
2106 if ((ndlp->nlp_flag & NLP_UNREG_INP) &&
2107 ((ndlp->nlp_DID & Fabric_DID_MASK) != Fabric_DID_MASK) &&
2108 !(vport->fc_flag & FC_OFFLINE_MODE)) {
2109 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2110 "4110 Issue PLOGI x%x deferred "
2111 "on NPort x%x rpi x%x Data: %p\n",
2112 ndlp->nlp_defer_did, ndlp->nlp_DID,
2113 ndlp->nlp_rpi, ndlp);
2115 /* We can only defer 1st PLOGI */
2116 if (ndlp->nlp_defer_did == NLP_EVT_NOTHING_PENDING)
2117 ndlp->nlp_defer_did = did;
2120 if (!NLP_CHK_NODE_ACT(ndlp))
2124 /* If ndlp is not NULL, we will bump the reference count on it */
2125 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
2126 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
2131 shost = lpfc_shost_from_vport(vport);
2132 spin_lock_irq(shost->host_lock);
2133 ndlp->nlp_flag &= ~NLP_FCP_PRLI_RJT;
2134 spin_unlock_irq(shost->host_lock);
2136 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2138 /* For PLOGI request, remainder of payload is service parameters */
2139 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
2140 pcmd += sizeof(uint32_t);
2141 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
2142 sp = (struct serv_parm *) pcmd;
2145 * If we are a N-port connected to a Fabric, fix-up paramm's so logins
2146 * to device on remote loops work.
2148 if ((vport->fc_flag & FC_FABRIC) && !(vport->fc_flag & FC_PUBLIC_LOOP))
2149 sp->cmn.altBbCredit = 1;
2151 if (sp->cmn.fcphLow < FC_PH_4_3)
2152 sp->cmn.fcphLow = FC_PH_4_3;
2154 if (sp->cmn.fcphHigh < FC_PH3)
2155 sp->cmn.fcphHigh = FC_PH3;
2157 sp->cmn.valid_vendor_ver_level = 0;
2158 memset(sp->un.vendorVersion, 0, sizeof(sp->un.vendorVersion));
2159 sp->cmn.bbRcvSizeMsb &= 0xF;
2161 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2162 "Issue PLOGI: did:x%x",
2165 /* If our firmware supports this feature, convey that
2166 * information to the target using the vendor specific field.
2168 if (phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) {
2169 sp->cmn.valid_vendor_ver_level = 1;
2170 sp->un.vv.vid = cpu_to_be32(LPFC_VV_EMLX_ID);
2171 sp->un.vv.flags = cpu_to_be32(LPFC_VV_SUPPRESS_RSP);
2174 phba->fc_stat.elsXmitPLOGI++;
2175 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
2176 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
2178 if (ret == IOCB_ERROR) {
2179 lpfc_els_free_iocb(phba, elsiocb);
2186 * lpfc_cmpl_els_prli - Completion callback function for prli
2187 * @phba: pointer to lpfc hba data structure.
2188 * @cmdiocb: pointer to lpfc command iocb data structure.
2189 * @rspiocb: pointer to lpfc response iocb data structure.
2191 * This routine is the completion callback function for a Process Login
2192 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
2193 * status. If there is error status reported, PRLI retry shall be attempted
2194 * by invoking the lpfc_els_retry() routine. Otherwise, the state
2195 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
2196 * ndlp to mark the PRLI completion.
2199 lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2200 struct lpfc_iocbq *rspiocb)
2202 struct lpfc_vport *vport = cmdiocb->vport;
2203 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2205 struct lpfc_nodelist *ndlp;
2207 /* we pass cmdiocb to state machine which needs rspiocb as well */
2208 cmdiocb->context_un.rsp_iocb = rspiocb;
2210 irsp = &(rspiocb->iocb);
2211 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2212 spin_lock_irq(shost->host_lock);
2213 ndlp->nlp_flag &= ~NLP_PRLI_SND;
2215 /* Driver supports multiple FC4 types. Counters matter. */
2216 vport->fc_prli_sent--;
2217 ndlp->fc4_prli_sent--;
2218 spin_unlock_irq(shost->host_lock);
2220 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2221 "PRLI cmpl: status:x%x/x%x did:x%x",
2222 irsp->ulpStatus, irsp->un.ulpWord[4],
2225 /* PRLI completes to NPort <nlp_DID> */
2226 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2227 "0103 PRLI completes to NPort x%06x "
2228 "Data: x%x x%x x%x x%x\n",
2229 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2230 vport->num_disc_nodes, ndlp->fc4_prli_sent);
2232 /* Check to see if link went down during discovery */
2233 if (lpfc_els_chk_latt(vport))
2236 if (irsp->ulpStatus) {
2237 /* Check for retry */
2238 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2239 /* ELS command is being retried */
2244 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2245 "2754 PRLI failure DID:%06X Status:x%x/x%x, "
2247 ndlp->nlp_DID, irsp->ulpStatus,
2248 irsp->un.ulpWord[4], ndlp->fc4_prli_sent);
2250 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2251 if (lpfc_error_lost_link(irsp))
2254 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2257 /* Good status, call state machine. However, if another
2258 * PRLI is outstanding, don't call the state machine
2259 * because final disposition to Mapped or Unmapped is
2262 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2267 lpfc_els_free_iocb(phba, cmdiocb);
2272 * lpfc_issue_els_prli - Issue a prli iocb command for a vport
2273 * @vport: pointer to a host virtual N_Port data structure.
2274 * @ndlp: pointer to a node-list data structure.
2275 * @retry: number of retries to the command IOCB.
2277 * This routine issues a Process Login (PRLI) ELS command for the
2278 * @vport. The PRLI service parameters are set up in the payload of the
2279 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
2280 * is put to the IOCB completion callback func field before invoking the
2281 * routine lpfc_sli_issue_iocb() to send out PRLI command.
2283 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2284 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2285 * will be stored into the context1 field of the IOCB for the completion
2286 * callback function to the PRLI ELS command.
2289 * 0 - successfully issued prli iocb command for @vport
2290 * 1 - failed to issue prli iocb command for @vport
2293 lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2296 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2297 struct lpfc_hba *phba = vport->phba;
2299 struct lpfc_nvme_prli *npr_nvme;
2300 struct lpfc_iocbq *elsiocb;
2303 u32 local_nlp_type, elscmd;
2306 * If we are in RSCN mode, the FC4 types supported from a
2307 * previous GFT_ID command may not be accurate. So, if we
2308 * are a NVME Initiator, always look for the possibility of
2309 * the remote NPort beng a NVME Target.
2311 if (phba->sli_rev == LPFC_SLI_REV4 &&
2312 vport->fc_flag & FC_RSCN_MODE &&
2313 vport->nvmei_support)
2314 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
2315 local_nlp_type = ndlp->nlp_fc4_type;
2317 /* This routine will issue 1 or 2 PRLIs, so zero all the ndlp
2318 * fields here before any of them can complete.
2320 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
2321 ndlp->nlp_type &= ~(NLP_NVME_TARGET | NLP_NVME_INITIATOR);
2322 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
2323 ndlp->nlp_flag &= ~(NLP_FIRSTBURST | NLP_NPR_2B_DISC);
2324 ndlp->nvme_fb_size = 0;
2327 if (local_nlp_type & NLP_FC4_FCP) {
2328 /* Payload is 4 + 16 = 20 x14 bytes. */
2329 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
2330 elscmd = ELS_CMD_PRLI;
2331 } else if (local_nlp_type & NLP_FC4_NVME) {
2332 /* Payload is 4 + 20 = 24 x18 bytes. */
2333 cmdsize = (sizeof(uint32_t) + sizeof(struct lpfc_nvme_prli));
2334 elscmd = ELS_CMD_NVMEPRLI;
2336 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2337 "3083 Unknown FC_TYPE x%x ndlp x%06x\n",
2338 ndlp->nlp_fc4_type, ndlp->nlp_DID);
2342 /* SLI3 ports don't support NVME. If this rport is a strict NVME
2343 * FC4 type, implicitly LOGO.
2345 if (phba->sli_rev == LPFC_SLI_REV3 &&
2346 ndlp->nlp_fc4_type == NLP_FC4_NVME) {
2347 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2348 "3088 Rport fc4 type 0x%x not supported by SLI3 adapter\n",
2350 lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM);
2354 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2355 ndlp->nlp_DID, elscmd);
2359 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2361 /* For PRLI request, remainder of payload is service parameters */
2362 memset(pcmd, 0, cmdsize);
2364 if (local_nlp_type & NLP_FC4_FCP) {
2365 /* Remainder of payload is FCP PRLI parameter page.
2366 * Note: this data structure is defined as
2367 * BE/LE in the structure definition so no
2368 * byte swap call is made.
2370 *((uint32_t *)(pcmd)) = ELS_CMD_PRLI;
2371 pcmd += sizeof(uint32_t);
2375 * If our firmware version is 3.20 or later,
2376 * set the following bits for FC-TAPE support.
2378 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
2379 npr->ConfmComplAllowed = 1;
2381 npr->TaskRetryIdReq = 1;
2383 npr->estabImagePair = 1;
2384 npr->readXferRdyDis = 1;
2385 if (vport->cfg_first_burst_size)
2386 npr->writeXferRdyDis = 1;
2388 /* For FCP support */
2389 npr->prliType = PRLI_FCP_TYPE;
2390 npr->initiatorFunc = 1;
2391 elsiocb->iocb_flag |= LPFC_PRLI_FCP_REQ;
2393 /* Remove FCP type - processed. */
2394 local_nlp_type &= ~NLP_FC4_FCP;
2395 } else if (local_nlp_type & NLP_FC4_NVME) {
2396 /* Remainder of payload is NVME PRLI parameter page.
2397 * This data structure is the newer definition that
2398 * uses bf macros so a byte swap is required.
2400 *((uint32_t *)(pcmd)) = ELS_CMD_NVMEPRLI;
2401 pcmd += sizeof(uint32_t);
2402 npr_nvme = (struct lpfc_nvme_prli *)pcmd;
2403 bf_set(prli_type_code, npr_nvme, PRLI_NVME_TYPE);
2404 bf_set(prli_estabImagePair, npr_nvme, 0); /* Should be 0 */
2406 /* Only initiators request first burst. */
2407 if ((phba->cfg_nvme_enable_fb) &&
2408 !phba->nvmet_support)
2409 bf_set(prli_fba, npr_nvme, 1);
2411 if (phba->nvmet_support) {
2412 bf_set(prli_tgt, npr_nvme, 1);
2413 bf_set(prli_disc, npr_nvme, 1);
2415 bf_set(prli_init, npr_nvme, 1);
2416 bf_set(prli_conf, npr_nvme, 1);
2419 npr_nvme->word1 = cpu_to_be32(npr_nvme->word1);
2420 npr_nvme->word4 = cpu_to_be32(npr_nvme->word4);
2421 elsiocb->iocb_flag |= LPFC_PRLI_NVME_REQ;
2423 /* Remove NVME type - processed. */
2424 local_nlp_type &= ~NLP_FC4_NVME;
2427 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2428 "Issue PRLI: did:x%x",
2429 ndlp->nlp_DID, 0, 0);
2431 phba->fc_stat.elsXmitPRLI++;
2432 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
2433 spin_lock_irq(shost->host_lock);
2434 ndlp->nlp_flag |= NLP_PRLI_SND;
2436 /* The vport counters are used for lpfc_scan_finished, but
2437 * the ndlp is used to track outstanding PRLIs for different
2440 vport->fc_prli_sent++;
2441 ndlp->fc4_prli_sent++;
2442 spin_unlock_irq(shost->host_lock);
2443 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2445 spin_lock_irq(shost->host_lock);
2446 ndlp->nlp_flag &= ~NLP_PRLI_SND;
2447 spin_unlock_irq(shost->host_lock);
2448 lpfc_els_free_iocb(phba, elsiocb);
2453 /* The driver supports 2 FC4 types. Make sure
2454 * a PRLI is issued for all types before exiting.
2456 if (phba->sli_rev == LPFC_SLI_REV4 &&
2457 local_nlp_type & (NLP_FC4_FCP | NLP_FC4_NVME))
2458 goto send_next_prli;
2464 * lpfc_rscn_disc - Perform rscn discovery for a vport
2465 * @vport: pointer to a host virtual N_Port data structure.
2467 * This routine performs Registration State Change Notification (RSCN)
2468 * discovery for a @vport. If the @vport's node port recovery count is not
2469 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
2470 * the nodes that need recovery. If none of the PLOGI were needed through
2471 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
2472 * invoked to check and handle possible more RSCN came in during the period
2473 * of processing the current ones.
2476 lpfc_rscn_disc(struct lpfc_vport *vport)
2478 lpfc_can_disctmo(vport);
2480 /* RSCN discovery */
2481 /* go thru NPR nodes and issue ELS PLOGIs */
2482 if (vport->fc_npr_cnt)
2483 if (lpfc_els_disc_plogi(vport))
2486 lpfc_end_rscn(vport);
2490 * lpfc_adisc_done - Complete the adisc phase of discovery
2491 * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
2493 * This function is called when the final ADISC is completed during discovery.
2494 * This function handles clearing link attention or issuing reg_vpi depending
2495 * on whether npiv is enabled. This function also kicks off the PLOGI phase of
2497 * This function is called with no locks held.
2500 lpfc_adisc_done(struct lpfc_vport *vport)
2502 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2503 struct lpfc_hba *phba = vport->phba;
2506 * For NPIV, cmpl_reg_vpi will set port_state to READY,
2507 * and continue discovery.
2509 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2510 !(vport->fc_flag & FC_RSCN_MODE) &&
2511 (phba->sli_rev < LPFC_SLI_REV4)) {
2512 /* The ADISCs are complete. Doesn't matter if they
2513 * succeeded or failed because the ADISC completion
2514 * routine guarantees to call the state machine and
2515 * the RPI is either unregistered (failed ADISC response)
2516 * or the RPI is still valid and the node is marked
2517 * mapped for a target. The exchanges should be in the
2518 * correct state. This code is specific to SLI3.
2520 lpfc_issue_clear_la(phba, vport);
2521 lpfc_issue_reg_vpi(phba, vport);
2525 * For SLI2, we need to set port_state to READY
2526 * and continue discovery.
2528 if (vport->port_state < LPFC_VPORT_READY) {
2529 /* If we get here, there is nothing to ADISC */
2530 lpfc_issue_clear_la(phba, vport);
2531 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
2532 vport->num_disc_nodes = 0;
2533 /* go thru NPR list, issue ELS PLOGIs */
2534 if (vport->fc_npr_cnt)
2535 lpfc_els_disc_plogi(vport);
2536 if (!vport->num_disc_nodes) {
2537 spin_lock_irq(shost->host_lock);
2538 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2539 spin_unlock_irq(shost->host_lock);
2540 lpfc_can_disctmo(vport);
2541 lpfc_end_rscn(vport);
2544 vport->port_state = LPFC_VPORT_READY;
2546 lpfc_rscn_disc(vport);
2550 * lpfc_more_adisc - Issue more adisc as needed
2551 * @vport: pointer to a host virtual N_Port data structure.
2553 * This routine determines whether there are more ndlps on a @vport
2554 * node list need to have Address Discover (ADISC) issued. If so, it will
2555 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
2556 * remaining nodes which need to have ADISC sent.
2559 lpfc_more_adisc(struct lpfc_vport *vport)
2561 if (vport->num_disc_nodes)
2562 vport->num_disc_nodes--;
2563 /* Continue discovery with <num_disc_nodes> ADISCs to go */
2564 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2565 "0210 Continue discovery with %d ADISCs to go "
2566 "Data: x%x x%x x%x\n",
2567 vport->num_disc_nodes, vport->fc_adisc_cnt,
2568 vport->fc_flag, vport->port_state);
2569 /* Check to see if there are more ADISCs to be sent */
2570 if (vport->fc_flag & FC_NLP_MORE) {
2571 lpfc_set_disctmo(vport);
2572 /* go thru NPR nodes and issue any remaining ELS ADISCs */
2573 lpfc_els_disc_adisc(vport);
2575 if (!vport->num_disc_nodes)
2576 lpfc_adisc_done(vport);
2581 * lpfc_cmpl_els_adisc - Completion callback function for adisc
2582 * @phba: pointer to lpfc hba data structure.
2583 * @cmdiocb: pointer to lpfc command iocb data structure.
2584 * @rspiocb: pointer to lpfc response iocb data structure.
2586 * This routine is the completion function for issuing the Address Discover
2587 * (ADISC) command. It first checks to see whether link went down during
2588 * the discovery process. If so, the node will be marked as node port
2589 * recovery for issuing discover IOCB by the link attention handler and
2590 * exit. Otherwise, the response status is checked. If error was reported
2591 * in the response status, the ADISC command shall be retried by invoking
2592 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
2593 * the response status, the state machine is invoked to set transition
2594 * with respect to NLP_EVT_CMPL_ADISC event.
2597 lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2598 struct lpfc_iocbq *rspiocb)
2600 struct lpfc_vport *vport = cmdiocb->vport;
2601 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2603 struct lpfc_nodelist *ndlp;
2606 /* we pass cmdiocb to state machine which needs rspiocb as well */
2607 cmdiocb->context_un.rsp_iocb = rspiocb;
2609 irsp = &(rspiocb->iocb);
2610 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2612 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2613 "ADISC cmpl: status:x%x/x%x did:x%x",
2614 irsp->ulpStatus, irsp->un.ulpWord[4],
2617 /* Since ndlp can be freed in the disc state machine, note if this node
2618 * is being used during discovery.
2620 spin_lock_irq(shost->host_lock);
2621 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
2622 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
2623 spin_unlock_irq(shost->host_lock);
2624 /* ADISC completes to NPort <nlp_DID> */
2625 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2626 "0104 ADISC completes to NPort x%x "
2627 "Data: x%x x%x x%x x%x x%x\n",
2628 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2629 irsp->ulpTimeout, disc, vport->num_disc_nodes);
2630 /* Check to see if link went down during discovery */
2631 if (lpfc_els_chk_latt(vport)) {
2632 spin_lock_irq(shost->host_lock);
2633 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2634 spin_unlock_irq(shost->host_lock);
2638 if (irsp->ulpStatus) {
2639 /* Check for retry */
2640 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2641 /* ELS command is being retried */
2643 spin_lock_irq(shost->host_lock);
2644 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2645 spin_unlock_irq(shost->host_lock);
2646 lpfc_set_disctmo(vport);
2651 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2652 "2755 ADISC failure DID:%06X Status:x%x/x%x\n",
2653 ndlp->nlp_DID, irsp->ulpStatus,
2654 irsp->un.ulpWord[4]);
2655 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2656 if (!lpfc_error_lost_link(irsp))
2657 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2658 NLP_EVT_CMPL_ADISC);
2660 /* Good status, call state machine */
2661 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2662 NLP_EVT_CMPL_ADISC);
2664 /* Check to see if there are more ADISCs to be sent */
2665 if (disc && vport->num_disc_nodes)
2666 lpfc_more_adisc(vport);
2668 lpfc_els_free_iocb(phba, cmdiocb);
2673 * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
2674 * @vport: pointer to a virtual N_Port data structure.
2675 * @ndlp: pointer to a node-list data structure.
2676 * @retry: number of retries to the command IOCB.
2678 * This routine issues an Address Discover (ADISC) for an @ndlp on a
2679 * @vport. It prepares the payload of the ADISC ELS command, updates the
2680 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
2681 * to issue the ADISC ELS command.
2683 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2684 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2685 * will be stored into the context1 field of the IOCB for the completion
2686 * callback function to the ADISC ELS command.
2689 * 0 - successfully issued adisc
2690 * 1 - failed to issue adisc
2693 lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2696 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2697 struct lpfc_hba *phba = vport->phba;
2699 struct lpfc_iocbq *elsiocb;
2703 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
2704 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2705 ndlp->nlp_DID, ELS_CMD_ADISC);
2709 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2711 /* For ADISC request, remainder of payload is service parameters */
2712 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
2713 pcmd += sizeof(uint32_t);
2715 /* Fill in ADISC payload */
2716 ap = (ADISC *) pcmd;
2717 ap->hardAL_PA = phba->fc_pref_ALPA;
2718 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2719 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
2720 ap->DID = be32_to_cpu(vport->fc_myDID);
2722 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2723 "Issue ADISC: did:x%x",
2724 ndlp->nlp_DID, 0, 0);
2726 phba->fc_stat.elsXmitADISC++;
2727 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
2728 spin_lock_irq(shost->host_lock);
2729 ndlp->nlp_flag |= NLP_ADISC_SND;
2730 spin_unlock_irq(shost->host_lock);
2731 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2733 spin_lock_irq(shost->host_lock);
2734 ndlp->nlp_flag &= ~NLP_ADISC_SND;
2735 spin_unlock_irq(shost->host_lock);
2736 lpfc_els_free_iocb(phba, elsiocb);
2743 * lpfc_cmpl_els_logo - Completion callback function for logo
2744 * @phba: pointer to lpfc hba data structure.
2745 * @cmdiocb: pointer to lpfc command iocb data structure.
2746 * @rspiocb: pointer to lpfc response iocb data structure.
2748 * This routine is the completion function for issuing the ELS Logout (LOGO)
2749 * command. If no error status was reported from the LOGO response, the
2750 * state machine of the associated ndlp shall be invoked for transition with
2751 * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
2752 * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
2755 lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2756 struct lpfc_iocbq *rspiocb)
2758 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2759 struct lpfc_vport *vport = ndlp->vport;
2760 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2762 struct lpfcMboxq *mbox;
2763 unsigned long flags;
2764 uint32_t skip_recovery = 0;
2766 /* we pass cmdiocb to state machine which needs rspiocb as well */
2767 cmdiocb->context_un.rsp_iocb = rspiocb;
2769 irsp = &(rspiocb->iocb);
2770 spin_lock_irq(shost->host_lock);
2771 ndlp->nlp_flag &= ~NLP_LOGO_SND;
2772 spin_unlock_irq(shost->host_lock);
2774 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2775 "LOGO cmpl: status:x%x/x%x did:x%x",
2776 irsp->ulpStatus, irsp->un.ulpWord[4],
2779 /* LOGO completes to NPort <nlp_DID> */
2780 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2781 "0105 LOGO completes to NPort x%x "
2782 "Data: x%x x%x x%x x%x\n",
2783 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2784 irsp->ulpTimeout, vport->num_disc_nodes);
2786 if (lpfc_els_chk_latt(vport)) {
2791 /* Check to see if link went down during discovery */
2792 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
2793 /* NLP_EVT_DEVICE_RM should unregister the RPI
2794 * which should abort all outstanding IOs.
2796 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2802 /* The LOGO will not be retried on failure. A LOGO was
2803 * issued to the remote rport and a ACC or RJT or no Answer are
2804 * all acceptable. Note the failure and move forward with
2805 * discovery. The PLOGI will retry.
2807 if (irsp->ulpStatus) {
2809 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2810 "2756 LOGO failure, No Retry DID:%06X Status:x%x/x%x\n",
2811 ndlp->nlp_DID, irsp->ulpStatus,
2812 irsp->un.ulpWord[4]);
2813 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2814 if (lpfc_error_lost_link(irsp)) {
2820 /* Call state machine. This will unregister the rpi if needed. */
2821 lpfc_disc_state_machine(vport, ndlp, cmdiocb, NLP_EVT_CMPL_LOGO);
2824 lpfc_els_free_iocb(phba, cmdiocb);
2825 /* If we are in pt2pt mode, we could rcv new S_ID on PLOGI */
2826 if ((vport->fc_flag & FC_PT2PT) &&
2827 !(vport->fc_flag & FC_PT2PT_PLOGI)) {
2828 phba->pport->fc_myDID = 0;
2830 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
2831 (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
2832 if (phba->nvmet_support)
2833 lpfc_nvmet_update_targetport(phba);
2835 lpfc_nvme_update_localport(phba->pport);
2838 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2840 lpfc_config_link(phba, mbox);
2841 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
2842 mbox->vport = vport;
2843 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) ==
2845 mempool_free(mbox, phba->mbox_mem_pool);
2852 * If the node is a target, the handling attempts to recover the port.
2853 * For any other port type, the rpi is unregistered as an implicit
2856 if (ndlp->nlp_type & (NLP_FCP_TARGET | NLP_NVME_TARGET) &&
2857 skip_recovery == 0) {
2858 lpfc_cancel_retry_delay_tmo(vport, ndlp);
2859 spin_lock_irqsave(shost->host_lock, flags);
2860 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2861 spin_unlock_irqrestore(shost->host_lock, flags);
2863 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2864 "3187 LOGO completes to NPort x%x: Start "
2865 "Recovery Data: x%x x%x x%x x%x\n",
2866 ndlp->nlp_DID, irsp->ulpStatus,
2867 irsp->un.ulpWord[4], irsp->ulpTimeout,
2868 vport->num_disc_nodes);
2869 lpfc_disc_start(vport);
2875 * lpfc_issue_els_logo - Issue a logo to an node on a vport
2876 * @vport: pointer to a virtual N_Port data structure.
2877 * @ndlp: pointer to a node-list data structure.
2878 * @retry: number of retries to the command IOCB.
2880 * This routine constructs and issues an ELS Logout (LOGO) iocb command
2881 * to a remote node, referred by an @ndlp on a @vport. It constructs the
2882 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
2883 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
2885 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2886 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2887 * will be stored into the context1 field of the IOCB for the completion
2888 * callback function to the LOGO ELS command.
2890 * Callers of this routine are expected to unregister the RPI first
2893 * 0 - successfully issued logo
2894 * 1 - failed to issue logo
2897 lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2900 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2901 struct lpfc_hba *phba = vport->phba;
2902 struct lpfc_iocbq *elsiocb;
2907 spin_lock_irq(shost->host_lock);
2908 if (ndlp->nlp_flag & NLP_LOGO_SND) {
2909 spin_unlock_irq(shost->host_lock);
2912 spin_unlock_irq(shost->host_lock);
2914 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
2915 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2916 ndlp->nlp_DID, ELS_CMD_LOGO);
2920 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2921 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
2922 pcmd += sizeof(uint32_t);
2924 /* Fill in LOGO payload */
2925 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
2926 pcmd += sizeof(uint32_t);
2927 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
2929 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2930 "Issue LOGO: did:x%x",
2931 ndlp->nlp_DID, 0, 0);
2933 phba->fc_stat.elsXmitLOGO++;
2934 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
2935 spin_lock_irq(shost->host_lock);
2936 ndlp->nlp_flag |= NLP_LOGO_SND;
2937 ndlp->nlp_flag &= ~NLP_ISSUE_LOGO;
2938 spin_unlock_irq(shost->host_lock);
2939 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
2940 if (rc == IOCB_ERROR) {
2941 spin_lock_irq(shost->host_lock);
2942 ndlp->nlp_flag &= ~NLP_LOGO_SND;
2943 spin_unlock_irq(shost->host_lock);
2944 lpfc_els_free_iocb(phba, elsiocb);
2948 spin_lock_irq(shost->host_lock);
2949 ndlp->nlp_prev_state = ndlp->nlp_state;
2950 spin_unlock_irq(shost->host_lock);
2951 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
2956 * lpfc_cmpl_els_cmd - Completion callback function for generic els command
2957 * @phba: pointer to lpfc hba data structure.
2958 * @cmdiocb: pointer to lpfc command iocb data structure.
2959 * @rspiocb: pointer to lpfc response iocb data structure.
2961 * This routine is a generic completion callback function for ELS commands.
2962 * Specifically, it is the callback function which does not need to perform
2963 * any command specific operations. It is currently used by the ELS command
2964 * issuing routines for the ELS State Change Request (SCR),
2965 * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution
2966 * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than
2967 * certain debug loggings, this callback function simply invokes the
2968 * lpfc_els_chk_latt() routine to check whether link went down during the
2969 * discovery process.
2972 lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2973 struct lpfc_iocbq *rspiocb)
2975 struct lpfc_vport *vport = cmdiocb->vport;
2978 irsp = &rspiocb->iocb;
2980 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2981 "ELS cmd cmpl: status:x%x/x%x did:x%x",
2982 irsp->ulpStatus, irsp->un.ulpWord[4],
2983 irsp->un.elsreq64.remoteID);
2984 /* ELS cmd tag <ulpIoTag> completes */
2985 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2986 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
2987 irsp->ulpIoTag, irsp->ulpStatus,
2988 irsp->un.ulpWord[4], irsp->ulpTimeout);
2989 /* Check to see if link went down during discovery */
2990 lpfc_els_chk_latt(vport);
2991 lpfc_els_free_iocb(phba, cmdiocb);
2996 * lpfc_issue_els_scr - Issue a scr to an node on a vport
2997 * @vport: pointer to a host virtual N_Port data structure.
2998 * @nportid: N_Port identifier to the remote node.
2999 * @retry: number of retries to the command IOCB.
3001 * This routine issues a State Change Request (SCR) to a fabric node
3002 * on a @vport. The remote node @nportid is passed into the function. It
3003 * first search the @vport node list to find the matching ndlp. If no such
3004 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
3005 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
3006 * routine is invoked to send the SCR IOCB.
3008 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3009 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3010 * will be stored into the context1 field of the IOCB for the completion
3011 * callback function to the SCR ELS command.
3014 * 0 - Successfully issued scr command
3015 * 1 - Failed to issue scr command
3018 lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
3020 struct lpfc_hba *phba = vport->phba;
3021 struct lpfc_iocbq *elsiocb;
3024 struct lpfc_nodelist *ndlp;
3026 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
3028 ndlp = lpfc_findnode_did(vport, nportid);
3030 ndlp = lpfc_nlp_init(vport, nportid);
3033 lpfc_enqueue_node(vport, ndlp);
3034 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
3035 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
3040 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
3041 ndlp->nlp_DID, ELS_CMD_SCR);
3044 /* This will trigger the release of the node just
3051 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3053 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
3054 pcmd += sizeof(uint32_t);
3056 /* For SCR, remainder of payload is SCR parameter page */
3057 memset(pcmd, 0, sizeof(SCR));
3058 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
3060 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3061 "Issue SCR: did:x%x",
3062 ndlp->nlp_DID, 0, 0);
3064 phba->fc_stat.elsXmitSCR++;
3065 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
3066 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
3068 /* The additional lpfc_nlp_put will cause the following
3069 * lpfc_els_free_iocb routine to trigger the rlease of
3073 lpfc_els_free_iocb(phba, elsiocb);
3076 /* This will cause the callback-function lpfc_cmpl_els_cmd to
3077 * trigger the release of node.
3079 if (!(vport->fc_flag & FC_PT2PT))
3085 * lpfc_issue_els_farpr - Issue a farp to an node on a vport
3086 * @vport: pointer to a host virtual N_Port data structure.
3087 * @nportid: N_Port identifier to the remote node.
3088 * @retry: number of retries to the command IOCB.
3090 * This routine issues a Fibre Channel Address Resolution Response
3091 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
3092 * is passed into the function. It first search the @vport node list to find
3093 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
3094 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
3095 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
3097 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3098 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3099 * will be stored into the context1 field of the IOCB for the completion
3100 * callback function to the PARPR ELS command.
3103 * 0 - Successfully issued farpr command
3104 * 1 - Failed to issue farpr command
3107 lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
3109 struct lpfc_hba *phba = vport->phba;
3110 struct lpfc_iocbq *elsiocb;
3115 struct lpfc_nodelist *ondlp;
3116 struct lpfc_nodelist *ndlp;
3118 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
3120 ndlp = lpfc_findnode_did(vport, nportid);
3122 ndlp = lpfc_nlp_init(vport, nportid);
3125 lpfc_enqueue_node(vport, ndlp);
3126 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
3127 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
3132 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
3133 ndlp->nlp_DID, ELS_CMD_RNID);
3135 /* This will trigger the release of the node just
3142 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3144 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
3145 pcmd += sizeof(uint32_t);
3147 /* Fill in FARPR payload */
3148 fp = (FARP *) (pcmd);
3149 memset(fp, 0, sizeof(FARP));
3150 lp = (uint32_t *) pcmd;
3151 *lp++ = be32_to_cpu(nportid);
3152 *lp++ = be32_to_cpu(vport->fc_myDID);
3154 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
3156 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
3157 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
3158 ondlp = lpfc_findnode_did(vport, nportid);
3159 if (ondlp && NLP_CHK_NODE_ACT(ondlp)) {
3160 memcpy(&fp->OportName, &ondlp->nlp_portname,
3161 sizeof(struct lpfc_name));
3162 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
3163 sizeof(struct lpfc_name));
3166 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3167 "Issue FARPR: did:x%x",
3168 ndlp->nlp_DID, 0, 0);
3170 phba->fc_stat.elsXmitFARPR++;
3171 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
3172 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
3174 /* The additional lpfc_nlp_put will cause the following
3175 * lpfc_els_free_iocb routine to trigger the release of
3179 lpfc_els_free_iocb(phba, elsiocb);
3182 /* This will cause the callback-function lpfc_cmpl_els_cmd to
3183 * trigger the release of the node.
3190 * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
3191 * @vport: pointer to a host virtual N_Port data structure.
3192 * @nlp: pointer to a node-list data structure.
3194 * This routine cancels the timer with a delayed IOCB-command retry for
3195 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
3196 * removes the ELS retry event if it presents. In addition, if the
3197 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
3198 * commands are sent for the @vport's nodes that require issuing discovery
3202 lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
3204 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3205 struct lpfc_work_evt *evtp;
3207 if (!(nlp->nlp_flag & NLP_DELAY_TMO))
3209 spin_lock_irq(shost->host_lock);
3210 nlp->nlp_flag &= ~NLP_DELAY_TMO;
3211 spin_unlock_irq(shost->host_lock);
3212 del_timer_sync(&nlp->nlp_delayfunc);
3213 nlp->nlp_last_elscmd = 0;
3214 if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
3215 list_del_init(&nlp->els_retry_evt.evt_listp);
3216 /* Decrement nlp reference count held for the delayed retry */
3217 evtp = &nlp->els_retry_evt;
3218 lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
3220 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
3221 spin_lock_irq(shost->host_lock);
3222 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
3223 spin_unlock_irq(shost->host_lock);
3224 if (vport->num_disc_nodes) {
3225 if (vport->port_state < LPFC_VPORT_READY) {
3226 /* Check if there are more ADISCs to be sent */
3227 lpfc_more_adisc(vport);
3229 /* Check if there are more PLOGIs to be sent */
3230 lpfc_more_plogi(vport);
3231 if (vport->num_disc_nodes == 0) {
3232 spin_lock_irq(shost->host_lock);
3233 vport->fc_flag &= ~FC_NDISC_ACTIVE;
3234 spin_unlock_irq(shost->host_lock);
3235 lpfc_can_disctmo(vport);
3236 lpfc_end_rscn(vport);
3245 * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
3246 * @ptr: holder for the pointer to the timer function associated data (ndlp).
3248 * This routine is invoked by the ndlp delayed-function timer to check
3249 * whether there is any pending ELS retry event(s) with the node. If not, it
3250 * simply returns. Otherwise, if there is at least one ELS delayed event, it
3251 * adds the delayed events to the HBA work list and invokes the
3252 * lpfc_worker_wake_up() routine to wake up worker thread to process the
3253 * event. Note that lpfc_nlp_get() is called before posting the event to
3254 * the work list to hold reference count of ndlp so that it guarantees the
3255 * reference to ndlp will still be available when the worker thread gets
3256 * to the event associated with the ndlp.
3259 lpfc_els_retry_delay(struct timer_list *t)
3261 struct lpfc_nodelist *ndlp = from_timer(ndlp, t, nlp_delayfunc);
3262 struct lpfc_vport *vport = ndlp->vport;
3263 struct lpfc_hba *phba = vport->phba;
3264 unsigned long flags;
3265 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
3267 spin_lock_irqsave(&phba->hbalock, flags);
3268 if (!list_empty(&evtp->evt_listp)) {
3269 spin_unlock_irqrestore(&phba->hbalock, flags);
3273 /* We need to hold the node by incrementing the reference
3274 * count until the queued work is done
3276 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
3277 if (evtp->evt_arg1) {
3278 evtp->evt = LPFC_EVT_ELS_RETRY;
3279 list_add_tail(&evtp->evt_listp, &phba->work_list);
3280 lpfc_worker_wake_up(phba);
3282 spin_unlock_irqrestore(&phba->hbalock, flags);
3287 * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
3288 * @ndlp: pointer to a node-list data structure.
3290 * This routine is the worker-thread handler for processing the @ndlp delayed
3291 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
3292 * the last ELS command from the associated ndlp and invokes the proper ELS
3293 * function according to the delayed ELS command to retry the command.
3296 lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
3298 struct lpfc_vport *vport = ndlp->vport;
3299 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3300 uint32_t cmd, retry;
3302 spin_lock_irq(shost->host_lock);
3303 cmd = ndlp->nlp_last_elscmd;
3304 ndlp->nlp_last_elscmd = 0;
3306 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
3307 spin_unlock_irq(shost->host_lock);
3311 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
3312 spin_unlock_irq(shost->host_lock);
3314 * If a discovery event readded nlp_delayfunc after timer
3315 * firing and before processing the timer, cancel the
3318 del_timer_sync(&ndlp->nlp_delayfunc);
3319 retry = ndlp->nlp_retry;
3320 ndlp->nlp_retry = 0;
3324 lpfc_issue_els_flogi(vport, ndlp, retry);
3327 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
3328 ndlp->nlp_prev_state = ndlp->nlp_state;
3329 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
3333 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
3334 ndlp->nlp_prev_state = ndlp->nlp_state;
3335 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
3339 case ELS_CMD_NVMEPRLI:
3340 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
3341 ndlp->nlp_prev_state = ndlp->nlp_state;
3342 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
3346 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
3347 ndlp->nlp_prev_state = ndlp->nlp_state;
3348 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
3352 if (!(vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI))
3353 lpfc_issue_els_fdisc(vport, ndlp, retry);
3360 * lpfc_link_reset - Issue link reset
3361 * @vport: pointer to a virtual N_Port data structure.
3363 * This routine performs link reset by sending INIT_LINK mailbox command.
3364 * For SLI-3 adapter, link attention interrupt is enabled before issuing
3365 * INIT_LINK mailbox command.
3368 * 0 - Link reset initiated successfully
3369 * 1 - Failed to initiate link reset
3372 lpfc_link_reset(struct lpfc_vport *vport)
3374 struct lpfc_hba *phba = vport->phba;
3379 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3380 "2851 Attempt link reset\n");
3381 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3383 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
3384 "2852 Failed to allocate mbox memory");
3388 /* Enable Link attention interrupts */
3389 if (phba->sli_rev <= LPFC_SLI_REV3) {
3390 spin_lock_irq(&phba->hbalock);
3391 phba->sli.sli_flag |= LPFC_PROCESS_LA;
3392 control = readl(phba->HCregaddr);
3393 control |= HC_LAINT_ENA;
3394 writel(control, phba->HCregaddr);
3395 readl(phba->HCregaddr); /* flush */
3396 spin_unlock_irq(&phba->hbalock);
3399 lpfc_init_link(phba, mbox, phba->cfg_topology,
3400 phba->cfg_link_speed);
3401 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
3402 mbox->vport = vport;
3403 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
3404 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
3405 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
3406 "2853 Failed to issue INIT_LINK "
3407 "mbox command, rc:x%x\n", rc);
3408 mempool_free(mbox, phba->mbox_mem_pool);
3416 * lpfc_els_retry - Make retry decision on an els command iocb
3417 * @phba: pointer to lpfc hba data structure.
3418 * @cmdiocb: pointer to lpfc command iocb data structure.
3419 * @rspiocb: pointer to lpfc response iocb data structure.
3421 * This routine makes a retry decision on an ELS command IOCB, which has
3422 * failed. The following ELS IOCBs use this function for retrying the command
3423 * when previously issued command responsed with error status: FLOGI, PLOGI,
3424 * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
3425 * returned error status, it makes the decision whether a retry shall be
3426 * issued for the command, and whether a retry shall be made immediately or
3427 * delayed. In the former case, the corresponding ELS command issuing-function
3428 * is called to retry the command. In the later case, the ELS command shall
3429 * be posted to the ndlp delayed event and delayed function timer set to the
3430 * ndlp for the delayed command issusing.
3433 * 0 - No retry of els command is made
3434 * 1 - Immediate or delayed retry of els command is made
3437 lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3438 struct lpfc_iocbq *rspiocb)
3440 struct lpfc_vport *vport = cmdiocb->vport;
3441 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3442 IOCB_t *irsp = &rspiocb->iocb;
3443 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3444 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3447 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
3451 int link_reset = 0, rc;
3454 /* Note: context2 may be 0 for internal driver abort
3455 * of delays ELS command.
3458 if (pcmd && pcmd->virt) {
3459 elscmd = (uint32_t *) (pcmd->virt);
3463 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
3464 did = ndlp->nlp_DID;
3466 /* We should only hit this case for retrying PLOGI */
3467 did = irsp->un.elsreq64.remoteID;
3468 ndlp = lpfc_findnode_did(vport, did);
3469 if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp))
3470 && (cmd != ELS_CMD_PLOGI))
3474 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3475 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
3476 *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
3478 switch (irsp->ulpStatus) {
3479 case IOSTAT_FCP_RSP_ERROR:
3481 case IOSTAT_REMOTE_STOP:
3482 if (phba->sli_rev == LPFC_SLI_REV4) {
3483 /* This IO was aborted by the target, we don't
3484 * know the rxid and because we did not send the
3485 * ABTS we cannot generate and RRQ.
3487 lpfc_set_rrq_active(phba, ndlp,
3488 cmdiocb->sli4_lxritag, 0, 0);
3491 case IOSTAT_LOCAL_REJECT:
3492 switch ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK)) {
3493 case IOERR_LOOP_OPEN_FAILURE:
3494 if (cmd == ELS_CMD_FLOGI) {
3495 if (PCI_DEVICE_ID_HORNET ==
3496 phba->pcidev->device) {
3497 phba->fc_topology = LPFC_TOPOLOGY_LOOP;
3498 phba->pport->fc_myDID = 0;
3499 phba->alpa_map[0] = 0;
3500 phba->alpa_map[1] = 0;
3503 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
3508 case IOERR_ILLEGAL_COMMAND:
3509 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3510 "0124 Retry illegal cmd x%x "
3511 "retry:x%x delay:x%x\n",
3512 cmd, cmdiocb->retry, delay);
3514 /* All command's retry policy */
3516 if (cmdiocb->retry > 2)
3520 case IOERR_NO_RESOURCES:
3521 logerr = 1; /* HBA out of resources */
3523 if (cmdiocb->retry > 100)
3528 case IOERR_ILLEGAL_FRAME:
3533 case IOERR_INVALID_RPI:
3534 if (cmd == ELS_CMD_PLOGI &&
3535 did == NameServer_DID) {
3536 /* Continue forever if plogi to */
3537 /* the nameserver fails */
3544 case IOERR_SEQUENCE_TIMEOUT:
3545 if (cmd == ELS_CMD_PLOGI &&
3546 did == NameServer_DID &&
3547 (cmdiocb->retry + 1) == maxretry) {
3548 /* Reset the Link */
3558 case IOSTAT_NPORT_RJT:
3559 case IOSTAT_FABRIC_RJT:
3560 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
3566 case IOSTAT_NPORT_BSY:
3567 case IOSTAT_FABRIC_BSY:
3568 logerr = 1; /* Fabric / Remote NPort out of resources */
3573 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
3574 /* Added for Vendor specifc support
3575 * Just keep retrying for these Rsn / Exp codes
3577 switch (stat.un.b.lsRjtRsnCode) {
3578 case LSRJT_UNABLE_TPC:
3579 /* The driver has a VALID PLOGI but the rport has
3580 * rejected the PRLI - can't do it now. Delay
3581 * for 1 second and try again - don't care about
3584 if (cmd == ELS_CMD_PRLI || cmd == ELS_CMD_NVMEPRLI) {
3586 maxretry = lpfc_max_els_tries + 1;
3591 /* Legacy bug fix code for targets with PLOGI delays. */
3592 if (stat.un.b.lsRjtRsnCodeExp ==
3593 LSEXP_CMD_IN_PROGRESS) {
3594 if (cmd == ELS_CMD_PLOGI) {
3601 if (stat.un.b.lsRjtRsnCodeExp ==
3602 LSEXP_CANT_GIVE_DATA) {
3603 if (cmd == ELS_CMD_PLOGI) {
3610 if (cmd == ELS_CMD_PLOGI) {
3612 maxretry = lpfc_max_els_tries + 1;
3616 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
3617 (cmd == ELS_CMD_FDISC) &&
3618 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
3619 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3620 "0125 FDISC Failed (x%x). "
3621 "Fabric out of resources\n",
3622 stat.un.lsRjtError);
3623 lpfc_vport_set_state(vport,
3624 FC_VPORT_NO_FABRIC_RSCS);
3628 case LSRJT_LOGICAL_BSY:
3629 if ((cmd == ELS_CMD_PLOGI) ||
3630 (cmd == ELS_CMD_PRLI) ||
3631 (cmd == ELS_CMD_NVMEPRLI)) {
3634 } else if (cmd == ELS_CMD_FDISC) {
3635 /* FDISC retry policy */
3637 if (cmdiocb->retry >= 32)
3643 case LSRJT_LOGICAL_ERR:
3644 /* There are some cases where switches return this
3645 * error when they are not ready and should be returning
3646 * Logical Busy. We should delay every time.
3648 if (cmd == ELS_CMD_FDISC &&
3649 stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
3653 } else if (cmd == ELS_CMD_FLOGI &&
3654 stat.un.b.lsRjtRsnCodeExp ==
3655 LSEXP_NOTHING_MORE) {
3656 vport->fc_sparam.cmn.bbRcvSizeMsb &= 0xf;
3658 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3659 "0820 FLOGI Failed (x%x). "
3660 "BBCredit Not Supported\n",
3661 stat.un.lsRjtError);
3665 case LSRJT_PROTOCOL_ERR:
3666 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
3667 (cmd == ELS_CMD_FDISC) &&
3668 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
3669 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
3671 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3672 "0122 FDISC Failed (x%x). "
3673 "Fabric Detected Bad WWN\n",
3674 stat.un.lsRjtError);
3675 lpfc_vport_set_state(vport,
3676 FC_VPORT_FABRIC_REJ_WWN);
3679 case LSRJT_VENDOR_UNIQUE:
3680 if ((stat.un.b.vendorUnique == 0x45) &&
3681 (cmd == ELS_CMD_FLOGI)) {
3685 case LSRJT_CMD_UNSUPPORTED:
3686 /* lpfc nvmet returns this type of LS_RJT when it
3687 * receives an FCP PRLI because lpfc nvmet only
3688 * support NVME. ELS request is terminated for FCP4
3691 if (stat.un.b.lsRjtRsnCodeExp ==
3692 LSEXP_REQ_UNSUPPORTED && cmd == ELS_CMD_PRLI) {
3693 spin_lock_irq(shost->host_lock);
3694 ndlp->nlp_flag |= NLP_FCP_PRLI_RJT;
3695 spin_unlock_irq(shost->host_lock);
3703 case IOSTAT_INTERMED_RSP:
3712 rc = lpfc_link_reset(vport);
3714 /* Do not give up. Retry PLOGI one more time and attempt
3715 * link reset if PLOGI fails again.
3724 if (did == FDMI_DID)
3727 if ((cmd == ELS_CMD_FLOGI) &&
3728 (phba->fc_topology != LPFC_TOPOLOGY_LOOP) &&
3729 !lpfc_error_lost_link(irsp)) {
3730 /* FLOGI retry policy */
3732 /* retry FLOGI forever */
3733 if (phba->link_flag != LS_LOOPBACK_MODE)
3738 if (cmdiocb->retry >= 100)
3740 else if (cmdiocb->retry >= 32)
3742 } else if ((cmd == ELS_CMD_FDISC) && !lpfc_error_lost_link(irsp)) {
3743 /* retry FDISCs every second up to devloss */
3745 maxretry = vport->cfg_devloss_tmo;
3750 if (maxretry && (cmdiocb->retry >= maxretry)) {
3751 phba->fc_stat.elsRetryExceeded++;
3755 if ((vport->load_flag & FC_UNLOADING) != 0)
3760 if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) {
3761 /* Stop retrying PLOGI and FDISC if in FCF discovery */
3762 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
3763 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3764 "2849 Stop retry ELS command "
3765 "x%x to remote NPORT x%x, "
3766 "Data: x%x x%x\n", cmd, did,
3767 cmdiocb->retry, delay);
3772 /* Retry ELS command <elsCmd> to remote NPORT <did> */
3773 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3774 "0107 Retry ELS command x%x to remote "
3775 "NPORT x%x Data: x%x x%x\n",
3776 cmd, did, cmdiocb->retry, delay);
3778 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
3779 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
3780 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
3781 IOERR_NO_RESOURCES))) {
3782 /* Don't reset timer for no resources */
3784 /* If discovery / RSCN timer is running, reset it */
3785 if (timer_pending(&vport->fc_disctmo) ||
3786 (vport->fc_flag & FC_RSCN_MODE))
3787 lpfc_set_disctmo(vport);
3790 phba->fc_stat.elsXmitRetry++;
3791 if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) {
3792 phba->fc_stat.elsDelayRetry++;
3793 ndlp->nlp_retry = cmdiocb->retry;
3795 /* delay is specified in milliseconds */
3796 mod_timer(&ndlp->nlp_delayfunc,
3797 jiffies + msecs_to_jiffies(delay));
3798 spin_lock_irq(shost->host_lock);
3799 ndlp->nlp_flag |= NLP_DELAY_TMO;
3800 spin_unlock_irq(shost->host_lock);
3802 ndlp->nlp_prev_state = ndlp->nlp_state;
3803 if ((cmd == ELS_CMD_PRLI) ||
3804 (cmd == ELS_CMD_NVMEPRLI))
3805 lpfc_nlp_set_state(vport, ndlp,
3806 NLP_STE_PRLI_ISSUE);
3808 lpfc_nlp_set_state(vport, ndlp,
3810 ndlp->nlp_last_elscmd = cmd;
3816 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
3819 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
3822 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
3823 ndlp->nlp_prev_state = ndlp->nlp_state;
3824 lpfc_nlp_set_state(vport, ndlp,
3825 NLP_STE_PLOGI_ISSUE);
3827 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
3830 ndlp->nlp_prev_state = ndlp->nlp_state;
3831 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
3832 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
3835 case ELS_CMD_NVMEPRLI:
3836 ndlp->nlp_prev_state = ndlp->nlp_state;
3837 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
3838 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
3841 ndlp->nlp_prev_state = ndlp->nlp_state;
3842 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
3843 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
3847 /* No retry ELS command <elsCmd> to remote NPORT <did> */
3849 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3850 "0137 No retry ELS command x%x to remote "
3851 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
3852 cmd, did, irsp->ulpStatus,
3853 irsp->un.ulpWord[4]);
3856 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3857 "0108 No retry ELS command x%x to remote "
3858 "NPORT x%x Retried:%d Error:x%x/%x\n",
3859 cmd, did, cmdiocb->retry, irsp->ulpStatus,
3860 irsp->un.ulpWord[4]);
3866 * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
3867 * @phba: pointer to lpfc hba data structure.
3868 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
3870 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
3871 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
3872 * checks to see whether there is a lpfc DMA buffer associated with the
3873 * response of the command IOCB. If so, it will be released before releasing
3874 * the lpfc DMA buffer associated with the IOCB itself.
3877 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3880 lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
3882 struct lpfc_dmabuf *buf_ptr;
3884 /* Free the response before processing the command. */
3885 if (!list_empty(&buf_ptr1->list)) {
3886 list_remove_head(&buf_ptr1->list, buf_ptr,
3889 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3892 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
3898 * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
3899 * @phba: pointer to lpfc hba data structure.
3900 * @buf_ptr: pointer to the lpfc dma buffer data structure.
3902 * This routine releases the lpfc Direct Memory Access (DMA) buffer
3903 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
3907 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3910 lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
3912 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3918 * lpfc_els_free_iocb - Free a command iocb and its associated resources
3919 * @phba: pointer to lpfc hba data structure.
3920 * @elsiocb: pointer to lpfc els command iocb data structure.
3922 * This routine frees a command IOCB and its associated resources. The
3923 * command IOCB data structure contains the reference to various associated
3924 * resources, these fields must be set to NULL if the associated reference
3926 * context1 - reference to ndlp
3927 * context2 - reference to cmd
3928 * context2->next - reference to rsp
3929 * context3 - reference to bpl
3931 * It first properly decrements the reference count held on ndlp for the
3932 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
3933 * set, it invokes the lpfc_els_free_data() routine to release the Direct
3934 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
3935 * adds the DMA buffer the @phba data structure for the delayed release.
3936 * If reference to the Buffer Pointer List (BPL) is present, the
3937 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
3938 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
3939 * invoked to release the IOCB data structure back to @phba IOCBQ list.
3942 * 0 - Success (currently, always return 0)
3945 lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
3947 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
3948 struct lpfc_nodelist *ndlp;
3950 ndlp = (struct lpfc_nodelist *)elsiocb->context1;
3952 if (ndlp->nlp_flag & NLP_DEFER_RM) {
3955 /* If the ndlp is not being used by another discovery
3958 if (!lpfc_nlp_not_used(ndlp)) {
3959 /* If ndlp is being used by another discovery
3960 * thread, just clear NLP_DEFER_RM
3962 ndlp->nlp_flag &= ~NLP_DEFER_RM;
3967 elsiocb->context1 = NULL;
3969 /* context2 = cmd, context2->next = rsp, context3 = bpl */
3970 if (elsiocb->context2) {
3971 if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
3972 /* Firmware could still be in progress of DMAing
3973 * payload, so don't free data buffer till after
3976 elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
3977 buf_ptr = elsiocb->context2;
3978 elsiocb->context2 = NULL;
3981 spin_lock_irq(&phba->hbalock);
3982 if (!list_empty(&buf_ptr->list)) {
3983 list_remove_head(&buf_ptr->list,
3984 buf_ptr1, struct lpfc_dmabuf,
3986 INIT_LIST_HEAD(&buf_ptr1->list);
3987 list_add_tail(&buf_ptr1->list,
3991 INIT_LIST_HEAD(&buf_ptr->list);
3992 list_add_tail(&buf_ptr->list, &phba->elsbuf);
3994 spin_unlock_irq(&phba->hbalock);
3997 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
3998 lpfc_els_free_data(phba, buf_ptr1);
3999 elsiocb->context2 = NULL;
4003 if (elsiocb->context3) {
4004 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
4005 lpfc_els_free_bpl(phba, buf_ptr);
4006 elsiocb->context3 = NULL;
4008 lpfc_sli_release_iocbq(phba, elsiocb);
4013 * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
4014 * @phba: pointer to lpfc hba data structure.
4015 * @cmdiocb: pointer to lpfc command iocb data structure.
4016 * @rspiocb: pointer to lpfc response iocb data structure.
4018 * This routine is the completion callback function to the Logout (LOGO)
4019 * Accept (ACC) Response ELS command. This routine is invoked to indicate
4020 * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
4021 * release the ndlp if it has the last reference remaining (reference count
4022 * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
4023 * field to NULL to inform the following lpfc_els_free_iocb() routine no
4024 * ndlp reference count needs to be decremented. Otherwise, the ndlp
4025 * reference use-count shall be decremented by the lpfc_els_free_iocb()
4026 * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
4027 * IOCB data structure.
4030 lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
4031 struct lpfc_iocbq *rspiocb)
4033 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
4034 struct lpfc_vport *vport = cmdiocb->vport;
4037 irsp = &rspiocb->iocb;
4038 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4039 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
4040 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
4041 /* ACC to LOGO completes to NPort <nlp_DID> */
4042 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4043 "0109 ACC to LOGO completes to NPort x%x "
4044 "Data: x%x x%x x%x\n",
4045 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4048 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
4049 /* NPort Recovery mode or node is just allocated */
4050 if (!lpfc_nlp_not_used(ndlp)) {
4051 /* If the ndlp is being used by another discovery
4052 * thread, just unregister the RPI.
4054 lpfc_unreg_rpi(vport, ndlp);
4056 /* Indicate the node has already released, should
4057 * not reference to it from within lpfc_els_free_iocb.
4059 cmdiocb->context1 = NULL;
4064 * The driver received a LOGO from the rport and has ACK'd it.
4065 * At this point, the driver is done so release the IOCB
4067 lpfc_els_free_iocb(phba, cmdiocb);
4071 * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
4072 * @phba: pointer to lpfc hba data structure.
4073 * @pmb: pointer to the driver internal queue element for mailbox command.
4075 * This routine is the completion callback function for unregister default
4076 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
4077 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
4078 * decrements the ndlp reference count held for this completion callback
4079 * function. After that, it invokes the lpfc_nlp_not_used() to check
4080 * whether there is only one reference left on the ndlp. If so, it will
4081 * perform one more decrement and trigger the release of the ndlp.
4084 lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4086 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
4087 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
4089 pmb->ctx_buf = NULL;
4090 pmb->ctx_ndlp = NULL;
4092 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4094 mempool_free(pmb, phba->mbox_mem_pool);
4096 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
4097 "0006 rpi%x DID:%x flg:%x %d map:%x %p\n",
4098 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
4099 kref_read(&ndlp->kref),
4100 ndlp->nlp_usg_map, ndlp);
4101 if (NLP_CHK_NODE_ACT(ndlp)) {
4103 /* This is the end of the default RPI cleanup logic for
4104 * this ndlp. If no other discovery threads are using
4105 * this ndlp, free all resources associated with it.
4107 lpfc_nlp_not_used(ndlp);
4109 lpfc_drop_node(ndlp->vport, ndlp);
4117 * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
4118 * @phba: pointer to lpfc hba data structure.
4119 * @cmdiocb: pointer to lpfc command iocb data structure.
4120 * @rspiocb: pointer to lpfc response iocb data structure.
4122 * This routine is the completion callback function for ELS Response IOCB
4123 * command. In normal case, this callback function just properly sets the
4124 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
4125 * field in the command IOCB is not NULL, the referred mailbox command will
4126 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
4127 * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
4128 * link down event occurred during the discovery, the lpfc_nlp_not_used()
4129 * routine shall be invoked trying to release the ndlp if no other threads
4130 * are currently referring it.
4133 lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
4134 struct lpfc_iocbq *rspiocb)
4136 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
4137 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
4138 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
4141 LPFC_MBOXQ_t *mbox = NULL;
4142 struct lpfc_dmabuf *mp = NULL;
4143 uint32_t ls_rjt = 0;
4145 irsp = &rspiocb->iocb;
4147 if (cmdiocb->context_un.mbox)
4148 mbox = cmdiocb->context_un.mbox;
4150 /* First determine if this is a LS_RJT cmpl. Note, this callback
4151 * function can have cmdiocb->contest1 (ndlp) field set to NULL.
4153 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
4154 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
4155 (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) {
4156 /* A LS_RJT associated with Default RPI cleanup has its own
4157 * separate code path.
4159 if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
4163 /* Check to see if link went down during discovery */
4164 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) {
4166 mp = (struct lpfc_dmabuf *)mbox->ctx_buf;
4168 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4171 mempool_free(mbox, phba->mbox_mem_pool);
4173 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
4174 (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
4175 if (lpfc_nlp_not_used(ndlp)) {
4177 /* Indicate the node has already released,
4178 * should not reference to it from within
4179 * the routine lpfc_els_free_iocb.
4181 cmdiocb->context1 = NULL;
4186 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4187 "ELS rsp cmpl: status:x%x/x%x did:x%x",
4188 irsp->ulpStatus, irsp->un.ulpWord[4],
4189 cmdiocb->iocb.un.elsreq64.remoteID);
4190 /* ELS response tag <ulpIoTag> completes */
4191 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4192 "0110 ELS response tag x%x completes "
4193 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
4194 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
4195 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
4196 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4199 if ((rspiocb->iocb.ulpStatus == 0)
4200 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
4201 if (!lpfc_unreg_rpi(vport, ndlp) &&
4202 (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
4203 ndlp->nlp_state == NLP_STE_REG_LOGIN_ISSUE)) {
4204 lpfc_printf_vlog(vport, KERN_INFO,
4206 "0314 PLOGI recov DID x%x "
4207 "Data: x%x x%x x%x\n",
4208 ndlp->nlp_DID, ndlp->nlp_state,
4209 ndlp->nlp_rpi, ndlp->nlp_flag);
4212 lpfc_mbuf_free(phba, mp->virt,
4216 mempool_free(mbox, phba->mbox_mem_pool);
4220 /* Increment reference count to ndlp to hold the
4221 * reference to ndlp for the callback function.
4223 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
4224 mbox->vport = vport;
4225 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
4226 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
4227 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
4230 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
4231 ndlp->nlp_prev_state = ndlp->nlp_state;
4232 lpfc_nlp_set_state(vport, ndlp,
4233 NLP_STE_REG_LOGIN_ISSUE);
4236 ndlp->nlp_flag |= NLP_REG_LOGIN_SEND;
4237 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
4238 != MBX_NOT_FINISHED)
4241 /* Decrement the ndlp reference count we
4242 * set for this failed mailbox command.
4245 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
4247 /* ELS rsp: Cannot issue reg_login for <NPortid> */
4248 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4249 "0138 ELS rsp: Cannot issue reg_login for x%x "
4250 "Data: x%x x%x x%x\n",
4251 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4254 if (lpfc_nlp_not_used(ndlp)) {
4256 /* Indicate node has already been released,
4257 * should not reference to it from within
4258 * the routine lpfc_els_free_iocb.
4260 cmdiocb->context1 = NULL;
4263 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
4264 if (!lpfc_error_lost_link(irsp) &&
4265 ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
4266 if (lpfc_nlp_not_used(ndlp)) {
4268 /* Indicate node has already been
4269 * released, should not reference
4270 * to it from within the routine
4271 * lpfc_els_free_iocb.
4273 cmdiocb->context1 = NULL;
4277 mp = (struct lpfc_dmabuf *)mbox->ctx_buf;
4279 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4282 mempool_free(mbox, phba->mbox_mem_pool);
4285 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
4286 spin_lock_irq(shost->host_lock);
4287 ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI);
4288 spin_unlock_irq(shost->host_lock);
4290 /* If the node is not being used by another discovery thread,
4291 * and we are sending a reject, we are done with it.
4292 * Release driver reference count here and free associated
4296 if (lpfc_nlp_not_used(ndlp))
4297 /* Indicate node has already been released,
4298 * should not reference to it from within
4299 * the routine lpfc_els_free_iocb.
4301 cmdiocb->context1 = NULL;
4305 lpfc_els_free_iocb(phba, cmdiocb);
4310 * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
4311 * @vport: pointer to a host virtual N_Port data structure.
4312 * @flag: the els command code to be accepted.
4313 * @oldiocb: pointer to the original lpfc command iocb data structure.
4314 * @ndlp: pointer to a node-list data structure.
4315 * @mbox: pointer to the driver internal queue element for mailbox command.
4317 * This routine prepares and issues an Accept (ACC) response IOCB
4318 * command. It uses the @flag to properly set up the IOCB field for the
4319 * specific ACC response command to be issued and invokes the
4320 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
4321 * @mbox pointer is passed in, it will be put into the context_un.mbox
4322 * field of the IOCB for the completion callback function to issue the
4323 * mailbox command to the HBA later when callback is invoked.
4325 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4326 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4327 * will be stored into the context1 field of the IOCB for the completion
4328 * callback function to the corresponding response ELS IOCB command.
4331 * 0 - Successfully issued acc response
4332 * 1 - Failed to issue acc response
4335 lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
4336 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
4339 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4340 struct lpfc_hba *phba = vport->phba;
4343 struct lpfc_iocbq *elsiocb;
4345 struct serv_parm *sp;
4348 ELS_PKT *els_pkt_ptr;
4350 oldcmd = &oldiocb->iocb;
4354 cmdsize = sizeof(uint32_t);
4355 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
4356 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
4358 spin_lock_irq(shost->host_lock);
4359 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
4360 spin_unlock_irq(shost->host_lock);
4364 icmd = &elsiocb->iocb;
4365 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4366 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4367 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4368 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4369 pcmd += sizeof(uint32_t);
4371 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4372 "Issue ACC: did:x%x flg:x%x",
4373 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4377 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
4378 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
4379 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
4383 icmd = &elsiocb->iocb;
4384 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4385 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4386 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4389 elsiocb->context_un.mbox = mbox;
4391 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4392 pcmd += sizeof(uint32_t);
4393 sp = (struct serv_parm *)pcmd;
4395 if (flag == ELS_CMD_FLOGI) {
4396 /* Copy the received service parameters back */
4397 memcpy(sp, &phba->fc_fabparam,
4398 sizeof(struct serv_parm));
4400 /* Clear the F_Port bit */
4403 /* Mark all class service parameters as invalid */
4404 sp->cls1.classValid = 0;
4405 sp->cls2.classValid = 0;
4406 sp->cls3.classValid = 0;
4407 sp->cls4.classValid = 0;
4409 /* Copy our worldwide names */
4410 memcpy(&sp->portName, &vport->fc_sparam.portName,
4411 sizeof(struct lpfc_name));
4412 memcpy(&sp->nodeName, &vport->fc_sparam.nodeName,
4413 sizeof(struct lpfc_name));
4415 memcpy(pcmd, &vport->fc_sparam,
4416 sizeof(struct serv_parm));
4418 sp->cmn.valid_vendor_ver_level = 0;
4419 memset(sp->un.vendorVersion, 0,
4420 sizeof(sp->un.vendorVersion));
4421 sp->cmn.bbRcvSizeMsb &= 0xF;
4423 /* If our firmware supports this feature, convey that
4424 * info to the target using the vendor specific field.
4426 if (phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) {
4427 sp->cmn.valid_vendor_ver_level = 1;
4428 sp->un.vv.vid = cpu_to_be32(LPFC_VV_EMLX_ID);
4430 cpu_to_be32(LPFC_VV_SUPPRESS_RSP);
4434 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4435 "Issue ACC FLOGI/PLOGI: did:x%x flg:x%x",
4436 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4439 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
4440 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
4441 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
4445 icmd = &elsiocb->iocb;
4446 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4447 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4448 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4450 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
4451 sizeof(uint32_t) + sizeof(PRLO));
4452 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
4453 els_pkt_ptr = (ELS_PKT *) pcmd;
4454 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
4456 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4457 "Issue ACC PRLO: did:x%x flg:x%x",
4458 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4463 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
4464 spin_lock_irq(shost->host_lock);
4465 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED ||
4466 ndlp->nlp_flag & NLP_REG_LOGIN_SEND))
4467 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
4468 spin_unlock_irq(shost->host_lock);
4469 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
4471 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4474 phba->fc_stat.elsXmitACC++;
4475 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4476 if (rc == IOCB_ERROR) {
4477 lpfc_els_free_iocb(phba, elsiocb);
4484 * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command
4485 * @vport: pointer to a virtual N_Port data structure.
4487 * @oldiocb: pointer to the original lpfc command iocb data structure.
4488 * @ndlp: pointer to a node-list data structure.
4489 * @mbox: pointer to the driver internal queue element for mailbox command.
4491 * This routine prepares and issue an Reject (RJT) response IOCB
4492 * command. If a @mbox pointer is passed in, it will be put into the
4493 * context_un.mbox field of the IOCB for the completion callback function
4494 * to issue to the HBA later.
4496 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4497 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4498 * will be stored into the context1 field of the IOCB for the completion
4499 * callback function to the reject response ELS IOCB command.
4502 * 0 - Successfully issued reject response
4503 * 1 - Failed to issue reject response
4506 lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
4507 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
4510 struct lpfc_hba *phba = vport->phba;
4513 struct lpfc_iocbq *elsiocb;
4518 cmdsize = 2 * sizeof(uint32_t);
4519 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4520 ndlp->nlp_DID, ELS_CMD_LS_RJT);
4524 icmd = &elsiocb->iocb;
4525 oldcmd = &oldiocb->iocb;
4526 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4527 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4528 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4530 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
4531 pcmd += sizeof(uint32_t);
4532 *((uint32_t *) (pcmd)) = rejectError;
4535 elsiocb->context_un.mbox = mbox;
4537 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
4538 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4539 "0129 Xmit ELS RJT x%x response tag x%x "
4540 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
4542 rejectError, elsiocb->iotag,
4543 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
4544 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
4545 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4546 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
4547 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
4549 phba->fc_stat.elsXmitLSRJT++;
4550 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4551 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4553 if (rc == IOCB_ERROR) {
4554 lpfc_els_free_iocb(phba, elsiocb);
4561 * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
4562 * @vport: pointer to a virtual N_Port data structure.
4563 * @oldiocb: pointer to the original lpfc command iocb data structure.
4564 * @ndlp: pointer to a node-list data structure.
4566 * This routine prepares and issues an Accept (ACC) response to Address
4567 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
4568 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
4570 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4571 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4572 * will be stored into the context1 field of the IOCB for the completion
4573 * callback function to the ADISC Accept response ELS IOCB command.
4576 * 0 - Successfully issued acc adisc response
4577 * 1 - Failed to issue adisc acc response
4580 lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
4581 struct lpfc_nodelist *ndlp)
4583 struct lpfc_hba *phba = vport->phba;
4585 IOCB_t *icmd, *oldcmd;
4586 struct lpfc_iocbq *elsiocb;
4591 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
4592 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4593 ndlp->nlp_DID, ELS_CMD_ACC);
4597 icmd = &elsiocb->iocb;
4598 oldcmd = &oldiocb->iocb;
4599 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4600 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4602 /* Xmit ADISC ACC response tag <ulpIoTag> */
4603 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4604 "0130 Xmit ADISC ACC response iotag x%x xri: "
4605 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
4606 elsiocb->iotag, elsiocb->iocb.ulpContext,
4607 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4609 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4611 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4612 pcmd += sizeof(uint32_t);
4614 ap = (ADISC *) (pcmd);
4615 ap->hardAL_PA = phba->fc_pref_ALPA;
4616 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
4617 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
4618 ap->DID = be32_to_cpu(vport->fc_myDID);
4620 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4621 "Issue ACC ADISC: did:x%x flg:x%x",
4622 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4624 phba->fc_stat.elsXmitACC++;
4625 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4626 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4627 if (rc == IOCB_ERROR) {
4628 lpfc_els_free_iocb(phba, elsiocb);
4632 /* Xmit ELS ACC response tag <ulpIoTag> */
4633 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4634 "0128 Xmit ELS ACC response Status: x%x, IoTag: x%x, "
4635 "XRI: x%x, DID: x%x, nlp_flag: x%x nlp_state: x%x "
4636 "RPI: x%x, fc_flag x%x\n",
4637 rc, elsiocb->iotag, elsiocb->sli4_xritag,
4638 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4639 ndlp->nlp_rpi, vport->fc_flag);
4644 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
4645 * @vport: pointer to a virtual N_Port data structure.
4646 * @oldiocb: pointer to the original lpfc command iocb data structure.
4647 * @ndlp: pointer to a node-list data structure.
4649 * This routine prepares and issues an Accept (ACC) response to Process
4650 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
4651 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
4653 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4654 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4655 * will be stored into the context1 field of the IOCB for the completion
4656 * callback function to the PRLI Accept response ELS IOCB command.
4659 * 0 - Successfully issued acc prli response
4660 * 1 - Failed to issue acc prli response
4663 lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
4664 struct lpfc_nodelist *ndlp)
4666 struct lpfc_hba *phba = vport->phba;
4668 struct lpfc_nvme_prli *npr_nvme;
4672 struct lpfc_iocbq *elsiocb;
4675 uint32_t prli_fc4_req, *req_payload;
4676 struct lpfc_dmabuf *req_buf;
4680 /* Need the incoming PRLI payload to determine if the ACC is for an
4681 * FC4 or NVME PRLI type. The PRLI type is at word 1.
4683 req_buf = (struct lpfc_dmabuf *)oldiocb->context2;
4684 req_payload = (((uint32_t *)req_buf->virt) + 1);
4686 /* PRLI type payload is at byte 3 for FCP or NVME. */
4687 prli_fc4_req = be32_to_cpu(*req_payload);
4688 prli_fc4_req = (prli_fc4_req >> 24) & 0xff;
4689 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4690 "6127 PRLI_ACC: Req Type x%x, Word1 x%08x\n",
4691 prli_fc4_req, *((uint32_t *)req_payload));
4693 if (prli_fc4_req == PRLI_FCP_TYPE) {
4694 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
4695 elsrspcmd = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
4696 } else if (prli_fc4_req & PRLI_NVME_TYPE) {
4697 cmdsize = sizeof(uint32_t) + sizeof(struct lpfc_nvme_prli);
4698 elsrspcmd = (ELS_CMD_ACC | (ELS_CMD_NVMEPRLI & ~ELS_RSP_MASK));
4703 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4704 ndlp->nlp_DID, elsrspcmd);
4708 icmd = &elsiocb->iocb;
4709 oldcmd = &oldiocb->iocb;
4710 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4711 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4713 /* Xmit PRLI ACC response tag <ulpIoTag> */
4714 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4715 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
4716 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
4717 elsiocb->iotag, elsiocb->iocb.ulpContext,
4718 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4720 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4721 memset(pcmd, 0, cmdsize);
4723 *((uint32_t *)(pcmd)) = elsrspcmd;
4724 pcmd += sizeof(uint32_t);
4726 /* For PRLI, remainder of payload is PRLI parameter page */
4729 if (prli_fc4_req == PRLI_FCP_TYPE) {
4731 * If the remote port is a target and our firmware version
4732 * is 3.20 or later, set the following bits for FC-TAPE
4735 npr = (PRLI *) pcmd;
4736 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
4737 (vpd->rev.feaLevelHigh >= 0x02)) {
4738 npr->ConfmComplAllowed = 1;
4740 npr->TaskRetryIdReq = 1;
4742 npr->acceptRspCode = PRLI_REQ_EXECUTED;
4743 npr->estabImagePair = 1;
4744 npr->readXferRdyDis = 1;
4745 npr->ConfmComplAllowed = 1;
4746 npr->prliType = PRLI_FCP_TYPE;
4747 npr->initiatorFunc = 1;
4748 } else if (prli_fc4_req & PRLI_NVME_TYPE) {
4749 /* Respond with an NVME PRLI Type */
4750 npr_nvme = (struct lpfc_nvme_prli *) pcmd;
4751 bf_set(prli_type_code, npr_nvme, PRLI_NVME_TYPE);
4752 bf_set(prli_estabImagePair, npr_nvme, 0); /* Should be 0 */
4753 bf_set(prli_acc_rsp_code, npr_nvme, PRLI_REQ_EXECUTED);
4754 if (phba->nvmet_support) {
4755 bf_set(prli_tgt, npr_nvme, 1);
4756 bf_set(prli_disc, npr_nvme, 1);
4757 if (phba->cfg_nvme_enable_fb) {
4758 bf_set(prli_fba, npr_nvme, 1);
4760 /* TBD. Target mode needs to post buffers
4761 * that support the configured first burst
4764 bf_set(prli_fb_sz, npr_nvme,
4765 phba->cfg_nvmet_fb_size);
4768 bf_set(prli_init, npr_nvme, 1);
4771 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
4772 "6015 NVME issue PRLI ACC word1 x%08x "
4773 "word4 x%08x word5 x%08x flag x%x, "
4774 "fcp_info x%x nlp_type x%x\n",
4775 npr_nvme->word1, npr_nvme->word4,
4776 npr_nvme->word5, ndlp->nlp_flag,
4777 ndlp->nlp_fcp_info, ndlp->nlp_type);
4778 npr_nvme->word1 = cpu_to_be32(npr_nvme->word1);
4779 npr_nvme->word4 = cpu_to_be32(npr_nvme->word4);
4780 npr_nvme->word5 = cpu_to_be32(npr_nvme->word5);
4782 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4783 "6128 Unknown FC_TYPE x%x x%x ndlp x%06x\n",
4784 prli_fc4_req, ndlp->nlp_fc4_type,
4787 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4788 "Issue ACC PRLI: did:x%x flg:x%x",
4789 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4791 phba->fc_stat.elsXmitACC++;
4792 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4794 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4795 if (rc == IOCB_ERROR) {
4796 lpfc_els_free_iocb(phba, elsiocb);
4803 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
4804 * @vport: pointer to a virtual N_Port data structure.
4805 * @format: rnid command format.
4806 * @oldiocb: pointer to the original lpfc command iocb data structure.
4807 * @ndlp: pointer to a node-list data structure.
4809 * This routine issues a Request Node Identification Data (RNID) Accept
4810 * (ACC) response. It constructs the RNID ACC response command according to
4811 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
4812 * issue the response. Note that this command does not need to hold the ndlp
4813 * reference count for the callback. So, the ndlp reference count taken by
4814 * the lpfc_prep_els_iocb() routine is put back and the context1 field of
4815 * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
4816 * there is no ndlp reference available.
4818 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4819 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4820 * will be stored into the context1 field of the IOCB for the completion
4821 * callback function. However, for the RNID Accept Response ELS command,
4822 * this is undone later by this routine after the IOCB is allocated.
4825 * 0 - Successfully issued acc rnid response
4826 * 1 - Failed to issue acc rnid response
4829 lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
4830 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
4832 struct lpfc_hba *phba = vport->phba;
4834 IOCB_t *icmd, *oldcmd;
4835 struct lpfc_iocbq *elsiocb;
4840 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
4841 + (2 * sizeof(struct lpfc_name));
4843 cmdsize += sizeof(RNID_TOP_DISC);
4845 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4846 ndlp->nlp_DID, ELS_CMD_ACC);
4850 icmd = &elsiocb->iocb;
4851 oldcmd = &oldiocb->iocb;
4852 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4853 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4855 /* Xmit RNID ACC response tag <ulpIoTag> */
4856 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4857 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
4858 elsiocb->iotag, elsiocb->iocb.ulpContext);
4859 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4860 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4861 pcmd += sizeof(uint32_t);
4863 memset(pcmd, 0, sizeof(RNID));
4864 rn = (RNID *) (pcmd);
4865 rn->Format = format;
4866 rn->CommonLen = (2 * sizeof(struct lpfc_name));
4867 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
4868 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
4871 rn->SpecificLen = 0;
4873 case RNID_TOPOLOGY_DISC:
4874 rn->SpecificLen = sizeof(RNID_TOP_DISC);
4875 memcpy(&rn->un.topologyDisc.portName,
4876 &vport->fc_portname, sizeof(struct lpfc_name));
4877 rn->un.topologyDisc.unitType = RNID_HBA;
4878 rn->un.topologyDisc.physPort = 0;
4879 rn->un.topologyDisc.attachedNodes = 0;
4883 rn->SpecificLen = 0;
4887 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4888 "Issue ACC RNID: did:x%x flg:x%x",
4889 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4891 phba->fc_stat.elsXmitACC++;
4892 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4894 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4895 if (rc == IOCB_ERROR) {
4896 lpfc_els_free_iocb(phba, elsiocb);
4903 * lpfc_els_clear_rrq - Clear the rq that this rrq describes.
4904 * @vport: pointer to a virtual N_Port data structure.
4905 * @iocb: pointer to the lpfc command iocb data structure.
4906 * @ndlp: pointer to a node-list data structure.
4911 lpfc_els_clear_rrq(struct lpfc_vport *vport,
4912 struct lpfc_iocbq *iocb, struct lpfc_nodelist *ndlp)
4914 struct lpfc_hba *phba = vport->phba;
4919 struct lpfc_node_rrq *prrq;
4922 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) iocb->context2)->virt);
4923 pcmd += sizeof(uint32_t);
4924 rrq = (struct RRQ *)pcmd;
4925 rrq->rrq_exchg = be32_to_cpu(rrq->rrq_exchg);
4926 rxid = bf_get(rrq_rxid, rrq);
4928 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4929 "2883 Clear RRQ for SID:x%x OXID:x%x RXID:x%x"
4931 be32_to_cpu(bf_get(rrq_did, rrq)),
4932 bf_get(rrq_oxid, rrq),
4934 iocb->iotag, iocb->iocb.ulpContext);
4936 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4937 "Clear RRQ: did:x%x flg:x%x exchg:x%.08x",
4938 ndlp->nlp_DID, ndlp->nlp_flag, rrq->rrq_exchg);
4939 if (vport->fc_myDID == be32_to_cpu(bf_get(rrq_did, rrq)))
4940 xri = bf_get(rrq_oxid, rrq);
4943 prrq = lpfc_get_active_rrq(vport, xri, ndlp->nlp_DID);
4945 lpfc_clr_rrq_active(phba, xri, prrq);
4950 * lpfc_els_rsp_echo_acc - Issue echo acc response
4951 * @vport: pointer to a virtual N_Port data structure.
4952 * @data: pointer to echo data to return in the accept.
4953 * @oldiocb: pointer to the original lpfc command iocb data structure.
4954 * @ndlp: pointer to a node-list data structure.
4957 * 0 - Successfully issued acc echo response
4958 * 1 - Failed to issue acc echo response
4961 lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data,
4962 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
4964 struct lpfc_hba *phba = vport->phba;
4965 struct lpfc_iocbq *elsiocb;
4970 cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len;
4972 /* The accumulated length can exceed the BPL_SIZE. For
4973 * now, use this as the limit
4975 if (cmdsize > LPFC_BPL_SIZE)
4976 cmdsize = LPFC_BPL_SIZE;
4977 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4978 ndlp->nlp_DID, ELS_CMD_ACC);
4982 elsiocb->iocb.ulpContext = oldiocb->iocb.ulpContext; /* Xri / rx_id */
4983 elsiocb->iocb.unsli3.rcvsli3.ox_id = oldiocb->iocb.unsli3.rcvsli3.ox_id;
4985 /* Xmit ECHO ACC response tag <ulpIoTag> */
4986 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4987 "2876 Xmit ECHO ACC response tag x%x xri x%x\n",
4988 elsiocb->iotag, elsiocb->iocb.ulpContext);
4989 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4990 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4991 pcmd += sizeof(uint32_t);
4992 memcpy(pcmd, data, cmdsize - sizeof(uint32_t));
4994 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4995 "Issue ACC ECHO: did:x%x flg:x%x",
4996 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4998 phba->fc_stat.elsXmitACC++;
4999 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5001 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5002 if (rc == IOCB_ERROR) {
5003 lpfc_els_free_iocb(phba, elsiocb);
5010 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
5011 * @vport: pointer to a host virtual N_Port data structure.
5013 * This routine issues Address Discover (ADISC) ELS commands to those
5014 * N_Ports which are in node port recovery state and ADISC has not been issued
5015 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
5016 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
5017 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
5018 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
5019 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
5020 * IOCBs quit for later pick up. On the other hand, after walking through
5021 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
5022 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
5023 * no more ADISC need to be sent.
5026 * The number of N_Ports with adisc issued.
5029 lpfc_els_disc_adisc(struct lpfc_vport *vport)
5031 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5032 struct lpfc_nodelist *ndlp, *next_ndlp;
5035 /* go thru NPR nodes and issue any remaining ELS ADISCs */
5036 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
5037 if (!NLP_CHK_NODE_ACT(ndlp))
5039 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
5040 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
5041 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
5042 spin_lock_irq(shost->host_lock);
5043 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
5044 spin_unlock_irq(shost->host_lock);
5045 ndlp->nlp_prev_state = ndlp->nlp_state;
5046 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
5047 lpfc_issue_els_adisc(vport, ndlp, 0);
5049 vport->num_disc_nodes++;
5050 if (vport->num_disc_nodes >=
5051 vport->cfg_discovery_threads) {
5052 spin_lock_irq(shost->host_lock);
5053 vport->fc_flag |= FC_NLP_MORE;
5054 spin_unlock_irq(shost->host_lock);
5059 if (sentadisc == 0) {
5060 spin_lock_irq(shost->host_lock);
5061 vport->fc_flag &= ~FC_NLP_MORE;
5062 spin_unlock_irq(shost->host_lock);
5068 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
5069 * @vport: pointer to a host virtual N_Port data structure.
5071 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
5072 * which are in node port recovery state, with a @vport. Each time an ELS
5073 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
5074 * the per @vport number of discover count (num_disc_nodes) shall be
5075 * incremented. If the num_disc_nodes reaches a pre-configured threshold
5076 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
5077 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
5078 * later pick up. On the other hand, after walking through all the ndlps with
5079 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
5080 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
5081 * PLOGI need to be sent.
5084 * The number of N_Ports with plogi issued.
5087 lpfc_els_disc_plogi(struct lpfc_vport *vport)
5089 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5090 struct lpfc_nodelist *ndlp, *next_ndlp;
5093 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
5094 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
5095 if (!NLP_CHK_NODE_ACT(ndlp))
5097 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
5098 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
5099 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
5100 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
5101 ndlp->nlp_prev_state = ndlp->nlp_state;
5102 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
5103 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
5105 vport->num_disc_nodes++;
5106 if (vport->num_disc_nodes >=
5107 vport->cfg_discovery_threads) {
5108 spin_lock_irq(shost->host_lock);
5109 vport->fc_flag |= FC_NLP_MORE;
5110 spin_unlock_irq(shost->host_lock);
5116 lpfc_set_disctmo(vport);
5119 spin_lock_irq(shost->host_lock);
5120 vport->fc_flag &= ~FC_NLP_MORE;
5121 spin_unlock_irq(shost->host_lock);
5127 lpfc_rdp_res_link_service(struct fc_rdp_link_service_desc *desc,
5131 desc->tag = cpu_to_be32(RDP_LINK_SERVICE_DESC_TAG);
5132 desc->payload.els_req = word0;
5133 desc->length = cpu_to_be32(sizeof(desc->payload));
5135 return sizeof(struct fc_rdp_link_service_desc);
5139 lpfc_rdp_res_sfp_desc(struct fc_rdp_sfp_desc *desc,
5140 uint8_t *page_a0, uint8_t *page_a2)
5142 uint16_t wavelength;
5143 uint16_t temperature;
5149 struct sff_trasnceiver_codes_byte4 *trasn_code_byte4;
5150 struct sff_trasnceiver_codes_byte5 *trasn_code_byte5;
5152 desc->tag = cpu_to_be32(RDP_SFP_DESC_TAG);
5154 trasn_code_byte4 = (struct sff_trasnceiver_codes_byte4 *)
5155 &page_a0[SSF_TRANSCEIVER_CODE_B4];
5156 trasn_code_byte5 = (struct sff_trasnceiver_codes_byte5 *)
5157 &page_a0[SSF_TRANSCEIVER_CODE_B5];
5159 if ((trasn_code_byte4->fc_sw_laser) ||
5160 (trasn_code_byte5->fc_sw_laser_sl) ||
5161 (trasn_code_byte5->fc_sw_laser_sn)) { /* check if its short WL */
5162 flag |= (SFP_FLAG_PT_SWLASER << SFP_FLAG_PT_SHIFT);
5163 } else if (trasn_code_byte4->fc_lw_laser) {
5164 wavelength = (page_a0[SSF_WAVELENGTH_B1] << 8) |
5165 page_a0[SSF_WAVELENGTH_B0];
5166 if (wavelength == SFP_WAVELENGTH_LC1310)
5167 flag |= SFP_FLAG_PT_LWLASER_LC1310 << SFP_FLAG_PT_SHIFT;
5168 if (wavelength == SFP_WAVELENGTH_LL1550)
5169 flag |= SFP_FLAG_PT_LWLASER_LL1550 << SFP_FLAG_PT_SHIFT;
5171 /* check if its SFP+ */
5172 flag |= ((page_a0[SSF_IDENTIFIER] == SFF_PG0_IDENT_SFP) ?
5173 SFP_FLAG_CT_SFP_PLUS : SFP_FLAG_CT_UNKNOWN)
5174 << SFP_FLAG_CT_SHIFT;
5176 /* check if its OPTICAL */
5177 flag |= ((page_a0[SSF_CONNECTOR] == SFF_PG0_CONNECTOR_LC) ?
5178 SFP_FLAG_IS_OPTICAL_PORT : 0)
5179 << SFP_FLAG_IS_OPTICAL_SHIFT;
5181 temperature = (page_a2[SFF_TEMPERATURE_B1] << 8 |
5182 page_a2[SFF_TEMPERATURE_B0]);
5183 vcc = (page_a2[SFF_VCC_B1] << 8 |
5184 page_a2[SFF_VCC_B0]);
5185 tx_power = (page_a2[SFF_TXPOWER_B1] << 8 |
5186 page_a2[SFF_TXPOWER_B0]);
5187 tx_bias = (page_a2[SFF_TX_BIAS_CURRENT_B1] << 8 |
5188 page_a2[SFF_TX_BIAS_CURRENT_B0]);
5189 rx_power = (page_a2[SFF_RXPOWER_B1] << 8 |
5190 page_a2[SFF_RXPOWER_B0]);
5191 desc->sfp_info.temperature = cpu_to_be16(temperature);
5192 desc->sfp_info.rx_power = cpu_to_be16(rx_power);
5193 desc->sfp_info.tx_bias = cpu_to_be16(tx_bias);
5194 desc->sfp_info.tx_power = cpu_to_be16(tx_power);
5195 desc->sfp_info.vcc = cpu_to_be16(vcc);
5197 desc->sfp_info.flags = cpu_to_be16(flag);
5198 desc->length = cpu_to_be32(sizeof(desc->sfp_info));
5200 return sizeof(struct fc_rdp_sfp_desc);
5204 lpfc_rdp_res_link_error(struct fc_rdp_link_error_status_desc *desc,
5209 desc->tag = cpu_to_be32(RDP_LINK_ERROR_STATUS_DESC_TAG);
5211 type = VN_PT_PHY_PF_PORT << VN_PT_PHY_SHIFT;
5213 desc->info.port_type = cpu_to_be32(type);
5215 desc->info.link_status.link_failure_cnt =
5216 cpu_to_be32(stat->linkFailureCnt);
5217 desc->info.link_status.loss_of_synch_cnt =
5218 cpu_to_be32(stat->lossSyncCnt);
5219 desc->info.link_status.loss_of_signal_cnt =
5220 cpu_to_be32(stat->lossSignalCnt);
5221 desc->info.link_status.primitive_seq_proto_err =
5222 cpu_to_be32(stat->primSeqErrCnt);
5223 desc->info.link_status.invalid_trans_word =
5224 cpu_to_be32(stat->invalidXmitWord);
5225 desc->info.link_status.invalid_crc_cnt = cpu_to_be32(stat->crcCnt);
5227 desc->length = cpu_to_be32(sizeof(desc->info));
5229 return sizeof(struct fc_rdp_link_error_status_desc);
5233 lpfc_rdp_res_bbc_desc(struct fc_rdp_bbc_desc *desc, READ_LNK_VAR *stat,
5234 struct lpfc_vport *vport)
5238 desc->tag = cpu_to_be32(RDP_BBC_DESC_TAG);
5240 bbCredit = vport->fc_sparam.cmn.bbCreditLsb |
5241 (vport->fc_sparam.cmn.bbCreditMsb << 8);
5242 desc->bbc_info.port_bbc = cpu_to_be32(bbCredit);
5243 if (vport->phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
5244 bbCredit = vport->phba->fc_fabparam.cmn.bbCreditLsb |
5245 (vport->phba->fc_fabparam.cmn.bbCreditMsb << 8);
5246 desc->bbc_info.attached_port_bbc = cpu_to_be32(bbCredit);
5248 desc->bbc_info.attached_port_bbc = 0;
5251 desc->bbc_info.rtt = 0;
5252 desc->length = cpu_to_be32(sizeof(desc->bbc_info));
5254 return sizeof(struct fc_rdp_bbc_desc);
5258 lpfc_rdp_res_oed_temp_desc(struct lpfc_hba *phba,
5259 struct fc_rdp_oed_sfp_desc *desc, uint8_t *page_a2)
5263 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5265 desc->oed_info.hi_alarm = page_a2[SSF_TEMP_HIGH_ALARM];
5266 desc->oed_info.lo_alarm = page_a2[SSF_TEMP_LOW_ALARM];
5267 desc->oed_info.hi_warning = page_a2[SSF_TEMP_HIGH_WARNING];
5268 desc->oed_info.lo_warning = page_a2[SSF_TEMP_LOW_WARNING];
5270 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TEMPERATURE)
5271 flags |= RDP_OET_HIGH_ALARM;
5272 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TEMPERATURE)
5273 flags |= RDP_OET_LOW_ALARM;
5274 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TEMPERATURE)
5275 flags |= RDP_OET_HIGH_WARNING;
5276 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TEMPERATURE)
5277 flags |= RDP_OET_LOW_WARNING;
5279 flags |= ((0xf & RDP_OED_TEMPERATURE) << RDP_OED_TYPE_SHIFT);
5280 desc->oed_info.function_flags = cpu_to_be32(flags);
5281 desc->length = cpu_to_be32(sizeof(desc->oed_info));
5282 return sizeof(struct fc_rdp_oed_sfp_desc);
5286 lpfc_rdp_res_oed_voltage_desc(struct lpfc_hba *phba,
5287 struct fc_rdp_oed_sfp_desc *desc,
5292 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5294 desc->oed_info.hi_alarm = page_a2[SSF_VOLTAGE_HIGH_ALARM];
5295 desc->oed_info.lo_alarm = page_a2[SSF_VOLTAGE_LOW_ALARM];
5296 desc->oed_info.hi_warning = page_a2[SSF_VOLTAGE_HIGH_WARNING];
5297 desc->oed_info.lo_warning = page_a2[SSF_VOLTAGE_LOW_WARNING];
5299 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_VOLTAGE)
5300 flags |= RDP_OET_HIGH_ALARM;
5301 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_VOLTAGE)
5302 flags |= RDP_OET_LOW_ALARM;
5303 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_VOLTAGE)
5304 flags |= RDP_OET_HIGH_WARNING;
5305 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_VOLTAGE)
5306 flags |= RDP_OET_LOW_WARNING;
5308 flags |= ((0xf & RDP_OED_VOLTAGE) << RDP_OED_TYPE_SHIFT);
5309 desc->oed_info.function_flags = cpu_to_be32(flags);
5310 desc->length = cpu_to_be32(sizeof(desc->oed_info));
5311 return sizeof(struct fc_rdp_oed_sfp_desc);
5315 lpfc_rdp_res_oed_txbias_desc(struct lpfc_hba *phba,
5316 struct fc_rdp_oed_sfp_desc *desc,
5321 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5323 desc->oed_info.hi_alarm = page_a2[SSF_BIAS_HIGH_ALARM];
5324 desc->oed_info.lo_alarm = page_a2[SSF_BIAS_LOW_ALARM];
5325 desc->oed_info.hi_warning = page_a2[SSF_BIAS_HIGH_WARNING];
5326 desc->oed_info.lo_warning = page_a2[SSF_BIAS_LOW_WARNING];
5328 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TXBIAS)
5329 flags |= RDP_OET_HIGH_ALARM;
5330 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TXBIAS)
5331 flags |= RDP_OET_LOW_ALARM;
5332 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TXBIAS)
5333 flags |= RDP_OET_HIGH_WARNING;
5334 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TXBIAS)
5335 flags |= RDP_OET_LOW_WARNING;
5337 flags |= ((0xf & RDP_OED_TXBIAS) << RDP_OED_TYPE_SHIFT);
5338 desc->oed_info.function_flags = cpu_to_be32(flags);
5339 desc->length = cpu_to_be32(sizeof(desc->oed_info));
5340 return sizeof(struct fc_rdp_oed_sfp_desc);
5344 lpfc_rdp_res_oed_txpower_desc(struct lpfc_hba *phba,
5345 struct fc_rdp_oed_sfp_desc *desc,
5350 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5352 desc->oed_info.hi_alarm = page_a2[SSF_TXPOWER_HIGH_ALARM];
5353 desc->oed_info.lo_alarm = page_a2[SSF_TXPOWER_LOW_ALARM];
5354 desc->oed_info.hi_warning = page_a2[SSF_TXPOWER_HIGH_WARNING];
5355 desc->oed_info.lo_warning = page_a2[SSF_TXPOWER_LOW_WARNING];
5357 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TXPOWER)
5358 flags |= RDP_OET_HIGH_ALARM;
5359 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TXPOWER)
5360 flags |= RDP_OET_LOW_ALARM;
5361 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TXPOWER)
5362 flags |= RDP_OET_HIGH_WARNING;
5363 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TXPOWER)
5364 flags |= RDP_OET_LOW_WARNING;
5366 flags |= ((0xf & RDP_OED_TXPOWER) << RDP_OED_TYPE_SHIFT);
5367 desc->oed_info.function_flags = cpu_to_be32(flags);
5368 desc->length = cpu_to_be32(sizeof(desc->oed_info));
5369 return sizeof(struct fc_rdp_oed_sfp_desc);
5374 lpfc_rdp_res_oed_rxpower_desc(struct lpfc_hba *phba,
5375 struct fc_rdp_oed_sfp_desc *desc,
5380 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5382 desc->oed_info.hi_alarm = page_a2[SSF_RXPOWER_HIGH_ALARM];
5383 desc->oed_info.lo_alarm = page_a2[SSF_RXPOWER_LOW_ALARM];
5384 desc->oed_info.hi_warning = page_a2[SSF_RXPOWER_HIGH_WARNING];
5385 desc->oed_info.lo_warning = page_a2[SSF_RXPOWER_LOW_WARNING];
5387 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_RXPOWER)
5388 flags |= RDP_OET_HIGH_ALARM;
5389 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_RXPOWER)
5390 flags |= RDP_OET_LOW_ALARM;
5391 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_RXPOWER)
5392 flags |= RDP_OET_HIGH_WARNING;
5393 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_RXPOWER)
5394 flags |= RDP_OET_LOW_WARNING;
5396 flags |= ((0xf & RDP_OED_RXPOWER) << RDP_OED_TYPE_SHIFT);
5397 desc->oed_info.function_flags = cpu_to_be32(flags);
5398 desc->length = cpu_to_be32(sizeof(desc->oed_info));
5399 return sizeof(struct fc_rdp_oed_sfp_desc);
5403 lpfc_rdp_res_opd_desc(struct fc_rdp_opd_sfp_desc *desc,
5404 uint8_t *page_a0, struct lpfc_vport *vport)
5406 desc->tag = cpu_to_be32(RDP_OPD_DESC_TAG);
5407 memcpy(desc->opd_info.vendor_name, &page_a0[SSF_VENDOR_NAME], 16);
5408 memcpy(desc->opd_info.model_number, &page_a0[SSF_VENDOR_PN], 16);
5409 memcpy(desc->opd_info.serial_number, &page_a0[SSF_VENDOR_SN], 16);
5410 memcpy(desc->opd_info.revision, &page_a0[SSF_VENDOR_REV], 4);
5411 memcpy(desc->opd_info.date, &page_a0[SSF_DATE_CODE], 8);
5412 desc->length = cpu_to_be32(sizeof(desc->opd_info));
5413 return sizeof(struct fc_rdp_opd_sfp_desc);
5417 lpfc_rdp_res_fec_desc(struct fc_fec_rdp_desc *desc, READ_LNK_VAR *stat)
5419 if (bf_get(lpfc_read_link_stat_gec2, stat) == 0)
5421 desc->tag = cpu_to_be32(RDP_FEC_DESC_TAG);
5423 desc->info.CorrectedBlocks =
5424 cpu_to_be32(stat->fecCorrBlkCount);
5425 desc->info.UncorrectableBlocks =
5426 cpu_to_be32(stat->fecUncorrBlkCount);
5428 desc->length = cpu_to_be32(sizeof(desc->info));
5430 return sizeof(struct fc_fec_rdp_desc);
5434 lpfc_rdp_res_speed(struct fc_rdp_port_speed_desc *desc, struct lpfc_hba *phba)
5436 uint16_t rdp_cap = 0;
5439 desc->tag = cpu_to_be32(RDP_PORT_SPEED_DESC_TAG);
5441 switch (phba->fc_linkspeed) {
5442 case LPFC_LINK_SPEED_1GHZ:
5443 rdp_speed = RDP_PS_1GB;
5445 case LPFC_LINK_SPEED_2GHZ:
5446 rdp_speed = RDP_PS_2GB;
5448 case LPFC_LINK_SPEED_4GHZ:
5449 rdp_speed = RDP_PS_4GB;
5451 case LPFC_LINK_SPEED_8GHZ:
5452 rdp_speed = RDP_PS_8GB;
5454 case LPFC_LINK_SPEED_10GHZ:
5455 rdp_speed = RDP_PS_10GB;
5457 case LPFC_LINK_SPEED_16GHZ:
5458 rdp_speed = RDP_PS_16GB;
5460 case LPFC_LINK_SPEED_32GHZ:
5461 rdp_speed = RDP_PS_32GB;
5463 case LPFC_LINK_SPEED_64GHZ:
5464 rdp_speed = RDP_PS_64GB;
5467 rdp_speed = RDP_PS_UNKNOWN;
5471 desc->info.port_speed.speed = cpu_to_be16(rdp_speed);
5473 if (phba->lmt & LMT_128Gb)
5474 rdp_cap |= RDP_PS_128GB;
5475 if (phba->lmt & LMT_64Gb)
5476 rdp_cap |= RDP_PS_64GB;
5477 if (phba->lmt & LMT_32Gb)
5478 rdp_cap |= RDP_PS_32GB;
5479 if (phba->lmt & LMT_16Gb)
5480 rdp_cap |= RDP_PS_16GB;
5481 if (phba->lmt & LMT_10Gb)
5482 rdp_cap |= RDP_PS_10GB;
5483 if (phba->lmt & LMT_8Gb)
5484 rdp_cap |= RDP_PS_8GB;
5485 if (phba->lmt & LMT_4Gb)
5486 rdp_cap |= RDP_PS_4GB;
5487 if (phba->lmt & LMT_2Gb)
5488 rdp_cap |= RDP_PS_2GB;
5489 if (phba->lmt & LMT_1Gb)
5490 rdp_cap |= RDP_PS_1GB;
5493 rdp_cap = RDP_CAP_UNKNOWN;
5494 if (phba->cfg_link_speed != LPFC_USER_LINK_SPEED_AUTO)
5495 rdp_cap |= RDP_CAP_USER_CONFIGURED;
5497 desc->info.port_speed.capabilities = cpu_to_be16(rdp_cap);
5498 desc->length = cpu_to_be32(sizeof(desc->info));
5499 return sizeof(struct fc_rdp_port_speed_desc);
5503 lpfc_rdp_res_diag_port_names(struct fc_rdp_port_name_desc *desc,
5504 struct lpfc_vport *vport)
5507 desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG);
5509 memcpy(desc->port_names.wwnn, &vport->fc_nodename,
5510 sizeof(desc->port_names.wwnn));
5512 memcpy(desc->port_names.wwpn, &vport->fc_portname,
5513 sizeof(desc->port_names.wwpn));
5515 desc->length = cpu_to_be32(sizeof(desc->port_names));
5516 return sizeof(struct fc_rdp_port_name_desc);
5520 lpfc_rdp_res_attach_port_names(struct fc_rdp_port_name_desc *desc,
5521 struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
5524 desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG);
5525 if (vport->fc_flag & FC_FABRIC) {
5526 memcpy(desc->port_names.wwnn, &vport->fabric_nodename,
5527 sizeof(desc->port_names.wwnn));
5529 memcpy(desc->port_names.wwpn, &vport->fabric_portname,
5530 sizeof(desc->port_names.wwpn));
5531 } else { /* Point to Point */
5532 memcpy(desc->port_names.wwnn, &ndlp->nlp_nodename,
5533 sizeof(desc->port_names.wwnn));
5535 memcpy(desc->port_names.wwnn, &ndlp->nlp_portname,
5536 sizeof(desc->port_names.wwpn));
5539 desc->length = cpu_to_be32(sizeof(desc->port_names));
5540 return sizeof(struct fc_rdp_port_name_desc);
5544 lpfc_els_rdp_cmpl(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context,
5547 struct lpfc_nodelist *ndlp = rdp_context->ndlp;
5548 struct lpfc_vport *vport = ndlp->vport;
5549 struct lpfc_iocbq *elsiocb;
5550 struct ulp_bde64 *bpl;
5553 struct ls_rjt *stat;
5554 struct fc_rdp_res_frame *rdp_res;
5555 uint32_t cmdsize, len;
5559 if (status != SUCCESS)
5562 /* This will change once we know the true size of the RDP payload */
5563 cmdsize = sizeof(struct fc_rdp_res_frame);
5565 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize,
5566 lpfc_max_els_tries, rdp_context->ndlp,
5567 rdp_context->ndlp->nlp_DID, ELS_CMD_ACC);
5570 goto free_rdp_context;
5572 icmd = &elsiocb->iocb;
5573 icmd->ulpContext = rdp_context->rx_id;
5574 icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id;
5576 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5577 "2171 Xmit RDP response tag x%x xri x%x, "
5578 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x",
5579 elsiocb->iotag, elsiocb->iocb.ulpContext,
5580 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5582 rdp_res = (struct fc_rdp_res_frame *)
5583 (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5584 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5585 memset(pcmd, 0, sizeof(struct fc_rdp_res_frame));
5586 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5588 /* Update Alarm and Warning */
5589 flag_ptr = (uint16_t *)(rdp_context->page_a2 + SSF_ALARM_FLAGS);
5590 phba->sfp_alarm |= *flag_ptr;
5591 flag_ptr = (uint16_t *)(rdp_context->page_a2 + SSF_WARNING_FLAGS);
5592 phba->sfp_warning |= *flag_ptr;
5594 /* For RDP payload */
5596 len += lpfc_rdp_res_link_service((struct fc_rdp_link_service_desc *)
5597 (len + pcmd), ELS_CMD_RDP);
5599 len += lpfc_rdp_res_sfp_desc((struct fc_rdp_sfp_desc *)(len + pcmd),
5600 rdp_context->page_a0, rdp_context->page_a2);
5601 len += lpfc_rdp_res_speed((struct fc_rdp_port_speed_desc *)(len + pcmd),
5603 len += lpfc_rdp_res_link_error((struct fc_rdp_link_error_status_desc *)
5604 (len + pcmd), &rdp_context->link_stat);
5605 len += lpfc_rdp_res_diag_port_names((struct fc_rdp_port_name_desc *)
5606 (len + pcmd), vport);
5607 len += lpfc_rdp_res_attach_port_names((struct fc_rdp_port_name_desc *)
5608 (len + pcmd), vport, ndlp);
5609 len += lpfc_rdp_res_fec_desc((struct fc_fec_rdp_desc *)(len + pcmd),
5610 &rdp_context->link_stat);
5611 len += lpfc_rdp_res_bbc_desc((struct fc_rdp_bbc_desc *)(len + pcmd),
5612 &rdp_context->link_stat, vport);
5613 len += lpfc_rdp_res_oed_temp_desc(phba,
5614 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5615 rdp_context->page_a2);
5616 len += lpfc_rdp_res_oed_voltage_desc(phba,
5617 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5618 rdp_context->page_a2);
5619 len += lpfc_rdp_res_oed_txbias_desc(phba,
5620 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5621 rdp_context->page_a2);
5622 len += lpfc_rdp_res_oed_txpower_desc(phba,
5623 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5624 rdp_context->page_a2);
5625 len += lpfc_rdp_res_oed_rxpower_desc(phba,
5626 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5627 rdp_context->page_a2);
5628 len += lpfc_rdp_res_opd_desc((struct fc_rdp_opd_sfp_desc *)(len + pcmd),
5629 rdp_context->page_a0, vport);
5631 rdp_res->length = cpu_to_be32(len - 8);
5632 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5634 /* Now that we know the true size of the payload, update the BPL */
5635 bpl = (struct ulp_bde64 *)
5636 (((struct lpfc_dmabuf *)(elsiocb->context3))->virt);
5637 bpl->tus.f.bdeSize = len;
5638 bpl->tus.f.bdeFlags = 0;
5639 bpl->tus.w = le32_to_cpu(bpl->tus.w);
5641 phba->fc_stat.elsXmitACC++;
5642 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5643 if (rc == IOCB_ERROR)
5644 lpfc_els_free_iocb(phba, elsiocb);
5650 cmdsize = 2 * sizeof(uint32_t);
5651 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, lpfc_max_els_tries,
5652 ndlp, ndlp->nlp_DID, ELS_CMD_LS_RJT);
5655 goto free_rdp_context;
5657 icmd = &elsiocb->iocb;
5658 icmd->ulpContext = rdp_context->rx_id;
5659 icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id;
5660 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5662 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
5663 stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t));
5664 stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5666 phba->fc_stat.elsXmitLSRJT++;
5667 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5668 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5670 if (rc == IOCB_ERROR)
5671 lpfc_els_free_iocb(phba, elsiocb);
5677 lpfc_get_rdp_info(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context)
5679 LPFC_MBOXQ_t *mbox = NULL;
5682 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5684 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_ELS,
5685 "7105 failed to allocate mailbox memory");
5689 if (lpfc_sli4_dump_page_a0(phba, mbox))
5690 goto prep_mbox_fail;
5691 mbox->vport = rdp_context->ndlp->vport;
5692 mbox->mbox_cmpl = lpfc_mbx_cmpl_rdp_page_a0;
5693 mbox->ctx_ndlp = (struct lpfc_rdp_context *)rdp_context;
5694 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
5695 if (rc == MBX_NOT_FINISHED)
5696 goto issue_mbox_fail;
5702 mempool_free(mbox, phba->mbox_mem_pool);
5707 * lpfc_els_rcv_rdp - Process an unsolicited RDP ELS.
5708 * @vport: pointer to a host virtual N_Port data structure.
5709 * @cmdiocb: pointer to lpfc command iocb data structure.
5710 * @ndlp: pointer to a node-list data structure.
5712 * This routine processes an unsolicited RDP(Read Diagnostic Parameters)
5713 * IOCB. First, the payload of the unsolicited RDP is checked.
5714 * Then it will (1) send MBX_DUMP_MEMORY, Embedded DMP_LMSD sub command TYPE-3
5715 * for Page A0, (2) send MBX_DUMP_MEMORY, DMP_LMSD for Page A2,
5716 * (3) send MBX_READ_LNK_STAT to get link stat, (4) Call lpfc_els_rdp_cmpl
5717 * gather all data and send RDP response.
5720 * 0 - Sent the acc response
5721 * 1 - Sent the reject response.
5724 lpfc_els_rcv_rdp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5725 struct lpfc_nodelist *ndlp)
5727 struct lpfc_hba *phba = vport->phba;
5728 struct lpfc_dmabuf *pcmd;
5729 uint8_t rjt_err, rjt_expl = LSEXP_NOTHING_MORE;
5730 struct fc_rdp_req_frame *rdp_req;
5731 struct lpfc_rdp_context *rdp_context;
5735 if (phba->sli_rev < LPFC_SLI_REV4 ||
5736 bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
5737 LPFC_SLI_INTF_IF_TYPE_2) {
5738 rjt_err = LSRJT_UNABLE_TPC;
5739 rjt_expl = LSEXP_REQ_UNSUPPORTED;
5743 if (phba->sli_rev < LPFC_SLI_REV4 || (phba->hba_flag & HBA_FCOE_MODE)) {
5744 rjt_err = LSRJT_UNABLE_TPC;
5745 rjt_expl = LSEXP_REQ_UNSUPPORTED;
5749 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5750 rdp_req = (struct fc_rdp_req_frame *) pcmd->virt;
5752 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5753 "2422 ELS RDP Request "
5754 "dec len %d tag x%x port_id %d len %d\n",
5755 be32_to_cpu(rdp_req->rdp_des_length),
5756 be32_to_cpu(rdp_req->nport_id_desc.tag),
5757 be32_to_cpu(rdp_req->nport_id_desc.nport_id),
5758 be32_to_cpu(rdp_req->nport_id_desc.length));
5760 if (sizeof(struct fc_rdp_nport_desc) !=
5761 be32_to_cpu(rdp_req->rdp_des_length))
5763 if (RDP_N_PORT_DESC_TAG != be32_to_cpu(rdp_req->nport_id_desc.tag))
5765 if (RDP_NPORT_ID_SIZE !=
5766 be32_to_cpu(rdp_req->nport_id_desc.length))
5768 rdp_context = kzalloc(sizeof(struct lpfc_rdp_context), GFP_KERNEL);
5770 rjt_err = LSRJT_UNABLE_TPC;
5774 cmd = &cmdiocb->iocb;
5775 rdp_context->ndlp = lpfc_nlp_get(ndlp);
5776 rdp_context->ox_id = cmd->unsli3.rcvsli3.ox_id;
5777 rdp_context->rx_id = cmd->ulpContext;
5778 rdp_context->cmpl = lpfc_els_rdp_cmpl;
5779 if (lpfc_get_rdp_info(phba, rdp_context)) {
5780 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_ELS,
5781 "2423 Unable to send mailbox");
5783 rjt_err = LSRJT_UNABLE_TPC;
5791 rjt_err = LSRJT_LOGICAL_ERR;
5794 memset(&stat, 0, sizeof(stat));
5795 stat.un.b.lsRjtRsnCode = rjt_err;
5796 stat.un.b.lsRjtRsnCodeExp = rjt_expl;
5797 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5803 lpfc_els_lcb_rsp(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
5808 struct lpfc_iocbq *elsiocb;
5809 struct lpfc_nodelist *ndlp;
5810 struct ls_rjt *stat;
5811 union lpfc_sli4_cfg_shdr *shdr;
5812 struct lpfc_lcb_context *lcb_context;
5813 struct fc_lcb_res_frame *lcb_res;
5814 uint32_t cmdsize, shdr_status, shdr_add_status;
5818 lcb_context = (struct lpfc_lcb_context *)pmb->ctx_ndlp;
5819 ndlp = lcb_context->ndlp;
5820 pmb->ctx_ndlp = NULL;
5821 pmb->ctx_buf = NULL;
5823 shdr = (union lpfc_sli4_cfg_shdr *)
5824 &pmb->u.mqe.un.beacon_config.header.cfg_shdr;
5825 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
5826 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
5828 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX,
5829 "0194 SET_BEACON_CONFIG mailbox "
5830 "completed with status x%x add_status x%x,"
5831 " mbx status x%x\n",
5832 shdr_status, shdr_add_status, mb->mbxStatus);
5834 if ((mb->mbxStatus != MBX_SUCCESS) || shdr_status ||
5835 (shdr_add_status == ADD_STATUS_OPERATION_ALREADY_ACTIVE) ||
5836 (shdr_add_status == ADD_STATUS_INVALID_REQUEST)) {
5837 mempool_free(pmb, phba->mbox_mem_pool);
5841 mempool_free(pmb, phba->mbox_mem_pool);
5842 cmdsize = sizeof(struct fc_lcb_res_frame);
5843 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5844 lpfc_max_els_tries, ndlp,
5845 ndlp->nlp_DID, ELS_CMD_ACC);
5847 /* Decrement the ndlp reference count from previous mbox command */
5851 goto free_lcb_context;
5853 lcb_res = (struct fc_lcb_res_frame *)
5854 (((struct lpfc_dmabuf *)elsiocb->context2)->virt);
5856 memset(lcb_res, 0, sizeof(struct fc_lcb_res_frame));
5857 icmd = &elsiocb->iocb;
5858 icmd->ulpContext = lcb_context->rx_id;
5859 icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id;
5861 pcmd = (uint8_t *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt);
5862 *((uint32_t *)(pcmd)) = ELS_CMD_ACC;
5863 lcb_res->lcb_sub_command = lcb_context->sub_command;
5864 lcb_res->lcb_type = lcb_context->type;
5865 lcb_res->capability = lcb_context->capability;
5866 lcb_res->lcb_frequency = lcb_context->frequency;
5867 lcb_res->lcb_duration = lcb_context->duration;
5868 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5869 phba->fc_stat.elsXmitACC++;
5870 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5871 if (rc == IOCB_ERROR)
5872 lpfc_els_free_iocb(phba, elsiocb);
5878 cmdsize = sizeof(struct fc_lcb_res_frame);
5879 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5880 lpfc_max_els_tries, ndlp,
5881 ndlp->nlp_DID, ELS_CMD_LS_RJT);
5884 goto free_lcb_context;
5886 icmd = &elsiocb->iocb;
5887 icmd->ulpContext = lcb_context->rx_id;
5888 icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id;
5889 pcmd = (uint8_t *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt);
5891 *((uint32_t *)(pcmd)) = ELS_CMD_LS_RJT;
5892 stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t));
5893 stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5895 if (shdr_add_status == ADD_STATUS_OPERATION_ALREADY_ACTIVE)
5896 stat->un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS;
5898 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5899 phba->fc_stat.elsXmitLSRJT++;
5900 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5901 if (rc == IOCB_ERROR)
5902 lpfc_els_free_iocb(phba, elsiocb);
5908 lpfc_sli4_set_beacon(struct lpfc_vport *vport,
5909 struct lpfc_lcb_context *lcb_context,
5910 uint32_t beacon_state)
5912 struct lpfc_hba *phba = vport->phba;
5913 union lpfc_sli4_cfg_shdr *cfg_shdr;
5914 LPFC_MBOXQ_t *mbox = NULL;
5918 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5922 cfg_shdr = &mbox->u.mqe.un.sli4_config.header.cfg_shdr;
5923 len = sizeof(struct lpfc_mbx_set_beacon_config) -
5924 sizeof(struct lpfc_sli4_cfg_mhdr);
5925 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
5926 LPFC_MBOX_OPCODE_SET_BEACON_CONFIG, len,
5927 LPFC_SLI4_MBX_EMBED);
5928 mbox->ctx_ndlp = (void *)lcb_context;
5929 mbox->vport = phba->pport;
5930 mbox->mbox_cmpl = lpfc_els_lcb_rsp;
5931 bf_set(lpfc_mbx_set_beacon_port_num, &mbox->u.mqe.un.beacon_config,
5932 phba->sli4_hba.physical_port);
5933 bf_set(lpfc_mbx_set_beacon_state, &mbox->u.mqe.un.beacon_config,
5935 mbox->u.mqe.un.beacon_config.word5 = 0; /* Reserved */
5938 * Check bv1s bit before issuing the mailbox
5939 * if bv1s == 1, LCB V1 supported
5940 * else, LCB V0 supported
5943 if (phba->sli4_hba.pc_sli4_params.bv1s) {
5944 /* COMMON_SET_BEACON_CONFIG_V1 */
5945 cfg_shdr->request.word9 = BEACON_VERSION_V1;
5946 lcb_context->capability |= LCB_CAPABILITY_DURATION;
5947 bf_set(lpfc_mbx_set_beacon_port_type,
5948 &mbox->u.mqe.un.beacon_config, 0);
5949 bf_set(lpfc_mbx_set_beacon_duration_v1,
5950 &mbox->u.mqe.un.beacon_config,
5951 be16_to_cpu(lcb_context->duration));
5953 /* COMMON_SET_BEACON_CONFIG_V0 */
5954 if (be16_to_cpu(lcb_context->duration) != 0) {
5955 mempool_free(mbox, phba->mbox_mem_pool);
5958 cfg_shdr->request.word9 = BEACON_VERSION_V0;
5959 lcb_context->capability &= ~(LCB_CAPABILITY_DURATION);
5960 bf_set(lpfc_mbx_set_beacon_state,
5961 &mbox->u.mqe.un.beacon_config, beacon_state);
5962 bf_set(lpfc_mbx_set_beacon_port_type,
5963 &mbox->u.mqe.un.beacon_config, 1);
5964 bf_set(lpfc_mbx_set_beacon_duration,
5965 &mbox->u.mqe.un.beacon_config,
5966 be16_to_cpu(lcb_context->duration));
5969 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
5970 if (rc == MBX_NOT_FINISHED) {
5971 mempool_free(mbox, phba->mbox_mem_pool);
5980 * lpfc_els_rcv_lcb - Process an unsolicited LCB
5981 * @vport: pointer to a host virtual N_Port data structure.
5982 * @cmdiocb: pointer to lpfc command iocb data structure.
5983 * @ndlp: pointer to a node-list data structure.
5985 * This routine processes an unsolicited LCB(LINK CABLE BEACON) IOCB.
5986 * First, the payload of the unsolicited LCB is checked.
5987 * Then based on Subcommand beacon will either turn on or off.
5990 * 0 - Sent the acc response
5991 * 1 - Sent the reject response.
5994 lpfc_els_rcv_lcb(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5995 struct lpfc_nodelist *ndlp)
5997 struct lpfc_hba *phba = vport->phba;
5998 struct lpfc_dmabuf *pcmd;
6000 struct fc_lcb_request_frame *beacon;
6001 struct lpfc_lcb_context *lcb_context;
6002 uint8_t state, rjt_err;
6005 pcmd = (struct lpfc_dmabuf *)cmdiocb->context2;
6006 lp = (uint8_t *)pcmd->virt;
6007 beacon = (struct fc_lcb_request_frame *)pcmd->virt;
6009 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6010 "0192 ELS LCB Data x%x x%x x%x x%x sub x%x "
6011 "type x%x frequency %x duration x%x\n",
6012 lp[0], lp[1], lp[2],
6013 beacon->lcb_command,
6014 beacon->lcb_sub_command,
6016 beacon->lcb_frequency,
6017 be16_to_cpu(beacon->lcb_duration));
6019 if (beacon->lcb_sub_command != LPFC_LCB_ON &&
6020 beacon->lcb_sub_command != LPFC_LCB_OFF) {
6021 rjt_err = LSRJT_CMD_UNSUPPORTED;
6025 if (phba->sli_rev < LPFC_SLI_REV4 ||
6026 phba->hba_flag & HBA_FCOE_MODE ||
6027 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
6028 LPFC_SLI_INTF_IF_TYPE_2)) {
6029 rjt_err = LSRJT_CMD_UNSUPPORTED;
6033 lcb_context = kmalloc(sizeof(*lcb_context), GFP_KERNEL);
6035 rjt_err = LSRJT_UNABLE_TPC;
6039 state = (beacon->lcb_sub_command == LPFC_LCB_ON) ? 1 : 0;
6040 lcb_context->sub_command = beacon->lcb_sub_command;
6041 lcb_context->capability = 0;
6042 lcb_context->type = beacon->lcb_type;
6043 lcb_context->frequency = beacon->lcb_frequency;
6044 lcb_context->duration = beacon->lcb_duration;
6045 lcb_context->ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id;
6046 lcb_context->rx_id = cmdiocb->iocb.ulpContext;
6047 lcb_context->ndlp = lpfc_nlp_get(ndlp);
6048 if (lpfc_sli4_set_beacon(vport, lcb_context, state)) {
6049 lpfc_printf_vlog(ndlp->vport, KERN_ERR,
6050 LOG_ELS, "0193 failed to send mail box");
6053 rjt_err = LSRJT_UNABLE_TPC;
6058 memset(&stat, 0, sizeof(stat));
6059 stat.un.b.lsRjtRsnCode = rjt_err;
6060 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
6066 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
6067 * @vport: pointer to a host virtual N_Port data structure.
6069 * This routine cleans up any Registration State Change Notification
6070 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
6071 * @vport together with the host_lock is used to prevent multiple thread
6072 * trying to access the RSCN array on a same @vport at the same time.
6075 lpfc_els_flush_rscn(struct lpfc_vport *vport)
6077 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6078 struct lpfc_hba *phba = vport->phba;
6081 spin_lock_irq(shost->host_lock);
6082 if (vport->fc_rscn_flush) {
6083 /* Another thread is walking fc_rscn_id_list on this vport */
6084 spin_unlock_irq(shost->host_lock);
6087 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
6088 vport->fc_rscn_flush = 1;
6089 spin_unlock_irq(shost->host_lock);
6091 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
6092 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
6093 vport->fc_rscn_id_list[i] = NULL;
6095 spin_lock_irq(shost->host_lock);
6096 vport->fc_rscn_id_cnt = 0;
6097 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
6098 spin_unlock_irq(shost->host_lock);
6099 lpfc_can_disctmo(vport);
6100 /* Indicate we are done walking this fc_rscn_id_list */
6101 vport->fc_rscn_flush = 0;
6105 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
6106 * @vport: pointer to a host virtual N_Port data structure.
6107 * @did: remote destination port identifier.
6109 * This routine checks whether there is any pending Registration State
6110 * Configuration Notification (RSCN) to a @did on @vport.
6113 * None zero - The @did matched with a pending rscn
6114 * 0 - not able to match @did with a pending rscn
6117 lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
6122 uint32_t payload_len, i;
6123 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6125 ns_did.un.word = did;
6127 /* Never match fabric nodes for RSCNs */
6128 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
6131 /* If we are doing a FULL RSCN rediscovery, match everything */
6132 if (vport->fc_flag & FC_RSCN_DISCOVERY)
6135 spin_lock_irq(shost->host_lock);
6136 if (vport->fc_rscn_flush) {
6137 /* Another thread is walking fc_rscn_id_list on this vport */
6138 spin_unlock_irq(shost->host_lock);
6141 /* Indicate we are walking fc_rscn_id_list on this vport */
6142 vport->fc_rscn_flush = 1;
6143 spin_unlock_irq(shost->host_lock);
6144 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
6145 lp = vport->fc_rscn_id_list[i]->virt;
6146 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
6147 payload_len -= sizeof(uint32_t); /* take off word 0 */
6148 while (payload_len) {
6149 rscn_did.un.word = be32_to_cpu(*lp++);
6150 payload_len -= sizeof(uint32_t);
6151 switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) {
6152 case RSCN_ADDRESS_FORMAT_PORT:
6153 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
6154 && (ns_did.un.b.area == rscn_did.un.b.area)
6155 && (ns_did.un.b.id == rscn_did.un.b.id))
6156 goto return_did_out;
6158 case RSCN_ADDRESS_FORMAT_AREA:
6159 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
6160 && (ns_did.un.b.area == rscn_did.un.b.area))
6161 goto return_did_out;
6163 case RSCN_ADDRESS_FORMAT_DOMAIN:
6164 if (ns_did.un.b.domain == rscn_did.un.b.domain)
6165 goto return_did_out;
6167 case RSCN_ADDRESS_FORMAT_FABRIC:
6168 goto return_did_out;
6172 /* Indicate we are done with walking fc_rscn_id_list on this vport */
6173 vport->fc_rscn_flush = 0;
6176 /* Indicate we are done with walking fc_rscn_id_list on this vport */
6177 vport->fc_rscn_flush = 0;
6182 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
6183 * @vport: pointer to a host virtual N_Port data structure.
6185 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
6186 * state machine for a @vport's nodes that are with pending RSCN (Registration
6187 * State Change Notification).
6190 * 0 - Successful (currently alway return 0)
6193 lpfc_rscn_recovery_check(struct lpfc_vport *vport)
6195 struct lpfc_nodelist *ndlp = NULL;
6197 /* Move all affected nodes by pending RSCNs to NPR state. */
6198 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
6199 if (!NLP_CHK_NODE_ACT(ndlp) ||
6200 (ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
6201 !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
6204 /* NVME Target mode does not do RSCN Recovery. */
6205 if (vport->phba->nvmet_support)
6208 /* If we are in the process of doing discovery on this
6209 * NPort, let it continue on its own.
6211 switch (ndlp->nlp_state) {
6212 case NLP_STE_PLOGI_ISSUE:
6213 case NLP_STE_ADISC_ISSUE:
6214 case NLP_STE_REG_LOGIN_ISSUE:
6215 case NLP_STE_PRLI_ISSUE:
6216 case NLP_STE_LOGO_ISSUE:
6221 lpfc_disc_state_machine(vport, ndlp, NULL,
6222 NLP_EVT_DEVICE_RECOVERY);
6223 lpfc_cancel_retry_delay_tmo(vport, ndlp);
6229 * lpfc_send_rscn_event - Send an RSCN event to management application
6230 * @vport: pointer to a host virtual N_Port data structure.
6231 * @cmdiocb: pointer to lpfc command iocb data structure.
6233 * lpfc_send_rscn_event sends an RSCN netlink event to management
6237 lpfc_send_rscn_event(struct lpfc_vport *vport,
6238 struct lpfc_iocbq *cmdiocb)
6240 struct lpfc_dmabuf *pcmd;
6241 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6242 uint32_t *payload_ptr;
6243 uint32_t payload_len;
6244 struct lpfc_rscn_event_header *rscn_event_data;
6246 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6247 payload_ptr = (uint32_t *) pcmd->virt;
6248 payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK);
6250 rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) +
6251 payload_len, GFP_KERNEL);
6252 if (!rscn_event_data) {
6253 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6254 "0147 Failed to allocate memory for RSCN event\n");
6257 rscn_event_data->event_type = FC_REG_RSCN_EVENT;
6258 rscn_event_data->payload_length = payload_len;
6259 memcpy(rscn_event_data->rscn_payload, payload_ptr,
6262 fc_host_post_vendor_event(shost,
6263 fc_get_event_number(),
6264 sizeof(struct lpfc_rscn_event_header) + payload_len,
6265 (char *)rscn_event_data,
6268 kfree(rscn_event_data);
6272 * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
6273 * @vport: pointer to a host virtual N_Port data structure.
6274 * @cmdiocb: pointer to lpfc command iocb data structure.
6275 * @ndlp: pointer to a node-list data structure.
6277 * This routine processes an unsolicited RSCN (Registration State Change
6278 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
6279 * to invoke fc_host_post_event() routine to the FC transport layer. If the
6280 * discover state machine is about to begin discovery, it just accepts the
6281 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
6282 * contains N_Port IDs for other vports on this HBA, it just accepts the
6283 * RSCN and ignore processing it. If the state machine is in the recovery
6284 * state, the fc_rscn_id_list of this @vport is walked and the
6285 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
6286 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
6287 * routine is invoked to handle the RSCN event.
6290 * 0 - Just sent the acc response
6291 * 1 - Sent the acc response and waited for name server completion
6294 lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6295 struct lpfc_nodelist *ndlp)
6297 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6298 struct lpfc_hba *phba = vport->phba;
6299 struct lpfc_dmabuf *pcmd;
6300 uint32_t *lp, *datap;
6301 uint32_t payload_len, length, nportid, *cmd;
6303 int rscn_id = 0, hba_id = 0;
6306 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6307 lp = (uint32_t *) pcmd->virt;
6309 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
6310 payload_len -= sizeof(uint32_t); /* take off word 0 */
6312 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6313 "0214 RSCN received Data: x%x x%x x%x x%x\n",
6314 vport->fc_flag, payload_len, *lp,
6315 vport->fc_rscn_id_cnt);
6317 /* Send an RSCN event to the management application */
6318 lpfc_send_rscn_event(vport, cmdiocb);
6320 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
6321 fc_host_post_event(shost, fc_get_event_number(),
6322 FCH_EVT_RSCN, lp[i]);
6324 /* If we are about to begin discovery, just ACC the RSCN.
6325 * Discovery processing will satisfy it.
6327 if (vport->port_state <= LPFC_NS_QRY) {
6328 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6329 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
6330 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
6332 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
6336 /* If this RSCN just contains NPortIDs for other vports on this HBA,
6337 * just ACC and ignore it.
6339 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
6340 !(vport->cfg_peer_port_login)) {
6345 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
6346 i -= sizeof(uint32_t);
6348 if (lpfc_find_vport_by_did(phba, nportid))
6351 if (rscn_id == hba_id) {
6352 /* ALL NPortIDs in RSCN are on HBA */
6353 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6355 "Data: x%x x%x x%x x%x\n",
6356 vport->fc_flag, payload_len,
6357 *lp, vport->fc_rscn_id_cnt);
6358 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6359 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
6360 ndlp->nlp_DID, vport->port_state,
6363 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
6369 spin_lock_irq(shost->host_lock);
6370 if (vport->fc_rscn_flush) {
6371 /* Another thread is walking fc_rscn_id_list on this vport */
6372 vport->fc_flag |= FC_RSCN_DISCOVERY;
6373 spin_unlock_irq(shost->host_lock);
6375 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
6378 /* Indicate we are walking fc_rscn_id_list on this vport */
6379 vport->fc_rscn_flush = 1;
6380 spin_unlock_irq(shost->host_lock);
6381 /* Get the array count after successfully have the token */
6382 rscn_cnt = vport->fc_rscn_id_cnt;
6383 /* If we are already processing an RSCN, save the received
6384 * RSCN payload buffer, cmdiocb->context2 to process later.
6386 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
6387 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6388 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
6389 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
6391 spin_lock_irq(shost->host_lock);
6392 vport->fc_flag |= FC_RSCN_DEFERRED;
6393 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
6394 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
6395 vport->fc_flag |= FC_RSCN_MODE;
6396 spin_unlock_irq(shost->host_lock);
6398 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
6399 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
6402 (payload_len + length <= LPFC_BPL_SIZE)) {
6403 *cmd &= ELS_CMD_MASK;
6404 *cmd |= cpu_to_be32(payload_len + length);
6405 memcpy(((uint8_t *)cmd) + length, lp,
6408 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
6409 vport->fc_rscn_id_cnt++;
6410 /* If we zero, cmdiocb->context2, the calling
6411 * routine will not try to free it.
6413 cmdiocb->context2 = NULL;
6416 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6417 "0235 Deferred RSCN "
6418 "Data: x%x x%x x%x\n",
6419 vport->fc_rscn_id_cnt, vport->fc_flag,
6422 vport->fc_flag |= FC_RSCN_DISCOVERY;
6423 spin_unlock_irq(shost->host_lock);
6424 /* ReDiscovery RSCN */
6425 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6426 "0234 ReDiscovery RSCN "
6427 "Data: x%x x%x x%x\n",
6428 vport->fc_rscn_id_cnt, vport->fc_flag,
6431 /* Indicate we are done walking fc_rscn_id_list on this vport */
6432 vport->fc_rscn_flush = 0;
6434 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
6435 /* send RECOVERY event for ALL nodes that match RSCN payload */
6436 lpfc_rscn_recovery_check(vport);
6439 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6440 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
6441 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
6443 spin_lock_irq(shost->host_lock);
6444 vport->fc_flag |= FC_RSCN_MODE;
6445 spin_unlock_irq(shost->host_lock);
6446 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
6447 /* Indicate we are done walking fc_rscn_id_list on this vport */
6448 vport->fc_rscn_flush = 0;
6450 * If we zero, cmdiocb->context2, the calling routine will
6451 * not try to free it.
6453 cmdiocb->context2 = NULL;
6454 lpfc_set_disctmo(vport);
6456 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
6457 /* send RECOVERY event for ALL nodes that match RSCN payload */
6458 lpfc_rscn_recovery_check(vport);
6459 return lpfc_els_handle_rscn(vport);
6463 * lpfc_els_handle_rscn - Handle rscn for a vport
6464 * @vport: pointer to a host virtual N_Port data structure.
6466 * This routine handles the Registration State Configuration Notification
6467 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
6468 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
6469 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
6470 * NameServer shall be issued. If CT command to the NameServer fails to be
6471 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
6472 * RSCN activities with the @vport.
6475 * 0 - Cleaned up rscn on the @vport
6476 * 1 - Wait for plogi to name server before proceed
6479 lpfc_els_handle_rscn(struct lpfc_vport *vport)
6481 struct lpfc_nodelist *ndlp;
6482 struct lpfc_hba *phba = vport->phba;
6484 /* Ignore RSCN if the port is being torn down. */
6485 if (vport->load_flag & FC_UNLOADING) {
6486 lpfc_els_flush_rscn(vport);
6490 /* Start timer for RSCN processing */
6491 lpfc_set_disctmo(vport);
6493 /* RSCN processed */
6494 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6495 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
6496 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
6499 /* To process RSCN, first compare RSCN data with NameServer */
6500 vport->fc_ns_retry = 0;
6501 vport->num_disc_nodes = 0;
6503 ndlp = lpfc_findnode_did(vport, NameServer_DID);
6504 if (ndlp && NLP_CHK_NODE_ACT(ndlp)
6505 && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
6506 /* Good ndlp, issue CT Request to NameServer. Need to
6507 * know how many gidfts were issued. If none, then just
6508 * flush the RSCN. Otherwise, the outstanding requests
6511 if (phba->cfg_ns_query == LPFC_NS_QUERY_GID_FT) {
6512 if (lpfc_issue_gidft(vport) > 0)
6514 } else if (phba->cfg_ns_query == LPFC_NS_QUERY_GID_PT) {
6515 if (lpfc_issue_gidpt(vport) > 0)
6521 /* Nameserver login in question. Revalidate. */
6523 ndlp = lpfc_enable_node(vport, ndlp,
6524 NLP_STE_PLOGI_ISSUE);
6526 lpfc_els_flush_rscn(vport);
6529 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
6531 ndlp = lpfc_nlp_init(vport, NameServer_DID);
6533 lpfc_els_flush_rscn(vport);
6536 ndlp->nlp_prev_state = ndlp->nlp_state;
6537 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
6539 ndlp->nlp_type |= NLP_FABRIC;
6540 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
6541 /* Wait for NameServer login cmpl before we can
6547 lpfc_els_flush_rscn(vport);
6552 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
6553 * @vport: pointer to a host virtual N_Port data structure.
6554 * @cmdiocb: pointer to lpfc command iocb data structure.
6555 * @ndlp: pointer to a node-list data structure.
6557 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
6558 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
6559 * point topology. As an unsolicited FLOGI should not be received in a loop
6560 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
6561 * lpfc_check_sparm() routine is invoked to check the parameters in the
6562 * unsolicited FLOGI. If parameters validation failed, the routine
6563 * lpfc_els_rsp_reject() shall be called with reject reason code set to
6564 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
6565 * FLOGI shall be compared with the Port WWN of the @vport to determine who
6566 * will initiate PLOGI. The higher lexicographical value party shall has
6567 * higher priority (as the winning port) and will initiate PLOGI and
6568 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
6569 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
6570 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
6573 * 0 - Successfully processed the unsolicited flogi
6574 * 1 - Failed to process the unsolicited flogi
6577 lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6578 struct lpfc_nodelist *ndlp)
6580 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6581 struct lpfc_hba *phba = vport->phba;
6582 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6583 uint32_t *lp = (uint32_t *) pcmd->virt;
6584 IOCB_t *icmd = &cmdiocb->iocb;
6585 struct serv_parm *sp;
6589 uint32_t fc_flag = 0;
6590 uint32_t port_state = 0;
6593 sp = (struct serv_parm *) lp;
6595 /* FLOGI received */
6597 lpfc_set_disctmo(vport);
6599 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
6600 /* We should never receive a FLOGI in loop mode, ignore it */
6601 did = icmd->un.elsreq64.remoteID;
6603 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
6605 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6606 "0113 An FLOGI ELS command x%x was "
6607 "received from DID x%x in Loop Mode\n",
6612 (void) lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1);
6615 * If our portname is greater than the remote portname,
6616 * then we initiate Nport login.
6619 rc = memcmp(&vport->fc_portname, &sp->portName,
6620 sizeof(struct lpfc_name));
6623 if (phba->sli_rev < LPFC_SLI_REV4) {
6624 mbox = mempool_alloc(phba->mbox_mem_pool,
6628 lpfc_linkdown(phba);
6629 lpfc_init_link(phba, mbox,
6631 phba->cfg_link_speed);
6632 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
6633 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
6634 mbox->vport = vport;
6635 rc = lpfc_sli_issue_mbox(phba, mbox,
6637 lpfc_set_loopback_flag(phba);
6638 if (rc == MBX_NOT_FINISHED)
6639 mempool_free(mbox, phba->mbox_mem_pool);
6643 /* abort the flogi coming back to ourselves
6644 * due to external loopback on the port.
6646 lpfc_els_abort_flogi(phba);
6649 } else if (rc > 0) { /* greater than */
6650 spin_lock_irq(shost->host_lock);
6651 vport->fc_flag |= FC_PT2PT_PLOGI;
6652 spin_unlock_irq(shost->host_lock);
6654 /* If we have the high WWPN we can assign our own
6655 * myDID; otherwise, we have to WAIT for a PLOGI
6656 * from the remote NPort to find out what it
6659 vport->fc_myDID = PT2PT_LocalID;
6661 vport->fc_myDID = PT2PT_RemoteID;
6665 * The vport state should go to LPFC_FLOGI only
6666 * AFTER we issue a FLOGI, not receive one.
6668 spin_lock_irq(shost->host_lock);
6669 fc_flag = vport->fc_flag;
6670 port_state = vport->port_state;
6671 vport->fc_flag |= FC_PT2PT;
6672 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
6674 /* Acking an unsol FLOGI. Count 1 for link bounce
6677 vport->rcv_flogi_cnt++;
6678 spin_unlock_irq(shost->host_lock);
6679 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6680 "3311 Rcv Flogi PS x%x new PS x%x "
6681 "fc_flag x%x new fc_flag x%x\n",
6682 port_state, vport->port_state,
6683 fc_flag, vport->fc_flag);
6686 * We temporarily set fc_myDID to make it look like we are
6687 * a Fabric. This is done just so we end up with the right
6688 * did / sid on the FLOGI ACC rsp.
6690 did = vport->fc_myDID;
6691 vport->fc_myDID = Fabric_DID;
6693 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
6695 /* Defer ACC response until AFTER we issue a FLOGI */
6696 if (!(phba->hba_flag & HBA_FLOGI_ISSUED)) {
6697 phba->defer_flogi_acc_rx_id = cmdiocb->iocb.ulpContext;
6698 phba->defer_flogi_acc_ox_id =
6699 cmdiocb->iocb.unsli3.rcvsli3.ox_id;
6701 vport->fc_myDID = did;
6703 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6704 "3344 Deferring FLOGI ACC: rx_id: x%x,"
6705 " ox_id: x%x, hba_flag x%x\n",
6706 phba->defer_flogi_acc_rx_id,
6707 phba->defer_flogi_acc_ox_id, phba->hba_flag);
6709 phba->defer_flogi_acc_flag = true;
6715 lpfc_els_rsp_acc(vport, ELS_CMD_FLOGI, cmdiocb, ndlp, NULL);
6717 /* Now lets put fc_myDID back to what its supposed to be */
6718 vport->fc_myDID = did;
6724 * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
6725 * @vport: pointer to a host virtual N_Port data structure.
6726 * @cmdiocb: pointer to lpfc command iocb data structure.
6727 * @ndlp: pointer to a node-list data structure.
6729 * This routine processes Request Node Identification Data (RNID) IOCB
6730 * received as an ELS unsolicited event. Only when the RNID specified format
6731 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
6732 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
6733 * Accept (ACC) the RNID ELS command. All the other RNID formats are
6734 * rejected by invoking the lpfc_els_rsp_reject() routine.
6737 * 0 - Successfully processed rnid iocb (currently always return 0)
6740 lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6741 struct lpfc_nodelist *ndlp)
6743 struct lpfc_dmabuf *pcmd;
6749 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6750 lp = (uint32_t *) pcmd->virt;
6757 switch (rn->Format) {
6759 case RNID_TOPOLOGY_DISC:
6761 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
6764 /* Reject this request because format not supported */
6765 stat.un.b.lsRjtRsvd0 = 0;
6766 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6767 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
6768 stat.un.b.vendorUnique = 0;
6769 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
6776 * lpfc_els_rcv_echo - Process an unsolicited echo iocb
6777 * @vport: pointer to a host virtual N_Port data structure.
6778 * @cmdiocb: pointer to lpfc command iocb data structure.
6779 * @ndlp: pointer to a node-list data structure.
6782 * 0 - Successfully processed echo iocb (currently always return 0)
6785 lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6786 struct lpfc_nodelist *ndlp)
6790 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
6792 /* skip over first word of echo command to find echo data */
6793 pcmd += sizeof(uint32_t);
6795 lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp);
6800 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
6801 * @vport: pointer to a host virtual N_Port data structure.
6802 * @cmdiocb: pointer to lpfc command iocb data structure.
6803 * @ndlp: pointer to a node-list data structure.
6805 * This routine processes a Link Incident Report Registration(LIRR) IOCB
6806 * received as an ELS unsolicited event. Currently, this function just invokes
6807 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
6810 * 0 - Successfully processed lirr iocb (currently always return 0)
6813 lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6814 struct lpfc_nodelist *ndlp)
6818 /* For now, unconditionally reject this command */
6819 stat.un.b.lsRjtRsvd0 = 0;
6820 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6821 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
6822 stat.un.b.vendorUnique = 0;
6823 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
6828 * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb
6829 * @vport: pointer to a host virtual N_Port data structure.
6830 * @cmdiocb: pointer to lpfc command iocb data structure.
6831 * @ndlp: pointer to a node-list data structure.
6833 * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB
6834 * received as an ELS unsolicited event. A request to RRQ shall only
6835 * be accepted if the Originator Nx_Port N_Port_ID or the Responder
6836 * Nx_Port N_Port_ID of the target Exchange is the same as the
6837 * N_Port_ID of the Nx_Port that makes the request. If the RRQ is
6838 * not accepted, an LS_RJT with reason code "Unable to perform
6839 * command request" and reason code explanation "Invalid Originator
6840 * S_ID" shall be returned. For now, we just unconditionally accept
6841 * RRQ from the target.
6844 lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6845 struct lpfc_nodelist *ndlp)
6847 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
6848 if (vport->phba->sli_rev == LPFC_SLI_REV4)
6849 lpfc_els_clear_rrq(vport, cmdiocb, ndlp);
6853 * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
6854 * @phba: pointer to lpfc hba data structure.
6855 * @pmb: pointer to the driver internal queue element for mailbox command.
6857 * This routine is the completion callback function for the MBX_READ_LNK_STAT
6858 * mailbox command. This callback function is to actually send the Accept
6859 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
6860 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
6861 * mailbox command, constructs the RPS response with the link statistics
6862 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
6863 * response to the RPS.
6865 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6866 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6867 * will be stored into the context1 field of the IOCB for the completion
6868 * callback function to the RPS Accept Response ELS IOCB command.
6872 lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
6876 struct RLS_RSP *rls_rsp;
6878 struct lpfc_iocbq *elsiocb;
6879 struct lpfc_nodelist *ndlp;
6886 ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
6887 rxid = (uint16_t)((unsigned long)(pmb->ctx_buf) & 0xffff);
6888 oxid = (uint16_t)(((unsigned long)(pmb->ctx_buf) >> 16) & 0xffff);
6889 pmb->ctx_buf = NULL;
6890 pmb->ctx_ndlp = NULL;
6892 if (mb->mbxStatus) {
6893 mempool_free(pmb, phba->mbox_mem_pool);
6897 cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t);
6898 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
6899 lpfc_max_els_tries, ndlp,
6900 ndlp->nlp_DID, ELS_CMD_ACC);
6902 /* Decrement the ndlp reference count from previous mbox command */
6906 mempool_free(pmb, phba->mbox_mem_pool);
6910 icmd = &elsiocb->iocb;
6911 icmd->ulpContext = rxid;
6912 icmd->unsli3.rcvsli3.ox_id = oxid;
6914 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6915 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
6916 pcmd += sizeof(uint32_t); /* Skip past command */
6917 rls_rsp = (struct RLS_RSP *)pcmd;
6919 rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
6920 rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
6921 rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
6922 rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
6923 rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
6924 rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
6925 mempool_free(pmb, phba->mbox_mem_pool);
6926 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
6927 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
6928 "2874 Xmit ELS RLS ACC response tag x%x xri x%x, "
6929 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
6930 elsiocb->iotag, elsiocb->iocb.ulpContext,
6931 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
6933 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
6934 phba->fc_stat.elsXmitACC++;
6935 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
6936 lpfc_els_free_iocb(phba, elsiocb);
6940 * lpfc_els_rsp_rps_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
6941 * @phba: pointer to lpfc hba data structure.
6942 * @pmb: pointer to the driver internal queue element for mailbox command.
6944 * This routine is the completion callback function for the MBX_READ_LNK_STAT
6945 * mailbox command. This callback function is to actually send the Accept
6946 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
6947 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
6948 * mailbox command, constructs the RPS response with the link statistics
6949 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
6950 * response to the RPS.
6952 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6953 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6954 * will be stored into the context1 field of the IOCB for the completion
6955 * callback function to the RPS Accept Response ELS IOCB command.
6959 lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
6965 struct lpfc_iocbq *elsiocb;
6966 struct lpfc_nodelist *ndlp;
6974 ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
6975 rxid = (uint16_t)((unsigned long)(pmb->ctx_buf) & 0xffff);
6976 oxid = (uint16_t)(((unsigned long)(pmb->ctx_buf) >> 16) & 0xffff);
6977 pmb->ctx_ndlp = NULL;
6978 pmb->ctx_buf = NULL;
6980 if (mb->mbxStatus) {
6981 mempool_free(pmb, phba->mbox_mem_pool);
6985 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
6986 mempool_free(pmb, phba->mbox_mem_pool);
6987 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
6988 lpfc_max_els_tries, ndlp,
6989 ndlp->nlp_DID, ELS_CMD_ACC);
6991 /* Decrement the ndlp reference count from previous mbox command */
6997 icmd = &elsiocb->iocb;
6998 icmd->ulpContext = rxid;
6999 icmd->unsli3.rcvsli3.ox_id = oxid;
7001 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7002 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
7003 pcmd += sizeof(uint32_t); /* Skip past command */
7004 rps_rsp = (RPS_RSP *)pcmd;
7006 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP)
7010 if (phba->pport->fc_flag & FC_FABRIC)
7014 rps_rsp->portStatus = cpu_to_be16(status);
7015 rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
7016 rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
7017 rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
7018 rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
7019 rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
7020 rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
7021 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
7022 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
7023 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
7024 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
7025 elsiocb->iotag, elsiocb->iocb.ulpContext,
7026 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
7028 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
7029 phba->fc_stat.elsXmitACC++;
7030 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
7031 lpfc_els_free_iocb(phba, elsiocb);
7036 * lpfc_els_rcv_rls - Process an unsolicited rls iocb
7037 * @vport: pointer to a host virtual N_Port data structure.
7038 * @cmdiocb: pointer to lpfc command iocb data structure.
7039 * @ndlp: pointer to a node-list data structure.
7041 * This routine processes Read Port Status (RPL) IOCB received as an
7042 * ELS unsolicited event. It first checks the remote port state. If the
7043 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
7044 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
7045 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
7046 * for reading the HBA link statistics. It is for the callback function,
7047 * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command
7048 * to actually sending out RPL Accept (ACC) response.
7051 * 0 - Successfully processed rls iocb (currently always return 0)
7054 lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7055 struct lpfc_nodelist *ndlp)
7057 struct lpfc_hba *phba = vport->phba;
7061 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
7062 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
7063 /* reject the unsolicited RPS request and done with it */
7066 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
7068 lpfc_read_lnk_stat(phba, mbox);
7069 mbox->ctx_buf = (void *)((unsigned long)
7070 ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) |
7071 cmdiocb->iocb.ulpContext)); /* rx_id */
7072 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
7073 mbox->vport = vport;
7074 mbox->mbox_cmpl = lpfc_els_rsp_rls_acc;
7075 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
7076 != MBX_NOT_FINISHED)
7077 /* Mbox completion will send ELS Response */
7079 /* Decrement reference count used for the failed mbox
7083 mempool_free(mbox, phba->mbox_mem_pool);
7086 /* issue rejection response */
7087 stat.un.b.lsRjtRsvd0 = 0;
7088 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
7089 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
7090 stat.un.b.vendorUnique = 0;
7091 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
7096 * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb
7097 * @vport: pointer to a host virtual N_Port data structure.
7098 * @cmdiocb: pointer to lpfc command iocb data structure.
7099 * @ndlp: pointer to a node-list data structure.
7101 * This routine processes Read Timout Value (RTV) IOCB received as an
7102 * ELS unsolicited event. It first checks the remote port state. If the
7103 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
7104 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
7105 * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout
7106 * Value (RTV) unsolicited IOCB event.
7108 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7109 * will be incremented by 1 for holding the ndlp and the reference to ndlp
7110 * will be stored into the context1 field of the IOCB for the completion
7111 * callback function to the RPS Accept Response ELS IOCB command.
7114 * 0 - Successfully processed rtv iocb (currently always return 0)
7117 lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7118 struct lpfc_nodelist *ndlp)
7120 struct lpfc_hba *phba = vport->phba;
7122 struct RTV_RSP *rtv_rsp;
7124 struct lpfc_iocbq *elsiocb;
7128 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
7129 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
7130 /* reject the unsolicited RPS request and done with it */
7133 cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t);
7134 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
7135 lpfc_max_els_tries, ndlp,
7136 ndlp->nlp_DID, ELS_CMD_ACC);
7141 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7142 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
7143 pcmd += sizeof(uint32_t); /* Skip past command */
7145 /* use the command's xri in the response */
7146 elsiocb->iocb.ulpContext = cmdiocb->iocb.ulpContext; /* Xri / rx_id */
7147 elsiocb->iocb.unsli3.rcvsli3.ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id;
7149 rtv_rsp = (struct RTV_RSP *)pcmd;
7151 /* populate RTV payload */
7152 rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000); /* report msecs */
7153 rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov);
7154 bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0);
7155 bf_set(qtov_rttov, rtv_rsp, 0); /* Field is for FC ONLY */
7156 rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov);
7158 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
7159 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
7160 "2875 Xmit ELS RTV ACC response tag x%x xri x%x, "
7161 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, "
7162 "Data: x%x x%x x%x\n",
7163 elsiocb->iotag, elsiocb->iocb.ulpContext,
7164 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
7166 rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov);
7167 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
7168 phba->fc_stat.elsXmitACC++;
7169 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
7170 lpfc_els_free_iocb(phba, elsiocb);
7174 /* issue rejection response */
7175 stat.un.b.lsRjtRsvd0 = 0;
7176 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
7177 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
7178 stat.un.b.vendorUnique = 0;
7179 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
7183 /* lpfc_els_rcv_rps - Process an unsolicited rps iocb
7184 * @vport: pointer to a host virtual N_Port data structure.
7185 * @cmdiocb: pointer to lpfc command iocb data structure.
7186 * @ndlp: pointer to a node-list data structure.
7188 * This routine processes Read Port Status (RPS) IOCB received as an
7189 * ELS unsolicited event. It first checks the remote port state. If the
7190 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
7191 * state, it invokes the lpfc_els_rsp_reject() routine to send the reject
7192 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
7193 * for reading the HBA link statistics. It is for the callback function,
7194 * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command
7195 * to actually sending out RPS Accept (ACC) response.
7198 * 0 - Successfully processed rps iocb (currently always return 0)
7201 lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7202 struct lpfc_nodelist *ndlp)
7204 struct lpfc_hba *phba = vport->phba;
7208 struct lpfc_dmabuf *pcmd;
7212 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
7213 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
7214 /* reject the unsolicited RPS request and done with it */
7217 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7218 lp = (uint32_t *) pcmd->virt;
7219 flag = (be32_to_cpu(*lp++) & 0xf);
7223 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
7224 ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
7225 sizeof(struct lpfc_name)) == 0))) {
7227 printk("Fix me....\n");
7229 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
7231 lpfc_read_lnk_stat(phba, mbox);
7232 mbox->ctx_buf = (void *)((unsigned long)
7233 ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) |
7234 cmdiocb->iocb.ulpContext)); /* rx_id */
7235 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
7236 mbox->vport = vport;
7237 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
7238 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
7239 != MBX_NOT_FINISHED)
7240 /* Mbox completion will send ELS Response */
7242 /* Decrement reference count used for the failed mbox
7246 mempool_free(mbox, phba->mbox_mem_pool);
7251 /* issue rejection response */
7252 stat.un.b.lsRjtRsvd0 = 0;
7253 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
7254 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
7255 stat.un.b.vendorUnique = 0;
7256 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
7260 /* lpfc_issue_els_rrq - Process an unsolicited rps iocb
7261 * @vport: pointer to a host virtual N_Port data structure.
7262 * @ndlp: pointer to a node-list data structure.
7263 * @did: DID of the target.
7264 * @rrq: Pointer to the rrq struct.
7266 * Build a ELS RRQ command and send it to the target. If the issue_iocb is
7267 * Successful the the completion handler will clear the RRQ.
7270 * 0 - Successfully sent rrq els iocb.
7271 * 1 - Failed to send rrq els iocb.
7274 lpfc_issue_els_rrq(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
7275 uint32_t did, struct lpfc_node_rrq *rrq)
7277 struct lpfc_hba *phba = vport->phba;
7278 struct RRQ *els_rrq;
7279 struct lpfc_iocbq *elsiocb;
7285 if (ndlp != rrq->ndlp)
7287 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
7290 /* If ndlp is not NULL, we will bump the reference count on it */
7291 cmdsize = (sizeof(uint32_t) + sizeof(struct RRQ));
7292 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, did,
7297 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7299 /* For RRQ request, remainder of payload is Exchange IDs */
7300 *((uint32_t *) (pcmd)) = ELS_CMD_RRQ;
7301 pcmd += sizeof(uint32_t);
7302 els_rrq = (struct RRQ *) pcmd;
7304 bf_set(rrq_oxid, els_rrq, phba->sli4_hba.xri_ids[rrq->xritag]);
7305 bf_set(rrq_rxid, els_rrq, rrq->rxid);
7306 bf_set(rrq_did, els_rrq, vport->fc_myDID);
7307 els_rrq->rrq = cpu_to_be32(els_rrq->rrq);
7308 els_rrq->rrq_exchg = cpu_to_be32(els_rrq->rrq_exchg);
7311 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7312 "Issue RRQ: did:x%x",
7313 did, rrq->xritag, rrq->rxid);
7314 elsiocb->context_un.rrq = rrq;
7315 elsiocb->iocb_cmpl = lpfc_cmpl_els_rrq;
7316 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
7318 if (ret == IOCB_ERROR) {
7319 lpfc_els_free_iocb(phba, elsiocb);
7326 * lpfc_send_rrq - Sends ELS RRQ if needed.
7327 * @phba: pointer to lpfc hba data structure.
7328 * @rrq: pointer to the active rrq.
7330 * This routine will call the lpfc_issue_els_rrq if the rrq is
7331 * still active for the xri. If this function returns a failure then
7332 * the caller needs to clean up the RRQ by calling lpfc_clr_active_rrq.
7334 * Returns 0 Success.
7338 lpfc_send_rrq(struct lpfc_hba *phba, struct lpfc_node_rrq *rrq)
7340 struct lpfc_nodelist *ndlp = lpfc_findnode_did(rrq->vport,
7342 if (lpfc_test_rrq_active(phba, ndlp, rrq->xritag))
7343 return lpfc_issue_els_rrq(rrq->vport, ndlp,
7350 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
7351 * @vport: pointer to a host virtual N_Port data structure.
7352 * @cmdsize: size of the ELS command.
7353 * @oldiocb: pointer to the original lpfc command iocb data structure.
7354 * @ndlp: pointer to a node-list data structure.
7356 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
7357 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
7359 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7360 * will be incremented by 1 for holding the ndlp and the reference to ndlp
7361 * will be stored into the context1 field of the IOCB for the completion
7362 * callback function to the RPL Accept Response ELS command.
7365 * 0 - Successfully issued ACC RPL ELS command
7366 * 1 - Failed to issue ACC RPL ELS command
7369 lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
7370 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
7372 struct lpfc_hba *phba = vport->phba;
7373 IOCB_t *icmd, *oldcmd;
7375 struct lpfc_iocbq *elsiocb;
7378 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
7379 ndlp->nlp_DID, ELS_CMD_ACC);
7384 icmd = &elsiocb->iocb;
7385 oldcmd = &oldiocb->iocb;
7386 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
7387 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
7389 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7390 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
7391 pcmd += sizeof(uint16_t);
7392 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
7393 pcmd += sizeof(uint16_t);
7395 /* Setup the RPL ACC payload */
7396 rpl_rsp.listLen = be32_to_cpu(1);
7398 rpl_rsp.port_num_blk.portNum = 0;
7399 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
7400 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
7401 sizeof(struct lpfc_name));
7402 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
7403 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
7404 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7405 "0120 Xmit ELS RPL ACC response tag x%x "
7406 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
7408 elsiocb->iotag, elsiocb->iocb.ulpContext,
7409 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
7411 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
7412 phba->fc_stat.elsXmitACC++;
7413 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
7415 lpfc_els_free_iocb(phba, elsiocb);
7422 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
7423 * @vport: pointer to a host virtual N_Port data structure.
7424 * @cmdiocb: pointer to lpfc command iocb data structure.
7425 * @ndlp: pointer to a node-list data structure.
7427 * This routine processes Read Port List (RPL) IOCB received as an ELS
7428 * unsolicited event. It first checks the remote port state. If the remote
7429 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
7430 * invokes the lpfc_els_rsp_reject() routine to send reject response.
7431 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
7432 * to accept the RPL.
7435 * 0 - Successfully processed rpl iocb (currently always return 0)
7438 lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7439 struct lpfc_nodelist *ndlp)
7441 struct lpfc_dmabuf *pcmd;
7448 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
7449 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
7450 /* issue rejection response */
7451 stat.un.b.lsRjtRsvd0 = 0;
7452 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
7453 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
7454 stat.un.b.vendorUnique = 0;
7455 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
7457 /* rejected the unsolicited RPL request and done with it */
7461 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7462 lp = (uint32_t *) pcmd->virt;
7463 rpl = (RPL *) (lp + 1);
7464 maxsize = be32_to_cpu(rpl->maxsize);
7466 /* We support only one port */
7467 if ((rpl->index == 0) &&
7469 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
7470 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
7472 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
7474 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
7480 * lpfc_els_rcv_farp - Process an unsolicited farp request els command
7481 * @vport: pointer to a virtual N_Port data structure.
7482 * @cmdiocb: pointer to lpfc command iocb data structure.
7483 * @ndlp: pointer to a node-list data structure.
7485 * This routine processes Fibre Channel Address Resolution Protocol
7486 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
7487 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
7488 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
7489 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
7490 * remote PortName is compared against the FC PortName stored in the @vport
7491 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
7492 * compared against the FC NodeName stored in the @vport data structure.
7493 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
7494 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
7495 * invoked to send out FARP Response to the remote node. Before sending the
7496 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
7497 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
7498 * routine is invoked to log into the remote port first.
7501 * 0 - Either the FARP Match Mode not supported or successfully processed
7504 lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7505 struct lpfc_nodelist *ndlp)
7507 struct lpfc_dmabuf *pcmd;
7511 uint32_t cmd, cnt, did;
7513 icmd = &cmdiocb->iocb;
7514 did = icmd->un.elsreq64.remoteID;
7515 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7516 lp = (uint32_t *) pcmd->virt;
7520 /* FARP-REQ received from DID <did> */
7521 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7522 "0601 FARP-REQ received from DID x%x\n", did);
7523 /* We will only support match on WWPN or WWNN */
7524 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
7529 /* If this FARP command is searching for my portname */
7530 if (fp->Mflags & FARP_MATCH_PORT) {
7531 if (memcmp(&fp->RportName, &vport->fc_portname,
7532 sizeof(struct lpfc_name)) == 0)
7536 /* If this FARP command is searching for my nodename */
7537 if (fp->Mflags & FARP_MATCH_NODE) {
7538 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
7539 sizeof(struct lpfc_name)) == 0)
7544 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
7545 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
7546 /* Log back into the node before sending the FARP. */
7547 if (fp->Rflags & FARP_REQUEST_PLOGI) {
7548 ndlp->nlp_prev_state = ndlp->nlp_state;
7549 lpfc_nlp_set_state(vport, ndlp,
7550 NLP_STE_PLOGI_ISSUE);
7551 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
7554 /* Send a FARP response to that node */
7555 if (fp->Rflags & FARP_REQUEST_FARPR)
7556 lpfc_issue_els_farpr(vport, did, 0);
7563 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
7564 * @vport: pointer to a host virtual N_Port data structure.
7565 * @cmdiocb: pointer to lpfc command iocb data structure.
7566 * @ndlp: pointer to a node-list data structure.
7568 * This routine processes Fibre Channel Address Resolution Protocol
7569 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
7570 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
7571 * the FARP response request.
7574 * 0 - Successfully processed FARPR IOCB (currently always return 0)
7577 lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7578 struct lpfc_nodelist *ndlp)
7580 struct lpfc_dmabuf *pcmd;
7585 icmd = &cmdiocb->iocb;
7586 did = icmd->un.elsreq64.remoteID;
7587 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7588 lp = (uint32_t *) pcmd->virt;
7591 /* FARP-RSP received from DID <did> */
7592 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7593 "0600 FARP-RSP received from DID x%x\n", did);
7594 /* ACCEPT the Farp resp request */
7595 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
7601 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
7602 * @vport: pointer to a host virtual N_Port data structure.
7603 * @cmdiocb: pointer to lpfc command iocb data structure.
7604 * @fan_ndlp: pointer to a node-list data structure.
7606 * This routine processes a Fabric Address Notification (FAN) IOCB
7607 * command received as an ELS unsolicited event. The FAN ELS command will
7608 * only be processed on a physical port (i.e., the @vport represents the
7609 * physical port). The fabric NodeName and PortName from the FAN IOCB are
7610 * compared against those in the phba data structure. If any of those is
7611 * different, the lpfc_initial_flogi() routine is invoked to initialize
7612 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
7613 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
7614 * is invoked to register login to the fabric.
7617 * 0 - Successfully processed fan iocb (currently always return 0).
7620 lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7621 struct lpfc_nodelist *fan_ndlp)
7623 struct lpfc_hba *phba = vport->phba;
7627 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
7628 lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
7630 /* FAN received; Fan does not have a reply sequence */
7631 if ((vport == phba->pport) &&
7632 (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
7633 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
7634 sizeof(struct lpfc_name))) ||
7635 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
7636 sizeof(struct lpfc_name)))) {
7637 /* This port has switched fabrics. FLOGI is required */
7638 lpfc_issue_init_vfi(vport);
7640 /* FAN verified - skip FLOGI */
7641 vport->fc_myDID = vport->fc_prevDID;
7642 if (phba->sli_rev < LPFC_SLI_REV4)
7643 lpfc_issue_fabric_reglogin(vport);
7645 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7646 "3138 Need register VFI: (x%x/%x)\n",
7647 vport->fc_prevDID, vport->fc_myDID);
7648 lpfc_issue_reg_vfi(vport);
7656 * lpfc_els_timeout - Handler funciton to the els timer
7657 * @ptr: holder for the timer function associated data.
7659 * This routine is invoked by the ELS timer after timeout. It posts the ELS
7660 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
7661 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
7662 * up the worker thread. It is for the worker thread to invoke the routine
7663 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
7666 lpfc_els_timeout(struct timer_list *t)
7668 struct lpfc_vport *vport = from_timer(vport, t, els_tmofunc);
7669 struct lpfc_hba *phba = vport->phba;
7670 uint32_t tmo_posted;
7671 unsigned long iflag;
7673 spin_lock_irqsave(&vport->work_port_lock, iflag);
7674 tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
7675 if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING)))
7676 vport->work_port_events |= WORKER_ELS_TMO;
7677 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
7679 if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING)))
7680 lpfc_worker_wake_up(phba);
7686 * lpfc_els_timeout_handler - Process an els timeout event
7687 * @vport: pointer to a virtual N_Port data structure.
7689 * This routine is the actual handler function that processes an ELS timeout
7690 * event. It walks the ELS ring to get and abort all the IOCBs (except the
7691 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
7692 * invoking the lpfc_sli_issue_abort_iotag() routine.
7695 lpfc_els_timeout_handler(struct lpfc_vport *vport)
7697 struct lpfc_hba *phba = vport->phba;
7698 struct lpfc_sli_ring *pring;
7699 struct lpfc_iocbq *tmp_iocb, *piocb;
7701 struct lpfc_dmabuf *pcmd;
7702 uint32_t els_command = 0;
7704 uint32_t remote_ID = 0xffffffff;
7705 LIST_HEAD(abort_list);
7708 timeout = (uint32_t)(phba->fc_ratov << 1);
7710 pring = lpfc_phba_elsring(phba);
7711 if (unlikely(!pring))
7714 if ((phba->pport->load_flag & FC_UNLOADING))
7716 spin_lock_irq(&phba->hbalock);
7717 if (phba->sli_rev == LPFC_SLI_REV4)
7718 spin_lock(&pring->ring_lock);
7720 if ((phba->pport->load_flag & FC_UNLOADING)) {
7721 if (phba->sli_rev == LPFC_SLI_REV4)
7722 spin_unlock(&pring->ring_lock);
7723 spin_unlock_irq(&phba->hbalock);
7727 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
7730 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
7731 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
7732 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
7735 if (piocb->vport != vport)
7738 pcmd = (struct lpfc_dmabuf *) piocb->context2;
7740 els_command = *(uint32_t *) (pcmd->virt);
7742 if (els_command == ELS_CMD_FARP ||
7743 els_command == ELS_CMD_FARPR ||
7744 els_command == ELS_CMD_FDISC)
7747 if (piocb->drvrTimeout > 0) {
7748 if (piocb->drvrTimeout >= timeout)
7749 piocb->drvrTimeout -= timeout;
7751 piocb->drvrTimeout = 0;
7755 remote_ID = 0xffffffff;
7756 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
7757 remote_ID = cmd->un.elsreq64.remoteID;
7759 struct lpfc_nodelist *ndlp;
7760 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
7761 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
7762 remote_ID = ndlp->nlp_DID;
7764 list_add_tail(&piocb->dlist, &abort_list);
7766 if (phba->sli_rev == LPFC_SLI_REV4)
7767 spin_unlock(&pring->ring_lock);
7768 spin_unlock_irq(&phba->hbalock);
7770 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
7772 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7773 "0127 ELS timeout Data: x%x x%x x%x "
7774 "x%x\n", els_command,
7775 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
7776 spin_lock_irq(&phba->hbalock);
7777 list_del_init(&piocb->dlist);
7778 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
7779 spin_unlock_irq(&phba->hbalock);
7782 if (!list_empty(&pring->txcmplq))
7783 if (!(phba->pport->load_flag & FC_UNLOADING))
7784 mod_timer(&vport->els_tmofunc,
7785 jiffies + msecs_to_jiffies(1000 * timeout));
7789 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
7790 * @vport: pointer to a host virtual N_Port data structure.
7792 * This routine is used to clean up all the outstanding ELS commands on a
7793 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
7794 * routine. After that, it walks the ELS transmit queue to remove all the
7795 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
7796 * the IOCBs with a non-NULL completion callback function, the callback
7797 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
7798 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
7799 * callback function, the IOCB will simply be released. Finally, it walks
7800 * the ELS transmit completion queue to issue an abort IOCB to any transmit
7801 * completion queue IOCB that is associated with the @vport and is not
7802 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
7803 * part of the discovery state machine) out to HBA by invoking the
7804 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
7805 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
7806 * the IOCBs are aborted when this function returns.
7809 lpfc_els_flush_cmd(struct lpfc_vport *vport)
7811 LIST_HEAD(abort_list);
7812 struct lpfc_hba *phba = vport->phba;
7813 struct lpfc_sli_ring *pring;
7814 struct lpfc_iocbq *tmp_iocb, *piocb;
7817 lpfc_fabric_abort_vport(vport);
7819 * For SLI3, only the hbalock is required. But SLI4 needs to coordinate
7820 * with the ring insert operation. Because lpfc_sli_issue_abort_iotag
7821 * ultimately grabs the ring_lock, the driver must splice the list into
7822 * a working list and release the locks before calling the abort.
7824 spin_lock_irq(&phba->hbalock);
7825 pring = lpfc_phba_elsring(phba);
7827 /* Bail out if we've no ELS wq, like in PCI error recovery case. */
7828 if (unlikely(!pring)) {
7829 spin_unlock_irq(&phba->hbalock);
7833 if (phba->sli_rev == LPFC_SLI_REV4)
7834 spin_lock(&pring->ring_lock);
7836 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
7837 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
7840 if (piocb->vport != vport)
7842 list_add_tail(&piocb->dlist, &abort_list);
7844 if (phba->sli_rev == LPFC_SLI_REV4)
7845 spin_unlock(&pring->ring_lock);
7846 spin_unlock_irq(&phba->hbalock);
7847 /* Abort each iocb on the aborted list and remove the dlist links. */
7848 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
7849 spin_lock_irq(&phba->hbalock);
7850 list_del_init(&piocb->dlist);
7851 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
7852 spin_unlock_irq(&phba->hbalock);
7854 if (!list_empty(&abort_list))
7855 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7856 "3387 abort list for txq not empty\n");
7857 INIT_LIST_HEAD(&abort_list);
7859 spin_lock_irq(&phba->hbalock);
7860 if (phba->sli_rev == LPFC_SLI_REV4)
7861 spin_lock(&pring->ring_lock);
7863 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
7866 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
7870 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
7871 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
7872 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
7873 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
7874 cmd->ulpCommand == CMD_ABORT_XRI_CN)
7877 if (piocb->vport != vport)
7880 list_del_init(&piocb->list);
7881 list_add_tail(&piocb->list, &abort_list);
7883 if (phba->sli_rev == LPFC_SLI_REV4)
7884 spin_unlock(&pring->ring_lock);
7885 spin_unlock_irq(&phba->hbalock);
7887 /* Cancell all the IOCBs from the completions list */
7888 lpfc_sli_cancel_iocbs(phba, &abort_list,
7889 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
7895 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
7896 * @phba: pointer to lpfc hba data structure.
7898 * This routine is used to clean up all the outstanding ELS commands on a
7899 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
7900 * routine. After that, it walks the ELS transmit queue to remove all the
7901 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
7902 * the IOCBs with the completion callback function associated, the callback
7903 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
7904 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
7905 * callback function associated, the IOCB will simply be released. Finally,
7906 * it walks the ELS transmit completion queue to issue an abort IOCB to any
7907 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
7908 * management plane IOCBs that are not part of the discovery state machine)
7909 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
7912 lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
7914 struct lpfc_vport *vport;
7916 spin_lock_irq(&phba->port_list_lock);
7917 list_for_each_entry(vport, &phba->port_list, listentry)
7918 lpfc_els_flush_cmd(vport);
7919 spin_unlock_irq(&phba->port_list_lock);
7925 * lpfc_send_els_failure_event - Posts an ELS command failure event
7926 * @phba: Pointer to hba context object.
7927 * @cmdiocbp: Pointer to command iocb which reported error.
7928 * @rspiocbp: Pointer to response iocb which reported error.
7930 * This function sends an event when there is an ELS command
7934 lpfc_send_els_failure_event(struct lpfc_hba *phba,
7935 struct lpfc_iocbq *cmdiocbp,
7936 struct lpfc_iocbq *rspiocbp)
7938 struct lpfc_vport *vport = cmdiocbp->vport;
7939 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7940 struct lpfc_lsrjt_event lsrjt_event;
7941 struct lpfc_fabric_event_header fabric_event;
7943 struct lpfc_nodelist *ndlp;
7946 ndlp = cmdiocbp->context1;
7947 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
7950 if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) {
7951 lsrjt_event.header.event_type = FC_REG_ELS_EVENT;
7952 lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV;
7953 memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname,
7954 sizeof(struct lpfc_name));
7955 memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename,
7956 sizeof(struct lpfc_name));
7957 pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
7958 cmdiocbp->context2)->virt);
7959 lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0;
7960 stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]);
7961 lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode;
7962 lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp;
7963 fc_host_post_vendor_event(shost,
7964 fc_get_event_number(),
7965 sizeof(lsrjt_event),
7966 (char *)&lsrjt_event,
7970 if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) ||
7971 (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) {
7972 fabric_event.event_type = FC_REG_FABRIC_EVENT;
7973 if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY)
7974 fabric_event.subcategory = LPFC_EVENT_PORT_BUSY;
7976 fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY;
7977 memcpy(fabric_event.wwpn, &ndlp->nlp_portname,
7978 sizeof(struct lpfc_name));
7979 memcpy(fabric_event.wwnn, &ndlp->nlp_nodename,
7980 sizeof(struct lpfc_name));
7981 fc_host_post_vendor_event(shost,
7982 fc_get_event_number(),
7983 sizeof(fabric_event),
7984 (char *)&fabric_event,
7992 * lpfc_send_els_event - Posts unsolicited els event
7993 * @vport: Pointer to vport object.
7994 * @ndlp: Pointer FC node object.
7995 * @cmd: ELS command code.
7997 * This function posts an event when there is an incoming
7998 * unsolicited ELS command.
8001 lpfc_send_els_event(struct lpfc_vport *vport,
8002 struct lpfc_nodelist *ndlp,
8005 struct lpfc_els_event_header *els_data = NULL;
8006 struct lpfc_logo_event *logo_data = NULL;
8007 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8009 if (*payload == ELS_CMD_LOGO) {
8010 logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL);
8012 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8013 "0148 Failed to allocate memory "
8014 "for LOGO event\n");
8017 els_data = &logo_data->header;
8019 els_data = kmalloc(sizeof(struct lpfc_els_event_header),
8022 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8023 "0149 Failed to allocate memory "
8028 els_data->event_type = FC_REG_ELS_EVENT;
8031 els_data->subcategory = LPFC_EVENT_PLOGI_RCV;
8034 els_data->subcategory = LPFC_EVENT_PRLO_RCV;
8037 els_data->subcategory = LPFC_EVENT_ADISC_RCV;
8040 els_data->subcategory = LPFC_EVENT_LOGO_RCV;
8041 /* Copy the WWPN in the LOGO payload */
8042 memcpy(logo_data->logo_wwpn, &payload[2],
8043 sizeof(struct lpfc_name));
8049 memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name));
8050 memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name));
8051 if (*payload == ELS_CMD_LOGO) {
8052 fc_host_post_vendor_event(shost,
8053 fc_get_event_number(),
8054 sizeof(struct lpfc_logo_event),
8059 fc_host_post_vendor_event(shost,
8060 fc_get_event_number(),
8061 sizeof(struct lpfc_els_event_header),
8072 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
8073 * @phba: pointer to lpfc hba data structure.
8074 * @pring: pointer to a SLI ring.
8075 * @vport: pointer to a host virtual N_Port data structure.
8076 * @elsiocb: pointer to lpfc els command iocb data structure.
8078 * This routine is used for processing the IOCB associated with a unsolicited
8079 * event. It first determines whether there is an existing ndlp that matches
8080 * the DID from the unsolicited IOCB. If not, it will create a new one with
8081 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
8082 * IOCB is then used to invoke the proper routine and to set up proper state
8083 * of the discovery state machine.
8086 lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
8087 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
8089 struct Scsi_Host *shost;
8090 struct lpfc_nodelist *ndlp;
8093 uint32_t cmd, did, newnode;
8094 uint8_t rjt_exp, rjt_err = 0, init_link = 0;
8095 IOCB_t *icmd = &elsiocb->iocb;
8098 if (!vport || !(elsiocb->context2))
8102 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
8104 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
8105 lpfc_post_buffer(phba, pring, 1);
8107 did = icmd->un.rcvels.remoteID;
8108 if (icmd->ulpStatus) {
8109 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8110 "RCV Unsol ELS: status:x%x/x%x did:x%x",
8111 icmd->ulpStatus, icmd->un.ulpWord[4], did);
8115 /* Check to see if link went down during discovery */
8116 if (lpfc_els_chk_latt(vport))
8119 /* Ignore traffic received during vport shutdown. */
8120 if (vport->load_flag & FC_UNLOADING)
8123 /* If NPort discovery is delayed drop incoming ELS */
8124 if ((vport->fc_flag & FC_DISC_DELAYED) &&
8125 (cmd != ELS_CMD_PLOGI))
8128 ndlp = lpfc_findnode_did(vport, did);
8130 /* Cannot find existing Fabric ndlp, so allocate a new one */
8131 ndlp = lpfc_nlp_init(vport, did);
8134 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
8136 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
8137 ndlp->nlp_type |= NLP_FABRIC;
8138 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
8139 ndlp = lpfc_enable_node(vport, ndlp,
8140 NLP_STE_UNUSED_NODE);
8143 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
8145 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
8146 ndlp->nlp_type |= NLP_FABRIC;
8147 } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
8148 /* This is similar to the new node path */
8149 ndlp = lpfc_nlp_get(ndlp);
8152 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
8156 phba->fc_stat.elsRcvFrame++;
8159 * Do not process any unsolicited ELS commands
8160 * if the ndlp is in DEV_LOSS
8162 shost = lpfc_shost_from_vport(vport);
8163 spin_lock_irq(shost->host_lock);
8164 if (ndlp->nlp_flag & NLP_IN_DEV_LOSS) {
8165 spin_unlock_irq(shost->host_lock);
8168 spin_unlock_irq(shost->host_lock);
8170 elsiocb->context1 = lpfc_nlp_get(ndlp);
8171 elsiocb->vport = vport;
8173 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
8174 cmd &= ELS_CMD_MASK;
8176 /* ELS command <elsCmd> received from NPORT <did> */
8177 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
8178 "0112 ELS command x%x received from NPORT x%x "
8179 "Data: x%x x%x x%x x%x\n",
8180 cmd, did, vport->port_state, vport->fc_flag,
8181 vport->fc_myDID, vport->fc_prevDID);
8183 /* reject till our FLOGI completes or PLOGI assigned DID via PT2PT */
8184 if ((vport->port_state < LPFC_FABRIC_CFG_LINK) &&
8185 (cmd != ELS_CMD_FLOGI) &&
8186 !((cmd == ELS_CMD_PLOGI) && (vport->fc_flag & FC_PT2PT))) {
8187 rjt_err = LSRJT_LOGICAL_BSY;
8188 rjt_exp = LSEXP_NOTHING_MORE;
8194 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8195 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
8196 did, vport->port_state, ndlp->nlp_flag);
8198 phba->fc_stat.elsRcvPLOGI++;
8199 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
8200 if (phba->sli_rev == LPFC_SLI_REV4 &&
8201 (phba->pport->fc_flag & FC_PT2PT)) {
8202 vport->fc_prevDID = vport->fc_myDID;
8203 /* Our DID needs to be updated before registering
8204 * the vfi. This is done in lpfc_rcv_plogi but
8205 * that is called after the reg_vfi.
8207 vport->fc_myDID = elsiocb->iocb.un.rcvels.parmRo;
8208 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
8209 "3312 Remote port assigned DID x%x "
8210 "%x\n", vport->fc_myDID,
8214 lpfc_send_els_event(vport, ndlp, payload);
8216 /* If Nport discovery is delayed, reject PLOGIs */
8217 if (vport->fc_flag & FC_DISC_DELAYED) {
8218 rjt_err = LSRJT_UNABLE_TPC;
8219 rjt_exp = LSEXP_NOTHING_MORE;
8223 if (vport->port_state < LPFC_DISC_AUTH) {
8224 if (!(phba->pport->fc_flag & FC_PT2PT) ||
8225 (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
8226 rjt_err = LSRJT_UNABLE_TPC;
8227 rjt_exp = LSEXP_NOTHING_MORE;
8232 spin_lock_irq(shost->host_lock);
8233 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
8234 spin_unlock_irq(shost->host_lock);
8236 lpfc_disc_state_machine(vport, ndlp, elsiocb,
8241 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8242 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
8243 did, vport->port_state, ndlp->nlp_flag);
8245 phba->fc_stat.elsRcvFLOGI++;
8247 /* If the driver believes fabric discovery is done and is ready,
8248 * bounce the link. There is some descrepancy.
8250 if (vport->port_state >= LPFC_LOCAL_CFG_LINK &&
8251 vport->fc_flag & FC_PT2PT &&
8252 vport->rcv_flogi_cnt >= 1) {
8253 rjt_err = LSRJT_LOGICAL_BSY;
8254 rjt_exp = LSEXP_NOTHING_MORE;
8259 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
8264 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8265 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
8266 did, vport->port_state, ndlp->nlp_flag);
8268 phba->fc_stat.elsRcvLOGO++;
8269 lpfc_send_els_event(vport, ndlp, payload);
8270 if (vport->port_state < LPFC_DISC_AUTH) {
8271 rjt_err = LSRJT_UNABLE_TPC;
8272 rjt_exp = LSEXP_NOTHING_MORE;
8275 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
8278 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8279 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
8280 did, vport->port_state, ndlp->nlp_flag);
8282 phba->fc_stat.elsRcvPRLO++;
8283 lpfc_send_els_event(vport, ndlp, payload);
8284 if (vport->port_state < LPFC_DISC_AUTH) {
8285 rjt_err = LSRJT_UNABLE_TPC;
8286 rjt_exp = LSEXP_NOTHING_MORE;
8289 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
8292 phba->fc_stat.elsRcvLCB++;
8293 lpfc_els_rcv_lcb(vport, elsiocb, ndlp);
8296 phba->fc_stat.elsRcvRDP++;
8297 lpfc_els_rcv_rdp(vport, elsiocb, ndlp);
8300 phba->fc_stat.elsRcvRSCN++;
8301 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
8306 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8307 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
8308 did, vport->port_state, ndlp->nlp_flag);
8310 lpfc_send_els_event(vport, ndlp, payload);
8311 phba->fc_stat.elsRcvADISC++;
8312 if (vport->port_state < LPFC_DISC_AUTH) {
8313 rjt_err = LSRJT_UNABLE_TPC;
8314 rjt_exp = LSEXP_NOTHING_MORE;
8317 lpfc_disc_state_machine(vport, ndlp, elsiocb,
8321 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8322 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
8323 did, vport->port_state, ndlp->nlp_flag);
8325 phba->fc_stat.elsRcvPDISC++;
8326 if (vport->port_state < LPFC_DISC_AUTH) {
8327 rjt_err = LSRJT_UNABLE_TPC;
8328 rjt_exp = LSEXP_NOTHING_MORE;
8331 lpfc_disc_state_machine(vport, ndlp, elsiocb,
8335 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8336 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
8337 did, vport->port_state, ndlp->nlp_flag);
8339 phba->fc_stat.elsRcvFARPR++;
8340 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
8343 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8344 "RCV FARP: did:x%x/ste:x%x flg:x%x",
8345 did, vport->port_state, ndlp->nlp_flag);
8347 phba->fc_stat.elsRcvFARP++;
8348 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
8351 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8352 "RCV FAN: did:x%x/ste:x%x flg:x%x",
8353 did, vport->port_state, ndlp->nlp_flag);
8355 phba->fc_stat.elsRcvFAN++;
8356 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
8359 case ELS_CMD_NVMEPRLI:
8360 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8361 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
8362 did, vport->port_state, ndlp->nlp_flag);
8364 phba->fc_stat.elsRcvPRLI++;
8365 if ((vport->port_state < LPFC_DISC_AUTH) &&
8366 (vport->fc_flag & FC_FABRIC)) {
8367 rjt_err = LSRJT_UNABLE_TPC;
8368 rjt_exp = LSEXP_NOTHING_MORE;
8371 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
8374 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8375 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
8376 did, vport->port_state, ndlp->nlp_flag);
8378 phba->fc_stat.elsRcvLIRR++;
8379 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
8384 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8385 "RCV RLS: did:x%x/ste:x%x flg:x%x",
8386 did, vport->port_state, ndlp->nlp_flag);
8388 phba->fc_stat.elsRcvRLS++;
8389 lpfc_els_rcv_rls(vport, elsiocb, ndlp);
8394 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8395 "RCV RPS: did:x%x/ste:x%x flg:x%x",
8396 did, vport->port_state, ndlp->nlp_flag);
8398 phba->fc_stat.elsRcvRPS++;
8399 lpfc_els_rcv_rps(vport, elsiocb, ndlp);
8404 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8405 "RCV RPL: did:x%x/ste:x%x flg:x%x",
8406 did, vport->port_state, ndlp->nlp_flag);
8408 phba->fc_stat.elsRcvRPL++;
8409 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
8414 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8415 "RCV RNID: did:x%x/ste:x%x flg:x%x",
8416 did, vport->port_state, ndlp->nlp_flag);
8418 phba->fc_stat.elsRcvRNID++;
8419 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
8424 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8425 "RCV RTV: did:x%x/ste:x%x flg:x%x",
8426 did, vport->port_state, ndlp->nlp_flag);
8427 phba->fc_stat.elsRcvRTV++;
8428 lpfc_els_rcv_rtv(vport, elsiocb, ndlp);
8433 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8434 "RCV RRQ: did:x%x/ste:x%x flg:x%x",
8435 did, vport->port_state, ndlp->nlp_flag);
8437 phba->fc_stat.elsRcvRRQ++;
8438 lpfc_els_rcv_rrq(vport, elsiocb, ndlp);
8443 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8444 "RCV ECHO: did:x%x/ste:x%x flg:x%x",
8445 did, vport->port_state, ndlp->nlp_flag);
8447 phba->fc_stat.elsRcvECHO++;
8448 lpfc_els_rcv_echo(vport, elsiocb, ndlp);
8453 /* receive this due to exchange closed */
8454 rjt_err = LSRJT_UNABLE_TPC;
8455 rjt_exp = LSEXP_INVALID_OX_RX;
8458 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8459 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
8460 cmd, did, vport->port_state);
8462 /* Unsupported ELS command, reject */
8463 rjt_err = LSRJT_CMD_UNSUPPORTED;
8464 rjt_exp = LSEXP_NOTHING_MORE;
8466 /* Unknown ELS command <elsCmd> received from NPORT <did> */
8467 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8468 "0115 Unknown ELS command x%x "
8469 "received from NPORT x%x\n", cmd, did);
8476 /* check if need to LS_RJT received ELS cmd */
8478 memset(&stat, 0, sizeof(stat));
8479 stat.un.b.lsRjtRsnCode = rjt_err;
8480 stat.un.b.lsRjtRsnCodeExp = rjt_exp;
8481 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
8485 lpfc_nlp_put(elsiocb->context1);
8486 elsiocb->context1 = NULL;
8488 /* Special case. Driver received an unsolicited command that
8489 * unsupportable given the driver's current state. Reset the
8490 * link and start over.
8493 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
8496 lpfc_linkdown(phba);
8497 lpfc_init_link(phba, mbox,
8499 phba->cfg_link_speed);
8500 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
8501 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
8502 mbox->vport = vport;
8503 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) ==
8505 mempool_free(mbox, phba->mbox_mem_pool);
8511 if (vport && !(vport->load_flag & FC_UNLOADING))
8512 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8513 "0111 Dropping received ELS cmd "
8514 "Data: x%x x%x x%x\n",
8515 icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout);
8516 phba->fc_stat.elsRcvDrop++;
8520 * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
8521 * @phba: pointer to lpfc hba data structure.
8522 * @pring: pointer to a SLI ring.
8523 * @elsiocb: pointer to lpfc els iocb data structure.
8525 * This routine is used to process an unsolicited event received from a SLI
8526 * (Service Level Interface) ring. The actual processing of the data buffer
8527 * associated with the unsolicited event is done by invoking the routine
8528 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
8529 * SLI ring on which the unsolicited event was received.
8532 lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
8533 struct lpfc_iocbq *elsiocb)
8535 struct lpfc_vport *vport = phba->pport;
8536 IOCB_t *icmd = &elsiocb->iocb;
8538 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
8539 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
8541 elsiocb->context1 = NULL;
8542 elsiocb->context2 = NULL;
8543 elsiocb->context3 = NULL;
8545 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
8546 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
8547 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
8548 (icmd->un.ulpWord[4] & IOERR_PARAM_MASK) ==
8549 IOERR_RCV_BUFFER_WAITING) {
8550 phba->fc_stat.NoRcvBuf++;
8551 /* Not enough posted buffers; Try posting more buffers */
8552 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
8553 lpfc_post_buffer(phba, pring, 0);
8557 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
8558 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
8559 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
8560 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
8561 vport = phba->pport;
8563 vport = lpfc_find_vport_by_vpid(phba,
8564 icmd->unsli3.rcvsli3.vpi);
8567 /* If there are no BDEs associated
8568 * with this IOCB, there is nothing to do.
8570 if (icmd->ulpBdeCount == 0)
8573 /* type of ELS cmd is first 32bit word
8576 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
8577 elsiocb->context2 = bdeBuf1;
8579 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
8580 icmd->un.cont64[0].addrLow);
8581 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
8585 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
8587 * The different unsolicited event handlers would tell us
8588 * if they are done with "mp" by setting context2 to NULL.
8590 if (elsiocb->context2) {
8591 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
8592 elsiocb->context2 = NULL;
8595 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
8596 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
8597 icmd->ulpBdeCount == 2) {
8598 elsiocb->context2 = bdeBuf2;
8599 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
8600 /* free mp if we are done with it */
8601 if (elsiocb->context2) {
8602 lpfc_in_buf_free(phba, elsiocb->context2);
8603 elsiocb->context2 = NULL;
8609 lpfc_start_fdmi(struct lpfc_vport *vport)
8611 struct lpfc_nodelist *ndlp;
8613 /* If this is the first time, allocate an ndlp and initialize
8614 * it. Otherwise, make sure the node is enabled and then do the
8617 ndlp = lpfc_findnode_did(vport, FDMI_DID);
8619 ndlp = lpfc_nlp_init(vport, FDMI_DID);
8621 ndlp->nlp_type |= NLP_FABRIC;
8626 if (!NLP_CHK_NODE_ACT(ndlp))
8627 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_NPR_NODE);
8630 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
8631 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
8636 * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
8637 * @phba: pointer to lpfc hba data structure.
8638 * @vport: pointer to a virtual N_Port data structure.
8640 * This routine issues a Port Login (PLOGI) to the Name Server with
8641 * State Change Request (SCR) for a @vport. This routine will create an
8642 * ndlp for the Name Server associated to the @vport if such node does
8643 * not already exist. The PLOGI to Name Server is issued by invoking the
8644 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
8645 * (FDMI) is configured to the @vport, a FDMI node will be created and
8646 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
8649 lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
8651 struct lpfc_nodelist *ndlp;
8652 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8655 * If lpfc_delay_discovery parameter is set and the clean address
8656 * bit is cleared and fc fabric parameters chenged, delay FC NPort
8659 spin_lock_irq(shost->host_lock);
8660 if (vport->fc_flag & FC_DISC_DELAYED) {
8661 spin_unlock_irq(shost->host_lock);
8662 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
8663 "3334 Delay fc port discovery for %d seconds\n",
8665 mod_timer(&vport->delayed_disc_tmo,
8666 jiffies + msecs_to_jiffies(1000 * phba->fc_ratov));
8669 spin_unlock_irq(shost->host_lock);
8671 ndlp = lpfc_findnode_did(vport, NameServer_DID);
8673 ndlp = lpfc_nlp_init(vport, NameServer_DID);
8675 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
8676 lpfc_disc_start(vport);
8679 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
8680 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8681 "0251 NameServer login: no memory\n");
8684 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
8685 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
8687 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
8688 lpfc_disc_start(vport);
8691 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
8692 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8693 "0348 NameServer login: node freed\n");
8697 ndlp->nlp_type |= NLP_FABRIC;
8699 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
8701 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
8702 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
8703 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8704 "0252 Cannot issue NameServer login\n");
8708 if ((phba->cfg_enable_SmartSAN ||
8709 (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) &&
8710 (vport->load_flag & FC_ALLOW_FDMI))
8711 lpfc_start_fdmi(vport);
8715 * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
8716 * @phba: pointer to lpfc hba data structure.
8717 * @pmb: pointer to the driver internal queue element for mailbox command.
8719 * This routine is the completion callback function to register new vport
8720 * mailbox command. If the new vport mailbox command completes successfully,
8721 * the fabric registration login shall be performed on physical port (the
8722 * new vport created is actually a physical port, with VPI 0) or the port
8723 * login to Name Server for State Change Request (SCR) will be performed
8724 * on virtual port (real virtual port, with VPI greater than 0).
8727 lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
8729 struct lpfc_vport *vport = pmb->vport;
8730 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8731 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
8732 MAILBOX_t *mb = &pmb->u.mb;
8735 spin_lock_irq(shost->host_lock);
8736 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
8737 spin_unlock_irq(shost->host_lock);
8739 if (mb->mbxStatus) {
8740 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
8741 "0915 Register VPI failed : Status: x%x"
8742 " upd bit: x%x \n", mb->mbxStatus,
8743 mb->un.varRegVpi.upd);
8744 if (phba->sli_rev == LPFC_SLI_REV4 &&
8745 mb->un.varRegVpi.upd)
8746 goto mbox_err_exit ;
8748 switch (mb->mbxStatus) {
8749 case 0x11: /* unsupported feature */
8750 case 0x9603: /* max_vpi exceeded */
8751 case 0x9602: /* Link event since CLEAR_LA */
8752 /* giving up on vport registration */
8753 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
8754 spin_lock_irq(shost->host_lock);
8755 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
8756 spin_unlock_irq(shost->host_lock);
8757 lpfc_can_disctmo(vport);
8759 /* If reg_vpi fail with invalid VPI status, re-init VPI */
8761 spin_lock_irq(shost->host_lock);
8762 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
8763 spin_unlock_irq(shost->host_lock);
8764 lpfc_init_vpi(phba, pmb, vport->vpi);
8766 pmb->mbox_cmpl = lpfc_init_vpi_cmpl;
8767 rc = lpfc_sli_issue_mbox(phba, pmb,
8769 if (rc == MBX_NOT_FINISHED) {
8770 lpfc_printf_vlog(vport,
8772 "2732 Failed to issue INIT_VPI"
8773 " mailbox command\n");
8780 /* Try to recover from this error */
8781 if (phba->sli_rev == LPFC_SLI_REV4)
8782 lpfc_sli4_unreg_all_rpis(vport);
8783 lpfc_mbx_unreg_vpi(vport);
8784 spin_lock_irq(shost->host_lock);
8785 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
8786 spin_unlock_irq(shost->host_lock);
8787 if (mb->mbxStatus == MBX_NOT_FINISHED)
8789 if ((vport->port_type == LPFC_PHYSICAL_PORT) &&
8790 !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG)) {
8791 if (phba->sli_rev == LPFC_SLI_REV4)
8792 lpfc_issue_init_vfi(vport);
8794 lpfc_initial_flogi(vport);
8796 lpfc_initial_fdisc(vport);
8801 spin_lock_irq(shost->host_lock);
8802 vport->vpi_state |= LPFC_VPI_REGISTERED;
8803 spin_unlock_irq(shost->host_lock);
8804 if (vport == phba->pport) {
8805 if (phba->sli_rev < LPFC_SLI_REV4)
8806 lpfc_issue_fabric_reglogin(vport);
8809 * If the physical port is instantiated using
8810 * FDISC, do not start vport discovery.
8812 if (vport->port_state != LPFC_FDISC)
8813 lpfc_start_fdiscs(phba);
8814 lpfc_do_scr_ns_plogi(phba, vport);
8817 lpfc_do_scr_ns_plogi(phba, vport);
8820 /* Now, we decrement the ndlp reference count held for this
8825 mempool_free(pmb, phba->mbox_mem_pool);
8830 * lpfc_register_new_vport - Register a new vport with a HBA
8831 * @phba: pointer to lpfc hba data structure.
8832 * @vport: pointer to a host virtual N_Port data structure.
8833 * @ndlp: pointer to a node-list data structure.
8835 * This routine registers the @vport as a new virtual port with a HBA.
8836 * It is done through a registering vpi mailbox command.
8839 lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
8840 struct lpfc_nodelist *ndlp)
8842 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8845 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
8847 lpfc_reg_vpi(vport, mbox);
8848 mbox->vport = vport;
8849 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
8850 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
8851 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
8852 == MBX_NOT_FINISHED) {
8853 /* mailbox command not success, decrement ndlp
8854 * reference count for this command
8857 mempool_free(mbox, phba->mbox_mem_pool);
8859 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
8860 "0253 Register VPI: Can't send mbox\n");
8864 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
8865 "0254 Register VPI: no memory\n");
8871 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
8872 spin_lock_irq(shost->host_lock);
8873 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
8874 spin_unlock_irq(shost->host_lock);
8879 * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer
8880 * @phba: pointer to lpfc hba data structure.
8882 * This routine cancels the retry delay timers to all the vports.
8885 lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba)
8887 struct lpfc_vport **vports;
8888 struct lpfc_nodelist *ndlp;
8889 uint32_t link_state;
8892 /* Treat this failure as linkdown for all vports */
8893 link_state = phba->link_state;
8894 lpfc_linkdown(phba);
8895 phba->link_state = link_state;
8897 vports = lpfc_create_vport_work_array(phba);
8900 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
8901 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
8903 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
8904 lpfc_els_flush_cmd(vports[i]);
8906 lpfc_destroy_vport_work_array(phba, vports);
8911 * lpfc_retry_pport_discovery - Start timer to retry FLOGI.
8912 * @phba: pointer to lpfc hba data structure.
8914 * This routine abort all pending discovery commands and
8915 * start a timer to retry FLOGI for the physical port
8919 lpfc_retry_pport_discovery(struct lpfc_hba *phba)
8921 struct lpfc_nodelist *ndlp;
8922 struct Scsi_Host *shost;
8924 /* Cancel the all vports retry delay retry timers */
8925 lpfc_cancel_all_vport_retry_delay_timer(phba);
8927 /* If fabric require FLOGI, then re-instantiate physical login */
8928 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
8932 shost = lpfc_shost_from_vport(phba->pport);
8933 mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000));
8934 spin_lock_irq(shost->host_lock);
8935 ndlp->nlp_flag |= NLP_DELAY_TMO;
8936 spin_unlock_irq(shost->host_lock);
8937 ndlp->nlp_last_elscmd = ELS_CMD_FLOGI;
8938 phba->pport->port_state = LPFC_FLOGI;
8943 * lpfc_fabric_login_reqd - Check if FLOGI required.
8944 * @phba: pointer to lpfc hba data structure.
8945 * @cmdiocb: pointer to FDISC command iocb.
8946 * @rspiocb: pointer to FDISC response iocb.
8948 * This routine checks if a FLOGI is reguired for FDISC
8952 lpfc_fabric_login_reqd(struct lpfc_hba *phba,
8953 struct lpfc_iocbq *cmdiocb,
8954 struct lpfc_iocbq *rspiocb)
8957 if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) ||
8958 (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED))
8965 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
8966 * @phba: pointer to lpfc hba data structure.
8967 * @cmdiocb: pointer to lpfc command iocb data structure.
8968 * @rspiocb: pointer to lpfc response iocb data structure.
8970 * This routine is the completion callback function to a Fabric Discover
8971 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
8972 * single threaded, each FDISC completion callback function will reset
8973 * the discovery timer for all vports such that the timers will not get
8974 * unnecessary timeout. The function checks the FDISC IOCB status. If error
8975 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
8976 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
8977 * assigned to the vport has been changed with the completion of the FDISC
8978 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
8979 * are unregistered from the HBA, and then the lpfc_register_new_vport()
8980 * routine is invoked to register new vport with the HBA. Otherwise, the
8981 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
8982 * Server for State Change Request (SCR).
8985 lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
8986 struct lpfc_iocbq *rspiocb)
8988 struct lpfc_vport *vport = cmdiocb->vport;
8989 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8990 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
8991 struct lpfc_nodelist *np;
8992 struct lpfc_nodelist *next_np;
8993 IOCB_t *irsp = &rspiocb->iocb;
8994 struct lpfc_iocbq *piocb;
8995 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
8996 struct serv_parm *sp;
8997 uint8_t fabric_param_changed;
8999 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
9000 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
9001 irsp->ulpStatus, irsp->un.ulpWord[4],
9003 /* Since all FDISCs are being single threaded, we
9004 * must reset the discovery timer for ALL vports
9005 * waiting to send FDISC when one completes.
9007 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
9008 lpfc_set_disctmo(piocb->vport);
9011 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
9012 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
9013 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
9015 if (irsp->ulpStatus) {
9017 if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) {
9018 lpfc_retry_pport_discovery(phba);
9022 /* Check for retry */
9023 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
9026 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
9027 "0126 FDISC failed. (x%x/x%x)\n",
9028 irsp->ulpStatus, irsp->un.ulpWord[4]);
9031 spin_lock_irq(shost->host_lock);
9032 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
9033 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
9034 vport->fc_flag |= FC_FABRIC;
9035 if (vport->phba->fc_topology == LPFC_TOPOLOGY_LOOP)
9036 vport->fc_flag |= FC_PUBLIC_LOOP;
9037 spin_unlock_irq(shost->host_lock);
9039 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
9040 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
9041 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
9044 sp = prsp->virt + sizeof(uint32_t);
9045 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
9046 memcpy(&vport->fabric_portname, &sp->portName,
9047 sizeof(struct lpfc_name));
9048 memcpy(&vport->fabric_nodename, &sp->nodeName,
9049 sizeof(struct lpfc_name));
9050 if (fabric_param_changed &&
9051 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
9052 /* If our NportID changed, we need to ensure all
9053 * remaining NPORTs get unreg_login'ed so we can
9056 list_for_each_entry_safe(np, next_np,
9057 &vport->fc_nodes, nlp_listp) {
9058 if (!NLP_CHK_NODE_ACT(ndlp) ||
9059 (np->nlp_state != NLP_STE_NPR_NODE) ||
9060 !(np->nlp_flag & NLP_NPR_ADISC))
9062 spin_lock_irq(shost->host_lock);
9063 np->nlp_flag &= ~NLP_NPR_ADISC;
9064 spin_unlock_irq(shost->host_lock);
9065 lpfc_unreg_rpi(vport, np);
9067 lpfc_cleanup_pending_mbox(vport);
9069 if (phba->sli_rev == LPFC_SLI_REV4)
9070 lpfc_sli4_unreg_all_rpis(vport);
9072 lpfc_mbx_unreg_vpi(vport);
9073 spin_lock_irq(shost->host_lock);
9074 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
9075 if (phba->sli_rev == LPFC_SLI_REV4)
9076 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
9078 vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG;
9079 spin_unlock_irq(shost->host_lock);
9080 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
9081 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
9083 * Driver needs to re-reg VPI in order for f/w
9084 * to update the MAC address.
9086 lpfc_register_new_vport(phba, vport, ndlp);
9090 if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)
9091 lpfc_issue_init_vpi(vport);
9092 else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
9093 lpfc_register_new_vport(phba, vport, ndlp);
9095 lpfc_do_scr_ns_plogi(phba, vport);
9098 if (vport->fc_vport &&
9099 (vport->fc_vport->vport_state != FC_VPORT_NO_FABRIC_RSCS))
9100 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
9101 /* Cancel discovery timer */
9102 lpfc_can_disctmo(vport);
9105 lpfc_els_free_iocb(phba, cmdiocb);
9109 * lpfc_issue_els_fdisc - Issue a fdisc iocb command
9110 * @vport: pointer to a virtual N_Port data structure.
9111 * @ndlp: pointer to a node-list data structure.
9112 * @retry: number of retries to the command IOCB.
9114 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
9115 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
9116 * routine to issue the IOCB, which makes sure only one outstanding fabric
9117 * IOCB will be sent off HBA at any given time.
9119 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
9120 * will be incremented by 1 for holding the ndlp and the reference to ndlp
9121 * will be stored into the context1 field of the IOCB for the completion
9122 * callback function to the FDISC ELS command.
9125 * 0 - Successfully issued fdisc iocb command
9126 * 1 - Failed to issue fdisc iocb command
9129 lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
9132 struct lpfc_hba *phba = vport->phba;
9134 struct lpfc_iocbq *elsiocb;
9135 struct serv_parm *sp;
9138 int did = ndlp->nlp_DID;
9141 vport->port_state = LPFC_FDISC;
9142 vport->fc_myDID = 0;
9143 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
9144 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
9147 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
9148 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
9149 "0255 Issue FDISC: no IOCB\n");
9153 icmd = &elsiocb->iocb;
9154 icmd->un.elsreq64.myID = 0;
9155 icmd->un.elsreq64.fl = 1;
9158 * SLI3 ports require a different context type value than SLI4.
9159 * Catch SLI3 ports here and override the prep.
9161 if (phba->sli_rev == LPFC_SLI_REV3) {
9166 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
9167 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
9168 pcmd += sizeof(uint32_t); /* CSP Word 1 */
9169 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
9170 sp = (struct serv_parm *) pcmd;
9171 /* Setup CSPs accordingly for Fabric */
9172 sp->cmn.e_d_tov = 0;
9173 sp->cmn.w2.r_a_tov = 0;
9174 sp->cmn.virtual_fabric_support = 0;
9175 sp->cls1.classValid = 0;
9176 sp->cls2.seqDelivery = 1;
9177 sp->cls3.seqDelivery = 1;
9179 pcmd += sizeof(uint32_t); /* CSP Word 2 */
9180 pcmd += sizeof(uint32_t); /* CSP Word 3 */
9181 pcmd += sizeof(uint32_t); /* CSP Word 4 */
9182 pcmd += sizeof(uint32_t); /* Port Name */
9183 memcpy(pcmd, &vport->fc_portname, 8);
9184 pcmd += sizeof(uint32_t); /* Node Name */
9185 pcmd += sizeof(uint32_t); /* Node Name */
9186 memcpy(pcmd, &vport->fc_nodename, 8);
9187 sp->cmn.valid_vendor_ver_level = 0;
9188 memset(sp->un.vendorVersion, 0, sizeof(sp->un.vendorVersion));
9189 lpfc_set_disctmo(vport);
9191 phba->fc_stat.elsXmitFDISC++;
9192 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
9194 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
9195 "Issue FDISC: did:x%x",
9198 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
9199 if (rc == IOCB_ERROR) {
9200 lpfc_els_free_iocb(phba, elsiocb);
9201 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
9202 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
9203 "0256 Issue FDISC: Cannot send IOCB\n");
9206 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
9211 * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
9212 * @phba: pointer to lpfc hba data structure.
9213 * @cmdiocb: pointer to lpfc command iocb data structure.
9214 * @rspiocb: pointer to lpfc response iocb data structure.
9216 * This routine is the completion callback function to the issuing of a LOGO
9217 * ELS command off a vport. It frees the command IOCB and then decrement the
9218 * reference count held on ndlp for this completion function, indicating that
9219 * the reference to the ndlp is no long needed. Note that the
9220 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
9221 * callback function and an additional explicit ndlp reference decrementation
9222 * will trigger the actual release of the ndlp.
9225 lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
9226 struct lpfc_iocbq *rspiocb)
9228 struct lpfc_vport *vport = cmdiocb->vport;
9230 struct lpfc_nodelist *ndlp;
9231 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
9233 ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
9234 irsp = &rspiocb->iocb;
9235 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
9236 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
9237 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
9239 lpfc_els_free_iocb(phba, cmdiocb);
9240 vport->unreg_vpi_cmpl = VPORT_ERROR;
9242 /* Trigger the release of the ndlp after logo */
9245 /* NPIV LOGO completes to NPort <nlp_DID> */
9246 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
9247 "2928 NPIV LOGO completes to NPort x%x "
9248 "Data: x%x x%x x%x x%x\n",
9249 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
9250 irsp->ulpTimeout, vport->num_disc_nodes);
9252 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
9253 spin_lock_irq(shost->host_lock);
9254 vport->fc_flag &= ~FC_NDISC_ACTIVE;
9255 vport->fc_flag &= ~FC_FABRIC;
9256 spin_unlock_irq(shost->host_lock);
9257 lpfc_can_disctmo(vport);
9262 * lpfc_issue_els_npiv_logo - Issue a logo off a vport
9263 * @vport: pointer to a virtual N_Port data structure.
9264 * @ndlp: pointer to a node-list data structure.
9266 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
9268 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
9269 * will be incremented by 1 for holding the ndlp and the reference to ndlp
9270 * will be stored into the context1 field of the IOCB for the completion
9271 * callback function to the LOGO ELS command.
9274 * 0 - Successfully issued logo off the @vport
9275 * 1 - Failed to issue logo off the @vport
9278 lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
9280 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
9281 struct lpfc_hba *phba = vport->phba;
9282 struct lpfc_iocbq *elsiocb;
9286 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
9287 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
9292 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
9293 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
9294 pcmd += sizeof(uint32_t);
9296 /* Fill in LOGO payload */
9297 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
9298 pcmd += sizeof(uint32_t);
9299 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
9301 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
9302 "Issue LOGO npiv did:x%x flg:x%x",
9303 ndlp->nlp_DID, ndlp->nlp_flag, 0);
9305 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
9306 spin_lock_irq(shost->host_lock);
9307 ndlp->nlp_flag |= NLP_LOGO_SND;
9308 spin_unlock_irq(shost->host_lock);
9309 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
9311 spin_lock_irq(shost->host_lock);
9312 ndlp->nlp_flag &= ~NLP_LOGO_SND;
9313 spin_unlock_irq(shost->host_lock);
9314 lpfc_els_free_iocb(phba, elsiocb);
9321 * lpfc_fabric_block_timeout - Handler function to the fabric block timer
9322 * @ptr: holder for the timer function associated data.
9324 * This routine is invoked by the fabric iocb block timer after
9325 * timeout. It posts the fabric iocb block timeout event by setting the
9326 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
9327 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
9328 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
9329 * posted event WORKER_FABRIC_BLOCK_TMO.
9332 lpfc_fabric_block_timeout(struct timer_list *t)
9334 struct lpfc_hba *phba = from_timer(phba, t, fabric_block_timer);
9335 unsigned long iflags;
9336 uint32_t tmo_posted;
9338 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
9339 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
9341 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
9342 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
9345 lpfc_worker_wake_up(phba);
9350 * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
9351 * @phba: pointer to lpfc hba data structure.
9353 * This routine issues one fabric iocb from the driver internal list to
9354 * the HBA. It first checks whether it's ready to issue one fabric iocb to
9355 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
9356 * remove one pending fabric iocb from the driver internal list and invokes
9357 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
9360 lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
9362 struct lpfc_iocbq *iocb;
9363 unsigned long iflags;
9369 spin_lock_irqsave(&phba->hbalock, iflags);
9370 /* Post any pending iocb to the SLI layer */
9371 if (atomic_read(&phba->fabric_iocb_count) == 0) {
9372 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
9375 /* Increment fabric iocb count to hold the position */
9376 atomic_inc(&phba->fabric_iocb_count);
9378 spin_unlock_irqrestore(&phba->hbalock, iflags);
9380 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
9381 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
9382 iocb->iocb_flag |= LPFC_IO_FABRIC;
9384 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
9385 "Fabric sched1: ste:x%x",
9386 iocb->vport->port_state, 0, 0);
9388 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
9390 if (ret == IOCB_ERROR) {
9391 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
9392 iocb->fabric_iocb_cmpl = NULL;
9393 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
9395 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
9396 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
9397 iocb->iocb_cmpl(phba, iocb, iocb);
9399 atomic_dec(&phba->fabric_iocb_count);
9408 * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
9409 * @phba: pointer to lpfc hba data structure.
9411 * This routine unblocks the issuing fabric iocb command. The function
9412 * will clear the fabric iocb block bit and then invoke the routine
9413 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
9414 * from the driver internal fabric iocb list.
9417 lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
9419 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
9421 lpfc_resume_fabric_iocbs(phba);
9426 * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
9427 * @phba: pointer to lpfc hba data structure.
9429 * This routine blocks the issuing fabric iocb for a specified amount of
9430 * time (currently 100 ms). This is done by set the fabric iocb block bit
9431 * and set up a timeout timer for 100ms. When the block bit is set, no more
9432 * fabric iocb will be issued out of the HBA.
9435 lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
9439 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
9440 /* Start a timer to unblock fabric iocbs after 100ms */
9442 mod_timer(&phba->fabric_block_timer,
9443 jiffies + msecs_to_jiffies(100));
9449 * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
9450 * @phba: pointer to lpfc hba data structure.
9451 * @cmdiocb: pointer to lpfc command iocb data structure.
9452 * @rspiocb: pointer to lpfc response iocb data structure.
9454 * This routine is the callback function that is put to the fabric iocb's
9455 * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
9456 * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
9457 * function first restores and invokes the original iocb's callback function
9458 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
9459 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
9462 lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
9463 struct lpfc_iocbq *rspiocb)
9467 BUG_ON((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC);
9469 switch (rspiocb->iocb.ulpStatus) {
9470 case IOSTAT_NPORT_RJT:
9471 case IOSTAT_FABRIC_RJT:
9472 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
9473 lpfc_block_fabric_iocbs(phba);
9477 case IOSTAT_NPORT_BSY:
9478 case IOSTAT_FABRIC_BSY:
9479 lpfc_block_fabric_iocbs(phba);
9483 stat.un.lsRjtError =
9484 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
9485 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
9486 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
9487 lpfc_block_fabric_iocbs(phba);
9491 BUG_ON(atomic_read(&phba->fabric_iocb_count) == 0);
9493 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
9494 cmdiocb->fabric_iocb_cmpl = NULL;
9495 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
9496 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
9498 atomic_dec(&phba->fabric_iocb_count);
9499 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
9500 /* Post any pending iocbs to HBA */
9501 lpfc_resume_fabric_iocbs(phba);
9506 * lpfc_issue_fabric_iocb - Issue a fabric iocb command
9507 * @phba: pointer to lpfc hba data structure.
9508 * @iocb: pointer to lpfc command iocb data structure.
9510 * This routine is used as the top-level API for issuing a fabric iocb command
9511 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
9512 * function makes sure that only one fabric bound iocb will be outstanding at
9513 * any given time. As such, this function will first check to see whether there
9514 * is already an outstanding fabric iocb on the wire. If so, it will put the
9515 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
9516 * issued later. Otherwise, it will issue the iocb on the wire and update the
9517 * fabric iocb count it indicate that there is one fabric iocb on the wire.
9519 * Note, this implementation has a potential sending out fabric IOCBs out of
9520 * order. The problem is caused by the construction of the "ready" boolen does
9521 * not include the condition that the internal fabric IOCB list is empty. As
9522 * such, it is possible a fabric IOCB issued by this routine might be "jump"
9523 * ahead of the fabric IOCBs in the internal list.
9526 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
9527 * IOCB_ERROR - failed to issue fabric iocb
9530 lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
9532 unsigned long iflags;
9536 BUG_ON(atomic_read(&phba->fabric_iocb_count) > 1);
9538 spin_lock_irqsave(&phba->hbalock, iflags);
9539 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
9540 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
9543 /* Increment fabric iocb count to hold the position */
9544 atomic_inc(&phba->fabric_iocb_count);
9545 spin_unlock_irqrestore(&phba->hbalock, iflags);
9547 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
9548 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
9549 iocb->iocb_flag |= LPFC_IO_FABRIC;
9551 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
9552 "Fabric sched2: ste:x%x",
9553 iocb->vport->port_state, 0, 0);
9555 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
9557 if (ret == IOCB_ERROR) {
9558 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
9559 iocb->fabric_iocb_cmpl = NULL;
9560 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
9561 atomic_dec(&phba->fabric_iocb_count);
9564 spin_lock_irqsave(&phba->hbalock, iflags);
9565 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
9566 spin_unlock_irqrestore(&phba->hbalock, iflags);
9573 * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
9574 * @vport: pointer to a virtual N_Port data structure.
9576 * This routine aborts all the IOCBs associated with a @vport from the
9577 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
9578 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
9579 * list, removes each IOCB associated with the @vport off the list, set the
9580 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
9581 * associated with the IOCB.
9583 static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
9585 LIST_HEAD(completions);
9586 struct lpfc_hba *phba = vport->phba;
9587 struct lpfc_iocbq *tmp_iocb, *piocb;
9589 spin_lock_irq(&phba->hbalock);
9590 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
9593 if (piocb->vport != vport)
9596 list_move_tail(&piocb->list, &completions);
9598 spin_unlock_irq(&phba->hbalock);
9600 /* Cancel all the IOCBs from the completions list */
9601 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
9606 * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
9607 * @ndlp: pointer to a node-list data structure.
9609 * This routine aborts all the IOCBs associated with an @ndlp from the
9610 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
9611 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
9612 * list, removes each IOCB associated with the @ndlp off the list, set the
9613 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
9614 * associated with the IOCB.
9616 void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
9618 LIST_HEAD(completions);
9619 struct lpfc_hba *phba = ndlp->phba;
9620 struct lpfc_iocbq *tmp_iocb, *piocb;
9621 struct lpfc_sli_ring *pring;
9623 pring = lpfc_phba_elsring(phba);
9625 if (unlikely(!pring))
9628 spin_lock_irq(&phba->hbalock);
9629 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
9631 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
9633 list_move_tail(&piocb->list, &completions);
9636 spin_unlock_irq(&phba->hbalock);
9638 /* Cancel all the IOCBs from the completions list */
9639 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
9644 * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
9645 * @phba: pointer to lpfc hba data structure.
9647 * This routine aborts all the IOCBs currently on the driver internal
9648 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
9649 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
9650 * list, removes IOCBs off the list, set the status feild to
9651 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
9654 void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
9656 LIST_HEAD(completions);
9658 spin_lock_irq(&phba->hbalock);
9659 list_splice_init(&phba->fabric_iocb_list, &completions);
9660 spin_unlock_irq(&phba->hbalock);
9662 /* Cancel all the IOCBs from the completions list */
9663 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
9668 * lpfc_sli4_vport_delete_els_xri_aborted -Remove all ndlp references for vport
9669 * @vport: pointer to lpfc vport data structure.
9671 * This routine is invoked by the vport cleanup for deletions and the cleanup
9672 * for an ndlp on removal.
9675 lpfc_sli4_vport_delete_els_xri_aborted(struct lpfc_vport *vport)
9677 struct lpfc_hba *phba = vport->phba;
9678 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
9679 unsigned long iflag = 0;
9681 spin_lock_irqsave(&phba->hbalock, iflag);
9682 spin_lock(&phba->sli4_hba.sgl_list_lock);
9683 list_for_each_entry_safe(sglq_entry, sglq_next,
9684 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
9685 if (sglq_entry->ndlp && sglq_entry->ndlp->vport == vport)
9686 sglq_entry->ndlp = NULL;
9688 spin_unlock(&phba->sli4_hba.sgl_list_lock);
9689 spin_unlock_irqrestore(&phba->hbalock, iflag);
9694 * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
9695 * @phba: pointer to lpfc hba data structure.
9696 * @axri: pointer to the els xri abort wcqe structure.
9698 * This routine is invoked by the worker thread to process a SLI4 slow-path
9702 lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba,
9703 struct sli4_wcqe_xri_aborted *axri)
9705 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
9706 uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri);
9709 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
9710 unsigned long iflag = 0;
9711 struct lpfc_nodelist *ndlp;
9712 struct lpfc_sli_ring *pring;
9714 pring = lpfc_phba_elsring(phba);
9716 spin_lock_irqsave(&phba->hbalock, iflag);
9717 spin_lock(&phba->sli4_hba.sgl_list_lock);
9718 list_for_each_entry_safe(sglq_entry, sglq_next,
9719 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
9720 if (sglq_entry->sli4_xritag == xri) {
9721 list_del(&sglq_entry->list);
9722 ndlp = sglq_entry->ndlp;
9723 sglq_entry->ndlp = NULL;
9724 list_add_tail(&sglq_entry->list,
9725 &phba->sli4_hba.lpfc_els_sgl_list);
9726 sglq_entry->state = SGL_FREED;
9727 spin_unlock(&phba->sli4_hba.sgl_list_lock);
9728 spin_unlock_irqrestore(&phba->hbalock, iflag);
9729 lpfc_set_rrq_active(phba, ndlp,
9730 sglq_entry->sli4_lxritag,
9733 /* Check if TXQ queue needs to be serviced */
9734 if (pring && !list_empty(&pring->txq))
9735 lpfc_worker_wake_up(phba);
9739 spin_unlock(&phba->sli4_hba.sgl_list_lock);
9740 lxri = lpfc_sli4_xri_inrange(phba, xri);
9741 if (lxri == NO_XRI) {
9742 spin_unlock_irqrestore(&phba->hbalock, iflag);
9745 spin_lock(&phba->sli4_hba.sgl_list_lock);
9746 sglq_entry = __lpfc_get_active_sglq(phba, lxri);
9747 if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) {
9748 spin_unlock(&phba->sli4_hba.sgl_list_lock);
9749 spin_unlock_irqrestore(&phba->hbalock, iflag);
9752 sglq_entry->state = SGL_XRI_ABORTED;
9753 spin_unlock(&phba->sli4_hba.sgl_list_lock);
9754 spin_unlock_irqrestore(&phba->hbalock, iflag);
9758 /* lpfc_sli_abts_recover_port - Recover a port that failed a BLS_ABORT req.
9759 * @vport: pointer to virtual port object.
9760 * @ndlp: nodelist pointer for the impacted node.
9762 * The driver calls this routine in response to an SLI4 XRI ABORT CQE
9763 * or an SLI3 ASYNC_STATUS_CN event from the port. For either event,
9764 * the driver is required to send a LOGO to the remote node before it
9765 * attempts to recover its login to the remote node.
9768 lpfc_sli_abts_recover_port(struct lpfc_vport *vport,
9769 struct lpfc_nodelist *ndlp)
9771 struct Scsi_Host *shost;
9772 struct lpfc_hba *phba;
9773 unsigned long flags = 0;
9775 shost = lpfc_shost_from_vport(vport);
9777 if (ndlp->nlp_state != NLP_STE_MAPPED_NODE) {
9778 lpfc_printf_log(phba, KERN_INFO,
9779 LOG_SLI, "3093 No rport recovery needed. "
9780 "rport in state 0x%x\n", ndlp->nlp_state);
9783 lpfc_printf_log(phba, KERN_ERR,
9784 LOG_ELS | LOG_FCP_ERROR | LOG_NVME_IOERR,
9785 "3094 Start rport recovery on shost id 0x%x "
9786 "fc_id 0x%06x vpi 0x%x rpi 0x%x state 0x%x "
9788 shost->host_no, ndlp->nlp_DID,
9789 vport->vpi, ndlp->nlp_rpi, ndlp->nlp_state,
9792 * The rport is not responding. Remove the FCP-2 flag to prevent
9793 * an ADISC in the follow-up recovery code.
9795 spin_lock_irqsave(shost->host_lock, flags);
9796 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
9797 ndlp->nlp_flag |= NLP_ISSUE_LOGO;
9798 spin_unlock_irqrestore(shost->host_lock, flags);
9799 lpfc_unreg_rpi(vport, ndlp);