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);
487 mboxq->mbox_cmpl = lpfc_mbx_cmpl_reg_vfi;
488 mboxq->vport = vport;
489 mboxq->context1 = dmabuf;
490 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
491 if (rc == MBX_NOT_FINISHED) {
498 mempool_free(mboxq, phba->mbox_mem_pool);
500 lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys);
504 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
505 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
506 "0289 Issue Register VFI failed: Err %d\n", rc);
511 * lpfc_issue_unreg_vfi - Unregister VFI for this vport's fabric login
512 * @vport: pointer to a host virtual N_Port data structure.
514 * This routine issues a UNREG_VFI mailbox with the vfi, vpi, fcfi triplet for
515 * the @vport. This mailbox command is necessary for SLI4 port only.
518 * 0 - successfully issued REG_VFI for @vport
519 * A failure code otherwise.
522 lpfc_issue_unreg_vfi(struct lpfc_vport *vport)
524 struct lpfc_hba *phba = vport->phba;
525 struct Scsi_Host *shost;
529 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
531 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
532 "2556 UNREG_VFI mbox allocation failed"
533 "HBA state x%x\n", phba->pport->port_state);
537 lpfc_unreg_vfi(mboxq, vport);
538 mboxq->vport = vport;
539 mboxq->mbox_cmpl = lpfc_unregister_vfi_cmpl;
541 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
542 if (rc == MBX_NOT_FINISHED) {
543 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
544 "2557 UNREG_VFI issue mbox failed rc x%x "
546 rc, phba->pport->port_state);
547 mempool_free(mboxq, phba->mbox_mem_pool);
551 shost = lpfc_shost_from_vport(vport);
552 spin_lock_irq(shost->host_lock);
553 vport->fc_flag &= ~FC_VFI_REGISTERED;
554 spin_unlock_irq(shost->host_lock);
559 * lpfc_check_clean_addr_bit - Check whether assigned FCID is clean.
560 * @vport: pointer to a host virtual N_Port data structure.
561 * @sp: pointer to service parameter data structure.
563 * This routine is called from FLOGI/FDISC completion handler functions.
564 * lpfc_check_clean_addr_bit return 1 when FCID/Fabric portname/ Fabric
565 * node nodename is changed in the completion service parameter else return
566 * 0. This function also set flag in the vport data structure to delay
567 * NP_Port discovery after the FLOGI/FDISC completion if Clean address bit
568 * in FLOGI/FDISC response is cleared and FCID/Fabric portname/ Fabric
569 * node nodename is changed in the completion service parameter.
572 * 0 - FCID and Fabric Nodename and Fabric portname is not changed.
573 * 1 - FCID or Fabric Nodename or Fabric portname is changed.
577 lpfc_check_clean_addr_bit(struct lpfc_vport *vport,
578 struct serv_parm *sp)
580 uint8_t fabric_param_changed = 0;
581 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
583 if ((vport->fc_prevDID != vport->fc_myDID) ||
584 memcmp(&vport->fabric_portname, &sp->portName,
585 sizeof(struct lpfc_name)) ||
586 memcmp(&vport->fabric_nodename, &sp->nodeName,
587 sizeof(struct lpfc_name)))
588 fabric_param_changed = 1;
591 * Word 1 Bit 31 in common service parameter is overloaded.
592 * Word 1 Bit 31 in FLOGI request is multiple NPort request
593 * Word 1 Bit 31 in FLOGI response is clean address bit
595 * If fabric parameter is changed and clean address bit is
596 * cleared delay nport discovery if
597 * - vport->fc_prevDID != 0 (not initial discovery) OR
598 * - lpfc_delay_discovery module parameter is set.
600 if (fabric_param_changed && !sp->cmn.clean_address_bit &&
601 (vport->fc_prevDID || lpfc_delay_discovery)) {
602 spin_lock_irq(shost->host_lock);
603 vport->fc_flag |= FC_DISC_DELAYED;
604 spin_unlock_irq(shost->host_lock);
607 return fabric_param_changed;
612 * lpfc_cmpl_els_flogi_fabric - Completion function for flogi to a fabric port
613 * @vport: pointer to a host virtual N_Port data structure.
614 * @ndlp: pointer to a node-list data structure.
615 * @sp: pointer to service parameter data structure.
616 * @irsp: pointer to the IOCB within the lpfc response IOCB.
618 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
619 * function to handle the completion of a Fabric Login (FLOGI) into a fabric
620 * port in a fabric topology. It properly sets up the parameters to the @ndlp
621 * from the IOCB response. It also check the newly assigned N_Port ID to the
622 * @vport against the previously assigned N_Port ID. If it is different from
623 * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine
624 * is invoked on all the remaining nodes with the @vport to unregister the
625 * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin()
626 * is invoked to register login to the fabric.
629 * 0 - Success (currently, always return 0)
632 lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
633 struct serv_parm *sp, IOCB_t *irsp)
635 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
636 struct lpfc_hba *phba = vport->phba;
637 struct lpfc_nodelist *np;
638 struct lpfc_nodelist *next_np;
639 uint8_t fabric_param_changed;
641 spin_lock_irq(shost->host_lock);
642 vport->fc_flag |= FC_FABRIC;
643 spin_unlock_irq(shost->host_lock);
645 phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
646 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
647 phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
649 phba->fc_edtovResol = sp->cmn.edtovResolution;
650 phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
652 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
653 spin_lock_irq(shost->host_lock);
654 vport->fc_flag |= FC_PUBLIC_LOOP;
655 spin_unlock_irq(shost->host_lock);
658 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
659 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
660 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name));
661 ndlp->nlp_class_sup = 0;
662 if (sp->cls1.classValid)
663 ndlp->nlp_class_sup |= FC_COS_CLASS1;
664 if (sp->cls2.classValid)
665 ndlp->nlp_class_sup |= FC_COS_CLASS2;
666 if (sp->cls3.classValid)
667 ndlp->nlp_class_sup |= FC_COS_CLASS3;
668 if (sp->cls4.classValid)
669 ndlp->nlp_class_sup |= FC_COS_CLASS4;
670 ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
671 sp->cmn.bbRcvSizeLsb;
673 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
674 memcpy(&vport->fabric_portname, &sp->portName,
675 sizeof(struct lpfc_name));
676 memcpy(&vport->fabric_nodename, &sp->nodeName,
677 sizeof(struct lpfc_name));
678 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
680 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
681 if (sp->cmn.response_multiple_NPort) {
682 lpfc_printf_vlog(vport, KERN_WARNING,
684 "1816 FLOGI NPIV supported, "
685 "response data 0x%x\n",
686 sp->cmn.response_multiple_NPort);
687 spin_lock_irq(&phba->hbalock);
688 phba->link_flag |= LS_NPIV_FAB_SUPPORTED;
689 spin_unlock_irq(&phba->hbalock);
691 /* Because we asked f/w for NPIV it still expects us
692 to call reg_vnpid atleast for the physcial host */
693 lpfc_printf_vlog(vport, KERN_WARNING,
695 "1817 Fabric does not support NPIV "
696 "- configuring single port mode.\n");
697 spin_lock_irq(&phba->hbalock);
698 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
699 spin_unlock_irq(&phba->hbalock);
703 if (fabric_param_changed &&
704 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
706 /* If our NportID changed, we need to ensure all
707 * remaining NPORTs get unreg_login'ed.
709 list_for_each_entry_safe(np, next_np,
710 &vport->fc_nodes, nlp_listp) {
711 if (!NLP_CHK_NODE_ACT(np))
713 if ((np->nlp_state != NLP_STE_NPR_NODE) ||
714 !(np->nlp_flag & NLP_NPR_ADISC))
716 spin_lock_irq(shost->host_lock);
717 np->nlp_flag &= ~NLP_NPR_ADISC;
718 spin_unlock_irq(shost->host_lock);
719 lpfc_unreg_rpi(vport, np);
721 lpfc_cleanup_pending_mbox(vport);
723 if (phba->sli_rev == LPFC_SLI_REV4) {
724 lpfc_sli4_unreg_all_rpis(vport);
725 lpfc_mbx_unreg_vpi(vport);
726 spin_lock_irq(shost->host_lock);
727 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
728 spin_unlock_irq(shost->host_lock);
732 * For SLI3 and SLI4, the VPI needs to be reregistered in
733 * response to this fabric parameter change event.
735 spin_lock_irq(shost->host_lock);
736 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
737 spin_unlock_irq(shost->host_lock);
738 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
739 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
741 * Driver needs to re-reg VPI in order for f/w
742 * to update the MAC address.
744 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
745 lpfc_register_new_vport(phba, vport, ndlp);
749 if (phba->sli_rev < LPFC_SLI_REV4) {
750 lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
751 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED &&
752 vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
753 lpfc_register_new_vport(phba, vport, ndlp);
755 lpfc_issue_fabric_reglogin(vport);
757 ndlp->nlp_type |= NLP_FABRIC;
758 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
759 if ((!(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) &&
760 (vport->vpi_state & LPFC_VPI_REGISTERED)) {
761 lpfc_start_fdiscs(phba);
762 lpfc_do_scr_ns_plogi(phba, vport);
763 } else if (vport->fc_flag & FC_VFI_REGISTERED)
764 lpfc_issue_init_vpi(vport);
766 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
767 "3135 Need register VFI: (x%x/%x)\n",
768 vport->fc_prevDID, vport->fc_myDID);
769 lpfc_issue_reg_vfi(vport);
776 * lpfc_cmpl_els_flogi_nport - Completion function for flogi to an N_Port
777 * @vport: pointer to a host virtual N_Port data structure.
778 * @ndlp: pointer to a node-list data structure.
779 * @sp: pointer to service parameter data structure.
781 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
782 * function to handle the completion of a Fabric Login (FLOGI) into an N_Port
783 * in a point-to-point topology. First, the @vport's N_Port Name is compared
784 * with the received N_Port Name: if the @vport's N_Port Name is greater than
785 * the received N_Port Name lexicographically, this node shall assign local
786 * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and
787 * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise,
788 * this node shall just wait for the remote node to issue PLOGI and assign
796 lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
797 struct serv_parm *sp)
799 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
800 struct lpfc_hba *phba = vport->phba;
804 spin_lock_irq(shost->host_lock);
805 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
806 spin_unlock_irq(shost->host_lock);
808 phba->fc_edtov = FF_DEF_EDTOV;
809 phba->fc_ratov = FF_DEF_RATOV;
810 rc = memcmp(&vport->fc_portname, &sp->portName,
811 sizeof(vport->fc_portname));
812 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
815 /* This side will initiate the PLOGI */
816 spin_lock_irq(shost->host_lock);
817 vport->fc_flag |= FC_PT2PT_PLOGI;
818 spin_unlock_irq(shost->host_lock);
821 * N_Port ID cannot be 0, set our to LocalID the other
822 * side will be RemoteID.
827 vport->fc_myDID = PT2PT_LocalID;
829 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
833 lpfc_config_link(phba, mbox);
835 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
837 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
838 if (rc == MBX_NOT_FINISHED) {
839 mempool_free(mbox, phba->mbox_mem_pool);
844 * For SLI4, the VFI/VPI are registered AFTER the
845 * Nport with the higher WWPN sends the PLOGI with
846 * an assigned NPortId.
850 if ((phba->sli_rev == LPFC_SLI_REV4) && rc)
851 lpfc_issue_reg_vfi(vport);
853 /* Decrement ndlp reference count indicating that ndlp can be
854 * safely released when other references to it are done.
858 ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
861 * Cannot find existing Fabric ndlp, so allocate a
864 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
867 lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID);
868 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
869 ndlp = lpfc_enable_node(vport, ndlp,
870 NLP_STE_UNUSED_NODE);
875 memcpy(&ndlp->nlp_portname, &sp->portName,
876 sizeof(struct lpfc_name));
877 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
878 sizeof(struct lpfc_name));
879 /* Set state will put ndlp onto node list if not already done */
880 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
881 spin_lock_irq(shost->host_lock);
882 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
883 spin_unlock_irq(shost->host_lock);
885 /* This side will wait for the PLOGI, decrement ndlp reference
886 * count indicating that ndlp can be released when other
887 * references to it are done.
891 /* If we are pt2pt with another NPort, force NPIV off! */
892 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
894 spin_lock_irq(shost->host_lock);
895 vport->fc_flag |= FC_PT2PT;
896 spin_unlock_irq(shost->host_lock);
898 /* Start discovery - this should just do CLEAR_LA */
899 lpfc_disc_start(vport);
906 * lpfc_cmpl_els_flogi - Completion callback function for flogi
907 * @phba: pointer to lpfc hba data structure.
908 * @cmdiocb: pointer to lpfc command iocb data structure.
909 * @rspiocb: pointer to lpfc response iocb data structure.
911 * This routine is the top-level completion callback function for issuing
912 * a Fabric Login (FLOGI) command. If the response IOCB reported error,
913 * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If
914 * retry has been made (either immediately or delayed with lpfc_els_retry()
915 * returning 1), the command IOCB will be released and function returned.
916 * If the retry attempt has been given up (possibly reach the maximum
917 * number of retries), one additional decrement of ndlp reference shall be
918 * invoked before going out after releasing the command IOCB. This will
919 * actually release the remote node (Note, lpfc_els_free_iocb() will also
920 * invoke one decrement of ndlp reference count). If no error reported in
921 * the IOCB status, the command Port ID field is used to determine whether
922 * this is a point-to-point topology or a fabric topology: if the Port ID
923 * field is assigned, it is a fabric topology; otherwise, it is a
924 * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or
925 * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the
926 * specific topology completion conditions.
929 lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
930 struct lpfc_iocbq *rspiocb)
932 struct lpfc_vport *vport = cmdiocb->vport;
933 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
934 IOCB_t *irsp = &rspiocb->iocb;
935 struct lpfc_nodelist *ndlp = cmdiocb->context1;
936 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
937 struct serv_parm *sp;
941 /* Check to see if link went down during discovery */
942 if (lpfc_els_chk_latt(vport)) {
943 /* One additional decrement on node reference count to
944 * trigger the release of the node
950 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
951 "FLOGI cmpl: status:x%x/x%x state:x%x",
952 irsp->ulpStatus, irsp->un.ulpWord[4],
955 if (irsp->ulpStatus) {
957 * In case of FIP mode, perform roundrobin FCF failover
958 * due to new FCF discovery
960 if ((phba->hba_flag & HBA_FIP_SUPPORT) &&
961 (phba->fcf.fcf_flag & FCF_DISCOVERY)) {
962 if (phba->link_state < LPFC_LINK_UP)
963 goto stop_rr_fcf_flogi;
964 if ((phba->fcoe_cvl_eventtag_attn ==
965 phba->fcoe_cvl_eventtag) &&
966 (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
967 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
969 goto stop_rr_fcf_flogi;
971 phba->fcoe_cvl_eventtag_attn =
972 phba->fcoe_cvl_eventtag;
973 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
974 "2611 FLOGI failed on FCF (x%x), "
975 "status:x%x/x%x, tmo:x%x, perform "
976 "roundrobin FCF failover\n",
977 phba->fcf.current_rec.fcf_indx,
978 irsp->ulpStatus, irsp->un.ulpWord[4],
980 lpfc_sli4_set_fcf_flogi_fail(phba,
981 phba->fcf.current_rec.fcf_indx);
982 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
983 rc = lpfc_sli4_fcf_rr_next_proc(vport, fcf_index);
990 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
991 "2858 FLOGI failure Status:x%x/x%x TMO:x%x\n",
992 irsp->ulpStatus, irsp->un.ulpWord[4],
995 /* Check for retry */
996 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
1000 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1001 "0100 FLOGI failure Status:x%x/x%x TMO:x%x\n",
1002 irsp->ulpStatus, irsp->un.ulpWord[4],
1005 /* FLOGI failed, so there is no fabric */
1006 spin_lock_irq(shost->host_lock);
1007 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
1008 spin_unlock_irq(shost->host_lock);
1010 /* If private loop, then allow max outstanding els to be
1011 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
1012 * alpa map would take too long otherwise.
1014 if (phba->alpa_map[0] == 0)
1015 vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
1016 if ((phba->sli_rev == LPFC_SLI_REV4) &&
1017 (!(vport->fc_flag & FC_VFI_REGISTERED) ||
1018 (vport->fc_prevDID != vport->fc_myDID))) {
1019 if (vport->fc_flag & FC_VFI_REGISTERED)
1020 lpfc_sli4_unreg_all_rpis(vport);
1021 lpfc_issue_reg_vfi(vport);
1027 spin_lock_irq(shost->host_lock);
1028 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
1029 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
1030 spin_unlock_irq(shost->host_lock);
1033 * The FLogI succeeded. Sync the data for the CPU before
1036 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
1038 sp = prsp->virt + sizeof(uint32_t);
1040 /* FLOGI completes successfully */
1041 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1042 "0101 FLOGI completes successfully "
1043 "Data: x%x x%x x%x x%x\n",
1044 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
1045 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution);
1047 if (vport->port_state == LPFC_FLOGI) {
1049 * If Common Service Parameters indicate Nport
1050 * we are point to point, if Fport we are Fabric.
1053 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
1054 else if (!(phba->hba_flag & HBA_FCOE_MODE))
1055 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
1057 lpfc_printf_vlog(vport, KERN_ERR,
1059 "2831 FLOGI response with cleared Fabric "
1060 "bit fcf_index 0x%x "
1061 "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x "
1063 "%02x%02x%02x%02x%02x%02x%02x%02x\n",
1064 phba->fcf.current_rec.fcf_indx,
1065 phba->fcf.current_rec.switch_name[0],
1066 phba->fcf.current_rec.switch_name[1],
1067 phba->fcf.current_rec.switch_name[2],
1068 phba->fcf.current_rec.switch_name[3],
1069 phba->fcf.current_rec.switch_name[4],
1070 phba->fcf.current_rec.switch_name[5],
1071 phba->fcf.current_rec.switch_name[6],
1072 phba->fcf.current_rec.switch_name[7],
1073 phba->fcf.current_rec.fabric_name[0],
1074 phba->fcf.current_rec.fabric_name[1],
1075 phba->fcf.current_rec.fabric_name[2],
1076 phba->fcf.current_rec.fabric_name[3],
1077 phba->fcf.current_rec.fabric_name[4],
1078 phba->fcf.current_rec.fabric_name[5],
1079 phba->fcf.current_rec.fabric_name[6],
1080 phba->fcf.current_rec.fabric_name[7]);
1082 spin_lock_irq(&phba->hbalock);
1083 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
1084 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
1085 spin_unlock_irq(&phba->hbalock);
1089 /* Mark the FCF discovery process done */
1090 if (phba->hba_flag & HBA_FIP_SUPPORT)
1091 lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP |
1093 "2769 FLOGI to FCF (x%x) "
1094 "completed successfully\n",
1095 phba->fcf.current_rec.fcf_indx);
1096 spin_lock_irq(&phba->hbalock);
1097 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
1098 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
1099 spin_unlock_irq(&phba->hbalock);
1107 if (!lpfc_error_lost_link(irsp)) {
1108 /* FLOGI failed, so just use loop map to make discovery list */
1109 lpfc_disc_list_loopmap(vport);
1111 /* Start discovery */
1112 lpfc_disc_start(vport);
1113 } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
1114 (((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
1115 IOERR_SLI_ABORTED) &&
1116 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
1117 IOERR_SLI_DOWN))) &&
1118 (phba->link_state != LPFC_CLEAR_LA)) {
1119 /* If FLOGI failed enable link interrupt. */
1120 lpfc_issue_clear_la(phba, vport);
1123 lpfc_els_free_iocb(phba, cmdiocb);
1127 * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport
1128 * @vport: pointer to a host virtual N_Port data structure.
1129 * @ndlp: pointer to a node-list data structure.
1130 * @retry: number of retries to the command IOCB.
1132 * This routine issues a Fabric Login (FLOGI) Request ELS command
1133 * for a @vport. The initiator service parameters are put into the payload
1134 * of the FLOGI Request IOCB and the top-level callback function pointer
1135 * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
1136 * function field. The lpfc_issue_fabric_iocb routine is invoked to send
1137 * out FLOGI ELS command with one outstanding fabric IOCB at a time.
1139 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1140 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1141 * will be stored into the context1 field of the IOCB for the completion
1142 * callback function to the FLOGI ELS command.
1145 * 0 - successfully issued flogi iocb for @vport
1146 * 1 - failed to issue flogi iocb for @vport
1149 lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1152 struct lpfc_hba *phba = vport->phba;
1153 struct serv_parm *sp;
1155 struct lpfc_iocbq *elsiocb;
1156 struct lpfc_sli_ring *pring;
1162 pring = &phba->sli.ring[LPFC_ELS_RING];
1164 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
1165 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1166 ndlp->nlp_DID, ELS_CMD_FLOGI);
1171 icmd = &elsiocb->iocb;
1172 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1174 /* For FLOGI request, remainder of payload is service parameters */
1175 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
1176 pcmd += sizeof(uint32_t);
1177 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
1178 sp = (struct serv_parm *) pcmd;
1180 /* Setup CSPs accordingly for Fabric */
1181 sp->cmn.e_d_tov = 0;
1182 sp->cmn.w2.r_a_tov = 0;
1183 sp->cmn.virtual_fabric_support = 0;
1184 sp->cls1.classValid = 0;
1185 if (sp->cmn.fcphLow < FC_PH3)
1186 sp->cmn.fcphLow = FC_PH3;
1187 if (sp->cmn.fcphHigh < FC_PH3)
1188 sp->cmn.fcphHigh = FC_PH3;
1190 if (phba->sli_rev == LPFC_SLI_REV4) {
1191 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
1192 LPFC_SLI_INTF_IF_TYPE_0) {
1193 elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1);
1194 elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1);
1195 /* FLOGI needs to be 3 for WQE FCFI */
1196 /* Set the fcfi to the fcfi we registered with */
1197 elsiocb->iocb.ulpContext = phba->fcf.fcfi;
1199 /* Can't do SLI4 class2 without support sequence coalescing */
1200 sp->cls2.classValid = 0;
1201 sp->cls2.seqDelivery = 0;
1203 /* Historical, setting sequential-delivery bit for SLI3 */
1204 sp->cls2.seqDelivery = (sp->cls2.classValid) ? 1 : 0;
1205 sp->cls3.seqDelivery = (sp->cls3.classValid) ? 1 : 0;
1206 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
1207 sp->cmn.request_multiple_Nport = 1;
1208 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
1212 sp->cmn.request_multiple_Nport = 0;
1215 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
1216 icmd->un.elsreq64.myID = 0;
1217 icmd->un.elsreq64.fl = 1;
1220 tmo = phba->fc_ratov;
1221 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
1222 lpfc_set_disctmo(vport);
1223 phba->fc_ratov = tmo;
1225 phba->fc_stat.elsXmitFLOGI++;
1226 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
1228 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1229 "Issue FLOGI: opt:x%x",
1230 phba->sli3_options, 0, 0);
1232 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
1233 if (rc == IOCB_ERROR) {
1234 lpfc_els_free_iocb(phba, elsiocb);
1241 * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs
1242 * @phba: pointer to lpfc hba data structure.
1244 * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
1245 * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
1246 * list and issues an abort IOCB commond on each outstanding IOCB that
1247 * contains a active Fabric_DID ndlp. Note that this function is to issue
1248 * the abort IOCB command on all the outstanding IOCBs, thus when this
1249 * function returns, it does not guarantee all the IOCBs are actually aborted.
1252 * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0)
1255 lpfc_els_abort_flogi(struct lpfc_hba *phba)
1257 struct lpfc_sli_ring *pring;
1258 struct lpfc_iocbq *iocb, *next_iocb;
1259 struct lpfc_nodelist *ndlp;
1262 /* Abort outstanding I/O on NPort <nlp_DID> */
1263 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
1264 "0201 Abort outstanding I/O on NPort x%x\n",
1267 pring = &phba->sli.ring[LPFC_ELS_RING];
1270 * Check the txcmplq for an iocb that matches the nport the driver is
1273 spin_lock_irq(&phba->hbalock);
1274 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
1276 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR) {
1277 ndlp = (struct lpfc_nodelist *)(iocb->context1);
1278 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
1279 (ndlp->nlp_DID == Fabric_DID))
1280 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
1283 spin_unlock_irq(&phba->hbalock);
1289 * lpfc_initial_flogi - Issue an initial fabric login for a vport
1290 * @vport: pointer to a host virtual N_Port data structure.
1292 * This routine issues an initial Fabric Login (FLOGI) for the @vport
1293 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1294 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1295 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1296 * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
1297 * is then invoked with the @vport and the ndlp to perform the FLOGI for the
1301 * 0 - failed to issue initial flogi for @vport
1302 * 1 - successfully issued initial flogi for @vport
1305 lpfc_initial_flogi(struct lpfc_vport *vport)
1307 struct lpfc_hba *phba = vport->phba;
1308 struct lpfc_nodelist *ndlp;
1310 vport->port_state = LPFC_FLOGI;
1311 lpfc_set_disctmo(vport);
1313 /* First look for the Fabric ndlp */
1314 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1316 /* Cannot find existing Fabric ndlp, so allocate a new one */
1317 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1320 lpfc_nlp_init(vport, ndlp, Fabric_DID);
1321 /* Set the node type */
1322 ndlp->nlp_type |= NLP_FABRIC;
1323 /* Put ndlp onto node list */
1324 lpfc_enqueue_node(vport, ndlp);
1325 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1326 /* re-setup ndlp without removing from node list */
1327 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1332 if (lpfc_issue_els_flogi(vport, ndlp, 0)) {
1333 /* This decrement of reference count to node shall kick off
1334 * the release of the node.
1343 * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport
1344 * @vport: pointer to a host virtual N_Port data structure.
1346 * This routine issues an initial Fabric Discover (FDISC) for the @vport
1347 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1348 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1349 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1350 * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
1351 * is then invoked with the @vport and the ndlp to perform the FDISC for the
1355 * 0 - failed to issue initial fdisc for @vport
1356 * 1 - successfully issued initial fdisc for @vport
1359 lpfc_initial_fdisc(struct lpfc_vport *vport)
1361 struct lpfc_hba *phba = vport->phba;
1362 struct lpfc_nodelist *ndlp;
1364 /* First look for the Fabric ndlp */
1365 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1367 /* Cannot find existing Fabric ndlp, so allocate a new one */
1368 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1371 lpfc_nlp_init(vport, ndlp, Fabric_DID);
1372 /* Put ndlp onto node list */
1373 lpfc_enqueue_node(vport, ndlp);
1374 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1375 /* re-setup ndlp without removing from node list */
1376 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1381 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
1382 /* decrement node reference count to trigger the release of
1392 * lpfc_more_plogi - Check and issue remaining plogis for a vport
1393 * @vport: pointer to a host virtual N_Port data structure.
1395 * This routine checks whether there are more remaining Port Logins
1396 * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
1397 * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
1398 * to issue ELS PLOGIs up to the configured discover threads with the
1399 * @vport (@vport->cfg_discovery_threads). The function also decrement
1400 * the @vport's num_disc_node by 1 if it is not already 0.
1403 lpfc_more_plogi(struct lpfc_vport *vport)
1407 if (vport->num_disc_nodes)
1408 vport->num_disc_nodes--;
1410 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
1411 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1412 "0232 Continue discovery with %d PLOGIs to go "
1413 "Data: x%x x%x x%x\n",
1414 vport->num_disc_nodes, vport->fc_plogi_cnt,
1415 vport->fc_flag, vport->port_state);
1416 /* Check to see if there are more PLOGIs to be sent */
1417 if (vport->fc_flag & FC_NLP_MORE)
1418 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
1419 sentplogi = lpfc_els_disc_plogi(vport);
1425 * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp
1426 * @phba: pointer to lpfc hba data structure.
1427 * @prsp: pointer to response IOCB payload.
1428 * @ndlp: pointer to a node-list data structure.
1430 * This routine checks and indicates whether the WWPN of an N_Port, retrieved
1431 * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
1432 * The following cases are considered N_Port confirmed:
1433 * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
1434 * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
1435 * it does not have WWPN assigned either. If the WWPN is confirmed, the
1436 * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
1437 * 1) if there is a node on vport list other than the @ndlp with the same
1438 * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
1439 * on that node to release the RPI associated with the node; 2) if there is
1440 * no node found on vport list with the same WWPN of the N_Port PLOGI logged
1441 * into, a new node shall be allocated (or activated). In either case, the
1442 * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
1443 * be released and the new_ndlp shall be put on to the vport node list and
1444 * its pointer returned as the confirmed node.
1446 * Note that before the @ndlp got "released", the keepDID from not-matching
1447 * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
1448 * of the @ndlp. This is because the release of @ndlp is actually to put it
1449 * into an inactive state on the vport node list and the vport node list
1450 * management algorithm does not allow two node with a same DID.
1453 * pointer to the PLOGI N_Port @ndlp
1455 static struct lpfc_nodelist *
1456 lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
1457 struct lpfc_nodelist *ndlp)
1459 struct lpfc_vport *vport = ndlp->vport;
1460 struct lpfc_nodelist *new_ndlp;
1461 struct lpfc_rport_data *rdata;
1462 struct fc_rport *rport;
1463 struct serv_parm *sp;
1464 uint8_t name[sizeof(struct lpfc_name)];
1465 uint32_t rc, keepDID = 0;
1468 struct lpfc_node_rrqs rrq;
1470 /* Fabric nodes can have the same WWPN so we don't bother searching
1471 * by WWPN. Just return the ndlp that was given to us.
1473 if (ndlp->nlp_type & NLP_FABRIC)
1476 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
1477 memset(name, 0, sizeof(struct lpfc_name));
1479 /* Now we find out if the NPort we are logging into, matches the WWPN
1480 * we have for that ndlp. If not, we have some work to do.
1482 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
1484 if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp))
1486 memset(&rrq.xri_bitmap, 0, sizeof(new_ndlp->active_rrqs.xri_bitmap));
1488 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1489 "3178 PLOGI confirm: ndlp %p x%x: new_ndlp %p\n",
1490 ndlp, ndlp->nlp_DID, new_ndlp);
1493 rc = memcmp(&ndlp->nlp_portname, name,
1494 sizeof(struct lpfc_name));
1497 new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
1500 lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID);
1501 } else if (!NLP_CHK_NODE_ACT(new_ndlp)) {
1502 rc = memcmp(&ndlp->nlp_portname, name,
1503 sizeof(struct lpfc_name));
1506 new_ndlp = lpfc_enable_node(vport, new_ndlp,
1507 NLP_STE_UNUSED_NODE);
1510 keepDID = new_ndlp->nlp_DID;
1511 if (phba->sli_rev == LPFC_SLI_REV4)
1512 memcpy(&rrq.xri_bitmap,
1513 &new_ndlp->active_rrqs.xri_bitmap,
1514 sizeof(new_ndlp->active_rrqs.xri_bitmap));
1516 keepDID = new_ndlp->nlp_DID;
1517 if (phba->sli_rev == LPFC_SLI_REV4)
1518 memcpy(&rrq.xri_bitmap,
1519 &new_ndlp->active_rrqs.xri_bitmap,
1520 sizeof(new_ndlp->active_rrqs.xri_bitmap));
1523 lpfc_unreg_rpi(vport, new_ndlp);
1524 new_ndlp->nlp_DID = ndlp->nlp_DID;
1525 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
1526 if (phba->sli_rev == LPFC_SLI_REV4)
1527 memcpy(new_ndlp->active_rrqs.xri_bitmap,
1528 &ndlp->active_rrqs.xri_bitmap,
1529 sizeof(ndlp->active_rrqs.xri_bitmap));
1531 if (ndlp->nlp_flag & NLP_NPR_2B_DISC)
1532 new_ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1533 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1535 /* Set state will put new_ndlp on to node list if not already done */
1536 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
1538 /* Move this back to NPR state */
1539 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
1540 /* The new_ndlp is replacing ndlp totally, so we need
1541 * to put ndlp on UNUSED list and try to free it.
1543 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1544 "3179 PLOGI confirm NEW: %x %x\n",
1545 new_ndlp->nlp_DID, keepDID);
1547 /* Fix up the rport accordingly */
1548 rport = ndlp->rport;
1550 rdata = rport->dd_data;
1551 if (rdata->pnode == ndlp) {
1554 rdata->pnode = lpfc_nlp_get(new_ndlp);
1555 new_ndlp->rport = rport;
1557 new_ndlp->nlp_type = ndlp->nlp_type;
1559 /* We shall actually free the ndlp with both nlp_DID and
1560 * nlp_portname fields equals 0 to avoid any ndlp on the
1561 * nodelist never to be used.
1563 if (ndlp->nlp_DID == 0) {
1564 spin_lock_irq(&phba->ndlp_lock);
1565 NLP_SET_FREE_REQ(ndlp);
1566 spin_unlock_irq(&phba->ndlp_lock);
1569 /* Two ndlps cannot have the same did on the nodelist */
1570 ndlp->nlp_DID = keepDID;
1571 if (phba->sli_rev == LPFC_SLI_REV4)
1572 memcpy(&ndlp->active_rrqs.xri_bitmap,
1574 sizeof(ndlp->active_rrqs.xri_bitmap));
1575 lpfc_drop_node(vport, ndlp);
1578 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1579 "3180 PLOGI confirm SWAP: %x %x\n",
1580 new_ndlp->nlp_DID, keepDID);
1582 lpfc_unreg_rpi(vport, ndlp);
1584 /* Two ndlps cannot have the same did */
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));
1591 /* Since we are swapping the ndlp passed in with the new one
1592 * and the did has already been swapped, copy over state.
1593 * The new WWNs are already in new_ndlp since thats what
1594 * we looked it up by in the begining of this routine.
1596 new_ndlp->nlp_state = ndlp->nlp_state;
1598 /* Since we are switching over to the new_ndlp, the old
1599 * ndlp should be put in the NPR state, unless we have
1600 * already started re-discovery on it.
1602 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
1603 (ndlp->nlp_state == NLP_STE_MAPPED_NODE))
1604 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1606 /* Fix up the rport accordingly */
1607 rport = ndlp->rport;
1609 rdata = rport->dd_data;
1610 put_node = rdata->pnode != NULL;
1611 put_rport = ndlp->rport != NULL;
1612 rdata->pnode = NULL;
1617 put_device(&rport->dev);
1624 * lpfc_end_rscn - Check and handle more rscn for a vport
1625 * @vport: pointer to a host virtual N_Port data structure.
1627 * This routine checks whether more Registration State Change
1628 * Notifications (RSCNs) came in while the discovery state machine was in
1629 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1630 * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1631 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1632 * handling the RSCNs.
1635 lpfc_end_rscn(struct lpfc_vport *vport)
1637 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1639 if (vport->fc_flag & FC_RSCN_MODE) {
1641 * Check to see if more RSCNs came in while we were
1642 * processing this one.
1644 if (vport->fc_rscn_id_cnt ||
1645 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
1646 lpfc_els_handle_rscn(vport);
1648 spin_lock_irq(shost->host_lock);
1649 vport->fc_flag &= ~FC_RSCN_MODE;
1650 spin_unlock_irq(shost->host_lock);
1656 * lpfc_cmpl_els_rrq - Completion handled for els RRQs.
1657 * @phba: pointer to lpfc hba data structure.
1658 * @cmdiocb: pointer to lpfc command iocb data structure.
1659 * @rspiocb: pointer to lpfc response iocb data structure.
1661 * This routine will call the clear rrq function to free the rrq and
1662 * clear the xri's bit in the ndlp's xri_bitmap. If the ndlp does not
1663 * exist then the clear_rrq is still called because the rrq needs to
1668 lpfc_cmpl_els_rrq(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1669 struct lpfc_iocbq *rspiocb)
1671 struct lpfc_vport *vport = cmdiocb->vport;
1673 struct lpfc_nodelist *ndlp;
1674 struct lpfc_node_rrq *rrq;
1676 /* we pass cmdiocb to state machine which needs rspiocb as well */
1677 rrq = cmdiocb->context_un.rrq;
1678 cmdiocb->context_un.rsp_iocb = rspiocb;
1680 irsp = &rspiocb->iocb;
1681 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1682 "RRQ cmpl: status:x%x/x%x did:x%x",
1683 irsp->ulpStatus, irsp->un.ulpWord[4],
1684 irsp->un.elsreq64.remoteID);
1686 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
1687 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || ndlp != rrq->ndlp) {
1688 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1689 "2882 RRQ completes to NPort x%x "
1690 "with no ndlp. Data: x%x x%x x%x\n",
1691 irsp->un.elsreq64.remoteID,
1692 irsp->ulpStatus, irsp->un.ulpWord[4],
1697 /* rrq completes to NPort <nlp_DID> */
1698 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1699 "2880 RRQ completes to NPort x%x "
1700 "Data: x%x x%x x%x x%x x%x\n",
1701 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1702 irsp->ulpTimeout, rrq->xritag, rrq->rxid);
1704 if (irsp->ulpStatus) {
1705 /* Check for retry */
1706 /* RRQ failed Don't print the vport to vport rjts */
1707 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1708 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1709 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1710 (phba)->pport->cfg_log_verbose & LOG_ELS)
1711 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1712 "2881 RRQ failure DID:%06X Status:x%x/x%x\n",
1713 ndlp->nlp_DID, irsp->ulpStatus,
1714 irsp->un.ulpWord[4]);
1718 lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
1719 lpfc_els_free_iocb(phba, cmdiocb);
1723 * lpfc_cmpl_els_plogi - Completion callback function for plogi
1724 * @phba: pointer to lpfc hba data structure.
1725 * @cmdiocb: pointer to lpfc command iocb data structure.
1726 * @rspiocb: pointer to lpfc response iocb data structure.
1728 * This routine is the completion callback function for issuing the Port
1729 * Login (PLOGI) command. For PLOGI completion, there must be an active
1730 * ndlp on the vport node list that matches the remote node ID from the
1731 * PLOGI response IOCB. If such ndlp does not exist, the PLOGI is simply
1732 * ignored and command IOCB released. The PLOGI response IOCB status is
1733 * checked for error conditons. If there is error status reported, PLOGI
1734 * retry shall be attempted by invoking the lpfc_els_retry() routine.
1735 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1736 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1737 * (DSM) is set for this PLOGI completion. Finally, it checks whether
1738 * there are additional N_Port nodes with the vport that need to perform
1739 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
1743 lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1744 struct lpfc_iocbq *rspiocb)
1746 struct lpfc_vport *vport = cmdiocb->vport;
1747 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1749 struct lpfc_nodelist *ndlp;
1750 struct lpfc_dmabuf *prsp;
1751 int disc, rc, did, type;
1753 /* we pass cmdiocb to state machine which needs rspiocb as well */
1754 cmdiocb->context_un.rsp_iocb = rspiocb;
1756 irsp = &rspiocb->iocb;
1757 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1758 "PLOGI cmpl: status:x%x/x%x did:x%x",
1759 irsp->ulpStatus, irsp->un.ulpWord[4],
1760 irsp->un.elsreq64.remoteID);
1762 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
1763 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
1764 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1765 "0136 PLOGI completes to NPort x%x "
1766 "with no ndlp. Data: x%x x%x x%x\n",
1767 irsp->un.elsreq64.remoteID,
1768 irsp->ulpStatus, irsp->un.ulpWord[4],
1773 /* Since ndlp can be freed in the disc state machine, note if this node
1774 * is being used during discovery.
1776 spin_lock_irq(shost->host_lock);
1777 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
1778 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1779 spin_unlock_irq(shost->host_lock);
1782 /* PLOGI completes to NPort <nlp_DID> */
1783 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1784 "0102 PLOGI completes to NPort x%x "
1785 "Data: x%x x%x x%x x%x x%x\n",
1786 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1787 irsp->ulpTimeout, disc, vport->num_disc_nodes);
1788 /* Check to see if link went down during discovery */
1789 if (lpfc_els_chk_latt(vport)) {
1790 spin_lock_irq(shost->host_lock);
1791 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1792 spin_unlock_irq(shost->host_lock);
1796 /* ndlp could be freed in DSM, save these values now */
1797 type = ndlp->nlp_type;
1798 did = ndlp->nlp_DID;
1800 if (irsp->ulpStatus) {
1801 /* Check for retry */
1802 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1803 /* ELS command is being retried */
1805 spin_lock_irq(shost->host_lock);
1806 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1807 spin_unlock_irq(shost->host_lock);
1811 /* PLOGI failed Don't print the vport to vport rjts */
1812 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1813 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1814 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1815 (phba)->pport->cfg_log_verbose & LOG_ELS)
1816 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1817 "2753 PLOGI failure DID:%06X Status:x%x/x%x\n",
1818 ndlp->nlp_DID, irsp->ulpStatus,
1819 irsp->un.ulpWord[4]);
1820 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1821 if (lpfc_error_lost_link(irsp))
1822 rc = NLP_STE_FREED_NODE;
1824 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1825 NLP_EVT_CMPL_PLOGI);
1827 /* Good status, call state machine */
1828 prsp = list_entry(((struct lpfc_dmabuf *)
1829 cmdiocb->context2)->list.next,
1830 struct lpfc_dmabuf, list);
1831 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
1832 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1833 NLP_EVT_CMPL_PLOGI);
1836 if (disc && vport->num_disc_nodes) {
1837 /* Check to see if there are more PLOGIs to be sent */
1838 lpfc_more_plogi(vport);
1840 if (vport->num_disc_nodes == 0) {
1841 spin_lock_irq(shost->host_lock);
1842 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1843 spin_unlock_irq(shost->host_lock);
1845 lpfc_can_disctmo(vport);
1846 lpfc_end_rscn(vport);
1851 lpfc_els_free_iocb(phba, cmdiocb);
1856 * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
1857 * @vport: pointer to a host virtual N_Port data structure.
1858 * @did: destination port identifier.
1859 * @retry: number of retries to the command IOCB.
1861 * This routine issues a Port Login (PLOGI) command to a remote N_Port
1862 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
1863 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
1864 * This routine constructs the proper feilds of the PLOGI IOCB and invokes
1865 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
1867 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1868 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1869 * will be stored into the context1 field of the IOCB for the completion
1870 * callback function to the PLOGI ELS command.
1873 * 0 - Successfully issued a plogi for @vport
1874 * 1 - failed to issue a plogi for @vport
1877 lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
1879 struct lpfc_hba *phba = vport->phba;
1880 struct serv_parm *sp;
1882 struct lpfc_nodelist *ndlp;
1883 struct lpfc_iocbq *elsiocb;
1884 struct lpfc_sli *psli;
1891 ndlp = lpfc_findnode_did(vport, did);
1892 if (ndlp && !NLP_CHK_NODE_ACT(ndlp))
1895 /* If ndlp is not NULL, we will bump the reference count on it */
1896 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
1897 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
1902 icmd = &elsiocb->iocb;
1903 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1905 /* For PLOGI request, remainder of payload is service parameters */
1906 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
1907 pcmd += sizeof(uint32_t);
1908 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
1909 sp = (struct serv_parm *) pcmd;
1912 * If we are a N-port connected to a Fabric, fix-up paramm's so logins
1913 * to device on remote loops work.
1915 if ((vport->fc_flag & FC_FABRIC) && !(vport->fc_flag & FC_PUBLIC_LOOP))
1916 sp->cmn.altBbCredit = 1;
1918 if (sp->cmn.fcphLow < FC_PH_4_3)
1919 sp->cmn.fcphLow = FC_PH_4_3;
1921 if (sp->cmn.fcphHigh < FC_PH3)
1922 sp->cmn.fcphHigh = FC_PH3;
1924 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1925 "Issue PLOGI: did:x%x",
1928 phba->fc_stat.elsXmitPLOGI++;
1929 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
1930 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
1932 if (ret == IOCB_ERROR) {
1933 lpfc_els_free_iocb(phba, elsiocb);
1940 * lpfc_cmpl_els_prli - Completion callback function for prli
1941 * @phba: pointer to lpfc hba data structure.
1942 * @cmdiocb: pointer to lpfc command iocb data structure.
1943 * @rspiocb: pointer to lpfc response iocb data structure.
1945 * This routine is the completion callback function for a Process Login
1946 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
1947 * status. If there is error status reported, PRLI retry shall be attempted
1948 * by invoking the lpfc_els_retry() routine. Otherwise, the state
1949 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
1950 * ndlp to mark the PRLI completion.
1953 lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1954 struct lpfc_iocbq *rspiocb)
1956 struct lpfc_vport *vport = cmdiocb->vport;
1957 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1959 struct lpfc_sli *psli;
1960 struct lpfc_nodelist *ndlp;
1963 /* we pass cmdiocb to state machine which needs rspiocb as well */
1964 cmdiocb->context_un.rsp_iocb = rspiocb;
1966 irsp = &(rspiocb->iocb);
1967 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1968 spin_lock_irq(shost->host_lock);
1969 ndlp->nlp_flag &= ~NLP_PRLI_SND;
1970 spin_unlock_irq(shost->host_lock);
1972 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1973 "PRLI cmpl: status:x%x/x%x did:x%x",
1974 irsp->ulpStatus, irsp->un.ulpWord[4],
1976 /* PRLI completes to NPort <nlp_DID> */
1977 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1978 "0103 PRLI completes to NPort x%x "
1979 "Data: x%x x%x x%x x%x\n",
1980 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1981 irsp->ulpTimeout, vport->num_disc_nodes);
1983 vport->fc_prli_sent--;
1984 /* Check to see if link went down during discovery */
1985 if (lpfc_els_chk_latt(vport))
1988 if (irsp->ulpStatus) {
1989 /* Check for retry */
1990 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1991 /* ELS command is being retried */
1995 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1996 "2754 PRLI failure DID:%06X Status:x%x/x%x\n",
1997 ndlp->nlp_DID, irsp->ulpStatus,
1998 irsp->un.ulpWord[4]);
1999 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2000 if (lpfc_error_lost_link(irsp))
2003 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2006 /* Good status, call state machine */
2007 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2010 lpfc_els_free_iocb(phba, cmdiocb);
2015 * lpfc_issue_els_prli - Issue a prli iocb command for a vport
2016 * @vport: pointer to a host virtual N_Port data structure.
2017 * @ndlp: pointer to a node-list data structure.
2018 * @retry: number of retries to the command IOCB.
2020 * This routine issues a Process Login (PRLI) ELS command for the
2021 * @vport. The PRLI service parameters are set up in the payload of the
2022 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
2023 * is put to the IOCB completion callback func field before invoking the
2024 * routine lpfc_sli_issue_iocb() to send out PRLI command.
2026 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2027 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2028 * will be stored into the context1 field of the IOCB for the completion
2029 * callback function to the PRLI ELS command.
2032 * 0 - successfully issued prli iocb command for @vport
2033 * 1 - failed to issue prli iocb command for @vport
2036 lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2039 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2040 struct lpfc_hba *phba = vport->phba;
2043 struct lpfc_iocbq *elsiocb;
2047 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
2048 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2049 ndlp->nlp_DID, ELS_CMD_PRLI);
2053 icmd = &elsiocb->iocb;
2054 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2056 /* For PRLI request, remainder of payload is service parameters */
2057 memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t)));
2058 *((uint32_t *) (pcmd)) = ELS_CMD_PRLI;
2059 pcmd += sizeof(uint32_t);
2061 /* For PRLI, remainder of payload is PRLI parameter page */
2062 npr = (PRLI *) pcmd;
2064 * If our firmware version is 3.20 or later,
2065 * set the following bits for FC-TAPE support.
2067 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
2068 npr->ConfmComplAllowed = 1;
2070 npr->TaskRetryIdReq = 1;
2072 npr->estabImagePair = 1;
2073 npr->readXferRdyDis = 1;
2075 /* For FCP support */
2076 npr->prliType = PRLI_FCP_TYPE;
2077 npr->initiatorFunc = 1;
2079 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2080 "Issue PRLI: did:x%x",
2081 ndlp->nlp_DID, 0, 0);
2083 phba->fc_stat.elsXmitPRLI++;
2084 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
2085 spin_lock_irq(shost->host_lock);
2086 ndlp->nlp_flag |= NLP_PRLI_SND;
2087 spin_unlock_irq(shost->host_lock);
2088 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2090 spin_lock_irq(shost->host_lock);
2091 ndlp->nlp_flag &= ~NLP_PRLI_SND;
2092 spin_unlock_irq(shost->host_lock);
2093 lpfc_els_free_iocb(phba, elsiocb);
2096 vport->fc_prli_sent++;
2101 * lpfc_rscn_disc - Perform rscn discovery for a vport
2102 * @vport: pointer to a host virtual N_Port data structure.
2104 * This routine performs Registration State Change Notification (RSCN)
2105 * discovery for a @vport. If the @vport's node port recovery count is not
2106 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
2107 * the nodes that need recovery. If none of the PLOGI were needed through
2108 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
2109 * invoked to check and handle possible more RSCN came in during the period
2110 * of processing the current ones.
2113 lpfc_rscn_disc(struct lpfc_vport *vport)
2115 lpfc_can_disctmo(vport);
2117 /* RSCN discovery */
2118 /* go thru NPR nodes and issue ELS PLOGIs */
2119 if (vport->fc_npr_cnt)
2120 if (lpfc_els_disc_plogi(vport))
2123 lpfc_end_rscn(vport);
2127 * lpfc_adisc_done - Complete the adisc phase of discovery
2128 * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
2130 * This function is called when the final ADISC is completed during discovery.
2131 * This function handles clearing link attention or issuing reg_vpi depending
2132 * on whether npiv is enabled. This function also kicks off the PLOGI phase of
2134 * This function is called with no locks held.
2137 lpfc_adisc_done(struct lpfc_vport *vport)
2139 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2140 struct lpfc_hba *phba = vport->phba;
2143 * For NPIV, cmpl_reg_vpi will set port_state to READY,
2144 * and continue discovery.
2146 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2147 !(vport->fc_flag & FC_RSCN_MODE) &&
2148 (phba->sli_rev < LPFC_SLI_REV4)) {
2149 lpfc_issue_reg_vpi(phba, vport);
2153 * For SLI2, we need to set port_state to READY
2154 * and continue discovery.
2156 if (vport->port_state < LPFC_VPORT_READY) {
2157 /* If we get here, there is nothing to ADISC */
2158 if (vport->port_type == LPFC_PHYSICAL_PORT)
2159 lpfc_issue_clear_la(phba, vport);
2160 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
2161 vport->num_disc_nodes = 0;
2162 /* go thru NPR list, issue ELS PLOGIs */
2163 if (vport->fc_npr_cnt)
2164 lpfc_els_disc_plogi(vport);
2165 if (!vport->num_disc_nodes) {
2166 spin_lock_irq(shost->host_lock);
2167 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2168 spin_unlock_irq(shost->host_lock);
2169 lpfc_can_disctmo(vport);
2170 lpfc_end_rscn(vport);
2173 vport->port_state = LPFC_VPORT_READY;
2175 lpfc_rscn_disc(vport);
2179 * lpfc_more_adisc - Issue more adisc as needed
2180 * @vport: pointer to a host virtual N_Port data structure.
2182 * This routine determines whether there are more ndlps on a @vport
2183 * node list need to have Address Discover (ADISC) issued. If so, it will
2184 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
2185 * remaining nodes which need to have ADISC sent.
2188 lpfc_more_adisc(struct lpfc_vport *vport)
2192 if (vport->num_disc_nodes)
2193 vport->num_disc_nodes--;
2194 /* Continue discovery with <num_disc_nodes> ADISCs to go */
2195 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2196 "0210 Continue discovery with %d ADISCs to go "
2197 "Data: x%x x%x x%x\n",
2198 vport->num_disc_nodes, vport->fc_adisc_cnt,
2199 vport->fc_flag, vport->port_state);
2200 /* Check to see if there are more ADISCs to be sent */
2201 if (vport->fc_flag & FC_NLP_MORE) {
2202 lpfc_set_disctmo(vport);
2203 /* go thru NPR nodes and issue any remaining ELS ADISCs */
2204 sentadisc = lpfc_els_disc_adisc(vport);
2206 if (!vport->num_disc_nodes)
2207 lpfc_adisc_done(vport);
2212 * lpfc_cmpl_els_adisc - Completion callback function for adisc
2213 * @phba: pointer to lpfc hba data structure.
2214 * @cmdiocb: pointer to lpfc command iocb data structure.
2215 * @rspiocb: pointer to lpfc response iocb data structure.
2217 * This routine is the completion function for issuing the Address Discover
2218 * (ADISC) command. It first checks to see whether link went down during
2219 * the discovery process. If so, the node will be marked as node port
2220 * recovery for issuing discover IOCB by the link attention handler and
2221 * exit. Otherwise, the response status is checked. If error was reported
2222 * in the response status, the ADISC command shall be retried by invoking
2223 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
2224 * the response status, the state machine is invoked to set transition
2225 * with respect to NLP_EVT_CMPL_ADISC event.
2228 lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2229 struct lpfc_iocbq *rspiocb)
2231 struct lpfc_vport *vport = cmdiocb->vport;
2232 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2234 struct lpfc_nodelist *ndlp;
2237 /* we pass cmdiocb to state machine which needs rspiocb as well */
2238 cmdiocb->context_un.rsp_iocb = rspiocb;
2240 irsp = &(rspiocb->iocb);
2241 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2243 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2244 "ADISC cmpl: status:x%x/x%x did:x%x",
2245 irsp->ulpStatus, irsp->un.ulpWord[4],
2248 /* Since ndlp can be freed in the disc state machine, note if this node
2249 * is being used during discovery.
2251 spin_lock_irq(shost->host_lock);
2252 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
2253 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
2254 spin_unlock_irq(shost->host_lock);
2255 /* ADISC completes to NPort <nlp_DID> */
2256 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2257 "0104 ADISC completes to NPort x%x "
2258 "Data: x%x x%x x%x x%x x%x\n",
2259 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2260 irsp->ulpTimeout, disc, vport->num_disc_nodes);
2261 /* Check to see if link went down during discovery */
2262 if (lpfc_els_chk_latt(vport)) {
2263 spin_lock_irq(shost->host_lock);
2264 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2265 spin_unlock_irq(shost->host_lock);
2269 if (irsp->ulpStatus) {
2270 /* Check for retry */
2271 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2272 /* ELS command is being retried */
2274 spin_lock_irq(shost->host_lock);
2275 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2276 spin_unlock_irq(shost->host_lock);
2277 lpfc_set_disctmo(vport);
2282 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2283 "2755 ADISC failure DID:%06X Status:x%x/x%x\n",
2284 ndlp->nlp_DID, irsp->ulpStatus,
2285 irsp->un.ulpWord[4]);
2286 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2287 if (!lpfc_error_lost_link(irsp))
2288 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2289 NLP_EVT_CMPL_ADISC);
2291 /* Good status, call state machine */
2292 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2293 NLP_EVT_CMPL_ADISC);
2295 /* Check to see if there are more ADISCs to be sent */
2296 if (disc && vport->num_disc_nodes)
2297 lpfc_more_adisc(vport);
2299 lpfc_els_free_iocb(phba, cmdiocb);
2304 * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
2305 * @vport: pointer to a virtual N_Port data structure.
2306 * @ndlp: pointer to a node-list data structure.
2307 * @retry: number of retries to the command IOCB.
2309 * This routine issues an Address Discover (ADISC) for an @ndlp on a
2310 * @vport. It prepares the payload of the ADISC ELS command, updates the
2311 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
2312 * to issue the ADISC ELS command.
2314 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2315 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2316 * will be stored into the context1 field of the IOCB for the completion
2317 * callback function to the ADISC ELS command.
2320 * 0 - successfully issued adisc
2321 * 1 - failed to issue adisc
2324 lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2327 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2328 struct lpfc_hba *phba = vport->phba;
2331 struct lpfc_iocbq *elsiocb;
2335 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
2336 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2337 ndlp->nlp_DID, ELS_CMD_ADISC);
2341 icmd = &elsiocb->iocb;
2342 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2344 /* For ADISC request, remainder of payload is service parameters */
2345 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
2346 pcmd += sizeof(uint32_t);
2348 /* Fill in ADISC payload */
2349 ap = (ADISC *) pcmd;
2350 ap->hardAL_PA = phba->fc_pref_ALPA;
2351 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2352 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
2353 ap->DID = be32_to_cpu(vport->fc_myDID);
2355 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2356 "Issue ADISC: did:x%x",
2357 ndlp->nlp_DID, 0, 0);
2359 phba->fc_stat.elsXmitADISC++;
2360 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
2361 spin_lock_irq(shost->host_lock);
2362 ndlp->nlp_flag |= NLP_ADISC_SND;
2363 spin_unlock_irq(shost->host_lock);
2364 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2366 spin_lock_irq(shost->host_lock);
2367 ndlp->nlp_flag &= ~NLP_ADISC_SND;
2368 spin_unlock_irq(shost->host_lock);
2369 lpfc_els_free_iocb(phba, elsiocb);
2376 * lpfc_cmpl_els_logo - Completion callback function for logo
2377 * @phba: pointer to lpfc hba data structure.
2378 * @cmdiocb: pointer to lpfc command iocb data structure.
2379 * @rspiocb: pointer to lpfc response iocb data structure.
2381 * This routine is the completion function for issuing the ELS Logout (LOGO)
2382 * command. If no error status was reported from the LOGO response, the
2383 * state machine of the associated ndlp shall be invoked for transition with
2384 * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
2385 * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
2388 lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2389 struct lpfc_iocbq *rspiocb)
2391 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2392 struct lpfc_vport *vport = ndlp->vport;
2393 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2395 struct lpfc_sli *psli;
2396 struct lpfcMboxq *mbox;
2397 unsigned long flags;
2398 uint32_t skip_recovery = 0;
2401 /* we pass cmdiocb to state machine which needs rspiocb as well */
2402 cmdiocb->context_un.rsp_iocb = rspiocb;
2404 irsp = &(rspiocb->iocb);
2405 spin_lock_irq(shost->host_lock);
2406 ndlp->nlp_flag &= ~NLP_LOGO_SND;
2407 spin_unlock_irq(shost->host_lock);
2409 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2410 "LOGO cmpl: status:x%x/x%x did:x%x",
2411 irsp->ulpStatus, irsp->un.ulpWord[4],
2414 /* LOGO completes to NPort <nlp_DID> */
2415 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2416 "0105 LOGO completes to NPort x%x "
2417 "Data: x%x x%x x%x x%x\n",
2418 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2419 irsp->ulpTimeout, vport->num_disc_nodes);
2421 if (lpfc_els_chk_latt(vport)) {
2426 /* Check to see if link went down during discovery */
2427 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
2428 /* NLP_EVT_DEVICE_RM should unregister the RPI
2429 * which should abort all outstanding IOs.
2431 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2437 if (irsp->ulpStatus) {
2438 /* Check for retry */
2439 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2440 /* ELS command is being retried */
2445 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2446 "2756 LOGO failure DID:%06X Status:x%x/x%x\n",
2447 ndlp->nlp_DID, irsp->ulpStatus,
2448 irsp->un.ulpWord[4]);
2449 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2450 if (lpfc_error_lost_link(irsp)) {
2456 /* Call state machine. This will unregister the rpi if needed. */
2457 lpfc_disc_state_machine(vport, ndlp, cmdiocb, NLP_EVT_CMPL_LOGO);
2460 lpfc_els_free_iocb(phba, cmdiocb);
2461 /* If we are in pt2pt mode, we could rcv new S_ID on PLOGI */
2462 if ((vport->fc_flag & FC_PT2PT) &&
2463 !(vport->fc_flag & FC_PT2PT_PLOGI)) {
2464 phba->pport->fc_myDID = 0;
2465 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2467 lpfc_config_link(phba, mbox);
2468 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
2469 mbox->vport = vport;
2470 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) ==
2472 mempool_free(mbox, phba->mbox_mem_pool);
2479 * If the node is a target, the handling attempts to recover the port.
2480 * For any other port type, the rpi is unregistered as an implicit
2483 if ((ndlp->nlp_type & NLP_FCP_TARGET) && (skip_recovery == 0)) {
2484 lpfc_cancel_retry_delay_tmo(vport, ndlp);
2485 spin_lock_irqsave(shost->host_lock, flags);
2486 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2487 spin_unlock_irqrestore(shost->host_lock, flags);
2489 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2490 "3187 LOGO completes to NPort x%x: Start "
2491 "Recovery Data: x%x x%x x%x x%x\n",
2492 ndlp->nlp_DID, irsp->ulpStatus,
2493 irsp->un.ulpWord[4], irsp->ulpTimeout,
2494 vport->num_disc_nodes);
2495 lpfc_disc_start(vport);
2501 * lpfc_issue_els_logo - Issue a logo to an node on a vport
2502 * @vport: pointer to a virtual N_Port data structure.
2503 * @ndlp: pointer to a node-list data structure.
2504 * @retry: number of retries to the command IOCB.
2506 * This routine constructs and issues an ELS Logout (LOGO) iocb command
2507 * to a remote node, referred by an @ndlp on a @vport. It constructs the
2508 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
2509 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
2511 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2512 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2513 * will be stored into the context1 field of the IOCB for the completion
2514 * callback function to the LOGO ELS command.
2517 * 0 - successfully issued logo
2518 * 1 - failed to issue logo
2521 lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2524 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2525 struct lpfc_hba *phba = vport->phba;
2527 struct lpfc_iocbq *elsiocb;
2532 spin_lock_irq(shost->host_lock);
2533 if (ndlp->nlp_flag & NLP_LOGO_SND) {
2534 spin_unlock_irq(shost->host_lock);
2537 spin_unlock_irq(shost->host_lock);
2539 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
2540 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2541 ndlp->nlp_DID, ELS_CMD_LOGO);
2545 icmd = &elsiocb->iocb;
2546 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2547 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
2548 pcmd += sizeof(uint32_t);
2550 /* Fill in LOGO payload */
2551 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
2552 pcmd += sizeof(uint32_t);
2553 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
2555 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2556 "Issue LOGO: did:x%x",
2557 ndlp->nlp_DID, 0, 0);
2560 * If we are issuing a LOGO, we may try to recover the remote NPort
2561 * by issuing a PLOGI later. Even though we issue ELS cmds by the
2562 * VPI, if we have a valid RPI, and that RPI gets unreg'ed while
2563 * that ELS command is in-flight, the HBA returns a IOERR_INVALID_RPI
2564 * for that ELS cmd. To avoid this situation, lets get rid of the
2565 * RPI right now, before any ELS cmds are sent.
2567 spin_lock_irq(shost->host_lock);
2568 ndlp->nlp_flag |= NLP_ISSUE_LOGO;
2569 spin_unlock_irq(shost->host_lock);
2570 if (lpfc_unreg_rpi(vport, ndlp)) {
2571 lpfc_els_free_iocb(phba, elsiocb);
2575 phba->fc_stat.elsXmitLOGO++;
2576 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
2577 spin_lock_irq(shost->host_lock);
2578 ndlp->nlp_flag |= NLP_LOGO_SND;
2579 ndlp->nlp_flag &= ~NLP_ISSUE_LOGO;
2580 spin_unlock_irq(shost->host_lock);
2581 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
2583 if (rc == IOCB_ERROR) {
2584 spin_lock_irq(shost->host_lock);
2585 ndlp->nlp_flag &= ~NLP_LOGO_SND;
2586 spin_unlock_irq(shost->host_lock);
2587 lpfc_els_free_iocb(phba, elsiocb);
2594 * lpfc_cmpl_els_cmd - Completion callback function for generic els command
2595 * @phba: pointer to lpfc hba data structure.
2596 * @cmdiocb: pointer to lpfc command iocb data structure.
2597 * @rspiocb: pointer to lpfc response iocb data structure.
2599 * This routine is a generic completion callback function for ELS commands.
2600 * Specifically, it is the callback function which does not need to perform
2601 * any command specific operations. It is currently used by the ELS command
2602 * issuing routines for the ELS State Change Request (SCR),
2603 * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution
2604 * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than
2605 * certain debug loggings, this callback function simply invokes the
2606 * lpfc_els_chk_latt() routine to check whether link went down during the
2607 * discovery process.
2610 lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2611 struct lpfc_iocbq *rspiocb)
2613 struct lpfc_vport *vport = cmdiocb->vport;
2616 irsp = &rspiocb->iocb;
2618 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2619 "ELS cmd cmpl: status:x%x/x%x did:x%x",
2620 irsp->ulpStatus, irsp->un.ulpWord[4],
2621 irsp->un.elsreq64.remoteID);
2622 /* ELS cmd tag <ulpIoTag> completes */
2623 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2624 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
2625 irsp->ulpIoTag, irsp->ulpStatus,
2626 irsp->un.ulpWord[4], irsp->ulpTimeout);
2627 /* Check to see if link went down during discovery */
2628 lpfc_els_chk_latt(vport);
2629 lpfc_els_free_iocb(phba, cmdiocb);
2634 * lpfc_issue_els_scr - Issue a scr to an node on a vport
2635 * @vport: pointer to a host virtual N_Port data structure.
2636 * @nportid: N_Port identifier to the remote node.
2637 * @retry: number of retries to the command IOCB.
2639 * This routine issues a State Change Request (SCR) to a fabric node
2640 * on a @vport. The remote node @nportid is passed into the function. It
2641 * first search the @vport node list to find the matching ndlp. If no such
2642 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
2643 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
2644 * routine is invoked to send the SCR IOCB.
2646 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2647 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2648 * will be stored into the context1 field of the IOCB for the completion
2649 * callback function to the SCR ELS command.
2652 * 0 - Successfully issued scr command
2653 * 1 - Failed to issue scr command
2656 lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
2658 struct lpfc_hba *phba = vport->phba;
2660 struct lpfc_iocbq *elsiocb;
2661 struct lpfc_sli *psli;
2664 struct lpfc_nodelist *ndlp;
2667 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
2669 ndlp = lpfc_findnode_did(vport, nportid);
2671 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2674 lpfc_nlp_init(vport, ndlp, nportid);
2675 lpfc_enqueue_node(vport, ndlp);
2676 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2677 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2682 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2683 ndlp->nlp_DID, ELS_CMD_SCR);
2686 /* This will trigger the release of the node just
2693 icmd = &elsiocb->iocb;
2694 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2696 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
2697 pcmd += sizeof(uint32_t);
2699 /* For SCR, remainder of payload is SCR parameter page */
2700 memset(pcmd, 0, sizeof(SCR));
2701 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
2703 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2704 "Issue SCR: did:x%x",
2705 ndlp->nlp_DID, 0, 0);
2707 phba->fc_stat.elsXmitSCR++;
2708 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
2709 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2711 /* The additional lpfc_nlp_put will cause the following
2712 * lpfc_els_free_iocb routine to trigger the rlease of
2716 lpfc_els_free_iocb(phba, elsiocb);
2719 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2720 * trigger the release of node.
2727 * lpfc_issue_els_farpr - Issue a farp to an node on a vport
2728 * @vport: pointer to a host virtual N_Port data structure.
2729 * @nportid: N_Port identifier to the remote node.
2730 * @retry: number of retries to the command IOCB.
2732 * This routine issues a Fibre Channel Address Resolution Response
2733 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
2734 * is passed into the function. It first search the @vport node list to find
2735 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
2736 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
2737 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
2739 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2740 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2741 * will be stored into the context1 field of the IOCB for the completion
2742 * callback function to the PARPR ELS command.
2745 * 0 - Successfully issued farpr command
2746 * 1 - Failed to issue farpr command
2749 lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
2751 struct lpfc_hba *phba = vport->phba;
2753 struct lpfc_iocbq *elsiocb;
2754 struct lpfc_sli *psli;
2759 struct lpfc_nodelist *ondlp;
2760 struct lpfc_nodelist *ndlp;
2763 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
2765 ndlp = lpfc_findnode_did(vport, nportid);
2767 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2770 lpfc_nlp_init(vport, ndlp, nportid);
2771 lpfc_enqueue_node(vport, ndlp);
2772 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2773 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2778 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2779 ndlp->nlp_DID, ELS_CMD_RNID);
2781 /* This will trigger the release of the node just
2788 icmd = &elsiocb->iocb;
2789 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2791 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
2792 pcmd += sizeof(uint32_t);
2794 /* Fill in FARPR payload */
2795 fp = (FARP *) (pcmd);
2796 memset(fp, 0, sizeof(FARP));
2797 lp = (uint32_t *) pcmd;
2798 *lp++ = be32_to_cpu(nportid);
2799 *lp++ = be32_to_cpu(vport->fc_myDID);
2801 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
2803 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
2804 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
2805 ondlp = lpfc_findnode_did(vport, nportid);
2806 if (ondlp && NLP_CHK_NODE_ACT(ondlp)) {
2807 memcpy(&fp->OportName, &ondlp->nlp_portname,
2808 sizeof(struct lpfc_name));
2809 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
2810 sizeof(struct lpfc_name));
2813 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2814 "Issue FARPR: did:x%x",
2815 ndlp->nlp_DID, 0, 0);
2817 phba->fc_stat.elsXmitFARPR++;
2818 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
2819 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2821 /* The additional lpfc_nlp_put will cause the following
2822 * lpfc_els_free_iocb routine to trigger the release of
2826 lpfc_els_free_iocb(phba, elsiocb);
2829 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2830 * trigger the release of the node.
2837 * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
2838 * @vport: pointer to a host virtual N_Port data structure.
2839 * @nlp: pointer to a node-list data structure.
2841 * This routine cancels the timer with a delayed IOCB-command retry for
2842 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
2843 * removes the ELS retry event if it presents. In addition, if the
2844 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
2845 * commands are sent for the @vport's nodes that require issuing discovery
2849 lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
2851 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2852 struct lpfc_work_evt *evtp;
2854 if (!(nlp->nlp_flag & NLP_DELAY_TMO))
2856 spin_lock_irq(shost->host_lock);
2857 nlp->nlp_flag &= ~NLP_DELAY_TMO;
2858 spin_unlock_irq(shost->host_lock);
2859 del_timer_sync(&nlp->nlp_delayfunc);
2860 nlp->nlp_last_elscmd = 0;
2861 if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
2862 list_del_init(&nlp->els_retry_evt.evt_listp);
2863 /* Decrement nlp reference count held for the delayed retry */
2864 evtp = &nlp->els_retry_evt;
2865 lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
2867 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
2868 spin_lock_irq(shost->host_lock);
2869 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
2870 spin_unlock_irq(shost->host_lock);
2871 if (vport->num_disc_nodes) {
2872 if (vport->port_state < LPFC_VPORT_READY) {
2873 /* Check if there are more ADISCs to be sent */
2874 lpfc_more_adisc(vport);
2876 /* Check if there are more PLOGIs to be sent */
2877 lpfc_more_plogi(vport);
2878 if (vport->num_disc_nodes == 0) {
2879 spin_lock_irq(shost->host_lock);
2880 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2881 spin_unlock_irq(shost->host_lock);
2882 lpfc_can_disctmo(vport);
2883 lpfc_end_rscn(vport);
2892 * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
2893 * @ptr: holder for the pointer to the timer function associated data (ndlp).
2895 * This routine is invoked by the ndlp delayed-function timer to check
2896 * whether there is any pending ELS retry event(s) with the node. If not, it
2897 * simply returns. Otherwise, if there is at least one ELS delayed event, it
2898 * adds the delayed events to the HBA work list and invokes the
2899 * lpfc_worker_wake_up() routine to wake up worker thread to process the
2900 * event. Note that lpfc_nlp_get() is called before posting the event to
2901 * the work list to hold reference count of ndlp so that it guarantees the
2902 * reference to ndlp will still be available when the worker thread gets
2903 * to the event associated with the ndlp.
2906 lpfc_els_retry_delay(unsigned long ptr)
2908 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr;
2909 struct lpfc_vport *vport = ndlp->vport;
2910 struct lpfc_hba *phba = vport->phba;
2911 unsigned long flags;
2912 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
2914 spin_lock_irqsave(&phba->hbalock, flags);
2915 if (!list_empty(&evtp->evt_listp)) {
2916 spin_unlock_irqrestore(&phba->hbalock, flags);
2920 /* We need to hold the node by incrementing the reference
2921 * count until the queued work is done
2923 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
2924 if (evtp->evt_arg1) {
2925 evtp->evt = LPFC_EVT_ELS_RETRY;
2926 list_add_tail(&evtp->evt_listp, &phba->work_list);
2927 lpfc_worker_wake_up(phba);
2929 spin_unlock_irqrestore(&phba->hbalock, flags);
2934 * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
2935 * @ndlp: pointer to a node-list data structure.
2937 * This routine is the worker-thread handler for processing the @ndlp delayed
2938 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
2939 * the last ELS command from the associated ndlp and invokes the proper ELS
2940 * function according to the delayed ELS command to retry the command.
2943 lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
2945 struct lpfc_vport *vport = ndlp->vport;
2946 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2947 uint32_t cmd, did, retry;
2949 spin_lock_irq(shost->host_lock);
2950 did = ndlp->nlp_DID;
2951 cmd = ndlp->nlp_last_elscmd;
2952 ndlp->nlp_last_elscmd = 0;
2954 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
2955 spin_unlock_irq(shost->host_lock);
2959 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
2960 spin_unlock_irq(shost->host_lock);
2962 * If a discovery event readded nlp_delayfunc after timer
2963 * firing and before processing the timer, cancel the
2966 del_timer_sync(&ndlp->nlp_delayfunc);
2967 retry = ndlp->nlp_retry;
2968 ndlp->nlp_retry = 0;
2972 lpfc_issue_els_flogi(vport, ndlp, retry);
2975 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
2976 ndlp->nlp_prev_state = ndlp->nlp_state;
2977 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2981 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
2982 ndlp->nlp_prev_state = ndlp->nlp_state;
2983 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2987 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
2988 ndlp->nlp_prev_state = ndlp->nlp_state;
2989 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
2993 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
2994 ndlp->nlp_prev_state = ndlp->nlp_state;
2995 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
2999 if (!(vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI))
3000 lpfc_issue_els_fdisc(vport, ndlp, retry);
3007 * lpfc_els_retry - Make retry decision on an els command iocb
3008 * @phba: pointer to lpfc hba data structure.
3009 * @cmdiocb: pointer to lpfc command iocb data structure.
3010 * @rspiocb: pointer to lpfc response iocb data structure.
3012 * This routine makes a retry decision on an ELS command IOCB, which has
3013 * failed. The following ELS IOCBs use this function for retrying the command
3014 * when previously issued command responsed with error status: FLOGI, PLOGI,
3015 * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
3016 * returned error status, it makes the decision whether a retry shall be
3017 * issued for the command, and whether a retry shall be made immediately or
3018 * delayed. In the former case, the corresponding ELS command issuing-function
3019 * is called to retry the command. In the later case, the ELS command shall
3020 * be posted to the ndlp delayed event and delayed function timer set to the
3021 * ndlp for the delayed command issusing.
3024 * 0 - No retry of els command is made
3025 * 1 - Immediate or delayed retry of els command is made
3028 lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3029 struct lpfc_iocbq *rspiocb)
3031 struct lpfc_vport *vport = cmdiocb->vport;
3032 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3033 IOCB_t *irsp = &rspiocb->iocb;
3034 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3035 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3038 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
3044 /* Note: context2 may be 0 for internal driver abort
3045 * of delays ELS command.
3048 if (pcmd && pcmd->virt) {
3049 elscmd = (uint32_t *) (pcmd->virt);
3053 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
3054 did = ndlp->nlp_DID;
3056 /* We should only hit this case for retrying PLOGI */
3057 did = irsp->un.elsreq64.remoteID;
3058 ndlp = lpfc_findnode_did(vport, did);
3059 if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp))
3060 && (cmd != ELS_CMD_PLOGI))
3064 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3065 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
3066 *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
3068 switch (irsp->ulpStatus) {
3069 case IOSTAT_FCP_RSP_ERROR:
3071 case IOSTAT_REMOTE_STOP:
3072 if (phba->sli_rev == LPFC_SLI_REV4) {
3073 /* This IO was aborted by the target, we don't
3074 * know the rxid and because we did not send the
3075 * ABTS we cannot generate and RRQ.
3077 lpfc_set_rrq_active(phba, ndlp,
3078 cmdiocb->sli4_lxritag, 0, 0);
3081 case IOSTAT_LOCAL_REJECT:
3082 switch ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK)) {
3083 case IOERR_LOOP_OPEN_FAILURE:
3084 if (cmd == ELS_CMD_FLOGI) {
3085 if (PCI_DEVICE_ID_HORNET ==
3086 phba->pcidev->device) {
3087 phba->fc_topology = LPFC_TOPOLOGY_LOOP;
3088 phba->pport->fc_myDID = 0;
3089 phba->alpa_map[0] = 0;
3090 phba->alpa_map[1] = 0;
3093 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
3098 case IOERR_ILLEGAL_COMMAND:
3099 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3100 "0124 Retry illegal cmd x%x "
3101 "retry:x%x delay:x%x\n",
3102 cmd, cmdiocb->retry, delay);
3104 /* All command's retry policy */
3106 if (cmdiocb->retry > 2)
3110 case IOERR_NO_RESOURCES:
3111 logerr = 1; /* HBA out of resources */
3113 if (cmdiocb->retry > 100)
3118 case IOERR_ILLEGAL_FRAME:
3123 case IOERR_SEQUENCE_TIMEOUT:
3124 case IOERR_INVALID_RPI:
3125 if (cmd == ELS_CMD_PLOGI &&
3126 did == NameServer_DID) {
3127 /* Continue forever if plogi to */
3128 /* the nameserver fails */
3137 case IOSTAT_NPORT_RJT:
3138 case IOSTAT_FABRIC_RJT:
3139 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
3145 case IOSTAT_NPORT_BSY:
3146 case IOSTAT_FABRIC_BSY:
3147 logerr = 1; /* Fabric / Remote NPort out of resources */
3152 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
3153 /* Added for Vendor specifc support
3154 * Just keep retrying for these Rsn / Exp codes
3156 switch (stat.un.b.lsRjtRsnCode) {
3157 case LSRJT_UNABLE_TPC:
3158 if (stat.un.b.lsRjtRsnCodeExp ==
3159 LSEXP_CMD_IN_PROGRESS) {
3160 if (cmd == ELS_CMD_PLOGI) {
3167 if (stat.un.b.lsRjtRsnCodeExp ==
3168 LSEXP_CANT_GIVE_DATA) {
3169 if (cmd == ELS_CMD_PLOGI) {
3176 if ((cmd == ELS_CMD_PLOGI) ||
3177 (cmd == ELS_CMD_PRLI)) {
3179 maxretry = lpfc_max_els_tries + 1;
3183 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
3184 (cmd == ELS_CMD_FDISC) &&
3185 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
3186 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3187 "0125 FDISC Failed (x%x). "
3188 "Fabric out of resources\n",
3189 stat.un.lsRjtError);
3190 lpfc_vport_set_state(vport,
3191 FC_VPORT_NO_FABRIC_RSCS);
3195 case LSRJT_LOGICAL_BSY:
3196 if ((cmd == ELS_CMD_PLOGI) ||
3197 (cmd == ELS_CMD_PRLI)) {
3200 } else if (cmd == ELS_CMD_FDISC) {
3201 /* FDISC retry policy */
3203 if (cmdiocb->retry >= 32)
3209 case LSRJT_LOGICAL_ERR:
3210 /* There are some cases where switches return this
3211 * error when they are not ready and should be returning
3212 * Logical Busy. We should delay every time.
3214 if (cmd == ELS_CMD_FDISC &&
3215 stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
3221 case LSRJT_PROTOCOL_ERR:
3222 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
3223 (cmd == ELS_CMD_FDISC) &&
3224 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
3225 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
3227 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3228 "0122 FDISC Failed (x%x). "
3229 "Fabric Detected Bad WWN\n",
3230 stat.un.lsRjtError);
3231 lpfc_vport_set_state(vport,
3232 FC_VPORT_FABRIC_REJ_WWN);
3238 case IOSTAT_INTERMED_RSP:
3246 if (did == FDMI_DID)
3249 if ((cmd == ELS_CMD_FLOGI) &&
3250 (phba->fc_topology != LPFC_TOPOLOGY_LOOP) &&
3251 !lpfc_error_lost_link(irsp)) {
3252 /* FLOGI retry policy */
3254 /* retry FLOGI forever */
3256 if (cmdiocb->retry >= 100)
3258 else if (cmdiocb->retry >= 32)
3260 } else if ((cmd == ELS_CMD_FDISC) && !lpfc_error_lost_link(irsp)) {
3261 /* retry FDISCs every second up to devloss */
3263 maxretry = vport->cfg_devloss_tmo;
3268 if (maxretry && (cmdiocb->retry >= maxretry)) {
3269 phba->fc_stat.elsRetryExceeded++;
3273 if ((vport->load_flag & FC_UNLOADING) != 0)
3277 if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) {
3278 /* Stop retrying PLOGI and FDISC if in FCF discovery */
3279 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
3280 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3281 "2849 Stop retry ELS command "
3282 "x%x to remote NPORT x%x, "
3283 "Data: x%x x%x\n", cmd, did,
3284 cmdiocb->retry, delay);
3289 /* Retry ELS command <elsCmd> to remote NPORT <did> */
3290 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3291 "0107 Retry ELS command x%x to remote "
3292 "NPORT x%x Data: x%x x%x\n",
3293 cmd, did, cmdiocb->retry, delay);
3295 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
3296 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
3297 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
3298 IOERR_NO_RESOURCES))) {
3299 /* Don't reset timer for no resources */
3301 /* If discovery / RSCN timer is running, reset it */
3302 if (timer_pending(&vport->fc_disctmo) ||
3303 (vport->fc_flag & FC_RSCN_MODE))
3304 lpfc_set_disctmo(vport);
3307 phba->fc_stat.elsXmitRetry++;
3308 if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) {
3309 phba->fc_stat.elsDelayRetry++;
3310 ndlp->nlp_retry = cmdiocb->retry;
3312 /* delay is specified in milliseconds */
3313 mod_timer(&ndlp->nlp_delayfunc,
3314 jiffies + msecs_to_jiffies(delay));
3315 spin_lock_irq(shost->host_lock);
3316 ndlp->nlp_flag |= NLP_DELAY_TMO;
3317 spin_unlock_irq(shost->host_lock);
3319 ndlp->nlp_prev_state = ndlp->nlp_state;
3320 if (cmd == ELS_CMD_PRLI)
3321 lpfc_nlp_set_state(vport, ndlp,
3322 NLP_STE_PRLI_ISSUE);
3324 lpfc_nlp_set_state(vport, ndlp,
3326 ndlp->nlp_last_elscmd = cmd;
3332 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
3335 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
3338 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
3339 ndlp->nlp_prev_state = ndlp->nlp_state;
3340 lpfc_nlp_set_state(vport, ndlp,
3341 NLP_STE_PLOGI_ISSUE);
3343 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
3346 ndlp->nlp_prev_state = ndlp->nlp_state;
3347 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
3348 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
3351 ndlp->nlp_prev_state = ndlp->nlp_state;
3352 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
3353 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
3356 ndlp->nlp_prev_state = ndlp->nlp_state;
3357 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
3358 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
3362 /* No retry ELS command <elsCmd> to remote NPORT <did> */
3364 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3365 "0137 No retry ELS command x%x to remote "
3366 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
3367 cmd, did, irsp->ulpStatus,
3368 irsp->un.ulpWord[4]);
3371 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3372 "0108 No retry ELS command x%x to remote "
3373 "NPORT x%x Retried:%d Error:x%x/%x\n",
3374 cmd, did, cmdiocb->retry, irsp->ulpStatus,
3375 irsp->un.ulpWord[4]);
3381 * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
3382 * @phba: pointer to lpfc hba data structure.
3383 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
3385 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
3386 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
3387 * checks to see whether there is a lpfc DMA buffer associated with the
3388 * response of the command IOCB. If so, it will be released before releasing
3389 * the lpfc DMA buffer associated with the IOCB itself.
3392 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3395 lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
3397 struct lpfc_dmabuf *buf_ptr;
3399 /* Free the response before processing the command. */
3400 if (!list_empty(&buf_ptr1->list)) {
3401 list_remove_head(&buf_ptr1->list, buf_ptr,
3404 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3407 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
3413 * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
3414 * @phba: pointer to lpfc hba data structure.
3415 * @buf_ptr: pointer to the lpfc dma buffer data structure.
3417 * This routine releases the lpfc Direct Memory Access (DMA) buffer
3418 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
3422 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3425 lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
3427 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3433 * lpfc_els_free_iocb - Free a command iocb and its associated resources
3434 * @phba: pointer to lpfc hba data structure.
3435 * @elsiocb: pointer to lpfc els command iocb data structure.
3437 * This routine frees a command IOCB and its associated resources. The
3438 * command IOCB data structure contains the reference to various associated
3439 * resources, these fields must be set to NULL if the associated reference
3441 * context1 - reference to ndlp
3442 * context2 - reference to cmd
3443 * context2->next - reference to rsp
3444 * context3 - reference to bpl
3446 * It first properly decrements the reference count held on ndlp for the
3447 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
3448 * set, it invokes the lpfc_els_free_data() routine to release the Direct
3449 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
3450 * adds the DMA buffer the @phba data structure for the delayed release.
3451 * If reference to the Buffer Pointer List (BPL) is present, the
3452 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
3453 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
3454 * invoked to release the IOCB data structure back to @phba IOCBQ list.
3457 * 0 - Success (currently, always return 0)
3460 lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
3462 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
3463 struct lpfc_nodelist *ndlp;
3465 ndlp = (struct lpfc_nodelist *)elsiocb->context1;
3467 if (ndlp->nlp_flag & NLP_DEFER_RM) {
3470 /* If the ndlp is not being used by another discovery
3473 if (!lpfc_nlp_not_used(ndlp)) {
3474 /* If ndlp is being used by another discovery
3475 * thread, just clear NLP_DEFER_RM
3477 ndlp->nlp_flag &= ~NLP_DEFER_RM;
3482 elsiocb->context1 = NULL;
3484 /* context2 = cmd, context2->next = rsp, context3 = bpl */
3485 if (elsiocb->context2) {
3486 if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
3487 /* Firmware could still be in progress of DMAing
3488 * payload, so don't free data buffer till after
3491 elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
3492 buf_ptr = elsiocb->context2;
3493 elsiocb->context2 = NULL;
3496 spin_lock_irq(&phba->hbalock);
3497 if (!list_empty(&buf_ptr->list)) {
3498 list_remove_head(&buf_ptr->list,
3499 buf_ptr1, struct lpfc_dmabuf,
3501 INIT_LIST_HEAD(&buf_ptr1->list);
3502 list_add_tail(&buf_ptr1->list,
3506 INIT_LIST_HEAD(&buf_ptr->list);
3507 list_add_tail(&buf_ptr->list, &phba->elsbuf);
3509 spin_unlock_irq(&phba->hbalock);
3512 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
3513 lpfc_els_free_data(phba, buf_ptr1);
3517 if (elsiocb->context3) {
3518 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
3519 lpfc_els_free_bpl(phba, buf_ptr);
3521 lpfc_sli_release_iocbq(phba, elsiocb);
3526 * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
3527 * @phba: pointer to lpfc hba data structure.
3528 * @cmdiocb: pointer to lpfc command iocb data structure.
3529 * @rspiocb: pointer to lpfc response iocb data structure.
3531 * This routine is the completion callback function to the Logout (LOGO)
3532 * Accept (ACC) Response ELS command. This routine is invoked to indicate
3533 * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
3534 * release the ndlp if it has the last reference remaining (reference count
3535 * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
3536 * field to NULL to inform the following lpfc_els_free_iocb() routine no
3537 * ndlp reference count needs to be decremented. Otherwise, the ndlp
3538 * reference use-count shall be decremented by the lpfc_els_free_iocb()
3539 * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
3540 * IOCB data structure.
3543 lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3544 struct lpfc_iocbq *rspiocb)
3546 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3547 struct lpfc_vport *vport = cmdiocb->vport;
3550 irsp = &rspiocb->iocb;
3551 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3552 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
3553 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
3554 /* ACC to LOGO completes to NPort <nlp_DID> */
3555 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3556 "0109 ACC to LOGO completes to NPort x%x "
3557 "Data: x%x x%x x%x\n",
3558 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3561 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
3562 /* NPort Recovery mode or node is just allocated */
3563 if (!lpfc_nlp_not_used(ndlp)) {
3564 /* If the ndlp is being used by another discovery
3565 * thread, just unregister the RPI.
3567 lpfc_unreg_rpi(vport, ndlp);
3569 /* Indicate the node has already released, should
3570 * not reference to it from within lpfc_els_free_iocb.
3572 cmdiocb->context1 = NULL;
3577 * The driver received a LOGO from the rport and has ACK'd it.
3578 * At this point, the driver is done so release the IOCB
3580 lpfc_els_free_iocb(phba, cmdiocb);
3583 * Remove the ndlp reference if it's a fabric node that has
3584 * sent us an unsolicted LOGO.
3586 if (ndlp->nlp_type & NLP_FABRIC)
3593 * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
3594 * @phba: pointer to lpfc hba data structure.
3595 * @pmb: pointer to the driver internal queue element for mailbox command.
3597 * This routine is the completion callback function for unregister default
3598 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
3599 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
3600 * decrements the ndlp reference count held for this completion callback
3601 * function. After that, it invokes the lpfc_nlp_not_used() to check
3602 * whether there is only one reference left on the ndlp. If so, it will
3603 * perform one more decrement and trigger the release of the ndlp.
3606 lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3608 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
3609 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
3611 pmb->context1 = NULL;
3612 pmb->context2 = NULL;
3614 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3616 mempool_free(pmb, phba->mbox_mem_pool);
3618 if (NLP_CHK_NODE_ACT(ndlp)) {
3620 /* This is the end of the default RPI cleanup logic for
3621 * this ndlp. If no other discovery threads are using
3622 * this ndlp, free all resources associated with it.
3624 lpfc_nlp_not_used(ndlp);
3626 lpfc_drop_node(ndlp->vport, ndlp);
3634 * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
3635 * @phba: pointer to lpfc hba data structure.
3636 * @cmdiocb: pointer to lpfc command iocb data structure.
3637 * @rspiocb: pointer to lpfc response iocb data structure.
3639 * This routine is the completion callback function for ELS Response IOCB
3640 * command. In normal case, this callback function just properly sets the
3641 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
3642 * field in the command IOCB is not NULL, the referred mailbox command will
3643 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
3644 * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
3645 * link down event occurred during the discovery, the lpfc_nlp_not_used()
3646 * routine shall be invoked trying to release the ndlp if no other threads
3647 * are currently referring it.
3650 lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3651 struct lpfc_iocbq *rspiocb)
3653 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3654 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
3655 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
3658 LPFC_MBOXQ_t *mbox = NULL;
3659 struct lpfc_dmabuf *mp = NULL;
3660 uint32_t ls_rjt = 0;
3662 irsp = &rspiocb->iocb;
3664 if (cmdiocb->context_un.mbox)
3665 mbox = cmdiocb->context_un.mbox;
3667 /* First determine if this is a LS_RJT cmpl. Note, this callback
3668 * function can have cmdiocb->contest1 (ndlp) field set to NULL.
3670 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
3671 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3672 (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) {
3673 /* A LS_RJT associated with Default RPI cleanup has its own
3674 * separate code path.
3676 if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
3680 /* Check to see if link went down during discovery */
3681 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) {
3683 mp = (struct lpfc_dmabuf *) mbox->context1;
3685 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3688 mempool_free(mbox, phba->mbox_mem_pool);
3690 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3691 (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
3692 if (lpfc_nlp_not_used(ndlp)) {
3694 /* Indicate the node has already released,
3695 * should not reference to it from within
3696 * the routine lpfc_els_free_iocb.
3698 cmdiocb->context1 = NULL;
3703 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3704 "ELS rsp cmpl: status:x%x/x%x did:x%x",
3705 irsp->ulpStatus, irsp->un.ulpWord[4],
3706 cmdiocb->iocb.un.elsreq64.remoteID);
3707 /* ELS response tag <ulpIoTag> completes */
3708 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3709 "0110 ELS response tag x%x completes "
3710 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
3711 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
3712 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
3713 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3716 if ((rspiocb->iocb.ulpStatus == 0)
3717 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
3718 lpfc_unreg_rpi(vport, ndlp);
3719 /* Increment reference count to ndlp to hold the
3720 * reference to ndlp for the callback function.
3722 mbox->context2 = lpfc_nlp_get(ndlp);
3723 mbox->vport = vport;
3724 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
3725 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
3726 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
3729 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
3730 ndlp->nlp_prev_state = ndlp->nlp_state;
3731 lpfc_nlp_set_state(vport, ndlp,
3732 NLP_STE_REG_LOGIN_ISSUE);
3734 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
3735 != MBX_NOT_FINISHED)
3738 /* Decrement the ndlp reference count we
3739 * set for this failed mailbox command.
3743 /* ELS rsp: Cannot issue reg_login for <NPortid> */
3744 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3745 "0138 ELS rsp: Cannot issue reg_login for x%x "
3746 "Data: x%x x%x x%x\n",
3747 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3750 if (lpfc_nlp_not_used(ndlp)) {
3752 /* Indicate node has already been released,
3753 * should not reference to it from within
3754 * the routine lpfc_els_free_iocb.
3756 cmdiocb->context1 = NULL;
3759 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
3760 if (!lpfc_error_lost_link(irsp) &&
3761 ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
3762 if (lpfc_nlp_not_used(ndlp)) {
3764 /* Indicate node has already been
3765 * released, should not reference
3766 * to it from within the routine
3767 * lpfc_els_free_iocb.
3769 cmdiocb->context1 = NULL;
3773 mp = (struct lpfc_dmabuf *) mbox->context1;
3775 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3778 mempool_free(mbox, phba->mbox_mem_pool);
3781 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
3782 spin_lock_irq(shost->host_lock);
3783 ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI);
3784 spin_unlock_irq(shost->host_lock);
3786 /* If the node is not being used by another discovery thread,
3787 * and we are sending a reject, we are done with it.
3788 * Release driver reference count here and free associated
3792 if (lpfc_nlp_not_used(ndlp))
3793 /* Indicate node has already been released,
3794 * should not reference to it from within
3795 * the routine lpfc_els_free_iocb.
3797 cmdiocb->context1 = NULL;
3800 lpfc_els_free_iocb(phba, cmdiocb);
3805 * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
3806 * @vport: pointer to a host virtual N_Port data structure.
3807 * @flag: the els command code to be accepted.
3808 * @oldiocb: pointer to the original lpfc command iocb data structure.
3809 * @ndlp: pointer to a node-list data structure.
3810 * @mbox: pointer to the driver internal queue element for mailbox command.
3812 * This routine prepares and issues an Accept (ACC) response IOCB
3813 * command. It uses the @flag to properly set up the IOCB field for the
3814 * specific ACC response command to be issued and invokes the
3815 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
3816 * @mbox pointer is passed in, it will be put into the context_un.mbox
3817 * field of the IOCB for the completion callback function to issue the
3818 * mailbox command to the HBA later when callback is invoked.
3820 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3821 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3822 * will be stored into the context1 field of the IOCB for the completion
3823 * callback function to the corresponding response ELS IOCB command.
3826 * 0 - Successfully issued acc response
3827 * 1 - Failed to issue acc response
3830 lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
3831 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
3834 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3835 struct lpfc_hba *phba = vport->phba;
3838 struct lpfc_iocbq *elsiocb;
3839 struct lpfc_sli *psli;
3843 ELS_PKT *els_pkt_ptr;
3846 oldcmd = &oldiocb->iocb;
3850 cmdsize = sizeof(uint32_t);
3851 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3852 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
3854 spin_lock_irq(shost->host_lock);
3855 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
3856 spin_unlock_irq(shost->host_lock);
3860 icmd = &elsiocb->iocb;
3861 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
3862 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
3863 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3864 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
3865 pcmd += sizeof(uint32_t);
3867 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3868 "Issue ACC: did:x%x flg:x%x",
3869 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3872 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
3873 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3874 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
3878 icmd = &elsiocb->iocb;
3879 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
3880 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
3881 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3884 elsiocb->context_un.mbox = mbox;
3886 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
3887 pcmd += sizeof(uint32_t);
3888 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
3890 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3891 "Issue ACC PLOGI: did:x%x flg:x%x",
3892 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3895 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
3896 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3897 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
3901 icmd = &elsiocb->iocb;
3902 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
3903 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
3904 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3906 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
3907 sizeof(uint32_t) + sizeof(PRLO));
3908 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
3909 els_pkt_ptr = (ELS_PKT *) pcmd;
3910 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
3912 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3913 "Issue ACC PRLO: did:x%x flg:x%x",
3914 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3919 /* Xmit ELS ACC response tag <ulpIoTag> */
3920 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3921 "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
3922 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x "
3924 elsiocb->iotag, elsiocb->iocb.ulpContext,
3925 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3926 ndlp->nlp_rpi, vport->fc_flag);
3927 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
3928 spin_lock_irq(shost->host_lock);
3929 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
3930 spin_unlock_irq(shost->host_lock);
3931 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
3933 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
3936 phba->fc_stat.elsXmitACC++;
3937 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
3938 if (rc == IOCB_ERROR) {
3939 lpfc_els_free_iocb(phba, elsiocb);
3946 * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command
3947 * @vport: pointer to a virtual N_Port data structure.
3949 * @oldiocb: pointer to the original lpfc command iocb data structure.
3950 * @ndlp: pointer to a node-list data structure.
3951 * @mbox: pointer to the driver internal queue element for mailbox command.
3953 * This routine prepares and issue an Reject (RJT) response IOCB
3954 * command. If a @mbox pointer is passed in, it will be put into the
3955 * context_un.mbox field of the IOCB for the completion callback function
3956 * to issue to the HBA later.
3958 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3959 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3960 * will be stored into the context1 field of the IOCB for the completion
3961 * callback function to the reject response ELS IOCB command.
3964 * 0 - Successfully issued reject response
3965 * 1 - Failed to issue reject response
3968 lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
3969 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
3972 struct lpfc_hba *phba = vport->phba;
3975 struct lpfc_iocbq *elsiocb;
3976 struct lpfc_sli *psli;
3982 cmdsize = 2 * sizeof(uint32_t);
3983 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3984 ndlp->nlp_DID, ELS_CMD_LS_RJT);
3988 icmd = &elsiocb->iocb;
3989 oldcmd = &oldiocb->iocb;
3990 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
3991 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
3992 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3994 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
3995 pcmd += sizeof(uint32_t);
3996 *((uint32_t *) (pcmd)) = rejectError;
3999 elsiocb->context_un.mbox = mbox;
4001 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
4002 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4003 "0129 Xmit ELS RJT x%x response tag x%x "
4004 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
4006 rejectError, elsiocb->iotag,
4007 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
4008 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
4009 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4010 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
4011 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
4013 phba->fc_stat.elsXmitLSRJT++;
4014 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4015 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4017 if (rc == IOCB_ERROR) {
4018 lpfc_els_free_iocb(phba, elsiocb);
4025 * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
4026 * @vport: pointer to a virtual N_Port data structure.
4027 * @oldiocb: pointer to the original lpfc command iocb data structure.
4028 * @ndlp: pointer to a node-list data structure.
4030 * This routine prepares and issues an Accept (ACC) response to Address
4031 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
4032 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
4034 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4035 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4036 * will be stored into the context1 field of the IOCB for the completion
4037 * callback function to the ADISC Accept response ELS IOCB command.
4040 * 0 - Successfully issued acc adisc response
4041 * 1 - Failed to issue adisc acc response
4044 lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
4045 struct lpfc_nodelist *ndlp)
4047 struct lpfc_hba *phba = vport->phba;
4049 IOCB_t *icmd, *oldcmd;
4050 struct lpfc_iocbq *elsiocb;
4055 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
4056 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4057 ndlp->nlp_DID, ELS_CMD_ACC);
4061 icmd = &elsiocb->iocb;
4062 oldcmd = &oldiocb->iocb;
4063 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4064 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4066 /* Xmit ADISC ACC response tag <ulpIoTag> */
4067 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4068 "0130 Xmit ADISC ACC response iotag x%x xri: "
4069 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
4070 elsiocb->iotag, elsiocb->iocb.ulpContext,
4071 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4073 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4075 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4076 pcmd += sizeof(uint32_t);
4078 ap = (ADISC *) (pcmd);
4079 ap->hardAL_PA = phba->fc_pref_ALPA;
4080 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
4081 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
4082 ap->DID = be32_to_cpu(vport->fc_myDID);
4084 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4085 "Issue ACC ADISC: did:x%x flg:x%x",
4086 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4088 phba->fc_stat.elsXmitACC++;
4089 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4090 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4091 if (rc == IOCB_ERROR) {
4092 lpfc_els_free_iocb(phba, elsiocb);
4099 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
4100 * @vport: pointer to a virtual N_Port data structure.
4101 * @oldiocb: pointer to the original lpfc command iocb data structure.
4102 * @ndlp: pointer to a node-list data structure.
4104 * This routine prepares and issues an Accept (ACC) response to Process
4105 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
4106 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
4108 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4109 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4110 * will be stored into the context1 field of the IOCB for the completion
4111 * callback function to the PRLI Accept response ELS IOCB command.
4114 * 0 - Successfully issued acc prli response
4115 * 1 - Failed to issue acc prli response
4118 lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
4119 struct lpfc_nodelist *ndlp)
4121 struct lpfc_hba *phba = vport->phba;
4126 struct lpfc_iocbq *elsiocb;
4127 struct lpfc_sli *psli;
4134 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
4135 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4136 ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)));
4140 icmd = &elsiocb->iocb;
4141 oldcmd = &oldiocb->iocb;
4142 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4143 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4145 /* Xmit PRLI ACC response tag <ulpIoTag> */
4146 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4147 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
4148 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
4149 elsiocb->iotag, elsiocb->iocb.ulpContext,
4150 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4152 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4154 *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
4155 pcmd += sizeof(uint32_t);
4157 /* For PRLI, remainder of payload is PRLI parameter page */
4158 memset(pcmd, 0, sizeof(PRLI));
4160 npr = (PRLI *) pcmd;
4163 * If the remote port is a target and our firmware version is 3.20 or
4164 * later, set the following bits for FC-TAPE support.
4166 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
4167 (vpd->rev.feaLevelHigh >= 0x02)) {
4168 npr->ConfmComplAllowed = 1;
4170 npr->TaskRetryIdReq = 1;
4173 npr->acceptRspCode = PRLI_REQ_EXECUTED;
4174 npr->estabImagePair = 1;
4175 npr->readXferRdyDis = 1;
4176 npr->ConfmComplAllowed = 1;
4178 npr->prliType = PRLI_FCP_TYPE;
4179 npr->initiatorFunc = 1;
4181 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4182 "Issue ACC PRLI: did:x%x flg:x%x",
4183 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4185 phba->fc_stat.elsXmitACC++;
4186 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4188 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4189 if (rc == IOCB_ERROR) {
4190 lpfc_els_free_iocb(phba, elsiocb);
4197 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
4198 * @vport: pointer to a virtual N_Port data structure.
4199 * @format: rnid command format.
4200 * @oldiocb: pointer to the original lpfc command iocb data structure.
4201 * @ndlp: pointer to a node-list data structure.
4203 * This routine issues a Request Node Identification Data (RNID) Accept
4204 * (ACC) response. It constructs the RNID ACC response command according to
4205 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
4206 * issue the response. Note that this command does not need to hold the ndlp
4207 * reference count for the callback. So, the ndlp reference count taken by
4208 * the lpfc_prep_els_iocb() routine is put back and the context1 field of
4209 * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
4210 * there is no ndlp reference available.
4212 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4213 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4214 * will be stored into the context1 field of the IOCB for the completion
4215 * callback function. However, for the RNID Accept Response ELS command,
4216 * this is undone later by this routine after the IOCB is allocated.
4219 * 0 - Successfully issued acc rnid response
4220 * 1 - Failed to issue acc rnid response
4223 lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
4224 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
4226 struct lpfc_hba *phba = vport->phba;
4228 IOCB_t *icmd, *oldcmd;
4229 struct lpfc_iocbq *elsiocb;
4230 struct lpfc_sli *psli;
4236 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
4237 + (2 * sizeof(struct lpfc_name));
4239 cmdsize += sizeof(RNID_TOP_DISC);
4241 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4242 ndlp->nlp_DID, ELS_CMD_ACC);
4246 icmd = &elsiocb->iocb;
4247 oldcmd = &oldiocb->iocb;
4248 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4249 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4251 /* Xmit RNID ACC response tag <ulpIoTag> */
4252 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4253 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
4254 elsiocb->iotag, elsiocb->iocb.ulpContext);
4255 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4256 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4257 pcmd += sizeof(uint32_t);
4259 memset(pcmd, 0, sizeof(RNID));
4260 rn = (RNID *) (pcmd);
4261 rn->Format = format;
4262 rn->CommonLen = (2 * sizeof(struct lpfc_name));
4263 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
4264 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
4267 rn->SpecificLen = 0;
4269 case RNID_TOPOLOGY_DISC:
4270 rn->SpecificLen = sizeof(RNID_TOP_DISC);
4271 memcpy(&rn->un.topologyDisc.portName,
4272 &vport->fc_portname, sizeof(struct lpfc_name));
4273 rn->un.topologyDisc.unitType = RNID_HBA;
4274 rn->un.topologyDisc.physPort = 0;
4275 rn->un.topologyDisc.attachedNodes = 0;
4279 rn->SpecificLen = 0;
4283 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4284 "Issue ACC RNID: did:x%x flg:x%x",
4285 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4287 phba->fc_stat.elsXmitACC++;
4288 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4290 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4291 if (rc == IOCB_ERROR) {
4292 lpfc_els_free_iocb(phba, elsiocb);
4299 * lpfc_els_clear_rrq - Clear the rq that this rrq describes.
4300 * @vport: pointer to a virtual N_Port data structure.
4301 * @iocb: pointer to the lpfc command iocb data structure.
4302 * @ndlp: pointer to a node-list data structure.
4307 lpfc_els_clear_rrq(struct lpfc_vport *vport,
4308 struct lpfc_iocbq *iocb, struct lpfc_nodelist *ndlp)
4310 struct lpfc_hba *phba = vport->phba;
4315 struct lpfc_node_rrq *prrq;
4318 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) iocb->context2)->virt);
4319 pcmd += sizeof(uint32_t);
4320 rrq = (struct RRQ *)pcmd;
4321 rrq->rrq_exchg = be32_to_cpu(rrq->rrq_exchg);
4322 rxid = bf_get(rrq_rxid, rrq);
4324 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4325 "2883 Clear RRQ for SID:x%x OXID:x%x RXID:x%x"
4327 be32_to_cpu(bf_get(rrq_did, rrq)),
4328 bf_get(rrq_oxid, rrq),
4330 iocb->iotag, iocb->iocb.ulpContext);
4332 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4333 "Clear RRQ: did:x%x flg:x%x exchg:x%.08x",
4334 ndlp->nlp_DID, ndlp->nlp_flag, rrq->rrq_exchg);
4335 if (vport->fc_myDID == be32_to_cpu(bf_get(rrq_did, rrq)))
4336 xri = bf_get(rrq_oxid, rrq);
4339 prrq = lpfc_get_active_rrq(vport, xri, ndlp->nlp_DID);
4341 lpfc_clr_rrq_active(phba, xri, prrq);
4346 * lpfc_els_rsp_echo_acc - Issue echo acc response
4347 * @vport: pointer to a virtual N_Port data structure.
4348 * @data: pointer to echo data to return in the accept.
4349 * @oldiocb: pointer to the original lpfc command iocb data structure.
4350 * @ndlp: pointer to a node-list data structure.
4353 * 0 - Successfully issued acc echo response
4354 * 1 - Failed to issue acc echo response
4357 lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data,
4358 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
4360 struct lpfc_hba *phba = vport->phba;
4361 struct lpfc_iocbq *elsiocb;
4362 struct lpfc_sli *psli;
4368 cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len;
4370 /* The accumulated length can exceed the BPL_SIZE. For
4371 * now, use this as the limit
4373 if (cmdsize > LPFC_BPL_SIZE)
4374 cmdsize = LPFC_BPL_SIZE;
4375 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4376 ndlp->nlp_DID, ELS_CMD_ACC);
4380 elsiocb->iocb.ulpContext = oldiocb->iocb.ulpContext; /* Xri / rx_id */
4381 elsiocb->iocb.unsli3.rcvsli3.ox_id = oldiocb->iocb.unsli3.rcvsli3.ox_id;
4383 /* Xmit ECHO ACC response tag <ulpIoTag> */
4384 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4385 "2876 Xmit ECHO ACC response tag x%x xri x%x\n",
4386 elsiocb->iotag, elsiocb->iocb.ulpContext);
4387 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4388 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4389 pcmd += sizeof(uint32_t);
4390 memcpy(pcmd, data, cmdsize - sizeof(uint32_t));
4392 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4393 "Issue ACC ECHO: did:x%x flg:x%x",
4394 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4396 phba->fc_stat.elsXmitACC++;
4397 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4399 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4400 if (rc == IOCB_ERROR) {
4401 lpfc_els_free_iocb(phba, elsiocb);
4408 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
4409 * @vport: pointer to a host virtual N_Port data structure.
4411 * This routine issues Address Discover (ADISC) ELS commands to those
4412 * N_Ports which are in node port recovery state and ADISC has not been issued
4413 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
4414 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
4415 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
4416 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
4417 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
4418 * IOCBs quit for later pick up. On the other hand, after walking through
4419 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
4420 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
4421 * no more ADISC need to be sent.
4424 * The number of N_Ports with adisc issued.
4427 lpfc_els_disc_adisc(struct lpfc_vport *vport)
4429 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4430 struct lpfc_nodelist *ndlp, *next_ndlp;
4433 /* go thru NPR nodes and issue any remaining ELS ADISCs */
4434 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
4435 if (!NLP_CHK_NODE_ACT(ndlp))
4437 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
4438 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
4439 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
4440 spin_lock_irq(shost->host_lock);
4441 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
4442 spin_unlock_irq(shost->host_lock);
4443 ndlp->nlp_prev_state = ndlp->nlp_state;
4444 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
4445 lpfc_issue_els_adisc(vport, ndlp, 0);
4447 vport->num_disc_nodes++;
4448 if (vport->num_disc_nodes >=
4449 vport->cfg_discovery_threads) {
4450 spin_lock_irq(shost->host_lock);
4451 vport->fc_flag |= FC_NLP_MORE;
4452 spin_unlock_irq(shost->host_lock);
4457 if (sentadisc == 0) {
4458 spin_lock_irq(shost->host_lock);
4459 vport->fc_flag &= ~FC_NLP_MORE;
4460 spin_unlock_irq(shost->host_lock);
4466 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
4467 * @vport: pointer to a host virtual N_Port data structure.
4469 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
4470 * which are in node port recovery state, with a @vport. Each time an ELS
4471 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
4472 * the per @vport number of discover count (num_disc_nodes) shall be
4473 * incremented. If the num_disc_nodes reaches a pre-configured threshold
4474 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
4475 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
4476 * later pick up. On the other hand, after walking through all the ndlps with
4477 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
4478 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
4479 * PLOGI need to be sent.
4482 * The number of N_Ports with plogi issued.
4485 lpfc_els_disc_plogi(struct lpfc_vport *vport)
4487 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4488 struct lpfc_nodelist *ndlp, *next_ndlp;
4491 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
4492 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
4493 if (!NLP_CHK_NODE_ACT(ndlp))
4495 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
4496 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
4497 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
4498 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
4499 ndlp->nlp_prev_state = ndlp->nlp_state;
4500 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
4501 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
4503 vport->num_disc_nodes++;
4504 if (vport->num_disc_nodes >=
4505 vport->cfg_discovery_threads) {
4506 spin_lock_irq(shost->host_lock);
4507 vport->fc_flag |= FC_NLP_MORE;
4508 spin_unlock_irq(shost->host_lock);
4514 lpfc_set_disctmo(vport);
4517 spin_lock_irq(shost->host_lock);
4518 vport->fc_flag &= ~FC_NLP_MORE;
4519 spin_unlock_irq(shost->host_lock);
4525 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
4526 * @vport: pointer to a host virtual N_Port data structure.
4528 * This routine cleans up any Registration State Change Notification
4529 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
4530 * @vport together with the host_lock is used to prevent multiple thread
4531 * trying to access the RSCN array on a same @vport at the same time.
4534 lpfc_els_flush_rscn(struct lpfc_vport *vport)
4536 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4537 struct lpfc_hba *phba = vport->phba;
4540 spin_lock_irq(shost->host_lock);
4541 if (vport->fc_rscn_flush) {
4542 /* Another thread is walking fc_rscn_id_list on this vport */
4543 spin_unlock_irq(shost->host_lock);
4546 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
4547 vport->fc_rscn_flush = 1;
4548 spin_unlock_irq(shost->host_lock);
4550 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
4551 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
4552 vport->fc_rscn_id_list[i] = NULL;
4554 spin_lock_irq(shost->host_lock);
4555 vport->fc_rscn_id_cnt = 0;
4556 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
4557 spin_unlock_irq(shost->host_lock);
4558 lpfc_can_disctmo(vport);
4559 /* Indicate we are done walking this fc_rscn_id_list */
4560 vport->fc_rscn_flush = 0;
4564 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
4565 * @vport: pointer to a host virtual N_Port data structure.
4566 * @did: remote destination port identifier.
4568 * This routine checks whether there is any pending Registration State
4569 * Configuration Notification (RSCN) to a @did on @vport.
4572 * None zero - The @did matched with a pending rscn
4573 * 0 - not able to match @did with a pending rscn
4576 lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
4581 uint32_t payload_len, i;
4582 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4584 ns_did.un.word = did;
4586 /* Never match fabric nodes for RSCNs */
4587 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
4590 /* If we are doing a FULL RSCN rediscovery, match everything */
4591 if (vport->fc_flag & FC_RSCN_DISCOVERY)
4594 spin_lock_irq(shost->host_lock);
4595 if (vport->fc_rscn_flush) {
4596 /* Another thread is walking fc_rscn_id_list on this vport */
4597 spin_unlock_irq(shost->host_lock);
4600 /* Indicate we are walking fc_rscn_id_list on this vport */
4601 vport->fc_rscn_flush = 1;
4602 spin_unlock_irq(shost->host_lock);
4603 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
4604 lp = vport->fc_rscn_id_list[i]->virt;
4605 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
4606 payload_len -= sizeof(uint32_t); /* take off word 0 */
4607 while (payload_len) {
4608 rscn_did.un.word = be32_to_cpu(*lp++);
4609 payload_len -= sizeof(uint32_t);
4610 switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) {
4611 case RSCN_ADDRESS_FORMAT_PORT:
4612 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
4613 && (ns_did.un.b.area == rscn_did.un.b.area)
4614 && (ns_did.un.b.id == rscn_did.un.b.id))
4615 goto return_did_out;
4617 case RSCN_ADDRESS_FORMAT_AREA:
4618 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
4619 && (ns_did.un.b.area == rscn_did.un.b.area))
4620 goto return_did_out;
4622 case RSCN_ADDRESS_FORMAT_DOMAIN:
4623 if (ns_did.un.b.domain == rscn_did.un.b.domain)
4624 goto return_did_out;
4626 case RSCN_ADDRESS_FORMAT_FABRIC:
4627 goto return_did_out;
4631 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4632 vport->fc_rscn_flush = 0;
4635 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4636 vport->fc_rscn_flush = 0;
4641 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
4642 * @vport: pointer to a host virtual N_Port data structure.
4644 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
4645 * state machine for a @vport's nodes that are with pending RSCN (Registration
4646 * State Change Notification).
4649 * 0 - Successful (currently alway return 0)
4652 lpfc_rscn_recovery_check(struct lpfc_vport *vport)
4654 struct lpfc_nodelist *ndlp = NULL;
4656 /* Move all affected nodes by pending RSCNs to NPR state. */
4657 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
4658 if (!NLP_CHK_NODE_ACT(ndlp) ||
4659 (ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
4660 !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
4662 lpfc_disc_state_machine(vport, ndlp, NULL,
4663 NLP_EVT_DEVICE_RECOVERY);
4664 lpfc_cancel_retry_delay_tmo(vport, ndlp);
4670 * lpfc_send_rscn_event - Send an RSCN event to management application
4671 * @vport: pointer to a host virtual N_Port data structure.
4672 * @cmdiocb: pointer to lpfc command iocb data structure.
4674 * lpfc_send_rscn_event sends an RSCN netlink event to management
4678 lpfc_send_rscn_event(struct lpfc_vport *vport,
4679 struct lpfc_iocbq *cmdiocb)
4681 struct lpfc_dmabuf *pcmd;
4682 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4683 uint32_t *payload_ptr;
4684 uint32_t payload_len;
4685 struct lpfc_rscn_event_header *rscn_event_data;
4687 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4688 payload_ptr = (uint32_t *) pcmd->virt;
4689 payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK);
4691 rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) +
4692 payload_len, GFP_KERNEL);
4693 if (!rscn_event_data) {
4694 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4695 "0147 Failed to allocate memory for RSCN event\n");
4698 rscn_event_data->event_type = FC_REG_RSCN_EVENT;
4699 rscn_event_data->payload_length = payload_len;
4700 memcpy(rscn_event_data->rscn_payload, payload_ptr,
4703 fc_host_post_vendor_event(shost,
4704 fc_get_event_number(),
4705 sizeof(struct lpfc_els_event_header) + payload_len,
4706 (char *)rscn_event_data,
4709 kfree(rscn_event_data);
4713 * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
4714 * @vport: pointer to a host virtual N_Port data structure.
4715 * @cmdiocb: pointer to lpfc command iocb data structure.
4716 * @ndlp: pointer to a node-list data structure.
4718 * This routine processes an unsolicited RSCN (Registration State Change
4719 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
4720 * to invoke fc_host_post_event() routine to the FC transport layer. If the
4721 * discover state machine is about to begin discovery, it just accepts the
4722 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
4723 * contains N_Port IDs for other vports on this HBA, it just accepts the
4724 * RSCN and ignore processing it. If the state machine is in the recovery
4725 * state, the fc_rscn_id_list of this @vport is walked and the
4726 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
4727 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
4728 * routine is invoked to handle the RSCN event.
4731 * 0 - Just sent the acc response
4732 * 1 - Sent the acc response and waited for name server completion
4735 lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4736 struct lpfc_nodelist *ndlp)
4738 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4739 struct lpfc_hba *phba = vport->phba;
4740 struct lpfc_dmabuf *pcmd;
4741 uint32_t *lp, *datap;
4743 uint32_t payload_len, length, nportid, *cmd;
4745 int rscn_id = 0, hba_id = 0;
4748 icmd = &cmdiocb->iocb;
4749 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4750 lp = (uint32_t *) pcmd->virt;
4752 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
4753 payload_len -= sizeof(uint32_t); /* take off word 0 */
4755 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4756 "0214 RSCN received Data: x%x x%x x%x x%x\n",
4757 vport->fc_flag, payload_len, *lp,
4758 vport->fc_rscn_id_cnt);
4760 /* Send an RSCN event to the management application */
4761 lpfc_send_rscn_event(vport, cmdiocb);
4763 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
4764 fc_host_post_event(shost, fc_get_event_number(),
4765 FCH_EVT_RSCN, lp[i]);
4767 /* If we are about to begin discovery, just ACC the RSCN.
4768 * Discovery processing will satisfy it.
4770 if (vport->port_state <= LPFC_NS_QRY) {
4771 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4772 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
4773 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4775 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
4779 /* If this RSCN just contains NPortIDs for other vports on this HBA,
4780 * just ACC and ignore it.
4782 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
4783 !(vport->cfg_peer_port_login)) {
4788 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
4789 i -= sizeof(uint32_t);
4791 if (lpfc_find_vport_by_did(phba, nportid))
4794 if (rscn_id == hba_id) {
4795 /* ALL NPortIDs in RSCN are on HBA */
4796 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4798 "Data: x%x x%x x%x x%x\n",
4799 vport->fc_flag, payload_len,
4800 *lp, vport->fc_rscn_id_cnt);
4801 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4802 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
4803 ndlp->nlp_DID, vport->port_state,
4806 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
4812 spin_lock_irq(shost->host_lock);
4813 if (vport->fc_rscn_flush) {
4814 /* Another thread is walking fc_rscn_id_list on this vport */
4815 vport->fc_flag |= FC_RSCN_DISCOVERY;
4816 spin_unlock_irq(shost->host_lock);
4818 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
4821 /* Indicate we are walking fc_rscn_id_list on this vport */
4822 vport->fc_rscn_flush = 1;
4823 spin_unlock_irq(shost->host_lock);
4824 /* Get the array count after successfully have the token */
4825 rscn_cnt = vport->fc_rscn_id_cnt;
4826 /* If we are already processing an RSCN, save the received
4827 * RSCN payload buffer, cmdiocb->context2 to process later.
4829 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
4830 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4831 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
4832 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4834 spin_lock_irq(shost->host_lock);
4835 vport->fc_flag |= FC_RSCN_DEFERRED;
4836 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
4837 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
4838 vport->fc_flag |= FC_RSCN_MODE;
4839 spin_unlock_irq(shost->host_lock);
4841 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
4842 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
4845 (payload_len + length <= LPFC_BPL_SIZE)) {
4846 *cmd &= ELS_CMD_MASK;
4847 *cmd |= cpu_to_be32(payload_len + length);
4848 memcpy(((uint8_t *)cmd) + length, lp,
4851 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
4852 vport->fc_rscn_id_cnt++;
4853 /* If we zero, cmdiocb->context2, the calling
4854 * routine will not try to free it.
4856 cmdiocb->context2 = NULL;
4859 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4860 "0235 Deferred RSCN "
4861 "Data: x%x x%x x%x\n",
4862 vport->fc_rscn_id_cnt, vport->fc_flag,
4865 vport->fc_flag |= FC_RSCN_DISCOVERY;
4866 spin_unlock_irq(shost->host_lock);
4867 /* ReDiscovery RSCN */
4868 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4869 "0234 ReDiscovery RSCN "
4870 "Data: x%x x%x x%x\n",
4871 vport->fc_rscn_id_cnt, vport->fc_flag,
4874 /* Indicate we are done walking fc_rscn_id_list on this vport */
4875 vport->fc_rscn_flush = 0;
4877 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
4878 /* send RECOVERY event for ALL nodes that match RSCN payload */
4879 lpfc_rscn_recovery_check(vport);
4880 spin_lock_irq(shost->host_lock);
4881 vport->fc_flag &= ~FC_RSCN_DEFERRED;
4882 spin_unlock_irq(shost->host_lock);
4885 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4886 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
4887 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4889 spin_lock_irq(shost->host_lock);
4890 vport->fc_flag |= FC_RSCN_MODE;
4891 spin_unlock_irq(shost->host_lock);
4892 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
4893 /* Indicate we are done walking fc_rscn_id_list on this vport */
4894 vport->fc_rscn_flush = 0;
4896 * If we zero, cmdiocb->context2, the calling routine will
4897 * not try to free it.
4899 cmdiocb->context2 = NULL;
4900 lpfc_set_disctmo(vport);
4902 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
4903 /* send RECOVERY event for ALL nodes that match RSCN payload */
4904 lpfc_rscn_recovery_check(vport);
4905 return lpfc_els_handle_rscn(vport);
4909 * lpfc_els_handle_rscn - Handle rscn for a vport
4910 * @vport: pointer to a host virtual N_Port data structure.
4912 * This routine handles the Registration State Configuration Notification
4913 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
4914 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
4915 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
4916 * NameServer shall be issued. If CT command to the NameServer fails to be
4917 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
4918 * RSCN activities with the @vport.
4921 * 0 - Cleaned up rscn on the @vport
4922 * 1 - Wait for plogi to name server before proceed
4925 lpfc_els_handle_rscn(struct lpfc_vport *vport)
4927 struct lpfc_nodelist *ndlp;
4928 struct lpfc_hba *phba = vport->phba;
4930 /* Ignore RSCN if the port is being torn down. */
4931 if (vport->load_flag & FC_UNLOADING) {
4932 lpfc_els_flush_rscn(vport);
4936 /* Start timer for RSCN processing */
4937 lpfc_set_disctmo(vport);
4939 /* RSCN processed */
4940 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4941 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
4942 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
4945 /* To process RSCN, first compare RSCN data with NameServer */
4946 vport->fc_ns_retry = 0;
4947 vport->num_disc_nodes = 0;
4949 ndlp = lpfc_findnode_did(vport, NameServer_DID);
4950 if (ndlp && NLP_CHK_NODE_ACT(ndlp)
4951 && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
4952 /* Good ndlp, issue CT Request to NameServer */
4953 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0)
4954 /* Wait for NameServer query cmpl before we can
4958 /* If login to NameServer does not exist, issue one */
4959 /* Good status, issue PLOGI to NameServer */
4960 ndlp = lpfc_findnode_did(vport, NameServer_DID);
4961 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
4962 /* Wait for NameServer login cmpl before we can
4967 ndlp = lpfc_enable_node(vport, ndlp,
4968 NLP_STE_PLOGI_ISSUE);
4970 lpfc_els_flush_rscn(vport);
4973 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
4975 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
4977 lpfc_els_flush_rscn(vport);
4980 lpfc_nlp_init(vport, ndlp, NameServer_DID);
4981 ndlp->nlp_prev_state = ndlp->nlp_state;
4982 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
4984 ndlp->nlp_type |= NLP_FABRIC;
4985 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
4986 /* Wait for NameServer login cmpl before we can
4992 lpfc_els_flush_rscn(vport);
4997 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
4998 * @vport: pointer to a host virtual N_Port data structure.
4999 * @cmdiocb: pointer to lpfc command iocb data structure.
5000 * @ndlp: pointer to a node-list data structure.
5002 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
5003 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
5004 * point topology. As an unsolicited FLOGI should not be received in a loop
5005 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
5006 * lpfc_check_sparm() routine is invoked to check the parameters in the
5007 * unsolicited FLOGI. If parameters validation failed, the routine
5008 * lpfc_els_rsp_reject() shall be called with reject reason code set to
5009 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
5010 * FLOGI shall be compared with the Port WWN of the @vport to determine who
5011 * will initiate PLOGI. The higher lexicographical value party shall has
5012 * higher priority (as the winning port) and will initiate PLOGI and
5013 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
5014 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
5015 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
5018 * 0 - Successfully processed the unsolicited flogi
5019 * 1 - Failed to process the unsolicited flogi
5022 lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5023 struct lpfc_nodelist *ndlp)
5025 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5026 struct lpfc_hba *phba = vport->phba;
5027 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5028 uint32_t *lp = (uint32_t *) pcmd->virt;
5029 IOCB_t *icmd = &cmdiocb->iocb;
5030 struct serv_parm *sp;
5037 sp = (struct serv_parm *) lp;
5039 /* FLOGI received */
5041 lpfc_set_disctmo(vport);
5043 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
5044 /* We should never receive a FLOGI in loop mode, ignore it */
5045 did = icmd->un.elsreq64.remoteID;
5047 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
5049 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5050 "0113 An FLOGI ELS command x%x was "
5051 "received from DID x%x in Loop Mode\n",
5056 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1))) {
5057 /* For a FLOGI we accept, then if our portname is greater
5058 * then the remote portname we initiate Nport login.
5061 rc = memcmp(&vport->fc_portname, &sp->portName,
5062 sizeof(struct lpfc_name));
5065 if (phba->sli_rev < LPFC_SLI_REV4) {
5066 mbox = mempool_alloc(phba->mbox_mem_pool,
5070 lpfc_linkdown(phba);
5071 lpfc_init_link(phba, mbox,
5073 phba->cfg_link_speed);
5074 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
5075 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5076 mbox->vport = vport;
5077 rc = lpfc_sli_issue_mbox(phba, mbox,
5079 lpfc_set_loopback_flag(phba);
5080 if (rc == MBX_NOT_FINISHED)
5081 mempool_free(mbox, phba->mbox_mem_pool);
5084 /* abort the flogi coming back to ourselves
5085 * due to external loopback on the port.
5087 lpfc_els_abort_flogi(phba);
5090 } else if (rc > 0) { /* greater than */
5091 spin_lock_irq(shost->host_lock);
5092 vport->fc_flag |= FC_PT2PT_PLOGI;
5093 spin_unlock_irq(shost->host_lock);
5095 /* If we have the high WWPN we can assign our own
5096 * myDID; otherwise, we have to WAIT for a PLOGI
5097 * from the remote NPort to find out what it
5100 vport->fc_myDID = PT2PT_LocalID;
5104 * The vport state should go to LPFC_FLOGI only
5105 * AFTER we issue a FLOGI, not receive one.
5107 spin_lock_irq(shost->host_lock);
5108 vport->fc_flag |= FC_PT2PT;
5109 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
5110 spin_unlock_irq(shost->host_lock);
5113 * We temporarily set fc_myDID to make it look like we are
5114 * a Fabric. This is done just so we end up with the right
5115 * did / sid on the FLOGI ACC rsp.
5117 did = vport->fc_myDID;
5118 vport->fc_myDID = Fabric_DID;
5121 /* Reject this request because invalid parameters */
5122 stat.un.b.lsRjtRsvd0 = 0;
5123 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5124 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
5125 stat.un.b.vendorUnique = 0;
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 LS_RJT rsp.
5132 did = vport->fc_myDID;
5133 vport->fc_myDID = Fabric_DID;
5135 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
5138 /* Now lets put fc_myDID back to what its supposed to be */
5139 vport->fc_myDID = did;
5145 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
5147 /* Now lets put fc_myDID back to what its supposed to be */
5148 vport->fc_myDID = did;
5150 if (!(vport->fc_flag & FC_PT2PT_PLOGI)) {
5152 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5156 lpfc_config_link(phba, mbox);
5158 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5159 mbox->vport = vport;
5160 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
5161 if (rc == MBX_NOT_FINISHED) {
5162 mempool_free(mbox, phba->mbox_mem_pool);
5173 * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
5174 * @vport: pointer to a host virtual N_Port data structure.
5175 * @cmdiocb: pointer to lpfc command iocb data structure.
5176 * @ndlp: pointer to a node-list data structure.
5178 * This routine processes Request Node Identification Data (RNID) IOCB
5179 * received as an ELS unsolicited event. Only when the RNID specified format
5180 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
5181 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
5182 * Accept (ACC) the RNID ELS command. All the other RNID formats are
5183 * rejected by invoking the lpfc_els_rsp_reject() routine.
5186 * 0 - Successfully processed rnid iocb (currently always return 0)
5189 lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5190 struct lpfc_nodelist *ndlp)
5192 struct lpfc_dmabuf *pcmd;
5199 icmd = &cmdiocb->iocb;
5200 did = icmd->un.elsreq64.remoteID;
5201 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5202 lp = (uint32_t *) pcmd->virt;
5209 switch (rn->Format) {
5211 case RNID_TOPOLOGY_DISC:
5213 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
5216 /* Reject this request because format not supported */
5217 stat.un.b.lsRjtRsvd0 = 0;
5218 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5219 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5220 stat.un.b.vendorUnique = 0;
5221 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
5228 * lpfc_els_rcv_echo - Process an unsolicited echo iocb
5229 * @vport: pointer to a host virtual N_Port data structure.
5230 * @cmdiocb: pointer to lpfc command iocb data structure.
5231 * @ndlp: pointer to a node-list data structure.
5234 * 0 - Successfully processed echo iocb (currently always return 0)
5237 lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5238 struct lpfc_nodelist *ndlp)
5242 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
5244 /* skip over first word of echo command to find echo data */
5245 pcmd += sizeof(uint32_t);
5247 lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp);
5252 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
5253 * @vport: pointer to a host virtual N_Port data structure.
5254 * @cmdiocb: pointer to lpfc command iocb data structure.
5255 * @ndlp: pointer to a node-list data structure.
5257 * This routine processes a Link Incident Report Registration(LIRR) IOCB
5258 * received as an ELS unsolicited event. Currently, this function just invokes
5259 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
5262 * 0 - Successfully processed lirr iocb (currently always return 0)
5265 lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5266 struct lpfc_nodelist *ndlp)
5270 /* For now, unconditionally reject this command */
5271 stat.un.b.lsRjtRsvd0 = 0;
5272 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5273 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5274 stat.un.b.vendorUnique = 0;
5275 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5280 * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb
5281 * @vport: pointer to a host virtual N_Port data structure.
5282 * @cmdiocb: pointer to lpfc command iocb data structure.
5283 * @ndlp: pointer to a node-list data structure.
5285 * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB
5286 * received as an ELS unsolicited event. A request to RRQ shall only
5287 * be accepted if the Originator Nx_Port N_Port_ID or the Responder
5288 * Nx_Port N_Port_ID of the target Exchange is the same as the
5289 * N_Port_ID of the Nx_Port that makes the request. If the RRQ is
5290 * not accepted, an LS_RJT with reason code "Unable to perform
5291 * command request" and reason code explanation "Invalid Originator
5292 * S_ID" shall be returned. For now, we just unconditionally accept
5293 * RRQ from the target.
5296 lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5297 struct lpfc_nodelist *ndlp)
5299 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
5300 if (vport->phba->sli_rev == LPFC_SLI_REV4)
5301 lpfc_els_clear_rrq(vport, cmdiocb, ndlp);
5305 * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
5306 * @phba: pointer to lpfc hba data structure.
5307 * @pmb: pointer to the driver internal queue element for mailbox command.
5309 * This routine is the completion callback function for the MBX_READ_LNK_STAT
5310 * mailbox command. This callback function is to actually send the Accept
5311 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
5312 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
5313 * mailbox command, constructs the RPS response with the link statistics
5314 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
5315 * response to the RPS.
5317 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5318 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5319 * will be stored into the context1 field of the IOCB for the completion
5320 * callback function to the RPS Accept Response ELS IOCB command.
5324 lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
5328 struct RLS_RSP *rls_rsp;
5330 struct lpfc_iocbq *elsiocb;
5331 struct lpfc_nodelist *ndlp;
5338 ndlp = (struct lpfc_nodelist *) pmb->context2;
5339 rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff);
5340 oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff);
5341 pmb->context1 = NULL;
5342 pmb->context2 = NULL;
5344 if (mb->mbxStatus) {
5345 mempool_free(pmb, phba->mbox_mem_pool);
5349 cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t);
5350 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5351 lpfc_max_els_tries, ndlp,
5352 ndlp->nlp_DID, ELS_CMD_ACC);
5354 /* Decrement the ndlp reference count from previous mbox command */
5358 mempool_free(pmb, phba->mbox_mem_pool);
5362 icmd = &elsiocb->iocb;
5363 icmd->ulpContext = rxid;
5364 icmd->unsli3.rcvsli3.ox_id = oxid;
5366 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5367 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5368 pcmd += sizeof(uint32_t); /* Skip past command */
5369 rls_rsp = (struct RLS_RSP *)pcmd;
5371 rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
5372 rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
5373 rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
5374 rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
5375 rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
5376 rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
5377 mempool_free(pmb, phba->mbox_mem_pool);
5378 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
5379 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
5380 "2874 Xmit ELS RLS ACC response tag x%x xri x%x, "
5381 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
5382 elsiocb->iotag, elsiocb->iocb.ulpContext,
5383 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5385 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5386 phba->fc_stat.elsXmitACC++;
5387 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
5388 lpfc_els_free_iocb(phba, elsiocb);
5392 * lpfc_els_rsp_rps_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
5393 * @phba: pointer to lpfc hba data structure.
5394 * @pmb: pointer to the driver internal queue element for mailbox command.
5396 * This routine is the completion callback function for the MBX_READ_LNK_STAT
5397 * mailbox command. This callback function is to actually send the Accept
5398 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
5399 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
5400 * mailbox command, constructs the RPS response with the link statistics
5401 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
5402 * response to the RPS.
5404 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5405 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5406 * will be stored into the context1 field of the IOCB for the completion
5407 * callback function to the RPS Accept Response ELS IOCB command.
5411 lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
5417 struct lpfc_iocbq *elsiocb;
5418 struct lpfc_nodelist *ndlp;
5426 ndlp = (struct lpfc_nodelist *) pmb->context2;
5427 rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff);
5428 oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff);
5429 pmb->context1 = NULL;
5430 pmb->context2 = NULL;
5432 if (mb->mbxStatus) {
5433 mempool_free(pmb, phba->mbox_mem_pool);
5437 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
5438 mempool_free(pmb, phba->mbox_mem_pool);
5439 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5440 lpfc_max_els_tries, ndlp,
5441 ndlp->nlp_DID, ELS_CMD_ACC);
5443 /* Decrement the ndlp reference count from previous mbox command */
5449 icmd = &elsiocb->iocb;
5450 icmd->ulpContext = rxid;
5451 icmd->unsli3.rcvsli3.ox_id = oxid;
5453 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5454 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5455 pcmd += sizeof(uint32_t); /* Skip past command */
5456 rps_rsp = (RPS_RSP *)pcmd;
5458 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP)
5462 if (phba->pport->fc_flag & FC_FABRIC)
5466 rps_rsp->portStatus = cpu_to_be16(status);
5467 rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
5468 rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
5469 rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
5470 rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
5471 rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
5472 rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
5473 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
5474 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
5475 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
5476 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
5477 elsiocb->iotag, elsiocb->iocb.ulpContext,
5478 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5480 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5481 phba->fc_stat.elsXmitACC++;
5482 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
5483 lpfc_els_free_iocb(phba, elsiocb);
5488 * lpfc_els_rcv_rls - Process an unsolicited rls iocb
5489 * @vport: pointer to a host virtual N_Port data structure.
5490 * @cmdiocb: pointer to lpfc command iocb data structure.
5491 * @ndlp: pointer to a node-list data structure.
5493 * This routine processes Read Port Status (RPL) IOCB received as an
5494 * ELS unsolicited event. It first checks the remote port state. If the
5495 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5496 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
5497 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
5498 * for reading the HBA link statistics. It is for the callback function,
5499 * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command
5500 * to actually sending out RPL Accept (ACC) response.
5503 * 0 - Successfully processed rls iocb (currently always return 0)
5506 lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5507 struct lpfc_nodelist *ndlp)
5509 struct lpfc_hba *phba = vport->phba;
5511 struct lpfc_dmabuf *pcmd;
5514 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5515 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
5516 /* reject the unsolicited RPS request and done with it */
5519 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5521 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
5523 lpfc_read_lnk_stat(phba, mbox);
5524 mbox->context1 = (void *)((unsigned long)
5525 ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) |
5526 cmdiocb->iocb.ulpContext)); /* rx_id */
5527 mbox->context2 = lpfc_nlp_get(ndlp);
5528 mbox->vport = vport;
5529 mbox->mbox_cmpl = lpfc_els_rsp_rls_acc;
5530 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
5531 != MBX_NOT_FINISHED)
5532 /* Mbox completion will send ELS Response */
5534 /* Decrement reference count used for the failed mbox
5538 mempool_free(mbox, phba->mbox_mem_pool);
5541 /* issue rejection response */
5542 stat.un.b.lsRjtRsvd0 = 0;
5543 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5544 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5545 stat.un.b.vendorUnique = 0;
5546 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5551 * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb
5552 * @vport: pointer to a host virtual N_Port data structure.
5553 * @cmdiocb: pointer to lpfc command iocb data structure.
5554 * @ndlp: pointer to a node-list data structure.
5556 * This routine processes Read Timout Value (RTV) IOCB received as an
5557 * ELS unsolicited event. It first checks the remote port state. If the
5558 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5559 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
5560 * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout
5561 * Value (RTV) unsolicited IOCB event.
5563 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5564 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5565 * will be stored into the context1 field of the IOCB for the completion
5566 * callback function to the RPS Accept Response ELS IOCB command.
5569 * 0 - Successfully processed rtv iocb (currently always return 0)
5572 lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5573 struct lpfc_nodelist *ndlp)
5575 struct lpfc_hba *phba = vport->phba;
5577 struct RTV_RSP *rtv_rsp;
5579 struct lpfc_iocbq *elsiocb;
5583 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5584 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
5585 /* reject the unsolicited RPS request and done with it */
5588 cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t);
5589 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5590 lpfc_max_els_tries, ndlp,
5591 ndlp->nlp_DID, ELS_CMD_ACC);
5596 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5597 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5598 pcmd += sizeof(uint32_t); /* Skip past command */
5600 /* use the command's xri in the response */
5601 elsiocb->iocb.ulpContext = cmdiocb->iocb.ulpContext; /* Xri / rx_id */
5602 elsiocb->iocb.unsli3.rcvsli3.ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id;
5604 rtv_rsp = (struct RTV_RSP *)pcmd;
5606 /* populate RTV payload */
5607 rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000); /* report msecs */
5608 rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov);
5609 bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0);
5610 bf_set(qtov_rttov, rtv_rsp, 0); /* Field is for FC ONLY */
5611 rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov);
5613 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
5614 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
5615 "2875 Xmit ELS RTV ACC response tag x%x xri x%x, "
5616 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, "
5617 "Data: x%x x%x x%x\n",
5618 elsiocb->iotag, elsiocb->iocb.ulpContext,
5619 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5621 rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov);
5622 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5623 phba->fc_stat.elsXmitACC++;
5624 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
5625 lpfc_els_free_iocb(phba, elsiocb);
5629 /* issue rejection response */
5630 stat.un.b.lsRjtRsvd0 = 0;
5631 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5632 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5633 stat.un.b.vendorUnique = 0;
5634 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5638 /* lpfc_els_rcv_rps - Process an unsolicited rps iocb
5639 * @vport: pointer to a host virtual N_Port data structure.
5640 * @cmdiocb: pointer to lpfc command iocb data structure.
5641 * @ndlp: pointer to a node-list data structure.
5643 * This routine processes Read Port Status (RPS) IOCB received as an
5644 * ELS unsolicited event. It first checks the remote port state. If the
5645 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5646 * state, it invokes the lpfc_els_rsp_reject() routine to send the reject
5647 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
5648 * for reading the HBA link statistics. It is for the callback function,
5649 * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command
5650 * to actually sending out RPS Accept (ACC) response.
5653 * 0 - Successfully processed rps iocb (currently always return 0)
5656 lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5657 struct lpfc_nodelist *ndlp)
5659 struct lpfc_hba *phba = vport->phba;
5663 struct lpfc_dmabuf *pcmd;
5667 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5668 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
5669 /* reject the unsolicited RPS request and done with it */
5672 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5673 lp = (uint32_t *) pcmd->virt;
5674 flag = (be32_to_cpu(*lp++) & 0xf);
5678 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
5679 ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
5680 sizeof(struct lpfc_name)) == 0))) {
5682 printk("Fix me....\n");
5684 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
5686 lpfc_read_lnk_stat(phba, mbox);
5687 mbox->context1 = (void *)((unsigned long)
5688 ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) |
5689 cmdiocb->iocb.ulpContext)); /* rx_id */
5690 mbox->context2 = lpfc_nlp_get(ndlp);
5691 mbox->vport = vport;
5692 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
5693 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
5694 != MBX_NOT_FINISHED)
5695 /* Mbox completion will send ELS Response */
5697 /* Decrement reference count used for the failed mbox
5701 mempool_free(mbox, phba->mbox_mem_pool);
5706 /* issue rejection response */
5707 stat.un.b.lsRjtRsvd0 = 0;
5708 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5709 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5710 stat.un.b.vendorUnique = 0;
5711 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5715 /* lpfc_issue_els_rrq - Process an unsolicited rps iocb
5716 * @vport: pointer to a host virtual N_Port data structure.
5717 * @ndlp: pointer to a node-list data structure.
5718 * @did: DID of the target.
5719 * @rrq: Pointer to the rrq struct.
5721 * Build a ELS RRQ command and send it to the target. If the issue_iocb is
5722 * Successful the the completion handler will clear the RRQ.
5725 * 0 - Successfully sent rrq els iocb.
5726 * 1 - Failed to send rrq els iocb.
5729 lpfc_issue_els_rrq(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
5730 uint32_t did, struct lpfc_node_rrq *rrq)
5732 struct lpfc_hba *phba = vport->phba;
5733 struct RRQ *els_rrq;
5735 struct lpfc_iocbq *elsiocb;
5741 if (ndlp != rrq->ndlp)
5743 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
5746 /* If ndlp is not NULL, we will bump the reference count on it */
5747 cmdsize = (sizeof(uint32_t) + sizeof(struct RRQ));
5748 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, did,
5753 icmd = &elsiocb->iocb;
5754 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5756 /* For RRQ request, remainder of payload is Exchange IDs */
5757 *((uint32_t *) (pcmd)) = ELS_CMD_RRQ;
5758 pcmd += sizeof(uint32_t);
5759 els_rrq = (struct RRQ *) pcmd;
5761 bf_set(rrq_oxid, els_rrq, phba->sli4_hba.xri_ids[rrq->xritag]);
5762 bf_set(rrq_rxid, els_rrq, rrq->rxid);
5763 bf_set(rrq_did, els_rrq, vport->fc_myDID);
5764 els_rrq->rrq = cpu_to_be32(els_rrq->rrq);
5765 els_rrq->rrq_exchg = cpu_to_be32(els_rrq->rrq_exchg);
5768 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
5769 "Issue RRQ: did:x%x",
5770 did, rrq->xritag, rrq->rxid);
5771 elsiocb->context_un.rrq = rrq;
5772 elsiocb->iocb_cmpl = lpfc_cmpl_els_rrq;
5773 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5775 if (ret == IOCB_ERROR) {
5776 lpfc_els_free_iocb(phba, elsiocb);
5783 * lpfc_send_rrq - Sends ELS RRQ if needed.
5784 * @phba: pointer to lpfc hba data structure.
5785 * @rrq: pointer to the active rrq.
5787 * This routine will call the lpfc_issue_els_rrq if the rrq is
5788 * still active for the xri. If this function returns a failure then
5789 * the caller needs to clean up the RRQ by calling lpfc_clr_active_rrq.
5791 * Returns 0 Success.
5795 lpfc_send_rrq(struct lpfc_hba *phba, struct lpfc_node_rrq *rrq)
5797 struct lpfc_nodelist *ndlp = lpfc_findnode_did(rrq->vport,
5799 if (lpfc_test_rrq_active(phba, ndlp, rrq->xritag))
5800 return lpfc_issue_els_rrq(rrq->vport, ndlp,
5807 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
5808 * @vport: pointer to a host virtual N_Port data structure.
5809 * @cmdsize: size of the ELS command.
5810 * @oldiocb: pointer to the original lpfc command iocb data structure.
5811 * @ndlp: pointer to a node-list data structure.
5813 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
5814 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
5816 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5817 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5818 * will be stored into the context1 field of the IOCB for the completion
5819 * callback function to the RPL Accept Response ELS command.
5822 * 0 - Successfully issued ACC RPL ELS command
5823 * 1 - Failed to issue ACC RPL ELS command
5826 lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
5827 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
5829 struct lpfc_hba *phba = vport->phba;
5830 IOCB_t *icmd, *oldcmd;
5832 struct lpfc_iocbq *elsiocb;
5835 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
5836 ndlp->nlp_DID, ELS_CMD_ACC);
5841 icmd = &elsiocb->iocb;
5842 oldcmd = &oldiocb->iocb;
5843 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
5844 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
5846 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5847 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5848 pcmd += sizeof(uint16_t);
5849 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
5850 pcmd += sizeof(uint16_t);
5852 /* Setup the RPL ACC payload */
5853 rpl_rsp.listLen = be32_to_cpu(1);
5855 rpl_rsp.port_num_blk.portNum = 0;
5856 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
5857 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
5858 sizeof(struct lpfc_name));
5859 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
5860 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
5861 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5862 "0120 Xmit ELS RPL ACC response tag x%x "
5863 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
5865 elsiocb->iotag, elsiocb->iocb.ulpContext,
5866 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5868 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5869 phba->fc_stat.elsXmitACC++;
5870 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
5872 lpfc_els_free_iocb(phba, elsiocb);
5879 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
5880 * @vport: pointer to a host virtual N_Port data structure.
5881 * @cmdiocb: pointer to lpfc command iocb data structure.
5882 * @ndlp: pointer to a node-list data structure.
5884 * This routine processes Read Port List (RPL) IOCB received as an ELS
5885 * unsolicited event. It first checks the remote port state. If the remote
5886 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
5887 * invokes the lpfc_els_rsp_reject() routine to send reject response.
5888 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
5889 * to accept the RPL.
5892 * 0 - Successfully processed rpl iocb (currently always return 0)
5895 lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5896 struct lpfc_nodelist *ndlp)
5898 struct lpfc_dmabuf *pcmd;
5905 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5906 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
5907 /* issue rejection response */
5908 stat.un.b.lsRjtRsvd0 = 0;
5909 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5910 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5911 stat.un.b.vendorUnique = 0;
5912 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
5914 /* rejected the unsolicited RPL request and done with it */
5918 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5919 lp = (uint32_t *) pcmd->virt;
5920 rpl = (RPL *) (lp + 1);
5921 maxsize = be32_to_cpu(rpl->maxsize);
5923 /* We support only one port */
5924 if ((rpl->index == 0) &&
5926 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
5927 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
5929 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
5931 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
5937 * lpfc_els_rcv_farp - Process an unsolicited farp request els command
5938 * @vport: pointer to a virtual N_Port data structure.
5939 * @cmdiocb: pointer to lpfc command iocb data structure.
5940 * @ndlp: pointer to a node-list data structure.
5942 * This routine processes Fibre Channel Address Resolution Protocol
5943 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
5944 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
5945 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
5946 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
5947 * remote PortName is compared against the FC PortName stored in the @vport
5948 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
5949 * compared against the FC NodeName stored in the @vport data structure.
5950 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
5951 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
5952 * invoked to send out FARP Response to the remote node. Before sending the
5953 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
5954 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
5955 * routine is invoked to log into the remote port first.
5958 * 0 - Either the FARP Match Mode not supported or successfully processed
5961 lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5962 struct lpfc_nodelist *ndlp)
5964 struct lpfc_dmabuf *pcmd;
5968 uint32_t cmd, cnt, did;
5970 icmd = &cmdiocb->iocb;
5971 did = icmd->un.elsreq64.remoteID;
5972 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5973 lp = (uint32_t *) pcmd->virt;
5977 /* FARP-REQ received from DID <did> */
5978 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5979 "0601 FARP-REQ received from DID x%x\n", did);
5980 /* We will only support match on WWPN or WWNN */
5981 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
5986 /* If this FARP command is searching for my portname */
5987 if (fp->Mflags & FARP_MATCH_PORT) {
5988 if (memcmp(&fp->RportName, &vport->fc_portname,
5989 sizeof(struct lpfc_name)) == 0)
5993 /* If this FARP command is searching for my nodename */
5994 if (fp->Mflags & FARP_MATCH_NODE) {
5995 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
5996 sizeof(struct lpfc_name)) == 0)
6001 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
6002 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
6003 /* Log back into the node before sending the FARP. */
6004 if (fp->Rflags & FARP_REQUEST_PLOGI) {
6005 ndlp->nlp_prev_state = ndlp->nlp_state;
6006 lpfc_nlp_set_state(vport, ndlp,
6007 NLP_STE_PLOGI_ISSUE);
6008 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
6011 /* Send a FARP response to that node */
6012 if (fp->Rflags & FARP_REQUEST_FARPR)
6013 lpfc_issue_els_farpr(vport, did, 0);
6020 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
6021 * @vport: pointer to a host virtual N_Port data structure.
6022 * @cmdiocb: pointer to lpfc command iocb data structure.
6023 * @ndlp: pointer to a node-list data structure.
6025 * This routine processes Fibre Channel Address Resolution Protocol
6026 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
6027 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
6028 * the FARP response request.
6031 * 0 - Successfully processed FARPR IOCB (currently always return 0)
6034 lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6035 struct lpfc_nodelist *ndlp)
6037 struct lpfc_dmabuf *pcmd;
6042 icmd = &cmdiocb->iocb;
6043 did = icmd->un.elsreq64.remoteID;
6044 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6045 lp = (uint32_t *) pcmd->virt;
6048 /* FARP-RSP received from DID <did> */
6049 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6050 "0600 FARP-RSP received from DID x%x\n", did);
6051 /* ACCEPT the Farp resp request */
6052 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
6058 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
6059 * @vport: pointer to a host virtual N_Port data structure.
6060 * @cmdiocb: pointer to lpfc command iocb data structure.
6061 * @fan_ndlp: pointer to a node-list data structure.
6063 * This routine processes a Fabric Address Notification (FAN) IOCB
6064 * command received as an ELS unsolicited event. The FAN ELS command will
6065 * only be processed on a physical port (i.e., the @vport represents the
6066 * physical port). The fabric NodeName and PortName from the FAN IOCB are
6067 * compared against those in the phba data structure. If any of those is
6068 * different, the lpfc_initial_flogi() routine is invoked to initialize
6069 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
6070 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
6071 * is invoked to register login to the fabric.
6074 * 0 - Successfully processed fan iocb (currently always return 0).
6077 lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6078 struct lpfc_nodelist *fan_ndlp)
6080 struct lpfc_hba *phba = vport->phba;
6084 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
6085 lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
6087 /* FAN received; Fan does not have a reply sequence */
6088 if ((vport == phba->pport) &&
6089 (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
6090 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
6091 sizeof(struct lpfc_name))) ||
6092 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
6093 sizeof(struct lpfc_name)))) {
6094 /* This port has switched fabrics. FLOGI is required */
6095 lpfc_issue_init_vfi(vport);
6097 /* FAN verified - skip FLOGI */
6098 vport->fc_myDID = vport->fc_prevDID;
6099 if (phba->sli_rev < LPFC_SLI_REV4)
6100 lpfc_issue_fabric_reglogin(vport);
6102 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6103 "3138 Need register VFI: (x%x/%x)\n",
6104 vport->fc_prevDID, vport->fc_myDID);
6105 lpfc_issue_reg_vfi(vport);
6113 * lpfc_els_timeout - Handler funciton to the els timer
6114 * @ptr: holder for the timer function associated data.
6116 * This routine is invoked by the ELS timer after timeout. It posts the ELS
6117 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
6118 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
6119 * up the worker thread. It is for the worker thread to invoke the routine
6120 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
6123 lpfc_els_timeout(unsigned long ptr)
6125 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
6126 struct lpfc_hba *phba = vport->phba;
6127 uint32_t tmo_posted;
6128 unsigned long iflag;
6130 spin_lock_irqsave(&vport->work_port_lock, iflag);
6131 tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
6133 vport->work_port_events |= WORKER_ELS_TMO;
6134 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
6137 lpfc_worker_wake_up(phba);
6143 * lpfc_els_timeout_handler - Process an els timeout event
6144 * @vport: pointer to a virtual N_Port data structure.
6146 * This routine is the actual handler function that processes an ELS timeout
6147 * event. It walks the ELS ring to get and abort all the IOCBs (except the
6148 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
6149 * invoking the lpfc_sli_issue_abort_iotag() routine.
6152 lpfc_els_timeout_handler(struct lpfc_vport *vport)
6154 struct lpfc_hba *phba = vport->phba;
6155 struct lpfc_sli_ring *pring;
6156 struct lpfc_iocbq *tmp_iocb, *piocb;
6158 struct lpfc_dmabuf *pcmd;
6159 uint32_t els_command = 0;
6161 uint32_t remote_ID = 0xffffffff;
6162 LIST_HEAD(txcmplq_completions);
6163 LIST_HEAD(abort_list);
6166 timeout = (uint32_t)(phba->fc_ratov << 1);
6168 pring = &phba->sli.ring[LPFC_ELS_RING];
6170 spin_lock_irq(&phba->hbalock);
6171 list_splice_init(&pring->txcmplq, &txcmplq_completions);
6172 spin_unlock_irq(&phba->hbalock);
6174 list_for_each_entry_safe(piocb, tmp_iocb, &txcmplq_completions, list) {
6177 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
6178 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
6179 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
6182 if (piocb->vport != vport)
6185 pcmd = (struct lpfc_dmabuf *) piocb->context2;
6187 els_command = *(uint32_t *) (pcmd->virt);
6189 if (els_command == ELS_CMD_FARP ||
6190 els_command == ELS_CMD_FARPR ||
6191 els_command == ELS_CMD_FDISC)
6194 if (piocb->drvrTimeout > 0) {
6195 if (piocb->drvrTimeout >= timeout)
6196 piocb->drvrTimeout -= timeout;
6198 piocb->drvrTimeout = 0;
6202 remote_ID = 0xffffffff;
6203 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
6204 remote_ID = cmd->un.elsreq64.remoteID;
6206 struct lpfc_nodelist *ndlp;
6207 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
6208 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
6209 remote_ID = ndlp->nlp_DID;
6211 list_add_tail(&piocb->dlist, &abort_list);
6213 spin_lock_irq(&phba->hbalock);
6214 list_splice(&txcmplq_completions, &pring->txcmplq);
6215 spin_unlock_irq(&phba->hbalock);
6217 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
6218 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6219 "0127 ELS timeout Data: x%x x%x x%x "
6220 "x%x\n", els_command,
6221 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
6222 spin_lock_irq(&phba->hbalock);
6223 list_del_init(&piocb->dlist);
6224 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
6225 spin_unlock_irq(&phba->hbalock);
6228 if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt)
6229 mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
6233 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
6234 * @vport: pointer to a host virtual N_Port data structure.
6236 * This routine is used to clean up all the outstanding ELS commands on a
6237 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
6238 * routine. After that, it walks the ELS transmit queue to remove all the
6239 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
6240 * the IOCBs with a non-NULL completion callback function, the callback
6241 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
6242 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
6243 * callback function, the IOCB will simply be released. Finally, it walks
6244 * the ELS transmit completion queue to issue an abort IOCB to any transmit
6245 * completion queue IOCB that is associated with the @vport and is not
6246 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
6247 * part of the discovery state machine) out to HBA by invoking the
6248 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
6249 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
6250 * the IOCBs are aborted when this function returns.
6253 lpfc_els_flush_cmd(struct lpfc_vport *vport)
6255 LIST_HEAD(completions);
6256 struct lpfc_hba *phba = vport->phba;
6257 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
6258 struct lpfc_iocbq *tmp_iocb, *piocb;
6261 lpfc_fabric_abort_vport(vport);
6263 spin_lock_irq(&phba->hbalock);
6264 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
6267 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
6271 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
6272 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
6273 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
6274 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
6275 cmd->ulpCommand == CMD_ABORT_XRI_CN)
6278 if (piocb->vport != vport)
6281 list_move_tail(&piocb->list, &completions);
6285 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
6286 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
6290 if (piocb->vport != vport)
6293 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
6295 spin_unlock_irq(&phba->hbalock);
6297 /* Cancell all the IOCBs from the completions list */
6298 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6305 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
6306 * @phba: pointer to lpfc hba data structure.
6308 * This routine is used to clean up all the outstanding ELS commands on a
6309 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
6310 * routine. After that, it walks the ELS transmit queue to remove all the
6311 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
6312 * the IOCBs with the completion callback function associated, the callback
6313 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
6314 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
6315 * callback function associated, the IOCB will simply be released. Finally,
6316 * it walks the ELS transmit completion queue to issue an abort IOCB to any
6317 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
6318 * management plane IOCBs that are not part of the discovery state machine)
6319 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
6322 lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
6324 LIST_HEAD(completions);
6325 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
6326 struct lpfc_iocbq *tmp_iocb, *piocb;
6329 lpfc_fabric_abort_hba(phba);
6330 spin_lock_irq(&phba->hbalock);
6331 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
6333 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
6335 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
6336 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
6337 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
6338 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
6339 cmd->ulpCommand == CMD_ABORT_XRI_CN)
6341 list_move_tail(&piocb->list, &completions);
6344 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
6345 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
6347 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
6349 spin_unlock_irq(&phba->hbalock);
6351 /* Cancel all the IOCBs from the completions list */
6352 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6359 * lpfc_send_els_failure_event - Posts an ELS command failure event
6360 * @phba: Pointer to hba context object.
6361 * @cmdiocbp: Pointer to command iocb which reported error.
6362 * @rspiocbp: Pointer to response iocb which reported error.
6364 * This function sends an event when there is an ELS command
6368 lpfc_send_els_failure_event(struct lpfc_hba *phba,
6369 struct lpfc_iocbq *cmdiocbp,
6370 struct lpfc_iocbq *rspiocbp)
6372 struct lpfc_vport *vport = cmdiocbp->vport;
6373 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6374 struct lpfc_lsrjt_event lsrjt_event;
6375 struct lpfc_fabric_event_header fabric_event;
6377 struct lpfc_nodelist *ndlp;
6380 ndlp = cmdiocbp->context1;
6381 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
6384 if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) {
6385 lsrjt_event.header.event_type = FC_REG_ELS_EVENT;
6386 lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV;
6387 memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname,
6388 sizeof(struct lpfc_name));
6389 memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename,
6390 sizeof(struct lpfc_name));
6391 pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
6392 cmdiocbp->context2)->virt);
6393 lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0;
6394 stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]);
6395 lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode;
6396 lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp;
6397 fc_host_post_vendor_event(shost,
6398 fc_get_event_number(),
6399 sizeof(lsrjt_event),
6400 (char *)&lsrjt_event,
6404 if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) ||
6405 (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) {
6406 fabric_event.event_type = FC_REG_FABRIC_EVENT;
6407 if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY)
6408 fabric_event.subcategory = LPFC_EVENT_PORT_BUSY;
6410 fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY;
6411 memcpy(fabric_event.wwpn, &ndlp->nlp_portname,
6412 sizeof(struct lpfc_name));
6413 memcpy(fabric_event.wwnn, &ndlp->nlp_nodename,
6414 sizeof(struct lpfc_name));
6415 fc_host_post_vendor_event(shost,
6416 fc_get_event_number(),
6417 sizeof(fabric_event),
6418 (char *)&fabric_event,
6426 * lpfc_send_els_event - Posts unsolicited els event
6427 * @vport: Pointer to vport object.
6428 * @ndlp: Pointer FC node object.
6429 * @cmd: ELS command code.
6431 * This function posts an event when there is an incoming
6432 * unsolicited ELS command.
6435 lpfc_send_els_event(struct lpfc_vport *vport,
6436 struct lpfc_nodelist *ndlp,
6439 struct lpfc_els_event_header *els_data = NULL;
6440 struct lpfc_logo_event *logo_data = NULL;
6441 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6443 if (*payload == ELS_CMD_LOGO) {
6444 logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL);
6446 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6447 "0148 Failed to allocate memory "
6448 "for LOGO event\n");
6451 els_data = &logo_data->header;
6453 els_data = kmalloc(sizeof(struct lpfc_els_event_header),
6456 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6457 "0149 Failed to allocate memory "
6462 els_data->event_type = FC_REG_ELS_EVENT;
6465 els_data->subcategory = LPFC_EVENT_PLOGI_RCV;
6468 els_data->subcategory = LPFC_EVENT_PRLO_RCV;
6471 els_data->subcategory = LPFC_EVENT_ADISC_RCV;
6474 els_data->subcategory = LPFC_EVENT_LOGO_RCV;
6475 /* Copy the WWPN in the LOGO payload */
6476 memcpy(logo_data->logo_wwpn, &payload[2],
6477 sizeof(struct lpfc_name));
6483 memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name));
6484 memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name));
6485 if (*payload == ELS_CMD_LOGO) {
6486 fc_host_post_vendor_event(shost,
6487 fc_get_event_number(),
6488 sizeof(struct lpfc_logo_event),
6493 fc_host_post_vendor_event(shost,
6494 fc_get_event_number(),
6495 sizeof(struct lpfc_els_event_header),
6506 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
6507 * @phba: pointer to lpfc hba data structure.
6508 * @pring: pointer to a SLI ring.
6509 * @vport: pointer to a host virtual N_Port data structure.
6510 * @elsiocb: pointer to lpfc els command iocb data structure.
6512 * This routine is used for processing the IOCB associated with a unsolicited
6513 * event. It first determines whether there is an existing ndlp that matches
6514 * the DID from the unsolicited IOCB. If not, it will create a new one with
6515 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
6516 * IOCB is then used to invoke the proper routine and to set up proper state
6517 * of the discovery state machine.
6520 lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
6521 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
6523 struct Scsi_Host *shost;
6524 struct lpfc_nodelist *ndlp;
6527 uint32_t cmd, did, newnode;
6528 uint8_t rjt_exp, rjt_err = 0;
6529 IOCB_t *icmd = &elsiocb->iocb;
6531 if (!vport || !(elsiocb->context2))
6535 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
6537 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
6538 lpfc_post_buffer(phba, pring, 1);
6540 did = icmd->un.rcvels.remoteID;
6541 if (icmd->ulpStatus) {
6542 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6543 "RCV Unsol ELS: status:x%x/x%x did:x%x",
6544 icmd->ulpStatus, icmd->un.ulpWord[4], did);
6548 /* Check to see if link went down during discovery */
6549 if (lpfc_els_chk_latt(vport))
6552 /* Ignore traffic received during vport shutdown. */
6553 if (vport->load_flag & FC_UNLOADING)
6556 /* If NPort discovery is delayed drop incoming ELS */
6557 if ((vport->fc_flag & FC_DISC_DELAYED) &&
6558 (cmd != ELS_CMD_PLOGI))
6561 ndlp = lpfc_findnode_did(vport, did);
6563 /* Cannot find existing Fabric ndlp, so allocate a new one */
6564 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
6568 lpfc_nlp_init(vport, ndlp, did);
6569 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
6571 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
6572 ndlp->nlp_type |= NLP_FABRIC;
6573 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
6574 ndlp = lpfc_enable_node(vport, ndlp,
6575 NLP_STE_UNUSED_NODE);
6578 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
6580 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
6581 ndlp->nlp_type |= NLP_FABRIC;
6582 } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
6583 /* This is similar to the new node path */
6584 ndlp = lpfc_nlp_get(ndlp);
6587 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
6591 phba->fc_stat.elsRcvFrame++;
6593 elsiocb->context1 = lpfc_nlp_get(ndlp);
6594 elsiocb->vport = vport;
6596 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
6597 cmd &= ELS_CMD_MASK;
6599 /* ELS command <elsCmd> received from NPORT <did> */
6600 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6601 "0112 ELS command x%x received from NPORT x%x "
6602 "Data: x%x\n", cmd, did, vport->port_state);
6605 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6606 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
6607 did, vport->port_state, ndlp->nlp_flag);
6609 phba->fc_stat.elsRcvPLOGI++;
6610 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
6612 lpfc_send_els_event(vport, ndlp, payload);
6614 /* If Nport discovery is delayed, reject PLOGIs */
6615 if (vport->fc_flag & FC_DISC_DELAYED) {
6616 rjt_err = LSRJT_UNABLE_TPC;
6617 rjt_exp = LSEXP_NOTHING_MORE;
6620 if (vport->port_state < LPFC_DISC_AUTH) {
6621 if (!(phba->pport->fc_flag & FC_PT2PT) ||
6622 (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
6623 rjt_err = LSRJT_UNABLE_TPC;
6624 rjt_exp = LSEXP_NOTHING_MORE;
6627 /* We get here, and drop thru, if we are PT2PT with
6628 * another NPort and the other side has initiated
6629 * the PLOGI before responding to our FLOGI.
6633 shost = lpfc_shost_from_vport(vport);
6634 spin_lock_irq(shost->host_lock);
6635 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
6636 spin_unlock_irq(shost->host_lock);
6638 lpfc_disc_state_machine(vport, ndlp, elsiocb,
6643 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6644 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
6645 did, vport->port_state, ndlp->nlp_flag);
6647 phba->fc_stat.elsRcvFLOGI++;
6648 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
6653 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6654 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
6655 did, vport->port_state, ndlp->nlp_flag);
6657 phba->fc_stat.elsRcvLOGO++;
6658 lpfc_send_els_event(vport, ndlp, payload);
6659 if (vport->port_state < LPFC_DISC_AUTH) {
6660 rjt_err = LSRJT_UNABLE_TPC;
6661 rjt_exp = LSEXP_NOTHING_MORE;
6664 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
6667 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6668 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
6669 did, vport->port_state, ndlp->nlp_flag);
6671 phba->fc_stat.elsRcvPRLO++;
6672 lpfc_send_els_event(vport, ndlp, payload);
6673 if (vport->port_state < LPFC_DISC_AUTH) {
6674 rjt_err = LSRJT_UNABLE_TPC;
6675 rjt_exp = LSEXP_NOTHING_MORE;
6678 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
6681 phba->fc_stat.elsRcvRSCN++;
6682 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
6687 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6688 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
6689 did, vport->port_state, ndlp->nlp_flag);
6691 lpfc_send_els_event(vport, ndlp, payload);
6692 phba->fc_stat.elsRcvADISC++;
6693 if (vport->port_state < LPFC_DISC_AUTH) {
6694 rjt_err = LSRJT_UNABLE_TPC;
6695 rjt_exp = LSEXP_NOTHING_MORE;
6698 lpfc_disc_state_machine(vport, ndlp, elsiocb,
6702 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6703 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
6704 did, vport->port_state, ndlp->nlp_flag);
6706 phba->fc_stat.elsRcvPDISC++;
6707 if (vport->port_state < LPFC_DISC_AUTH) {
6708 rjt_err = LSRJT_UNABLE_TPC;
6709 rjt_exp = LSEXP_NOTHING_MORE;
6712 lpfc_disc_state_machine(vport, ndlp, elsiocb,
6716 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6717 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
6718 did, vport->port_state, ndlp->nlp_flag);
6720 phba->fc_stat.elsRcvFARPR++;
6721 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
6724 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6725 "RCV FARP: did:x%x/ste:x%x flg:x%x",
6726 did, vport->port_state, ndlp->nlp_flag);
6728 phba->fc_stat.elsRcvFARP++;
6729 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
6732 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6733 "RCV FAN: did:x%x/ste:x%x flg:x%x",
6734 did, vport->port_state, ndlp->nlp_flag);
6736 phba->fc_stat.elsRcvFAN++;
6737 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
6740 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6741 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
6742 did, vport->port_state, ndlp->nlp_flag);
6744 phba->fc_stat.elsRcvPRLI++;
6745 if (vport->port_state < LPFC_DISC_AUTH) {
6746 rjt_err = LSRJT_UNABLE_TPC;
6747 rjt_exp = LSEXP_NOTHING_MORE;
6750 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
6753 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6754 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
6755 did, vport->port_state, ndlp->nlp_flag);
6757 phba->fc_stat.elsRcvLIRR++;
6758 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
6763 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6764 "RCV RLS: did:x%x/ste:x%x flg:x%x",
6765 did, vport->port_state, ndlp->nlp_flag);
6767 phba->fc_stat.elsRcvRLS++;
6768 lpfc_els_rcv_rls(vport, elsiocb, ndlp);
6773 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6774 "RCV RPS: did:x%x/ste:x%x flg:x%x",
6775 did, vport->port_state, ndlp->nlp_flag);
6777 phba->fc_stat.elsRcvRPS++;
6778 lpfc_els_rcv_rps(vport, elsiocb, ndlp);
6783 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6784 "RCV RPL: did:x%x/ste:x%x flg:x%x",
6785 did, vport->port_state, ndlp->nlp_flag);
6787 phba->fc_stat.elsRcvRPL++;
6788 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
6793 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6794 "RCV RNID: did:x%x/ste:x%x flg:x%x",
6795 did, vport->port_state, ndlp->nlp_flag);
6797 phba->fc_stat.elsRcvRNID++;
6798 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
6803 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6804 "RCV RTV: did:x%x/ste:x%x flg:x%x",
6805 did, vport->port_state, ndlp->nlp_flag);
6806 phba->fc_stat.elsRcvRTV++;
6807 lpfc_els_rcv_rtv(vport, elsiocb, ndlp);
6812 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6813 "RCV RRQ: did:x%x/ste:x%x flg:x%x",
6814 did, vport->port_state, ndlp->nlp_flag);
6816 phba->fc_stat.elsRcvRRQ++;
6817 lpfc_els_rcv_rrq(vport, elsiocb, ndlp);
6822 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6823 "RCV ECHO: did:x%x/ste:x%x flg:x%x",
6824 did, vport->port_state, ndlp->nlp_flag);
6826 phba->fc_stat.elsRcvECHO++;
6827 lpfc_els_rcv_echo(vport, elsiocb, ndlp);
6832 /* receive this due to exchange closed */
6833 rjt_err = LSRJT_UNABLE_TPC;
6834 rjt_exp = LSEXP_INVALID_OX_RX;
6837 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6838 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
6839 cmd, did, vport->port_state);
6841 /* Unsupported ELS command, reject */
6842 rjt_err = LSRJT_CMD_UNSUPPORTED;
6843 rjt_exp = LSEXP_NOTHING_MORE;
6845 /* Unknown ELS command <elsCmd> received from NPORT <did> */
6846 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6847 "0115 Unknown ELS command x%x "
6848 "received from NPORT x%x\n", cmd, did);
6854 /* check if need to LS_RJT received ELS cmd */
6856 memset(&stat, 0, sizeof(stat));
6857 stat.un.b.lsRjtRsnCode = rjt_err;
6858 stat.un.b.lsRjtRsnCodeExp = rjt_exp;
6859 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
6863 lpfc_nlp_put(elsiocb->context1);
6864 elsiocb->context1 = NULL;
6868 if (vport && !(vport->load_flag & FC_UNLOADING))
6869 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6870 "0111 Dropping received ELS cmd "
6871 "Data: x%x x%x x%x\n",
6872 icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout);
6873 phba->fc_stat.elsRcvDrop++;
6877 * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
6878 * @phba: pointer to lpfc hba data structure.
6879 * @pring: pointer to a SLI ring.
6880 * @elsiocb: pointer to lpfc els iocb data structure.
6882 * This routine is used to process an unsolicited event received from a SLI
6883 * (Service Level Interface) ring. The actual processing of the data buffer
6884 * associated with the unsolicited event is done by invoking the routine
6885 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
6886 * SLI ring on which the unsolicited event was received.
6889 lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
6890 struct lpfc_iocbq *elsiocb)
6892 struct lpfc_vport *vport = phba->pport;
6893 IOCB_t *icmd = &elsiocb->iocb;
6895 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
6896 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
6898 elsiocb->context1 = NULL;
6899 elsiocb->context2 = NULL;
6900 elsiocb->context3 = NULL;
6902 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
6903 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
6904 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
6905 (icmd->un.ulpWord[4] & IOERR_PARAM_MASK) ==
6906 IOERR_RCV_BUFFER_WAITING) {
6907 phba->fc_stat.NoRcvBuf++;
6908 /* Not enough posted buffers; Try posting more buffers */
6909 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
6910 lpfc_post_buffer(phba, pring, 0);
6914 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
6915 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
6916 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
6917 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
6918 vport = phba->pport;
6920 vport = lpfc_find_vport_by_vpid(phba,
6921 icmd->unsli3.rcvsli3.vpi);
6924 /* If there are no BDEs associated
6925 * with this IOCB, there is nothing to do.
6927 if (icmd->ulpBdeCount == 0)
6930 /* type of ELS cmd is first 32bit word
6933 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
6934 elsiocb->context2 = bdeBuf1;
6936 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
6937 icmd->un.cont64[0].addrLow);
6938 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
6942 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
6944 * The different unsolicited event handlers would tell us
6945 * if they are done with "mp" by setting context2 to NULL.
6947 if (elsiocb->context2) {
6948 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
6949 elsiocb->context2 = NULL;
6952 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
6953 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
6954 icmd->ulpBdeCount == 2) {
6955 elsiocb->context2 = bdeBuf2;
6956 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
6957 /* free mp if we are done with it */
6958 if (elsiocb->context2) {
6959 lpfc_in_buf_free(phba, elsiocb->context2);
6960 elsiocb->context2 = NULL;
6966 * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
6967 * @phba: pointer to lpfc hba data structure.
6968 * @vport: pointer to a virtual N_Port data structure.
6970 * This routine issues a Port Login (PLOGI) to the Name Server with
6971 * State Change Request (SCR) for a @vport. This routine will create an
6972 * ndlp for the Name Server associated to the @vport if such node does
6973 * not already exist. The PLOGI to Name Server is issued by invoking the
6974 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
6975 * (FDMI) is configured to the @vport, a FDMI node will be created and
6976 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
6979 lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
6981 struct lpfc_nodelist *ndlp, *ndlp_fdmi;
6982 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6985 * If lpfc_delay_discovery parameter is set and the clean address
6986 * bit is cleared and fc fabric parameters chenged, delay FC NPort
6989 spin_lock_irq(shost->host_lock);
6990 if (vport->fc_flag & FC_DISC_DELAYED) {
6991 spin_unlock_irq(shost->host_lock);
6992 mod_timer(&vport->delayed_disc_tmo,
6993 jiffies + HZ * phba->fc_ratov);
6996 spin_unlock_irq(shost->host_lock);
6998 ndlp = lpfc_findnode_did(vport, NameServer_DID);
7000 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
7002 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
7003 lpfc_disc_start(vport);
7006 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
7007 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7008 "0251 NameServer login: no memory\n");
7011 lpfc_nlp_init(vport, ndlp, NameServer_DID);
7012 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
7013 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
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 "0348 NameServer login: node freed\n");
7025 ndlp->nlp_type |= NLP_FABRIC;
7027 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
7029 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
7030 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
7031 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7032 "0252 Cannot issue NameServer login\n");
7036 if (vport->cfg_fdmi_on) {
7037 /* If this is the first time, allocate an ndlp and initialize
7038 * it. Otherwise, make sure the node is enabled and then do the
7041 ndlp_fdmi = lpfc_findnode_did(vport, FDMI_DID);
7043 ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
7046 lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID);
7047 ndlp_fdmi->nlp_type |= NLP_FABRIC;
7051 if (!NLP_CHK_NODE_ACT(ndlp_fdmi))
7052 ndlp_fdmi = lpfc_enable_node(vport,
7057 lpfc_nlp_set_state(vport, ndlp_fdmi,
7058 NLP_STE_PLOGI_ISSUE);
7059 lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID, 0);
7065 * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
7066 * @phba: pointer to lpfc hba data structure.
7067 * @pmb: pointer to the driver internal queue element for mailbox command.
7069 * This routine is the completion callback function to register new vport
7070 * mailbox command. If the new vport mailbox command completes successfully,
7071 * the fabric registration login shall be performed on physical port (the
7072 * new vport created is actually a physical port, with VPI 0) or the port
7073 * login to Name Server for State Change Request (SCR) will be performed
7074 * on virtual port (real virtual port, with VPI greater than 0).
7077 lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
7079 struct lpfc_vport *vport = pmb->vport;
7080 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7081 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
7082 MAILBOX_t *mb = &pmb->u.mb;
7085 spin_lock_irq(shost->host_lock);
7086 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
7087 spin_unlock_irq(shost->host_lock);
7089 if (mb->mbxStatus) {
7090 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
7091 "0915 Register VPI failed : Status: x%x"
7092 " upd bit: x%x \n", mb->mbxStatus,
7093 mb->un.varRegVpi.upd);
7094 if (phba->sli_rev == LPFC_SLI_REV4 &&
7095 mb->un.varRegVpi.upd)
7096 goto mbox_err_exit ;
7098 switch (mb->mbxStatus) {
7099 case 0x11: /* unsupported feature */
7100 case 0x9603: /* max_vpi exceeded */
7101 case 0x9602: /* Link event since CLEAR_LA */
7102 /* giving up on vport registration */
7103 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
7104 spin_lock_irq(shost->host_lock);
7105 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
7106 spin_unlock_irq(shost->host_lock);
7107 lpfc_can_disctmo(vport);
7109 /* If reg_vpi fail with invalid VPI status, re-init VPI */
7111 spin_lock_irq(shost->host_lock);
7112 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
7113 spin_unlock_irq(shost->host_lock);
7114 lpfc_init_vpi(phba, pmb, vport->vpi);
7116 pmb->mbox_cmpl = lpfc_init_vpi_cmpl;
7117 rc = lpfc_sli_issue_mbox(phba, pmb,
7119 if (rc == MBX_NOT_FINISHED) {
7120 lpfc_printf_vlog(vport,
7122 "2732 Failed to issue INIT_VPI"
7123 " mailbox command\n");
7130 /* Try to recover from this error */
7131 if (phba->sli_rev == LPFC_SLI_REV4)
7132 lpfc_sli4_unreg_all_rpis(vport);
7133 lpfc_mbx_unreg_vpi(vport);
7134 spin_lock_irq(shost->host_lock);
7135 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
7136 spin_unlock_irq(shost->host_lock);
7137 if (vport->port_type == LPFC_PHYSICAL_PORT
7138 && !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG))
7139 lpfc_issue_init_vfi(vport);
7141 lpfc_initial_fdisc(vport);
7145 spin_lock_irq(shost->host_lock);
7146 vport->vpi_state |= LPFC_VPI_REGISTERED;
7147 spin_unlock_irq(shost->host_lock);
7148 if (vport == phba->pport) {
7149 if (phba->sli_rev < LPFC_SLI_REV4)
7150 lpfc_issue_fabric_reglogin(vport);
7153 * If the physical port is instantiated using
7154 * FDISC, do not start vport discovery.
7156 if (vport->port_state != LPFC_FDISC)
7157 lpfc_start_fdiscs(phba);
7158 lpfc_do_scr_ns_plogi(phba, vport);
7161 lpfc_do_scr_ns_plogi(phba, vport);
7164 /* Now, we decrement the ndlp reference count held for this
7169 mempool_free(pmb, phba->mbox_mem_pool);
7174 * lpfc_register_new_vport - Register a new vport with a HBA
7175 * @phba: pointer to lpfc hba data structure.
7176 * @vport: pointer to a host virtual N_Port data structure.
7177 * @ndlp: pointer to a node-list data structure.
7179 * This routine registers the @vport as a new virtual port with a HBA.
7180 * It is done through a registering vpi mailbox command.
7183 lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
7184 struct lpfc_nodelist *ndlp)
7186 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7189 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
7191 lpfc_reg_vpi(vport, mbox);
7192 mbox->vport = vport;
7193 mbox->context2 = lpfc_nlp_get(ndlp);
7194 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
7195 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
7196 == MBX_NOT_FINISHED) {
7197 /* mailbox command not success, decrement ndlp
7198 * reference count for this command
7201 mempool_free(mbox, phba->mbox_mem_pool);
7203 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
7204 "0253 Register VPI: Can't send mbox\n");
7208 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
7209 "0254 Register VPI: no memory\n");
7215 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
7216 spin_lock_irq(shost->host_lock);
7217 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
7218 spin_unlock_irq(shost->host_lock);
7223 * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer
7224 * @phba: pointer to lpfc hba data structure.
7226 * This routine cancels the retry delay timers to all the vports.
7229 lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba)
7231 struct lpfc_vport **vports;
7232 struct lpfc_nodelist *ndlp;
7233 uint32_t link_state;
7236 /* Treat this failure as linkdown for all vports */
7237 link_state = phba->link_state;
7238 lpfc_linkdown(phba);
7239 phba->link_state = link_state;
7241 vports = lpfc_create_vport_work_array(phba);
7244 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
7245 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
7247 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
7248 lpfc_els_flush_cmd(vports[i]);
7250 lpfc_destroy_vport_work_array(phba, vports);
7255 * lpfc_retry_pport_discovery - Start timer to retry FLOGI.
7256 * @phba: pointer to lpfc hba data structure.
7258 * This routine abort all pending discovery commands and
7259 * start a timer to retry FLOGI for the physical port
7263 lpfc_retry_pport_discovery(struct lpfc_hba *phba)
7265 struct lpfc_nodelist *ndlp;
7266 struct Scsi_Host *shost;
7268 /* Cancel the all vports retry delay retry timers */
7269 lpfc_cancel_all_vport_retry_delay_timer(phba);
7271 /* If fabric require FLOGI, then re-instantiate physical login */
7272 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
7276 shost = lpfc_shost_from_vport(phba->pport);
7277 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
7278 spin_lock_irq(shost->host_lock);
7279 ndlp->nlp_flag |= NLP_DELAY_TMO;
7280 spin_unlock_irq(shost->host_lock);
7281 ndlp->nlp_last_elscmd = ELS_CMD_FLOGI;
7282 phba->pport->port_state = LPFC_FLOGI;
7287 * lpfc_fabric_login_reqd - Check if FLOGI required.
7288 * @phba: pointer to lpfc hba data structure.
7289 * @cmdiocb: pointer to FDISC command iocb.
7290 * @rspiocb: pointer to FDISC response iocb.
7292 * This routine checks if a FLOGI is reguired for FDISC
7296 lpfc_fabric_login_reqd(struct lpfc_hba *phba,
7297 struct lpfc_iocbq *cmdiocb,
7298 struct lpfc_iocbq *rspiocb)
7301 if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) ||
7302 (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED))
7309 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
7310 * @phba: pointer to lpfc hba data structure.
7311 * @cmdiocb: pointer to lpfc command iocb data structure.
7312 * @rspiocb: pointer to lpfc response iocb data structure.
7314 * This routine is the completion callback function to a Fabric Discover
7315 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
7316 * single threaded, each FDISC completion callback function will reset
7317 * the discovery timer for all vports such that the timers will not get
7318 * unnecessary timeout. The function checks the FDISC IOCB status. If error
7319 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
7320 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
7321 * assigned to the vport has been changed with the completion of the FDISC
7322 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
7323 * are unregistered from the HBA, and then the lpfc_register_new_vport()
7324 * routine is invoked to register new vport with the HBA. Otherwise, the
7325 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
7326 * Server for State Change Request (SCR).
7329 lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
7330 struct lpfc_iocbq *rspiocb)
7332 struct lpfc_vport *vport = cmdiocb->vport;
7333 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7334 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
7335 struct lpfc_nodelist *np;
7336 struct lpfc_nodelist *next_np;
7337 IOCB_t *irsp = &rspiocb->iocb;
7338 struct lpfc_iocbq *piocb;
7339 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
7340 struct serv_parm *sp;
7341 uint8_t fabric_param_changed;
7343 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7344 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
7345 irsp->ulpStatus, irsp->un.ulpWord[4],
7347 /* Since all FDISCs are being single threaded, we
7348 * must reset the discovery timer for ALL vports
7349 * waiting to send FDISC when one completes.
7351 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
7352 lpfc_set_disctmo(piocb->vport);
7355 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7356 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
7357 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
7359 if (irsp->ulpStatus) {
7361 if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) {
7362 lpfc_retry_pport_discovery(phba);
7366 /* Check for retry */
7367 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
7370 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7371 "0126 FDISC failed. (x%x/x%x)\n",
7372 irsp->ulpStatus, irsp->un.ulpWord[4]);
7375 spin_lock_irq(shost->host_lock);
7376 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
7377 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
7378 vport->fc_flag |= FC_FABRIC;
7379 if (vport->phba->fc_topology == LPFC_TOPOLOGY_LOOP)
7380 vport->fc_flag |= FC_PUBLIC_LOOP;
7381 spin_unlock_irq(shost->host_lock);
7383 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
7384 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
7385 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
7386 sp = prsp->virt + sizeof(uint32_t);
7387 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
7388 memcpy(&vport->fabric_portname, &sp->portName,
7389 sizeof(struct lpfc_name));
7390 memcpy(&vport->fabric_nodename, &sp->nodeName,
7391 sizeof(struct lpfc_name));
7392 if (fabric_param_changed &&
7393 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
7394 /* If our NportID changed, we need to ensure all
7395 * remaining NPORTs get unreg_login'ed so we can
7398 list_for_each_entry_safe(np, next_np,
7399 &vport->fc_nodes, nlp_listp) {
7400 if (!NLP_CHK_NODE_ACT(ndlp) ||
7401 (np->nlp_state != NLP_STE_NPR_NODE) ||
7402 !(np->nlp_flag & NLP_NPR_ADISC))
7404 spin_lock_irq(shost->host_lock);
7405 np->nlp_flag &= ~NLP_NPR_ADISC;
7406 spin_unlock_irq(shost->host_lock);
7407 lpfc_unreg_rpi(vport, np);
7409 lpfc_cleanup_pending_mbox(vport);
7411 if (phba->sli_rev == LPFC_SLI_REV4)
7412 lpfc_sli4_unreg_all_rpis(vport);
7414 lpfc_mbx_unreg_vpi(vport);
7415 spin_lock_irq(shost->host_lock);
7416 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
7417 if (phba->sli_rev == LPFC_SLI_REV4)
7418 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
7420 vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG;
7421 spin_unlock_irq(shost->host_lock);
7422 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
7423 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
7425 * Driver needs to re-reg VPI in order for f/w
7426 * to update the MAC address.
7428 lpfc_register_new_vport(phba, vport, ndlp);
7432 if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)
7433 lpfc_issue_init_vpi(vport);
7434 else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
7435 lpfc_register_new_vport(phba, vport, ndlp);
7437 lpfc_do_scr_ns_plogi(phba, vport);
7440 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
7441 /* Cancel discovery timer */
7442 lpfc_can_disctmo(vport);
7445 lpfc_els_free_iocb(phba, cmdiocb);
7449 * lpfc_issue_els_fdisc - Issue a fdisc iocb command
7450 * @vport: pointer to a virtual N_Port data structure.
7451 * @ndlp: pointer to a node-list data structure.
7452 * @retry: number of retries to the command IOCB.
7454 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
7455 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
7456 * routine to issue the IOCB, which makes sure only one outstanding fabric
7457 * IOCB will be sent off HBA at any given time.
7459 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7460 * will be incremented by 1 for holding the ndlp and the reference to ndlp
7461 * will be stored into the context1 field of the IOCB for the completion
7462 * callback function to the FDISC ELS command.
7465 * 0 - Successfully issued fdisc iocb command
7466 * 1 - Failed to issue fdisc iocb command
7469 lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
7472 struct lpfc_hba *phba = vport->phba;
7474 struct lpfc_iocbq *elsiocb;
7475 struct serv_parm *sp;
7478 int did = ndlp->nlp_DID;
7481 vport->port_state = LPFC_FDISC;
7482 vport->fc_myDID = 0;
7483 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
7484 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
7487 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
7488 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7489 "0255 Issue FDISC: no IOCB\n");
7493 icmd = &elsiocb->iocb;
7494 icmd->un.elsreq64.myID = 0;
7495 icmd->un.elsreq64.fl = 1;
7498 * SLI3 ports require a different context type value than SLI4.
7499 * Catch SLI3 ports here and override the prep.
7501 if (phba->sli_rev == LPFC_SLI_REV3) {
7506 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7507 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
7508 pcmd += sizeof(uint32_t); /* CSP Word 1 */
7509 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
7510 sp = (struct serv_parm *) pcmd;
7511 /* Setup CSPs accordingly for Fabric */
7512 sp->cmn.e_d_tov = 0;
7513 sp->cmn.w2.r_a_tov = 0;
7514 sp->cmn.virtual_fabric_support = 0;
7515 sp->cls1.classValid = 0;
7516 sp->cls2.seqDelivery = 1;
7517 sp->cls3.seqDelivery = 1;
7519 pcmd += sizeof(uint32_t); /* CSP Word 2 */
7520 pcmd += sizeof(uint32_t); /* CSP Word 3 */
7521 pcmd += sizeof(uint32_t); /* CSP Word 4 */
7522 pcmd += sizeof(uint32_t); /* Port Name */
7523 memcpy(pcmd, &vport->fc_portname, 8);
7524 pcmd += sizeof(uint32_t); /* Node Name */
7525 pcmd += sizeof(uint32_t); /* Node Name */
7526 memcpy(pcmd, &vport->fc_nodename, 8);
7528 lpfc_set_disctmo(vport);
7530 phba->fc_stat.elsXmitFDISC++;
7531 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
7533 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7534 "Issue FDISC: did:x%x",
7537 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
7538 if (rc == IOCB_ERROR) {
7539 lpfc_els_free_iocb(phba, elsiocb);
7540 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
7541 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7542 "0256 Issue FDISC: Cannot send IOCB\n");
7545 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
7550 * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
7551 * @phba: pointer to lpfc hba data structure.
7552 * @cmdiocb: pointer to lpfc command iocb data structure.
7553 * @rspiocb: pointer to lpfc response iocb data structure.
7555 * This routine is the completion callback function to the issuing of a LOGO
7556 * ELS command off a vport. It frees the command IOCB and then decrement the
7557 * reference count held on ndlp for this completion function, indicating that
7558 * the reference to the ndlp is no long needed. Note that the
7559 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
7560 * callback function and an additional explicit ndlp reference decrementation
7561 * will trigger the actual release of the ndlp.
7564 lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
7565 struct lpfc_iocbq *rspiocb)
7567 struct lpfc_vport *vport = cmdiocb->vport;
7569 struct lpfc_nodelist *ndlp;
7570 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7572 ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
7573 irsp = &rspiocb->iocb;
7574 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7575 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
7576 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
7578 lpfc_els_free_iocb(phba, cmdiocb);
7579 vport->unreg_vpi_cmpl = VPORT_ERROR;
7581 /* Trigger the release of the ndlp after logo */
7584 /* NPIV LOGO completes to NPort <nlp_DID> */
7585 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7586 "2928 NPIV LOGO completes to NPort x%x "
7587 "Data: x%x x%x x%x x%x\n",
7588 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
7589 irsp->ulpTimeout, vport->num_disc_nodes);
7591 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
7592 spin_lock_irq(shost->host_lock);
7593 vport->fc_flag &= ~FC_FABRIC;
7594 spin_unlock_irq(shost->host_lock);
7599 * lpfc_issue_els_npiv_logo - Issue a logo off a vport
7600 * @vport: pointer to a virtual N_Port data structure.
7601 * @ndlp: pointer to a node-list data structure.
7603 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
7605 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7606 * will be incremented by 1 for holding the ndlp and the reference to ndlp
7607 * will be stored into the context1 field of the IOCB for the completion
7608 * callback function to the LOGO ELS command.
7611 * 0 - Successfully issued logo off the @vport
7612 * 1 - Failed to issue logo off the @vport
7615 lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
7617 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7618 struct lpfc_hba *phba = vport->phba;
7620 struct lpfc_iocbq *elsiocb;
7624 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
7625 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
7630 icmd = &elsiocb->iocb;
7631 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7632 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
7633 pcmd += sizeof(uint32_t);
7635 /* Fill in LOGO payload */
7636 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
7637 pcmd += sizeof(uint32_t);
7638 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
7640 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7641 "Issue LOGO npiv did:x%x flg:x%x",
7642 ndlp->nlp_DID, ndlp->nlp_flag, 0);
7644 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
7645 spin_lock_irq(shost->host_lock);
7646 ndlp->nlp_flag |= NLP_LOGO_SND;
7647 spin_unlock_irq(shost->host_lock);
7648 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
7650 spin_lock_irq(shost->host_lock);
7651 ndlp->nlp_flag &= ~NLP_LOGO_SND;
7652 spin_unlock_irq(shost->host_lock);
7653 lpfc_els_free_iocb(phba, elsiocb);
7660 * lpfc_fabric_block_timeout - Handler function to the fabric block timer
7661 * @ptr: holder for the timer function associated data.
7663 * This routine is invoked by the fabric iocb block timer after
7664 * timeout. It posts the fabric iocb block timeout event by setting the
7665 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
7666 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
7667 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
7668 * posted event WORKER_FABRIC_BLOCK_TMO.
7671 lpfc_fabric_block_timeout(unsigned long ptr)
7673 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
7674 unsigned long iflags;
7675 uint32_t tmo_posted;
7677 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
7678 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
7680 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
7681 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
7684 lpfc_worker_wake_up(phba);
7689 * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
7690 * @phba: pointer to lpfc hba data structure.
7692 * This routine issues one fabric iocb from the driver internal list to
7693 * the HBA. It first checks whether it's ready to issue one fabric iocb to
7694 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
7695 * remove one pending fabric iocb from the driver internal list and invokes
7696 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
7699 lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
7701 struct lpfc_iocbq *iocb;
7702 unsigned long iflags;
7708 spin_lock_irqsave(&phba->hbalock, iflags);
7709 /* Post any pending iocb to the SLI layer */
7710 if (atomic_read(&phba->fabric_iocb_count) == 0) {
7711 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
7714 /* Increment fabric iocb count to hold the position */
7715 atomic_inc(&phba->fabric_iocb_count);
7717 spin_unlock_irqrestore(&phba->hbalock, iflags);
7719 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
7720 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
7721 iocb->iocb_flag |= LPFC_IO_FABRIC;
7723 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
7724 "Fabric sched1: ste:x%x",
7725 iocb->vport->port_state, 0, 0);
7727 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
7729 if (ret == IOCB_ERROR) {
7730 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
7731 iocb->fabric_iocb_cmpl = NULL;
7732 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
7734 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
7735 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
7736 iocb->iocb_cmpl(phba, iocb, iocb);
7738 atomic_dec(&phba->fabric_iocb_count);
7747 * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
7748 * @phba: pointer to lpfc hba data structure.
7750 * This routine unblocks the issuing fabric iocb command. The function
7751 * will clear the fabric iocb block bit and then invoke the routine
7752 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
7753 * from the driver internal fabric iocb list.
7756 lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
7758 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
7760 lpfc_resume_fabric_iocbs(phba);
7765 * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
7766 * @phba: pointer to lpfc hba data structure.
7768 * This routine blocks the issuing fabric iocb for a specified amount of
7769 * time (currently 100 ms). This is done by set the fabric iocb block bit
7770 * and set up a timeout timer for 100ms. When the block bit is set, no more
7771 * fabric iocb will be issued out of the HBA.
7774 lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
7778 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
7779 /* Start a timer to unblock fabric iocbs after 100ms */
7781 mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 );
7787 * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
7788 * @phba: pointer to lpfc hba data structure.
7789 * @cmdiocb: pointer to lpfc command iocb data structure.
7790 * @rspiocb: pointer to lpfc response iocb data structure.
7792 * This routine is the callback function that is put to the fabric iocb's
7793 * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
7794 * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
7795 * function first restores and invokes the original iocb's callback function
7796 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
7797 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
7800 lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
7801 struct lpfc_iocbq *rspiocb)
7805 if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC)
7808 switch (rspiocb->iocb.ulpStatus) {
7809 case IOSTAT_NPORT_RJT:
7810 case IOSTAT_FABRIC_RJT:
7811 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
7812 lpfc_block_fabric_iocbs(phba);
7816 case IOSTAT_NPORT_BSY:
7817 case IOSTAT_FABRIC_BSY:
7818 lpfc_block_fabric_iocbs(phba);
7822 stat.un.lsRjtError =
7823 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
7824 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
7825 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
7826 lpfc_block_fabric_iocbs(phba);
7830 if (atomic_read(&phba->fabric_iocb_count) == 0)
7833 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
7834 cmdiocb->fabric_iocb_cmpl = NULL;
7835 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
7836 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
7838 atomic_dec(&phba->fabric_iocb_count);
7839 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
7840 /* Post any pending iocbs to HBA */
7841 lpfc_resume_fabric_iocbs(phba);
7846 * lpfc_issue_fabric_iocb - Issue a fabric iocb command
7847 * @phba: pointer to lpfc hba data structure.
7848 * @iocb: pointer to lpfc command iocb data structure.
7850 * This routine is used as the top-level API for issuing a fabric iocb command
7851 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
7852 * function makes sure that only one fabric bound iocb will be outstanding at
7853 * any given time. As such, this function will first check to see whether there
7854 * is already an outstanding fabric iocb on the wire. If so, it will put the
7855 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
7856 * issued later. Otherwise, it will issue the iocb on the wire and update the
7857 * fabric iocb count it indicate that there is one fabric iocb on the wire.
7859 * Note, this implementation has a potential sending out fabric IOCBs out of
7860 * order. The problem is caused by the construction of the "ready" boolen does
7861 * not include the condition that the internal fabric IOCB list is empty. As
7862 * such, it is possible a fabric IOCB issued by this routine might be "jump"
7863 * ahead of the fabric IOCBs in the internal list.
7866 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
7867 * IOCB_ERROR - failed to issue fabric iocb
7870 lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
7872 unsigned long iflags;
7876 if (atomic_read(&phba->fabric_iocb_count) > 1)
7879 spin_lock_irqsave(&phba->hbalock, iflags);
7880 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
7881 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
7884 /* Increment fabric iocb count to hold the position */
7885 atomic_inc(&phba->fabric_iocb_count);
7886 spin_unlock_irqrestore(&phba->hbalock, iflags);
7888 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
7889 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
7890 iocb->iocb_flag |= LPFC_IO_FABRIC;
7892 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
7893 "Fabric sched2: ste:x%x",
7894 iocb->vport->port_state, 0, 0);
7896 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
7898 if (ret == IOCB_ERROR) {
7899 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
7900 iocb->fabric_iocb_cmpl = NULL;
7901 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
7902 atomic_dec(&phba->fabric_iocb_count);
7905 spin_lock_irqsave(&phba->hbalock, iflags);
7906 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
7907 spin_unlock_irqrestore(&phba->hbalock, iflags);
7914 * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
7915 * @vport: pointer to a virtual N_Port data structure.
7917 * This routine aborts all the IOCBs associated with a @vport from the
7918 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
7919 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
7920 * list, removes each IOCB associated with the @vport off the list, set the
7921 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
7922 * associated with the IOCB.
7924 static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
7926 LIST_HEAD(completions);
7927 struct lpfc_hba *phba = vport->phba;
7928 struct lpfc_iocbq *tmp_iocb, *piocb;
7930 spin_lock_irq(&phba->hbalock);
7931 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
7934 if (piocb->vport != vport)
7937 list_move_tail(&piocb->list, &completions);
7939 spin_unlock_irq(&phba->hbalock);
7941 /* Cancel all the IOCBs from the completions list */
7942 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
7947 * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
7948 * @ndlp: pointer to a node-list data structure.
7950 * This routine aborts all the IOCBs associated with an @ndlp from the
7951 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
7952 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
7953 * list, removes each IOCB associated with the @ndlp off the list, set the
7954 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
7955 * associated with the IOCB.
7957 void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
7959 LIST_HEAD(completions);
7960 struct lpfc_hba *phba = ndlp->phba;
7961 struct lpfc_iocbq *tmp_iocb, *piocb;
7962 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
7964 spin_lock_irq(&phba->hbalock);
7965 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
7967 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
7969 list_move_tail(&piocb->list, &completions);
7972 spin_unlock_irq(&phba->hbalock);
7974 /* Cancel all the IOCBs from the completions list */
7975 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
7980 * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
7981 * @phba: pointer to lpfc hba data structure.
7983 * This routine aborts all the IOCBs currently on the driver internal
7984 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
7985 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
7986 * list, removes IOCBs off the list, set the status feild to
7987 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
7990 void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
7992 LIST_HEAD(completions);
7994 spin_lock_irq(&phba->hbalock);
7995 list_splice_init(&phba->fabric_iocb_list, &completions);
7996 spin_unlock_irq(&phba->hbalock);
7998 /* Cancel all the IOCBs from the completions list */
7999 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
8004 * lpfc_sli4_vport_delete_els_xri_aborted -Remove all ndlp references for vport
8005 * @vport: pointer to lpfc vport data structure.
8007 * This routine is invoked by the vport cleanup for deletions and the cleanup
8008 * for an ndlp on removal.
8011 lpfc_sli4_vport_delete_els_xri_aborted(struct lpfc_vport *vport)
8013 struct lpfc_hba *phba = vport->phba;
8014 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
8015 unsigned long iflag = 0;
8017 spin_lock_irqsave(&phba->hbalock, iflag);
8018 spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
8019 list_for_each_entry_safe(sglq_entry, sglq_next,
8020 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
8021 if (sglq_entry->ndlp && sglq_entry->ndlp->vport == vport)
8022 sglq_entry->ndlp = NULL;
8024 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
8025 spin_unlock_irqrestore(&phba->hbalock, iflag);
8030 * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
8031 * @phba: pointer to lpfc hba data structure.
8032 * @axri: pointer to the els xri abort wcqe structure.
8034 * This routine is invoked by the worker thread to process a SLI4 slow-path
8038 lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba,
8039 struct sli4_wcqe_xri_aborted *axri)
8041 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
8042 uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri);
8045 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
8046 unsigned long iflag = 0;
8047 struct lpfc_nodelist *ndlp;
8048 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
8050 spin_lock_irqsave(&phba->hbalock, iflag);
8051 spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
8052 list_for_each_entry_safe(sglq_entry, sglq_next,
8053 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
8054 if (sglq_entry->sli4_xritag == xri) {
8055 list_del(&sglq_entry->list);
8056 ndlp = sglq_entry->ndlp;
8057 sglq_entry->ndlp = NULL;
8058 list_add_tail(&sglq_entry->list,
8059 &phba->sli4_hba.lpfc_sgl_list);
8060 sglq_entry->state = SGL_FREED;
8061 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
8062 spin_unlock_irqrestore(&phba->hbalock, iflag);
8063 lpfc_set_rrq_active(phba, ndlp,
8064 sglq_entry->sli4_lxritag,
8067 /* Check if TXQ queue needs to be serviced */
8069 lpfc_worker_wake_up(phba);
8073 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
8074 lxri = lpfc_sli4_xri_inrange(phba, xri);
8075 if (lxri == NO_XRI) {
8076 spin_unlock_irqrestore(&phba->hbalock, iflag);
8079 sglq_entry = __lpfc_get_active_sglq(phba, lxri);
8080 if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) {
8081 spin_unlock_irqrestore(&phba->hbalock, iflag);
8084 sglq_entry->state = SGL_XRI_ABORTED;
8085 spin_unlock_irqrestore(&phba->hbalock, iflag);
8089 /* lpfc_sli_abts_recover_port - Recover a port that failed a BLS_ABORT req.
8090 * @vport: pointer to virtual port object.
8091 * @ndlp: nodelist pointer for the impacted node.
8093 * The driver calls this routine in response to an SLI4 XRI ABORT CQE
8094 * or an SLI3 ASYNC_STATUS_CN event from the port. For either event,
8095 * the driver is required to send a LOGO to the remote node before it
8096 * attempts to recover its login to the remote node.
8099 lpfc_sli_abts_recover_port(struct lpfc_vport *vport,
8100 struct lpfc_nodelist *ndlp)
8102 struct Scsi_Host *shost;
8103 struct lpfc_hba *phba;
8104 unsigned long flags = 0;
8106 shost = lpfc_shost_from_vport(vport);
8108 if (ndlp->nlp_state != NLP_STE_MAPPED_NODE) {
8109 lpfc_printf_log(phba, KERN_INFO,
8110 LOG_SLI, "3093 No rport recovery needed. "
8111 "rport in state 0x%x\n", ndlp->nlp_state);
8114 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
8115 "3094 Start rport recovery on shost id 0x%x "
8116 "fc_id 0x%06x vpi 0x%x rpi 0x%x state 0x%x "
8118 shost->host_no, ndlp->nlp_DID,
8119 vport->vpi, ndlp->nlp_rpi, ndlp->nlp_state,
8122 * The rport is not responding. Remove the FCP-2 flag to prevent
8123 * an ADISC in the follow-up recovery code.
8125 spin_lock_irqsave(shost->host_lock, flags);
8126 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
8127 spin_unlock_irqrestore(shost->host_lock, flags);
8128 lpfc_issue_els_logo(vport, ndlp, 0);
8129 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);