1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2012 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. *
7 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
9 * This program is free software; you can redistribute it and/or *
10 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
20 *******************************************************************/
21 /* See Fibre Channel protocol T11 FC-LS for details */
22 #include <linux/blkdev.h>
23 #include <linux/pci.h>
24 #include <linux/slab.h>
25 #include <linux/interrupt.h>
27 #include <scsi/scsi.h>
28 #include <scsi/scsi_device.h>
29 #include <scsi/scsi_host.h>
30 #include <scsi/scsi_transport_fc.h>
35 #include "lpfc_sli4.h"
37 #include "lpfc_disc.h"
38 #include "lpfc_scsi.h"
40 #include "lpfc_logmsg.h"
41 #include "lpfc_crtn.h"
42 #include "lpfc_vport.h"
43 #include "lpfc_debugfs.h"
45 static int lpfc_els_retry(struct lpfc_hba *, struct lpfc_iocbq *,
47 static void lpfc_cmpl_fabric_iocb(struct lpfc_hba *, struct lpfc_iocbq *,
49 static void lpfc_fabric_abort_vport(struct lpfc_vport *vport);
50 static int lpfc_issue_els_fdisc(struct lpfc_vport *vport,
51 struct lpfc_nodelist *ndlp, uint8_t retry);
52 static int lpfc_issue_fabric_iocb(struct lpfc_hba *phba,
53 struct lpfc_iocbq *iocb);
55 static int lpfc_max_els_tries = 3;
58 * lpfc_els_chk_latt - Check host link attention event for a vport
59 * @vport: pointer to a host virtual N_Port data structure.
61 * This routine checks whether there is an outstanding host link
62 * attention event during the discovery process with the @vport. It is done
63 * by reading the HBA's Host Attention (HA) register. If there is any host
64 * link attention events during this @vport's discovery process, the @vport
65 * shall be marked as FC_ABORT_DISCOVERY, a host link attention clear shall
66 * be issued if the link state is not already in host link cleared state,
67 * and a return code shall indicate whether the host link attention event
70 * Note that, if either the host link is in state LPFC_LINK_DOWN or @vport
71 * state in LPFC_VPORT_READY, the request for checking host link attention
72 * event will be ignored and a return code shall indicate no host link
73 * attention event had happened.
76 * 0 - no host link attention event happened
77 * 1 - host link attention event happened
80 lpfc_els_chk_latt(struct lpfc_vport *vport)
82 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
83 struct lpfc_hba *phba = vport->phba;
86 if (vport->port_state >= LPFC_VPORT_READY ||
87 phba->link_state == LPFC_LINK_DOWN ||
88 phba->sli_rev > LPFC_SLI_REV3)
91 /* Read the HBA Host Attention Register */
92 if (lpfc_readl(phba->HAregaddr, &ha_copy))
95 if (!(ha_copy & HA_LATT))
98 /* Pending Link Event during Discovery */
99 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
100 "0237 Pending Link Event during "
101 "Discovery: State x%x\n",
102 phba->pport->port_state);
104 /* CLEAR_LA should re-enable link attention events and
105 * we should then immediately take a LATT event. The
106 * LATT processing should call lpfc_linkdown() which
107 * will cleanup any left over in-progress discovery
110 spin_lock_irq(shost->host_lock);
111 vport->fc_flag |= FC_ABORT_DISCOVERY;
112 spin_unlock_irq(shost->host_lock);
114 if (phba->link_state != LPFC_CLEAR_LA)
115 lpfc_issue_clear_la(phba, vport);
121 * lpfc_prep_els_iocb - Allocate and prepare a lpfc iocb data structure
122 * @vport: pointer to a host virtual N_Port data structure.
123 * @expectRsp: flag indicating whether response is expected.
124 * @cmdSize: size of the ELS command.
125 * @retry: number of retries to the command IOCB when it fails.
126 * @ndlp: pointer to a node-list data structure.
127 * @did: destination identifier.
128 * @elscmd: the ELS command code.
130 * This routine is used for allocating a lpfc-IOCB data structure from
131 * the driver lpfc-IOCB free-list and prepare the IOCB with the parameters
132 * passed into the routine for discovery state machine to issue an Extended
133 * Link Service (ELS) commands. It is a generic lpfc-IOCB allocation
134 * and preparation routine that is used by all the discovery state machine
135 * routines and the ELS command-specific fields will be later set up by
136 * the individual discovery machine routines after calling this routine
137 * allocating and preparing a generic IOCB data structure. It fills in the
138 * Buffer Descriptor Entries (BDEs), allocates buffers for both command
139 * payload and response payload (if expected). The reference count on the
140 * ndlp is incremented by 1 and the reference to the ndlp is put into
141 * context1 of the IOCB data structure for this IOCB to hold the ndlp
142 * reference for the command's callback function to access later.
145 * Pointer to the newly allocated/prepared els iocb data structure
146 * NULL - when els iocb data structure allocation/preparation failed
149 lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp,
150 uint16_t cmdSize, uint8_t retry,
151 struct lpfc_nodelist *ndlp, uint32_t did,
154 struct lpfc_hba *phba = vport->phba;
155 struct lpfc_iocbq *elsiocb;
156 struct lpfc_dmabuf *pcmd, *prsp, *pbuflist;
157 struct ulp_bde64 *bpl;
161 if (!lpfc_is_link_up(phba))
164 /* Allocate buffer for command iocb */
165 elsiocb = lpfc_sli_get_iocbq(phba);
171 * If this command is for fabric controller and HBA running
172 * in FIP mode send FLOGI, FDISC and LOGO as FIP frames.
174 if ((did == Fabric_DID) &&
175 (phba->hba_flag & HBA_FIP_SUPPORT) &&
176 ((elscmd == ELS_CMD_FLOGI) ||
177 (elscmd == ELS_CMD_FDISC) ||
178 (elscmd == ELS_CMD_LOGO)))
181 elsiocb->iocb_flag |=
182 ((LPFC_ELS_ID_FLOGI << LPFC_FIP_ELS_ID_SHIFT)
183 & LPFC_FIP_ELS_ID_MASK);
186 elsiocb->iocb_flag |=
187 ((LPFC_ELS_ID_FDISC << LPFC_FIP_ELS_ID_SHIFT)
188 & LPFC_FIP_ELS_ID_MASK);
191 elsiocb->iocb_flag |=
192 ((LPFC_ELS_ID_LOGO << LPFC_FIP_ELS_ID_SHIFT)
193 & LPFC_FIP_ELS_ID_MASK);
197 elsiocb->iocb_flag &= ~LPFC_FIP_ELS_ID_MASK;
199 icmd = &elsiocb->iocb;
201 /* fill in BDEs for command */
202 /* Allocate buffer for command payload */
203 pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
205 pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys);
206 if (!pcmd || !pcmd->virt)
207 goto els_iocb_free_pcmb_exit;
209 INIT_LIST_HEAD(&pcmd->list);
211 /* Allocate buffer for response payload */
213 prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
215 prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
217 if (!prsp || !prsp->virt)
218 goto els_iocb_free_prsp_exit;
219 INIT_LIST_HEAD(&prsp->list);
223 /* Allocate buffer for Buffer ptr list */
224 pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
226 pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
228 if (!pbuflist || !pbuflist->virt)
229 goto els_iocb_free_pbuf_exit;
231 INIT_LIST_HEAD(&pbuflist->list);
234 icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
235 icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
236 icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
237 icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64));
239 icmd->un.elsreq64.remoteID = did; /* DID */
240 icmd->ulpCommand = CMD_ELS_REQUEST64_CR;
241 icmd->ulpTimeout = phba->fc_ratov * 2;
243 icmd->un.xseq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
244 icmd->un.xseq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
245 icmd->un.xseq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
246 icmd->un.xseq64.bdl.bdeSize = sizeof(struct ulp_bde64);
247 icmd->un.xseq64.xmit_els_remoteID = did; /* DID */
248 icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX;
250 icmd->ulpBdeCount = 1;
252 icmd->ulpClass = CLASS3;
255 * If we have NPIV enabled, we want to send ELS traffic by VPI.
256 * For SLI4, since the driver controls VPIs we also want to include
257 * all ELS pt2pt protocol traffic as well.
259 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) ||
260 ((phba->sli_rev == LPFC_SLI_REV4) &&
261 (vport->fc_flag & FC_PT2PT))) {
264 icmd->un.elsreq64.myID = vport->fc_myDID;
266 /* For ELS_REQUEST64_CR, use the VPI by default */
267 icmd->ulpContext = phba->vpi_ids[vport->vpi];
271 /* The CT field must be 0=INVALID_RPI for the ECHO cmd */
272 if (elscmd == ELS_CMD_ECHO)
273 icmd->ulpCt_l = 0; /* context = invalid RPI */
275 icmd->ulpCt_l = 1; /* context = VPI */
278 bpl = (struct ulp_bde64 *) pbuflist->virt;
279 bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys));
280 bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys));
281 bpl->tus.f.bdeSize = cmdSize;
282 bpl->tus.f.bdeFlags = 0;
283 bpl->tus.w = le32_to_cpu(bpl->tus.w);
287 bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys));
288 bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys));
289 bpl->tus.f.bdeSize = FCELSSIZE;
290 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
291 bpl->tus.w = le32_to_cpu(bpl->tus.w);
294 /* prevent preparing iocb with NULL ndlp reference */
295 elsiocb->context1 = lpfc_nlp_get(ndlp);
296 if (!elsiocb->context1)
297 goto els_iocb_free_pbuf_exit;
298 elsiocb->context2 = pcmd;
299 elsiocb->context3 = pbuflist;
300 elsiocb->retry = retry;
301 elsiocb->vport = vport;
302 elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT;
305 list_add(&prsp->list, &pcmd->list);
308 /* Xmit ELS command <elsCmd> to remote NPORT <did> */
309 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
310 "0116 Xmit ELS command x%x to remote "
311 "NPORT x%x I/O tag: x%x, port state: x%x\n",
312 elscmd, did, elsiocb->iotag,
315 /* Xmit ELS response <elsCmd> to remote NPORT <did> */
316 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
317 "0117 Xmit ELS response x%x to remote "
318 "NPORT x%x I/O tag: x%x, size: x%x\n",
319 elscmd, ndlp->nlp_DID, elsiocb->iotag,
324 els_iocb_free_pbuf_exit:
326 lpfc_mbuf_free(phba, prsp->virt, prsp->phys);
329 els_iocb_free_prsp_exit:
330 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
333 els_iocb_free_pcmb_exit:
335 lpfc_sli_release_iocbq(phba, elsiocb);
340 * lpfc_issue_fabric_reglogin - Issue fabric registration login for a vport
341 * @vport: pointer to a host virtual N_Port data structure.
343 * This routine issues a fabric registration login for a @vport. An
344 * active ndlp node with Fabric_DID must already exist for this @vport.
345 * The routine invokes two mailbox commands to carry out fabric registration
346 * login through the HBA firmware: the first mailbox command requests the
347 * HBA to perform link configuration for the @vport; and the second mailbox
348 * command requests the HBA to perform the actual fabric registration login
352 * 0 - successfully issued fabric registration login for @vport
353 * -ENXIO -- failed to issue fabric registration login for @vport
356 lpfc_issue_fabric_reglogin(struct lpfc_vport *vport)
358 struct lpfc_hba *phba = vport->phba;
360 struct lpfc_dmabuf *mp;
361 struct lpfc_nodelist *ndlp;
362 struct serv_parm *sp;
366 sp = &phba->fc_fabparam;
367 ndlp = lpfc_findnode_did(vport, Fabric_DID);
368 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
373 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
379 vport->port_state = LPFC_FABRIC_CFG_LINK;
380 lpfc_config_link(phba, mbox);
381 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
384 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
385 if (rc == MBX_NOT_FINISHED) {
390 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
395 rc = lpfc_reg_rpi(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox,
402 mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login;
404 /* increment the reference count on ndlp to hold reference
405 * for the callback routine.
407 mbox->context2 = lpfc_nlp_get(ndlp);
409 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
410 if (rc == MBX_NOT_FINISHED) {
412 goto fail_issue_reg_login;
417 fail_issue_reg_login:
418 /* decrement the reference count on ndlp just incremented
419 * for the failed mbox command.
422 mp = (struct lpfc_dmabuf *) mbox->context1;
423 lpfc_mbuf_free(phba, mp->virt, mp->phys);
426 mempool_free(mbox, phba->mbox_mem_pool);
429 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
430 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
431 "0249 Cannot issue Register Fabric login: Err %d\n", err);
436 * lpfc_issue_reg_vfi - Register VFI for this vport's fabric login
437 * @vport: pointer to a host virtual N_Port data structure.
439 * This routine issues a REG_VFI mailbox for the vfi, vpi, fcfi triplet for
440 * the @vport. This mailbox command is necessary for SLI4 port only.
443 * 0 - successfully issued REG_VFI for @vport
444 * A failure code otherwise.
447 lpfc_issue_reg_vfi(struct lpfc_vport *vport)
449 struct lpfc_hba *phba = vport->phba;
451 struct lpfc_nodelist *ndlp;
452 struct serv_parm *sp;
453 struct lpfc_dmabuf *dmabuf;
456 sp = &phba->fc_fabparam;
457 /* move forward in case of SLI4 FC port loopback test and pt2pt mode */
458 if ((phba->sli_rev == LPFC_SLI_REV4) &&
459 !(phba->link_flag & LS_LOOPBACK_MODE) &&
460 !(vport->fc_flag & FC_PT2PT)) {
461 ndlp = lpfc_findnode_did(vport, Fabric_DID);
462 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
468 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
473 dmabuf->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &dmabuf->phys);
476 goto fail_free_dmabuf;
479 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
482 goto fail_free_coherent;
484 vport->port_state = LPFC_FABRIC_CFG_LINK;
485 memcpy(dmabuf->virt, &phba->fc_fabparam, sizeof(vport->fc_sparam));
486 lpfc_reg_vfi(mboxq, vport, dmabuf->phys);
488 mboxq->mbox_cmpl = lpfc_mbx_cmpl_reg_vfi;
489 mboxq->vport = vport;
490 mboxq->context1 = dmabuf;
491 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
492 if (rc == MBX_NOT_FINISHED) {
499 mempool_free(mboxq, phba->mbox_mem_pool);
501 lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys);
505 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
506 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
507 "0289 Issue Register VFI failed: Err %d\n", rc);
512 * lpfc_issue_unreg_vfi - Unregister VFI for this vport's fabric login
513 * @vport: pointer to a host virtual N_Port data structure.
515 * This routine issues a UNREG_VFI mailbox with the vfi, vpi, fcfi triplet for
516 * the @vport. This mailbox command is necessary for SLI4 port only.
519 * 0 - successfully issued REG_VFI for @vport
520 * A failure code otherwise.
523 lpfc_issue_unreg_vfi(struct lpfc_vport *vport)
525 struct lpfc_hba *phba = vport->phba;
526 struct Scsi_Host *shost;
530 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
532 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
533 "2556 UNREG_VFI mbox allocation failed"
534 "HBA state x%x\n", phba->pport->port_state);
538 lpfc_unreg_vfi(mboxq, vport);
539 mboxq->vport = vport;
540 mboxq->mbox_cmpl = lpfc_unregister_vfi_cmpl;
542 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
543 if (rc == MBX_NOT_FINISHED) {
544 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
545 "2557 UNREG_VFI issue mbox failed rc x%x "
547 rc, phba->pport->port_state);
548 mempool_free(mboxq, phba->mbox_mem_pool);
552 shost = lpfc_shost_from_vport(vport);
553 spin_lock_irq(shost->host_lock);
554 vport->fc_flag &= ~FC_VFI_REGISTERED;
555 spin_unlock_irq(shost->host_lock);
560 * lpfc_check_clean_addr_bit - Check whether assigned FCID is clean.
561 * @vport: pointer to a host virtual N_Port data structure.
562 * @sp: pointer to service parameter data structure.
564 * This routine is called from FLOGI/FDISC completion handler functions.
565 * lpfc_check_clean_addr_bit return 1 when FCID/Fabric portname/ Fabric
566 * node nodename is changed in the completion service parameter else return
567 * 0. This function also set flag in the vport data structure to delay
568 * NP_Port discovery after the FLOGI/FDISC completion if Clean address bit
569 * in FLOGI/FDISC response is cleared and FCID/Fabric portname/ Fabric
570 * node nodename is changed in the completion service parameter.
573 * 0 - FCID and Fabric Nodename and Fabric portname is not changed.
574 * 1 - FCID or Fabric Nodename or Fabric portname is changed.
578 lpfc_check_clean_addr_bit(struct lpfc_vport *vport,
579 struct serv_parm *sp)
581 uint8_t fabric_param_changed = 0;
582 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
584 if ((vport->fc_prevDID != vport->fc_myDID) ||
585 memcmp(&vport->fabric_portname, &sp->portName,
586 sizeof(struct lpfc_name)) ||
587 memcmp(&vport->fabric_nodename, &sp->nodeName,
588 sizeof(struct lpfc_name)))
589 fabric_param_changed = 1;
592 * Word 1 Bit 31 in common service parameter is overloaded.
593 * Word 1 Bit 31 in FLOGI request is multiple NPort request
594 * Word 1 Bit 31 in FLOGI response is clean address bit
596 * If fabric parameter is changed and clean address bit is
597 * cleared delay nport discovery if
598 * - vport->fc_prevDID != 0 (not initial discovery) OR
599 * - lpfc_delay_discovery module parameter is set.
601 if (fabric_param_changed && !sp->cmn.clean_address_bit &&
602 (vport->fc_prevDID || lpfc_delay_discovery)) {
603 spin_lock_irq(shost->host_lock);
604 vport->fc_flag |= FC_DISC_DELAYED;
605 spin_unlock_irq(shost->host_lock);
608 return fabric_param_changed;
613 * lpfc_cmpl_els_flogi_fabric - Completion function for flogi to a fabric port
614 * @vport: pointer to a host virtual N_Port data structure.
615 * @ndlp: pointer to a node-list data structure.
616 * @sp: pointer to service parameter data structure.
617 * @irsp: pointer to the IOCB within the lpfc response IOCB.
619 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
620 * function to handle the completion of a Fabric Login (FLOGI) into a fabric
621 * port in a fabric topology. It properly sets up the parameters to the @ndlp
622 * from the IOCB response. It also check the newly assigned N_Port ID to the
623 * @vport against the previously assigned N_Port ID. If it is different from
624 * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine
625 * is invoked on all the remaining nodes with the @vport to unregister the
626 * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin()
627 * is invoked to register login to the fabric.
630 * 0 - Success (currently, always return 0)
633 lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
634 struct serv_parm *sp, IOCB_t *irsp)
636 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
637 struct lpfc_hba *phba = vport->phba;
638 struct lpfc_nodelist *np;
639 struct lpfc_nodelist *next_np;
640 uint8_t fabric_param_changed;
642 spin_lock_irq(shost->host_lock);
643 vport->fc_flag |= FC_FABRIC;
644 spin_unlock_irq(shost->host_lock);
646 phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
647 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
648 phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
650 phba->fc_edtovResol = sp->cmn.edtovResolution;
651 phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
653 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
654 spin_lock_irq(shost->host_lock);
655 vport->fc_flag |= FC_PUBLIC_LOOP;
656 spin_unlock_irq(shost->host_lock);
659 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
660 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
661 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name));
662 ndlp->nlp_class_sup = 0;
663 if (sp->cls1.classValid)
664 ndlp->nlp_class_sup |= FC_COS_CLASS1;
665 if (sp->cls2.classValid)
666 ndlp->nlp_class_sup |= FC_COS_CLASS2;
667 if (sp->cls3.classValid)
668 ndlp->nlp_class_sup |= FC_COS_CLASS3;
669 if (sp->cls4.classValid)
670 ndlp->nlp_class_sup |= FC_COS_CLASS4;
671 ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
672 sp->cmn.bbRcvSizeLsb;
674 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
675 memcpy(&vport->fabric_portname, &sp->portName,
676 sizeof(struct lpfc_name));
677 memcpy(&vport->fabric_nodename, &sp->nodeName,
678 sizeof(struct lpfc_name));
679 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
681 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
682 if (sp->cmn.response_multiple_NPort) {
683 lpfc_printf_vlog(vport, KERN_WARNING,
685 "1816 FLOGI NPIV supported, "
686 "response data 0x%x\n",
687 sp->cmn.response_multiple_NPort);
688 spin_lock_irq(&phba->hbalock);
689 phba->link_flag |= LS_NPIV_FAB_SUPPORTED;
690 spin_unlock_irq(&phba->hbalock);
692 /* Because we asked f/w for NPIV it still expects us
693 to call reg_vnpid atleast for the physcial host */
694 lpfc_printf_vlog(vport, KERN_WARNING,
696 "1817 Fabric does not support NPIV "
697 "- configuring single port mode.\n");
698 spin_lock_irq(&phba->hbalock);
699 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
700 spin_unlock_irq(&phba->hbalock);
705 * For FC we need to do some special processing because of the SLI
706 * Port's default settings of the Common Service Parameters.
708 if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC) {
709 /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */
710 if ((phba->sli_rev == LPFC_SLI_REV4) && fabric_param_changed)
711 lpfc_unregister_fcf_prep(phba);
713 /* This should just update the VFI CSPs*/
714 if (vport->fc_flag & FC_VFI_REGISTERED)
715 lpfc_issue_reg_vfi(vport);
718 if (fabric_param_changed &&
719 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
721 /* If our NportID changed, we need to ensure all
722 * remaining NPORTs get unreg_login'ed.
724 list_for_each_entry_safe(np, next_np,
725 &vport->fc_nodes, nlp_listp) {
726 if (!NLP_CHK_NODE_ACT(np))
728 if ((np->nlp_state != NLP_STE_NPR_NODE) ||
729 !(np->nlp_flag & NLP_NPR_ADISC))
731 spin_lock_irq(shost->host_lock);
732 np->nlp_flag &= ~NLP_NPR_ADISC;
733 spin_unlock_irq(shost->host_lock);
734 lpfc_unreg_rpi(vport, np);
736 lpfc_cleanup_pending_mbox(vport);
738 if (phba->sli_rev == LPFC_SLI_REV4) {
739 lpfc_sli4_unreg_all_rpis(vport);
740 lpfc_mbx_unreg_vpi(vport);
741 spin_lock_irq(shost->host_lock);
742 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
743 spin_unlock_irq(shost->host_lock);
747 * For SLI3 and SLI4, the VPI needs to be reregistered in
748 * response to this fabric parameter change event.
750 spin_lock_irq(shost->host_lock);
751 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
752 spin_unlock_irq(shost->host_lock);
753 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
754 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
756 * Driver needs to re-reg VPI in order for f/w
757 * to update the MAC address.
759 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
760 lpfc_register_new_vport(phba, vport, ndlp);
764 if (phba->sli_rev < LPFC_SLI_REV4) {
765 lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
766 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED &&
767 vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
768 lpfc_register_new_vport(phba, vport, ndlp);
770 lpfc_issue_fabric_reglogin(vport);
772 ndlp->nlp_type |= NLP_FABRIC;
773 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
774 if ((!(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) &&
775 (vport->vpi_state & LPFC_VPI_REGISTERED)) {
776 lpfc_start_fdiscs(phba);
777 lpfc_do_scr_ns_plogi(phba, vport);
778 } else if (vport->fc_flag & FC_VFI_REGISTERED)
779 lpfc_issue_init_vpi(vport);
781 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
782 "3135 Need register VFI: (x%x/%x)\n",
783 vport->fc_prevDID, vport->fc_myDID);
784 lpfc_issue_reg_vfi(vport);
791 * lpfc_cmpl_els_flogi_nport - Completion function for flogi to an N_Port
792 * @vport: pointer to a host virtual N_Port data structure.
793 * @ndlp: pointer to a node-list data structure.
794 * @sp: pointer to service parameter data structure.
796 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
797 * function to handle the completion of a Fabric Login (FLOGI) into an N_Port
798 * in a point-to-point topology. First, the @vport's N_Port Name is compared
799 * with the received N_Port Name: if the @vport's N_Port Name is greater than
800 * the received N_Port Name lexicographically, this node shall assign local
801 * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and
802 * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise,
803 * this node shall just wait for the remote node to issue PLOGI and assign
811 lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
812 struct serv_parm *sp)
814 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
815 struct lpfc_hba *phba = vport->phba;
819 spin_lock_irq(shost->host_lock);
820 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
821 spin_unlock_irq(shost->host_lock);
823 phba->fc_edtov = FF_DEF_EDTOV;
824 phba->fc_ratov = FF_DEF_RATOV;
825 rc = memcmp(&vport->fc_portname, &sp->portName,
826 sizeof(vport->fc_portname));
827 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
830 /* This side will initiate the PLOGI */
831 spin_lock_irq(shost->host_lock);
832 vport->fc_flag |= FC_PT2PT_PLOGI;
833 spin_unlock_irq(shost->host_lock);
836 * N_Port ID cannot be 0, set our to LocalID the other
837 * side will be RemoteID.
842 vport->fc_myDID = PT2PT_LocalID;
844 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
848 lpfc_config_link(phba, mbox);
850 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
852 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
853 if (rc == MBX_NOT_FINISHED) {
854 mempool_free(mbox, phba->mbox_mem_pool);
859 * For SLI4, the VFI/VPI are registered AFTER the
860 * Nport with the higher WWPN sends the PLOGI with
861 * an assigned NPortId.
865 if ((phba->sli_rev == LPFC_SLI_REV4) && rc)
866 lpfc_issue_reg_vfi(vport);
868 /* Decrement ndlp reference count indicating that ndlp can be
869 * safely released when other references to it are done.
873 ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
876 * Cannot find existing Fabric ndlp, so allocate a
879 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
882 lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID);
883 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
884 ndlp = lpfc_enable_node(vport, ndlp,
885 NLP_STE_UNUSED_NODE);
890 memcpy(&ndlp->nlp_portname, &sp->portName,
891 sizeof(struct lpfc_name));
892 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
893 sizeof(struct lpfc_name));
894 /* Set state will put ndlp onto node list if not already done */
895 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
896 spin_lock_irq(shost->host_lock);
897 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
898 spin_unlock_irq(shost->host_lock);
900 /* This side will wait for the PLOGI, decrement ndlp reference
901 * count indicating that ndlp can be released when other
902 * references to it are done.
906 /* If we are pt2pt with another NPort, force NPIV off! */
907 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
909 spin_lock_irq(shost->host_lock);
910 vport->fc_flag |= FC_PT2PT;
911 spin_unlock_irq(shost->host_lock);
913 /* Start discovery - this should just do CLEAR_LA */
914 lpfc_disc_start(vport);
921 * lpfc_cmpl_els_flogi - Completion callback function for flogi
922 * @phba: pointer to lpfc hba data structure.
923 * @cmdiocb: pointer to lpfc command iocb data structure.
924 * @rspiocb: pointer to lpfc response iocb data structure.
926 * This routine is the top-level completion callback function for issuing
927 * a Fabric Login (FLOGI) command. If the response IOCB reported error,
928 * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If
929 * retry has been made (either immediately or delayed with lpfc_els_retry()
930 * returning 1), the command IOCB will be released and function returned.
931 * If the retry attempt has been given up (possibly reach the maximum
932 * number of retries), one additional decrement of ndlp reference shall be
933 * invoked before going out after releasing the command IOCB. This will
934 * actually release the remote node (Note, lpfc_els_free_iocb() will also
935 * invoke one decrement of ndlp reference count). If no error reported in
936 * the IOCB status, the command Port ID field is used to determine whether
937 * this is a point-to-point topology or a fabric topology: if the Port ID
938 * field is assigned, it is a fabric topology; otherwise, it is a
939 * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or
940 * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the
941 * specific topology completion conditions.
944 lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
945 struct lpfc_iocbq *rspiocb)
947 struct lpfc_vport *vport = cmdiocb->vport;
948 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
949 IOCB_t *irsp = &rspiocb->iocb;
950 struct lpfc_nodelist *ndlp = cmdiocb->context1;
951 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
952 struct serv_parm *sp;
956 /* Check to see if link went down during discovery */
957 if (lpfc_els_chk_latt(vport)) {
958 /* One additional decrement on node reference count to
959 * trigger the release of the node
965 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
966 "FLOGI cmpl: status:x%x/x%x state:x%x",
967 irsp->ulpStatus, irsp->un.ulpWord[4],
970 if (irsp->ulpStatus) {
972 * In case of FIP mode, perform roundrobin FCF failover
973 * due to new FCF discovery
975 if ((phba->hba_flag & HBA_FIP_SUPPORT) &&
976 (phba->fcf.fcf_flag & FCF_DISCOVERY)) {
977 if (phba->link_state < LPFC_LINK_UP)
978 goto stop_rr_fcf_flogi;
979 if ((phba->fcoe_cvl_eventtag_attn ==
980 phba->fcoe_cvl_eventtag) &&
981 (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
982 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
984 goto stop_rr_fcf_flogi;
986 phba->fcoe_cvl_eventtag_attn =
987 phba->fcoe_cvl_eventtag;
988 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
989 "2611 FLOGI failed on FCF (x%x), "
990 "status:x%x/x%x, tmo:x%x, perform "
991 "roundrobin FCF failover\n",
992 phba->fcf.current_rec.fcf_indx,
993 irsp->ulpStatus, irsp->un.ulpWord[4],
995 lpfc_sli4_set_fcf_flogi_fail(phba,
996 phba->fcf.current_rec.fcf_indx);
997 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
998 rc = lpfc_sli4_fcf_rr_next_proc(vport, fcf_index);
1005 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1006 "2858 FLOGI failure Status:x%x/x%x TMO:x%x\n",
1007 irsp->ulpStatus, irsp->un.ulpWord[4],
1010 /* Check for retry */
1011 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
1015 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1016 "0100 FLOGI failure Status:x%x/x%x TMO:x%x\n",
1017 irsp->ulpStatus, irsp->un.ulpWord[4],
1020 /* FLOGI failed, so there is no fabric */
1021 spin_lock_irq(shost->host_lock);
1022 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
1023 spin_unlock_irq(shost->host_lock);
1025 /* If private loop, then allow max outstanding els to be
1026 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
1027 * alpa map would take too long otherwise.
1029 if (phba->alpa_map[0] == 0)
1030 vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
1031 if ((phba->sli_rev == LPFC_SLI_REV4) &&
1032 (!(vport->fc_flag & FC_VFI_REGISTERED) ||
1033 (vport->fc_prevDID != vport->fc_myDID))) {
1034 if (vport->fc_flag & FC_VFI_REGISTERED)
1035 lpfc_sli4_unreg_all_rpis(vport);
1036 lpfc_issue_reg_vfi(vport);
1042 spin_lock_irq(shost->host_lock);
1043 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
1044 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
1045 spin_unlock_irq(shost->host_lock);
1048 * The FLogI succeeded. Sync the data for the CPU before
1051 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
1053 sp = prsp->virt + sizeof(uint32_t);
1055 /* FLOGI completes successfully */
1056 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1057 "0101 FLOGI completes successfully "
1058 "Data: x%x x%x x%x x%x\n",
1059 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
1060 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution);
1062 if (vport->port_state == LPFC_FLOGI) {
1064 * If Common Service Parameters indicate Nport
1065 * we are point to point, if Fport we are Fabric.
1068 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
1069 else if (!(phba->hba_flag & HBA_FCOE_MODE))
1070 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
1072 lpfc_printf_vlog(vport, KERN_ERR,
1074 "2831 FLOGI response with cleared Fabric "
1075 "bit fcf_index 0x%x "
1076 "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x "
1078 "%02x%02x%02x%02x%02x%02x%02x%02x\n",
1079 phba->fcf.current_rec.fcf_indx,
1080 phba->fcf.current_rec.switch_name[0],
1081 phba->fcf.current_rec.switch_name[1],
1082 phba->fcf.current_rec.switch_name[2],
1083 phba->fcf.current_rec.switch_name[3],
1084 phba->fcf.current_rec.switch_name[4],
1085 phba->fcf.current_rec.switch_name[5],
1086 phba->fcf.current_rec.switch_name[6],
1087 phba->fcf.current_rec.switch_name[7],
1088 phba->fcf.current_rec.fabric_name[0],
1089 phba->fcf.current_rec.fabric_name[1],
1090 phba->fcf.current_rec.fabric_name[2],
1091 phba->fcf.current_rec.fabric_name[3],
1092 phba->fcf.current_rec.fabric_name[4],
1093 phba->fcf.current_rec.fabric_name[5],
1094 phba->fcf.current_rec.fabric_name[6],
1095 phba->fcf.current_rec.fabric_name[7]);
1097 spin_lock_irq(&phba->hbalock);
1098 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
1099 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
1100 spin_unlock_irq(&phba->hbalock);
1104 /* Mark the FCF discovery process done */
1105 if (phba->hba_flag & HBA_FIP_SUPPORT)
1106 lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP |
1108 "2769 FLOGI to FCF (x%x) "
1109 "completed successfully\n",
1110 phba->fcf.current_rec.fcf_indx);
1111 spin_lock_irq(&phba->hbalock);
1112 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
1113 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
1114 spin_unlock_irq(&phba->hbalock);
1122 if (!lpfc_error_lost_link(irsp)) {
1123 /* FLOGI failed, so just use loop map to make discovery list */
1124 lpfc_disc_list_loopmap(vport);
1126 /* Start discovery */
1127 lpfc_disc_start(vport);
1128 } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
1129 (((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
1130 IOERR_SLI_ABORTED) &&
1131 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
1132 IOERR_SLI_DOWN))) &&
1133 (phba->link_state != LPFC_CLEAR_LA)) {
1134 /* If FLOGI failed enable link interrupt. */
1135 lpfc_issue_clear_la(phba, vport);
1138 lpfc_els_free_iocb(phba, cmdiocb);
1142 * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport
1143 * @vport: pointer to a host virtual N_Port data structure.
1144 * @ndlp: pointer to a node-list data structure.
1145 * @retry: number of retries to the command IOCB.
1147 * This routine issues a Fabric Login (FLOGI) Request ELS command
1148 * for a @vport. The initiator service parameters are put into the payload
1149 * of the FLOGI Request IOCB and the top-level callback function pointer
1150 * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
1151 * function field. The lpfc_issue_fabric_iocb routine is invoked to send
1152 * out FLOGI ELS command with one outstanding fabric IOCB at a time.
1154 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1155 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1156 * will be stored into the context1 field of the IOCB for the completion
1157 * callback function to the FLOGI ELS command.
1160 * 0 - successfully issued flogi iocb for @vport
1161 * 1 - failed to issue flogi iocb for @vport
1164 lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1167 struct lpfc_hba *phba = vport->phba;
1168 struct serv_parm *sp;
1170 struct lpfc_iocbq *elsiocb;
1171 struct lpfc_sli_ring *pring;
1177 pring = &phba->sli.ring[LPFC_ELS_RING];
1179 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
1180 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1181 ndlp->nlp_DID, ELS_CMD_FLOGI);
1186 icmd = &elsiocb->iocb;
1187 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1189 /* For FLOGI request, remainder of payload is service parameters */
1190 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
1191 pcmd += sizeof(uint32_t);
1192 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
1193 sp = (struct serv_parm *) pcmd;
1195 /* Setup CSPs accordingly for Fabric */
1196 sp->cmn.e_d_tov = 0;
1197 sp->cmn.w2.r_a_tov = 0;
1198 sp->cmn.virtual_fabric_support = 0;
1199 sp->cls1.classValid = 0;
1200 if (sp->cmn.fcphLow < FC_PH3)
1201 sp->cmn.fcphLow = FC_PH3;
1202 if (sp->cmn.fcphHigh < FC_PH3)
1203 sp->cmn.fcphHigh = FC_PH3;
1205 if (phba->sli_rev == LPFC_SLI_REV4) {
1206 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
1207 LPFC_SLI_INTF_IF_TYPE_0) {
1208 elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1);
1209 elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1);
1210 /* FLOGI needs to be 3 for WQE FCFI */
1211 /* Set the fcfi to the fcfi we registered with */
1212 elsiocb->iocb.ulpContext = phba->fcf.fcfi;
1214 /* Can't do SLI4 class2 without support sequence coalescing */
1215 sp->cls2.classValid = 0;
1216 sp->cls2.seqDelivery = 0;
1218 /* Historical, setting sequential-delivery bit for SLI3 */
1219 sp->cls2.seqDelivery = (sp->cls2.classValid) ? 1 : 0;
1220 sp->cls3.seqDelivery = (sp->cls3.classValid) ? 1 : 0;
1221 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
1222 sp->cmn.request_multiple_Nport = 1;
1223 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
1227 sp->cmn.request_multiple_Nport = 0;
1230 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
1231 icmd->un.elsreq64.myID = 0;
1232 icmd->un.elsreq64.fl = 1;
1235 tmo = phba->fc_ratov;
1236 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
1237 lpfc_set_disctmo(vport);
1238 phba->fc_ratov = tmo;
1240 phba->fc_stat.elsXmitFLOGI++;
1241 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
1243 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1244 "Issue FLOGI: opt:x%x",
1245 phba->sli3_options, 0, 0);
1247 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
1248 if (rc == IOCB_ERROR) {
1249 lpfc_els_free_iocb(phba, elsiocb);
1256 * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs
1257 * @phba: pointer to lpfc hba data structure.
1259 * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
1260 * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
1261 * list and issues an abort IOCB commond on each outstanding IOCB that
1262 * contains a active Fabric_DID ndlp. Note that this function is to issue
1263 * the abort IOCB command on all the outstanding IOCBs, thus when this
1264 * function returns, it does not guarantee all the IOCBs are actually aborted.
1267 * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0)
1270 lpfc_els_abort_flogi(struct lpfc_hba *phba)
1272 struct lpfc_sli_ring *pring;
1273 struct lpfc_iocbq *iocb, *next_iocb;
1274 struct lpfc_nodelist *ndlp;
1277 /* Abort outstanding I/O on NPort <nlp_DID> */
1278 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
1279 "0201 Abort outstanding I/O on NPort x%x\n",
1282 pring = &phba->sli.ring[LPFC_ELS_RING];
1285 * Check the txcmplq for an iocb that matches the nport the driver is
1288 spin_lock_irq(&phba->hbalock);
1289 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
1291 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR) {
1292 ndlp = (struct lpfc_nodelist *)(iocb->context1);
1293 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
1294 (ndlp->nlp_DID == Fabric_DID))
1295 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
1298 spin_unlock_irq(&phba->hbalock);
1304 * lpfc_initial_flogi - Issue an initial fabric login for a vport
1305 * @vport: pointer to a host virtual N_Port data structure.
1307 * This routine issues an initial Fabric Login (FLOGI) for the @vport
1308 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1309 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1310 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1311 * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
1312 * is then invoked with the @vport and the ndlp to perform the FLOGI for the
1316 * 0 - failed to issue initial flogi for @vport
1317 * 1 - successfully issued initial flogi for @vport
1320 lpfc_initial_flogi(struct lpfc_vport *vport)
1322 struct lpfc_hba *phba = vport->phba;
1323 struct lpfc_nodelist *ndlp;
1325 vport->port_state = LPFC_FLOGI;
1326 lpfc_set_disctmo(vport);
1328 /* First look for the Fabric ndlp */
1329 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1331 /* Cannot find existing Fabric ndlp, so allocate a new one */
1332 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1335 lpfc_nlp_init(vport, ndlp, Fabric_DID);
1336 /* Set the node type */
1337 ndlp->nlp_type |= NLP_FABRIC;
1338 /* Put ndlp onto node list */
1339 lpfc_enqueue_node(vport, ndlp);
1340 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1341 /* re-setup ndlp without removing from node list */
1342 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1347 if (lpfc_issue_els_flogi(vport, ndlp, 0)) {
1348 /* This decrement of reference count to node shall kick off
1349 * the release of the node.
1358 * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport
1359 * @vport: pointer to a host virtual N_Port data structure.
1361 * This routine issues an initial Fabric Discover (FDISC) for the @vport
1362 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1363 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1364 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1365 * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
1366 * is then invoked with the @vport and the ndlp to perform the FDISC for the
1370 * 0 - failed to issue initial fdisc for @vport
1371 * 1 - successfully issued initial fdisc for @vport
1374 lpfc_initial_fdisc(struct lpfc_vport *vport)
1376 struct lpfc_hba *phba = vport->phba;
1377 struct lpfc_nodelist *ndlp;
1379 /* First look for the Fabric ndlp */
1380 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1382 /* Cannot find existing Fabric ndlp, so allocate a new one */
1383 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1386 lpfc_nlp_init(vport, ndlp, Fabric_DID);
1387 /* Put ndlp onto node list */
1388 lpfc_enqueue_node(vport, ndlp);
1389 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1390 /* re-setup ndlp without removing from node list */
1391 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1396 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
1397 /* decrement node reference count to trigger the release of
1407 * lpfc_more_plogi - Check and issue remaining plogis for a vport
1408 * @vport: pointer to a host virtual N_Port data structure.
1410 * This routine checks whether there are more remaining Port Logins
1411 * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
1412 * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
1413 * to issue ELS PLOGIs up to the configured discover threads with the
1414 * @vport (@vport->cfg_discovery_threads). The function also decrement
1415 * the @vport's num_disc_node by 1 if it is not already 0.
1418 lpfc_more_plogi(struct lpfc_vport *vport)
1422 if (vport->num_disc_nodes)
1423 vport->num_disc_nodes--;
1425 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
1426 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1427 "0232 Continue discovery with %d PLOGIs to go "
1428 "Data: x%x x%x x%x\n",
1429 vport->num_disc_nodes, vport->fc_plogi_cnt,
1430 vport->fc_flag, vport->port_state);
1431 /* Check to see if there are more PLOGIs to be sent */
1432 if (vport->fc_flag & FC_NLP_MORE)
1433 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
1434 sentplogi = lpfc_els_disc_plogi(vport);
1440 * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp
1441 * @phba: pointer to lpfc hba data structure.
1442 * @prsp: pointer to response IOCB payload.
1443 * @ndlp: pointer to a node-list data structure.
1445 * This routine checks and indicates whether the WWPN of an N_Port, retrieved
1446 * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
1447 * The following cases are considered N_Port confirmed:
1448 * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
1449 * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
1450 * it does not have WWPN assigned either. If the WWPN is confirmed, the
1451 * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
1452 * 1) if there is a node on vport list other than the @ndlp with the same
1453 * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
1454 * on that node to release the RPI associated with the node; 2) if there is
1455 * no node found on vport list with the same WWPN of the N_Port PLOGI logged
1456 * into, a new node shall be allocated (or activated). In either case, the
1457 * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
1458 * be released and the new_ndlp shall be put on to the vport node list and
1459 * its pointer returned as the confirmed node.
1461 * Note that before the @ndlp got "released", the keepDID from not-matching
1462 * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
1463 * of the @ndlp. This is because the release of @ndlp is actually to put it
1464 * into an inactive state on the vport node list and the vport node list
1465 * management algorithm does not allow two node with a same DID.
1468 * pointer to the PLOGI N_Port @ndlp
1470 static struct lpfc_nodelist *
1471 lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
1472 struct lpfc_nodelist *ndlp)
1474 struct lpfc_vport *vport = ndlp->vport;
1475 struct lpfc_nodelist *new_ndlp;
1476 struct lpfc_rport_data *rdata;
1477 struct fc_rport *rport;
1478 struct serv_parm *sp;
1479 uint8_t name[sizeof(struct lpfc_name)];
1480 uint32_t rc, keepDID = 0;
1483 struct lpfc_node_rrqs rrq;
1485 /* Fabric nodes can have the same WWPN so we don't bother searching
1486 * by WWPN. Just return the ndlp that was given to us.
1488 if (ndlp->nlp_type & NLP_FABRIC)
1491 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
1492 memset(name, 0, sizeof(struct lpfc_name));
1494 /* Now we find out if the NPort we are logging into, matches the WWPN
1495 * we have for that ndlp. If not, we have some work to do.
1497 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
1499 if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp))
1501 memset(&rrq.xri_bitmap, 0, sizeof(new_ndlp->active_rrqs.xri_bitmap));
1503 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1504 "3178 PLOGI confirm: ndlp %p x%x: new_ndlp %p\n",
1505 ndlp, ndlp->nlp_DID, new_ndlp);
1508 rc = memcmp(&ndlp->nlp_portname, name,
1509 sizeof(struct lpfc_name));
1512 new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
1515 lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID);
1516 } else if (!NLP_CHK_NODE_ACT(new_ndlp)) {
1517 rc = memcmp(&ndlp->nlp_portname, name,
1518 sizeof(struct lpfc_name));
1521 new_ndlp = lpfc_enable_node(vport, new_ndlp,
1522 NLP_STE_UNUSED_NODE);
1525 keepDID = new_ndlp->nlp_DID;
1526 if (phba->sli_rev == LPFC_SLI_REV4)
1527 memcpy(&rrq.xri_bitmap,
1528 &new_ndlp->active_rrqs.xri_bitmap,
1529 sizeof(new_ndlp->active_rrqs.xri_bitmap));
1531 keepDID = new_ndlp->nlp_DID;
1532 if (phba->sli_rev == LPFC_SLI_REV4)
1533 memcpy(&rrq.xri_bitmap,
1534 &new_ndlp->active_rrqs.xri_bitmap,
1535 sizeof(new_ndlp->active_rrqs.xri_bitmap));
1538 lpfc_unreg_rpi(vport, new_ndlp);
1539 new_ndlp->nlp_DID = ndlp->nlp_DID;
1540 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
1541 if (phba->sli_rev == LPFC_SLI_REV4)
1542 memcpy(new_ndlp->active_rrqs.xri_bitmap,
1543 &ndlp->active_rrqs.xri_bitmap,
1544 sizeof(ndlp->active_rrqs.xri_bitmap));
1546 if (ndlp->nlp_flag & NLP_NPR_2B_DISC)
1547 new_ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1548 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1550 /* Set state will put new_ndlp on to node list if not already done */
1551 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
1553 /* Move this back to NPR state */
1554 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
1555 /* The new_ndlp is replacing ndlp totally, so we need
1556 * to put ndlp on UNUSED list and try to free it.
1558 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1559 "3179 PLOGI confirm NEW: %x %x\n",
1560 new_ndlp->nlp_DID, keepDID);
1562 /* Fix up the rport accordingly */
1563 rport = ndlp->rport;
1565 rdata = rport->dd_data;
1566 if (rdata->pnode == ndlp) {
1569 rdata->pnode = lpfc_nlp_get(new_ndlp);
1570 new_ndlp->rport = rport;
1572 new_ndlp->nlp_type = ndlp->nlp_type;
1574 /* We shall actually free the ndlp with both nlp_DID and
1575 * nlp_portname fields equals 0 to avoid any ndlp on the
1576 * nodelist never to be used.
1578 if (ndlp->nlp_DID == 0) {
1579 spin_lock_irq(&phba->ndlp_lock);
1580 NLP_SET_FREE_REQ(ndlp);
1581 spin_unlock_irq(&phba->ndlp_lock);
1584 /* Two ndlps cannot have the same did on the nodelist */
1585 ndlp->nlp_DID = keepDID;
1586 if (phba->sli_rev == LPFC_SLI_REV4)
1587 memcpy(&ndlp->active_rrqs.xri_bitmap,
1589 sizeof(ndlp->active_rrqs.xri_bitmap));
1590 lpfc_drop_node(vport, ndlp);
1593 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1594 "3180 PLOGI confirm SWAP: %x %x\n",
1595 new_ndlp->nlp_DID, keepDID);
1597 lpfc_unreg_rpi(vport, ndlp);
1599 /* Two ndlps cannot have the same did */
1600 ndlp->nlp_DID = keepDID;
1601 if (phba->sli_rev == LPFC_SLI_REV4)
1602 memcpy(&ndlp->active_rrqs.xri_bitmap,
1604 sizeof(ndlp->active_rrqs.xri_bitmap));
1606 /* Since we are swapping the ndlp passed in with the new one
1607 * and the did has already been swapped, copy over state.
1608 * The new WWNs are already in new_ndlp since thats what
1609 * we looked it up by in the begining of this routine.
1611 new_ndlp->nlp_state = ndlp->nlp_state;
1613 /* Since we are switching over to the new_ndlp, the old
1614 * ndlp should be put in the NPR state, unless we have
1615 * already started re-discovery on it.
1617 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
1618 (ndlp->nlp_state == NLP_STE_MAPPED_NODE))
1619 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1621 /* Fix up the rport accordingly */
1622 rport = ndlp->rport;
1624 rdata = rport->dd_data;
1625 put_node = rdata->pnode != NULL;
1626 put_rport = ndlp->rport != NULL;
1627 rdata->pnode = NULL;
1632 put_device(&rport->dev);
1639 * lpfc_end_rscn - Check and handle more rscn for a vport
1640 * @vport: pointer to a host virtual N_Port data structure.
1642 * This routine checks whether more Registration State Change
1643 * Notifications (RSCNs) came in while the discovery state machine was in
1644 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1645 * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1646 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1647 * handling the RSCNs.
1650 lpfc_end_rscn(struct lpfc_vport *vport)
1652 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1654 if (vport->fc_flag & FC_RSCN_MODE) {
1656 * Check to see if more RSCNs came in while we were
1657 * processing this one.
1659 if (vport->fc_rscn_id_cnt ||
1660 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
1661 lpfc_els_handle_rscn(vport);
1663 spin_lock_irq(shost->host_lock);
1664 vport->fc_flag &= ~FC_RSCN_MODE;
1665 spin_unlock_irq(shost->host_lock);
1671 * lpfc_cmpl_els_rrq - Completion handled for els RRQs.
1672 * @phba: pointer to lpfc hba data structure.
1673 * @cmdiocb: pointer to lpfc command iocb data structure.
1674 * @rspiocb: pointer to lpfc response iocb data structure.
1676 * This routine will call the clear rrq function to free the rrq and
1677 * clear the xri's bit in the ndlp's xri_bitmap. If the ndlp does not
1678 * exist then the clear_rrq is still called because the rrq needs to
1683 lpfc_cmpl_els_rrq(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1684 struct lpfc_iocbq *rspiocb)
1686 struct lpfc_vport *vport = cmdiocb->vport;
1688 struct lpfc_nodelist *ndlp;
1689 struct lpfc_node_rrq *rrq;
1691 /* we pass cmdiocb to state machine which needs rspiocb as well */
1692 rrq = cmdiocb->context_un.rrq;
1693 cmdiocb->context_un.rsp_iocb = rspiocb;
1695 irsp = &rspiocb->iocb;
1696 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1697 "RRQ cmpl: status:x%x/x%x did:x%x",
1698 irsp->ulpStatus, irsp->un.ulpWord[4],
1699 irsp->un.elsreq64.remoteID);
1701 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
1702 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || ndlp != rrq->ndlp) {
1703 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1704 "2882 RRQ completes to NPort x%x "
1705 "with no ndlp. Data: x%x x%x x%x\n",
1706 irsp->un.elsreq64.remoteID,
1707 irsp->ulpStatus, irsp->un.ulpWord[4],
1712 /* rrq completes to NPort <nlp_DID> */
1713 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1714 "2880 RRQ completes to NPort x%x "
1715 "Data: x%x x%x x%x x%x x%x\n",
1716 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1717 irsp->ulpTimeout, rrq->xritag, rrq->rxid);
1719 if (irsp->ulpStatus) {
1720 /* Check for retry */
1721 /* RRQ failed Don't print the vport to vport rjts */
1722 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1723 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1724 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1725 (phba)->pport->cfg_log_verbose & LOG_ELS)
1726 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1727 "2881 RRQ failure DID:%06X Status:x%x/x%x\n",
1728 ndlp->nlp_DID, irsp->ulpStatus,
1729 irsp->un.ulpWord[4]);
1733 lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
1734 lpfc_els_free_iocb(phba, cmdiocb);
1738 * lpfc_cmpl_els_plogi - Completion callback function for plogi
1739 * @phba: pointer to lpfc hba data structure.
1740 * @cmdiocb: pointer to lpfc command iocb data structure.
1741 * @rspiocb: pointer to lpfc response iocb data structure.
1743 * This routine is the completion callback function for issuing the Port
1744 * Login (PLOGI) command. For PLOGI completion, there must be an active
1745 * ndlp on the vport node list that matches the remote node ID from the
1746 * PLOGI response IOCB. If such ndlp does not exist, the PLOGI is simply
1747 * ignored and command IOCB released. The PLOGI response IOCB status is
1748 * checked for error conditons. If there is error status reported, PLOGI
1749 * retry shall be attempted by invoking the lpfc_els_retry() routine.
1750 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1751 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1752 * (DSM) is set for this PLOGI completion. Finally, it checks whether
1753 * there are additional N_Port nodes with the vport that need to perform
1754 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
1758 lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1759 struct lpfc_iocbq *rspiocb)
1761 struct lpfc_vport *vport = cmdiocb->vport;
1762 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1764 struct lpfc_nodelist *ndlp;
1765 struct lpfc_dmabuf *prsp;
1766 int disc, rc, did, type;
1768 /* we pass cmdiocb to state machine which needs rspiocb as well */
1769 cmdiocb->context_un.rsp_iocb = rspiocb;
1771 irsp = &rspiocb->iocb;
1772 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1773 "PLOGI cmpl: status:x%x/x%x did:x%x",
1774 irsp->ulpStatus, irsp->un.ulpWord[4],
1775 irsp->un.elsreq64.remoteID);
1777 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
1778 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
1779 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1780 "0136 PLOGI completes to NPort x%x "
1781 "with no ndlp. Data: x%x x%x x%x\n",
1782 irsp->un.elsreq64.remoteID,
1783 irsp->ulpStatus, irsp->un.ulpWord[4],
1788 /* Since ndlp can be freed in the disc state machine, note if this node
1789 * is being used during discovery.
1791 spin_lock_irq(shost->host_lock);
1792 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
1793 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1794 spin_unlock_irq(shost->host_lock);
1797 /* PLOGI completes to NPort <nlp_DID> */
1798 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1799 "0102 PLOGI completes to NPort x%x "
1800 "Data: x%x x%x x%x x%x x%x\n",
1801 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1802 irsp->ulpTimeout, disc, vport->num_disc_nodes);
1803 /* Check to see if link went down during discovery */
1804 if (lpfc_els_chk_latt(vport)) {
1805 spin_lock_irq(shost->host_lock);
1806 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1807 spin_unlock_irq(shost->host_lock);
1811 /* ndlp could be freed in DSM, save these values now */
1812 type = ndlp->nlp_type;
1813 did = ndlp->nlp_DID;
1815 if (irsp->ulpStatus) {
1816 /* Check for retry */
1817 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1818 /* ELS command is being retried */
1820 spin_lock_irq(shost->host_lock);
1821 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1822 spin_unlock_irq(shost->host_lock);
1826 /* PLOGI failed Don't print the vport to vport rjts */
1827 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1828 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1829 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1830 (phba)->pport->cfg_log_verbose & LOG_ELS)
1831 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1832 "2753 PLOGI failure DID:%06X Status:x%x/x%x\n",
1833 ndlp->nlp_DID, irsp->ulpStatus,
1834 irsp->un.ulpWord[4]);
1835 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1836 if (lpfc_error_lost_link(irsp))
1837 rc = NLP_STE_FREED_NODE;
1839 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1840 NLP_EVT_CMPL_PLOGI);
1842 /* Good status, call state machine */
1843 prsp = list_entry(((struct lpfc_dmabuf *)
1844 cmdiocb->context2)->list.next,
1845 struct lpfc_dmabuf, list);
1846 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
1847 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1848 NLP_EVT_CMPL_PLOGI);
1851 if (disc && vport->num_disc_nodes) {
1852 /* Check to see if there are more PLOGIs to be sent */
1853 lpfc_more_plogi(vport);
1855 if (vport->num_disc_nodes == 0) {
1856 spin_lock_irq(shost->host_lock);
1857 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1858 spin_unlock_irq(shost->host_lock);
1860 lpfc_can_disctmo(vport);
1861 lpfc_end_rscn(vport);
1866 lpfc_els_free_iocb(phba, cmdiocb);
1871 * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
1872 * @vport: pointer to a host virtual N_Port data structure.
1873 * @did: destination port identifier.
1874 * @retry: number of retries to the command IOCB.
1876 * This routine issues a Port Login (PLOGI) command to a remote N_Port
1877 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
1878 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
1879 * This routine constructs the proper feilds of the PLOGI IOCB and invokes
1880 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
1882 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1883 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1884 * will be stored into the context1 field of the IOCB for the completion
1885 * callback function to the PLOGI ELS command.
1888 * 0 - Successfully issued a plogi for @vport
1889 * 1 - failed to issue a plogi for @vport
1892 lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
1894 struct lpfc_hba *phba = vport->phba;
1895 struct serv_parm *sp;
1897 struct lpfc_nodelist *ndlp;
1898 struct lpfc_iocbq *elsiocb;
1899 struct lpfc_sli *psli;
1906 ndlp = lpfc_findnode_did(vport, did);
1907 if (ndlp && !NLP_CHK_NODE_ACT(ndlp))
1910 /* If ndlp is not NULL, we will bump the reference count on it */
1911 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
1912 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
1917 icmd = &elsiocb->iocb;
1918 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1920 /* For PLOGI request, remainder of payload is service parameters */
1921 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
1922 pcmd += sizeof(uint32_t);
1923 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
1924 sp = (struct serv_parm *) pcmd;
1927 * If we are a N-port connected to a Fabric, fix-up paramm's so logins
1928 * to device on remote loops work.
1930 if ((vport->fc_flag & FC_FABRIC) && !(vport->fc_flag & FC_PUBLIC_LOOP))
1931 sp->cmn.altBbCredit = 1;
1933 if (sp->cmn.fcphLow < FC_PH_4_3)
1934 sp->cmn.fcphLow = FC_PH_4_3;
1936 if (sp->cmn.fcphHigh < FC_PH3)
1937 sp->cmn.fcphHigh = FC_PH3;
1939 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1940 "Issue PLOGI: did:x%x",
1943 phba->fc_stat.elsXmitPLOGI++;
1944 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
1945 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
1947 if (ret == IOCB_ERROR) {
1948 lpfc_els_free_iocb(phba, elsiocb);
1955 * lpfc_cmpl_els_prli - Completion callback function for prli
1956 * @phba: pointer to lpfc hba data structure.
1957 * @cmdiocb: pointer to lpfc command iocb data structure.
1958 * @rspiocb: pointer to lpfc response iocb data structure.
1960 * This routine is the completion callback function for a Process Login
1961 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
1962 * status. If there is error status reported, PRLI retry shall be attempted
1963 * by invoking the lpfc_els_retry() routine. Otherwise, the state
1964 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
1965 * ndlp to mark the PRLI completion.
1968 lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1969 struct lpfc_iocbq *rspiocb)
1971 struct lpfc_vport *vport = cmdiocb->vport;
1972 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1974 struct lpfc_sli *psli;
1975 struct lpfc_nodelist *ndlp;
1978 /* we pass cmdiocb to state machine which needs rspiocb as well */
1979 cmdiocb->context_un.rsp_iocb = rspiocb;
1981 irsp = &(rspiocb->iocb);
1982 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1983 spin_lock_irq(shost->host_lock);
1984 ndlp->nlp_flag &= ~NLP_PRLI_SND;
1985 spin_unlock_irq(shost->host_lock);
1987 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1988 "PRLI cmpl: status:x%x/x%x did:x%x",
1989 irsp->ulpStatus, irsp->un.ulpWord[4],
1991 /* PRLI completes to NPort <nlp_DID> */
1992 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1993 "0103 PRLI completes to NPort x%x "
1994 "Data: x%x x%x x%x x%x\n",
1995 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1996 irsp->ulpTimeout, vport->num_disc_nodes);
1998 vport->fc_prli_sent--;
1999 /* Check to see if link went down during discovery */
2000 if (lpfc_els_chk_latt(vport))
2003 if (irsp->ulpStatus) {
2004 /* Check for retry */
2005 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2006 /* ELS command is being retried */
2010 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2011 "2754 PRLI failure DID:%06X Status:x%x/x%x\n",
2012 ndlp->nlp_DID, irsp->ulpStatus,
2013 irsp->un.ulpWord[4]);
2014 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2015 if (lpfc_error_lost_link(irsp))
2018 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2021 /* Good status, call state machine */
2022 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2025 lpfc_els_free_iocb(phba, cmdiocb);
2030 * lpfc_issue_els_prli - Issue a prli iocb command for a vport
2031 * @vport: pointer to a host virtual N_Port data structure.
2032 * @ndlp: pointer to a node-list data structure.
2033 * @retry: number of retries to the command IOCB.
2035 * This routine issues a Process Login (PRLI) ELS command for the
2036 * @vport. The PRLI service parameters are set up in the payload of the
2037 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
2038 * is put to the IOCB completion callback func field before invoking the
2039 * routine lpfc_sli_issue_iocb() to send out PRLI command.
2041 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2042 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2043 * will be stored into the context1 field of the IOCB for the completion
2044 * callback function to the PRLI ELS command.
2047 * 0 - successfully issued prli iocb command for @vport
2048 * 1 - failed to issue prli iocb command for @vport
2051 lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2054 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2055 struct lpfc_hba *phba = vport->phba;
2058 struct lpfc_iocbq *elsiocb;
2062 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
2063 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2064 ndlp->nlp_DID, ELS_CMD_PRLI);
2068 icmd = &elsiocb->iocb;
2069 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2071 /* For PRLI request, remainder of payload is service parameters */
2072 memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t)));
2073 *((uint32_t *) (pcmd)) = ELS_CMD_PRLI;
2074 pcmd += sizeof(uint32_t);
2076 /* For PRLI, remainder of payload is PRLI parameter page */
2077 npr = (PRLI *) pcmd;
2079 * If our firmware version is 3.20 or later,
2080 * set the following bits for FC-TAPE support.
2082 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
2083 npr->ConfmComplAllowed = 1;
2085 npr->TaskRetryIdReq = 1;
2087 npr->estabImagePair = 1;
2088 npr->readXferRdyDis = 1;
2090 /* For FCP support */
2091 npr->prliType = PRLI_FCP_TYPE;
2092 npr->initiatorFunc = 1;
2094 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2095 "Issue PRLI: did:x%x",
2096 ndlp->nlp_DID, 0, 0);
2098 phba->fc_stat.elsXmitPRLI++;
2099 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
2100 spin_lock_irq(shost->host_lock);
2101 ndlp->nlp_flag |= NLP_PRLI_SND;
2102 spin_unlock_irq(shost->host_lock);
2103 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2105 spin_lock_irq(shost->host_lock);
2106 ndlp->nlp_flag &= ~NLP_PRLI_SND;
2107 spin_unlock_irq(shost->host_lock);
2108 lpfc_els_free_iocb(phba, elsiocb);
2111 vport->fc_prli_sent++;
2116 * lpfc_rscn_disc - Perform rscn discovery for a vport
2117 * @vport: pointer to a host virtual N_Port data structure.
2119 * This routine performs Registration State Change Notification (RSCN)
2120 * discovery for a @vport. If the @vport's node port recovery count is not
2121 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
2122 * the nodes that need recovery. If none of the PLOGI were needed through
2123 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
2124 * invoked to check and handle possible more RSCN came in during the period
2125 * of processing the current ones.
2128 lpfc_rscn_disc(struct lpfc_vport *vport)
2130 lpfc_can_disctmo(vport);
2132 /* RSCN discovery */
2133 /* go thru NPR nodes and issue ELS PLOGIs */
2134 if (vport->fc_npr_cnt)
2135 if (lpfc_els_disc_plogi(vport))
2138 lpfc_end_rscn(vport);
2142 * lpfc_adisc_done - Complete the adisc phase of discovery
2143 * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
2145 * This function is called when the final ADISC is completed during discovery.
2146 * This function handles clearing link attention or issuing reg_vpi depending
2147 * on whether npiv is enabled. This function also kicks off the PLOGI phase of
2149 * This function is called with no locks held.
2152 lpfc_adisc_done(struct lpfc_vport *vport)
2154 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2155 struct lpfc_hba *phba = vport->phba;
2158 * For NPIV, cmpl_reg_vpi will set port_state to READY,
2159 * and continue discovery.
2161 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2162 !(vport->fc_flag & FC_RSCN_MODE) &&
2163 (phba->sli_rev < LPFC_SLI_REV4)) {
2164 lpfc_issue_reg_vpi(phba, vport);
2168 * For SLI2, we need to set port_state to READY
2169 * and continue discovery.
2171 if (vport->port_state < LPFC_VPORT_READY) {
2172 /* If we get here, there is nothing to ADISC */
2173 if (vport->port_type == LPFC_PHYSICAL_PORT)
2174 lpfc_issue_clear_la(phba, vport);
2175 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
2176 vport->num_disc_nodes = 0;
2177 /* go thru NPR list, issue ELS PLOGIs */
2178 if (vport->fc_npr_cnt)
2179 lpfc_els_disc_plogi(vport);
2180 if (!vport->num_disc_nodes) {
2181 spin_lock_irq(shost->host_lock);
2182 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2183 spin_unlock_irq(shost->host_lock);
2184 lpfc_can_disctmo(vport);
2185 lpfc_end_rscn(vport);
2188 vport->port_state = LPFC_VPORT_READY;
2190 lpfc_rscn_disc(vport);
2194 * lpfc_more_adisc - Issue more adisc as needed
2195 * @vport: pointer to a host virtual N_Port data structure.
2197 * This routine determines whether there are more ndlps on a @vport
2198 * node list need to have Address Discover (ADISC) issued. If so, it will
2199 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
2200 * remaining nodes which need to have ADISC sent.
2203 lpfc_more_adisc(struct lpfc_vport *vport)
2207 if (vport->num_disc_nodes)
2208 vport->num_disc_nodes--;
2209 /* Continue discovery with <num_disc_nodes> ADISCs to go */
2210 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2211 "0210 Continue discovery with %d ADISCs to go "
2212 "Data: x%x x%x x%x\n",
2213 vport->num_disc_nodes, vport->fc_adisc_cnt,
2214 vport->fc_flag, vport->port_state);
2215 /* Check to see if there are more ADISCs to be sent */
2216 if (vport->fc_flag & FC_NLP_MORE) {
2217 lpfc_set_disctmo(vport);
2218 /* go thru NPR nodes and issue any remaining ELS ADISCs */
2219 sentadisc = lpfc_els_disc_adisc(vport);
2221 if (!vport->num_disc_nodes)
2222 lpfc_adisc_done(vport);
2227 * lpfc_cmpl_els_adisc - Completion callback function for adisc
2228 * @phba: pointer to lpfc hba data structure.
2229 * @cmdiocb: pointer to lpfc command iocb data structure.
2230 * @rspiocb: pointer to lpfc response iocb data structure.
2232 * This routine is the completion function for issuing the Address Discover
2233 * (ADISC) command. It first checks to see whether link went down during
2234 * the discovery process. If so, the node will be marked as node port
2235 * recovery for issuing discover IOCB by the link attention handler and
2236 * exit. Otherwise, the response status is checked. If error was reported
2237 * in the response status, the ADISC command shall be retried by invoking
2238 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
2239 * the response status, the state machine is invoked to set transition
2240 * with respect to NLP_EVT_CMPL_ADISC event.
2243 lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2244 struct lpfc_iocbq *rspiocb)
2246 struct lpfc_vport *vport = cmdiocb->vport;
2247 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2249 struct lpfc_nodelist *ndlp;
2252 /* we pass cmdiocb to state machine which needs rspiocb as well */
2253 cmdiocb->context_un.rsp_iocb = rspiocb;
2255 irsp = &(rspiocb->iocb);
2256 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2258 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2259 "ADISC cmpl: status:x%x/x%x did:x%x",
2260 irsp->ulpStatus, irsp->un.ulpWord[4],
2263 /* Since ndlp can be freed in the disc state machine, note if this node
2264 * is being used during discovery.
2266 spin_lock_irq(shost->host_lock);
2267 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
2268 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
2269 spin_unlock_irq(shost->host_lock);
2270 /* ADISC completes to NPort <nlp_DID> */
2271 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2272 "0104 ADISC completes to NPort x%x "
2273 "Data: x%x x%x x%x x%x x%x\n",
2274 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2275 irsp->ulpTimeout, disc, vport->num_disc_nodes);
2276 /* Check to see if link went down during discovery */
2277 if (lpfc_els_chk_latt(vport)) {
2278 spin_lock_irq(shost->host_lock);
2279 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2280 spin_unlock_irq(shost->host_lock);
2284 if (irsp->ulpStatus) {
2285 /* Check for retry */
2286 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2287 /* ELS command is being retried */
2289 spin_lock_irq(shost->host_lock);
2290 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2291 spin_unlock_irq(shost->host_lock);
2292 lpfc_set_disctmo(vport);
2297 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2298 "2755 ADISC failure DID:%06X Status:x%x/x%x\n",
2299 ndlp->nlp_DID, irsp->ulpStatus,
2300 irsp->un.ulpWord[4]);
2301 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2302 if (!lpfc_error_lost_link(irsp))
2303 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2304 NLP_EVT_CMPL_ADISC);
2306 /* Good status, call state machine */
2307 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2308 NLP_EVT_CMPL_ADISC);
2310 /* Check to see if there are more ADISCs to be sent */
2311 if (disc && vport->num_disc_nodes)
2312 lpfc_more_adisc(vport);
2314 lpfc_els_free_iocb(phba, cmdiocb);
2319 * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
2320 * @vport: pointer to a virtual N_Port data structure.
2321 * @ndlp: pointer to a node-list data structure.
2322 * @retry: number of retries to the command IOCB.
2324 * This routine issues an Address Discover (ADISC) for an @ndlp on a
2325 * @vport. It prepares the payload of the ADISC ELS command, updates the
2326 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
2327 * to issue the ADISC ELS command.
2329 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2330 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2331 * will be stored into the context1 field of the IOCB for the completion
2332 * callback function to the ADISC ELS command.
2335 * 0 - successfully issued adisc
2336 * 1 - failed to issue adisc
2339 lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2342 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2343 struct lpfc_hba *phba = vport->phba;
2346 struct lpfc_iocbq *elsiocb;
2350 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
2351 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2352 ndlp->nlp_DID, ELS_CMD_ADISC);
2356 icmd = &elsiocb->iocb;
2357 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2359 /* For ADISC request, remainder of payload is service parameters */
2360 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
2361 pcmd += sizeof(uint32_t);
2363 /* Fill in ADISC payload */
2364 ap = (ADISC *) pcmd;
2365 ap->hardAL_PA = phba->fc_pref_ALPA;
2366 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2367 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
2368 ap->DID = be32_to_cpu(vport->fc_myDID);
2370 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2371 "Issue ADISC: did:x%x",
2372 ndlp->nlp_DID, 0, 0);
2374 phba->fc_stat.elsXmitADISC++;
2375 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
2376 spin_lock_irq(shost->host_lock);
2377 ndlp->nlp_flag |= NLP_ADISC_SND;
2378 spin_unlock_irq(shost->host_lock);
2379 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2381 spin_lock_irq(shost->host_lock);
2382 ndlp->nlp_flag &= ~NLP_ADISC_SND;
2383 spin_unlock_irq(shost->host_lock);
2384 lpfc_els_free_iocb(phba, elsiocb);
2391 * lpfc_cmpl_els_logo - Completion callback function for logo
2392 * @phba: pointer to lpfc hba data structure.
2393 * @cmdiocb: pointer to lpfc command iocb data structure.
2394 * @rspiocb: pointer to lpfc response iocb data structure.
2396 * This routine is the completion function for issuing the ELS Logout (LOGO)
2397 * command. If no error status was reported from the LOGO response, the
2398 * state machine of the associated ndlp shall be invoked for transition with
2399 * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
2400 * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
2403 lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2404 struct lpfc_iocbq *rspiocb)
2406 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2407 struct lpfc_vport *vport = ndlp->vport;
2408 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2410 struct lpfc_sli *psli;
2411 struct lpfcMboxq *mbox;
2412 unsigned long flags;
2413 uint32_t skip_recovery = 0;
2416 /* we pass cmdiocb to state machine which needs rspiocb as well */
2417 cmdiocb->context_un.rsp_iocb = rspiocb;
2419 irsp = &(rspiocb->iocb);
2420 spin_lock_irq(shost->host_lock);
2421 ndlp->nlp_flag &= ~NLP_LOGO_SND;
2422 spin_unlock_irq(shost->host_lock);
2424 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2425 "LOGO cmpl: status:x%x/x%x did:x%x",
2426 irsp->ulpStatus, irsp->un.ulpWord[4],
2429 /* LOGO completes to NPort <nlp_DID> */
2430 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2431 "0105 LOGO completes to NPort x%x "
2432 "Data: x%x x%x x%x x%x\n",
2433 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2434 irsp->ulpTimeout, vport->num_disc_nodes);
2436 if (lpfc_els_chk_latt(vport)) {
2441 /* Check to see if link went down during discovery */
2442 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
2443 /* NLP_EVT_DEVICE_RM should unregister the RPI
2444 * which should abort all outstanding IOs.
2446 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2452 if (irsp->ulpStatus) {
2453 /* Check for retry */
2454 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2455 /* ELS command is being retried */
2460 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2461 "2756 LOGO failure DID:%06X Status:x%x/x%x\n",
2462 ndlp->nlp_DID, irsp->ulpStatus,
2463 irsp->un.ulpWord[4]);
2464 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2465 if (lpfc_error_lost_link(irsp)) {
2471 /* Call state machine. This will unregister the rpi if needed. */
2472 lpfc_disc_state_machine(vport, ndlp, cmdiocb, NLP_EVT_CMPL_LOGO);
2475 lpfc_els_free_iocb(phba, cmdiocb);
2476 /* If we are in pt2pt mode, we could rcv new S_ID on PLOGI */
2477 if ((vport->fc_flag & FC_PT2PT) &&
2478 !(vport->fc_flag & FC_PT2PT_PLOGI)) {
2479 phba->pport->fc_myDID = 0;
2480 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2482 lpfc_config_link(phba, mbox);
2483 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
2484 mbox->vport = vport;
2485 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) ==
2487 mempool_free(mbox, phba->mbox_mem_pool);
2494 * If the node is a target, the handling attempts to recover the port.
2495 * For any other port type, the rpi is unregistered as an implicit
2498 if ((ndlp->nlp_type & NLP_FCP_TARGET) && (skip_recovery == 0)) {
2499 lpfc_cancel_retry_delay_tmo(vport, ndlp);
2500 spin_lock_irqsave(shost->host_lock, flags);
2501 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2502 spin_unlock_irqrestore(shost->host_lock, flags);
2504 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2505 "3187 LOGO completes to NPort x%x: Start "
2506 "Recovery Data: x%x x%x x%x x%x\n",
2507 ndlp->nlp_DID, irsp->ulpStatus,
2508 irsp->un.ulpWord[4], irsp->ulpTimeout,
2509 vport->num_disc_nodes);
2510 lpfc_disc_start(vport);
2516 * lpfc_issue_els_logo - Issue a logo to an node on a vport
2517 * @vport: pointer to a virtual N_Port data structure.
2518 * @ndlp: pointer to a node-list data structure.
2519 * @retry: number of retries to the command IOCB.
2521 * This routine constructs and issues an ELS Logout (LOGO) iocb command
2522 * to a remote node, referred by an @ndlp on a @vport. It constructs the
2523 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
2524 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
2526 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2527 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2528 * will be stored into the context1 field of the IOCB for the completion
2529 * callback function to the LOGO ELS command.
2532 * 0 - successfully issued logo
2533 * 1 - failed to issue logo
2536 lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2539 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2540 struct lpfc_hba *phba = vport->phba;
2542 struct lpfc_iocbq *elsiocb;
2547 spin_lock_irq(shost->host_lock);
2548 if (ndlp->nlp_flag & NLP_LOGO_SND) {
2549 spin_unlock_irq(shost->host_lock);
2552 spin_unlock_irq(shost->host_lock);
2554 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
2555 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2556 ndlp->nlp_DID, ELS_CMD_LOGO);
2560 icmd = &elsiocb->iocb;
2561 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2562 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
2563 pcmd += sizeof(uint32_t);
2565 /* Fill in LOGO payload */
2566 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
2567 pcmd += sizeof(uint32_t);
2568 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
2570 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2571 "Issue LOGO: did:x%x",
2572 ndlp->nlp_DID, 0, 0);
2575 * If we are issuing a LOGO, we may try to recover the remote NPort
2576 * by issuing a PLOGI later. Even though we issue ELS cmds by the
2577 * VPI, if we have a valid RPI, and that RPI gets unreg'ed while
2578 * that ELS command is in-flight, the HBA returns a IOERR_INVALID_RPI
2579 * for that ELS cmd. To avoid this situation, lets get rid of the
2580 * RPI right now, before any ELS cmds are sent.
2582 spin_lock_irq(shost->host_lock);
2583 ndlp->nlp_flag |= NLP_ISSUE_LOGO;
2584 spin_unlock_irq(shost->host_lock);
2585 if (lpfc_unreg_rpi(vport, ndlp)) {
2586 lpfc_els_free_iocb(phba, elsiocb);
2590 phba->fc_stat.elsXmitLOGO++;
2591 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
2592 spin_lock_irq(shost->host_lock);
2593 ndlp->nlp_flag |= NLP_LOGO_SND;
2594 ndlp->nlp_flag &= ~NLP_ISSUE_LOGO;
2595 spin_unlock_irq(shost->host_lock);
2596 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
2598 if (rc == IOCB_ERROR) {
2599 spin_lock_irq(shost->host_lock);
2600 ndlp->nlp_flag &= ~NLP_LOGO_SND;
2601 spin_unlock_irq(shost->host_lock);
2602 lpfc_els_free_iocb(phba, elsiocb);
2609 * lpfc_cmpl_els_cmd - Completion callback function for generic els command
2610 * @phba: pointer to lpfc hba data structure.
2611 * @cmdiocb: pointer to lpfc command iocb data structure.
2612 * @rspiocb: pointer to lpfc response iocb data structure.
2614 * This routine is a generic completion callback function for ELS commands.
2615 * Specifically, it is the callback function which does not need to perform
2616 * any command specific operations. It is currently used by the ELS command
2617 * issuing routines for the ELS State Change Request (SCR),
2618 * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution
2619 * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than
2620 * certain debug loggings, this callback function simply invokes the
2621 * lpfc_els_chk_latt() routine to check whether link went down during the
2622 * discovery process.
2625 lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2626 struct lpfc_iocbq *rspiocb)
2628 struct lpfc_vport *vport = cmdiocb->vport;
2631 irsp = &rspiocb->iocb;
2633 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2634 "ELS cmd cmpl: status:x%x/x%x did:x%x",
2635 irsp->ulpStatus, irsp->un.ulpWord[4],
2636 irsp->un.elsreq64.remoteID);
2637 /* ELS cmd tag <ulpIoTag> completes */
2638 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2639 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
2640 irsp->ulpIoTag, irsp->ulpStatus,
2641 irsp->un.ulpWord[4], irsp->ulpTimeout);
2642 /* Check to see if link went down during discovery */
2643 lpfc_els_chk_latt(vport);
2644 lpfc_els_free_iocb(phba, cmdiocb);
2649 * lpfc_issue_els_scr - Issue a scr to an node on a vport
2650 * @vport: pointer to a host virtual N_Port data structure.
2651 * @nportid: N_Port identifier to the remote node.
2652 * @retry: number of retries to the command IOCB.
2654 * This routine issues a State Change Request (SCR) to a fabric node
2655 * on a @vport. The remote node @nportid is passed into the function. It
2656 * first search the @vport node list to find the matching ndlp. If no such
2657 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
2658 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
2659 * routine is invoked to send the SCR IOCB.
2661 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2662 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2663 * will be stored into the context1 field of the IOCB for the completion
2664 * callback function to the SCR ELS command.
2667 * 0 - Successfully issued scr command
2668 * 1 - Failed to issue scr command
2671 lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
2673 struct lpfc_hba *phba = vport->phba;
2675 struct lpfc_iocbq *elsiocb;
2676 struct lpfc_sli *psli;
2679 struct lpfc_nodelist *ndlp;
2682 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
2684 ndlp = lpfc_findnode_did(vport, nportid);
2686 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2689 lpfc_nlp_init(vport, ndlp, nportid);
2690 lpfc_enqueue_node(vport, ndlp);
2691 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2692 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2697 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2698 ndlp->nlp_DID, ELS_CMD_SCR);
2701 /* This will trigger the release of the node just
2708 icmd = &elsiocb->iocb;
2709 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2711 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
2712 pcmd += sizeof(uint32_t);
2714 /* For SCR, remainder of payload is SCR parameter page */
2715 memset(pcmd, 0, sizeof(SCR));
2716 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
2718 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2719 "Issue SCR: did:x%x",
2720 ndlp->nlp_DID, 0, 0);
2722 phba->fc_stat.elsXmitSCR++;
2723 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
2724 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2726 /* The additional lpfc_nlp_put will cause the following
2727 * lpfc_els_free_iocb routine to trigger the rlease of
2731 lpfc_els_free_iocb(phba, elsiocb);
2734 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2735 * trigger the release of node.
2742 * lpfc_issue_els_farpr - Issue a farp to an node on a vport
2743 * @vport: pointer to a host virtual N_Port data structure.
2744 * @nportid: N_Port identifier to the remote node.
2745 * @retry: number of retries to the command IOCB.
2747 * This routine issues a Fibre Channel Address Resolution Response
2748 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
2749 * is passed into the function. It first search the @vport node list to find
2750 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
2751 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
2752 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
2754 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2755 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2756 * will be stored into the context1 field of the IOCB for the completion
2757 * callback function to the PARPR ELS command.
2760 * 0 - Successfully issued farpr command
2761 * 1 - Failed to issue farpr command
2764 lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
2766 struct lpfc_hba *phba = vport->phba;
2768 struct lpfc_iocbq *elsiocb;
2769 struct lpfc_sli *psli;
2774 struct lpfc_nodelist *ondlp;
2775 struct lpfc_nodelist *ndlp;
2778 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
2780 ndlp = lpfc_findnode_did(vport, nportid);
2782 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2785 lpfc_nlp_init(vport, ndlp, nportid);
2786 lpfc_enqueue_node(vport, ndlp);
2787 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2788 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2793 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2794 ndlp->nlp_DID, ELS_CMD_RNID);
2796 /* This will trigger the release of the node just
2803 icmd = &elsiocb->iocb;
2804 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2806 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
2807 pcmd += sizeof(uint32_t);
2809 /* Fill in FARPR payload */
2810 fp = (FARP *) (pcmd);
2811 memset(fp, 0, sizeof(FARP));
2812 lp = (uint32_t *) pcmd;
2813 *lp++ = be32_to_cpu(nportid);
2814 *lp++ = be32_to_cpu(vport->fc_myDID);
2816 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
2818 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
2819 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
2820 ondlp = lpfc_findnode_did(vport, nportid);
2821 if (ondlp && NLP_CHK_NODE_ACT(ondlp)) {
2822 memcpy(&fp->OportName, &ondlp->nlp_portname,
2823 sizeof(struct lpfc_name));
2824 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
2825 sizeof(struct lpfc_name));
2828 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2829 "Issue FARPR: did:x%x",
2830 ndlp->nlp_DID, 0, 0);
2832 phba->fc_stat.elsXmitFARPR++;
2833 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
2834 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2836 /* The additional lpfc_nlp_put will cause the following
2837 * lpfc_els_free_iocb routine to trigger the release of
2841 lpfc_els_free_iocb(phba, elsiocb);
2844 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2845 * trigger the release of the node.
2852 * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
2853 * @vport: pointer to a host virtual N_Port data structure.
2854 * @nlp: pointer to a node-list data structure.
2856 * This routine cancels the timer with a delayed IOCB-command retry for
2857 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
2858 * removes the ELS retry event if it presents. In addition, if the
2859 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
2860 * commands are sent for the @vport's nodes that require issuing discovery
2864 lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
2866 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2867 struct lpfc_work_evt *evtp;
2869 if (!(nlp->nlp_flag & NLP_DELAY_TMO))
2871 spin_lock_irq(shost->host_lock);
2872 nlp->nlp_flag &= ~NLP_DELAY_TMO;
2873 spin_unlock_irq(shost->host_lock);
2874 del_timer_sync(&nlp->nlp_delayfunc);
2875 nlp->nlp_last_elscmd = 0;
2876 if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
2877 list_del_init(&nlp->els_retry_evt.evt_listp);
2878 /* Decrement nlp reference count held for the delayed retry */
2879 evtp = &nlp->els_retry_evt;
2880 lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
2882 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
2883 spin_lock_irq(shost->host_lock);
2884 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
2885 spin_unlock_irq(shost->host_lock);
2886 if (vport->num_disc_nodes) {
2887 if (vport->port_state < LPFC_VPORT_READY) {
2888 /* Check if there are more ADISCs to be sent */
2889 lpfc_more_adisc(vport);
2891 /* Check if there are more PLOGIs to be sent */
2892 lpfc_more_plogi(vport);
2893 if (vport->num_disc_nodes == 0) {
2894 spin_lock_irq(shost->host_lock);
2895 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2896 spin_unlock_irq(shost->host_lock);
2897 lpfc_can_disctmo(vport);
2898 lpfc_end_rscn(vport);
2907 * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
2908 * @ptr: holder for the pointer to the timer function associated data (ndlp).
2910 * This routine is invoked by the ndlp delayed-function timer to check
2911 * whether there is any pending ELS retry event(s) with the node. If not, it
2912 * simply returns. Otherwise, if there is at least one ELS delayed event, it
2913 * adds the delayed events to the HBA work list and invokes the
2914 * lpfc_worker_wake_up() routine to wake up worker thread to process the
2915 * event. Note that lpfc_nlp_get() is called before posting the event to
2916 * the work list to hold reference count of ndlp so that it guarantees the
2917 * reference to ndlp will still be available when the worker thread gets
2918 * to the event associated with the ndlp.
2921 lpfc_els_retry_delay(unsigned long ptr)
2923 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr;
2924 struct lpfc_vport *vport = ndlp->vport;
2925 struct lpfc_hba *phba = vport->phba;
2926 unsigned long flags;
2927 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
2929 spin_lock_irqsave(&phba->hbalock, flags);
2930 if (!list_empty(&evtp->evt_listp)) {
2931 spin_unlock_irqrestore(&phba->hbalock, flags);
2935 /* We need to hold the node by incrementing the reference
2936 * count until the queued work is done
2938 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
2939 if (evtp->evt_arg1) {
2940 evtp->evt = LPFC_EVT_ELS_RETRY;
2941 list_add_tail(&evtp->evt_listp, &phba->work_list);
2942 lpfc_worker_wake_up(phba);
2944 spin_unlock_irqrestore(&phba->hbalock, flags);
2949 * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
2950 * @ndlp: pointer to a node-list data structure.
2952 * This routine is the worker-thread handler for processing the @ndlp delayed
2953 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
2954 * the last ELS command from the associated ndlp and invokes the proper ELS
2955 * function according to the delayed ELS command to retry the command.
2958 lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
2960 struct lpfc_vport *vport = ndlp->vport;
2961 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2962 uint32_t cmd, did, retry;
2964 spin_lock_irq(shost->host_lock);
2965 did = ndlp->nlp_DID;
2966 cmd = ndlp->nlp_last_elscmd;
2967 ndlp->nlp_last_elscmd = 0;
2969 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
2970 spin_unlock_irq(shost->host_lock);
2974 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
2975 spin_unlock_irq(shost->host_lock);
2977 * If a discovery event readded nlp_delayfunc after timer
2978 * firing and before processing the timer, cancel the
2981 del_timer_sync(&ndlp->nlp_delayfunc);
2982 retry = ndlp->nlp_retry;
2983 ndlp->nlp_retry = 0;
2987 lpfc_issue_els_flogi(vport, ndlp, retry);
2990 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
2991 ndlp->nlp_prev_state = ndlp->nlp_state;
2992 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2996 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
2997 ndlp->nlp_prev_state = ndlp->nlp_state;
2998 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
3002 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
3003 ndlp->nlp_prev_state = ndlp->nlp_state;
3004 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
3008 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
3009 ndlp->nlp_prev_state = ndlp->nlp_state;
3010 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
3014 if (!(vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI))
3015 lpfc_issue_els_fdisc(vport, ndlp, retry);
3022 * lpfc_els_retry - Make retry decision on an els command iocb
3023 * @phba: pointer to lpfc hba data structure.
3024 * @cmdiocb: pointer to lpfc command iocb data structure.
3025 * @rspiocb: pointer to lpfc response iocb data structure.
3027 * This routine makes a retry decision on an ELS command IOCB, which has
3028 * failed. The following ELS IOCBs use this function for retrying the command
3029 * when previously issued command responsed with error status: FLOGI, PLOGI,
3030 * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
3031 * returned error status, it makes the decision whether a retry shall be
3032 * issued for the command, and whether a retry shall be made immediately or
3033 * delayed. In the former case, the corresponding ELS command issuing-function
3034 * is called to retry the command. In the later case, the ELS command shall
3035 * be posted to the ndlp delayed event and delayed function timer set to the
3036 * ndlp for the delayed command issusing.
3039 * 0 - No retry of els command is made
3040 * 1 - Immediate or delayed retry of els command is made
3043 lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3044 struct lpfc_iocbq *rspiocb)
3046 struct lpfc_vport *vport = cmdiocb->vport;
3047 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3048 IOCB_t *irsp = &rspiocb->iocb;
3049 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3050 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3053 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
3059 /* Note: context2 may be 0 for internal driver abort
3060 * of delays ELS command.
3063 if (pcmd && pcmd->virt) {
3064 elscmd = (uint32_t *) (pcmd->virt);
3068 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
3069 did = ndlp->nlp_DID;
3071 /* We should only hit this case for retrying PLOGI */
3072 did = irsp->un.elsreq64.remoteID;
3073 ndlp = lpfc_findnode_did(vport, did);
3074 if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp))
3075 && (cmd != ELS_CMD_PLOGI))
3079 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3080 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
3081 *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
3083 switch (irsp->ulpStatus) {
3084 case IOSTAT_FCP_RSP_ERROR:
3086 case IOSTAT_REMOTE_STOP:
3087 if (phba->sli_rev == LPFC_SLI_REV4) {
3088 /* This IO was aborted by the target, we don't
3089 * know the rxid and because we did not send the
3090 * ABTS we cannot generate and RRQ.
3092 lpfc_set_rrq_active(phba, ndlp,
3093 cmdiocb->sli4_lxritag, 0, 0);
3096 case IOSTAT_LOCAL_REJECT:
3097 switch ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK)) {
3098 case IOERR_LOOP_OPEN_FAILURE:
3099 if (cmd == ELS_CMD_FLOGI) {
3100 if (PCI_DEVICE_ID_HORNET ==
3101 phba->pcidev->device) {
3102 phba->fc_topology = LPFC_TOPOLOGY_LOOP;
3103 phba->pport->fc_myDID = 0;
3104 phba->alpa_map[0] = 0;
3105 phba->alpa_map[1] = 0;
3108 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
3113 case IOERR_ILLEGAL_COMMAND:
3114 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3115 "0124 Retry illegal cmd x%x "
3116 "retry:x%x delay:x%x\n",
3117 cmd, cmdiocb->retry, delay);
3119 /* All command's retry policy */
3121 if (cmdiocb->retry > 2)
3125 case IOERR_NO_RESOURCES:
3126 logerr = 1; /* HBA out of resources */
3128 if (cmdiocb->retry > 100)
3133 case IOERR_ILLEGAL_FRAME:
3138 case IOERR_SEQUENCE_TIMEOUT:
3139 case IOERR_INVALID_RPI:
3140 if (cmd == ELS_CMD_PLOGI &&
3141 did == NameServer_DID) {
3142 /* Continue forever if plogi to */
3143 /* the nameserver fails */
3152 case IOSTAT_NPORT_RJT:
3153 case IOSTAT_FABRIC_RJT:
3154 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
3160 case IOSTAT_NPORT_BSY:
3161 case IOSTAT_FABRIC_BSY:
3162 logerr = 1; /* Fabric / Remote NPort out of resources */
3167 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
3168 /* Added for Vendor specifc support
3169 * Just keep retrying for these Rsn / Exp codes
3171 switch (stat.un.b.lsRjtRsnCode) {
3172 case LSRJT_UNABLE_TPC:
3173 if (stat.un.b.lsRjtRsnCodeExp ==
3174 LSEXP_CMD_IN_PROGRESS) {
3175 if (cmd == ELS_CMD_PLOGI) {
3182 if (stat.un.b.lsRjtRsnCodeExp ==
3183 LSEXP_CANT_GIVE_DATA) {
3184 if (cmd == ELS_CMD_PLOGI) {
3191 if ((cmd == ELS_CMD_PLOGI) ||
3192 (cmd == ELS_CMD_PRLI)) {
3194 maxretry = lpfc_max_els_tries + 1;
3198 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
3199 (cmd == ELS_CMD_FDISC) &&
3200 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
3201 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3202 "0125 FDISC Failed (x%x). "
3203 "Fabric out of resources\n",
3204 stat.un.lsRjtError);
3205 lpfc_vport_set_state(vport,
3206 FC_VPORT_NO_FABRIC_RSCS);
3210 case LSRJT_LOGICAL_BSY:
3211 if ((cmd == ELS_CMD_PLOGI) ||
3212 (cmd == ELS_CMD_PRLI)) {
3215 } else if (cmd == ELS_CMD_FDISC) {
3216 /* FDISC retry policy */
3218 if (cmdiocb->retry >= 32)
3224 case LSRJT_LOGICAL_ERR:
3225 /* There are some cases where switches return this
3226 * error when they are not ready and should be returning
3227 * Logical Busy. We should delay every time.
3229 if (cmd == ELS_CMD_FDISC &&
3230 stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
3236 case LSRJT_PROTOCOL_ERR:
3237 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
3238 (cmd == ELS_CMD_FDISC) &&
3239 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
3240 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
3242 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3243 "0122 FDISC Failed (x%x). "
3244 "Fabric Detected Bad WWN\n",
3245 stat.un.lsRjtError);
3246 lpfc_vport_set_state(vport,
3247 FC_VPORT_FABRIC_REJ_WWN);
3253 case IOSTAT_INTERMED_RSP:
3261 if (did == FDMI_DID)
3264 if ((cmd == ELS_CMD_FLOGI) &&
3265 (phba->fc_topology != LPFC_TOPOLOGY_LOOP) &&
3266 !lpfc_error_lost_link(irsp)) {
3267 /* FLOGI retry policy */
3269 /* retry FLOGI forever */
3271 if (cmdiocb->retry >= 100)
3273 else if (cmdiocb->retry >= 32)
3275 } else if ((cmd == ELS_CMD_FDISC) && !lpfc_error_lost_link(irsp)) {
3276 /* retry FDISCs every second up to devloss */
3278 maxretry = vport->cfg_devloss_tmo;
3283 if (maxretry && (cmdiocb->retry >= maxretry)) {
3284 phba->fc_stat.elsRetryExceeded++;
3288 if ((vport->load_flag & FC_UNLOADING) != 0)
3292 if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) {
3293 /* Stop retrying PLOGI and FDISC if in FCF discovery */
3294 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
3295 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3296 "2849 Stop retry ELS command "
3297 "x%x to remote NPORT x%x, "
3298 "Data: x%x x%x\n", cmd, did,
3299 cmdiocb->retry, delay);
3304 /* Retry ELS command <elsCmd> to remote NPORT <did> */
3305 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3306 "0107 Retry ELS command x%x to remote "
3307 "NPORT x%x Data: x%x x%x\n",
3308 cmd, did, cmdiocb->retry, delay);
3310 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
3311 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
3312 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
3313 IOERR_NO_RESOURCES))) {
3314 /* Don't reset timer for no resources */
3316 /* If discovery / RSCN timer is running, reset it */
3317 if (timer_pending(&vport->fc_disctmo) ||
3318 (vport->fc_flag & FC_RSCN_MODE))
3319 lpfc_set_disctmo(vport);
3322 phba->fc_stat.elsXmitRetry++;
3323 if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) {
3324 phba->fc_stat.elsDelayRetry++;
3325 ndlp->nlp_retry = cmdiocb->retry;
3327 /* delay is specified in milliseconds */
3328 mod_timer(&ndlp->nlp_delayfunc,
3329 jiffies + msecs_to_jiffies(delay));
3330 spin_lock_irq(shost->host_lock);
3331 ndlp->nlp_flag |= NLP_DELAY_TMO;
3332 spin_unlock_irq(shost->host_lock);
3334 ndlp->nlp_prev_state = ndlp->nlp_state;
3335 if (cmd == ELS_CMD_PRLI)
3336 lpfc_nlp_set_state(vport, ndlp,
3337 NLP_STE_PRLI_ISSUE);
3339 lpfc_nlp_set_state(vport, ndlp,
3341 ndlp->nlp_last_elscmd = cmd;
3347 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
3350 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
3353 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
3354 ndlp->nlp_prev_state = ndlp->nlp_state;
3355 lpfc_nlp_set_state(vport, ndlp,
3356 NLP_STE_PLOGI_ISSUE);
3358 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
3361 ndlp->nlp_prev_state = ndlp->nlp_state;
3362 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
3363 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
3366 ndlp->nlp_prev_state = ndlp->nlp_state;
3367 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
3368 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
3371 ndlp->nlp_prev_state = ndlp->nlp_state;
3372 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
3373 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
3377 /* No retry ELS command <elsCmd> to remote NPORT <did> */
3379 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3380 "0137 No retry ELS command x%x to remote "
3381 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
3382 cmd, did, irsp->ulpStatus,
3383 irsp->un.ulpWord[4]);
3386 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3387 "0108 No retry ELS command x%x to remote "
3388 "NPORT x%x Retried:%d Error:x%x/%x\n",
3389 cmd, did, cmdiocb->retry, irsp->ulpStatus,
3390 irsp->un.ulpWord[4]);
3396 * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
3397 * @phba: pointer to lpfc hba data structure.
3398 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
3400 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
3401 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
3402 * checks to see whether there is a lpfc DMA buffer associated with the
3403 * response of the command IOCB. If so, it will be released before releasing
3404 * the lpfc DMA buffer associated with the IOCB itself.
3407 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3410 lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
3412 struct lpfc_dmabuf *buf_ptr;
3414 /* Free the response before processing the command. */
3415 if (!list_empty(&buf_ptr1->list)) {
3416 list_remove_head(&buf_ptr1->list, buf_ptr,
3419 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3422 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
3428 * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
3429 * @phba: pointer to lpfc hba data structure.
3430 * @buf_ptr: pointer to the lpfc dma buffer data structure.
3432 * This routine releases the lpfc Direct Memory Access (DMA) buffer
3433 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
3437 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3440 lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
3442 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3448 * lpfc_els_free_iocb - Free a command iocb and its associated resources
3449 * @phba: pointer to lpfc hba data structure.
3450 * @elsiocb: pointer to lpfc els command iocb data structure.
3452 * This routine frees a command IOCB and its associated resources. The
3453 * command IOCB data structure contains the reference to various associated
3454 * resources, these fields must be set to NULL if the associated reference
3456 * context1 - reference to ndlp
3457 * context2 - reference to cmd
3458 * context2->next - reference to rsp
3459 * context3 - reference to bpl
3461 * It first properly decrements the reference count held on ndlp for the
3462 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
3463 * set, it invokes the lpfc_els_free_data() routine to release the Direct
3464 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
3465 * adds the DMA buffer the @phba data structure for the delayed release.
3466 * If reference to the Buffer Pointer List (BPL) is present, the
3467 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
3468 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
3469 * invoked to release the IOCB data structure back to @phba IOCBQ list.
3472 * 0 - Success (currently, always return 0)
3475 lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
3477 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
3478 struct lpfc_nodelist *ndlp;
3480 ndlp = (struct lpfc_nodelist *)elsiocb->context1;
3482 if (ndlp->nlp_flag & NLP_DEFER_RM) {
3485 /* If the ndlp is not being used by another discovery
3488 if (!lpfc_nlp_not_used(ndlp)) {
3489 /* If ndlp is being used by another discovery
3490 * thread, just clear NLP_DEFER_RM
3492 ndlp->nlp_flag &= ~NLP_DEFER_RM;
3497 elsiocb->context1 = NULL;
3499 /* context2 = cmd, context2->next = rsp, context3 = bpl */
3500 if (elsiocb->context2) {
3501 if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
3502 /* Firmware could still be in progress of DMAing
3503 * payload, so don't free data buffer till after
3506 elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
3507 buf_ptr = elsiocb->context2;
3508 elsiocb->context2 = NULL;
3511 spin_lock_irq(&phba->hbalock);
3512 if (!list_empty(&buf_ptr->list)) {
3513 list_remove_head(&buf_ptr->list,
3514 buf_ptr1, struct lpfc_dmabuf,
3516 INIT_LIST_HEAD(&buf_ptr1->list);
3517 list_add_tail(&buf_ptr1->list,
3521 INIT_LIST_HEAD(&buf_ptr->list);
3522 list_add_tail(&buf_ptr->list, &phba->elsbuf);
3524 spin_unlock_irq(&phba->hbalock);
3527 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
3528 lpfc_els_free_data(phba, buf_ptr1);
3532 if (elsiocb->context3) {
3533 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
3534 lpfc_els_free_bpl(phba, buf_ptr);
3536 lpfc_sli_release_iocbq(phba, elsiocb);
3541 * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
3542 * @phba: pointer to lpfc hba data structure.
3543 * @cmdiocb: pointer to lpfc command iocb data structure.
3544 * @rspiocb: pointer to lpfc response iocb data structure.
3546 * This routine is the completion callback function to the Logout (LOGO)
3547 * Accept (ACC) Response ELS command. This routine is invoked to indicate
3548 * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
3549 * release the ndlp if it has the last reference remaining (reference count
3550 * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
3551 * field to NULL to inform the following lpfc_els_free_iocb() routine no
3552 * ndlp reference count needs to be decremented. Otherwise, the ndlp
3553 * reference use-count shall be decremented by the lpfc_els_free_iocb()
3554 * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
3555 * IOCB data structure.
3558 lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3559 struct lpfc_iocbq *rspiocb)
3561 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3562 struct lpfc_vport *vport = cmdiocb->vport;
3565 irsp = &rspiocb->iocb;
3566 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3567 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
3568 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
3569 /* ACC to LOGO completes to NPort <nlp_DID> */
3570 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3571 "0109 ACC to LOGO completes to NPort x%x "
3572 "Data: x%x x%x x%x\n",
3573 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3576 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
3577 /* NPort Recovery mode or node is just allocated */
3578 if (!lpfc_nlp_not_used(ndlp)) {
3579 /* If the ndlp is being used by another discovery
3580 * thread, just unregister the RPI.
3582 lpfc_unreg_rpi(vport, ndlp);
3584 /* Indicate the node has already released, should
3585 * not reference to it from within lpfc_els_free_iocb.
3587 cmdiocb->context1 = NULL;
3592 * The driver received a LOGO from the rport and has ACK'd it.
3593 * At this point, the driver is done so release the IOCB
3595 lpfc_els_free_iocb(phba, cmdiocb);
3598 * Remove the ndlp reference if it's a fabric node that has
3599 * sent us an unsolicted LOGO.
3601 if (ndlp->nlp_type & NLP_FABRIC)
3608 * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
3609 * @phba: pointer to lpfc hba data structure.
3610 * @pmb: pointer to the driver internal queue element for mailbox command.
3612 * This routine is the completion callback function for unregister default
3613 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
3614 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
3615 * decrements the ndlp reference count held for this completion callback
3616 * function. After that, it invokes the lpfc_nlp_not_used() to check
3617 * whether there is only one reference left on the ndlp. If so, it will
3618 * perform one more decrement and trigger the release of the ndlp.
3621 lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3623 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
3624 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
3626 pmb->context1 = NULL;
3627 pmb->context2 = NULL;
3629 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3631 mempool_free(pmb, phba->mbox_mem_pool);
3633 if (NLP_CHK_NODE_ACT(ndlp)) {
3635 /* This is the end of the default RPI cleanup logic for
3636 * this ndlp. If no other discovery threads are using
3637 * this ndlp, free all resources associated with it.
3639 lpfc_nlp_not_used(ndlp);
3641 lpfc_drop_node(ndlp->vport, ndlp);
3649 * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
3650 * @phba: pointer to lpfc hba data structure.
3651 * @cmdiocb: pointer to lpfc command iocb data structure.
3652 * @rspiocb: pointer to lpfc response iocb data structure.
3654 * This routine is the completion callback function for ELS Response IOCB
3655 * command. In normal case, this callback function just properly sets the
3656 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
3657 * field in the command IOCB is not NULL, the referred mailbox command will
3658 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
3659 * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
3660 * link down event occurred during the discovery, the lpfc_nlp_not_used()
3661 * routine shall be invoked trying to release the ndlp if no other threads
3662 * are currently referring it.
3665 lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3666 struct lpfc_iocbq *rspiocb)
3668 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3669 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
3670 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
3673 LPFC_MBOXQ_t *mbox = NULL;
3674 struct lpfc_dmabuf *mp = NULL;
3675 uint32_t ls_rjt = 0;
3677 irsp = &rspiocb->iocb;
3679 if (cmdiocb->context_un.mbox)
3680 mbox = cmdiocb->context_un.mbox;
3682 /* First determine if this is a LS_RJT cmpl. Note, this callback
3683 * function can have cmdiocb->contest1 (ndlp) field set to NULL.
3685 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
3686 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3687 (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) {
3688 /* A LS_RJT associated with Default RPI cleanup has its own
3689 * separate code path.
3691 if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
3695 /* Check to see if link went down during discovery */
3696 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) {
3698 mp = (struct lpfc_dmabuf *) mbox->context1;
3700 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3703 mempool_free(mbox, phba->mbox_mem_pool);
3705 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3706 (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
3707 if (lpfc_nlp_not_used(ndlp)) {
3709 /* Indicate the node has already released,
3710 * should not reference to it from within
3711 * the routine lpfc_els_free_iocb.
3713 cmdiocb->context1 = NULL;
3718 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3719 "ELS rsp cmpl: status:x%x/x%x did:x%x",
3720 irsp->ulpStatus, irsp->un.ulpWord[4],
3721 cmdiocb->iocb.un.elsreq64.remoteID);
3722 /* ELS response tag <ulpIoTag> completes */
3723 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3724 "0110 ELS response tag x%x completes "
3725 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
3726 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
3727 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
3728 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3731 if ((rspiocb->iocb.ulpStatus == 0)
3732 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
3733 lpfc_unreg_rpi(vport, ndlp);
3734 /* Increment reference count to ndlp to hold the
3735 * reference to ndlp for the callback function.
3737 mbox->context2 = lpfc_nlp_get(ndlp);
3738 mbox->vport = vport;
3739 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
3740 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
3741 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
3744 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
3745 ndlp->nlp_prev_state = ndlp->nlp_state;
3746 lpfc_nlp_set_state(vport, ndlp,
3747 NLP_STE_REG_LOGIN_ISSUE);
3749 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
3750 != MBX_NOT_FINISHED)
3753 /* Decrement the ndlp reference count we
3754 * set for this failed mailbox command.
3758 /* ELS rsp: Cannot issue reg_login for <NPortid> */
3759 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3760 "0138 ELS rsp: Cannot issue reg_login for x%x "
3761 "Data: x%x x%x x%x\n",
3762 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3765 if (lpfc_nlp_not_used(ndlp)) {
3767 /* Indicate node has already been released,
3768 * should not reference to it from within
3769 * the routine lpfc_els_free_iocb.
3771 cmdiocb->context1 = NULL;
3774 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
3775 if (!lpfc_error_lost_link(irsp) &&
3776 ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
3777 if (lpfc_nlp_not_used(ndlp)) {
3779 /* Indicate node has already been
3780 * released, should not reference
3781 * to it from within the routine
3782 * lpfc_els_free_iocb.
3784 cmdiocb->context1 = NULL;
3788 mp = (struct lpfc_dmabuf *) mbox->context1;
3790 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3793 mempool_free(mbox, phba->mbox_mem_pool);
3796 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
3797 spin_lock_irq(shost->host_lock);
3798 ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI);
3799 spin_unlock_irq(shost->host_lock);
3801 /* If the node is not being used by another discovery thread,
3802 * and we are sending a reject, we are done with it.
3803 * Release driver reference count here and free associated
3807 if (lpfc_nlp_not_used(ndlp))
3808 /* Indicate node has already been released,
3809 * should not reference to it from within
3810 * the routine lpfc_els_free_iocb.
3812 cmdiocb->context1 = NULL;
3815 lpfc_els_free_iocb(phba, cmdiocb);
3820 * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
3821 * @vport: pointer to a host virtual N_Port data structure.
3822 * @flag: the els command code to be accepted.
3823 * @oldiocb: pointer to the original lpfc command iocb data structure.
3824 * @ndlp: pointer to a node-list data structure.
3825 * @mbox: pointer to the driver internal queue element for mailbox command.
3827 * This routine prepares and issues an Accept (ACC) response IOCB
3828 * command. It uses the @flag to properly set up the IOCB field for the
3829 * specific ACC response command to be issued and invokes the
3830 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
3831 * @mbox pointer is passed in, it will be put into the context_un.mbox
3832 * field of the IOCB for the completion callback function to issue the
3833 * mailbox command to the HBA later when callback is invoked.
3835 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3836 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3837 * will be stored into the context1 field of the IOCB for the completion
3838 * callback function to the corresponding response ELS IOCB command.
3841 * 0 - Successfully issued acc response
3842 * 1 - Failed to issue acc response
3845 lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
3846 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
3849 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3850 struct lpfc_hba *phba = vport->phba;
3853 struct lpfc_iocbq *elsiocb;
3854 struct lpfc_sli *psli;
3858 ELS_PKT *els_pkt_ptr;
3861 oldcmd = &oldiocb->iocb;
3865 cmdsize = sizeof(uint32_t);
3866 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3867 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
3869 spin_lock_irq(shost->host_lock);
3870 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
3871 spin_unlock_irq(shost->host_lock);
3875 icmd = &elsiocb->iocb;
3876 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
3877 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
3878 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3879 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
3880 pcmd += sizeof(uint32_t);
3882 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3883 "Issue ACC: did:x%x flg:x%x",
3884 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3887 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
3888 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3889 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
3893 icmd = &elsiocb->iocb;
3894 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
3895 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
3896 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3899 elsiocb->context_un.mbox = mbox;
3901 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
3902 pcmd += sizeof(uint32_t);
3903 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
3905 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3906 "Issue ACC PLOGI: did:x%x flg:x%x",
3907 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3910 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
3911 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3912 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
3916 icmd = &elsiocb->iocb;
3917 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
3918 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
3919 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3921 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
3922 sizeof(uint32_t) + sizeof(PRLO));
3923 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
3924 els_pkt_ptr = (ELS_PKT *) pcmd;
3925 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
3927 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3928 "Issue ACC PRLO: did:x%x flg:x%x",
3929 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3934 /* Xmit ELS ACC response tag <ulpIoTag> */
3935 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3936 "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
3937 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x "
3939 elsiocb->iotag, elsiocb->iocb.ulpContext,
3940 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3941 ndlp->nlp_rpi, vport->fc_flag);
3942 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
3943 spin_lock_irq(shost->host_lock);
3944 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
3945 spin_unlock_irq(shost->host_lock);
3946 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
3948 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
3951 phba->fc_stat.elsXmitACC++;
3952 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
3953 if (rc == IOCB_ERROR) {
3954 lpfc_els_free_iocb(phba, elsiocb);
3961 * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command
3962 * @vport: pointer to a virtual N_Port data structure.
3964 * @oldiocb: pointer to the original lpfc command iocb data structure.
3965 * @ndlp: pointer to a node-list data structure.
3966 * @mbox: pointer to the driver internal queue element for mailbox command.
3968 * This routine prepares and issue an Reject (RJT) response IOCB
3969 * command. If a @mbox pointer is passed in, it will be put into the
3970 * context_un.mbox field of the IOCB for the completion callback function
3971 * to issue to the HBA later.
3973 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3974 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3975 * will be stored into the context1 field of the IOCB for the completion
3976 * callback function to the reject response ELS IOCB command.
3979 * 0 - Successfully issued reject response
3980 * 1 - Failed to issue reject response
3983 lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
3984 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
3987 struct lpfc_hba *phba = vport->phba;
3990 struct lpfc_iocbq *elsiocb;
3991 struct lpfc_sli *psli;
3997 cmdsize = 2 * sizeof(uint32_t);
3998 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3999 ndlp->nlp_DID, ELS_CMD_LS_RJT);
4003 icmd = &elsiocb->iocb;
4004 oldcmd = &oldiocb->iocb;
4005 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4006 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4007 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4009 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
4010 pcmd += sizeof(uint32_t);
4011 *((uint32_t *) (pcmd)) = rejectError;
4014 elsiocb->context_un.mbox = mbox;
4016 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
4017 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4018 "0129 Xmit ELS RJT x%x response tag x%x "
4019 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
4021 rejectError, elsiocb->iotag,
4022 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
4023 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
4024 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4025 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
4026 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
4028 phba->fc_stat.elsXmitLSRJT++;
4029 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4030 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4032 if (rc == IOCB_ERROR) {
4033 lpfc_els_free_iocb(phba, elsiocb);
4040 * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
4041 * @vport: pointer to a virtual N_Port data structure.
4042 * @oldiocb: pointer to the original lpfc command iocb data structure.
4043 * @ndlp: pointer to a node-list data structure.
4045 * This routine prepares and issues an Accept (ACC) response to Address
4046 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
4047 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
4049 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4050 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4051 * will be stored into the context1 field of the IOCB for the completion
4052 * callback function to the ADISC Accept response ELS IOCB command.
4055 * 0 - Successfully issued acc adisc response
4056 * 1 - Failed to issue adisc acc response
4059 lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
4060 struct lpfc_nodelist *ndlp)
4062 struct lpfc_hba *phba = vport->phba;
4064 IOCB_t *icmd, *oldcmd;
4065 struct lpfc_iocbq *elsiocb;
4070 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
4071 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4072 ndlp->nlp_DID, ELS_CMD_ACC);
4076 icmd = &elsiocb->iocb;
4077 oldcmd = &oldiocb->iocb;
4078 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4079 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4081 /* Xmit ADISC ACC response tag <ulpIoTag> */
4082 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4083 "0130 Xmit ADISC ACC response iotag x%x xri: "
4084 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
4085 elsiocb->iotag, elsiocb->iocb.ulpContext,
4086 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4088 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4090 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4091 pcmd += sizeof(uint32_t);
4093 ap = (ADISC *) (pcmd);
4094 ap->hardAL_PA = phba->fc_pref_ALPA;
4095 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
4096 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
4097 ap->DID = be32_to_cpu(vport->fc_myDID);
4099 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4100 "Issue ACC ADISC: did:x%x flg:x%x",
4101 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4103 phba->fc_stat.elsXmitACC++;
4104 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4105 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4106 if (rc == IOCB_ERROR) {
4107 lpfc_els_free_iocb(phba, elsiocb);
4114 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
4115 * @vport: pointer to a virtual N_Port data structure.
4116 * @oldiocb: pointer to the original lpfc command iocb data structure.
4117 * @ndlp: pointer to a node-list data structure.
4119 * This routine prepares and issues an Accept (ACC) response to Process
4120 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
4121 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
4123 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4124 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4125 * will be stored into the context1 field of the IOCB for the completion
4126 * callback function to the PRLI Accept response ELS IOCB command.
4129 * 0 - Successfully issued acc prli response
4130 * 1 - Failed to issue acc prli response
4133 lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
4134 struct lpfc_nodelist *ndlp)
4136 struct lpfc_hba *phba = vport->phba;
4141 struct lpfc_iocbq *elsiocb;
4142 struct lpfc_sli *psli;
4149 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
4150 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4151 ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)));
4155 icmd = &elsiocb->iocb;
4156 oldcmd = &oldiocb->iocb;
4157 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4158 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4160 /* Xmit PRLI ACC response tag <ulpIoTag> */
4161 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4162 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
4163 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
4164 elsiocb->iotag, elsiocb->iocb.ulpContext,
4165 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4167 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4169 *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
4170 pcmd += sizeof(uint32_t);
4172 /* For PRLI, remainder of payload is PRLI parameter page */
4173 memset(pcmd, 0, sizeof(PRLI));
4175 npr = (PRLI *) pcmd;
4178 * If the remote port is a target and our firmware version is 3.20 or
4179 * later, set the following bits for FC-TAPE support.
4181 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
4182 (vpd->rev.feaLevelHigh >= 0x02)) {
4183 npr->ConfmComplAllowed = 1;
4185 npr->TaskRetryIdReq = 1;
4188 npr->acceptRspCode = PRLI_REQ_EXECUTED;
4189 npr->estabImagePair = 1;
4190 npr->readXferRdyDis = 1;
4191 npr->ConfmComplAllowed = 1;
4193 npr->prliType = PRLI_FCP_TYPE;
4194 npr->initiatorFunc = 1;
4196 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4197 "Issue ACC PRLI: did:x%x flg:x%x",
4198 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4200 phba->fc_stat.elsXmitACC++;
4201 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4203 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4204 if (rc == IOCB_ERROR) {
4205 lpfc_els_free_iocb(phba, elsiocb);
4212 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
4213 * @vport: pointer to a virtual N_Port data structure.
4214 * @format: rnid command format.
4215 * @oldiocb: pointer to the original lpfc command iocb data structure.
4216 * @ndlp: pointer to a node-list data structure.
4218 * This routine issues a Request Node Identification Data (RNID) Accept
4219 * (ACC) response. It constructs the RNID ACC response command according to
4220 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
4221 * issue the response. Note that this command does not need to hold the ndlp
4222 * reference count for the callback. So, the ndlp reference count taken by
4223 * the lpfc_prep_els_iocb() routine is put back and the context1 field of
4224 * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
4225 * there is no ndlp reference available.
4227 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4228 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4229 * will be stored into the context1 field of the IOCB for the completion
4230 * callback function. However, for the RNID Accept Response ELS command,
4231 * this is undone later by this routine after the IOCB is allocated.
4234 * 0 - Successfully issued acc rnid response
4235 * 1 - Failed to issue acc rnid response
4238 lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
4239 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
4241 struct lpfc_hba *phba = vport->phba;
4243 IOCB_t *icmd, *oldcmd;
4244 struct lpfc_iocbq *elsiocb;
4245 struct lpfc_sli *psli;
4251 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
4252 + (2 * sizeof(struct lpfc_name));
4254 cmdsize += sizeof(RNID_TOP_DISC);
4256 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4257 ndlp->nlp_DID, ELS_CMD_ACC);
4261 icmd = &elsiocb->iocb;
4262 oldcmd = &oldiocb->iocb;
4263 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4264 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4266 /* Xmit RNID ACC response tag <ulpIoTag> */
4267 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4268 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
4269 elsiocb->iotag, elsiocb->iocb.ulpContext);
4270 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4271 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4272 pcmd += sizeof(uint32_t);
4274 memset(pcmd, 0, sizeof(RNID));
4275 rn = (RNID *) (pcmd);
4276 rn->Format = format;
4277 rn->CommonLen = (2 * sizeof(struct lpfc_name));
4278 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
4279 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
4282 rn->SpecificLen = 0;
4284 case RNID_TOPOLOGY_DISC:
4285 rn->SpecificLen = sizeof(RNID_TOP_DISC);
4286 memcpy(&rn->un.topologyDisc.portName,
4287 &vport->fc_portname, sizeof(struct lpfc_name));
4288 rn->un.topologyDisc.unitType = RNID_HBA;
4289 rn->un.topologyDisc.physPort = 0;
4290 rn->un.topologyDisc.attachedNodes = 0;
4294 rn->SpecificLen = 0;
4298 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4299 "Issue ACC RNID: did:x%x flg:x%x",
4300 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4302 phba->fc_stat.elsXmitACC++;
4303 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4305 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4306 if (rc == IOCB_ERROR) {
4307 lpfc_els_free_iocb(phba, elsiocb);
4314 * lpfc_els_clear_rrq - Clear the rq that this rrq describes.
4315 * @vport: pointer to a virtual N_Port data structure.
4316 * @iocb: pointer to the lpfc command iocb data structure.
4317 * @ndlp: pointer to a node-list data structure.
4322 lpfc_els_clear_rrq(struct lpfc_vport *vport,
4323 struct lpfc_iocbq *iocb, struct lpfc_nodelist *ndlp)
4325 struct lpfc_hba *phba = vport->phba;
4330 struct lpfc_node_rrq *prrq;
4333 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) iocb->context2)->virt);
4334 pcmd += sizeof(uint32_t);
4335 rrq = (struct RRQ *)pcmd;
4336 rrq->rrq_exchg = be32_to_cpu(rrq->rrq_exchg);
4337 rxid = bf_get(rrq_rxid, rrq);
4339 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4340 "2883 Clear RRQ for SID:x%x OXID:x%x RXID:x%x"
4342 be32_to_cpu(bf_get(rrq_did, rrq)),
4343 bf_get(rrq_oxid, rrq),
4345 iocb->iotag, iocb->iocb.ulpContext);
4347 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4348 "Clear RRQ: did:x%x flg:x%x exchg:x%.08x",
4349 ndlp->nlp_DID, ndlp->nlp_flag, rrq->rrq_exchg);
4350 if (vport->fc_myDID == be32_to_cpu(bf_get(rrq_did, rrq)))
4351 xri = bf_get(rrq_oxid, rrq);
4354 prrq = lpfc_get_active_rrq(vport, xri, ndlp->nlp_DID);
4356 lpfc_clr_rrq_active(phba, xri, prrq);
4361 * lpfc_els_rsp_echo_acc - Issue echo acc response
4362 * @vport: pointer to a virtual N_Port data structure.
4363 * @data: pointer to echo data to return in the accept.
4364 * @oldiocb: pointer to the original lpfc command iocb data structure.
4365 * @ndlp: pointer to a node-list data structure.
4368 * 0 - Successfully issued acc echo response
4369 * 1 - Failed to issue acc echo response
4372 lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data,
4373 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
4375 struct lpfc_hba *phba = vport->phba;
4376 struct lpfc_iocbq *elsiocb;
4377 struct lpfc_sli *psli;
4383 cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len;
4385 /* The accumulated length can exceed the BPL_SIZE. For
4386 * now, use this as the limit
4388 if (cmdsize > LPFC_BPL_SIZE)
4389 cmdsize = LPFC_BPL_SIZE;
4390 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4391 ndlp->nlp_DID, ELS_CMD_ACC);
4395 elsiocb->iocb.ulpContext = oldiocb->iocb.ulpContext; /* Xri / rx_id */
4396 elsiocb->iocb.unsli3.rcvsli3.ox_id = oldiocb->iocb.unsli3.rcvsli3.ox_id;
4398 /* Xmit ECHO ACC response tag <ulpIoTag> */
4399 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4400 "2876 Xmit ECHO ACC response tag x%x xri x%x\n",
4401 elsiocb->iotag, elsiocb->iocb.ulpContext);
4402 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4403 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4404 pcmd += sizeof(uint32_t);
4405 memcpy(pcmd, data, cmdsize - sizeof(uint32_t));
4407 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4408 "Issue ACC ECHO: did:x%x flg:x%x",
4409 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4411 phba->fc_stat.elsXmitACC++;
4412 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4414 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4415 if (rc == IOCB_ERROR) {
4416 lpfc_els_free_iocb(phba, elsiocb);
4423 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
4424 * @vport: pointer to a host virtual N_Port data structure.
4426 * This routine issues Address Discover (ADISC) ELS commands to those
4427 * N_Ports which are in node port recovery state and ADISC has not been issued
4428 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
4429 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
4430 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
4431 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
4432 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
4433 * IOCBs quit for later pick up. On the other hand, after walking through
4434 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
4435 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
4436 * no more ADISC need to be sent.
4439 * The number of N_Ports with adisc issued.
4442 lpfc_els_disc_adisc(struct lpfc_vport *vport)
4444 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4445 struct lpfc_nodelist *ndlp, *next_ndlp;
4448 /* go thru NPR nodes and issue any remaining ELS ADISCs */
4449 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
4450 if (!NLP_CHK_NODE_ACT(ndlp))
4452 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
4453 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
4454 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
4455 spin_lock_irq(shost->host_lock);
4456 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
4457 spin_unlock_irq(shost->host_lock);
4458 ndlp->nlp_prev_state = ndlp->nlp_state;
4459 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
4460 lpfc_issue_els_adisc(vport, ndlp, 0);
4462 vport->num_disc_nodes++;
4463 if (vport->num_disc_nodes >=
4464 vport->cfg_discovery_threads) {
4465 spin_lock_irq(shost->host_lock);
4466 vport->fc_flag |= FC_NLP_MORE;
4467 spin_unlock_irq(shost->host_lock);
4472 if (sentadisc == 0) {
4473 spin_lock_irq(shost->host_lock);
4474 vport->fc_flag &= ~FC_NLP_MORE;
4475 spin_unlock_irq(shost->host_lock);
4481 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
4482 * @vport: pointer to a host virtual N_Port data structure.
4484 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
4485 * which are in node port recovery state, with a @vport. Each time an ELS
4486 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
4487 * the per @vport number of discover count (num_disc_nodes) shall be
4488 * incremented. If the num_disc_nodes reaches a pre-configured threshold
4489 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
4490 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
4491 * later pick up. On the other hand, after walking through all the ndlps with
4492 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
4493 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
4494 * PLOGI need to be sent.
4497 * The number of N_Ports with plogi issued.
4500 lpfc_els_disc_plogi(struct lpfc_vport *vport)
4502 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4503 struct lpfc_nodelist *ndlp, *next_ndlp;
4506 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
4507 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
4508 if (!NLP_CHK_NODE_ACT(ndlp))
4510 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
4511 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
4512 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
4513 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
4514 ndlp->nlp_prev_state = ndlp->nlp_state;
4515 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
4516 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
4518 vport->num_disc_nodes++;
4519 if (vport->num_disc_nodes >=
4520 vport->cfg_discovery_threads) {
4521 spin_lock_irq(shost->host_lock);
4522 vport->fc_flag |= FC_NLP_MORE;
4523 spin_unlock_irq(shost->host_lock);
4529 lpfc_set_disctmo(vport);
4532 spin_lock_irq(shost->host_lock);
4533 vport->fc_flag &= ~FC_NLP_MORE;
4534 spin_unlock_irq(shost->host_lock);
4540 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
4541 * @vport: pointer to a host virtual N_Port data structure.
4543 * This routine cleans up any Registration State Change Notification
4544 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
4545 * @vport together with the host_lock is used to prevent multiple thread
4546 * trying to access the RSCN array on a same @vport at the same time.
4549 lpfc_els_flush_rscn(struct lpfc_vport *vport)
4551 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4552 struct lpfc_hba *phba = vport->phba;
4555 spin_lock_irq(shost->host_lock);
4556 if (vport->fc_rscn_flush) {
4557 /* Another thread is walking fc_rscn_id_list on this vport */
4558 spin_unlock_irq(shost->host_lock);
4561 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
4562 vport->fc_rscn_flush = 1;
4563 spin_unlock_irq(shost->host_lock);
4565 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
4566 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
4567 vport->fc_rscn_id_list[i] = NULL;
4569 spin_lock_irq(shost->host_lock);
4570 vport->fc_rscn_id_cnt = 0;
4571 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
4572 spin_unlock_irq(shost->host_lock);
4573 lpfc_can_disctmo(vport);
4574 /* Indicate we are done walking this fc_rscn_id_list */
4575 vport->fc_rscn_flush = 0;
4579 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
4580 * @vport: pointer to a host virtual N_Port data structure.
4581 * @did: remote destination port identifier.
4583 * This routine checks whether there is any pending Registration State
4584 * Configuration Notification (RSCN) to a @did on @vport.
4587 * None zero - The @did matched with a pending rscn
4588 * 0 - not able to match @did with a pending rscn
4591 lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
4596 uint32_t payload_len, i;
4597 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4599 ns_did.un.word = did;
4601 /* Never match fabric nodes for RSCNs */
4602 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
4605 /* If we are doing a FULL RSCN rediscovery, match everything */
4606 if (vport->fc_flag & FC_RSCN_DISCOVERY)
4609 spin_lock_irq(shost->host_lock);
4610 if (vport->fc_rscn_flush) {
4611 /* Another thread is walking fc_rscn_id_list on this vport */
4612 spin_unlock_irq(shost->host_lock);
4615 /* Indicate we are walking fc_rscn_id_list on this vport */
4616 vport->fc_rscn_flush = 1;
4617 spin_unlock_irq(shost->host_lock);
4618 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
4619 lp = vport->fc_rscn_id_list[i]->virt;
4620 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
4621 payload_len -= sizeof(uint32_t); /* take off word 0 */
4622 while (payload_len) {
4623 rscn_did.un.word = be32_to_cpu(*lp++);
4624 payload_len -= sizeof(uint32_t);
4625 switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) {
4626 case RSCN_ADDRESS_FORMAT_PORT:
4627 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
4628 && (ns_did.un.b.area == rscn_did.un.b.area)
4629 && (ns_did.un.b.id == rscn_did.un.b.id))
4630 goto return_did_out;
4632 case RSCN_ADDRESS_FORMAT_AREA:
4633 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
4634 && (ns_did.un.b.area == rscn_did.un.b.area))
4635 goto return_did_out;
4637 case RSCN_ADDRESS_FORMAT_DOMAIN:
4638 if (ns_did.un.b.domain == rscn_did.un.b.domain)
4639 goto return_did_out;
4641 case RSCN_ADDRESS_FORMAT_FABRIC:
4642 goto return_did_out;
4646 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4647 vport->fc_rscn_flush = 0;
4650 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4651 vport->fc_rscn_flush = 0;
4656 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
4657 * @vport: pointer to a host virtual N_Port data structure.
4659 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
4660 * state machine for a @vport's nodes that are with pending RSCN (Registration
4661 * State Change Notification).
4664 * 0 - Successful (currently alway return 0)
4667 lpfc_rscn_recovery_check(struct lpfc_vport *vport)
4669 struct lpfc_nodelist *ndlp = NULL;
4671 /* Move all affected nodes by pending RSCNs to NPR state. */
4672 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
4673 if (!NLP_CHK_NODE_ACT(ndlp) ||
4674 (ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
4675 !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
4677 lpfc_disc_state_machine(vport, ndlp, NULL,
4678 NLP_EVT_DEVICE_RECOVERY);
4679 lpfc_cancel_retry_delay_tmo(vport, ndlp);
4685 * lpfc_send_rscn_event - Send an RSCN event to management application
4686 * @vport: pointer to a host virtual N_Port data structure.
4687 * @cmdiocb: pointer to lpfc command iocb data structure.
4689 * lpfc_send_rscn_event sends an RSCN netlink event to management
4693 lpfc_send_rscn_event(struct lpfc_vport *vport,
4694 struct lpfc_iocbq *cmdiocb)
4696 struct lpfc_dmabuf *pcmd;
4697 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4698 uint32_t *payload_ptr;
4699 uint32_t payload_len;
4700 struct lpfc_rscn_event_header *rscn_event_data;
4702 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4703 payload_ptr = (uint32_t *) pcmd->virt;
4704 payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK);
4706 rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) +
4707 payload_len, GFP_KERNEL);
4708 if (!rscn_event_data) {
4709 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4710 "0147 Failed to allocate memory for RSCN event\n");
4713 rscn_event_data->event_type = FC_REG_RSCN_EVENT;
4714 rscn_event_data->payload_length = payload_len;
4715 memcpy(rscn_event_data->rscn_payload, payload_ptr,
4718 fc_host_post_vendor_event(shost,
4719 fc_get_event_number(),
4720 sizeof(struct lpfc_els_event_header) + payload_len,
4721 (char *)rscn_event_data,
4724 kfree(rscn_event_data);
4728 * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
4729 * @vport: pointer to a host virtual N_Port data structure.
4730 * @cmdiocb: pointer to lpfc command iocb data structure.
4731 * @ndlp: pointer to a node-list data structure.
4733 * This routine processes an unsolicited RSCN (Registration State Change
4734 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
4735 * to invoke fc_host_post_event() routine to the FC transport layer. If the
4736 * discover state machine is about to begin discovery, it just accepts the
4737 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
4738 * contains N_Port IDs for other vports on this HBA, it just accepts the
4739 * RSCN and ignore processing it. If the state machine is in the recovery
4740 * state, the fc_rscn_id_list of this @vport is walked and the
4741 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
4742 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
4743 * routine is invoked to handle the RSCN event.
4746 * 0 - Just sent the acc response
4747 * 1 - Sent the acc response and waited for name server completion
4750 lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4751 struct lpfc_nodelist *ndlp)
4753 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4754 struct lpfc_hba *phba = vport->phba;
4755 struct lpfc_dmabuf *pcmd;
4756 uint32_t *lp, *datap;
4758 uint32_t payload_len, length, nportid, *cmd;
4760 int rscn_id = 0, hba_id = 0;
4763 icmd = &cmdiocb->iocb;
4764 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4765 lp = (uint32_t *) pcmd->virt;
4767 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
4768 payload_len -= sizeof(uint32_t); /* take off word 0 */
4770 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4771 "0214 RSCN received Data: x%x x%x x%x x%x\n",
4772 vport->fc_flag, payload_len, *lp,
4773 vport->fc_rscn_id_cnt);
4775 /* Send an RSCN event to the management application */
4776 lpfc_send_rscn_event(vport, cmdiocb);
4778 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
4779 fc_host_post_event(shost, fc_get_event_number(),
4780 FCH_EVT_RSCN, lp[i]);
4782 /* If we are about to begin discovery, just ACC the RSCN.
4783 * Discovery processing will satisfy it.
4785 if (vport->port_state <= LPFC_NS_QRY) {
4786 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4787 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
4788 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4790 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
4794 /* If this RSCN just contains NPortIDs for other vports on this HBA,
4795 * just ACC and ignore it.
4797 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
4798 !(vport->cfg_peer_port_login)) {
4803 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
4804 i -= sizeof(uint32_t);
4806 if (lpfc_find_vport_by_did(phba, nportid))
4809 if (rscn_id == hba_id) {
4810 /* ALL NPortIDs in RSCN are on HBA */
4811 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4813 "Data: x%x x%x x%x x%x\n",
4814 vport->fc_flag, payload_len,
4815 *lp, vport->fc_rscn_id_cnt);
4816 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4817 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
4818 ndlp->nlp_DID, vport->port_state,
4821 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
4827 spin_lock_irq(shost->host_lock);
4828 if (vport->fc_rscn_flush) {
4829 /* Another thread is walking fc_rscn_id_list on this vport */
4830 vport->fc_flag |= FC_RSCN_DISCOVERY;
4831 spin_unlock_irq(shost->host_lock);
4833 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
4836 /* Indicate we are walking fc_rscn_id_list on this vport */
4837 vport->fc_rscn_flush = 1;
4838 spin_unlock_irq(shost->host_lock);
4839 /* Get the array count after successfully have the token */
4840 rscn_cnt = vport->fc_rscn_id_cnt;
4841 /* If we are already processing an RSCN, save the received
4842 * RSCN payload buffer, cmdiocb->context2 to process later.
4844 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
4845 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4846 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
4847 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4849 spin_lock_irq(shost->host_lock);
4850 vport->fc_flag |= FC_RSCN_DEFERRED;
4851 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
4852 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
4853 vport->fc_flag |= FC_RSCN_MODE;
4854 spin_unlock_irq(shost->host_lock);
4856 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
4857 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
4860 (payload_len + length <= LPFC_BPL_SIZE)) {
4861 *cmd &= ELS_CMD_MASK;
4862 *cmd |= cpu_to_be32(payload_len + length);
4863 memcpy(((uint8_t *)cmd) + length, lp,
4866 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
4867 vport->fc_rscn_id_cnt++;
4868 /* If we zero, cmdiocb->context2, the calling
4869 * routine will not try to free it.
4871 cmdiocb->context2 = NULL;
4874 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4875 "0235 Deferred RSCN "
4876 "Data: x%x x%x x%x\n",
4877 vport->fc_rscn_id_cnt, vport->fc_flag,
4880 vport->fc_flag |= FC_RSCN_DISCOVERY;
4881 spin_unlock_irq(shost->host_lock);
4882 /* ReDiscovery RSCN */
4883 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4884 "0234 ReDiscovery RSCN "
4885 "Data: x%x x%x x%x\n",
4886 vport->fc_rscn_id_cnt, vport->fc_flag,
4889 /* Indicate we are done walking fc_rscn_id_list on this vport */
4890 vport->fc_rscn_flush = 0;
4892 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
4893 /* send RECOVERY event for ALL nodes that match RSCN payload */
4894 lpfc_rscn_recovery_check(vport);
4895 spin_lock_irq(shost->host_lock);
4896 vport->fc_flag &= ~FC_RSCN_DEFERRED;
4897 spin_unlock_irq(shost->host_lock);
4900 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4901 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
4902 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4904 spin_lock_irq(shost->host_lock);
4905 vport->fc_flag |= FC_RSCN_MODE;
4906 spin_unlock_irq(shost->host_lock);
4907 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
4908 /* Indicate we are done walking fc_rscn_id_list on this vport */
4909 vport->fc_rscn_flush = 0;
4911 * If we zero, cmdiocb->context2, the calling routine will
4912 * not try to free it.
4914 cmdiocb->context2 = NULL;
4915 lpfc_set_disctmo(vport);
4917 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
4918 /* send RECOVERY event for ALL nodes that match RSCN payload */
4919 lpfc_rscn_recovery_check(vport);
4920 return lpfc_els_handle_rscn(vport);
4924 * lpfc_els_handle_rscn - Handle rscn for a vport
4925 * @vport: pointer to a host virtual N_Port data structure.
4927 * This routine handles the Registration State Configuration Notification
4928 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
4929 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
4930 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
4931 * NameServer shall be issued. If CT command to the NameServer fails to be
4932 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
4933 * RSCN activities with the @vport.
4936 * 0 - Cleaned up rscn on the @vport
4937 * 1 - Wait for plogi to name server before proceed
4940 lpfc_els_handle_rscn(struct lpfc_vport *vport)
4942 struct lpfc_nodelist *ndlp;
4943 struct lpfc_hba *phba = vport->phba;
4945 /* Ignore RSCN if the port is being torn down. */
4946 if (vport->load_flag & FC_UNLOADING) {
4947 lpfc_els_flush_rscn(vport);
4951 /* Start timer for RSCN processing */
4952 lpfc_set_disctmo(vport);
4954 /* RSCN processed */
4955 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4956 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
4957 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
4960 /* To process RSCN, first compare RSCN data with NameServer */
4961 vport->fc_ns_retry = 0;
4962 vport->num_disc_nodes = 0;
4964 ndlp = lpfc_findnode_did(vport, NameServer_DID);
4965 if (ndlp && NLP_CHK_NODE_ACT(ndlp)
4966 && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
4967 /* Good ndlp, issue CT Request to NameServer */
4968 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0)
4969 /* Wait for NameServer query cmpl before we can
4973 /* If login to NameServer does not exist, issue one */
4974 /* Good status, issue PLOGI to NameServer */
4975 ndlp = lpfc_findnode_did(vport, NameServer_DID);
4976 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
4977 /* Wait for NameServer login cmpl before we can
4982 ndlp = lpfc_enable_node(vport, ndlp,
4983 NLP_STE_PLOGI_ISSUE);
4985 lpfc_els_flush_rscn(vport);
4988 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
4990 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
4992 lpfc_els_flush_rscn(vport);
4995 lpfc_nlp_init(vport, ndlp, NameServer_DID);
4996 ndlp->nlp_prev_state = ndlp->nlp_state;
4997 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
4999 ndlp->nlp_type |= NLP_FABRIC;
5000 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
5001 /* Wait for NameServer login cmpl before we can
5007 lpfc_els_flush_rscn(vport);
5012 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
5013 * @vport: pointer to a host virtual N_Port data structure.
5014 * @cmdiocb: pointer to lpfc command iocb data structure.
5015 * @ndlp: pointer to a node-list data structure.
5017 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
5018 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
5019 * point topology. As an unsolicited FLOGI should not be received in a loop
5020 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
5021 * lpfc_check_sparm() routine is invoked to check the parameters in the
5022 * unsolicited FLOGI. If parameters validation failed, the routine
5023 * lpfc_els_rsp_reject() shall be called with reject reason code set to
5024 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
5025 * FLOGI shall be compared with the Port WWN of the @vport to determine who
5026 * will initiate PLOGI. The higher lexicographical value party shall has
5027 * higher priority (as the winning port) and will initiate PLOGI and
5028 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
5029 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
5030 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
5033 * 0 - Successfully processed the unsolicited flogi
5034 * 1 - Failed to process the unsolicited flogi
5037 lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5038 struct lpfc_nodelist *ndlp)
5040 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5041 struct lpfc_hba *phba = vport->phba;
5042 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5043 uint32_t *lp = (uint32_t *) pcmd->virt;
5044 IOCB_t *icmd = &cmdiocb->iocb;
5045 struct serv_parm *sp;
5052 sp = (struct serv_parm *) lp;
5054 /* FLOGI received */
5056 lpfc_set_disctmo(vport);
5058 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
5059 /* We should never receive a FLOGI in loop mode, ignore it */
5060 did = icmd->un.elsreq64.remoteID;
5062 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
5064 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5065 "0113 An FLOGI ELS command x%x was "
5066 "received from DID x%x in Loop Mode\n",
5071 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1))) {
5072 /* For a FLOGI we accept, then if our portname is greater
5073 * then the remote portname we initiate Nport login.
5076 rc = memcmp(&vport->fc_portname, &sp->portName,
5077 sizeof(struct lpfc_name));
5080 if (phba->sli_rev < LPFC_SLI_REV4) {
5081 mbox = mempool_alloc(phba->mbox_mem_pool,
5085 lpfc_linkdown(phba);
5086 lpfc_init_link(phba, mbox,
5088 phba->cfg_link_speed);
5089 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
5090 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5091 mbox->vport = vport;
5092 rc = lpfc_sli_issue_mbox(phba, mbox,
5094 lpfc_set_loopback_flag(phba);
5095 if (rc == MBX_NOT_FINISHED)
5096 mempool_free(mbox, phba->mbox_mem_pool);
5099 /* abort the flogi coming back to ourselves
5100 * due to external loopback on the port.
5102 lpfc_els_abort_flogi(phba);
5105 } else if (rc > 0) { /* greater than */
5106 spin_lock_irq(shost->host_lock);
5107 vport->fc_flag |= FC_PT2PT_PLOGI;
5108 spin_unlock_irq(shost->host_lock);
5110 /* If we have the high WWPN we can assign our own
5111 * myDID; otherwise, we have to WAIT for a PLOGI
5112 * from the remote NPort to find out what it
5115 vport->fc_myDID = PT2PT_LocalID;
5119 * The vport state should go to LPFC_FLOGI only
5120 * AFTER we issue a FLOGI, not receive one.
5122 spin_lock_irq(shost->host_lock);
5123 vport->fc_flag |= FC_PT2PT;
5124 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
5125 spin_unlock_irq(shost->host_lock);
5128 * We temporarily set fc_myDID to make it look like we are
5129 * a Fabric. This is done just so we end up with the right
5130 * did / sid on the FLOGI ACC rsp.
5132 did = vport->fc_myDID;
5133 vport->fc_myDID = Fabric_DID;
5136 /* Reject this request because invalid parameters */
5137 stat.un.b.lsRjtRsvd0 = 0;
5138 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5139 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
5140 stat.un.b.vendorUnique = 0;
5143 * We temporarily set fc_myDID to make it look like we are
5144 * a Fabric. This is done just so we end up with the right
5145 * did / sid on the FLOGI LS_RJT rsp.
5147 did = vport->fc_myDID;
5148 vport->fc_myDID = Fabric_DID;
5150 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
5153 /* Now lets put fc_myDID back to what its supposed to be */
5154 vport->fc_myDID = did;
5160 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
5162 /* Now lets put fc_myDID back to what its supposed to be */
5163 vport->fc_myDID = did;
5165 if (!(vport->fc_flag & FC_PT2PT_PLOGI)) {
5167 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5171 lpfc_config_link(phba, mbox);
5173 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5174 mbox->vport = vport;
5175 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
5176 if (rc == MBX_NOT_FINISHED) {
5177 mempool_free(mbox, phba->mbox_mem_pool);
5188 * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
5189 * @vport: pointer to a host virtual N_Port data structure.
5190 * @cmdiocb: pointer to lpfc command iocb data structure.
5191 * @ndlp: pointer to a node-list data structure.
5193 * This routine processes Request Node Identification Data (RNID) IOCB
5194 * received as an ELS unsolicited event. Only when the RNID specified format
5195 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
5196 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
5197 * Accept (ACC) the RNID ELS command. All the other RNID formats are
5198 * rejected by invoking the lpfc_els_rsp_reject() routine.
5201 * 0 - Successfully processed rnid iocb (currently always return 0)
5204 lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5205 struct lpfc_nodelist *ndlp)
5207 struct lpfc_dmabuf *pcmd;
5214 icmd = &cmdiocb->iocb;
5215 did = icmd->un.elsreq64.remoteID;
5216 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5217 lp = (uint32_t *) pcmd->virt;
5224 switch (rn->Format) {
5226 case RNID_TOPOLOGY_DISC:
5228 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
5231 /* Reject this request because format not supported */
5232 stat.un.b.lsRjtRsvd0 = 0;
5233 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5234 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5235 stat.un.b.vendorUnique = 0;
5236 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
5243 * lpfc_els_rcv_echo - Process an unsolicited echo iocb
5244 * @vport: pointer to a host virtual N_Port data structure.
5245 * @cmdiocb: pointer to lpfc command iocb data structure.
5246 * @ndlp: pointer to a node-list data structure.
5249 * 0 - Successfully processed echo iocb (currently always return 0)
5252 lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5253 struct lpfc_nodelist *ndlp)
5257 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
5259 /* skip over first word of echo command to find echo data */
5260 pcmd += sizeof(uint32_t);
5262 lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp);
5267 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
5268 * @vport: pointer to a host virtual N_Port data structure.
5269 * @cmdiocb: pointer to lpfc command iocb data structure.
5270 * @ndlp: pointer to a node-list data structure.
5272 * This routine processes a Link Incident Report Registration(LIRR) IOCB
5273 * received as an ELS unsolicited event. Currently, this function just invokes
5274 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
5277 * 0 - Successfully processed lirr iocb (currently always return 0)
5280 lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5281 struct lpfc_nodelist *ndlp)
5285 /* For now, unconditionally reject this command */
5286 stat.un.b.lsRjtRsvd0 = 0;
5287 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5288 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5289 stat.un.b.vendorUnique = 0;
5290 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5295 * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb
5296 * @vport: pointer to a host virtual N_Port data structure.
5297 * @cmdiocb: pointer to lpfc command iocb data structure.
5298 * @ndlp: pointer to a node-list data structure.
5300 * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB
5301 * received as an ELS unsolicited event. A request to RRQ shall only
5302 * be accepted if the Originator Nx_Port N_Port_ID or the Responder
5303 * Nx_Port N_Port_ID of the target Exchange is the same as the
5304 * N_Port_ID of the Nx_Port that makes the request. If the RRQ is
5305 * not accepted, an LS_RJT with reason code "Unable to perform
5306 * command request" and reason code explanation "Invalid Originator
5307 * S_ID" shall be returned. For now, we just unconditionally accept
5308 * RRQ from the target.
5311 lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5312 struct lpfc_nodelist *ndlp)
5314 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
5315 if (vport->phba->sli_rev == LPFC_SLI_REV4)
5316 lpfc_els_clear_rrq(vport, cmdiocb, ndlp);
5320 * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
5321 * @phba: pointer to lpfc hba data structure.
5322 * @pmb: pointer to the driver internal queue element for mailbox command.
5324 * This routine is the completion callback function for the MBX_READ_LNK_STAT
5325 * mailbox command. This callback function is to actually send the Accept
5326 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
5327 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
5328 * mailbox command, constructs the RPS response with the link statistics
5329 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
5330 * response to the RPS.
5332 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5333 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5334 * will be stored into the context1 field of the IOCB for the completion
5335 * callback function to the RPS Accept Response ELS IOCB command.
5339 lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
5343 struct RLS_RSP *rls_rsp;
5345 struct lpfc_iocbq *elsiocb;
5346 struct lpfc_nodelist *ndlp;
5353 ndlp = (struct lpfc_nodelist *) pmb->context2;
5354 rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff);
5355 oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff);
5356 pmb->context1 = NULL;
5357 pmb->context2 = NULL;
5359 if (mb->mbxStatus) {
5360 mempool_free(pmb, phba->mbox_mem_pool);
5364 cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t);
5365 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5366 lpfc_max_els_tries, ndlp,
5367 ndlp->nlp_DID, ELS_CMD_ACC);
5369 /* Decrement the ndlp reference count from previous mbox command */
5373 mempool_free(pmb, phba->mbox_mem_pool);
5377 icmd = &elsiocb->iocb;
5378 icmd->ulpContext = rxid;
5379 icmd->unsli3.rcvsli3.ox_id = oxid;
5381 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5382 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5383 pcmd += sizeof(uint32_t); /* Skip past command */
5384 rls_rsp = (struct RLS_RSP *)pcmd;
5386 rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
5387 rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
5388 rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
5389 rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
5390 rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
5391 rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
5392 mempool_free(pmb, phba->mbox_mem_pool);
5393 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
5394 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
5395 "2874 Xmit ELS RLS ACC response tag x%x xri x%x, "
5396 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
5397 elsiocb->iotag, elsiocb->iocb.ulpContext,
5398 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5400 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5401 phba->fc_stat.elsXmitACC++;
5402 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
5403 lpfc_els_free_iocb(phba, elsiocb);
5407 * lpfc_els_rsp_rps_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
5408 * @phba: pointer to lpfc hba data structure.
5409 * @pmb: pointer to the driver internal queue element for mailbox command.
5411 * This routine is the completion callback function for the MBX_READ_LNK_STAT
5412 * mailbox command. This callback function is to actually send the Accept
5413 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
5414 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
5415 * mailbox command, constructs the RPS response with the link statistics
5416 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
5417 * response to the RPS.
5419 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5420 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5421 * will be stored into the context1 field of the IOCB for the completion
5422 * callback function to the RPS Accept Response ELS IOCB command.
5426 lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
5432 struct lpfc_iocbq *elsiocb;
5433 struct lpfc_nodelist *ndlp;
5441 ndlp = (struct lpfc_nodelist *) pmb->context2;
5442 rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff);
5443 oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff);
5444 pmb->context1 = NULL;
5445 pmb->context2 = NULL;
5447 if (mb->mbxStatus) {
5448 mempool_free(pmb, phba->mbox_mem_pool);
5452 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
5453 mempool_free(pmb, phba->mbox_mem_pool);
5454 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5455 lpfc_max_els_tries, ndlp,
5456 ndlp->nlp_DID, ELS_CMD_ACC);
5458 /* Decrement the ndlp reference count from previous mbox command */
5464 icmd = &elsiocb->iocb;
5465 icmd->ulpContext = rxid;
5466 icmd->unsli3.rcvsli3.ox_id = oxid;
5468 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5469 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5470 pcmd += sizeof(uint32_t); /* Skip past command */
5471 rps_rsp = (RPS_RSP *)pcmd;
5473 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP)
5477 if (phba->pport->fc_flag & FC_FABRIC)
5481 rps_rsp->portStatus = cpu_to_be16(status);
5482 rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
5483 rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
5484 rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
5485 rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
5486 rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
5487 rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
5488 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
5489 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
5490 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
5491 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
5492 elsiocb->iotag, elsiocb->iocb.ulpContext,
5493 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5495 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5496 phba->fc_stat.elsXmitACC++;
5497 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
5498 lpfc_els_free_iocb(phba, elsiocb);
5503 * lpfc_els_rcv_rls - Process an unsolicited rls iocb
5504 * @vport: pointer to a host virtual N_Port data structure.
5505 * @cmdiocb: pointer to lpfc command iocb data structure.
5506 * @ndlp: pointer to a node-list data structure.
5508 * This routine processes Read Port Status (RPL) IOCB received as an
5509 * ELS unsolicited event. It first checks the remote port state. If the
5510 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5511 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
5512 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
5513 * for reading the HBA link statistics. It is for the callback function,
5514 * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command
5515 * to actually sending out RPL Accept (ACC) response.
5518 * 0 - Successfully processed rls iocb (currently always return 0)
5521 lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5522 struct lpfc_nodelist *ndlp)
5524 struct lpfc_hba *phba = vport->phba;
5526 struct lpfc_dmabuf *pcmd;
5529 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5530 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
5531 /* reject the unsolicited RPS request and done with it */
5534 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5536 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
5538 lpfc_read_lnk_stat(phba, mbox);
5539 mbox->context1 = (void *)((unsigned long)
5540 ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) |
5541 cmdiocb->iocb.ulpContext)); /* rx_id */
5542 mbox->context2 = lpfc_nlp_get(ndlp);
5543 mbox->vport = vport;
5544 mbox->mbox_cmpl = lpfc_els_rsp_rls_acc;
5545 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
5546 != MBX_NOT_FINISHED)
5547 /* Mbox completion will send ELS Response */
5549 /* Decrement reference count used for the failed mbox
5553 mempool_free(mbox, phba->mbox_mem_pool);
5556 /* issue rejection response */
5557 stat.un.b.lsRjtRsvd0 = 0;
5558 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5559 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5560 stat.un.b.vendorUnique = 0;
5561 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5566 * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb
5567 * @vport: pointer to a host virtual N_Port data structure.
5568 * @cmdiocb: pointer to lpfc command iocb data structure.
5569 * @ndlp: pointer to a node-list data structure.
5571 * This routine processes Read Timout Value (RTV) IOCB received as an
5572 * ELS unsolicited event. It first checks the remote port state. If the
5573 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5574 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
5575 * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout
5576 * Value (RTV) unsolicited IOCB event.
5578 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5579 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5580 * will be stored into the context1 field of the IOCB for the completion
5581 * callback function to the RPS Accept Response ELS IOCB command.
5584 * 0 - Successfully processed rtv iocb (currently always return 0)
5587 lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5588 struct lpfc_nodelist *ndlp)
5590 struct lpfc_hba *phba = vport->phba;
5592 struct RTV_RSP *rtv_rsp;
5594 struct lpfc_iocbq *elsiocb;
5598 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5599 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
5600 /* reject the unsolicited RPS request and done with it */
5603 cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t);
5604 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5605 lpfc_max_els_tries, ndlp,
5606 ndlp->nlp_DID, ELS_CMD_ACC);
5611 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5612 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5613 pcmd += sizeof(uint32_t); /* Skip past command */
5615 /* use the command's xri in the response */
5616 elsiocb->iocb.ulpContext = cmdiocb->iocb.ulpContext; /* Xri / rx_id */
5617 elsiocb->iocb.unsli3.rcvsli3.ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id;
5619 rtv_rsp = (struct RTV_RSP *)pcmd;
5621 /* populate RTV payload */
5622 rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000); /* report msecs */
5623 rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov);
5624 bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0);
5625 bf_set(qtov_rttov, rtv_rsp, 0); /* Field is for FC ONLY */
5626 rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov);
5628 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
5629 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
5630 "2875 Xmit ELS RTV ACC response tag x%x xri x%x, "
5631 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, "
5632 "Data: x%x x%x x%x\n",
5633 elsiocb->iotag, elsiocb->iocb.ulpContext,
5634 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5636 rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov);
5637 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5638 phba->fc_stat.elsXmitACC++;
5639 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
5640 lpfc_els_free_iocb(phba, elsiocb);
5644 /* issue rejection response */
5645 stat.un.b.lsRjtRsvd0 = 0;
5646 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5647 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5648 stat.un.b.vendorUnique = 0;
5649 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5653 /* lpfc_els_rcv_rps - Process an unsolicited rps iocb
5654 * @vport: pointer to a host virtual N_Port data structure.
5655 * @cmdiocb: pointer to lpfc command iocb data structure.
5656 * @ndlp: pointer to a node-list data structure.
5658 * This routine processes Read Port Status (RPS) IOCB received as an
5659 * ELS unsolicited event. It first checks the remote port state. If the
5660 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5661 * state, it invokes the lpfc_els_rsp_reject() routine to send the reject
5662 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
5663 * for reading the HBA link statistics. It is for the callback function,
5664 * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command
5665 * to actually sending out RPS Accept (ACC) response.
5668 * 0 - Successfully processed rps iocb (currently always return 0)
5671 lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5672 struct lpfc_nodelist *ndlp)
5674 struct lpfc_hba *phba = vport->phba;
5678 struct lpfc_dmabuf *pcmd;
5682 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5683 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
5684 /* reject the unsolicited RPS request and done with it */
5687 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5688 lp = (uint32_t *) pcmd->virt;
5689 flag = (be32_to_cpu(*lp++) & 0xf);
5693 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
5694 ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
5695 sizeof(struct lpfc_name)) == 0))) {
5697 printk("Fix me....\n");
5699 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
5701 lpfc_read_lnk_stat(phba, mbox);
5702 mbox->context1 = (void *)((unsigned long)
5703 ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) |
5704 cmdiocb->iocb.ulpContext)); /* rx_id */
5705 mbox->context2 = lpfc_nlp_get(ndlp);
5706 mbox->vport = vport;
5707 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
5708 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
5709 != MBX_NOT_FINISHED)
5710 /* Mbox completion will send ELS Response */
5712 /* Decrement reference count used for the failed mbox
5716 mempool_free(mbox, phba->mbox_mem_pool);
5721 /* issue rejection response */
5722 stat.un.b.lsRjtRsvd0 = 0;
5723 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5724 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5725 stat.un.b.vendorUnique = 0;
5726 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5730 /* lpfc_issue_els_rrq - Process an unsolicited rps iocb
5731 * @vport: pointer to a host virtual N_Port data structure.
5732 * @ndlp: pointer to a node-list data structure.
5733 * @did: DID of the target.
5734 * @rrq: Pointer to the rrq struct.
5736 * Build a ELS RRQ command and send it to the target. If the issue_iocb is
5737 * Successful the the completion handler will clear the RRQ.
5740 * 0 - Successfully sent rrq els iocb.
5741 * 1 - Failed to send rrq els iocb.
5744 lpfc_issue_els_rrq(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
5745 uint32_t did, struct lpfc_node_rrq *rrq)
5747 struct lpfc_hba *phba = vport->phba;
5748 struct RRQ *els_rrq;
5750 struct lpfc_iocbq *elsiocb;
5756 if (ndlp != rrq->ndlp)
5758 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
5761 /* If ndlp is not NULL, we will bump the reference count on it */
5762 cmdsize = (sizeof(uint32_t) + sizeof(struct RRQ));
5763 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, did,
5768 icmd = &elsiocb->iocb;
5769 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5771 /* For RRQ request, remainder of payload is Exchange IDs */
5772 *((uint32_t *) (pcmd)) = ELS_CMD_RRQ;
5773 pcmd += sizeof(uint32_t);
5774 els_rrq = (struct RRQ *) pcmd;
5776 bf_set(rrq_oxid, els_rrq, phba->sli4_hba.xri_ids[rrq->xritag]);
5777 bf_set(rrq_rxid, els_rrq, rrq->rxid);
5778 bf_set(rrq_did, els_rrq, vport->fc_myDID);
5779 els_rrq->rrq = cpu_to_be32(els_rrq->rrq);
5780 els_rrq->rrq_exchg = cpu_to_be32(els_rrq->rrq_exchg);
5783 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
5784 "Issue RRQ: did:x%x",
5785 did, rrq->xritag, rrq->rxid);
5786 elsiocb->context_un.rrq = rrq;
5787 elsiocb->iocb_cmpl = lpfc_cmpl_els_rrq;
5788 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5790 if (ret == IOCB_ERROR) {
5791 lpfc_els_free_iocb(phba, elsiocb);
5798 * lpfc_send_rrq - Sends ELS RRQ if needed.
5799 * @phba: pointer to lpfc hba data structure.
5800 * @rrq: pointer to the active rrq.
5802 * This routine will call the lpfc_issue_els_rrq if the rrq is
5803 * still active for the xri. If this function returns a failure then
5804 * the caller needs to clean up the RRQ by calling lpfc_clr_active_rrq.
5806 * Returns 0 Success.
5810 lpfc_send_rrq(struct lpfc_hba *phba, struct lpfc_node_rrq *rrq)
5812 struct lpfc_nodelist *ndlp = lpfc_findnode_did(rrq->vport,
5814 if (lpfc_test_rrq_active(phba, ndlp, rrq->xritag))
5815 return lpfc_issue_els_rrq(rrq->vport, ndlp,
5822 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
5823 * @vport: pointer to a host virtual N_Port data structure.
5824 * @cmdsize: size of the ELS command.
5825 * @oldiocb: pointer to the original lpfc command iocb data structure.
5826 * @ndlp: pointer to a node-list data structure.
5828 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
5829 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
5831 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5832 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5833 * will be stored into the context1 field of the IOCB for the completion
5834 * callback function to the RPL Accept Response ELS command.
5837 * 0 - Successfully issued ACC RPL ELS command
5838 * 1 - Failed to issue ACC RPL ELS command
5841 lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
5842 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
5844 struct lpfc_hba *phba = vport->phba;
5845 IOCB_t *icmd, *oldcmd;
5847 struct lpfc_iocbq *elsiocb;
5850 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
5851 ndlp->nlp_DID, ELS_CMD_ACC);
5856 icmd = &elsiocb->iocb;
5857 oldcmd = &oldiocb->iocb;
5858 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
5859 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
5861 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5862 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5863 pcmd += sizeof(uint16_t);
5864 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
5865 pcmd += sizeof(uint16_t);
5867 /* Setup the RPL ACC payload */
5868 rpl_rsp.listLen = be32_to_cpu(1);
5870 rpl_rsp.port_num_blk.portNum = 0;
5871 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
5872 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
5873 sizeof(struct lpfc_name));
5874 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
5875 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
5876 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5877 "0120 Xmit ELS RPL ACC response tag x%x "
5878 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
5880 elsiocb->iotag, elsiocb->iocb.ulpContext,
5881 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5883 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5884 phba->fc_stat.elsXmitACC++;
5885 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
5887 lpfc_els_free_iocb(phba, elsiocb);
5894 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
5895 * @vport: pointer to a host virtual N_Port data structure.
5896 * @cmdiocb: pointer to lpfc command iocb data structure.
5897 * @ndlp: pointer to a node-list data structure.
5899 * This routine processes Read Port List (RPL) IOCB received as an ELS
5900 * unsolicited event. It first checks the remote port state. If the remote
5901 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
5902 * invokes the lpfc_els_rsp_reject() routine to send reject response.
5903 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
5904 * to accept the RPL.
5907 * 0 - Successfully processed rpl iocb (currently always return 0)
5910 lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5911 struct lpfc_nodelist *ndlp)
5913 struct lpfc_dmabuf *pcmd;
5920 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5921 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
5922 /* issue rejection response */
5923 stat.un.b.lsRjtRsvd0 = 0;
5924 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5925 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5926 stat.un.b.vendorUnique = 0;
5927 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
5929 /* rejected the unsolicited RPL request and done with it */
5933 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5934 lp = (uint32_t *) pcmd->virt;
5935 rpl = (RPL *) (lp + 1);
5936 maxsize = be32_to_cpu(rpl->maxsize);
5938 /* We support only one port */
5939 if ((rpl->index == 0) &&
5941 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
5942 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
5944 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
5946 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
5952 * lpfc_els_rcv_farp - Process an unsolicited farp request els command
5953 * @vport: pointer to a virtual N_Port data structure.
5954 * @cmdiocb: pointer to lpfc command iocb data structure.
5955 * @ndlp: pointer to a node-list data structure.
5957 * This routine processes Fibre Channel Address Resolution Protocol
5958 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
5959 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
5960 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
5961 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
5962 * remote PortName is compared against the FC PortName stored in the @vport
5963 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
5964 * compared against the FC NodeName stored in the @vport data structure.
5965 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
5966 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
5967 * invoked to send out FARP Response to the remote node. Before sending the
5968 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
5969 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
5970 * routine is invoked to log into the remote port first.
5973 * 0 - Either the FARP Match Mode not supported or successfully processed
5976 lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5977 struct lpfc_nodelist *ndlp)
5979 struct lpfc_dmabuf *pcmd;
5983 uint32_t cmd, cnt, did;
5985 icmd = &cmdiocb->iocb;
5986 did = icmd->un.elsreq64.remoteID;
5987 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5988 lp = (uint32_t *) pcmd->virt;
5992 /* FARP-REQ received from DID <did> */
5993 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5994 "0601 FARP-REQ received from DID x%x\n", did);
5995 /* We will only support match on WWPN or WWNN */
5996 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
6001 /* If this FARP command is searching for my portname */
6002 if (fp->Mflags & FARP_MATCH_PORT) {
6003 if (memcmp(&fp->RportName, &vport->fc_portname,
6004 sizeof(struct lpfc_name)) == 0)
6008 /* If this FARP command is searching for my nodename */
6009 if (fp->Mflags & FARP_MATCH_NODE) {
6010 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
6011 sizeof(struct lpfc_name)) == 0)
6016 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
6017 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
6018 /* Log back into the node before sending the FARP. */
6019 if (fp->Rflags & FARP_REQUEST_PLOGI) {
6020 ndlp->nlp_prev_state = ndlp->nlp_state;
6021 lpfc_nlp_set_state(vport, ndlp,
6022 NLP_STE_PLOGI_ISSUE);
6023 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
6026 /* Send a FARP response to that node */
6027 if (fp->Rflags & FARP_REQUEST_FARPR)
6028 lpfc_issue_els_farpr(vport, did, 0);
6035 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
6036 * @vport: pointer to a host virtual N_Port data structure.
6037 * @cmdiocb: pointer to lpfc command iocb data structure.
6038 * @ndlp: pointer to a node-list data structure.
6040 * This routine processes Fibre Channel Address Resolution Protocol
6041 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
6042 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
6043 * the FARP response request.
6046 * 0 - Successfully processed FARPR IOCB (currently always return 0)
6049 lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6050 struct lpfc_nodelist *ndlp)
6052 struct lpfc_dmabuf *pcmd;
6057 icmd = &cmdiocb->iocb;
6058 did = icmd->un.elsreq64.remoteID;
6059 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6060 lp = (uint32_t *) pcmd->virt;
6063 /* FARP-RSP received from DID <did> */
6064 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6065 "0600 FARP-RSP received from DID x%x\n", did);
6066 /* ACCEPT the Farp resp request */
6067 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
6073 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
6074 * @vport: pointer to a host virtual N_Port data structure.
6075 * @cmdiocb: pointer to lpfc command iocb data structure.
6076 * @fan_ndlp: pointer to a node-list data structure.
6078 * This routine processes a Fabric Address Notification (FAN) IOCB
6079 * command received as an ELS unsolicited event. The FAN ELS command will
6080 * only be processed on a physical port (i.e., the @vport represents the
6081 * physical port). The fabric NodeName and PortName from the FAN IOCB are
6082 * compared against those in the phba data structure. If any of those is
6083 * different, the lpfc_initial_flogi() routine is invoked to initialize
6084 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
6085 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
6086 * is invoked to register login to the fabric.
6089 * 0 - Successfully processed fan iocb (currently always return 0).
6092 lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6093 struct lpfc_nodelist *fan_ndlp)
6095 struct lpfc_hba *phba = vport->phba;
6099 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
6100 lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
6102 /* FAN received; Fan does not have a reply sequence */
6103 if ((vport == phba->pport) &&
6104 (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
6105 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
6106 sizeof(struct lpfc_name))) ||
6107 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
6108 sizeof(struct lpfc_name)))) {
6109 /* This port has switched fabrics. FLOGI is required */
6110 lpfc_issue_init_vfi(vport);
6112 /* FAN verified - skip FLOGI */
6113 vport->fc_myDID = vport->fc_prevDID;
6114 if (phba->sli_rev < LPFC_SLI_REV4)
6115 lpfc_issue_fabric_reglogin(vport);
6117 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6118 "3138 Need register VFI: (x%x/%x)\n",
6119 vport->fc_prevDID, vport->fc_myDID);
6120 lpfc_issue_reg_vfi(vport);
6128 * lpfc_els_timeout - Handler funciton to the els timer
6129 * @ptr: holder for the timer function associated data.
6131 * This routine is invoked by the ELS timer after timeout. It posts the ELS
6132 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
6133 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
6134 * up the worker thread. It is for the worker thread to invoke the routine
6135 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
6138 lpfc_els_timeout(unsigned long ptr)
6140 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
6141 struct lpfc_hba *phba = vport->phba;
6142 uint32_t tmo_posted;
6143 unsigned long iflag;
6145 spin_lock_irqsave(&vport->work_port_lock, iflag);
6146 tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
6148 vport->work_port_events |= WORKER_ELS_TMO;
6149 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
6152 lpfc_worker_wake_up(phba);
6158 * lpfc_els_timeout_handler - Process an els timeout event
6159 * @vport: pointer to a virtual N_Port data structure.
6161 * This routine is the actual handler function that processes an ELS timeout
6162 * event. It walks the ELS ring to get and abort all the IOCBs (except the
6163 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
6164 * invoking the lpfc_sli_issue_abort_iotag() routine.
6167 lpfc_els_timeout_handler(struct lpfc_vport *vport)
6169 struct lpfc_hba *phba = vport->phba;
6170 struct lpfc_sli_ring *pring;
6171 struct lpfc_iocbq *tmp_iocb, *piocb;
6173 struct lpfc_dmabuf *pcmd;
6174 uint32_t els_command = 0;
6176 uint32_t remote_ID = 0xffffffff;
6177 LIST_HEAD(txcmplq_completions);
6178 LIST_HEAD(abort_list);
6181 timeout = (uint32_t)(phba->fc_ratov << 1);
6183 pring = &phba->sli.ring[LPFC_ELS_RING];
6185 spin_lock_irq(&phba->hbalock);
6186 list_splice_init(&pring->txcmplq, &txcmplq_completions);
6187 spin_unlock_irq(&phba->hbalock);
6189 list_for_each_entry_safe(piocb, tmp_iocb, &txcmplq_completions, list) {
6192 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
6193 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
6194 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
6197 if (piocb->vport != vport)
6200 pcmd = (struct lpfc_dmabuf *) piocb->context2;
6202 els_command = *(uint32_t *) (pcmd->virt);
6204 if (els_command == ELS_CMD_FARP ||
6205 els_command == ELS_CMD_FARPR ||
6206 els_command == ELS_CMD_FDISC)
6209 if (piocb->drvrTimeout > 0) {
6210 if (piocb->drvrTimeout >= timeout)
6211 piocb->drvrTimeout -= timeout;
6213 piocb->drvrTimeout = 0;
6217 remote_ID = 0xffffffff;
6218 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
6219 remote_ID = cmd->un.elsreq64.remoteID;
6221 struct lpfc_nodelist *ndlp;
6222 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
6223 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
6224 remote_ID = ndlp->nlp_DID;
6226 list_add_tail(&piocb->dlist, &abort_list);
6228 spin_lock_irq(&phba->hbalock);
6229 list_splice(&txcmplq_completions, &pring->txcmplq);
6230 spin_unlock_irq(&phba->hbalock);
6232 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
6233 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6234 "0127 ELS timeout Data: x%x x%x x%x "
6235 "x%x\n", els_command,
6236 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
6237 spin_lock_irq(&phba->hbalock);
6238 list_del_init(&piocb->dlist);
6239 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
6240 spin_unlock_irq(&phba->hbalock);
6243 if (!list_empty(&phba->sli.ring[LPFC_ELS_RING].txcmplq))
6244 mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
6248 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
6249 * @vport: pointer to a host virtual N_Port data structure.
6251 * This routine is used to clean up all the outstanding ELS commands on a
6252 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
6253 * routine. After that, it walks the ELS transmit queue to remove all the
6254 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
6255 * the IOCBs with a non-NULL completion callback function, the callback
6256 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
6257 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
6258 * callback function, the IOCB will simply be released. Finally, it walks
6259 * the ELS transmit completion queue to issue an abort IOCB to any transmit
6260 * completion queue IOCB that is associated with the @vport and is not
6261 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
6262 * part of the discovery state machine) out to HBA by invoking the
6263 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
6264 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
6265 * the IOCBs are aborted when this function returns.
6268 lpfc_els_flush_cmd(struct lpfc_vport *vport)
6270 LIST_HEAD(completions);
6271 struct lpfc_hba *phba = vport->phba;
6272 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
6273 struct lpfc_iocbq *tmp_iocb, *piocb;
6276 lpfc_fabric_abort_vport(vport);
6278 spin_lock_irq(&phba->hbalock);
6279 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
6282 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
6286 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
6287 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
6288 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
6289 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
6290 cmd->ulpCommand == CMD_ABORT_XRI_CN)
6293 if (piocb->vport != vport)
6296 list_move_tail(&piocb->list, &completions);
6299 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
6300 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
6304 if (piocb->vport != vport)
6307 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
6309 spin_unlock_irq(&phba->hbalock);
6311 /* Cancell all the IOCBs from the completions list */
6312 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6319 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
6320 * @phba: pointer to lpfc hba data structure.
6322 * This routine is used to clean up all the outstanding ELS commands on a
6323 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
6324 * routine. After that, it walks the ELS transmit queue to remove all the
6325 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
6326 * the IOCBs with the completion callback function associated, the callback
6327 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
6328 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
6329 * callback function associated, the IOCB will simply be released. Finally,
6330 * it walks the ELS transmit completion queue to issue an abort IOCB to any
6331 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
6332 * management plane IOCBs that are not part of the discovery state machine)
6333 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
6336 lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
6338 LIST_HEAD(completions);
6339 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
6340 struct lpfc_iocbq *tmp_iocb, *piocb;
6343 lpfc_fabric_abort_hba(phba);
6344 spin_lock_irq(&phba->hbalock);
6345 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
6347 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
6349 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
6350 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
6351 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
6352 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
6353 cmd->ulpCommand == CMD_ABORT_XRI_CN)
6355 list_move_tail(&piocb->list, &completions);
6357 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
6358 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
6360 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
6362 spin_unlock_irq(&phba->hbalock);
6364 /* Cancel all the IOCBs from the completions list */
6365 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6372 * lpfc_send_els_failure_event - Posts an ELS command failure event
6373 * @phba: Pointer to hba context object.
6374 * @cmdiocbp: Pointer to command iocb which reported error.
6375 * @rspiocbp: Pointer to response iocb which reported error.
6377 * This function sends an event when there is an ELS command
6381 lpfc_send_els_failure_event(struct lpfc_hba *phba,
6382 struct lpfc_iocbq *cmdiocbp,
6383 struct lpfc_iocbq *rspiocbp)
6385 struct lpfc_vport *vport = cmdiocbp->vport;
6386 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6387 struct lpfc_lsrjt_event lsrjt_event;
6388 struct lpfc_fabric_event_header fabric_event;
6390 struct lpfc_nodelist *ndlp;
6393 ndlp = cmdiocbp->context1;
6394 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
6397 if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) {
6398 lsrjt_event.header.event_type = FC_REG_ELS_EVENT;
6399 lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV;
6400 memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname,
6401 sizeof(struct lpfc_name));
6402 memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename,
6403 sizeof(struct lpfc_name));
6404 pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
6405 cmdiocbp->context2)->virt);
6406 lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0;
6407 stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]);
6408 lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode;
6409 lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp;
6410 fc_host_post_vendor_event(shost,
6411 fc_get_event_number(),
6412 sizeof(lsrjt_event),
6413 (char *)&lsrjt_event,
6417 if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) ||
6418 (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) {
6419 fabric_event.event_type = FC_REG_FABRIC_EVENT;
6420 if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY)
6421 fabric_event.subcategory = LPFC_EVENT_PORT_BUSY;
6423 fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY;
6424 memcpy(fabric_event.wwpn, &ndlp->nlp_portname,
6425 sizeof(struct lpfc_name));
6426 memcpy(fabric_event.wwnn, &ndlp->nlp_nodename,
6427 sizeof(struct lpfc_name));
6428 fc_host_post_vendor_event(shost,
6429 fc_get_event_number(),
6430 sizeof(fabric_event),
6431 (char *)&fabric_event,
6439 * lpfc_send_els_event - Posts unsolicited els event
6440 * @vport: Pointer to vport object.
6441 * @ndlp: Pointer FC node object.
6442 * @cmd: ELS command code.
6444 * This function posts an event when there is an incoming
6445 * unsolicited ELS command.
6448 lpfc_send_els_event(struct lpfc_vport *vport,
6449 struct lpfc_nodelist *ndlp,
6452 struct lpfc_els_event_header *els_data = NULL;
6453 struct lpfc_logo_event *logo_data = NULL;
6454 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6456 if (*payload == ELS_CMD_LOGO) {
6457 logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL);
6459 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6460 "0148 Failed to allocate memory "
6461 "for LOGO event\n");
6464 els_data = &logo_data->header;
6466 els_data = kmalloc(sizeof(struct lpfc_els_event_header),
6469 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6470 "0149 Failed to allocate memory "
6475 els_data->event_type = FC_REG_ELS_EVENT;
6478 els_data->subcategory = LPFC_EVENT_PLOGI_RCV;
6481 els_data->subcategory = LPFC_EVENT_PRLO_RCV;
6484 els_data->subcategory = LPFC_EVENT_ADISC_RCV;
6487 els_data->subcategory = LPFC_EVENT_LOGO_RCV;
6488 /* Copy the WWPN in the LOGO payload */
6489 memcpy(logo_data->logo_wwpn, &payload[2],
6490 sizeof(struct lpfc_name));
6496 memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name));
6497 memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name));
6498 if (*payload == ELS_CMD_LOGO) {
6499 fc_host_post_vendor_event(shost,
6500 fc_get_event_number(),
6501 sizeof(struct lpfc_logo_event),
6506 fc_host_post_vendor_event(shost,
6507 fc_get_event_number(),
6508 sizeof(struct lpfc_els_event_header),
6519 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
6520 * @phba: pointer to lpfc hba data structure.
6521 * @pring: pointer to a SLI ring.
6522 * @vport: pointer to a host virtual N_Port data structure.
6523 * @elsiocb: pointer to lpfc els command iocb data structure.
6525 * This routine is used for processing the IOCB associated with a unsolicited
6526 * event. It first determines whether there is an existing ndlp that matches
6527 * the DID from the unsolicited IOCB. If not, it will create a new one with
6528 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
6529 * IOCB is then used to invoke the proper routine and to set up proper state
6530 * of the discovery state machine.
6533 lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
6534 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
6536 struct Scsi_Host *shost;
6537 struct lpfc_nodelist *ndlp;
6540 uint32_t cmd, did, newnode;
6541 uint8_t rjt_exp, rjt_err = 0;
6542 IOCB_t *icmd = &elsiocb->iocb;
6544 if (!vport || !(elsiocb->context2))
6548 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
6550 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
6551 lpfc_post_buffer(phba, pring, 1);
6553 did = icmd->un.rcvels.remoteID;
6554 if (icmd->ulpStatus) {
6555 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6556 "RCV Unsol ELS: status:x%x/x%x did:x%x",
6557 icmd->ulpStatus, icmd->un.ulpWord[4], did);
6561 /* Check to see if link went down during discovery */
6562 if (lpfc_els_chk_latt(vport))
6565 /* Ignore traffic received during vport shutdown. */
6566 if (vport->load_flag & FC_UNLOADING)
6569 /* If NPort discovery is delayed drop incoming ELS */
6570 if ((vport->fc_flag & FC_DISC_DELAYED) &&
6571 (cmd != ELS_CMD_PLOGI))
6574 ndlp = lpfc_findnode_did(vport, did);
6576 /* Cannot find existing Fabric ndlp, so allocate a new one */
6577 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
6581 lpfc_nlp_init(vport, ndlp, did);
6582 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
6584 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
6585 ndlp->nlp_type |= NLP_FABRIC;
6586 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
6587 ndlp = lpfc_enable_node(vport, ndlp,
6588 NLP_STE_UNUSED_NODE);
6591 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
6593 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
6594 ndlp->nlp_type |= NLP_FABRIC;
6595 } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
6596 /* This is similar to the new node path */
6597 ndlp = lpfc_nlp_get(ndlp);
6600 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
6604 phba->fc_stat.elsRcvFrame++;
6606 elsiocb->context1 = lpfc_nlp_get(ndlp);
6607 elsiocb->vport = vport;
6609 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
6610 cmd &= ELS_CMD_MASK;
6612 /* ELS command <elsCmd> received from NPORT <did> */
6613 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6614 "0112 ELS command x%x received from NPORT x%x "
6615 "Data: x%x\n", cmd, did, vport->port_state);
6618 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6619 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
6620 did, vport->port_state, ndlp->nlp_flag);
6622 phba->fc_stat.elsRcvPLOGI++;
6623 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
6625 lpfc_send_els_event(vport, ndlp, payload);
6627 /* If Nport discovery is delayed, reject PLOGIs */
6628 if (vport->fc_flag & FC_DISC_DELAYED) {
6629 rjt_err = LSRJT_UNABLE_TPC;
6630 rjt_exp = LSEXP_NOTHING_MORE;
6633 if (vport->port_state < LPFC_DISC_AUTH) {
6634 if (!(phba->pport->fc_flag & FC_PT2PT) ||
6635 (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
6636 rjt_err = LSRJT_UNABLE_TPC;
6637 rjt_exp = LSEXP_NOTHING_MORE;
6640 /* We get here, and drop thru, if we are PT2PT with
6641 * another NPort and the other side has initiated
6642 * the PLOGI before responding to our FLOGI.
6646 shost = lpfc_shost_from_vport(vport);
6647 spin_lock_irq(shost->host_lock);
6648 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
6649 spin_unlock_irq(shost->host_lock);
6651 lpfc_disc_state_machine(vport, ndlp, elsiocb,
6656 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6657 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
6658 did, vport->port_state, ndlp->nlp_flag);
6660 phba->fc_stat.elsRcvFLOGI++;
6661 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
6666 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6667 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
6668 did, vport->port_state, ndlp->nlp_flag);
6670 phba->fc_stat.elsRcvLOGO++;
6671 lpfc_send_els_event(vport, ndlp, payload);
6672 if (vport->port_state < LPFC_DISC_AUTH) {
6673 rjt_err = LSRJT_UNABLE_TPC;
6674 rjt_exp = LSEXP_NOTHING_MORE;
6677 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
6680 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6681 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
6682 did, vport->port_state, ndlp->nlp_flag);
6684 phba->fc_stat.elsRcvPRLO++;
6685 lpfc_send_els_event(vport, ndlp, payload);
6686 if (vport->port_state < LPFC_DISC_AUTH) {
6687 rjt_err = LSRJT_UNABLE_TPC;
6688 rjt_exp = LSEXP_NOTHING_MORE;
6691 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
6694 phba->fc_stat.elsRcvRSCN++;
6695 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
6700 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6701 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
6702 did, vport->port_state, ndlp->nlp_flag);
6704 lpfc_send_els_event(vport, ndlp, payload);
6705 phba->fc_stat.elsRcvADISC++;
6706 if (vport->port_state < LPFC_DISC_AUTH) {
6707 rjt_err = LSRJT_UNABLE_TPC;
6708 rjt_exp = LSEXP_NOTHING_MORE;
6711 lpfc_disc_state_machine(vport, ndlp, elsiocb,
6715 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6716 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
6717 did, vport->port_state, ndlp->nlp_flag);
6719 phba->fc_stat.elsRcvPDISC++;
6720 if (vport->port_state < LPFC_DISC_AUTH) {
6721 rjt_err = LSRJT_UNABLE_TPC;
6722 rjt_exp = LSEXP_NOTHING_MORE;
6725 lpfc_disc_state_machine(vport, ndlp, elsiocb,
6729 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6730 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
6731 did, vport->port_state, ndlp->nlp_flag);
6733 phba->fc_stat.elsRcvFARPR++;
6734 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
6737 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6738 "RCV FARP: did:x%x/ste:x%x flg:x%x",
6739 did, vport->port_state, ndlp->nlp_flag);
6741 phba->fc_stat.elsRcvFARP++;
6742 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
6745 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6746 "RCV FAN: did:x%x/ste:x%x flg:x%x",
6747 did, vport->port_state, ndlp->nlp_flag);
6749 phba->fc_stat.elsRcvFAN++;
6750 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
6753 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6754 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
6755 did, vport->port_state, ndlp->nlp_flag);
6757 phba->fc_stat.elsRcvPRLI++;
6758 if (vport->port_state < LPFC_DISC_AUTH) {
6759 rjt_err = LSRJT_UNABLE_TPC;
6760 rjt_exp = LSEXP_NOTHING_MORE;
6763 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
6766 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6767 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
6768 did, vport->port_state, ndlp->nlp_flag);
6770 phba->fc_stat.elsRcvLIRR++;
6771 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
6776 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6777 "RCV RLS: did:x%x/ste:x%x flg:x%x",
6778 did, vport->port_state, ndlp->nlp_flag);
6780 phba->fc_stat.elsRcvRLS++;
6781 lpfc_els_rcv_rls(vport, elsiocb, ndlp);
6786 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6787 "RCV RPS: did:x%x/ste:x%x flg:x%x",
6788 did, vport->port_state, ndlp->nlp_flag);
6790 phba->fc_stat.elsRcvRPS++;
6791 lpfc_els_rcv_rps(vport, elsiocb, ndlp);
6796 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6797 "RCV RPL: did:x%x/ste:x%x flg:x%x",
6798 did, vport->port_state, ndlp->nlp_flag);
6800 phba->fc_stat.elsRcvRPL++;
6801 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
6806 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6807 "RCV RNID: did:x%x/ste:x%x flg:x%x",
6808 did, vport->port_state, ndlp->nlp_flag);
6810 phba->fc_stat.elsRcvRNID++;
6811 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
6816 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6817 "RCV RTV: did:x%x/ste:x%x flg:x%x",
6818 did, vport->port_state, ndlp->nlp_flag);
6819 phba->fc_stat.elsRcvRTV++;
6820 lpfc_els_rcv_rtv(vport, elsiocb, ndlp);
6825 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6826 "RCV RRQ: did:x%x/ste:x%x flg:x%x",
6827 did, vport->port_state, ndlp->nlp_flag);
6829 phba->fc_stat.elsRcvRRQ++;
6830 lpfc_els_rcv_rrq(vport, elsiocb, ndlp);
6835 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6836 "RCV ECHO: did:x%x/ste:x%x flg:x%x",
6837 did, vport->port_state, ndlp->nlp_flag);
6839 phba->fc_stat.elsRcvECHO++;
6840 lpfc_els_rcv_echo(vport, elsiocb, ndlp);
6845 /* receive this due to exchange closed */
6846 rjt_err = LSRJT_UNABLE_TPC;
6847 rjt_exp = LSEXP_INVALID_OX_RX;
6850 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6851 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
6852 cmd, did, vport->port_state);
6854 /* Unsupported ELS command, reject */
6855 rjt_err = LSRJT_CMD_UNSUPPORTED;
6856 rjt_exp = LSEXP_NOTHING_MORE;
6858 /* Unknown ELS command <elsCmd> received from NPORT <did> */
6859 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6860 "0115 Unknown ELS command x%x "
6861 "received from NPORT x%x\n", cmd, did);
6867 /* check if need to LS_RJT received ELS cmd */
6869 memset(&stat, 0, sizeof(stat));
6870 stat.un.b.lsRjtRsnCode = rjt_err;
6871 stat.un.b.lsRjtRsnCodeExp = rjt_exp;
6872 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
6876 lpfc_nlp_put(elsiocb->context1);
6877 elsiocb->context1 = NULL;
6881 if (vport && !(vport->load_flag & FC_UNLOADING))
6882 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6883 "0111 Dropping received ELS cmd "
6884 "Data: x%x x%x x%x\n",
6885 icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout);
6886 phba->fc_stat.elsRcvDrop++;
6890 * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
6891 * @phba: pointer to lpfc hba data structure.
6892 * @pring: pointer to a SLI ring.
6893 * @elsiocb: pointer to lpfc els iocb data structure.
6895 * This routine is used to process an unsolicited event received from a SLI
6896 * (Service Level Interface) ring. The actual processing of the data buffer
6897 * associated with the unsolicited event is done by invoking the routine
6898 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
6899 * SLI ring on which the unsolicited event was received.
6902 lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
6903 struct lpfc_iocbq *elsiocb)
6905 struct lpfc_vport *vport = phba->pport;
6906 IOCB_t *icmd = &elsiocb->iocb;
6908 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
6909 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
6911 elsiocb->context1 = NULL;
6912 elsiocb->context2 = NULL;
6913 elsiocb->context3 = NULL;
6915 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
6916 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
6917 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
6918 (icmd->un.ulpWord[4] & IOERR_PARAM_MASK) ==
6919 IOERR_RCV_BUFFER_WAITING) {
6920 phba->fc_stat.NoRcvBuf++;
6921 /* Not enough posted buffers; Try posting more buffers */
6922 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
6923 lpfc_post_buffer(phba, pring, 0);
6927 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
6928 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
6929 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
6930 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
6931 vport = phba->pport;
6933 vport = lpfc_find_vport_by_vpid(phba,
6934 icmd->unsli3.rcvsli3.vpi);
6937 /* If there are no BDEs associated
6938 * with this IOCB, there is nothing to do.
6940 if (icmd->ulpBdeCount == 0)
6943 /* type of ELS cmd is first 32bit word
6946 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
6947 elsiocb->context2 = bdeBuf1;
6949 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
6950 icmd->un.cont64[0].addrLow);
6951 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
6955 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
6957 * The different unsolicited event handlers would tell us
6958 * if they are done with "mp" by setting context2 to NULL.
6960 if (elsiocb->context2) {
6961 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
6962 elsiocb->context2 = NULL;
6965 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
6966 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
6967 icmd->ulpBdeCount == 2) {
6968 elsiocb->context2 = bdeBuf2;
6969 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
6970 /* free mp if we are done with it */
6971 if (elsiocb->context2) {
6972 lpfc_in_buf_free(phba, elsiocb->context2);
6973 elsiocb->context2 = NULL;
6979 * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
6980 * @phba: pointer to lpfc hba data structure.
6981 * @vport: pointer to a virtual N_Port data structure.
6983 * This routine issues a Port Login (PLOGI) to the Name Server with
6984 * State Change Request (SCR) for a @vport. This routine will create an
6985 * ndlp for the Name Server associated to the @vport if such node does
6986 * not already exist. The PLOGI to Name Server is issued by invoking the
6987 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
6988 * (FDMI) is configured to the @vport, a FDMI node will be created and
6989 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
6992 lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
6994 struct lpfc_nodelist *ndlp, *ndlp_fdmi;
6995 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6998 * If lpfc_delay_discovery parameter is set and the clean address
6999 * bit is cleared and fc fabric parameters chenged, delay FC NPort
7002 spin_lock_irq(shost->host_lock);
7003 if (vport->fc_flag & FC_DISC_DELAYED) {
7004 spin_unlock_irq(shost->host_lock);
7005 mod_timer(&vport->delayed_disc_tmo,
7006 jiffies + HZ * phba->fc_ratov);
7009 spin_unlock_irq(shost->host_lock);
7011 ndlp = lpfc_findnode_did(vport, NameServer_DID);
7013 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
7015 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
7016 lpfc_disc_start(vport);
7019 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
7020 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7021 "0251 NameServer login: no memory\n");
7024 lpfc_nlp_init(vport, ndlp, NameServer_DID);
7025 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
7026 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
7028 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
7029 lpfc_disc_start(vport);
7032 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
7033 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7034 "0348 NameServer login: node freed\n");
7038 ndlp->nlp_type |= NLP_FABRIC;
7040 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
7042 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
7043 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
7044 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7045 "0252 Cannot issue NameServer login\n");
7049 if (vport->cfg_fdmi_on) {
7050 /* If this is the first time, allocate an ndlp and initialize
7051 * it. Otherwise, make sure the node is enabled and then do the
7054 ndlp_fdmi = lpfc_findnode_did(vport, FDMI_DID);
7056 ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
7059 lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID);
7060 ndlp_fdmi->nlp_type |= NLP_FABRIC;
7064 if (!NLP_CHK_NODE_ACT(ndlp_fdmi))
7065 ndlp_fdmi = lpfc_enable_node(vport,
7070 lpfc_nlp_set_state(vport, ndlp_fdmi,
7071 NLP_STE_PLOGI_ISSUE);
7072 lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID, 0);
7078 * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
7079 * @phba: pointer to lpfc hba data structure.
7080 * @pmb: pointer to the driver internal queue element for mailbox command.
7082 * This routine is the completion callback function to register new vport
7083 * mailbox command. If the new vport mailbox command completes successfully,
7084 * the fabric registration login shall be performed on physical port (the
7085 * new vport created is actually a physical port, with VPI 0) or the port
7086 * login to Name Server for State Change Request (SCR) will be performed
7087 * on virtual port (real virtual port, with VPI greater than 0).
7090 lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
7092 struct lpfc_vport *vport = pmb->vport;
7093 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7094 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
7095 MAILBOX_t *mb = &pmb->u.mb;
7098 spin_lock_irq(shost->host_lock);
7099 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
7100 spin_unlock_irq(shost->host_lock);
7102 if (mb->mbxStatus) {
7103 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
7104 "0915 Register VPI failed : Status: x%x"
7105 " upd bit: x%x \n", mb->mbxStatus,
7106 mb->un.varRegVpi.upd);
7107 if (phba->sli_rev == LPFC_SLI_REV4 &&
7108 mb->un.varRegVpi.upd)
7109 goto mbox_err_exit ;
7111 switch (mb->mbxStatus) {
7112 case 0x11: /* unsupported feature */
7113 case 0x9603: /* max_vpi exceeded */
7114 case 0x9602: /* Link event since CLEAR_LA */
7115 /* giving up on vport registration */
7116 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
7117 spin_lock_irq(shost->host_lock);
7118 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
7119 spin_unlock_irq(shost->host_lock);
7120 lpfc_can_disctmo(vport);
7122 /* If reg_vpi fail with invalid VPI status, re-init VPI */
7124 spin_lock_irq(shost->host_lock);
7125 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
7126 spin_unlock_irq(shost->host_lock);
7127 lpfc_init_vpi(phba, pmb, vport->vpi);
7129 pmb->mbox_cmpl = lpfc_init_vpi_cmpl;
7130 rc = lpfc_sli_issue_mbox(phba, pmb,
7132 if (rc == MBX_NOT_FINISHED) {
7133 lpfc_printf_vlog(vport,
7135 "2732 Failed to issue INIT_VPI"
7136 " mailbox command\n");
7143 /* Try to recover from this error */
7144 if (phba->sli_rev == LPFC_SLI_REV4)
7145 lpfc_sli4_unreg_all_rpis(vport);
7146 lpfc_mbx_unreg_vpi(vport);
7147 spin_lock_irq(shost->host_lock);
7148 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
7149 spin_unlock_irq(shost->host_lock);
7150 if (vport->port_type == LPFC_PHYSICAL_PORT
7151 && !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG))
7152 lpfc_issue_init_vfi(vport);
7154 lpfc_initial_fdisc(vport);
7158 spin_lock_irq(shost->host_lock);
7159 vport->vpi_state |= LPFC_VPI_REGISTERED;
7160 spin_unlock_irq(shost->host_lock);
7161 if (vport == phba->pport) {
7162 if (phba->sli_rev < LPFC_SLI_REV4)
7163 lpfc_issue_fabric_reglogin(vport);
7166 * If the physical port is instantiated using
7167 * FDISC, do not start vport discovery.
7169 if (vport->port_state != LPFC_FDISC)
7170 lpfc_start_fdiscs(phba);
7171 lpfc_do_scr_ns_plogi(phba, vport);
7174 lpfc_do_scr_ns_plogi(phba, vport);
7177 /* Now, we decrement the ndlp reference count held for this
7182 mempool_free(pmb, phba->mbox_mem_pool);
7187 * lpfc_register_new_vport - Register a new vport with a HBA
7188 * @phba: pointer to lpfc hba data structure.
7189 * @vport: pointer to a host virtual N_Port data structure.
7190 * @ndlp: pointer to a node-list data structure.
7192 * This routine registers the @vport as a new virtual port with a HBA.
7193 * It is done through a registering vpi mailbox command.
7196 lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
7197 struct lpfc_nodelist *ndlp)
7199 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7202 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
7204 lpfc_reg_vpi(vport, mbox);
7205 mbox->vport = vport;
7206 mbox->context2 = lpfc_nlp_get(ndlp);
7207 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
7208 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
7209 == MBX_NOT_FINISHED) {
7210 /* mailbox command not success, decrement ndlp
7211 * reference count for this command
7214 mempool_free(mbox, phba->mbox_mem_pool);
7216 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
7217 "0253 Register VPI: Can't send mbox\n");
7221 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
7222 "0254 Register VPI: no memory\n");
7228 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
7229 spin_lock_irq(shost->host_lock);
7230 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
7231 spin_unlock_irq(shost->host_lock);
7236 * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer
7237 * @phba: pointer to lpfc hba data structure.
7239 * This routine cancels the retry delay timers to all the vports.
7242 lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba)
7244 struct lpfc_vport **vports;
7245 struct lpfc_nodelist *ndlp;
7246 uint32_t link_state;
7249 /* Treat this failure as linkdown for all vports */
7250 link_state = phba->link_state;
7251 lpfc_linkdown(phba);
7252 phba->link_state = link_state;
7254 vports = lpfc_create_vport_work_array(phba);
7257 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
7258 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
7260 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
7261 lpfc_els_flush_cmd(vports[i]);
7263 lpfc_destroy_vport_work_array(phba, vports);
7268 * lpfc_retry_pport_discovery - Start timer to retry FLOGI.
7269 * @phba: pointer to lpfc hba data structure.
7271 * This routine abort all pending discovery commands and
7272 * start a timer to retry FLOGI for the physical port
7276 lpfc_retry_pport_discovery(struct lpfc_hba *phba)
7278 struct lpfc_nodelist *ndlp;
7279 struct Scsi_Host *shost;
7281 /* Cancel the all vports retry delay retry timers */
7282 lpfc_cancel_all_vport_retry_delay_timer(phba);
7284 /* If fabric require FLOGI, then re-instantiate physical login */
7285 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
7289 shost = lpfc_shost_from_vport(phba->pport);
7290 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
7291 spin_lock_irq(shost->host_lock);
7292 ndlp->nlp_flag |= NLP_DELAY_TMO;
7293 spin_unlock_irq(shost->host_lock);
7294 ndlp->nlp_last_elscmd = ELS_CMD_FLOGI;
7295 phba->pport->port_state = LPFC_FLOGI;
7300 * lpfc_fabric_login_reqd - Check if FLOGI required.
7301 * @phba: pointer to lpfc hba data structure.
7302 * @cmdiocb: pointer to FDISC command iocb.
7303 * @rspiocb: pointer to FDISC response iocb.
7305 * This routine checks if a FLOGI is reguired for FDISC
7309 lpfc_fabric_login_reqd(struct lpfc_hba *phba,
7310 struct lpfc_iocbq *cmdiocb,
7311 struct lpfc_iocbq *rspiocb)
7314 if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) ||
7315 (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED))
7322 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
7323 * @phba: pointer to lpfc hba data structure.
7324 * @cmdiocb: pointer to lpfc command iocb data structure.
7325 * @rspiocb: pointer to lpfc response iocb data structure.
7327 * This routine is the completion callback function to a Fabric Discover
7328 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
7329 * single threaded, each FDISC completion callback function will reset
7330 * the discovery timer for all vports such that the timers will not get
7331 * unnecessary timeout. The function checks the FDISC IOCB status. If error
7332 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
7333 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
7334 * assigned to the vport has been changed with the completion of the FDISC
7335 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
7336 * are unregistered from the HBA, and then the lpfc_register_new_vport()
7337 * routine is invoked to register new vport with the HBA. Otherwise, the
7338 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
7339 * Server for State Change Request (SCR).
7342 lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
7343 struct lpfc_iocbq *rspiocb)
7345 struct lpfc_vport *vport = cmdiocb->vport;
7346 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7347 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
7348 struct lpfc_nodelist *np;
7349 struct lpfc_nodelist *next_np;
7350 IOCB_t *irsp = &rspiocb->iocb;
7351 struct lpfc_iocbq *piocb;
7352 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
7353 struct serv_parm *sp;
7354 uint8_t fabric_param_changed;
7356 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7357 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
7358 irsp->ulpStatus, irsp->un.ulpWord[4],
7360 /* Since all FDISCs are being single threaded, we
7361 * must reset the discovery timer for ALL vports
7362 * waiting to send FDISC when one completes.
7364 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
7365 lpfc_set_disctmo(piocb->vport);
7368 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7369 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
7370 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
7372 if (irsp->ulpStatus) {
7374 if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) {
7375 lpfc_retry_pport_discovery(phba);
7379 /* Check for retry */
7380 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
7383 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7384 "0126 FDISC failed. (x%x/x%x)\n",
7385 irsp->ulpStatus, irsp->un.ulpWord[4]);
7388 spin_lock_irq(shost->host_lock);
7389 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
7390 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
7391 vport->fc_flag |= FC_FABRIC;
7392 if (vport->phba->fc_topology == LPFC_TOPOLOGY_LOOP)
7393 vport->fc_flag |= FC_PUBLIC_LOOP;
7394 spin_unlock_irq(shost->host_lock);
7396 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
7397 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
7398 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
7399 sp = prsp->virt + sizeof(uint32_t);
7400 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
7401 memcpy(&vport->fabric_portname, &sp->portName,
7402 sizeof(struct lpfc_name));
7403 memcpy(&vport->fabric_nodename, &sp->nodeName,
7404 sizeof(struct lpfc_name));
7405 if (fabric_param_changed &&
7406 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
7407 /* If our NportID changed, we need to ensure all
7408 * remaining NPORTs get unreg_login'ed so we can
7411 list_for_each_entry_safe(np, next_np,
7412 &vport->fc_nodes, nlp_listp) {
7413 if (!NLP_CHK_NODE_ACT(ndlp) ||
7414 (np->nlp_state != NLP_STE_NPR_NODE) ||
7415 !(np->nlp_flag & NLP_NPR_ADISC))
7417 spin_lock_irq(shost->host_lock);
7418 np->nlp_flag &= ~NLP_NPR_ADISC;
7419 spin_unlock_irq(shost->host_lock);
7420 lpfc_unreg_rpi(vport, np);
7422 lpfc_cleanup_pending_mbox(vport);
7424 if (phba->sli_rev == LPFC_SLI_REV4)
7425 lpfc_sli4_unreg_all_rpis(vport);
7427 lpfc_mbx_unreg_vpi(vport);
7428 spin_lock_irq(shost->host_lock);
7429 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
7430 if (phba->sli_rev == LPFC_SLI_REV4)
7431 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
7433 vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG;
7434 spin_unlock_irq(shost->host_lock);
7435 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
7436 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
7438 * Driver needs to re-reg VPI in order for f/w
7439 * to update the MAC address.
7441 lpfc_register_new_vport(phba, vport, ndlp);
7445 if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)
7446 lpfc_issue_init_vpi(vport);
7447 else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
7448 lpfc_register_new_vport(phba, vport, ndlp);
7450 lpfc_do_scr_ns_plogi(phba, vport);
7453 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
7454 /* Cancel discovery timer */
7455 lpfc_can_disctmo(vport);
7458 lpfc_els_free_iocb(phba, cmdiocb);
7462 * lpfc_issue_els_fdisc - Issue a fdisc iocb command
7463 * @vport: pointer to a virtual N_Port data structure.
7464 * @ndlp: pointer to a node-list data structure.
7465 * @retry: number of retries to the command IOCB.
7467 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
7468 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
7469 * routine to issue the IOCB, which makes sure only one outstanding fabric
7470 * IOCB will be sent off HBA at any given time.
7472 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7473 * will be incremented by 1 for holding the ndlp and the reference to ndlp
7474 * will be stored into the context1 field of the IOCB for the completion
7475 * callback function to the FDISC ELS command.
7478 * 0 - Successfully issued fdisc iocb command
7479 * 1 - Failed to issue fdisc iocb command
7482 lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
7485 struct lpfc_hba *phba = vport->phba;
7487 struct lpfc_iocbq *elsiocb;
7488 struct serv_parm *sp;
7491 int did = ndlp->nlp_DID;
7494 vport->port_state = LPFC_FDISC;
7495 vport->fc_myDID = 0;
7496 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
7497 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
7500 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
7501 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7502 "0255 Issue FDISC: no IOCB\n");
7506 icmd = &elsiocb->iocb;
7507 icmd->un.elsreq64.myID = 0;
7508 icmd->un.elsreq64.fl = 1;
7511 * SLI3 ports require a different context type value than SLI4.
7512 * Catch SLI3 ports here and override the prep.
7514 if (phba->sli_rev == LPFC_SLI_REV3) {
7519 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7520 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
7521 pcmd += sizeof(uint32_t); /* CSP Word 1 */
7522 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
7523 sp = (struct serv_parm *) pcmd;
7524 /* Setup CSPs accordingly for Fabric */
7525 sp->cmn.e_d_tov = 0;
7526 sp->cmn.w2.r_a_tov = 0;
7527 sp->cmn.virtual_fabric_support = 0;
7528 sp->cls1.classValid = 0;
7529 sp->cls2.seqDelivery = 1;
7530 sp->cls3.seqDelivery = 1;
7532 pcmd += sizeof(uint32_t); /* CSP Word 2 */
7533 pcmd += sizeof(uint32_t); /* CSP Word 3 */
7534 pcmd += sizeof(uint32_t); /* CSP Word 4 */
7535 pcmd += sizeof(uint32_t); /* Port Name */
7536 memcpy(pcmd, &vport->fc_portname, 8);
7537 pcmd += sizeof(uint32_t); /* Node Name */
7538 pcmd += sizeof(uint32_t); /* Node Name */
7539 memcpy(pcmd, &vport->fc_nodename, 8);
7541 lpfc_set_disctmo(vport);
7543 phba->fc_stat.elsXmitFDISC++;
7544 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
7546 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7547 "Issue FDISC: did:x%x",
7550 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
7551 if (rc == IOCB_ERROR) {
7552 lpfc_els_free_iocb(phba, elsiocb);
7553 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
7554 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7555 "0256 Issue FDISC: Cannot send IOCB\n");
7558 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
7563 * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
7564 * @phba: pointer to lpfc hba data structure.
7565 * @cmdiocb: pointer to lpfc command iocb data structure.
7566 * @rspiocb: pointer to lpfc response iocb data structure.
7568 * This routine is the completion callback function to the issuing of a LOGO
7569 * ELS command off a vport. It frees the command IOCB and then decrement the
7570 * reference count held on ndlp for this completion function, indicating that
7571 * the reference to the ndlp is no long needed. Note that the
7572 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
7573 * callback function and an additional explicit ndlp reference decrementation
7574 * will trigger the actual release of the ndlp.
7577 lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
7578 struct lpfc_iocbq *rspiocb)
7580 struct lpfc_vport *vport = cmdiocb->vport;
7582 struct lpfc_nodelist *ndlp;
7583 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7585 ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
7586 irsp = &rspiocb->iocb;
7587 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7588 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
7589 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
7591 lpfc_els_free_iocb(phba, cmdiocb);
7592 vport->unreg_vpi_cmpl = VPORT_ERROR;
7594 /* Trigger the release of the ndlp after logo */
7597 /* NPIV LOGO completes to NPort <nlp_DID> */
7598 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7599 "2928 NPIV LOGO completes to NPort x%x "
7600 "Data: x%x x%x x%x x%x\n",
7601 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
7602 irsp->ulpTimeout, vport->num_disc_nodes);
7604 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
7605 spin_lock_irq(shost->host_lock);
7606 vport->fc_flag &= ~FC_FABRIC;
7607 spin_unlock_irq(shost->host_lock);
7612 * lpfc_issue_els_npiv_logo - Issue a logo off a vport
7613 * @vport: pointer to a virtual N_Port data structure.
7614 * @ndlp: pointer to a node-list data structure.
7616 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
7618 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7619 * will be incremented by 1 for holding the ndlp and the reference to ndlp
7620 * will be stored into the context1 field of the IOCB for the completion
7621 * callback function to the LOGO ELS command.
7624 * 0 - Successfully issued logo off the @vport
7625 * 1 - Failed to issue logo off the @vport
7628 lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
7630 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7631 struct lpfc_hba *phba = vport->phba;
7633 struct lpfc_iocbq *elsiocb;
7637 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
7638 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
7643 icmd = &elsiocb->iocb;
7644 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7645 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
7646 pcmd += sizeof(uint32_t);
7648 /* Fill in LOGO payload */
7649 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
7650 pcmd += sizeof(uint32_t);
7651 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
7653 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7654 "Issue LOGO npiv did:x%x flg:x%x",
7655 ndlp->nlp_DID, ndlp->nlp_flag, 0);
7657 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
7658 spin_lock_irq(shost->host_lock);
7659 ndlp->nlp_flag |= NLP_LOGO_SND;
7660 spin_unlock_irq(shost->host_lock);
7661 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
7663 spin_lock_irq(shost->host_lock);
7664 ndlp->nlp_flag &= ~NLP_LOGO_SND;
7665 spin_unlock_irq(shost->host_lock);
7666 lpfc_els_free_iocb(phba, elsiocb);
7673 * lpfc_fabric_block_timeout - Handler function to the fabric block timer
7674 * @ptr: holder for the timer function associated data.
7676 * This routine is invoked by the fabric iocb block timer after
7677 * timeout. It posts the fabric iocb block timeout event by setting the
7678 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
7679 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
7680 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
7681 * posted event WORKER_FABRIC_BLOCK_TMO.
7684 lpfc_fabric_block_timeout(unsigned long ptr)
7686 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
7687 unsigned long iflags;
7688 uint32_t tmo_posted;
7690 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
7691 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
7693 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
7694 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
7697 lpfc_worker_wake_up(phba);
7702 * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
7703 * @phba: pointer to lpfc hba data structure.
7705 * This routine issues one fabric iocb from the driver internal list to
7706 * the HBA. It first checks whether it's ready to issue one fabric iocb to
7707 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
7708 * remove one pending fabric iocb from the driver internal list and invokes
7709 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
7712 lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
7714 struct lpfc_iocbq *iocb;
7715 unsigned long iflags;
7721 spin_lock_irqsave(&phba->hbalock, iflags);
7722 /* Post any pending iocb to the SLI layer */
7723 if (atomic_read(&phba->fabric_iocb_count) == 0) {
7724 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
7727 /* Increment fabric iocb count to hold the position */
7728 atomic_inc(&phba->fabric_iocb_count);
7730 spin_unlock_irqrestore(&phba->hbalock, iflags);
7732 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
7733 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
7734 iocb->iocb_flag |= LPFC_IO_FABRIC;
7736 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
7737 "Fabric sched1: ste:x%x",
7738 iocb->vport->port_state, 0, 0);
7740 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
7742 if (ret == IOCB_ERROR) {
7743 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
7744 iocb->fabric_iocb_cmpl = NULL;
7745 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
7747 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
7748 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
7749 iocb->iocb_cmpl(phba, iocb, iocb);
7751 atomic_dec(&phba->fabric_iocb_count);
7760 * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
7761 * @phba: pointer to lpfc hba data structure.
7763 * This routine unblocks the issuing fabric iocb command. The function
7764 * will clear the fabric iocb block bit and then invoke the routine
7765 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
7766 * from the driver internal fabric iocb list.
7769 lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
7771 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
7773 lpfc_resume_fabric_iocbs(phba);
7778 * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
7779 * @phba: pointer to lpfc hba data structure.
7781 * This routine blocks the issuing fabric iocb for a specified amount of
7782 * time (currently 100 ms). This is done by set the fabric iocb block bit
7783 * and set up a timeout timer for 100ms. When the block bit is set, no more
7784 * fabric iocb will be issued out of the HBA.
7787 lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
7791 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
7792 /* Start a timer to unblock fabric iocbs after 100ms */
7794 mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 );
7800 * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
7801 * @phba: pointer to lpfc hba data structure.
7802 * @cmdiocb: pointer to lpfc command iocb data structure.
7803 * @rspiocb: pointer to lpfc response iocb data structure.
7805 * This routine is the callback function that is put to the fabric iocb's
7806 * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
7807 * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
7808 * function first restores and invokes the original iocb's callback function
7809 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
7810 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
7813 lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
7814 struct lpfc_iocbq *rspiocb)
7818 if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC)
7821 switch (rspiocb->iocb.ulpStatus) {
7822 case IOSTAT_NPORT_RJT:
7823 case IOSTAT_FABRIC_RJT:
7824 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
7825 lpfc_block_fabric_iocbs(phba);
7829 case IOSTAT_NPORT_BSY:
7830 case IOSTAT_FABRIC_BSY:
7831 lpfc_block_fabric_iocbs(phba);
7835 stat.un.lsRjtError =
7836 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
7837 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
7838 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
7839 lpfc_block_fabric_iocbs(phba);
7843 if (atomic_read(&phba->fabric_iocb_count) == 0)
7846 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
7847 cmdiocb->fabric_iocb_cmpl = NULL;
7848 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
7849 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
7851 atomic_dec(&phba->fabric_iocb_count);
7852 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
7853 /* Post any pending iocbs to HBA */
7854 lpfc_resume_fabric_iocbs(phba);
7859 * lpfc_issue_fabric_iocb - Issue a fabric iocb command
7860 * @phba: pointer to lpfc hba data structure.
7861 * @iocb: pointer to lpfc command iocb data structure.
7863 * This routine is used as the top-level API for issuing a fabric iocb command
7864 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
7865 * function makes sure that only one fabric bound iocb will be outstanding at
7866 * any given time. As such, this function will first check to see whether there
7867 * is already an outstanding fabric iocb on the wire. If so, it will put the
7868 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
7869 * issued later. Otherwise, it will issue the iocb on the wire and update the
7870 * fabric iocb count it indicate that there is one fabric iocb on the wire.
7872 * Note, this implementation has a potential sending out fabric IOCBs out of
7873 * order. The problem is caused by the construction of the "ready" boolen does
7874 * not include the condition that the internal fabric IOCB list is empty. As
7875 * such, it is possible a fabric IOCB issued by this routine might be "jump"
7876 * ahead of the fabric IOCBs in the internal list.
7879 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
7880 * IOCB_ERROR - failed to issue fabric iocb
7883 lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
7885 unsigned long iflags;
7889 if (atomic_read(&phba->fabric_iocb_count) > 1)
7892 spin_lock_irqsave(&phba->hbalock, iflags);
7893 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
7894 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
7897 /* Increment fabric iocb count to hold the position */
7898 atomic_inc(&phba->fabric_iocb_count);
7899 spin_unlock_irqrestore(&phba->hbalock, iflags);
7901 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
7902 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
7903 iocb->iocb_flag |= LPFC_IO_FABRIC;
7905 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
7906 "Fabric sched2: ste:x%x",
7907 iocb->vport->port_state, 0, 0);
7909 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
7911 if (ret == IOCB_ERROR) {
7912 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
7913 iocb->fabric_iocb_cmpl = NULL;
7914 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
7915 atomic_dec(&phba->fabric_iocb_count);
7918 spin_lock_irqsave(&phba->hbalock, iflags);
7919 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
7920 spin_unlock_irqrestore(&phba->hbalock, iflags);
7927 * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
7928 * @vport: pointer to a virtual N_Port data structure.
7930 * This routine aborts all the IOCBs associated with a @vport from the
7931 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
7932 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
7933 * list, removes each IOCB associated with the @vport off the list, set the
7934 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
7935 * associated with the IOCB.
7937 static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
7939 LIST_HEAD(completions);
7940 struct lpfc_hba *phba = vport->phba;
7941 struct lpfc_iocbq *tmp_iocb, *piocb;
7943 spin_lock_irq(&phba->hbalock);
7944 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
7947 if (piocb->vport != vport)
7950 list_move_tail(&piocb->list, &completions);
7952 spin_unlock_irq(&phba->hbalock);
7954 /* Cancel all the IOCBs from the completions list */
7955 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
7960 * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
7961 * @ndlp: pointer to a node-list data structure.
7963 * This routine aborts all the IOCBs associated with an @ndlp from the
7964 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
7965 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
7966 * list, removes each IOCB associated with the @ndlp off the list, set the
7967 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
7968 * associated with the IOCB.
7970 void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
7972 LIST_HEAD(completions);
7973 struct lpfc_hba *phba = ndlp->phba;
7974 struct lpfc_iocbq *tmp_iocb, *piocb;
7975 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
7977 spin_lock_irq(&phba->hbalock);
7978 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
7980 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
7982 list_move_tail(&piocb->list, &completions);
7985 spin_unlock_irq(&phba->hbalock);
7987 /* Cancel all the IOCBs from the completions list */
7988 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
7993 * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
7994 * @phba: pointer to lpfc hba data structure.
7996 * This routine aborts all the IOCBs currently on the driver internal
7997 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
7998 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
7999 * list, removes IOCBs off the list, set the status feild to
8000 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
8003 void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
8005 LIST_HEAD(completions);
8007 spin_lock_irq(&phba->hbalock);
8008 list_splice_init(&phba->fabric_iocb_list, &completions);
8009 spin_unlock_irq(&phba->hbalock);
8011 /* Cancel all the IOCBs from the completions list */
8012 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
8017 * lpfc_sli4_vport_delete_els_xri_aborted -Remove all ndlp references for vport
8018 * @vport: pointer to lpfc vport data structure.
8020 * This routine is invoked by the vport cleanup for deletions and the cleanup
8021 * for an ndlp on removal.
8024 lpfc_sli4_vport_delete_els_xri_aborted(struct lpfc_vport *vport)
8026 struct lpfc_hba *phba = vport->phba;
8027 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
8028 unsigned long iflag = 0;
8030 spin_lock_irqsave(&phba->hbalock, iflag);
8031 spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
8032 list_for_each_entry_safe(sglq_entry, sglq_next,
8033 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
8034 if (sglq_entry->ndlp && sglq_entry->ndlp->vport == vport)
8035 sglq_entry->ndlp = NULL;
8037 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
8038 spin_unlock_irqrestore(&phba->hbalock, iflag);
8043 * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
8044 * @phba: pointer to lpfc hba data structure.
8045 * @axri: pointer to the els xri abort wcqe structure.
8047 * This routine is invoked by the worker thread to process a SLI4 slow-path
8051 lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba,
8052 struct sli4_wcqe_xri_aborted *axri)
8054 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
8055 uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri);
8058 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
8059 unsigned long iflag = 0;
8060 struct lpfc_nodelist *ndlp;
8061 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
8063 spin_lock_irqsave(&phba->hbalock, iflag);
8064 spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
8065 list_for_each_entry_safe(sglq_entry, sglq_next,
8066 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
8067 if (sglq_entry->sli4_xritag == xri) {
8068 list_del(&sglq_entry->list);
8069 ndlp = sglq_entry->ndlp;
8070 sglq_entry->ndlp = NULL;
8071 list_add_tail(&sglq_entry->list,
8072 &phba->sli4_hba.lpfc_sgl_list);
8073 sglq_entry->state = SGL_FREED;
8074 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
8075 spin_unlock_irqrestore(&phba->hbalock, iflag);
8076 lpfc_set_rrq_active(phba, ndlp,
8077 sglq_entry->sli4_lxritag,
8080 /* Check if TXQ queue needs to be serviced */
8081 if (!(list_empty(&pring->txq)))
8082 lpfc_worker_wake_up(phba);
8086 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
8087 lxri = lpfc_sli4_xri_inrange(phba, xri);
8088 if (lxri == NO_XRI) {
8089 spin_unlock_irqrestore(&phba->hbalock, iflag);
8092 sglq_entry = __lpfc_get_active_sglq(phba, lxri);
8093 if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) {
8094 spin_unlock_irqrestore(&phba->hbalock, iflag);
8097 sglq_entry->state = SGL_XRI_ABORTED;
8098 spin_unlock_irqrestore(&phba->hbalock, iflag);
8102 /* lpfc_sli_abts_recover_port - Recover a port that failed a BLS_ABORT req.
8103 * @vport: pointer to virtual port object.
8104 * @ndlp: nodelist pointer for the impacted node.
8106 * The driver calls this routine in response to an SLI4 XRI ABORT CQE
8107 * or an SLI3 ASYNC_STATUS_CN event from the port. For either event,
8108 * the driver is required to send a LOGO to the remote node before it
8109 * attempts to recover its login to the remote node.
8112 lpfc_sli_abts_recover_port(struct lpfc_vport *vport,
8113 struct lpfc_nodelist *ndlp)
8115 struct Scsi_Host *shost;
8116 struct lpfc_hba *phba;
8117 unsigned long flags = 0;
8119 shost = lpfc_shost_from_vport(vport);
8121 if (ndlp->nlp_state != NLP_STE_MAPPED_NODE) {
8122 lpfc_printf_log(phba, KERN_INFO,
8123 LOG_SLI, "3093 No rport recovery needed. "
8124 "rport in state 0x%x\n", ndlp->nlp_state);
8127 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
8128 "3094 Start rport recovery on shost id 0x%x "
8129 "fc_id 0x%06x vpi 0x%x rpi 0x%x state 0x%x "
8131 shost->host_no, ndlp->nlp_DID,
8132 vport->vpi, ndlp->nlp_rpi, ndlp->nlp_state,
8135 * The rport is not responding. Remove the FCP-2 flag to prevent
8136 * an ADISC in the follow-up recovery code.
8138 spin_lock_irqsave(shost->host_lock, flags);
8139 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
8140 spin_unlock_irqrestore(shost->host_lock, flags);
8141 lpfc_issue_els_logo(vport, ndlp, 0);
8142 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);