1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2009 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 ha_copy = readl(phba->HAregaddr);
94 if (!(ha_copy & HA_LATT))
97 /* Pending Link Event during Discovery */
98 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
99 "0237 Pending Link Event during "
100 "Discovery: State x%x\n",
101 phba->pport->port_state);
103 /* CLEAR_LA should re-enable link attention events and
104 * we should then imediately take a LATT event. The
105 * LATT processing should call lpfc_linkdown() which
106 * will cleanup any left over in-progress discovery
109 spin_lock_irq(shost->host_lock);
110 vport->fc_flag |= FC_ABORT_DISCOVERY;
111 spin_unlock_irq(shost->host_lock);
113 if (phba->link_state != LPFC_CLEAR_LA)
114 lpfc_issue_clear_la(phba, vport);
120 * lpfc_prep_els_iocb - Allocate and prepare a lpfc iocb data structure
121 * @vport: pointer to a host virtual N_Port data structure.
122 * @expectRsp: flag indicating whether response is expected.
123 * @cmdSize: size of the ELS command.
124 * @retry: number of retries to the command IOCB when it fails.
125 * @ndlp: pointer to a node-list data structure.
126 * @did: destination identifier.
127 * @elscmd: the ELS command code.
129 * This routine is used for allocating a lpfc-IOCB data structure from
130 * the driver lpfc-IOCB free-list and prepare the IOCB with the parameters
131 * passed into the routine for discovery state machine to issue an Extended
132 * Link Service (ELS) commands. It is a generic lpfc-IOCB allocation
133 * and preparation routine that is used by all the discovery state machine
134 * routines and the ELS command-specific fields will be later set up by
135 * the individual discovery machine routines after calling this routine
136 * allocating and preparing a generic IOCB data structure. It fills in the
137 * Buffer Descriptor Entries (BDEs), allocates buffers for both command
138 * payload and response payload (if expected). The reference count on the
139 * ndlp is incremented by 1 and the reference to the ndlp is put into
140 * context1 of the IOCB data structure for this IOCB to hold the ndlp
141 * reference for the command's callback function to access later.
144 * Pointer to the newly allocated/prepared els iocb data structure
145 * NULL - when els iocb data structure allocation/preparation failed
148 lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp,
149 uint16_t cmdSize, uint8_t retry,
150 struct lpfc_nodelist *ndlp, uint32_t did,
153 struct lpfc_hba *phba = vport->phba;
154 struct lpfc_iocbq *elsiocb;
155 struct lpfc_dmabuf *pcmd, *prsp, *pbuflist;
156 struct ulp_bde64 *bpl;
160 if (!lpfc_is_link_up(phba))
163 /* Allocate buffer for command iocb */
164 elsiocb = lpfc_sli_get_iocbq(phba);
170 * If this command is for fabric controller and HBA running
171 * in FIP mode send FLOGI, FDISC and LOGO as FIP frames.
173 if ((did == Fabric_DID) &&
174 (phba->hba_flag & HBA_FIP_SUPPORT) &&
175 ((elscmd == ELS_CMD_FLOGI) ||
176 (elscmd == ELS_CMD_FDISC) ||
177 (elscmd == ELS_CMD_LOGO)))
180 elsiocb->iocb_flag |= ((ELS_ID_FLOGI << LPFC_FIP_ELS_ID_SHIFT)
181 & LPFC_FIP_ELS_ID_MASK);
184 elsiocb->iocb_flag |= ((ELS_ID_FDISC << LPFC_FIP_ELS_ID_SHIFT)
185 & LPFC_FIP_ELS_ID_MASK);
188 elsiocb->iocb_flag |= ((ELS_ID_LOGO << LPFC_FIP_ELS_ID_SHIFT)
189 & LPFC_FIP_ELS_ID_MASK);
193 elsiocb->iocb_flag &= ~LPFC_FIP_ELS_ID_MASK;
195 icmd = &elsiocb->iocb;
197 /* fill in BDEs for command */
198 /* Allocate buffer for command payload */
199 pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
201 pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys);
202 if (!pcmd || !pcmd->virt)
203 goto els_iocb_free_pcmb_exit;
205 INIT_LIST_HEAD(&pcmd->list);
207 /* Allocate buffer for response payload */
209 prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
211 prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
213 if (!prsp || !prsp->virt)
214 goto els_iocb_free_prsp_exit;
215 INIT_LIST_HEAD(&prsp->list);
219 /* Allocate buffer for Buffer ptr list */
220 pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
222 pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
224 if (!pbuflist || !pbuflist->virt)
225 goto els_iocb_free_pbuf_exit;
227 INIT_LIST_HEAD(&pbuflist->list);
229 icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
230 icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
231 icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
232 icmd->un.elsreq64.remoteID = did; /* DID */
234 icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64));
235 icmd->ulpCommand = CMD_ELS_REQUEST64_CR;
236 icmd->ulpTimeout = phba->fc_ratov * 2;
238 icmd->un.elsreq64.bdl.bdeSize = sizeof(struct ulp_bde64);
239 icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX;
241 icmd->ulpBdeCount = 1;
243 icmd->ulpClass = CLASS3;
245 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
246 icmd->un.elsreq64.myID = vport->fc_myDID;
248 /* For ELS_REQUEST64_CR, use the VPI by default */
249 icmd->ulpContext = vport->vpi + phba->vpi_base;
251 /* The CT field must be 0=INVALID_RPI for the ECHO cmd */
252 if (elscmd == ELS_CMD_ECHO)
253 icmd->ulpCt_l = 0; /* context = invalid RPI */
255 icmd->ulpCt_l = 1; /* context = VPI */
258 bpl = (struct ulp_bde64 *) pbuflist->virt;
259 bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys));
260 bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys));
261 bpl->tus.f.bdeSize = cmdSize;
262 bpl->tus.f.bdeFlags = 0;
263 bpl->tus.w = le32_to_cpu(bpl->tus.w);
267 bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys));
268 bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys));
269 bpl->tus.f.bdeSize = FCELSSIZE;
270 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
271 bpl->tus.w = le32_to_cpu(bpl->tus.w);
274 /* prevent preparing iocb with NULL ndlp reference */
275 elsiocb->context1 = lpfc_nlp_get(ndlp);
276 if (!elsiocb->context1)
277 goto els_iocb_free_pbuf_exit;
278 elsiocb->context2 = pcmd;
279 elsiocb->context3 = pbuflist;
280 elsiocb->retry = retry;
281 elsiocb->vport = vport;
282 elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT;
285 list_add(&prsp->list, &pcmd->list);
288 /* Xmit ELS command <elsCmd> to remote NPORT <did> */
289 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
290 "0116 Xmit ELS command x%x to remote "
291 "NPORT x%x I/O tag: x%x, port state: x%x\n",
292 elscmd, did, elsiocb->iotag,
295 /* Xmit ELS response <elsCmd> to remote NPORT <did> */
296 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
297 "0117 Xmit ELS response x%x to remote "
298 "NPORT x%x I/O tag: x%x, size: x%x\n",
299 elscmd, ndlp->nlp_DID, elsiocb->iotag,
304 els_iocb_free_pbuf_exit:
306 lpfc_mbuf_free(phba, prsp->virt, prsp->phys);
309 els_iocb_free_prsp_exit:
310 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
313 els_iocb_free_pcmb_exit:
315 lpfc_sli_release_iocbq(phba, elsiocb);
320 * lpfc_issue_fabric_reglogin - Issue fabric registration login for a vport
321 * @vport: pointer to a host virtual N_Port data structure.
323 * This routine issues a fabric registration login for a @vport. An
324 * active ndlp node with Fabric_DID must already exist for this @vport.
325 * The routine invokes two mailbox commands to carry out fabric registration
326 * login through the HBA firmware: the first mailbox command requests the
327 * HBA to perform link configuration for the @vport; and the second mailbox
328 * command requests the HBA to perform the actual fabric registration login
332 * 0 - successfully issued fabric registration login for @vport
333 * -ENXIO -- failed to issue fabric registration login for @vport
336 lpfc_issue_fabric_reglogin(struct lpfc_vport *vport)
338 struct lpfc_hba *phba = vport->phba;
340 struct lpfc_dmabuf *mp;
341 struct lpfc_nodelist *ndlp;
342 struct serv_parm *sp;
346 sp = &phba->fc_fabparam;
347 ndlp = lpfc_findnode_did(vport, Fabric_DID);
348 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
353 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
359 vport->port_state = LPFC_FABRIC_CFG_LINK;
360 lpfc_config_link(phba, mbox);
361 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
364 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
365 if (rc == MBX_NOT_FINISHED) {
370 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
375 rc = lpfc_reg_rpi(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox, 0);
381 mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login;
383 /* increment the reference count on ndlp to hold reference
384 * for the callback routine.
386 mbox->context2 = lpfc_nlp_get(ndlp);
388 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
389 if (rc == MBX_NOT_FINISHED) {
391 goto fail_issue_reg_login;
396 fail_issue_reg_login:
397 /* decrement the reference count on ndlp just incremented
398 * for the failed mbox command.
401 mp = (struct lpfc_dmabuf *) mbox->context1;
402 lpfc_mbuf_free(phba, mp->virt, mp->phys);
405 mempool_free(mbox, phba->mbox_mem_pool);
408 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
409 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
410 "0249 Cannot issue Register Fabric login: Err %d\n", err);
415 * lpfc_issue_reg_vfi - Register VFI for this vport's fabric login
416 * @vport: pointer to a host virtual N_Port data structure.
418 * This routine issues a REG_VFI mailbox for the vfi, vpi, fcfi triplet for
419 * the @vport. This mailbox command is necessary for FCoE only.
422 * 0 - successfully issued REG_VFI for @vport
423 * A failure code otherwise.
426 lpfc_issue_reg_vfi(struct lpfc_vport *vport)
428 struct lpfc_hba *phba = vport->phba;
430 struct lpfc_nodelist *ndlp;
431 struct serv_parm *sp;
432 struct lpfc_dmabuf *dmabuf;
435 sp = &phba->fc_fabparam;
436 ndlp = lpfc_findnode_did(vport, Fabric_DID);
437 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
442 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
447 dmabuf->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &dmabuf->phys);
450 goto fail_free_dmabuf;
452 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
455 goto fail_free_coherent;
457 vport->port_state = LPFC_FABRIC_CFG_LINK;
458 memcpy(dmabuf->virt, &phba->fc_fabparam, sizeof(vport->fc_sparam));
459 lpfc_reg_vfi(mboxq, vport, dmabuf->phys);
460 mboxq->mbox_cmpl = lpfc_mbx_cmpl_reg_vfi;
461 mboxq->vport = vport;
462 mboxq->context1 = dmabuf;
463 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
464 if (rc == MBX_NOT_FINISHED) {
471 mempool_free(mboxq, phba->mbox_mem_pool);
473 lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys);
477 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
478 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
479 "0289 Issue Register VFI failed: Err %d\n", rc);
484 * lpfc_cmpl_els_flogi_fabric - Completion function for flogi to a fabric port
485 * @vport: pointer to a host virtual N_Port data structure.
486 * @ndlp: pointer to a node-list data structure.
487 * @sp: pointer to service parameter data structure.
488 * @irsp: pointer to the IOCB within the lpfc response IOCB.
490 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
491 * function to handle the completion of a Fabric Login (FLOGI) into a fabric
492 * port in a fabric topology. It properly sets up the parameters to the @ndlp
493 * from the IOCB response. It also check the newly assigned N_Port ID to the
494 * @vport against the previously assigned N_Port ID. If it is different from
495 * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine
496 * is invoked on all the remaining nodes with the @vport to unregister the
497 * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin()
498 * is invoked to register login to the fabric.
501 * 0 - Success (currently, always return 0)
504 lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
505 struct serv_parm *sp, IOCB_t *irsp)
507 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
508 struct lpfc_hba *phba = vport->phba;
509 struct lpfc_nodelist *np;
510 struct lpfc_nodelist *next_np;
512 spin_lock_irq(shost->host_lock);
513 vport->fc_flag |= FC_FABRIC;
514 spin_unlock_irq(shost->host_lock);
516 phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
517 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
518 phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
520 phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
522 if (phba->fc_topology == TOPOLOGY_LOOP) {
523 spin_lock_irq(shost->host_lock);
524 vport->fc_flag |= FC_PUBLIC_LOOP;
525 spin_unlock_irq(shost->host_lock);
528 * If we are a N-port connected to a Fabric, fixup sparam's so
529 * logins to devices on remote loops work.
531 vport->fc_sparam.cmn.altBbCredit = 1;
534 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
535 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
536 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name));
537 ndlp->nlp_class_sup = 0;
538 if (sp->cls1.classValid)
539 ndlp->nlp_class_sup |= FC_COS_CLASS1;
540 if (sp->cls2.classValid)
541 ndlp->nlp_class_sup |= FC_COS_CLASS2;
542 if (sp->cls3.classValid)
543 ndlp->nlp_class_sup |= FC_COS_CLASS3;
544 if (sp->cls4.classValid)
545 ndlp->nlp_class_sup |= FC_COS_CLASS4;
546 ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
547 sp->cmn.bbRcvSizeLsb;
548 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
550 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
551 if (sp->cmn.response_multiple_NPort) {
552 lpfc_printf_vlog(vport, KERN_WARNING,
554 "1816 FLOGI NPIV supported, "
555 "response data 0x%x\n",
556 sp->cmn.response_multiple_NPort);
557 phba->link_flag |= LS_NPIV_FAB_SUPPORTED;
559 /* Because we asked f/w for NPIV it still expects us
560 to call reg_vnpid atleast for the physcial host */
561 lpfc_printf_vlog(vport, KERN_WARNING,
563 "1817 Fabric does not support NPIV "
564 "- configuring single port mode.\n");
565 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
569 if ((vport->fc_prevDID != vport->fc_myDID) &&
570 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
572 /* If our NportID changed, we need to ensure all
573 * remaining NPORTs get unreg_login'ed.
575 list_for_each_entry_safe(np, next_np,
576 &vport->fc_nodes, nlp_listp) {
577 if (!NLP_CHK_NODE_ACT(np))
579 if ((np->nlp_state != NLP_STE_NPR_NODE) ||
580 !(np->nlp_flag & NLP_NPR_ADISC))
582 spin_lock_irq(shost->host_lock);
583 np->nlp_flag &= ~NLP_NPR_ADISC;
584 spin_unlock_irq(shost->host_lock);
585 lpfc_unreg_rpi(vport, np);
587 lpfc_cleanup_pending_mbox(vport);
588 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
589 lpfc_mbx_unreg_vpi(vport);
590 spin_lock_irq(shost->host_lock);
591 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
592 spin_unlock_irq(shost->host_lock);
595 * If VPI is unreged, driver need to do INIT_VPI
596 * before re-registering
598 if (phba->sli_rev == LPFC_SLI_REV4) {
599 spin_lock_irq(shost->host_lock);
600 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
601 spin_unlock_irq(shost->host_lock);
605 if (phba->sli_rev < LPFC_SLI_REV4) {
606 lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
607 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED &&
608 vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
609 lpfc_register_new_vport(phba, vport, ndlp);
611 lpfc_issue_fabric_reglogin(vport);
613 ndlp->nlp_type |= NLP_FABRIC;
614 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
615 if ((!(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) &&
616 (vport->vpi_state & LPFC_VPI_REGISTERED)) {
617 lpfc_start_fdiscs(phba);
618 lpfc_do_scr_ns_plogi(phba, vport);
619 } else if (vport->fc_flag & FC_VFI_REGISTERED)
620 lpfc_issue_init_vpi(vport);
622 lpfc_issue_reg_vfi(vport);
627 * lpfc_cmpl_els_flogi_nport - Completion function for flogi to an N_Port
628 * @vport: pointer to a host virtual N_Port data structure.
629 * @ndlp: pointer to a node-list data structure.
630 * @sp: pointer to service parameter data structure.
632 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
633 * function to handle the completion of a Fabric Login (FLOGI) into an N_Port
634 * in a point-to-point topology. First, the @vport's N_Port Name is compared
635 * with the received N_Port Name: if the @vport's N_Port Name is greater than
636 * the received N_Port Name lexicographically, this node shall assign local
637 * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and
638 * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise,
639 * this node shall just wait for the remote node to issue PLOGI and assign
647 lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
648 struct serv_parm *sp)
650 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
651 struct lpfc_hba *phba = vport->phba;
655 spin_lock_irq(shost->host_lock);
656 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
657 spin_unlock_irq(shost->host_lock);
659 phba->fc_edtov = FF_DEF_EDTOV;
660 phba->fc_ratov = FF_DEF_RATOV;
661 rc = memcmp(&vport->fc_portname, &sp->portName,
662 sizeof(vport->fc_portname));
664 /* This side will initiate the PLOGI */
665 spin_lock_irq(shost->host_lock);
666 vport->fc_flag |= FC_PT2PT_PLOGI;
667 spin_unlock_irq(shost->host_lock);
670 * N_Port ID cannot be 0, set our to LocalID the other
671 * side will be RemoteID.
676 vport->fc_myDID = PT2PT_LocalID;
678 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
682 lpfc_config_link(phba, mbox);
684 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
686 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
687 if (rc == MBX_NOT_FINISHED) {
688 mempool_free(mbox, phba->mbox_mem_pool);
691 /* Decrement ndlp reference count indicating that ndlp can be
692 * safely released when other references to it are done.
696 ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
699 * Cannot find existing Fabric ndlp, so allocate a
702 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
705 lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID);
706 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
707 ndlp = lpfc_enable_node(vport, ndlp,
708 NLP_STE_UNUSED_NODE);
713 memcpy(&ndlp->nlp_portname, &sp->portName,
714 sizeof(struct lpfc_name));
715 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
716 sizeof(struct lpfc_name));
717 /* Set state will put ndlp onto node list if not already done */
718 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
719 spin_lock_irq(shost->host_lock);
720 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
721 spin_unlock_irq(shost->host_lock);
723 /* This side will wait for the PLOGI, decrement ndlp reference
724 * count indicating that ndlp can be released when other
725 * references to it are done.
729 /* If we are pt2pt with another NPort, force NPIV off! */
730 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
732 spin_lock_irq(shost->host_lock);
733 vport->fc_flag |= FC_PT2PT;
734 spin_unlock_irq(shost->host_lock);
736 /* Start discovery - this should just do CLEAR_LA */
737 lpfc_disc_start(vport);
744 * lpfc_cmpl_els_flogi - Completion callback function for flogi
745 * @phba: pointer to lpfc hba data structure.
746 * @cmdiocb: pointer to lpfc command iocb data structure.
747 * @rspiocb: pointer to lpfc response iocb data structure.
749 * This routine is the top-level completion callback function for issuing
750 * a Fabric Login (FLOGI) command. If the response IOCB reported error,
751 * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If
752 * retry has been made (either immediately or delayed with lpfc_els_retry()
753 * returning 1), the command IOCB will be released and function returned.
754 * If the retry attempt has been given up (possibly reach the maximum
755 * number of retries), one additional decrement of ndlp reference shall be
756 * invoked before going out after releasing the command IOCB. This will
757 * actually release the remote node (Note, lpfc_els_free_iocb() will also
758 * invoke one decrement of ndlp reference count). If no error reported in
759 * the IOCB status, the command Port ID field is used to determine whether
760 * this is a point-to-point topology or a fabric topology: if the Port ID
761 * field is assigned, it is a fabric topology; otherwise, it is a
762 * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or
763 * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the
764 * specific topology completion conditions.
767 lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
768 struct lpfc_iocbq *rspiocb)
770 struct lpfc_vport *vport = cmdiocb->vport;
771 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
772 IOCB_t *irsp = &rspiocb->iocb;
773 struct lpfc_nodelist *ndlp = cmdiocb->context1;
774 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
775 struct serv_parm *sp;
779 /* Check to see if link went down during discovery */
780 if (lpfc_els_chk_latt(vport)) {
781 /* One additional decrement on node reference count to
782 * trigger the release of the node
788 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
789 "FLOGI cmpl: status:x%x/x%x state:x%x",
790 irsp->ulpStatus, irsp->un.ulpWord[4],
793 if (irsp->ulpStatus) {
795 * In case of FIP mode, perform round robin FCF failover
796 * due to new FCF discovery
798 if ((phba->hba_flag & HBA_FIP_SUPPORT) &&
799 (phba->fcf.fcf_flag & FCF_DISCOVERY) &&
800 (irsp->ulpStatus != IOSTAT_LOCAL_REJECT) &&
801 (irsp->un.ulpWord[4] != IOERR_SLI_ABORTED)) {
802 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
803 "2611 FLOGI failed on registered "
804 "FCF record fcf_index:%d, trying "
805 "to perform round robin failover\n",
806 phba->fcf.current_rec.fcf_indx);
807 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
808 if (fcf_index == LPFC_FCOE_FCF_NEXT_NONE) {
810 * Exhausted the eligible FCF record list,
811 * fail through to retry FLOGI on current
814 lpfc_printf_log(phba, KERN_WARNING,
816 "2760 Completed one round "
817 "of FLOGI FCF round robin "
818 "failover list, retry FLOGI "
819 "on currently registered "
821 phba->fcf.current_rec.fcf_indx);
823 lpfc_printf_log(phba, KERN_INFO,
825 "2794 FLOGI FCF round robin "
826 "failover to FCF index x%x\n",
828 rc = lpfc_sli4_fcf_rr_read_fcf_rec(phba,
831 lpfc_printf_log(phba, KERN_WARNING,
834 "robin FCF failover "
838 phba->fcf.current_rec.fcf_indx);
844 /* Check for retry */
845 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
848 /* FLOGI failed, so there is no fabric */
849 spin_lock_irq(shost->host_lock);
850 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
851 spin_unlock_irq(shost->host_lock);
853 /* If private loop, then allow max outstanding els to be
854 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
855 * alpa map would take too long otherwise.
857 if (phba->alpa_map[0] == 0) {
858 vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
862 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
863 "0100 FLOGI failure Status:x%x/x%x TMO:x%x\n",
864 irsp->ulpStatus, irsp->un.ulpWord[4],
868 spin_lock_irq(shost->host_lock);
869 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
870 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
871 spin_unlock_irq(shost->host_lock);
874 * The FLogI succeeded. Sync the data for the CPU before
877 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
879 sp = prsp->virt + sizeof(uint32_t);
881 /* FLOGI completes successfully */
882 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
883 "0101 FLOGI completes successfully "
884 "Data: x%x x%x x%x x%x\n",
885 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
886 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution);
888 if (vport->port_state == LPFC_FLOGI) {
890 * If Common Service Parameters indicate Nport
891 * we are point to point, if Fport we are Fabric.
894 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
895 else if (!(phba->hba_flag & HBA_FCOE_SUPPORT))
896 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
898 lpfc_printf_vlog(vport, KERN_ERR,
900 "2831 FLOGI response with cleared Fabric "
901 "bit fcf_index 0x%x "
902 "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x "
904 "%02x%02x%02x%02x%02x%02x%02x%02x\n",
905 phba->fcf.current_rec.fcf_indx,
906 phba->fcf.current_rec.switch_name[0],
907 phba->fcf.current_rec.switch_name[1],
908 phba->fcf.current_rec.switch_name[2],
909 phba->fcf.current_rec.switch_name[3],
910 phba->fcf.current_rec.switch_name[4],
911 phba->fcf.current_rec.switch_name[5],
912 phba->fcf.current_rec.switch_name[6],
913 phba->fcf.current_rec.switch_name[7],
914 phba->fcf.current_rec.fabric_name[0],
915 phba->fcf.current_rec.fabric_name[1],
916 phba->fcf.current_rec.fabric_name[2],
917 phba->fcf.current_rec.fabric_name[3],
918 phba->fcf.current_rec.fabric_name[4],
919 phba->fcf.current_rec.fabric_name[5],
920 phba->fcf.current_rec.fabric_name[6],
921 phba->fcf.current_rec.fabric_name[7]);
923 spin_lock_irq(&phba->hbalock);
924 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
925 spin_unlock_irq(&phba->hbalock);
929 /* Mark the FCF discovery process done */
930 if (phba->hba_flag & HBA_FIP_SUPPORT)
931 lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP |
933 "2769 FLOGI successful on FCF "
934 "record: current_fcf_index:"
935 "x%x, terminate FCF round "
936 "robin failover process\n",
937 phba->fcf.current_rec.fcf_indx);
938 spin_lock_irq(&phba->hbalock);
939 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
940 spin_unlock_irq(&phba->hbalock);
948 if (!lpfc_error_lost_link(irsp)) {
949 /* FLOGI failed, so just use loop map to make discovery list */
950 lpfc_disc_list_loopmap(vport);
952 /* Start discovery */
953 lpfc_disc_start(vport);
954 } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
955 ((irsp->un.ulpWord[4] != IOERR_SLI_ABORTED) &&
956 (irsp->un.ulpWord[4] != IOERR_SLI_DOWN))) &&
957 (phba->link_state != LPFC_CLEAR_LA)) {
958 /* If FLOGI failed enable link interrupt. */
959 lpfc_issue_clear_la(phba, vport);
962 lpfc_els_free_iocb(phba, cmdiocb);
966 * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport
967 * @vport: pointer to a host virtual N_Port data structure.
968 * @ndlp: pointer to a node-list data structure.
969 * @retry: number of retries to the command IOCB.
971 * This routine issues a Fabric Login (FLOGI) Request ELS command
972 * for a @vport. The initiator service parameters are put into the payload
973 * of the FLOGI Request IOCB and the top-level callback function pointer
974 * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
975 * function field. The lpfc_issue_fabric_iocb routine is invoked to send
976 * out FLOGI ELS command with one outstanding fabric IOCB at a time.
978 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
979 * will be incremented by 1 for holding the ndlp and the reference to ndlp
980 * will be stored into the context1 field of the IOCB for the completion
981 * callback function to the FLOGI ELS command.
984 * 0 - successfully issued flogi iocb for @vport
985 * 1 - failed to issue flogi iocb for @vport
988 lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
991 struct lpfc_hba *phba = vport->phba;
992 struct serv_parm *sp;
994 struct lpfc_iocbq *elsiocb;
995 struct lpfc_sli_ring *pring;
1001 pring = &phba->sli.ring[LPFC_ELS_RING];
1003 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
1004 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1005 ndlp->nlp_DID, ELS_CMD_FLOGI);
1010 icmd = &elsiocb->iocb;
1011 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1013 /* For FLOGI request, remainder of payload is service parameters */
1014 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
1015 pcmd += sizeof(uint32_t);
1016 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
1017 sp = (struct serv_parm *) pcmd;
1019 /* Setup CSPs accordingly for Fabric */
1020 sp->cmn.e_d_tov = 0;
1021 sp->cmn.w2.r_a_tov = 0;
1022 sp->cls1.classValid = 0;
1023 sp->cls2.seqDelivery = 1;
1024 sp->cls3.seqDelivery = 1;
1025 if (sp->cmn.fcphLow < FC_PH3)
1026 sp->cmn.fcphLow = FC_PH3;
1027 if (sp->cmn.fcphHigh < FC_PH3)
1028 sp->cmn.fcphHigh = FC_PH3;
1030 if (phba->sli_rev == LPFC_SLI_REV4) {
1031 elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1);
1032 elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1);
1033 /* FLOGI needs to be 3 for WQE FCFI */
1034 /* Set the fcfi to the fcfi we registered with */
1035 elsiocb->iocb.ulpContext = phba->fcf.fcfi;
1036 } else if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
1037 sp->cmn.request_multiple_Nport = 1;
1038 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
1043 if (phba->fc_topology != TOPOLOGY_LOOP) {
1044 icmd->un.elsreq64.myID = 0;
1045 icmd->un.elsreq64.fl = 1;
1048 tmo = phba->fc_ratov;
1049 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
1050 lpfc_set_disctmo(vport);
1051 phba->fc_ratov = tmo;
1053 phba->fc_stat.elsXmitFLOGI++;
1054 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
1056 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1057 "Issue FLOGI: opt:x%x",
1058 phba->sli3_options, 0, 0);
1060 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
1061 if (rc == IOCB_ERROR) {
1062 lpfc_els_free_iocb(phba, elsiocb);
1069 * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs
1070 * @phba: pointer to lpfc hba data structure.
1072 * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
1073 * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
1074 * list and issues an abort IOCB commond on each outstanding IOCB that
1075 * contains a active Fabric_DID ndlp. Note that this function is to issue
1076 * the abort IOCB command on all the outstanding IOCBs, thus when this
1077 * function returns, it does not guarantee all the IOCBs are actually aborted.
1080 * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0)
1083 lpfc_els_abort_flogi(struct lpfc_hba *phba)
1085 struct lpfc_sli_ring *pring;
1086 struct lpfc_iocbq *iocb, *next_iocb;
1087 struct lpfc_nodelist *ndlp;
1090 /* Abort outstanding I/O on NPort <nlp_DID> */
1091 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
1092 "0201 Abort outstanding I/O on NPort x%x\n",
1095 pring = &phba->sli.ring[LPFC_ELS_RING];
1098 * Check the txcmplq for an iocb that matches the nport the driver is
1101 spin_lock_irq(&phba->hbalock);
1102 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
1104 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR &&
1105 icmd->un.elsreq64.bdl.ulpIoTag32) {
1106 ndlp = (struct lpfc_nodelist *)(iocb->context1);
1107 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
1108 (ndlp->nlp_DID == Fabric_DID))
1109 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
1112 spin_unlock_irq(&phba->hbalock);
1118 * lpfc_initial_flogi - Issue an initial fabric login for a vport
1119 * @vport: pointer to a host virtual N_Port data structure.
1121 * This routine issues an initial Fabric Login (FLOGI) for the @vport
1122 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1123 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1124 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1125 * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
1126 * is then invoked with the @vport and the ndlp to perform the FLOGI for the
1130 * 0 - failed to issue initial flogi for @vport
1131 * 1 - successfully issued initial flogi for @vport
1134 lpfc_initial_flogi(struct lpfc_vport *vport)
1136 struct lpfc_hba *phba = vport->phba;
1137 struct lpfc_nodelist *ndlp;
1139 vport->port_state = LPFC_FLOGI;
1140 lpfc_set_disctmo(vport);
1142 /* First look for the Fabric ndlp */
1143 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1145 /* Cannot find existing Fabric ndlp, so allocate a new one */
1146 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1149 lpfc_nlp_init(vport, ndlp, Fabric_DID);
1150 /* Set the node type */
1151 ndlp->nlp_type |= NLP_FABRIC;
1152 /* Put ndlp onto node list */
1153 lpfc_enqueue_node(vport, ndlp);
1154 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1155 /* re-setup ndlp without removing from node list */
1156 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1161 if (lpfc_issue_els_flogi(vport, ndlp, 0))
1162 /* This decrement of reference count to node shall kick off
1163 * the release of the node.
1171 * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport
1172 * @vport: pointer to a host virtual N_Port data structure.
1174 * This routine issues an initial Fabric Discover (FDISC) for the @vport
1175 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1176 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1177 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1178 * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
1179 * is then invoked with the @vport and the ndlp to perform the FDISC for the
1183 * 0 - failed to issue initial fdisc for @vport
1184 * 1 - successfully issued initial fdisc for @vport
1187 lpfc_initial_fdisc(struct lpfc_vport *vport)
1189 struct lpfc_hba *phba = vport->phba;
1190 struct lpfc_nodelist *ndlp;
1192 /* First look for the Fabric ndlp */
1193 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1195 /* Cannot find existing Fabric ndlp, so allocate a new one */
1196 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1199 lpfc_nlp_init(vport, ndlp, Fabric_DID);
1200 /* Put ndlp onto node list */
1201 lpfc_enqueue_node(vport, ndlp);
1202 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1203 /* re-setup ndlp without removing from node list */
1204 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1209 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
1210 /* decrement node reference count to trigger the release of
1220 * lpfc_more_plogi - Check and issue remaining plogis for a vport
1221 * @vport: pointer to a host virtual N_Port data structure.
1223 * This routine checks whether there are more remaining Port Logins
1224 * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
1225 * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
1226 * to issue ELS PLOGIs up to the configured discover threads with the
1227 * @vport (@vport->cfg_discovery_threads). The function also decrement
1228 * the @vport's num_disc_node by 1 if it is not already 0.
1231 lpfc_more_plogi(struct lpfc_vport *vport)
1235 if (vport->num_disc_nodes)
1236 vport->num_disc_nodes--;
1238 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
1239 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1240 "0232 Continue discovery with %d PLOGIs to go "
1241 "Data: x%x x%x x%x\n",
1242 vport->num_disc_nodes, vport->fc_plogi_cnt,
1243 vport->fc_flag, vport->port_state);
1244 /* Check to see if there are more PLOGIs to be sent */
1245 if (vport->fc_flag & FC_NLP_MORE)
1246 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
1247 sentplogi = lpfc_els_disc_plogi(vport);
1253 * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp
1254 * @phba: pointer to lpfc hba data structure.
1255 * @prsp: pointer to response IOCB payload.
1256 * @ndlp: pointer to a node-list data structure.
1258 * This routine checks and indicates whether the WWPN of an N_Port, retrieved
1259 * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
1260 * The following cases are considered N_Port confirmed:
1261 * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
1262 * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
1263 * it does not have WWPN assigned either. If the WWPN is confirmed, the
1264 * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
1265 * 1) if there is a node on vport list other than the @ndlp with the same
1266 * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
1267 * on that node to release the RPI associated with the node; 2) if there is
1268 * no node found on vport list with the same WWPN of the N_Port PLOGI logged
1269 * into, a new node shall be allocated (or activated). In either case, the
1270 * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
1271 * be released and the new_ndlp shall be put on to the vport node list and
1272 * its pointer returned as the confirmed node.
1274 * Note that before the @ndlp got "released", the keepDID from not-matching
1275 * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
1276 * of the @ndlp. This is because the release of @ndlp is actually to put it
1277 * into an inactive state on the vport node list and the vport node list
1278 * management algorithm does not allow two node with a same DID.
1281 * pointer to the PLOGI N_Port @ndlp
1283 static struct lpfc_nodelist *
1284 lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
1285 struct lpfc_nodelist *ndlp)
1287 struct lpfc_vport *vport = ndlp->vport;
1288 struct lpfc_nodelist *new_ndlp;
1289 struct lpfc_rport_data *rdata;
1290 struct fc_rport *rport;
1291 struct serv_parm *sp;
1292 uint8_t name[sizeof(struct lpfc_name)];
1293 uint32_t rc, keepDID = 0;
1295 /* Fabric nodes can have the same WWPN so we don't bother searching
1296 * by WWPN. Just return the ndlp that was given to us.
1298 if (ndlp->nlp_type & NLP_FABRIC)
1301 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
1302 memset(name, 0, sizeof(struct lpfc_name));
1304 /* Now we find out if the NPort we are logging into, matches the WWPN
1305 * we have for that ndlp. If not, we have some work to do.
1307 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
1309 if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp))
1313 rc = memcmp(&ndlp->nlp_portname, name,
1314 sizeof(struct lpfc_name));
1317 new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
1320 lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID);
1321 } else if (!NLP_CHK_NODE_ACT(new_ndlp)) {
1322 rc = memcmp(&ndlp->nlp_portname, name,
1323 sizeof(struct lpfc_name));
1326 new_ndlp = lpfc_enable_node(vport, new_ndlp,
1327 NLP_STE_UNUSED_NODE);
1330 keepDID = new_ndlp->nlp_DID;
1332 keepDID = new_ndlp->nlp_DID;
1334 lpfc_unreg_rpi(vport, new_ndlp);
1335 new_ndlp->nlp_DID = ndlp->nlp_DID;
1336 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
1338 if (ndlp->nlp_flag & NLP_NPR_2B_DISC)
1339 new_ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1340 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1342 /* Set state will put new_ndlp on to node list if not already done */
1343 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
1345 /* Move this back to NPR state */
1346 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
1347 /* The new_ndlp is replacing ndlp totally, so we need
1348 * to put ndlp on UNUSED list and try to free it.
1351 /* Fix up the rport accordingly */
1352 rport = ndlp->rport;
1354 rdata = rport->dd_data;
1355 if (rdata->pnode == ndlp) {
1358 rdata->pnode = lpfc_nlp_get(new_ndlp);
1359 new_ndlp->rport = rport;
1361 new_ndlp->nlp_type = ndlp->nlp_type;
1363 /* We shall actually free the ndlp with both nlp_DID and
1364 * nlp_portname fields equals 0 to avoid any ndlp on the
1365 * nodelist never to be used.
1367 if (ndlp->nlp_DID == 0) {
1368 spin_lock_irq(&phba->ndlp_lock);
1369 NLP_SET_FREE_REQ(ndlp);
1370 spin_unlock_irq(&phba->ndlp_lock);
1373 /* Two ndlps cannot have the same did on the nodelist */
1374 ndlp->nlp_DID = keepDID;
1375 lpfc_drop_node(vport, ndlp);
1378 lpfc_unreg_rpi(vport, ndlp);
1379 /* Two ndlps cannot have the same did */
1380 ndlp->nlp_DID = keepDID;
1381 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1387 * lpfc_end_rscn - Check and handle more rscn for a vport
1388 * @vport: pointer to a host virtual N_Port data structure.
1390 * This routine checks whether more Registration State Change
1391 * Notifications (RSCNs) came in while the discovery state machine was in
1392 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1393 * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1394 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1395 * handling the RSCNs.
1398 lpfc_end_rscn(struct lpfc_vport *vport)
1400 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1402 if (vport->fc_flag & FC_RSCN_MODE) {
1404 * Check to see if more RSCNs came in while we were
1405 * processing this one.
1407 if (vport->fc_rscn_id_cnt ||
1408 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
1409 lpfc_els_handle_rscn(vport);
1411 spin_lock_irq(shost->host_lock);
1412 vport->fc_flag &= ~FC_RSCN_MODE;
1413 spin_unlock_irq(shost->host_lock);
1419 * lpfc_cmpl_els_plogi - Completion callback function for plogi
1420 * @phba: pointer to lpfc hba data structure.
1421 * @cmdiocb: pointer to lpfc command iocb data structure.
1422 * @rspiocb: pointer to lpfc response iocb data structure.
1424 * This routine is the completion callback function for issuing the Port
1425 * Login (PLOGI) command. For PLOGI completion, there must be an active
1426 * ndlp on the vport node list that matches the remote node ID from the
1427 * PLOGI reponse IOCB. If such ndlp does not exist, the PLOGI is simply
1428 * ignored and command IOCB released. The PLOGI response IOCB status is
1429 * checked for error conditons. If there is error status reported, PLOGI
1430 * retry shall be attempted by invoking the lpfc_els_retry() routine.
1431 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1432 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1433 * (DSM) is set for this PLOGI completion. Finally, it checks whether
1434 * there are additional N_Port nodes with the vport that need to perform
1435 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
1439 lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1440 struct lpfc_iocbq *rspiocb)
1442 struct lpfc_vport *vport = cmdiocb->vport;
1443 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1445 struct lpfc_nodelist *ndlp;
1446 struct lpfc_dmabuf *prsp;
1447 int disc, rc, did, type;
1449 /* we pass cmdiocb to state machine which needs rspiocb as well */
1450 cmdiocb->context_un.rsp_iocb = rspiocb;
1452 irsp = &rspiocb->iocb;
1453 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1454 "PLOGI cmpl: status:x%x/x%x did:x%x",
1455 irsp->ulpStatus, irsp->un.ulpWord[4],
1456 irsp->un.elsreq64.remoteID);
1458 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
1459 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
1460 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1461 "0136 PLOGI completes to NPort x%x "
1462 "with no ndlp. Data: x%x x%x x%x\n",
1463 irsp->un.elsreq64.remoteID,
1464 irsp->ulpStatus, irsp->un.ulpWord[4],
1469 /* Since ndlp can be freed in the disc state machine, note if this node
1470 * is being used during discovery.
1472 spin_lock_irq(shost->host_lock);
1473 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
1474 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1475 spin_unlock_irq(shost->host_lock);
1478 /* PLOGI completes to NPort <nlp_DID> */
1479 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1480 "0102 PLOGI completes to NPort x%x "
1481 "Data: x%x x%x x%x x%x x%x\n",
1482 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1483 irsp->ulpTimeout, disc, vport->num_disc_nodes);
1484 /* Check to see if link went down during discovery */
1485 if (lpfc_els_chk_latt(vport)) {
1486 spin_lock_irq(shost->host_lock);
1487 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1488 spin_unlock_irq(shost->host_lock);
1492 /* ndlp could be freed in DSM, save these values now */
1493 type = ndlp->nlp_type;
1494 did = ndlp->nlp_DID;
1496 if (irsp->ulpStatus) {
1497 /* Check for retry */
1498 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1499 /* ELS command is being retried */
1501 spin_lock_irq(shost->host_lock);
1502 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1503 spin_unlock_irq(shost->host_lock);
1507 /* PLOGI failed Don't print the vport to vport rjts */
1508 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1509 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1510 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1511 (phba)->pport->cfg_log_verbose & LOG_ELS)
1512 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1513 "2753 PLOGI failure DID:%06X Status:x%x/x%x\n",
1514 ndlp->nlp_DID, irsp->ulpStatus,
1515 irsp->un.ulpWord[4]);
1516 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1517 if (lpfc_error_lost_link(irsp))
1518 rc = NLP_STE_FREED_NODE;
1520 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1521 NLP_EVT_CMPL_PLOGI);
1523 /* Good status, call state machine */
1524 prsp = list_entry(((struct lpfc_dmabuf *)
1525 cmdiocb->context2)->list.next,
1526 struct lpfc_dmabuf, list);
1527 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
1528 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1529 NLP_EVT_CMPL_PLOGI);
1532 if (disc && vport->num_disc_nodes) {
1533 /* Check to see if there are more PLOGIs to be sent */
1534 lpfc_more_plogi(vport);
1536 if (vport->num_disc_nodes == 0) {
1537 spin_lock_irq(shost->host_lock);
1538 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1539 spin_unlock_irq(shost->host_lock);
1541 lpfc_can_disctmo(vport);
1542 lpfc_end_rscn(vport);
1547 lpfc_els_free_iocb(phba, cmdiocb);
1552 * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
1553 * @vport: pointer to a host virtual N_Port data structure.
1554 * @did: destination port identifier.
1555 * @retry: number of retries to the command IOCB.
1557 * This routine issues a Port Login (PLOGI) command to a remote N_Port
1558 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
1559 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
1560 * This routine constructs the proper feilds of the PLOGI IOCB and invokes
1561 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
1563 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1564 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1565 * will be stored into the context1 field of the IOCB for the completion
1566 * callback function to the PLOGI ELS command.
1569 * 0 - Successfully issued a plogi for @vport
1570 * 1 - failed to issue a plogi for @vport
1573 lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
1575 struct lpfc_hba *phba = vport->phba;
1576 struct serv_parm *sp;
1578 struct lpfc_nodelist *ndlp;
1579 struct lpfc_iocbq *elsiocb;
1580 struct lpfc_sli *psli;
1587 ndlp = lpfc_findnode_did(vport, did);
1588 if (ndlp && !NLP_CHK_NODE_ACT(ndlp))
1591 /* If ndlp is not NULL, we will bump the reference count on it */
1592 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
1593 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
1598 icmd = &elsiocb->iocb;
1599 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1601 /* For PLOGI request, remainder of payload is service parameters */
1602 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
1603 pcmd += sizeof(uint32_t);
1604 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
1605 sp = (struct serv_parm *) pcmd;
1607 if (sp->cmn.fcphLow < FC_PH_4_3)
1608 sp->cmn.fcphLow = FC_PH_4_3;
1610 if (sp->cmn.fcphHigh < FC_PH3)
1611 sp->cmn.fcphHigh = FC_PH3;
1613 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1614 "Issue PLOGI: did:x%x",
1617 phba->fc_stat.elsXmitPLOGI++;
1618 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
1619 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
1621 if (ret == IOCB_ERROR) {
1622 lpfc_els_free_iocb(phba, elsiocb);
1629 * lpfc_cmpl_els_prli - Completion callback function for prli
1630 * @phba: pointer to lpfc hba data structure.
1631 * @cmdiocb: pointer to lpfc command iocb data structure.
1632 * @rspiocb: pointer to lpfc response iocb data structure.
1634 * This routine is the completion callback function for a Process Login
1635 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
1636 * status. If there is error status reported, PRLI retry shall be attempted
1637 * by invoking the lpfc_els_retry() routine. Otherwise, the state
1638 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
1639 * ndlp to mark the PRLI completion.
1642 lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1643 struct lpfc_iocbq *rspiocb)
1645 struct lpfc_vport *vport = cmdiocb->vport;
1646 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1648 struct lpfc_sli *psli;
1649 struct lpfc_nodelist *ndlp;
1652 /* we pass cmdiocb to state machine which needs rspiocb as well */
1653 cmdiocb->context_un.rsp_iocb = rspiocb;
1655 irsp = &(rspiocb->iocb);
1656 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1657 spin_lock_irq(shost->host_lock);
1658 ndlp->nlp_flag &= ~NLP_PRLI_SND;
1659 spin_unlock_irq(shost->host_lock);
1661 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1662 "PRLI cmpl: status:x%x/x%x did:x%x",
1663 irsp->ulpStatus, irsp->un.ulpWord[4],
1665 /* PRLI completes to NPort <nlp_DID> */
1666 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1667 "0103 PRLI completes to NPort x%x "
1668 "Data: x%x x%x x%x x%x\n",
1669 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1670 irsp->ulpTimeout, vport->num_disc_nodes);
1672 vport->fc_prli_sent--;
1673 /* Check to see if link went down during discovery */
1674 if (lpfc_els_chk_latt(vport))
1677 if (irsp->ulpStatus) {
1678 /* Check for retry */
1679 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1680 /* ELS command is being retried */
1684 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1685 "2754 PRLI failure DID:%06X Status:x%x/x%x\n",
1686 ndlp->nlp_DID, irsp->ulpStatus,
1687 irsp->un.ulpWord[4]);
1688 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1689 if (lpfc_error_lost_link(irsp))
1692 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1695 /* Good status, call state machine */
1696 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1699 lpfc_els_free_iocb(phba, cmdiocb);
1704 * lpfc_issue_els_prli - Issue a prli iocb command for a vport
1705 * @vport: pointer to a host virtual N_Port data structure.
1706 * @ndlp: pointer to a node-list data structure.
1707 * @retry: number of retries to the command IOCB.
1709 * This routine issues a Process Login (PRLI) ELS command for the
1710 * @vport. The PRLI service parameters are set up in the payload of the
1711 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
1712 * is put to the IOCB completion callback func field before invoking the
1713 * routine lpfc_sli_issue_iocb() to send out PRLI command.
1715 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1716 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1717 * will be stored into the context1 field of the IOCB for the completion
1718 * callback function to the PRLI ELS command.
1721 * 0 - successfully issued prli iocb command for @vport
1722 * 1 - failed to issue prli iocb command for @vport
1725 lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1728 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1729 struct lpfc_hba *phba = vport->phba;
1732 struct lpfc_iocbq *elsiocb;
1736 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
1737 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1738 ndlp->nlp_DID, ELS_CMD_PRLI);
1742 icmd = &elsiocb->iocb;
1743 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1745 /* For PRLI request, remainder of payload is service parameters */
1746 memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t)));
1747 *((uint32_t *) (pcmd)) = ELS_CMD_PRLI;
1748 pcmd += sizeof(uint32_t);
1750 /* For PRLI, remainder of payload is PRLI parameter page */
1751 npr = (PRLI *) pcmd;
1753 * If our firmware version is 3.20 or later,
1754 * set the following bits for FC-TAPE support.
1756 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
1757 npr->ConfmComplAllowed = 1;
1759 npr->TaskRetryIdReq = 1;
1761 npr->estabImagePair = 1;
1762 npr->readXferRdyDis = 1;
1764 /* For FCP support */
1765 npr->prliType = PRLI_FCP_TYPE;
1766 npr->initiatorFunc = 1;
1768 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1769 "Issue PRLI: did:x%x",
1770 ndlp->nlp_DID, 0, 0);
1772 phba->fc_stat.elsXmitPRLI++;
1773 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
1774 spin_lock_irq(shost->host_lock);
1775 ndlp->nlp_flag |= NLP_PRLI_SND;
1776 spin_unlock_irq(shost->host_lock);
1777 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
1779 spin_lock_irq(shost->host_lock);
1780 ndlp->nlp_flag &= ~NLP_PRLI_SND;
1781 spin_unlock_irq(shost->host_lock);
1782 lpfc_els_free_iocb(phba, elsiocb);
1785 vport->fc_prli_sent++;
1790 * lpfc_rscn_disc - Perform rscn discovery for a vport
1791 * @vport: pointer to a host virtual N_Port data structure.
1793 * This routine performs Registration State Change Notification (RSCN)
1794 * discovery for a @vport. If the @vport's node port recovery count is not
1795 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
1796 * the nodes that need recovery. If none of the PLOGI were needed through
1797 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
1798 * invoked to check and handle possible more RSCN came in during the period
1799 * of processing the current ones.
1802 lpfc_rscn_disc(struct lpfc_vport *vport)
1804 lpfc_can_disctmo(vport);
1806 /* RSCN discovery */
1807 /* go thru NPR nodes and issue ELS PLOGIs */
1808 if (vport->fc_npr_cnt)
1809 if (lpfc_els_disc_plogi(vport))
1812 lpfc_end_rscn(vport);
1816 * lpfc_adisc_done - Complete the adisc phase of discovery
1817 * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
1819 * This function is called when the final ADISC is completed during discovery.
1820 * This function handles clearing link attention or issuing reg_vpi depending
1821 * on whether npiv is enabled. This function also kicks off the PLOGI phase of
1823 * This function is called with no locks held.
1826 lpfc_adisc_done(struct lpfc_vport *vport)
1828 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1829 struct lpfc_hba *phba = vport->phba;
1832 * For NPIV, cmpl_reg_vpi will set port_state to READY,
1833 * and continue discovery.
1835 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
1836 !(vport->fc_flag & FC_RSCN_MODE) &&
1837 (phba->sli_rev < LPFC_SLI_REV4)) {
1838 lpfc_issue_reg_vpi(phba, vport);
1842 * For SLI2, we need to set port_state to READY
1843 * and continue discovery.
1845 if (vport->port_state < LPFC_VPORT_READY) {
1846 /* If we get here, there is nothing to ADISC */
1847 if (vport->port_type == LPFC_PHYSICAL_PORT)
1848 lpfc_issue_clear_la(phba, vport);
1849 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
1850 vport->num_disc_nodes = 0;
1851 /* go thru NPR list, issue ELS PLOGIs */
1852 if (vport->fc_npr_cnt)
1853 lpfc_els_disc_plogi(vport);
1854 if (!vport->num_disc_nodes) {
1855 spin_lock_irq(shost->host_lock);
1856 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1857 spin_unlock_irq(shost->host_lock);
1858 lpfc_can_disctmo(vport);
1859 lpfc_end_rscn(vport);
1862 vport->port_state = LPFC_VPORT_READY;
1864 lpfc_rscn_disc(vport);
1868 * lpfc_more_adisc - Issue more adisc as needed
1869 * @vport: pointer to a host virtual N_Port data structure.
1871 * This routine determines whether there are more ndlps on a @vport
1872 * node list need to have Address Discover (ADISC) issued. If so, it will
1873 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
1874 * remaining nodes which need to have ADISC sent.
1877 lpfc_more_adisc(struct lpfc_vport *vport)
1881 if (vport->num_disc_nodes)
1882 vport->num_disc_nodes--;
1883 /* Continue discovery with <num_disc_nodes> ADISCs to go */
1884 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1885 "0210 Continue discovery with %d ADISCs to go "
1886 "Data: x%x x%x x%x\n",
1887 vport->num_disc_nodes, vport->fc_adisc_cnt,
1888 vport->fc_flag, vport->port_state);
1889 /* Check to see if there are more ADISCs to be sent */
1890 if (vport->fc_flag & FC_NLP_MORE) {
1891 lpfc_set_disctmo(vport);
1892 /* go thru NPR nodes and issue any remaining ELS ADISCs */
1893 sentadisc = lpfc_els_disc_adisc(vport);
1895 if (!vport->num_disc_nodes)
1896 lpfc_adisc_done(vport);
1901 * lpfc_cmpl_els_adisc - Completion callback function for adisc
1902 * @phba: pointer to lpfc hba data structure.
1903 * @cmdiocb: pointer to lpfc command iocb data structure.
1904 * @rspiocb: pointer to lpfc response iocb data structure.
1906 * This routine is the completion function for issuing the Address Discover
1907 * (ADISC) command. It first checks to see whether link went down during
1908 * the discovery process. If so, the node will be marked as node port
1909 * recovery for issuing discover IOCB by the link attention handler and
1910 * exit. Otherwise, the response status is checked. If error was reported
1911 * in the response status, the ADISC command shall be retried by invoking
1912 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
1913 * the response status, the state machine is invoked to set transition
1914 * with respect to NLP_EVT_CMPL_ADISC event.
1917 lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1918 struct lpfc_iocbq *rspiocb)
1920 struct lpfc_vport *vport = cmdiocb->vport;
1921 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1923 struct lpfc_nodelist *ndlp;
1926 /* we pass cmdiocb to state machine which needs rspiocb as well */
1927 cmdiocb->context_un.rsp_iocb = rspiocb;
1929 irsp = &(rspiocb->iocb);
1930 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1932 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1933 "ADISC cmpl: status:x%x/x%x did:x%x",
1934 irsp->ulpStatus, irsp->un.ulpWord[4],
1937 /* Since ndlp can be freed in the disc state machine, note if this node
1938 * is being used during discovery.
1940 spin_lock_irq(shost->host_lock);
1941 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
1942 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
1943 spin_unlock_irq(shost->host_lock);
1944 /* ADISC completes to NPort <nlp_DID> */
1945 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1946 "0104 ADISC completes to NPort x%x "
1947 "Data: x%x x%x x%x x%x x%x\n",
1948 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1949 irsp->ulpTimeout, disc, vport->num_disc_nodes);
1950 /* Check to see if link went down during discovery */
1951 if (lpfc_els_chk_latt(vport)) {
1952 spin_lock_irq(shost->host_lock);
1953 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1954 spin_unlock_irq(shost->host_lock);
1958 if (irsp->ulpStatus) {
1959 /* Check for retry */
1960 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1961 /* ELS command is being retried */
1963 spin_lock_irq(shost->host_lock);
1964 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1965 spin_unlock_irq(shost->host_lock);
1966 lpfc_set_disctmo(vport);
1971 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1972 "2755 ADISC failure DID:%06X Status:x%x/x%x\n",
1973 ndlp->nlp_DID, irsp->ulpStatus,
1974 irsp->un.ulpWord[4]);
1975 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1976 if (!lpfc_error_lost_link(irsp))
1977 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1978 NLP_EVT_CMPL_ADISC);
1980 /* Good status, call state machine */
1981 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1982 NLP_EVT_CMPL_ADISC);
1984 /* Check to see if there are more ADISCs to be sent */
1985 if (disc && vport->num_disc_nodes)
1986 lpfc_more_adisc(vport);
1988 lpfc_els_free_iocb(phba, cmdiocb);
1993 * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
1994 * @vport: pointer to a virtual N_Port data structure.
1995 * @ndlp: pointer to a node-list data structure.
1996 * @retry: number of retries to the command IOCB.
1998 * This routine issues an Address Discover (ADISC) for an @ndlp on a
1999 * @vport. It prepares the payload of the ADISC ELS command, updates the
2000 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
2001 * to issue the ADISC ELS command.
2003 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2004 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2005 * will be stored into the context1 field of the IOCB for the completion
2006 * callback function to the ADISC ELS command.
2009 * 0 - successfully issued adisc
2010 * 1 - failed to issue adisc
2013 lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2016 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2017 struct lpfc_hba *phba = vport->phba;
2020 struct lpfc_iocbq *elsiocb;
2024 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
2025 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2026 ndlp->nlp_DID, ELS_CMD_ADISC);
2030 icmd = &elsiocb->iocb;
2031 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2033 /* For ADISC request, remainder of payload is service parameters */
2034 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
2035 pcmd += sizeof(uint32_t);
2037 /* Fill in ADISC payload */
2038 ap = (ADISC *) pcmd;
2039 ap->hardAL_PA = phba->fc_pref_ALPA;
2040 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2041 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
2042 ap->DID = be32_to_cpu(vport->fc_myDID);
2044 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2045 "Issue ADISC: did:x%x",
2046 ndlp->nlp_DID, 0, 0);
2048 phba->fc_stat.elsXmitADISC++;
2049 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
2050 spin_lock_irq(shost->host_lock);
2051 ndlp->nlp_flag |= NLP_ADISC_SND;
2052 spin_unlock_irq(shost->host_lock);
2053 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2055 spin_lock_irq(shost->host_lock);
2056 ndlp->nlp_flag &= ~NLP_ADISC_SND;
2057 spin_unlock_irq(shost->host_lock);
2058 lpfc_els_free_iocb(phba, elsiocb);
2065 * lpfc_cmpl_els_logo - Completion callback function for logo
2066 * @phba: pointer to lpfc hba data structure.
2067 * @cmdiocb: pointer to lpfc command iocb data structure.
2068 * @rspiocb: pointer to lpfc response iocb data structure.
2070 * This routine is the completion function for issuing the ELS Logout (LOGO)
2071 * command. If no error status was reported from the LOGO response, the
2072 * state machine of the associated ndlp shall be invoked for transition with
2073 * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
2074 * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
2077 lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2078 struct lpfc_iocbq *rspiocb)
2080 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2081 struct lpfc_vport *vport = ndlp->vport;
2082 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2084 struct lpfc_sli *psli;
2087 /* we pass cmdiocb to state machine which needs rspiocb as well */
2088 cmdiocb->context_un.rsp_iocb = rspiocb;
2090 irsp = &(rspiocb->iocb);
2091 spin_lock_irq(shost->host_lock);
2092 ndlp->nlp_flag &= ~NLP_LOGO_SND;
2093 spin_unlock_irq(shost->host_lock);
2095 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2096 "LOGO cmpl: status:x%x/x%x did:x%x",
2097 irsp->ulpStatus, irsp->un.ulpWord[4],
2099 /* LOGO completes to NPort <nlp_DID> */
2100 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2101 "0105 LOGO completes to NPort x%x "
2102 "Data: x%x x%x x%x x%x\n",
2103 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2104 irsp->ulpTimeout, vport->num_disc_nodes);
2105 /* Check to see if link went down during discovery */
2106 if (lpfc_els_chk_latt(vport))
2109 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
2110 /* NLP_EVT_DEVICE_RM should unregister the RPI
2111 * which should abort all outstanding IOs.
2113 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2118 if (irsp->ulpStatus) {
2119 /* Check for retry */
2120 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
2121 /* ELS command is being retried */
2124 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2125 "2756 LOGO failure DID:%06X Status:x%x/x%x\n",
2126 ndlp->nlp_DID, irsp->ulpStatus,
2127 irsp->un.ulpWord[4]);
2128 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2129 if (lpfc_error_lost_link(irsp))
2132 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2135 /* Good status, call state machine.
2136 * This will unregister the rpi if needed.
2138 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2141 lpfc_els_free_iocb(phba, cmdiocb);
2146 * lpfc_issue_els_logo - Issue a logo to an node on a vport
2147 * @vport: pointer to a virtual N_Port data structure.
2148 * @ndlp: pointer to a node-list data structure.
2149 * @retry: number of retries to the command IOCB.
2151 * This routine constructs and issues an ELS Logout (LOGO) iocb command
2152 * to a remote node, referred by an @ndlp on a @vport. It constructs the
2153 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
2154 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
2156 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2157 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2158 * will be stored into the context1 field of the IOCB for the completion
2159 * callback function to the LOGO ELS command.
2162 * 0 - successfully issued logo
2163 * 1 - failed to issue logo
2166 lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2169 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2170 struct lpfc_hba *phba = vport->phba;
2172 struct lpfc_iocbq *elsiocb;
2177 spin_lock_irq(shost->host_lock);
2178 if (ndlp->nlp_flag & NLP_LOGO_SND) {
2179 spin_unlock_irq(shost->host_lock);
2182 spin_unlock_irq(shost->host_lock);
2184 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
2185 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2186 ndlp->nlp_DID, ELS_CMD_LOGO);
2190 icmd = &elsiocb->iocb;
2191 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2192 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
2193 pcmd += sizeof(uint32_t);
2195 /* Fill in LOGO payload */
2196 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
2197 pcmd += sizeof(uint32_t);
2198 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
2200 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2201 "Issue LOGO: did:x%x",
2202 ndlp->nlp_DID, 0, 0);
2204 phba->fc_stat.elsXmitLOGO++;
2205 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
2206 spin_lock_irq(shost->host_lock);
2207 ndlp->nlp_flag |= NLP_LOGO_SND;
2208 spin_unlock_irq(shost->host_lock);
2209 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
2211 if (rc == IOCB_ERROR) {
2212 spin_lock_irq(shost->host_lock);
2213 ndlp->nlp_flag &= ~NLP_LOGO_SND;
2214 spin_unlock_irq(shost->host_lock);
2215 lpfc_els_free_iocb(phba, elsiocb);
2222 * lpfc_cmpl_els_cmd - Completion callback function for generic els command
2223 * @phba: pointer to lpfc hba data structure.
2224 * @cmdiocb: pointer to lpfc command iocb data structure.
2225 * @rspiocb: pointer to lpfc response iocb data structure.
2227 * This routine is a generic completion callback function for ELS commands.
2228 * Specifically, it is the callback function which does not need to perform
2229 * any command specific operations. It is currently used by the ELS command
2230 * issuing routines for the ELS State Change Request (SCR),
2231 * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution
2232 * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than
2233 * certain debug loggings, this callback function simply invokes the
2234 * lpfc_els_chk_latt() routine to check whether link went down during the
2235 * discovery process.
2238 lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2239 struct lpfc_iocbq *rspiocb)
2241 struct lpfc_vport *vport = cmdiocb->vport;
2244 irsp = &rspiocb->iocb;
2246 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2247 "ELS cmd cmpl: status:x%x/x%x did:x%x",
2248 irsp->ulpStatus, irsp->un.ulpWord[4],
2249 irsp->un.elsreq64.remoteID);
2250 /* ELS cmd tag <ulpIoTag> completes */
2251 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2252 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
2253 irsp->ulpIoTag, irsp->ulpStatus,
2254 irsp->un.ulpWord[4], irsp->ulpTimeout);
2255 /* Check to see if link went down during discovery */
2256 lpfc_els_chk_latt(vport);
2257 lpfc_els_free_iocb(phba, cmdiocb);
2262 * lpfc_issue_els_scr - Issue a scr to an node on a vport
2263 * @vport: pointer to a host virtual N_Port data structure.
2264 * @nportid: N_Port identifier to the remote node.
2265 * @retry: number of retries to the command IOCB.
2267 * This routine issues a State Change Request (SCR) to a fabric node
2268 * on a @vport. The remote node @nportid is passed into the function. It
2269 * first search the @vport node list to find the matching ndlp. If no such
2270 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
2271 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
2272 * routine is invoked to send the SCR IOCB.
2274 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2275 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2276 * will be stored into the context1 field of the IOCB for the completion
2277 * callback function to the SCR ELS command.
2280 * 0 - Successfully issued scr command
2281 * 1 - Failed to issue scr command
2284 lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
2286 struct lpfc_hba *phba = vport->phba;
2288 struct lpfc_iocbq *elsiocb;
2289 struct lpfc_sli *psli;
2292 struct lpfc_nodelist *ndlp;
2295 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
2297 ndlp = lpfc_findnode_did(vport, nportid);
2299 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2302 lpfc_nlp_init(vport, ndlp, nportid);
2303 lpfc_enqueue_node(vport, ndlp);
2304 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2305 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2310 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2311 ndlp->nlp_DID, ELS_CMD_SCR);
2314 /* This will trigger the release of the node just
2321 icmd = &elsiocb->iocb;
2322 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2324 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
2325 pcmd += sizeof(uint32_t);
2327 /* For SCR, remainder of payload is SCR parameter page */
2328 memset(pcmd, 0, sizeof(SCR));
2329 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
2331 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2332 "Issue SCR: did:x%x",
2333 ndlp->nlp_DID, 0, 0);
2335 phba->fc_stat.elsXmitSCR++;
2336 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
2337 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2339 /* The additional lpfc_nlp_put will cause the following
2340 * lpfc_els_free_iocb routine to trigger the rlease of
2344 lpfc_els_free_iocb(phba, elsiocb);
2347 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2348 * trigger the release of node.
2355 * lpfc_issue_els_farpr - Issue a farp to an node on a vport
2356 * @vport: pointer to a host virtual N_Port data structure.
2357 * @nportid: N_Port identifier to the remote node.
2358 * @retry: number of retries to the command IOCB.
2360 * This routine issues a Fibre Channel Address Resolution Response
2361 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
2362 * is passed into the function. It first search the @vport node list to find
2363 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
2364 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
2365 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
2367 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2368 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2369 * will be stored into the context1 field of the IOCB for the completion
2370 * callback function to the PARPR ELS command.
2373 * 0 - Successfully issued farpr command
2374 * 1 - Failed to issue farpr command
2377 lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
2379 struct lpfc_hba *phba = vport->phba;
2381 struct lpfc_iocbq *elsiocb;
2382 struct lpfc_sli *psli;
2387 struct lpfc_nodelist *ondlp;
2388 struct lpfc_nodelist *ndlp;
2391 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
2393 ndlp = lpfc_findnode_did(vport, nportid);
2395 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2398 lpfc_nlp_init(vport, ndlp, nportid);
2399 lpfc_enqueue_node(vport, ndlp);
2400 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2401 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2406 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2407 ndlp->nlp_DID, ELS_CMD_RNID);
2409 /* This will trigger the release of the node just
2416 icmd = &elsiocb->iocb;
2417 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2419 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
2420 pcmd += sizeof(uint32_t);
2422 /* Fill in FARPR payload */
2423 fp = (FARP *) (pcmd);
2424 memset(fp, 0, sizeof(FARP));
2425 lp = (uint32_t *) pcmd;
2426 *lp++ = be32_to_cpu(nportid);
2427 *lp++ = be32_to_cpu(vport->fc_myDID);
2429 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
2431 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
2432 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
2433 ondlp = lpfc_findnode_did(vport, nportid);
2434 if (ondlp && NLP_CHK_NODE_ACT(ondlp)) {
2435 memcpy(&fp->OportName, &ondlp->nlp_portname,
2436 sizeof(struct lpfc_name));
2437 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
2438 sizeof(struct lpfc_name));
2441 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2442 "Issue FARPR: did:x%x",
2443 ndlp->nlp_DID, 0, 0);
2445 phba->fc_stat.elsXmitFARPR++;
2446 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
2447 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2449 /* The additional lpfc_nlp_put will cause the following
2450 * lpfc_els_free_iocb routine to trigger the release of
2454 lpfc_els_free_iocb(phba, elsiocb);
2457 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2458 * trigger the release of the node.
2465 * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
2466 * @vport: pointer to a host virtual N_Port data structure.
2467 * @nlp: pointer to a node-list data structure.
2469 * This routine cancels the timer with a delayed IOCB-command retry for
2470 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
2471 * removes the ELS retry event if it presents. In addition, if the
2472 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
2473 * commands are sent for the @vport's nodes that require issuing discovery
2477 lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
2479 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2480 struct lpfc_work_evt *evtp;
2482 if (!(nlp->nlp_flag & NLP_DELAY_TMO))
2484 spin_lock_irq(shost->host_lock);
2485 nlp->nlp_flag &= ~NLP_DELAY_TMO;
2486 spin_unlock_irq(shost->host_lock);
2487 del_timer_sync(&nlp->nlp_delayfunc);
2488 nlp->nlp_last_elscmd = 0;
2489 if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
2490 list_del_init(&nlp->els_retry_evt.evt_listp);
2491 /* Decrement nlp reference count held for the delayed retry */
2492 evtp = &nlp->els_retry_evt;
2493 lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
2495 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
2496 spin_lock_irq(shost->host_lock);
2497 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
2498 spin_unlock_irq(shost->host_lock);
2499 if (vport->num_disc_nodes) {
2500 if (vport->port_state < LPFC_VPORT_READY) {
2501 /* Check if there are more ADISCs to be sent */
2502 lpfc_more_adisc(vport);
2504 /* Check if there are more PLOGIs to be sent */
2505 lpfc_more_plogi(vport);
2506 if (vport->num_disc_nodes == 0) {
2507 spin_lock_irq(shost->host_lock);
2508 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2509 spin_unlock_irq(shost->host_lock);
2510 lpfc_can_disctmo(vport);
2511 lpfc_end_rscn(vport);
2520 * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
2521 * @ptr: holder for the pointer to the timer function associated data (ndlp).
2523 * This routine is invoked by the ndlp delayed-function timer to check
2524 * whether there is any pending ELS retry event(s) with the node. If not, it
2525 * simply returns. Otherwise, if there is at least one ELS delayed event, it
2526 * adds the delayed events to the HBA work list and invokes the
2527 * lpfc_worker_wake_up() routine to wake up worker thread to process the
2528 * event. Note that lpfc_nlp_get() is called before posting the event to
2529 * the work list to hold reference count of ndlp so that it guarantees the
2530 * reference to ndlp will still be available when the worker thread gets
2531 * to the event associated with the ndlp.
2534 lpfc_els_retry_delay(unsigned long ptr)
2536 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr;
2537 struct lpfc_vport *vport = ndlp->vport;
2538 struct lpfc_hba *phba = vport->phba;
2539 unsigned long flags;
2540 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
2542 spin_lock_irqsave(&phba->hbalock, flags);
2543 if (!list_empty(&evtp->evt_listp)) {
2544 spin_unlock_irqrestore(&phba->hbalock, flags);
2548 /* We need to hold the node by incrementing the reference
2549 * count until the queued work is done
2551 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
2552 if (evtp->evt_arg1) {
2553 evtp->evt = LPFC_EVT_ELS_RETRY;
2554 list_add_tail(&evtp->evt_listp, &phba->work_list);
2555 lpfc_worker_wake_up(phba);
2557 spin_unlock_irqrestore(&phba->hbalock, flags);
2562 * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
2563 * @ndlp: pointer to a node-list data structure.
2565 * This routine is the worker-thread handler for processing the @ndlp delayed
2566 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
2567 * the last ELS command from the associated ndlp and invokes the proper ELS
2568 * function according to the delayed ELS command to retry the command.
2571 lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
2573 struct lpfc_vport *vport = ndlp->vport;
2574 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2575 uint32_t cmd, did, retry;
2577 spin_lock_irq(shost->host_lock);
2578 did = ndlp->nlp_DID;
2579 cmd = ndlp->nlp_last_elscmd;
2580 ndlp->nlp_last_elscmd = 0;
2582 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
2583 spin_unlock_irq(shost->host_lock);
2587 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
2588 spin_unlock_irq(shost->host_lock);
2590 * If a discovery event readded nlp_delayfunc after timer
2591 * firing and before processing the timer, cancel the
2594 del_timer_sync(&ndlp->nlp_delayfunc);
2595 retry = ndlp->nlp_retry;
2596 ndlp->nlp_retry = 0;
2600 lpfc_issue_els_flogi(vport, ndlp, retry);
2603 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
2604 ndlp->nlp_prev_state = ndlp->nlp_state;
2605 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2609 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
2610 ndlp->nlp_prev_state = ndlp->nlp_state;
2611 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2615 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
2616 ndlp->nlp_prev_state = ndlp->nlp_state;
2617 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
2621 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
2622 ndlp->nlp_prev_state = ndlp->nlp_state;
2623 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2627 lpfc_issue_els_fdisc(vport, ndlp, retry);
2634 * lpfc_els_retry - Make retry decision on an els command iocb
2635 * @phba: pointer to lpfc hba data structure.
2636 * @cmdiocb: pointer to lpfc command iocb data structure.
2637 * @rspiocb: pointer to lpfc response iocb data structure.
2639 * This routine makes a retry decision on an ELS command IOCB, which has
2640 * failed. The following ELS IOCBs use this function for retrying the command
2641 * when previously issued command responsed with error status: FLOGI, PLOGI,
2642 * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
2643 * returned error status, it makes the decision whether a retry shall be
2644 * issued for the command, and whether a retry shall be made immediately or
2645 * delayed. In the former case, the corresponding ELS command issuing-function
2646 * is called to retry the command. In the later case, the ELS command shall
2647 * be posted to the ndlp delayed event and delayed function timer set to the
2648 * ndlp for the delayed command issusing.
2651 * 0 - No retry of els command is made
2652 * 1 - Immediate or delayed retry of els command is made
2655 lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2656 struct lpfc_iocbq *rspiocb)
2658 struct lpfc_vport *vport = cmdiocb->vport;
2659 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2660 IOCB_t *irsp = &rspiocb->iocb;
2661 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2662 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
2665 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
2671 /* Note: context2 may be 0 for internal driver abort
2672 * of delays ELS command.
2675 if (pcmd && pcmd->virt) {
2676 elscmd = (uint32_t *) (pcmd->virt);
2680 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
2681 did = ndlp->nlp_DID;
2683 /* We should only hit this case for retrying PLOGI */
2684 did = irsp->un.elsreq64.remoteID;
2685 ndlp = lpfc_findnode_did(vport, did);
2686 if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp))
2687 && (cmd != ELS_CMD_PLOGI))
2691 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2692 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
2693 *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
2695 switch (irsp->ulpStatus) {
2696 case IOSTAT_FCP_RSP_ERROR:
2697 case IOSTAT_REMOTE_STOP:
2700 case IOSTAT_LOCAL_REJECT:
2701 switch ((irsp->un.ulpWord[4] & 0xff)) {
2702 case IOERR_LOOP_OPEN_FAILURE:
2703 if (cmd == ELS_CMD_FLOGI) {
2704 if (PCI_DEVICE_ID_HORNET ==
2705 phba->pcidev->device) {
2706 phba->fc_topology = TOPOLOGY_LOOP;
2707 phba->pport->fc_myDID = 0;
2708 phba->alpa_map[0] = 0;
2709 phba->alpa_map[1] = 0;
2712 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
2717 case IOERR_ILLEGAL_COMMAND:
2718 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2719 "0124 Retry illegal cmd x%x "
2720 "retry:x%x delay:x%x\n",
2721 cmd, cmdiocb->retry, delay);
2723 /* All command's retry policy */
2725 if (cmdiocb->retry > 2)
2729 case IOERR_NO_RESOURCES:
2730 logerr = 1; /* HBA out of resources */
2732 if (cmdiocb->retry > 100)
2737 case IOERR_ILLEGAL_FRAME:
2742 case IOERR_SEQUENCE_TIMEOUT:
2743 case IOERR_INVALID_RPI:
2749 case IOSTAT_NPORT_RJT:
2750 case IOSTAT_FABRIC_RJT:
2751 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
2757 case IOSTAT_NPORT_BSY:
2758 case IOSTAT_FABRIC_BSY:
2759 logerr = 1; /* Fabric / Remote NPort out of resources */
2764 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
2765 /* Added for Vendor specifc support
2766 * Just keep retrying for these Rsn / Exp codes
2768 switch (stat.un.b.lsRjtRsnCode) {
2769 case LSRJT_UNABLE_TPC:
2770 if (stat.un.b.lsRjtRsnCodeExp ==
2771 LSEXP_CMD_IN_PROGRESS) {
2772 if (cmd == ELS_CMD_PLOGI) {
2779 if (stat.un.b.lsRjtRsnCodeExp ==
2780 LSEXP_CANT_GIVE_DATA) {
2781 if (cmd == ELS_CMD_PLOGI) {
2788 if (cmd == ELS_CMD_PLOGI) {
2790 maxretry = lpfc_max_els_tries + 1;
2794 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2795 (cmd == ELS_CMD_FDISC) &&
2796 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
2797 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2798 "0125 FDISC Failed (x%x). "
2799 "Fabric out of resources\n",
2800 stat.un.lsRjtError);
2801 lpfc_vport_set_state(vport,
2802 FC_VPORT_NO_FABRIC_RSCS);
2806 case LSRJT_LOGICAL_BSY:
2807 if ((cmd == ELS_CMD_PLOGI) ||
2808 (cmd == ELS_CMD_PRLI)) {
2811 } else if (cmd == ELS_CMD_FDISC) {
2812 /* FDISC retry policy */
2814 if (cmdiocb->retry >= 32)
2820 case LSRJT_LOGICAL_ERR:
2821 /* There are some cases where switches return this
2822 * error when they are not ready and should be returning
2823 * Logical Busy. We should delay every time.
2825 if (cmd == ELS_CMD_FDISC &&
2826 stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
2832 case LSRJT_PROTOCOL_ERR:
2833 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2834 (cmd == ELS_CMD_FDISC) &&
2835 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
2836 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
2838 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2839 "0122 FDISC Failed (x%x). "
2840 "Fabric Detected Bad WWN\n",
2841 stat.un.lsRjtError);
2842 lpfc_vport_set_state(vport,
2843 FC_VPORT_FABRIC_REJ_WWN);
2849 case IOSTAT_INTERMED_RSP:
2857 if (did == FDMI_DID)
2860 if (((cmd == ELS_CMD_FLOGI) || (cmd == ELS_CMD_FDISC)) &&
2861 (phba->fc_topology != TOPOLOGY_LOOP) &&
2862 !lpfc_error_lost_link(irsp)) {
2863 /* FLOGI retry policy */
2867 if (cmdiocb->retry >= 100)
2869 else if (cmdiocb->retry >= 32)
2874 if (maxretry && (cmdiocb->retry >= maxretry)) {
2875 phba->fc_stat.elsRetryExceeded++;
2879 if ((vport->load_flag & FC_UNLOADING) != 0)
2884 /* Retry ELS command <elsCmd> to remote NPORT <did> */
2885 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2886 "0107 Retry ELS command x%x to remote "
2887 "NPORT x%x Data: x%x x%x\n",
2888 cmd, did, cmdiocb->retry, delay);
2890 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
2891 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
2892 ((irsp->un.ulpWord[4] & 0xff) != IOERR_NO_RESOURCES))) {
2893 /* Don't reset timer for no resources */
2895 /* If discovery / RSCN timer is running, reset it */
2896 if (timer_pending(&vport->fc_disctmo) ||
2897 (vport->fc_flag & FC_RSCN_MODE))
2898 lpfc_set_disctmo(vport);
2901 phba->fc_stat.elsXmitRetry++;
2902 if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) {
2903 phba->fc_stat.elsDelayRetry++;
2904 ndlp->nlp_retry = cmdiocb->retry;
2906 /* delay is specified in milliseconds */
2907 mod_timer(&ndlp->nlp_delayfunc,
2908 jiffies + msecs_to_jiffies(delay));
2909 spin_lock_irq(shost->host_lock);
2910 ndlp->nlp_flag |= NLP_DELAY_TMO;
2911 spin_unlock_irq(shost->host_lock);
2913 ndlp->nlp_prev_state = ndlp->nlp_state;
2914 if (cmd == ELS_CMD_PRLI)
2915 lpfc_nlp_set_state(vport, ndlp,
2916 NLP_STE_REG_LOGIN_ISSUE);
2918 lpfc_nlp_set_state(vport, ndlp,
2920 ndlp->nlp_last_elscmd = cmd;
2926 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
2929 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
2932 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
2933 ndlp->nlp_prev_state = ndlp->nlp_state;
2934 lpfc_nlp_set_state(vport, ndlp,
2935 NLP_STE_PLOGI_ISSUE);
2937 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
2940 ndlp->nlp_prev_state = ndlp->nlp_state;
2941 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2942 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
2945 ndlp->nlp_prev_state = ndlp->nlp_state;
2946 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
2947 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
2950 ndlp->nlp_prev_state = ndlp->nlp_state;
2951 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2952 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
2956 /* No retry ELS command <elsCmd> to remote NPORT <did> */
2958 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2959 "0137 No retry ELS command x%x to remote "
2960 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
2961 cmd, did, irsp->ulpStatus,
2962 irsp->un.ulpWord[4]);
2965 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2966 "0108 No retry ELS command x%x to remote "
2967 "NPORT x%x Retried:%d Error:x%x/%x\n",
2968 cmd, did, cmdiocb->retry, irsp->ulpStatus,
2969 irsp->un.ulpWord[4]);
2975 * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
2976 * @phba: pointer to lpfc hba data structure.
2977 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
2979 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
2980 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
2981 * checks to see whether there is a lpfc DMA buffer associated with the
2982 * response of the command IOCB. If so, it will be released before releasing
2983 * the lpfc DMA buffer associated with the IOCB itself.
2986 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
2989 lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
2991 struct lpfc_dmabuf *buf_ptr;
2993 /* Free the response before processing the command. */
2994 if (!list_empty(&buf_ptr1->list)) {
2995 list_remove_head(&buf_ptr1->list, buf_ptr,
2998 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3001 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
3007 * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
3008 * @phba: pointer to lpfc hba data structure.
3009 * @buf_ptr: pointer to the lpfc dma buffer data structure.
3011 * This routine releases the lpfc Direct Memory Access (DMA) buffer
3012 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
3016 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3019 lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
3021 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3027 * lpfc_els_free_iocb - Free a command iocb and its associated resources
3028 * @phba: pointer to lpfc hba data structure.
3029 * @elsiocb: pointer to lpfc els command iocb data structure.
3031 * This routine frees a command IOCB and its associated resources. The
3032 * command IOCB data structure contains the reference to various associated
3033 * resources, these fields must be set to NULL if the associated reference
3035 * context1 - reference to ndlp
3036 * context2 - reference to cmd
3037 * context2->next - reference to rsp
3038 * context3 - reference to bpl
3040 * It first properly decrements the reference count held on ndlp for the
3041 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
3042 * set, it invokes the lpfc_els_free_data() routine to release the Direct
3043 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
3044 * adds the DMA buffer the @phba data structure for the delayed release.
3045 * If reference to the Buffer Pointer List (BPL) is present, the
3046 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
3047 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
3048 * invoked to release the IOCB data structure back to @phba IOCBQ list.
3051 * 0 - Success (currently, always return 0)
3054 lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
3056 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
3057 struct lpfc_nodelist *ndlp;
3059 ndlp = (struct lpfc_nodelist *)elsiocb->context1;
3061 if (ndlp->nlp_flag & NLP_DEFER_RM) {
3064 /* If the ndlp is not being used by another discovery
3067 if (!lpfc_nlp_not_used(ndlp)) {
3068 /* If ndlp is being used by another discovery
3069 * thread, just clear NLP_DEFER_RM
3071 ndlp->nlp_flag &= ~NLP_DEFER_RM;
3076 elsiocb->context1 = NULL;
3078 /* context2 = cmd, context2->next = rsp, context3 = bpl */
3079 if (elsiocb->context2) {
3080 if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
3081 /* Firmware could still be in progress of DMAing
3082 * payload, so don't free data buffer till after
3085 elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
3086 buf_ptr = elsiocb->context2;
3087 elsiocb->context2 = NULL;
3090 spin_lock_irq(&phba->hbalock);
3091 if (!list_empty(&buf_ptr->list)) {
3092 list_remove_head(&buf_ptr->list,
3093 buf_ptr1, struct lpfc_dmabuf,
3095 INIT_LIST_HEAD(&buf_ptr1->list);
3096 list_add_tail(&buf_ptr1->list,
3100 INIT_LIST_HEAD(&buf_ptr->list);
3101 list_add_tail(&buf_ptr->list, &phba->elsbuf);
3103 spin_unlock_irq(&phba->hbalock);
3106 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
3107 lpfc_els_free_data(phba, buf_ptr1);
3111 if (elsiocb->context3) {
3112 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
3113 lpfc_els_free_bpl(phba, buf_ptr);
3115 lpfc_sli_release_iocbq(phba, elsiocb);
3120 * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
3121 * @phba: pointer to lpfc hba data structure.
3122 * @cmdiocb: pointer to lpfc command iocb data structure.
3123 * @rspiocb: pointer to lpfc response iocb data structure.
3125 * This routine is the completion callback function to the Logout (LOGO)
3126 * Accept (ACC) Response ELS command. This routine is invoked to indicate
3127 * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
3128 * release the ndlp if it has the last reference remaining (reference count
3129 * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
3130 * field to NULL to inform the following lpfc_els_free_iocb() routine no
3131 * ndlp reference count needs to be decremented. Otherwise, the ndlp
3132 * reference use-count shall be decremented by the lpfc_els_free_iocb()
3133 * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
3134 * IOCB data structure.
3137 lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3138 struct lpfc_iocbq *rspiocb)
3140 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3141 struct lpfc_vport *vport = cmdiocb->vport;
3144 irsp = &rspiocb->iocb;
3145 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3146 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
3147 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
3148 /* ACC to LOGO completes to NPort <nlp_DID> */
3149 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3150 "0109 ACC to LOGO completes to NPort x%x "
3151 "Data: x%x x%x x%x\n",
3152 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3155 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
3156 /* NPort Recovery mode or node is just allocated */
3157 if (!lpfc_nlp_not_used(ndlp)) {
3158 /* If the ndlp is being used by another discovery
3159 * thread, just unregister the RPI.
3161 lpfc_unreg_rpi(vport, ndlp);
3163 /* Indicate the node has already released, should
3164 * not reference to it from within lpfc_els_free_iocb.
3166 cmdiocb->context1 = NULL;
3169 lpfc_els_free_iocb(phba, cmdiocb);
3174 * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
3175 * @phba: pointer to lpfc hba data structure.
3176 * @pmb: pointer to the driver internal queue element for mailbox command.
3178 * This routine is the completion callback function for unregister default
3179 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
3180 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
3181 * decrements the ndlp reference count held for this completion callback
3182 * function. After that, it invokes the lpfc_nlp_not_used() to check
3183 * whether there is only one reference left on the ndlp. If so, it will
3184 * perform one more decrement and trigger the release of the ndlp.
3187 lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3189 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
3190 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
3193 * This routine is used to register and unregister in previous SLI
3196 if ((pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) &&
3197 (phba->sli_rev == LPFC_SLI_REV4))
3198 lpfc_sli4_free_rpi(phba, pmb->u.mb.un.varUnregLogin.rpi);
3200 pmb->context1 = NULL;
3201 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3203 mempool_free(pmb, phba->mbox_mem_pool);
3204 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
3206 /* This is the end of the default RPI cleanup logic for this
3207 * ndlp. If no other discovery threads are using this ndlp.
3208 * we should free all resources associated with it.
3210 lpfc_nlp_not_used(ndlp);
3217 * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
3218 * @phba: pointer to lpfc hba data structure.
3219 * @cmdiocb: pointer to lpfc command iocb data structure.
3220 * @rspiocb: pointer to lpfc response iocb data structure.
3222 * This routine is the completion callback function for ELS Response IOCB
3223 * command. In normal case, this callback function just properly sets the
3224 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
3225 * field in the command IOCB is not NULL, the referred mailbox command will
3226 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
3227 * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
3228 * link down event occurred during the discovery, the lpfc_nlp_not_used()
3229 * routine shall be invoked trying to release the ndlp if no other threads
3230 * are currently referring it.
3233 lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3234 struct lpfc_iocbq *rspiocb)
3236 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3237 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
3238 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
3241 LPFC_MBOXQ_t *mbox = NULL;
3242 struct lpfc_dmabuf *mp = NULL;
3243 uint32_t ls_rjt = 0;
3245 irsp = &rspiocb->iocb;
3247 if (cmdiocb->context_un.mbox)
3248 mbox = cmdiocb->context_un.mbox;
3250 /* First determine if this is a LS_RJT cmpl. Note, this callback
3251 * function can have cmdiocb->contest1 (ndlp) field set to NULL.
3253 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
3254 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3255 (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) {
3256 /* A LS_RJT associated with Default RPI cleanup has its own
3257 * separate code path.
3259 if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
3263 /* Check to see if link went down during discovery */
3264 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) {
3266 mp = (struct lpfc_dmabuf *) mbox->context1;
3268 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3271 mempool_free(mbox, phba->mbox_mem_pool);
3273 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3274 (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
3275 if (lpfc_nlp_not_used(ndlp)) {
3277 /* Indicate the node has already released,
3278 * should not reference to it from within
3279 * the routine lpfc_els_free_iocb.
3281 cmdiocb->context1 = NULL;
3286 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3287 "ELS rsp cmpl: status:x%x/x%x did:x%x",
3288 irsp->ulpStatus, irsp->un.ulpWord[4],
3289 cmdiocb->iocb.un.elsreq64.remoteID);
3290 /* ELS response tag <ulpIoTag> completes */
3291 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3292 "0110 ELS response tag x%x completes "
3293 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
3294 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
3295 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
3296 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3299 if ((rspiocb->iocb.ulpStatus == 0)
3300 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
3301 lpfc_unreg_rpi(vport, ndlp);
3302 /* Increment reference count to ndlp to hold the
3303 * reference to ndlp for the callback function.
3305 mbox->context2 = lpfc_nlp_get(ndlp);
3306 mbox->vport = vport;
3307 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
3308 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
3309 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
3312 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
3313 ndlp->nlp_prev_state = ndlp->nlp_state;
3314 lpfc_nlp_set_state(vport, ndlp,
3315 NLP_STE_REG_LOGIN_ISSUE);
3317 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
3318 != MBX_NOT_FINISHED)
3321 /* Decrement the ndlp reference count we
3322 * set for this failed mailbox command.
3326 /* ELS rsp: Cannot issue reg_login for <NPortid> */
3327 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3328 "0138 ELS rsp: Cannot issue reg_login for x%x "
3329 "Data: x%x x%x x%x\n",
3330 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3333 if (lpfc_nlp_not_used(ndlp)) {
3335 /* Indicate node has already been released,
3336 * should not reference to it from within
3337 * the routine lpfc_els_free_iocb.
3339 cmdiocb->context1 = NULL;
3342 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
3343 if (!lpfc_error_lost_link(irsp) &&
3344 ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
3345 if (lpfc_nlp_not_used(ndlp)) {
3347 /* Indicate node has already been
3348 * released, should not reference
3349 * to it from within the routine
3350 * lpfc_els_free_iocb.
3352 cmdiocb->context1 = NULL;
3356 mp = (struct lpfc_dmabuf *) mbox->context1;
3358 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3361 mempool_free(mbox, phba->mbox_mem_pool);
3364 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
3365 spin_lock_irq(shost->host_lock);
3366 ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI);
3367 spin_unlock_irq(shost->host_lock);
3369 /* If the node is not being used by another discovery thread,
3370 * and we are sending a reject, we are done with it.
3371 * Release driver reference count here and free associated
3375 if (lpfc_nlp_not_used(ndlp))
3376 /* Indicate node has already been released,
3377 * should not reference to it from within
3378 * the routine lpfc_els_free_iocb.
3380 cmdiocb->context1 = NULL;
3383 lpfc_els_free_iocb(phba, cmdiocb);
3388 * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
3389 * @vport: pointer to a host virtual N_Port data structure.
3390 * @flag: the els command code to be accepted.
3391 * @oldiocb: pointer to the original lpfc command iocb data structure.
3392 * @ndlp: pointer to a node-list data structure.
3393 * @mbox: pointer to the driver internal queue element for mailbox command.
3395 * This routine prepares and issues an Accept (ACC) response IOCB
3396 * command. It uses the @flag to properly set up the IOCB field for the
3397 * specific ACC response command to be issued and invokes the
3398 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
3399 * @mbox pointer is passed in, it will be put into the context_un.mbox
3400 * field of the IOCB for the completion callback function to issue the
3401 * mailbox command to the HBA later when callback is invoked.
3403 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3404 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3405 * will be stored into the context1 field of the IOCB for the completion
3406 * callback function to the corresponding response ELS IOCB command.
3409 * 0 - Successfully issued acc response
3410 * 1 - Failed to issue acc response
3413 lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
3414 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
3417 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3418 struct lpfc_hba *phba = vport->phba;
3421 struct lpfc_iocbq *elsiocb;
3422 struct lpfc_sli *psli;
3426 ELS_PKT *els_pkt_ptr;
3429 oldcmd = &oldiocb->iocb;
3433 cmdsize = sizeof(uint32_t);
3434 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3435 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
3437 spin_lock_irq(shost->host_lock);
3438 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
3439 spin_unlock_irq(shost->host_lock);
3443 icmd = &elsiocb->iocb;
3444 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3445 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3446 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
3447 pcmd += sizeof(uint32_t);
3449 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3450 "Issue ACC: did:x%x flg:x%x",
3451 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3454 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
3455 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3456 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
3460 icmd = &elsiocb->iocb;
3461 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3462 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3465 elsiocb->context_un.mbox = mbox;
3467 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
3468 pcmd += sizeof(uint32_t);
3469 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
3471 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3472 "Issue ACC PLOGI: did:x%x flg:x%x",
3473 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3476 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
3477 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3478 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
3482 icmd = &elsiocb->iocb;
3483 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3484 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3486 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
3487 sizeof(uint32_t) + sizeof(PRLO));
3488 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
3489 els_pkt_ptr = (ELS_PKT *) pcmd;
3490 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
3492 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3493 "Issue ACC PRLO: did:x%x flg:x%x",
3494 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3499 /* Xmit ELS ACC response tag <ulpIoTag> */
3500 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3501 "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
3502 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n",
3503 elsiocb->iotag, elsiocb->iocb.ulpContext,
3504 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3506 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
3507 spin_lock_irq(shost->host_lock);
3508 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
3509 spin_unlock_irq(shost->host_lock);
3510 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
3512 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
3515 phba->fc_stat.elsXmitACC++;
3516 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
3517 if (rc == IOCB_ERROR) {
3518 lpfc_els_free_iocb(phba, elsiocb);
3525 * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command
3526 * @vport: pointer to a virtual N_Port data structure.
3528 * @oldiocb: pointer to the original lpfc command iocb data structure.
3529 * @ndlp: pointer to a node-list data structure.
3530 * @mbox: pointer to the driver internal queue element for mailbox command.
3532 * This routine prepares and issue an Reject (RJT) response IOCB
3533 * command. If a @mbox pointer is passed in, it will be put into the
3534 * context_un.mbox field of the IOCB for the completion callback function
3535 * to issue to the HBA later.
3537 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3538 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3539 * will be stored into the context1 field of the IOCB for the completion
3540 * callback function to the reject response ELS IOCB command.
3543 * 0 - Successfully issued reject response
3544 * 1 - Failed to issue reject response
3547 lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
3548 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
3551 struct lpfc_hba *phba = vport->phba;
3554 struct lpfc_iocbq *elsiocb;
3555 struct lpfc_sli *psli;
3561 cmdsize = 2 * sizeof(uint32_t);
3562 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3563 ndlp->nlp_DID, ELS_CMD_LS_RJT);
3567 icmd = &elsiocb->iocb;
3568 oldcmd = &oldiocb->iocb;
3569 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3570 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3572 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
3573 pcmd += sizeof(uint32_t);
3574 *((uint32_t *) (pcmd)) = rejectError;
3577 elsiocb->context_un.mbox = mbox;
3579 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
3580 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3581 "0129 Xmit ELS RJT x%x response tag x%x "
3582 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
3584 rejectError, elsiocb->iotag,
3585 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
3586 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
3587 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3588 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
3589 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
3591 phba->fc_stat.elsXmitLSRJT++;
3592 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
3593 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
3595 if (rc == IOCB_ERROR) {
3596 lpfc_els_free_iocb(phba, elsiocb);
3603 * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
3604 * @vport: pointer to a virtual N_Port data structure.
3605 * @oldiocb: pointer to the original lpfc command iocb data structure.
3606 * @ndlp: pointer to a node-list data structure.
3608 * This routine prepares and issues an Accept (ACC) response to Address
3609 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
3610 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3612 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3613 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3614 * will be stored into the context1 field of the IOCB for the completion
3615 * callback function to the ADISC Accept response ELS IOCB command.
3618 * 0 - Successfully issued acc adisc response
3619 * 1 - Failed to issue adisc acc response
3622 lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
3623 struct lpfc_nodelist *ndlp)
3625 struct lpfc_hba *phba = vport->phba;
3627 IOCB_t *icmd, *oldcmd;
3628 struct lpfc_iocbq *elsiocb;
3633 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
3634 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3635 ndlp->nlp_DID, ELS_CMD_ACC);
3639 icmd = &elsiocb->iocb;
3640 oldcmd = &oldiocb->iocb;
3641 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3643 /* Xmit ADISC ACC response tag <ulpIoTag> */
3644 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3645 "0130 Xmit ADISC ACC response iotag x%x xri: "
3646 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
3647 elsiocb->iotag, elsiocb->iocb.ulpContext,
3648 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3650 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3652 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
3653 pcmd += sizeof(uint32_t);
3655 ap = (ADISC *) (pcmd);
3656 ap->hardAL_PA = phba->fc_pref_ALPA;
3657 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
3658 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
3659 ap->DID = be32_to_cpu(vport->fc_myDID);
3661 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3662 "Issue ACC ADISC: did:x%x flg:x%x",
3663 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3665 phba->fc_stat.elsXmitACC++;
3666 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
3667 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
3668 if (rc == IOCB_ERROR) {
3669 lpfc_els_free_iocb(phba, elsiocb);
3676 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
3677 * @vport: pointer to a virtual N_Port data structure.
3678 * @oldiocb: pointer to the original lpfc command iocb data structure.
3679 * @ndlp: pointer to a node-list data structure.
3681 * This routine prepares and issues an Accept (ACC) response to Process
3682 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
3683 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3685 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3686 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3687 * will be stored into the context1 field of the IOCB for the completion
3688 * callback function to the PRLI Accept response ELS IOCB command.
3691 * 0 - Successfully issued acc prli response
3692 * 1 - Failed to issue acc prli response
3695 lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
3696 struct lpfc_nodelist *ndlp)
3698 struct lpfc_hba *phba = vport->phba;
3703 struct lpfc_iocbq *elsiocb;
3704 struct lpfc_sli *psli;
3711 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
3712 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3713 ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)));
3717 icmd = &elsiocb->iocb;
3718 oldcmd = &oldiocb->iocb;
3719 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3720 /* Xmit PRLI ACC response tag <ulpIoTag> */
3721 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3722 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
3723 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
3724 elsiocb->iotag, elsiocb->iocb.ulpContext,
3725 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3727 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3729 *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
3730 pcmd += sizeof(uint32_t);
3732 /* For PRLI, remainder of payload is PRLI parameter page */
3733 memset(pcmd, 0, sizeof(PRLI));
3735 npr = (PRLI *) pcmd;
3738 * If the remote port is a target and our firmware version is 3.20 or
3739 * later, set the following bits for FC-TAPE support.
3741 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
3742 (vpd->rev.feaLevelHigh >= 0x02)) {
3743 npr->ConfmComplAllowed = 1;
3745 npr->TaskRetryIdReq = 1;
3748 npr->acceptRspCode = PRLI_REQ_EXECUTED;
3749 npr->estabImagePair = 1;
3750 npr->readXferRdyDis = 1;
3751 npr->ConfmComplAllowed = 1;
3753 npr->prliType = PRLI_FCP_TYPE;
3754 npr->initiatorFunc = 1;
3756 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3757 "Issue ACC PRLI: did:x%x flg:x%x",
3758 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3760 phba->fc_stat.elsXmitACC++;
3761 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
3763 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
3764 if (rc == IOCB_ERROR) {
3765 lpfc_els_free_iocb(phba, elsiocb);
3772 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
3773 * @vport: pointer to a virtual N_Port data structure.
3774 * @format: rnid command format.
3775 * @oldiocb: pointer to the original lpfc command iocb data structure.
3776 * @ndlp: pointer to a node-list data structure.
3778 * This routine issues a Request Node Identification Data (RNID) Accept
3779 * (ACC) response. It constructs the RNID ACC response command according to
3780 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
3781 * issue the response. Note that this command does not need to hold the ndlp
3782 * reference count for the callback. So, the ndlp reference count taken by
3783 * the lpfc_prep_els_iocb() routine is put back and the context1 field of
3784 * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
3785 * there is no ndlp reference available.
3787 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3788 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3789 * will be stored into the context1 field of the IOCB for the completion
3790 * callback function. However, for the RNID Accept Response ELS command,
3791 * this is undone later by this routine after the IOCB is allocated.
3794 * 0 - Successfully issued acc rnid response
3795 * 1 - Failed to issue acc rnid response
3798 lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
3799 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
3801 struct lpfc_hba *phba = vport->phba;
3803 IOCB_t *icmd, *oldcmd;
3804 struct lpfc_iocbq *elsiocb;
3805 struct lpfc_sli *psli;
3811 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
3812 + (2 * sizeof(struct lpfc_name));
3814 cmdsize += sizeof(RNID_TOP_DISC);
3816 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3817 ndlp->nlp_DID, ELS_CMD_ACC);
3821 icmd = &elsiocb->iocb;
3822 oldcmd = &oldiocb->iocb;
3823 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3824 /* Xmit RNID ACC response tag <ulpIoTag> */
3825 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3826 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
3827 elsiocb->iotag, elsiocb->iocb.ulpContext);
3828 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3829 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
3830 pcmd += sizeof(uint32_t);
3832 memset(pcmd, 0, sizeof(RNID));
3833 rn = (RNID *) (pcmd);
3834 rn->Format = format;
3835 rn->CommonLen = (2 * sizeof(struct lpfc_name));
3836 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
3837 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
3840 rn->SpecificLen = 0;
3842 case RNID_TOPOLOGY_DISC:
3843 rn->SpecificLen = sizeof(RNID_TOP_DISC);
3844 memcpy(&rn->un.topologyDisc.portName,
3845 &vport->fc_portname, sizeof(struct lpfc_name));
3846 rn->un.topologyDisc.unitType = RNID_HBA;
3847 rn->un.topologyDisc.physPort = 0;
3848 rn->un.topologyDisc.attachedNodes = 0;
3852 rn->SpecificLen = 0;
3856 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3857 "Issue ACC RNID: did:x%x flg:x%x",
3858 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3860 phba->fc_stat.elsXmitACC++;
3861 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
3863 elsiocb->context1 = NULL; /* Don't need ndlp for cmpl,
3864 * it could be freed */
3866 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
3867 if (rc == IOCB_ERROR) {
3868 lpfc_els_free_iocb(phba, elsiocb);
3875 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
3876 * @vport: pointer to a host virtual N_Port data structure.
3878 * This routine issues Address Discover (ADISC) ELS commands to those
3879 * N_Ports which are in node port recovery state and ADISC has not been issued
3880 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
3881 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
3882 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
3883 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
3884 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
3885 * IOCBs quit for later pick up. On the other hand, after walking through
3886 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
3887 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
3888 * no more ADISC need to be sent.
3891 * The number of N_Ports with adisc issued.
3894 lpfc_els_disc_adisc(struct lpfc_vport *vport)
3896 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3897 struct lpfc_nodelist *ndlp, *next_ndlp;
3900 /* go thru NPR nodes and issue any remaining ELS ADISCs */
3901 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
3902 if (!NLP_CHK_NODE_ACT(ndlp))
3904 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
3905 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
3906 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
3907 spin_lock_irq(shost->host_lock);
3908 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
3909 spin_unlock_irq(shost->host_lock);
3910 ndlp->nlp_prev_state = ndlp->nlp_state;
3911 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
3912 lpfc_issue_els_adisc(vport, ndlp, 0);
3914 vport->num_disc_nodes++;
3915 if (vport->num_disc_nodes >=
3916 vport->cfg_discovery_threads) {
3917 spin_lock_irq(shost->host_lock);
3918 vport->fc_flag |= FC_NLP_MORE;
3919 spin_unlock_irq(shost->host_lock);
3924 if (sentadisc == 0) {
3925 spin_lock_irq(shost->host_lock);
3926 vport->fc_flag &= ~FC_NLP_MORE;
3927 spin_unlock_irq(shost->host_lock);
3933 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
3934 * @vport: pointer to a host virtual N_Port data structure.
3936 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
3937 * which are in node port recovery state, with a @vport. Each time an ELS
3938 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
3939 * the per @vport number of discover count (num_disc_nodes) shall be
3940 * incremented. If the num_disc_nodes reaches a pre-configured threshold
3941 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
3942 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
3943 * later pick up. On the other hand, after walking through all the ndlps with
3944 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
3945 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
3946 * PLOGI need to be sent.
3949 * The number of N_Ports with plogi issued.
3952 lpfc_els_disc_plogi(struct lpfc_vport *vport)
3954 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3955 struct lpfc_nodelist *ndlp, *next_ndlp;
3958 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
3959 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
3960 if (!NLP_CHK_NODE_ACT(ndlp))
3962 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
3963 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
3964 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
3965 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
3966 ndlp->nlp_prev_state = ndlp->nlp_state;
3967 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
3968 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
3970 vport->num_disc_nodes++;
3971 if (vport->num_disc_nodes >=
3972 vport->cfg_discovery_threads) {
3973 spin_lock_irq(shost->host_lock);
3974 vport->fc_flag |= FC_NLP_MORE;
3975 spin_unlock_irq(shost->host_lock);
3981 lpfc_set_disctmo(vport);
3984 spin_lock_irq(shost->host_lock);
3985 vport->fc_flag &= ~FC_NLP_MORE;
3986 spin_unlock_irq(shost->host_lock);
3992 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
3993 * @vport: pointer to a host virtual N_Port data structure.
3995 * This routine cleans up any Registration State Change Notification
3996 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
3997 * @vport together with the host_lock is used to prevent multiple thread
3998 * trying to access the RSCN array on a same @vport at the same time.
4001 lpfc_els_flush_rscn(struct lpfc_vport *vport)
4003 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4004 struct lpfc_hba *phba = vport->phba;
4007 spin_lock_irq(shost->host_lock);
4008 if (vport->fc_rscn_flush) {
4009 /* Another thread is walking fc_rscn_id_list on this vport */
4010 spin_unlock_irq(shost->host_lock);
4013 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
4014 vport->fc_rscn_flush = 1;
4015 spin_unlock_irq(shost->host_lock);
4017 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
4018 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
4019 vport->fc_rscn_id_list[i] = NULL;
4021 spin_lock_irq(shost->host_lock);
4022 vport->fc_rscn_id_cnt = 0;
4023 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
4024 spin_unlock_irq(shost->host_lock);
4025 lpfc_can_disctmo(vport);
4026 /* Indicate we are done walking this fc_rscn_id_list */
4027 vport->fc_rscn_flush = 0;
4031 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
4032 * @vport: pointer to a host virtual N_Port data structure.
4033 * @did: remote destination port identifier.
4035 * This routine checks whether there is any pending Registration State
4036 * Configuration Notification (RSCN) to a @did on @vport.
4039 * None zero - The @did matched with a pending rscn
4040 * 0 - not able to match @did with a pending rscn
4043 lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
4048 uint32_t payload_len, i;
4049 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4051 ns_did.un.word = did;
4053 /* Never match fabric nodes for RSCNs */
4054 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
4057 /* If we are doing a FULL RSCN rediscovery, match everything */
4058 if (vport->fc_flag & FC_RSCN_DISCOVERY)
4061 spin_lock_irq(shost->host_lock);
4062 if (vport->fc_rscn_flush) {
4063 /* Another thread is walking fc_rscn_id_list on this vport */
4064 spin_unlock_irq(shost->host_lock);
4067 /* Indicate we are walking fc_rscn_id_list on this vport */
4068 vport->fc_rscn_flush = 1;
4069 spin_unlock_irq(shost->host_lock);
4070 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
4071 lp = vport->fc_rscn_id_list[i]->virt;
4072 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
4073 payload_len -= sizeof(uint32_t); /* take off word 0 */
4074 while (payload_len) {
4075 rscn_did.un.word = be32_to_cpu(*lp++);
4076 payload_len -= sizeof(uint32_t);
4077 switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) {
4078 case RSCN_ADDRESS_FORMAT_PORT:
4079 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
4080 && (ns_did.un.b.area == rscn_did.un.b.area)
4081 && (ns_did.un.b.id == rscn_did.un.b.id))
4082 goto return_did_out;
4084 case RSCN_ADDRESS_FORMAT_AREA:
4085 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
4086 && (ns_did.un.b.area == rscn_did.un.b.area))
4087 goto return_did_out;
4089 case RSCN_ADDRESS_FORMAT_DOMAIN:
4090 if (ns_did.un.b.domain == rscn_did.un.b.domain)
4091 goto return_did_out;
4093 case RSCN_ADDRESS_FORMAT_FABRIC:
4094 goto return_did_out;
4098 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4099 vport->fc_rscn_flush = 0;
4102 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4103 vport->fc_rscn_flush = 0;
4108 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
4109 * @vport: pointer to a host virtual N_Port data structure.
4111 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
4112 * state machine for a @vport's nodes that are with pending RSCN (Registration
4113 * State Change Notification).
4116 * 0 - Successful (currently alway return 0)
4119 lpfc_rscn_recovery_check(struct lpfc_vport *vport)
4121 struct lpfc_nodelist *ndlp = NULL;
4123 /* Move all affected nodes by pending RSCNs to NPR state. */
4124 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
4125 if (!NLP_CHK_NODE_ACT(ndlp) ||
4126 (ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
4127 !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
4129 lpfc_disc_state_machine(vport, ndlp, NULL,
4130 NLP_EVT_DEVICE_RECOVERY);
4131 lpfc_cancel_retry_delay_tmo(vport, ndlp);
4137 * lpfc_send_rscn_event - Send an RSCN event to management application
4138 * @vport: pointer to a host virtual N_Port data structure.
4139 * @cmdiocb: pointer to lpfc command iocb data structure.
4141 * lpfc_send_rscn_event sends an RSCN netlink event to management
4145 lpfc_send_rscn_event(struct lpfc_vport *vport,
4146 struct lpfc_iocbq *cmdiocb)
4148 struct lpfc_dmabuf *pcmd;
4149 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4150 uint32_t *payload_ptr;
4151 uint32_t payload_len;
4152 struct lpfc_rscn_event_header *rscn_event_data;
4154 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4155 payload_ptr = (uint32_t *) pcmd->virt;
4156 payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK);
4158 rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) +
4159 payload_len, GFP_KERNEL);
4160 if (!rscn_event_data) {
4161 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4162 "0147 Failed to allocate memory for RSCN event\n");
4165 rscn_event_data->event_type = FC_REG_RSCN_EVENT;
4166 rscn_event_data->payload_length = payload_len;
4167 memcpy(rscn_event_data->rscn_payload, payload_ptr,
4170 fc_host_post_vendor_event(shost,
4171 fc_get_event_number(),
4172 sizeof(struct lpfc_els_event_header) + payload_len,
4173 (char *)rscn_event_data,
4176 kfree(rscn_event_data);
4180 * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
4181 * @vport: pointer to a host virtual N_Port data structure.
4182 * @cmdiocb: pointer to lpfc command iocb data structure.
4183 * @ndlp: pointer to a node-list data structure.
4185 * This routine processes an unsolicited RSCN (Registration State Change
4186 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
4187 * to invoke fc_host_post_event() routine to the FC transport layer. If the
4188 * discover state machine is about to begin discovery, it just accepts the
4189 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
4190 * contains N_Port IDs for other vports on this HBA, it just accepts the
4191 * RSCN and ignore processing it. If the state machine is in the recovery
4192 * state, the fc_rscn_id_list of this @vport is walked and the
4193 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
4194 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
4195 * routine is invoked to handle the RSCN event.
4198 * 0 - Just sent the acc response
4199 * 1 - Sent the acc response and waited for name server completion
4202 lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4203 struct lpfc_nodelist *ndlp)
4205 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4206 struct lpfc_hba *phba = vport->phba;
4207 struct lpfc_dmabuf *pcmd;
4208 uint32_t *lp, *datap;
4210 uint32_t payload_len, length, nportid, *cmd;
4212 int rscn_id = 0, hba_id = 0;
4215 icmd = &cmdiocb->iocb;
4216 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4217 lp = (uint32_t *) pcmd->virt;
4219 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
4220 payload_len -= sizeof(uint32_t); /* take off word 0 */
4222 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4223 "0214 RSCN received Data: x%x x%x x%x x%x\n",
4224 vport->fc_flag, payload_len, *lp,
4225 vport->fc_rscn_id_cnt);
4227 /* Send an RSCN event to the management application */
4228 lpfc_send_rscn_event(vport, cmdiocb);
4230 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
4231 fc_host_post_event(shost, fc_get_event_number(),
4232 FCH_EVT_RSCN, lp[i]);
4234 /* If we are about to begin discovery, just ACC the RSCN.
4235 * Discovery processing will satisfy it.
4237 if (vport->port_state <= LPFC_NS_QRY) {
4238 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4239 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
4240 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4242 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
4246 /* If this RSCN just contains NPortIDs for other vports on this HBA,
4247 * just ACC and ignore it.
4249 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
4250 !(vport->cfg_peer_port_login)) {
4255 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
4256 i -= sizeof(uint32_t);
4258 if (lpfc_find_vport_by_did(phba, nportid))
4261 if (rscn_id == hba_id) {
4262 /* ALL NPortIDs in RSCN are on HBA */
4263 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4265 "Data: x%x x%x x%x x%x\n",
4266 vport->fc_flag, payload_len,
4267 *lp, vport->fc_rscn_id_cnt);
4268 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4269 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
4270 ndlp->nlp_DID, vport->port_state,
4273 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
4279 spin_lock_irq(shost->host_lock);
4280 if (vport->fc_rscn_flush) {
4281 /* Another thread is walking fc_rscn_id_list on this vport */
4282 vport->fc_flag |= FC_RSCN_DISCOVERY;
4283 spin_unlock_irq(shost->host_lock);
4285 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
4288 /* Indicate we are walking fc_rscn_id_list on this vport */
4289 vport->fc_rscn_flush = 1;
4290 spin_unlock_irq(shost->host_lock);
4291 /* Get the array count after successfully have the token */
4292 rscn_cnt = vport->fc_rscn_id_cnt;
4293 /* If we are already processing an RSCN, save the received
4294 * RSCN payload buffer, cmdiocb->context2 to process later.
4296 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
4297 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4298 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
4299 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4301 spin_lock_irq(shost->host_lock);
4302 vport->fc_flag |= FC_RSCN_DEFERRED;
4303 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
4304 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
4305 vport->fc_flag |= FC_RSCN_MODE;
4306 spin_unlock_irq(shost->host_lock);
4308 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
4309 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
4312 (payload_len + length <= LPFC_BPL_SIZE)) {
4313 *cmd &= ELS_CMD_MASK;
4314 *cmd |= cpu_to_be32(payload_len + length);
4315 memcpy(((uint8_t *)cmd) + length, lp,
4318 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
4319 vport->fc_rscn_id_cnt++;
4320 /* If we zero, cmdiocb->context2, the calling
4321 * routine will not try to free it.
4323 cmdiocb->context2 = NULL;
4326 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4327 "0235 Deferred RSCN "
4328 "Data: x%x x%x x%x\n",
4329 vport->fc_rscn_id_cnt, vport->fc_flag,
4332 vport->fc_flag |= FC_RSCN_DISCOVERY;
4333 spin_unlock_irq(shost->host_lock);
4334 /* ReDiscovery RSCN */
4335 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4336 "0234 ReDiscovery RSCN "
4337 "Data: x%x x%x x%x\n",
4338 vport->fc_rscn_id_cnt, vport->fc_flag,
4341 /* Indicate we are done walking fc_rscn_id_list on this vport */
4342 vport->fc_rscn_flush = 0;
4344 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
4345 /* send RECOVERY event for ALL nodes that match RSCN payload */
4346 lpfc_rscn_recovery_check(vport);
4347 spin_lock_irq(shost->host_lock);
4348 vport->fc_flag &= ~FC_RSCN_DEFERRED;
4349 spin_unlock_irq(shost->host_lock);
4352 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4353 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
4354 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4356 spin_lock_irq(shost->host_lock);
4357 vport->fc_flag |= FC_RSCN_MODE;
4358 spin_unlock_irq(shost->host_lock);
4359 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
4360 /* Indicate we are done walking fc_rscn_id_list on this vport */
4361 vport->fc_rscn_flush = 0;
4363 * If we zero, cmdiocb->context2, the calling routine will
4364 * not try to free it.
4366 cmdiocb->context2 = NULL;
4367 lpfc_set_disctmo(vport);
4369 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
4370 /* send RECOVERY event for ALL nodes that match RSCN payload */
4371 lpfc_rscn_recovery_check(vport);
4372 return lpfc_els_handle_rscn(vport);
4376 * lpfc_els_handle_rscn - Handle rscn for a vport
4377 * @vport: pointer to a host virtual N_Port data structure.
4379 * This routine handles the Registration State Configuration Notification
4380 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
4381 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
4382 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
4383 * NameServer shall be issued. If CT command to the NameServer fails to be
4384 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
4385 * RSCN activities with the @vport.
4388 * 0 - Cleaned up rscn on the @vport
4389 * 1 - Wait for plogi to name server before proceed
4392 lpfc_els_handle_rscn(struct lpfc_vport *vport)
4394 struct lpfc_nodelist *ndlp;
4395 struct lpfc_hba *phba = vport->phba;
4397 /* Ignore RSCN if the port is being torn down. */
4398 if (vport->load_flag & FC_UNLOADING) {
4399 lpfc_els_flush_rscn(vport);
4403 /* Start timer for RSCN processing */
4404 lpfc_set_disctmo(vport);
4406 /* RSCN processed */
4407 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4408 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
4409 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
4412 /* To process RSCN, first compare RSCN data with NameServer */
4413 vport->fc_ns_retry = 0;
4414 vport->num_disc_nodes = 0;
4416 ndlp = lpfc_findnode_did(vport, NameServer_DID);
4417 if (ndlp && NLP_CHK_NODE_ACT(ndlp)
4418 && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
4419 /* Good ndlp, issue CT Request to NameServer */
4420 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0)
4421 /* Wait for NameServer query cmpl before we can
4425 /* If login to NameServer does not exist, issue one */
4426 /* Good status, issue PLOGI to NameServer */
4427 ndlp = lpfc_findnode_did(vport, NameServer_DID);
4428 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
4429 /* Wait for NameServer login cmpl before we can
4434 ndlp = lpfc_enable_node(vport, ndlp,
4435 NLP_STE_PLOGI_ISSUE);
4437 lpfc_els_flush_rscn(vport);
4440 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
4442 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
4444 lpfc_els_flush_rscn(vport);
4447 lpfc_nlp_init(vport, ndlp, NameServer_DID);
4448 ndlp->nlp_prev_state = ndlp->nlp_state;
4449 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
4451 ndlp->nlp_type |= NLP_FABRIC;
4452 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
4453 /* Wait for NameServer login cmpl before we can
4459 lpfc_els_flush_rscn(vport);
4464 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
4465 * @vport: pointer to a host virtual N_Port data structure.
4466 * @cmdiocb: pointer to lpfc command iocb data structure.
4467 * @ndlp: pointer to a node-list data structure.
4469 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
4470 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
4471 * point topology. As an unsolicited FLOGI should not be received in a loop
4472 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
4473 * lpfc_check_sparm() routine is invoked to check the parameters in the
4474 * unsolicited FLOGI. If parameters validation failed, the routine
4475 * lpfc_els_rsp_reject() shall be called with reject reason code set to
4476 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
4477 * FLOGI shall be compared with the Port WWN of the @vport to determine who
4478 * will initiate PLOGI. The higher lexicographical value party shall has
4479 * higher priority (as the winning port) and will initiate PLOGI and
4480 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
4481 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
4482 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
4485 * 0 - Successfully processed the unsolicited flogi
4486 * 1 - Failed to process the unsolicited flogi
4489 lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4490 struct lpfc_nodelist *ndlp)
4492 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4493 struct lpfc_hba *phba = vport->phba;
4494 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4495 uint32_t *lp = (uint32_t *) pcmd->virt;
4496 IOCB_t *icmd = &cmdiocb->iocb;
4497 struct serv_parm *sp;
4504 sp = (struct serv_parm *) lp;
4506 /* FLOGI received */
4508 lpfc_set_disctmo(vport);
4510 if (phba->fc_topology == TOPOLOGY_LOOP) {
4511 /* We should never receive a FLOGI in loop mode, ignore it */
4512 did = icmd->un.elsreq64.remoteID;
4514 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
4516 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4517 "0113 An FLOGI ELS command x%x was "
4518 "received from DID x%x in Loop Mode\n",
4525 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1))) {
4526 /* For a FLOGI we accept, then if our portname is greater
4527 * then the remote portname we initiate Nport login.
4530 rc = memcmp(&vport->fc_portname, &sp->portName,
4531 sizeof(struct lpfc_name));
4534 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4538 lpfc_linkdown(phba);
4539 lpfc_init_link(phba, mbox,
4541 phba->cfg_link_speed);
4542 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
4543 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
4544 mbox->vport = vport;
4545 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
4546 lpfc_set_loopback_flag(phba);
4547 if (rc == MBX_NOT_FINISHED) {
4548 mempool_free(mbox, phba->mbox_mem_pool);
4551 } else if (rc > 0) { /* greater than */
4552 spin_lock_irq(shost->host_lock);
4553 vport->fc_flag |= FC_PT2PT_PLOGI;
4554 spin_unlock_irq(shost->host_lock);
4556 spin_lock_irq(shost->host_lock);
4557 vport->fc_flag |= FC_PT2PT;
4558 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
4559 spin_unlock_irq(shost->host_lock);
4561 /* Reject this request because invalid parameters */
4562 stat.un.b.lsRjtRsvd0 = 0;
4563 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4564 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
4565 stat.un.b.vendorUnique = 0;
4566 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4572 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
4578 * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
4579 * @vport: pointer to a host virtual N_Port data structure.
4580 * @cmdiocb: pointer to lpfc command iocb data structure.
4581 * @ndlp: pointer to a node-list data structure.
4583 * This routine processes Request Node Identification Data (RNID) IOCB
4584 * received as an ELS unsolicited event. Only when the RNID specified format
4585 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
4586 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
4587 * Accept (ACC) the RNID ELS command. All the other RNID formats are
4588 * rejected by invoking the lpfc_els_rsp_reject() routine.
4591 * 0 - Successfully processed rnid iocb (currently always return 0)
4594 lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4595 struct lpfc_nodelist *ndlp)
4597 struct lpfc_dmabuf *pcmd;
4604 icmd = &cmdiocb->iocb;
4605 did = icmd->un.elsreq64.remoteID;
4606 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4607 lp = (uint32_t *) pcmd->virt;
4614 switch (rn->Format) {
4616 case RNID_TOPOLOGY_DISC:
4618 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
4621 /* Reject this request because format not supported */
4622 stat.un.b.lsRjtRsvd0 = 0;
4623 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4624 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4625 stat.un.b.vendorUnique = 0;
4626 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4633 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
4634 * @vport: pointer to a host virtual N_Port data structure.
4635 * @cmdiocb: pointer to lpfc command iocb data structure.
4636 * @ndlp: pointer to a node-list data structure.
4638 * This routine processes a Link Incident Report Registration(LIRR) IOCB
4639 * received as an ELS unsolicited event. Currently, this function just invokes
4640 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
4643 * 0 - Successfully processed lirr iocb (currently always return 0)
4646 lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4647 struct lpfc_nodelist *ndlp)
4651 /* For now, unconditionally reject this command */
4652 stat.un.b.lsRjtRsvd0 = 0;
4653 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4654 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4655 stat.un.b.vendorUnique = 0;
4656 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
4661 * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb
4662 * @vport: pointer to a host virtual N_Port data structure.
4663 * @cmdiocb: pointer to lpfc command iocb data structure.
4664 * @ndlp: pointer to a node-list data structure.
4666 * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB
4667 * received as an ELS unsolicited event. A request to RRQ shall only
4668 * be accepted if the Originator Nx_Port N_Port_ID or the Responder
4669 * Nx_Port N_Port_ID of the target Exchange is the same as the
4670 * N_Port_ID of the Nx_Port that makes the request. If the RRQ is
4671 * not accepted, an LS_RJT with reason code "Unable to perform
4672 * command request" and reason code explanation "Invalid Originator
4673 * S_ID" shall be returned. For now, we just unconditionally accept
4674 * RRQ from the target.
4677 lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4678 struct lpfc_nodelist *ndlp)
4680 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
4684 * lpfc_els_rsp_rps_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
4685 * @phba: pointer to lpfc hba data structure.
4686 * @pmb: pointer to the driver internal queue element for mailbox command.
4688 * This routine is the completion callback function for the MBX_READ_LNK_STAT
4689 * mailbox command. This callback function is to actually send the Accept
4690 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
4691 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
4692 * mailbox command, constructs the RPS response with the link statistics
4693 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
4694 * response to the RPS.
4696 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4697 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4698 * will be stored into the context1 field of the IOCB for the completion
4699 * callback function to the RPS Accept Response ELS IOCB command.
4703 lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4709 struct lpfc_iocbq *elsiocb;
4710 struct lpfc_nodelist *ndlp;
4711 uint16_t xri, status;
4716 ndlp = (struct lpfc_nodelist *) pmb->context2;
4717 xri = (uint16_t) ((unsigned long)(pmb->context1));
4718 pmb->context1 = NULL;
4719 pmb->context2 = NULL;
4721 if (mb->mbxStatus) {
4722 mempool_free(pmb, phba->mbox_mem_pool);
4726 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
4727 mempool_free(pmb, phba->mbox_mem_pool);
4728 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
4729 lpfc_max_els_tries, ndlp,
4730 ndlp->nlp_DID, ELS_CMD_ACC);
4732 /* Decrement the ndlp reference count from previous mbox command */
4738 icmd = &elsiocb->iocb;
4739 icmd->ulpContext = xri;
4741 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4742 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4743 pcmd += sizeof(uint32_t); /* Skip past command */
4744 rps_rsp = (RPS_RSP *)pcmd;
4746 if (phba->fc_topology != TOPOLOGY_LOOP)
4750 if (phba->pport->fc_flag & FC_FABRIC)
4754 rps_rsp->portStatus = cpu_to_be16(status);
4755 rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
4756 rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
4757 rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
4758 rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
4759 rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
4760 rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
4761 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
4762 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
4763 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
4764 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
4765 elsiocb->iotag, elsiocb->iocb.ulpContext,
4766 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4768 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4769 phba->fc_stat.elsXmitACC++;
4770 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
4771 lpfc_els_free_iocb(phba, elsiocb);
4776 * lpfc_els_rcv_rps - Process an unsolicited rps iocb
4777 * @vport: pointer to a host virtual N_Port data structure.
4778 * @cmdiocb: pointer to lpfc command iocb data structure.
4779 * @ndlp: pointer to a node-list data structure.
4781 * This routine processes Read Port Status (RPS) IOCB received as an
4782 * ELS unsolicited event. It first checks the remote port state. If the
4783 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
4784 * state, it invokes the lpfc_els_rsp_reject() routine to send the reject
4785 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
4786 * for reading the HBA link statistics. It is for the callback function,
4787 * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command
4788 * to actually sending out RPS Accept (ACC) response.
4791 * 0 - Successfully processed rps iocb (currently always return 0)
4794 lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4795 struct lpfc_nodelist *ndlp)
4797 struct lpfc_hba *phba = vport->phba;
4801 struct lpfc_dmabuf *pcmd;
4805 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
4806 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
4807 /* reject the unsolicited RPS request and done with it */
4810 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4811 lp = (uint32_t *) pcmd->virt;
4812 flag = (be32_to_cpu(*lp++) & 0xf);
4816 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
4817 ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
4818 sizeof(struct lpfc_name)) == 0))) {
4820 printk("Fix me....\n");
4822 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
4824 lpfc_read_lnk_stat(phba, mbox);
4826 (void *)((unsigned long) cmdiocb->iocb.ulpContext);
4827 mbox->context2 = lpfc_nlp_get(ndlp);
4828 mbox->vport = vport;
4829 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
4830 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
4831 != MBX_NOT_FINISHED)
4832 /* Mbox completion will send ELS Response */
4834 /* Decrement reference count used for the failed mbox
4838 mempool_free(mbox, phba->mbox_mem_pool);
4843 /* issue rejection response */
4844 stat.un.b.lsRjtRsvd0 = 0;
4845 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4846 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4847 stat.un.b.vendorUnique = 0;
4848 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
4853 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
4854 * @vport: pointer to a host virtual N_Port data structure.
4855 * @cmdsize: size of the ELS command.
4856 * @oldiocb: pointer to the original lpfc command iocb data structure.
4857 * @ndlp: pointer to a node-list data structure.
4859 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
4860 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
4862 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4863 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4864 * will be stored into the context1 field of the IOCB for the completion
4865 * callback function to the RPL Accept Response ELS command.
4868 * 0 - Successfully issued ACC RPL ELS command
4869 * 1 - Failed to issue ACC RPL ELS command
4872 lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
4873 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
4875 struct lpfc_hba *phba = vport->phba;
4876 IOCB_t *icmd, *oldcmd;
4878 struct lpfc_iocbq *elsiocb;
4881 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4882 ndlp->nlp_DID, ELS_CMD_ACC);
4887 icmd = &elsiocb->iocb;
4888 oldcmd = &oldiocb->iocb;
4889 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
4891 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4892 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4893 pcmd += sizeof(uint16_t);
4894 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
4895 pcmd += sizeof(uint16_t);
4897 /* Setup the RPL ACC payload */
4898 rpl_rsp.listLen = be32_to_cpu(1);
4900 rpl_rsp.port_num_blk.portNum = 0;
4901 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
4902 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
4903 sizeof(struct lpfc_name));
4904 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
4905 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
4906 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4907 "0120 Xmit ELS RPL ACC response tag x%x "
4908 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
4910 elsiocb->iotag, elsiocb->iocb.ulpContext,
4911 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4913 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4914 phba->fc_stat.elsXmitACC++;
4915 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
4917 lpfc_els_free_iocb(phba, elsiocb);
4924 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
4925 * @vport: pointer to a host virtual N_Port data structure.
4926 * @cmdiocb: pointer to lpfc command iocb data structure.
4927 * @ndlp: pointer to a node-list data structure.
4929 * This routine processes Read Port List (RPL) IOCB received as an ELS
4930 * unsolicited event. It first checks the remote port state. If the remote
4931 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
4932 * invokes the lpfc_els_rsp_reject() routine to send reject response.
4933 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
4934 * to accept the RPL.
4937 * 0 - Successfully processed rpl iocb (currently always return 0)
4940 lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4941 struct lpfc_nodelist *ndlp)
4943 struct lpfc_dmabuf *pcmd;
4950 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
4951 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
4952 /* issue rejection response */
4953 stat.un.b.lsRjtRsvd0 = 0;
4954 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4955 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4956 stat.un.b.vendorUnique = 0;
4957 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4959 /* rejected the unsolicited RPL request and done with it */
4963 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4964 lp = (uint32_t *) pcmd->virt;
4965 rpl = (RPL *) (lp + 1);
4967 maxsize = be32_to_cpu(rpl->maxsize);
4969 /* We support only one port */
4970 if ((rpl->index == 0) &&
4972 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
4973 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
4975 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
4977 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
4983 * lpfc_els_rcv_farp - Process an unsolicited farp request els command
4984 * @vport: pointer to a virtual N_Port data structure.
4985 * @cmdiocb: pointer to lpfc command iocb data structure.
4986 * @ndlp: pointer to a node-list data structure.
4988 * This routine processes Fibre Channel Address Resolution Protocol
4989 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
4990 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
4991 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
4992 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
4993 * remote PortName is compared against the FC PortName stored in the @vport
4994 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
4995 * compared against the FC NodeName stored in the @vport data structure.
4996 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
4997 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
4998 * invoked to send out FARP Response to the remote node. Before sending the
4999 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
5000 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
5001 * routine is invoked to log into the remote port first.
5004 * 0 - Either the FARP Match Mode not supported or successfully processed
5007 lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5008 struct lpfc_nodelist *ndlp)
5010 struct lpfc_dmabuf *pcmd;
5014 uint32_t cmd, cnt, did;
5016 icmd = &cmdiocb->iocb;
5017 did = icmd->un.elsreq64.remoteID;
5018 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5019 lp = (uint32_t *) pcmd->virt;
5023 /* FARP-REQ received from DID <did> */
5024 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5025 "0601 FARP-REQ received from DID x%x\n", did);
5026 /* We will only support match on WWPN or WWNN */
5027 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
5032 /* If this FARP command is searching for my portname */
5033 if (fp->Mflags & FARP_MATCH_PORT) {
5034 if (memcmp(&fp->RportName, &vport->fc_portname,
5035 sizeof(struct lpfc_name)) == 0)
5039 /* If this FARP command is searching for my nodename */
5040 if (fp->Mflags & FARP_MATCH_NODE) {
5041 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
5042 sizeof(struct lpfc_name)) == 0)
5047 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
5048 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
5049 /* Log back into the node before sending the FARP. */
5050 if (fp->Rflags & FARP_REQUEST_PLOGI) {
5051 ndlp->nlp_prev_state = ndlp->nlp_state;
5052 lpfc_nlp_set_state(vport, ndlp,
5053 NLP_STE_PLOGI_ISSUE);
5054 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
5057 /* Send a FARP response to that node */
5058 if (fp->Rflags & FARP_REQUEST_FARPR)
5059 lpfc_issue_els_farpr(vport, did, 0);
5066 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
5067 * @vport: pointer to a host virtual N_Port data structure.
5068 * @cmdiocb: pointer to lpfc command iocb data structure.
5069 * @ndlp: pointer to a node-list data structure.
5071 * This routine processes Fibre Channel Address Resolution Protocol
5072 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
5073 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
5074 * the FARP response request.
5077 * 0 - Successfully processed FARPR IOCB (currently always return 0)
5080 lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5081 struct lpfc_nodelist *ndlp)
5083 struct lpfc_dmabuf *pcmd;
5088 icmd = &cmdiocb->iocb;
5089 did = icmd->un.elsreq64.remoteID;
5090 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5091 lp = (uint32_t *) pcmd->virt;
5094 /* FARP-RSP received from DID <did> */
5095 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5096 "0600 FARP-RSP received from DID x%x\n", did);
5097 /* ACCEPT the Farp resp request */
5098 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
5104 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
5105 * @vport: pointer to a host virtual N_Port data structure.
5106 * @cmdiocb: pointer to lpfc command iocb data structure.
5107 * @fan_ndlp: pointer to a node-list data structure.
5109 * This routine processes a Fabric Address Notification (FAN) IOCB
5110 * command received as an ELS unsolicited event. The FAN ELS command will
5111 * only be processed on a physical port (i.e., the @vport represents the
5112 * physical port). The fabric NodeName and PortName from the FAN IOCB are
5113 * compared against those in the phba data structure. If any of those is
5114 * different, the lpfc_initial_flogi() routine is invoked to initialize
5115 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
5116 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
5117 * is invoked to register login to the fabric.
5120 * 0 - Successfully processed fan iocb (currently always return 0).
5123 lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5124 struct lpfc_nodelist *fan_ndlp)
5126 struct lpfc_hba *phba = vport->phba;
5130 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
5131 lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
5133 /* FAN received; Fan does not have a reply sequence */
5134 if ((vport == phba->pport) &&
5135 (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
5136 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
5137 sizeof(struct lpfc_name))) ||
5138 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
5139 sizeof(struct lpfc_name)))) {
5140 /* This port has switched fabrics. FLOGI is required */
5141 lpfc_initial_flogi(vport);
5143 /* FAN verified - skip FLOGI */
5144 vport->fc_myDID = vport->fc_prevDID;
5145 if (phba->sli_rev < LPFC_SLI_REV4)
5146 lpfc_issue_fabric_reglogin(vport);
5148 lpfc_issue_reg_vfi(vport);
5155 * lpfc_els_timeout - Handler funciton to the els timer
5156 * @ptr: holder for the timer function associated data.
5158 * This routine is invoked by the ELS timer after timeout. It posts the ELS
5159 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
5160 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
5161 * up the worker thread. It is for the worker thread to invoke the routine
5162 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
5165 lpfc_els_timeout(unsigned long ptr)
5167 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
5168 struct lpfc_hba *phba = vport->phba;
5169 uint32_t tmo_posted;
5170 unsigned long iflag;
5172 spin_lock_irqsave(&vport->work_port_lock, iflag);
5173 tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
5175 vport->work_port_events |= WORKER_ELS_TMO;
5176 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
5179 lpfc_worker_wake_up(phba);
5185 * lpfc_els_timeout_handler - Process an els timeout event
5186 * @vport: pointer to a virtual N_Port data structure.
5188 * This routine is the actual handler function that processes an ELS timeout
5189 * event. It walks the ELS ring to get and abort all the IOCBs (except the
5190 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
5191 * invoking the lpfc_sli_issue_abort_iotag() routine.
5194 lpfc_els_timeout_handler(struct lpfc_vport *vport)
5196 struct lpfc_hba *phba = vport->phba;
5197 struct lpfc_sli_ring *pring;
5198 struct lpfc_iocbq *tmp_iocb, *piocb;
5200 struct lpfc_dmabuf *pcmd;
5201 uint32_t els_command = 0;
5203 uint32_t remote_ID = 0xffffffff;
5204 LIST_HEAD(txcmplq_completions);
5205 LIST_HEAD(abort_list);
5208 timeout = (uint32_t)(phba->fc_ratov << 1);
5210 pring = &phba->sli.ring[LPFC_ELS_RING];
5212 spin_lock_irq(&phba->hbalock);
5213 list_splice_init(&pring->txcmplq, &txcmplq_completions);
5214 spin_unlock_irq(&phba->hbalock);
5216 list_for_each_entry_safe(piocb, tmp_iocb, &txcmplq_completions, list) {
5219 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
5220 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
5221 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
5224 if (piocb->vport != vport)
5227 pcmd = (struct lpfc_dmabuf *) piocb->context2;
5229 els_command = *(uint32_t *) (pcmd->virt);
5231 if (els_command == ELS_CMD_FARP ||
5232 els_command == ELS_CMD_FARPR ||
5233 els_command == ELS_CMD_FDISC)
5236 if (piocb->drvrTimeout > 0) {
5237 if (piocb->drvrTimeout >= timeout)
5238 piocb->drvrTimeout -= timeout;
5240 piocb->drvrTimeout = 0;
5244 remote_ID = 0xffffffff;
5245 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
5246 remote_ID = cmd->un.elsreq64.remoteID;
5248 struct lpfc_nodelist *ndlp;
5249 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
5250 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
5251 remote_ID = ndlp->nlp_DID;
5253 list_add_tail(&piocb->dlist, &abort_list);
5255 spin_lock_irq(&phba->hbalock);
5256 list_splice(&txcmplq_completions, &pring->txcmplq);
5257 spin_unlock_irq(&phba->hbalock);
5259 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
5260 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5261 "0127 ELS timeout Data: x%x x%x x%x "
5262 "x%x\n", els_command,
5263 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
5264 spin_lock_irq(&phba->hbalock);
5265 list_del_init(&piocb->dlist);
5266 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
5267 spin_unlock_irq(&phba->hbalock);
5270 if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt)
5271 mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
5275 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
5276 * @vport: pointer to a host virtual N_Port data structure.
5278 * This routine is used to clean up all the outstanding ELS commands on a
5279 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
5280 * routine. After that, it walks the ELS transmit queue to remove all the
5281 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
5282 * the IOCBs with a non-NULL completion callback function, the callback
5283 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
5284 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
5285 * callback function, the IOCB will simply be released. Finally, it walks
5286 * the ELS transmit completion queue to issue an abort IOCB to any transmit
5287 * completion queue IOCB that is associated with the @vport and is not
5288 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
5289 * part of the discovery state machine) out to HBA by invoking the
5290 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
5291 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
5292 * the IOCBs are aborted when this function returns.
5295 lpfc_els_flush_cmd(struct lpfc_vport *vport)
5297 LIST_HEAD(completions);
5298 struct lpfc_hba *phba = vport->phba;
5299 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
5300 struct lpfc_iocbq *tmp_iocb, *piocb;
5303 lpfc_fabric_abort_vport(vport);
5305 spin_lock_irq(&phba->hbalock);
5306 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
5309 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
5313 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
5314 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
5315 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
5316 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
5317 cmd->ulpCommand == CMD_ABORT_XRI_CN)
5320 if (piocb->vport != vport)
5323 list_move_tail(&piocb->list, &completions);
5327 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
5328 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
5332 if (piocb->vport != vport)
5335 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
5337 spin_unlock_irq(&phba->hbalock);
5339 /* Cancell all the IOCBs from the completions list */
5340 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
5347 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
5348 * @phba: pointer to lpfc hba data structure.
5350 * This routine is used to clean up all the outstanding ELS commands on a
5351 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
5352 * routine. After that, it walks the ELS transmit queue to remove all the
5353 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
5354 * the IOCBs with the completion callback function associated, the callback
5355 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
5356 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
5357 * callback function associated, the IOCB will simply be released. Finally,
5358 * it walks the ELS transmit completion queue to issue an abort IOCB to any
5359 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
5360 * management plane IOCBs that are not part of the discovery state machine)
5361 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
5364 lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
5366 LIST_HEAD(completions);
5367 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
5368 struct lpfc_iocbq *tmp_iocb, *piocb;
5371 lpfc_fabric_abort_hba(phba);
5372 spin_lock_irq(&phba->hbalock);
5373 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
5375 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
5377 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
5378 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
5379 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
5380 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
5381 cmd->ulpCommand == CMD_ABORT_XRI_CN)
5383 list_move_tail(&piocb->list, &completions);
5386 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
5387 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
5389 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
5391 spin_unlock_irq(&phba->hbalock);
5393 /* Cancel all the IOCBs from the completions list */
5394 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
5401 * lpfc_send_els_failure_event - Posts an ELS command failure event
5402 * @phba: Pointer to hba context object.
5403 * @cmdiocbp: Pointer to command iocb which reported error.
5404 * @rspiocbp: Pointer to response iocb which reported error.
5406 * This function sends an event when there is an ELS command
5410 lpfc_send_els_failure_event(struct lpfc_hba *phba,
5411 struct lpfc_iocbq *cmdiocbp,
5412 struct lpfc_iocbq *rspiocbp)
5414 struct lpfc_vport *vport = cmdiocbp->vport;
5415 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5416 struct lpfc_lsrjt_event lsrjt_event;
5417 struct lpfc_fabric_event_header fabric_event;
5419 struct lpfc_nodelist *ndlp;
5422 ndlp = cmdiocbp->context1;
5423 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
5426 if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) {
5427 lsrjt_event.header.event_type = FC_REG_ELS_EVENT;
5428 lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV;
5429 memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname,
5430 sizeof(struct lpfc_name));
5431 memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename,
5432 sizeof(struct lpfc_name));
5433 pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
5434 cmdiocbp->context2)->virt);
5435 lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0;
5436 stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]);
5437 lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode;
5438 lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp;
5439 fc_host_post_vendor_event(shost,
5440 fc_get_event_number(),
5441 sizeof(lsrjt_event),
5442 (char *)&lsrjt_event,
5446 if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) ||
5447 (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) {
5448 fabric_event.event_type = FC_REG_FABRIC_EVENT;
5449 if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY)
5450 fabric_event.subcategory = LPFC_EVENT_PORT_BUSY;
5452 fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY;
5453 memcpy(fabric_event.wwpn, &ndlp->nlp_portname,
5454 sizeof(struct lpfc_name));
5455 memcpy(fabric_event.wwnn, &ndlp->nlp_nodename,
5456 sizeof(struct lpfc_name));
5457 fc_host_post_vendor_event(shost,
5458 fc_get_event_number(),
5459 sizeof(fabric_event),
5460 (char *)&fabric_event,
5468 * lpfc_send_els_event - Posts unsolicited els event
5469 * @vport: Pointer to vport object.
5470 * @ndlp: Pointer FC node object.
5471 * @cmd: ELS command code.
5473 * This function posts an event when there is an incoming
5474 * unsolicited ELS command.
5477 lpfc_send_els_event(struct lpfc_vport *vport,
5478 struct lpfc_nodelist *ndlp,
5481 struct lpfc_els_event_header *els_data = NULL;
5482 struct lpfc_logo_event *logo_data = NULL;
5483 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5485 if (*payload == ELS_CMD_LOGO) {
5486 logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL);
5488 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5489 "0148 Failed to allocate memory "
5490 "for LOGO event\n");
5493 els_data = &logo_data->header;
5495 els_data = kmalloc(sizeof(struct lpfc_els_event_header),
5498 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5499 "0149 Failed to allocate memory "
5504 els_data->event_type = FC_REG_ELS_EVENT;
5507 els_data->subcategory = LPFC_EVENT_PLOGI_RCV;
5510 els_data->subcategory = LPFC_EVENT_PRLO_RCV;
5513 els_data->subcategory = LPFC_EVENT_ADISC_RCV;
5516 els_data->subcategory = LPFC_EVENT_LOGO_RCV;
5517 /* Copy the WWPN in the LOGO payload */
5518 memcpy(logo_data->logo_wwpn, &payload[2],
5519 sizeof(struct lpfc_name));
5525 memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name));
5526 memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name));
5527 if (*payload == ELS_CMD_LOGO) {
5528 fc_host_post_vendor_event(shost,
5529 fc_get_event_number(),
5530 sizeof(struct lpfc_logo_event),
5535 fc_host_post_vendor_event(shost,
5536 fc_get_event_number(),
5537 sizeof(struct lpfc_els_event_header),
5548 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
5549 * @phba: pointer to lpfc hba data structure.
5550 * @pring: pointer to a SLI ring.
5551 * @vport: pointer to a host virtual N_Port data structure.
5552 * @elsiocb: pointer to lpfc els command iocb data structure.
5554 * This routine is used for processing the IOCB associated with a unsolicited
5555 * event. It first determines whether there is an existing ndlp that matches
5556 * the DID from the unsolicited IOCB. If not, it will create a new one with
5557 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
5558 * IOCB is then used to invoke the proper routine and to set up proper state
5559 * of the discovery state machine.
5562 lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
5563 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
5565 struct Scsi_Host *shost;
5566 struct lpfc_nodelist *ndlp;
5569 uint32_t cmd, did, newnode, rjt_err = 0;
5570 IOCB_t *icmd = &elsiocb->iocb;
5572 if (!vport || !(elsiocb->context2))
5576 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
5578 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
5579 lpfc_post_buffer(phba, pring, 1);
5581 did = icmd->un.rcvels.remoteID;
5582 if (icmd->ulpStatus) {
5583 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5584 "RCV Unsol ELS: status:x%x/x%x did:x%x",
5585 icmd->ulpStatus, icmd->un.ulpWord[4], did);
5589 /* Check to see if link went down during discovery */
5590 if (lpfc_els_chk_latt(vport))
5593 /* Ignore traffic received during vport shutdown. */
5594 if (vport->load_flag & FC_UNLOADING)
5597 ndlp = lpfc_findnode_did(vport, did);
5599 /* Cannot find existing Fabric ndlp, so allocate a new one */
5600 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
5604 lpfc_nlp_init(vport, ndlp, did);
5605 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5607 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
5608 ndlp->nlp_type |= NLP_FABRIC;
5609 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
5610 ndlp = lpfc_enable_node(vport, ndlp,
5611 NLP_STE_UNUSED_NODE);
5614 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5616 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
5617 ndlp->nlp_type |= NLP_FABRIC;
5618 } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
5619 /* This is similar to the new node path */
5620 ndlp = lpfc_nlp_get(ndlp);
5623 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5627 phba->fc_stat.elsRcvFrame++;
5629 elsiocb->context1 = lpfc_nlp_get(ndlp);
5630 elsiocb->vport = vport;
5632 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
5633 cmd &= ELS_CMD_MASK;
5635 /* ELS command <elsCmd> received from NPORT <did> */
5636 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5637 "0112 ELS command x%x received from NPORT x%x "
5638 "Data: x%x\n", cmd, did, vport->port_state);
5641 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5642 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
5643 did, vport->port_state, ndlp->nlp_flag);
5645 phba->fc_stat.elsRcvPLOGI++;
5646 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
5648 lpfc_send_els_event(vport, ndlp, payload);
5649 if (vport->port_state < LPFC_DISC_AUTH) {
5650 if (!(phba->pport->fc_flag & FC_PT2PT) ||
5651 (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
5652 rjt_err = LSRJT_UNABLE_TPC;
5655 /* We get here, and drop thru, if we are PT2PT with
5656 * another NPort and the other side has initiated
5657 * the PLOGI before responding to our FLOGI.
5661 shost = lpfc_shost_from_vport(vport);
5662 spin_lock_irq(shost->host_lock);
5663 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
5664 spin_unlock_irq(shost->host_lock);
5666 lpfc_disc_state_machine(vport, ndlp, elsiocb,
5671 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5672 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
5673 did, vport->port_state, ndlp->nlp_flag);
5675 phba->fc_stat.elsRcvFLOGI++;
5676 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
5681 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5682 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
5683 did, vport->port_state, ndlp->nlp_flag);
5685 phba->fc_stat.elsRcvLOGO++;
5686 lpfc_send_els_event(vport, ndlp, payload);
5687 if (vport->port_state < LPFC_DISC_AUTH) {
5688 rjt_err = LSRJT_UNABLE_TPC;
5691 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
5694 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5695 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
5696 did, vport->port_state, ndlp->nlp_flag);
5698 phba->fc_stat.elsRcvPRLO++;
5699 lpfc_send_els_event(vport, ndlp, payload);
5700 if (vport->port_state < LPFC_DISC_AUTH) {
5701 rjt_err = LSRJT_UNABLE_TPC;
5704 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
5707 phba->fc_stat.elsRcvRSCN++;
5708 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
5713 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5714 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
5715 did, vport->port_state, ndlp->nlp_flag);
5717 lpfc_send_els_event(vport, ndlp, payload);
5718 phba->fc_stat.elsRcvADISC++;
5719 if (vport->port_state < LPFC_DISC_AUTH) {
5720 rjt_err = LSRJT_UNABLE_TPC;
5723 lpfc_disc_state_machine(vport, ndlp, elsiocb,
5727 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5728 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
5729 did, vport->port_state, ndlp->nlp_flag);
5731 phba->fc_stat.elsRcvPDISC++;
5732 if (vport->port_state < LPFC_DISC_AUTH) {
5733 rjt_err = LSRJT_UNABLE_TPC;
5736 lpfc_disc_state_machine(vport, ndlp, elsiocb,
5740 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5741 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
5742 did, vport->port_state, ndlp->nlp_flag);
5744 phba->fc_stat.elsRcvFARPR++;
5745 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
5748 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5749 "RCV FARP: did:x%x/ste:x%x flg:x%x",
5750 did, vport->port_state, ndlp->nlp_flag);
5752 phba->fc_stat.elsRcvFARP++;
5753 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
5756 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5757 "RCV FAN: did:x%x/ste:x%x flg:x%x",
5758 did, vport->port_state, ndlp->nlp_flag);
5760 phba->fc_stat.elsRcvFAN++;
5761 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
5764 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5765 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
5766 did, vport->port_state, ndlp->nlp_flag);
5768 phba->fc_stat.elsRcvPRLI++;
5769 if (vport->port_state < LPFC_DISC_AUTH) {
5770 rjt_err = LSRJT_UNABLE_TPC;
5773 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
5776 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5777 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
5778 did, vport->port_state, ndlp->nlp_flag);
5780 phba->fc_stat.elsRcvLIRR++;
5781 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
5786 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5787 "RCV RPS: did:x%x/ste:x%x flg:x%x",
5788 did, vport->port_state, ndlp->nlp_flag);
5790 phba->fc_stat.elsRcvRPS++;
5791 lpfc_els_rcv_rps(vport, elsiocb, ndlp);
5796 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5797 "RCV RPL: did:x%x/ste:x%x flg:x%x",
5798 did, vport->port_state, ndlp->nlp_flag);
5800 phba->fc_stat.elsRcvRPL++;
5801 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
5806 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5807 "RCV RNID: did:x%x/ste:x%x flg:x%x",
5808 did, vport->port_state, ndlp->nlp_flag);
5810 phba->fc_stat.elsRcvRNID++;
5811 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
5816 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5817 "RCV RRQ: did:x%x/ste:x%x flg:x%x",
5818 did, vport->port_state, ndlp->nlp_flag);
5820 phba->fc_stat.elsRcvRRQ++;
5821 lpfc_els_rcv_rrq(vport, elsiocb, ndlp);
5826 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5827 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
5828 cmd, did, vport->port_state);
5830 /* Unsupported ELS command, reject */
5831 rjt_err = LSRJT_INVALID_CMD;
5833 /* Unknown ELS command <elsCmd> received from NPORT <did> */
5834 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5835 "0115 Unknown ELS command x%x "
5836 "received from NPORT x%x\n", cmd, did);
5842 /* check if need to LS_RJT received ELS cmd */
5844 memset(&stat, 0, sizeof(stat));
5845 stat.un.b.lsRjtRsnCode = rjt_err;
5846 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
5847 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
5851 lpfc_nlp_put(elsiocb->context1);
5852 elsiocb->context1 = NULL;
5856 if (vport && !(vport->load_flag & FC_UNLOADING))
5857 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5858 "0111 Dropping received ELS cmd "
5859 "Data: x%x x%x x%x\n",
5860 icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout);
5861 phba->fc_stat.elsRcvDrop++;
5865 * lpfc_find_vport_by_vpid - Find a vport on a HBA through vport identifier
5866 * @phba: pointer to lpfc hba data structure.
5867 * @vpi: host virtual N_Port identifier.
5869 * This routine finds a vport on a HBA (referred by @phba) through a
5870 * @vpi. The function walks the HBA's vport list and returns the address
5871 * of the vport with the matching @vpi.
5874 * NULL - No vport with the matching @vpi found
5875 * Otherwise - Address to the vport with the matching @vpi.
5878 lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi)
5880 struct lpfc_vport *vport;
5881 unsigned long flags;
5883 spin_lock_irqsave(&phba->hbalock, flags);
5884 list_for_each_entry(vport, &phba->port_list, listentry) {
5885 if (vport->vpi == vpi) {
5886 spin_unlock_irqrestore(&phba->hbalock, flags);
5890 spin_unlock_irqrestore(&phba->hbalock, flags);
5895 * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
5896 * @phba: pointer to lpfc hba data structure.
5897 * @pring: pointer to a SLI ring.
5898 * @elsiocb: pointer to lpfc els iocb data structure.
5900 * This routine is used to process an unsolicited event received from a SLI
5901 * (Service Level Interface) ring. The actual processing of the data buffer
5902 * associated with the unsolicited event is done by invoking the routine
5903 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
5904 * SLI ring on which the unsolicited event was received.
5907 lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
5908 struct lpfc_iocbq *elsiocb)
5910 struct lpfc_vport *vport = phba->pport;
5911 IOCB_t *icmd = &elsiocb->iocb;
5913 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
5914 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
5916 elsiocb->context1 = NULL;
5917 elsiocb->context2 = NULL;
5918 elsiocb->context3 = NULL;
5920 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
5921 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
5922 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
5923 (icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING) {
5924 phba->fc_stat.NoRcvBuf++;
5925 /* Not enough posted buffers; Try posting more buffers */
5926 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
5927 lpfc_post_buffer(phba, pring, 0);
5931 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
5932 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
5933 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
5934 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
5935 vport = phba->pport;
5937 vport = lpfc_find_vport_by_vpid(phba,
5938 icmd->unsli3.rcvsli3.vpi - phba->vpi_base);
5940 /* If there are no BDEs associated
5941 * with this IOCB, there is nothing to do.
5943 if (icmd->ulpBdeCount == 0)
5946 /* type of ELS cmd is first 32bit word
5949 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
5950 elsiocb->context2 = bdeBuf1;
5952 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
5953 icmd->un.cont64[0].addrLow);
5954 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
5958 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
5960 * The different unsolicited event handlers would tell us
5961 * if they are done with "mp" by setting context2 to NULL.
5963 if (elsiocb->context2) {
5964 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
5965 elsiocb->context2 = NULL;
5968 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
5969 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
5970 icmd->ulpBdeCount == 2) {
5971 elsiocb->context2 = bdeBuf2;
5972 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
5973 /* free mp if we are done with it */
5974 if (elsiocb->context2) {
5975 lpfc_in_buf_free(phba, elsiocb->context2);
5976 elsiocb->context2 = NULL;
5982 * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
5983 * @phba: pointer to lpfc hba data structure.
5984 * @vport: pointer to a virtual N_Port data structure.
5986 * This routine issues a Port Login (PLOGI) to the Name Server with
5987 * State Change Request (SCR) for a @vport. This routine will create an
5988 * ndlp for the Name Server associated to the @vport if such node does
5989 * not already exist. The PLOGI to Name Server is issued by invoking the
5990 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
5991 * (FDMI) is configured to the @vport, a FDMI node will be created and
5992 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
5995 lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
5997 struct lpfc_nodelist *ndlp, *ndlp_fdmi;
5999 ndlp = lpfc_findnode_did(vport, NameServer_DID);
6001 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
6003 if (phba->fc_topology == TOPOLOGY_LOOP) {
6004 lpfc_disc_start(vport);
6007 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6008 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6009 "0251 NameServer login: no memory\n");
6012 lpfc_nlp_init(vport, ndlp, NameServer_DID);
6013 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
6014 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
6016 if (phba->fc_topology == TOPOLOGY_LOOP) {
6017 lpfc_disc_start(vport);
6020 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6021 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6022 "0348 NameServer login: node freed\n");
6026 ndlp->nlp_type |= NLP_FABRIC;
6028 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
6030 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
6031 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6032 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6033 "0252 Cannot issue NameServer login\n");
6037 if (vport->cfg_fdmi_on) {
6038 ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
6041 lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID);
6042 ndlp_fdmi->nlp_type |= NLP_FABRIC;
6043 lpfc_nlp_set_state(vport, ndlp_fdmi,
6044 NLP_STE_PLOGI_ISSUE);
6045 lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID,
6053 * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
6054 * @phba: pointer to lpfc hba data structure.
6055 * @pmb: pointer to the driver internal queue element for mailbox command.
6057 * This routine is the completion callback function to register new vport
6058 * mailbox command. If the new vport mailbox command completes successfully,
6059 * the fabric registration login shall be performed on physical port (the
6060 * new vport created is actually a physical port, with VPI 0) or the port
6061 * login to Name Server for State Change Request (SCR) will be performed
6062 * on virtual port (real virtual port, with VPI greater than 0).
6065 lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
6067 struct lpfc_vport *vport = pmb->vport;
6068 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6069 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
6070 MAILBOX_t *mb = &pmb->u.mb;
6073 spin_lock_irq(shost->host_lock);
6074 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
6075 spin_unlock_irq(shost->host_lock);
6077 if (mb->mbxStatus) {
6078 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
6079 "0915 Register VPI failed: 0x%x\n",
6082 switch (mb->mbxStatus) {
6083 case 0x11: /* unsupported feature */
6084 case 0x9603: /* max_vpi exceeded */
6085 case 0x9602: /* Link event since CLEAR_LA */
6086 /* giving up on vport registration */
6087 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6088 spin_lock_irq(shost->host_lock);
6089 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
6090 spin_unlock_irq(shost->host_lock);
6091 lpfc_can_disctmo(vport);
6093 /* If reg_vpi fail with invalid VPI status, re-init VPI */
6095 spin_lock_irq(shost->host_lock);
6096 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
6097 spin_unlock_irq(shost->host_lock);
6098 lpfc_init_vpi(phba, pmb, vport->vpi);
6100 pmb->mbox_cmpl = lpfc_init_vpi_cmpl;
6101 rc = lpfc_sli_issue_mbox(phba, pmb,
6103 if (rc == MBX_NOT_FINISHED) {
6104 lpfc_printf_vlog(vport,
6106 "2732 Failed to issue INIT_VPI"
6107 " mailbox command\n");
6114 /* Try to recover from this error */
6115 lpfc_mbx_unreg_vpi(vport);
6116 spin_lock_irq(shost->host_lock);
6117 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
6118 spin_unlock_irq(shost->host_lock);
6119 if (vport->port_type == LPFC_PHYSICAL_PORT
6120 && !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG))
6121 lpfc_initial_flogi(vport);
6123 lpfc_initial_fdisc(vport);
6127 spin_lock_irq(shost->host_lock);
6128 vport->vpi_state |= LPFC_VPI_REGISTERED;
6129 spin_unlock_irq(shost->host_lock);
6130 if (vport == phba->pport) {
6131 if (phba->sli_rev < LPFC_SLI_REV4)
6132 lpfc_issue_fabric_reglogin(vport);
6135 * If the physical port is instantiated using
6136 * FDISC, do not start vport discovery.
6138 if (vport->port_state != LPFC_FDISC)
6139 lpfc_start_fdiscs(phba);
6140 lpfc_do_scr_ns_plogi(phba, vport);
6143 lpfc_do_scr_ns_plogi(phba, vport);
6146 /* Now, we decrement the ndlp reference count held for this
6151 mempool_free(pmb, phba->mbox_mem_pool);
6156 * lpfc_register_new_vport - Register a new vport with a HBA
6157 * @phba: pointer to lpfc hba data structure.
6158 * @vport: pointer to a host virtual N_Port data structure.
6159 * @ndlp: pointer to a node-list data structure.
6161 * This routine registers the @vport as a new virtual port with a HBA.
6162 * It is done through a registering vpi mailbox command.
6165 lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
6166 struct lpfc_nodelist *ndlp)
6168 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6171 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6173 lpfc_reg_vpi(vport, mbox);
6174 mbox->vport = vport;
6175 mbox->context2 = lpfc_nlp_get(ndlp);
6176 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
6177 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
6178 == MBX_NOT_FINISHED) {
6179 /* mailbox command not success, decrement ndlp
6180 * reference count for this command
6183 mempool_free(mbox, phba->mbox_mem_pool);
6185 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
6186 "0253 Register VPI: Can't send mbox\n");
6190 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
6191 "0254 Register VPI: no memory\n");
6197 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6198 spin_lock_irq(shost->host_lock);
6199 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
6200 spin_unlock_irq(shost->host_lock);
6205 * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer
6206 * @phba: pointer to lpfc hba data structure.
6208 * This routine cancels the retry delay timers to all the vports.
6211 lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba)
6213 struct lpfc_vport **vports;
6214 struct lpfc_nodelist *ndlp;
6215 uint32_t link_state;
6218 /* Treat this failure as linkdown for all vports */
6219 link_state = phba->link_state;
6220 lpfc_linkdown(phba);
6221 phba->link_state = link_state;
6223 vports = lpfc_create_vport_work_array(phba);
6226 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
6227 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
6229 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
6230 lpfc_els_flush_cmd(vports[i]);
6232 lpfc_destroy_vport_work_array(phba, vports);
6237 * lpfc_retry_pport_discovery - Start timer to retry FLOGI.
6238 * @phba: pointer to lpfc hba data structure.
6240 * This routine abort all pending discovery commands and
6241 * start a timer to retry FLOGI for the physical port
6245 lpfc_retry_pport_discovery(struct lpfc_hba *phba)
6247 struct lpfc_nodelist *ndlp;
6248 struct Scsi_Host *shost;
6250 /* Cancel the all vports retry delay retry timers */
6251 lpfc_cancel_all_vport_retry_delay_timer(phba);
6253 /* If fabric require FLOGI, then re-instantiate physical login */
6254 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
6258 shost = lpfc_shost_from_vport(phba->pport);
6259 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
6260 spin_lock_irq(shost->host_lock);
6261 ndlp->nlp_flag |= NLP_DELAY_TMO;
6262 spin_unlock_irq(shost->host_lock);
6263 ndlp->nlp_last_elscmd = ELS_CMD_FLOGI;
6264 phba->pport->port_state = LPFC_FLOGI;
6269 * lpfc_fabric_login_reqd - Check if FLOGI required.
6270 * @phba: pointer to lpfc hba data structure.
6271 * @cmdiocb: pointer to FDISC command iocb.
6272 * @rspiocb: pointer to FDISC response iocb.
6274 * This routine checks if a FLOGI is reguired for FDISC
6278 lpfc_fabric_login_reqd(struct lpfc_hba *phba,
6279 struct lpfc_iocbq *cmdiocb,
6280 struct lpfc_iocbq *rspiocb)
6283 if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) ||
6284 (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED))
6291 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
6292 * @phba: pointer to lpfc hba data structure.
6293 * @cmdiocb: pointer to lpfc command iocb data structure.
6294 * @rspiocb: pointer to lpfc response iocb data structure.
6296 * This routine is the completion callback function to a Fabric Discover
6297 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
6298 * single threaded, each FDISC completion callback function will reset
6299 * the discovery timer for all vports such that the timers will not get
6300 * unnecessary timeout. The function checks the FDISC IOCB status. If error
6301 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
6302 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
6303 * assigned to the vport has been changed with the completion of the FDISC
6304 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
6305 * are unregistered from the HBA, and then the lpfc_register_new_vport()
6306 * routine is invoked to register new vport with the HBA. Otherwise, the
6307 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
6308 * Server for State Change Request (SCR).
6311 lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
6312 struct lpfc_iocbq *rspiocb)
6314 struct lpfc_vport *vport = cmdiocb->vport;
6315 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6316 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
6317 struct lpfc_nodelist *np;
6318 struct lpfc_nodelist *next_np;
6319 IOCB_t *irsp = &rspiocb->iocb;
6320 struct lpfc_iocbq *piocb;
6322 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6323 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
6324 irsp->ulpStatus, irsp->un.ulpWord[4],
6326 /* Since all FDISCs are being single threaded, we
6327 * must reset the discovery timer for ALL vports
6328 * waiting to send FDISC when one completes.
6330 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
6331 lpfc_set_disctmo(piocb->vport);
6334 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6335 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
6336 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
6338 if (irsp->ulpStatus) {
6340 if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) {
6341 lpfc_retry_pport_discovery(phba);
6345 /* Check for retry */
6346 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
6349 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6350 "0126 FDISC failed. (%d/%d)\n",
6351 irsp->ulpStatus, irsp->un.ulpWord[4]);
6354 spin_lock_irq(shost->host_lock);
6355 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
6356 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
6357 vport->fc_flag |= FC_FABRIC;
6358 if (vport->phba->fc_topology == TOPOLOGY_LOOP)
6359 vport->fc_flag |= FC_PUBLIC_LOOP;
6360 spin_unlock_irq(shost->host_lock);
6362 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
6363 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
6364 if ((vport->fc_prevDID != vport->fc_myDID) &&
6365 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
6366 /* If our NportID changed, we need to ensure all
6367 * remaining NPORTs get unreg_login'ed so we can
6370 list_for_each_entry_safe(np, next_np,
6371 &vport->fc_nodes, nlp_listp) {
6372 if (!NLP_CHK_NODE_ACT(ndlp) ||
6373 (np->nlp_state != NLP_STE_NPR_NODE) ||
6374 !(np->nlp_flag & NLP_NPR_ADISC))
6376 spin_lock_irq(shost->host_lock);
6377 np->nlp_flag &= ~NLP_NPR_ADISC;
6378 spin_unlock_irq(shost->host_lock);
6379 lpfc_unreg_rpi(vport, np);
6381 lpfc_cleanup_pending_mbox(vport);
6382 lpfc_mbx_unreg_vpi(vport);
6383 spin_lock_irq(shost->host_lock);
6384 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
6385 if (phba->sli_rev == LPFC_SLI_REV4)
6386 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
6388 vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG;
6389 spin_unlock_irq(shost->host_lock);
6392 if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)
6393 lpfc_issue_init_vpi(vport);
6394 else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
6395 lpfc_register_new_vport(phba, vport, ndlp);
6397 lpfc_do_scr_ns_plogi(phba, vport);
6400 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6401 /* Cancel discovery timer */
6402 lpfc_can_disctmo(vport);
6405 lpfc_els_free_iocb(phba, cmdiocb);
6409 * lpfc_issue_els_fdisc - Issue a fdisc iocb command
6410 * @vport: pointer to a virtual N_Port data structure.
6411 * @ndlp: pointer to a node-list data structure.
6412 * @retry: number of retries to the command IOCB.
6414 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
6415 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
6416 * routine to issue the IOCB, which makes sure only one outstanding fabric
6417 * IOCB will be sent off HBA at any given time.
6419 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6420 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6421 * will be stored into the context1 field of the IOCB for the completion
6422 * callback function to the FDISC ELS command.
6425 * 0 - Successfully issued fdisc iocb command
6426 * 1 - Failed to issue fdisc iocb command
6429 lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
6432 struct lpfc_hba *phba = vport->phba;
6434 struct lpfc_iocbq *elsiocb;
6435 struct serv_parm *sp;
6438 int did = ndlp->nlp_DID;
6441 vport->port_state = LPFC_FDISC;
6442 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
6443 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
6446 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6447 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6448 "0255 Issue FDISC: no IOCB\n");
6452 icmd = &elsiocb->iocb;
6453 icmd->un.elsreq64.myID = 0;
6454 icmd->un.elsreq64.fl = 1;
6456 if (phba->sli_rev == LPFC_SLI_REV4) {
6457 /* FDISC needs to be 1 for WQE VPI */
6458 elsiocb->iocb.ulpCt_h = (SLI4_CT_VPI >> 1) & 1;
6459 elsiocb->iocb.ulpCt_l = SLI4_CT_VPI & 1 ;
6460 /* Set the ulpContext to the vpi */
6461 elsiocb->iocb.ulpContext = vport->vpi + phba->vpi_base;
6463 /* For FDISC, Let FDISC rsp set the NPortID for this VPI */
6468 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6469 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
6470 pcmd += sizeof(uint32_t); /* CSP Word 1 */
6471 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
6472 sp = (struct serv_parm *) pcmd;
6473 /* Setup CSPs accordingly for Fabric */
6474 sp->cmn.e_d_tov = 0;
6475 sp->cmn.w2.r_a_tov = 0;
6476 sp->cls1.classValid = 0;
6477 sp->cls2.seqDelivery = 1;
6478 sp->cls3.seqDelivery = 1;
6480 pcmd += sizeof(uint32_t); /* CSP Word 2 */
6481 pcmd += sizeof(uint32_t); /* CSP Word 3 */
6482 pcmd += sizeof(uint32_t); /* CSP Word 4 */
6483 pcmd += sizeof(uint32_t); /* Port Name */
6484 memcpy(pcmd, &vport->fc_portname, 8);
6485 pcmd += sizeof(uint32_t); /* Node Name */
6486 pcmd += sizeof(uint32_t); /* Node Name */
6487 memcpy(pcmd, &vport->fc_nodename, 8);
6489 lpfc_set_disctmo(vport);
6491 phba->fc_stat.elsXmitFDISC++;
6492 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
6494 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6495 "Issue FDISC: did:x%x",
6498 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
6499 if (rc == IOCB_ERROR) {
6500 lpfc_els_free_iocb(phba, elsiocb);
6501 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6502 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6503 "0256 Issue FDISC: Cannot send IOCB\n");
6506 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
6511 * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
6512 * @phba: pointer to lpfc hba data structure.
6513 * @cmdiocb: pointer to lpfc command iocb data structure.
6514 * @rspiocb: pointer to lpfc response iocb data structure.
6516 * This routine is the completion callback function to the issuing of a LOGO
6517 * ELS command off a vport. It frees the command IOCB and then decrement the
6518 * reference count held on ndlp for this completion function, indicating that
6519 * the reference to the ndlp is no long needed. Note that the
6520 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
6521 * callback function and an additional explicit ndlp reference decrementation
6522 * will trigger the actual release of the ndlp.
6525 lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
6526 struct lpfc_iocbq *rspiocb)
6528 struct lpfc_vport *vport = cmdiocb->vport;
6530 struct lpfc_nodelist *ndlp;
6531 ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
6533 irsp = &rspiocb->iocb;
6534 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6535 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
6536 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
6538 lpfc_els_free_iocb(phba, cmdiocb);
6539 vport->unreg_vpi_cmpl = VPORT_ERROR;
6541 /* Trigger the release of the ndlp after logo */
6546 * lpfc_issue_els_npiv_logo - Issue a logo off a vport
6547 * @vport: pointer to a virtual N_Port data structure.
6548 * @ndlp: pointer to a node-list data structure.
6550 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
6552 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6553 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6554 * will be stored into the context1 field of the IOCB for the completion
6555 * callback function to the LOGO ELS command.
6558 * 0 - Successfully issued logo off the @vport
6559 * 1 - Failed to issue logo off the @vport
6562 lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
6564 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6565 struct lpfc_hba *phba = vport->phba;
6567 struct lpfc_iocbq *elsiocb;
6571 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
6572 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
6577 icmd = &elsiocb->iocb;
6578 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6579 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
6580 pcmd += sizeof(uint32_t);
6582 /* Fill in LOGO payload */
6583 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
6584 pcmd += sizeof(uint32_t);
6585 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
6587 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6588 "Issue LOGO npiv did:x%x flg:x%x",
6589 ndlp->nlp_DID, ndlp->nlp_flag, 0);
6591 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
6592 spin_lock_irq(shost->host_lock);
6593 ndlp->nlp_flag |= NLP_LOGO_SND;
6594 spin_unlock_irq(shost->host_lock);
6595 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
6597 spin_lock_irq(shost->host_lock);
6598 ndlp->nlp_flag &= ~NLP_LOGO_SND;
6599 spin_unlock_irq(shost->host_lock);
6600 lpfc_els_free_iocb(phba, elsiocb);
6607 * lpfc_fabric_block_timeout - Handler function to the fabric block timer
6608 * @ptr: holder for the timer function associated data.
6610 * This routine is invoked by the fabric iocb block timer after
6611 * timeout. It posts the fabric iocb block timeout event by setting the
6612 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
6613 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
6614 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
6615 * posted event WORKER_FABRIC_BLOCK_TMO.
6618 lpfc_fabric_block_timeout(unsigned long ptr)
6620 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
6621 unsigned long iflags;
6622 uint32_t tmo_posted;
6624 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
6625 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
6627 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
6628 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
6631 lpfc_worker_wake_up(phba);
6636 * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
6637 * @phba: pointer to lpfc hba data structure.
6639 * This routine issues one fabric iocb from the driver internal list to
6640 * the HBA. It first checks whether it's ready to issue one fabric iocb to
6641 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
6642 * remove one pending fabric iocb from the driver internal list and invokes
6643 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
6646 lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
6648 struct lpfc_iocbq *iocb;
6649 unsigned long iflags;
6655 spin_lock_irqsave(&phba->hbalock, iflags);
6656 /* Post any pending iocb to the SLI layer */
6657 if (atomic_read(&phba->fabric_iocb_count) == 0) {
6658 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
6661 /* Increment fabric iocb count to hold the position */
6662 atomic_inc(&phba->fabric_iocb_count);
6664 spin_unlock_irqrestore(&phba->hbalock, iflags);
6666 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
6667 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
6668 iocb->iocb_flag |= LPFC_IO_FABRIC;
6670 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
6671 "Fabric sched1: ste:x%x",
6672 iocb->vport->port_state, 0, 0);
6674 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
6676 if (ret == IOCB_ERROR) {
6677 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
6678 iocb->fabric_iocb_cmpl = NULL;
6679 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
6681 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
6682 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
6683 iocb->iocb_cmpl(phba, iocb, iocb);
6685 atomic_dec(&phba->fabric_iocb_count);
6694 * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
6695 * @phba: pointer to lpfc hba data structure.
6697 * This routine unblocks the issuing fabric iocb command. The function
6698 * will clear the fabric iocb block bit and then invoke the routine
6699 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
6700 * from the driver internal fabric iocb list.
6703 lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
6705 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
6707 lpfc_resume_fabric_iocbs(phba);
6712 * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
6713 * @phba: pointer to lpfc hba data structure.
6715 * This routine blocks the issuing fabric iocb for a specified amount of
6716 * time (currently 100 ms). This is done by set the fabric iocb block bit
6717 * and set up a timeout timer for 100ms. When the block bit is set, no more
6718 * fabric iocb will be issued out of the HBA.
6721 lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
6725 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
6726 /* Start a timer to unblock fabric iocbs after 100ms */
6728 mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 );
6734 * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
6735 * @phba: pointer to lpfc hba data structure.
6736 * @cmdiocb: pointer to lpfc command iocb data structure.
6737 * @rspiocb: pointer to lpfc response iocb data structure.
6739 * This routine is the callback function that is put to the fabric iocb's
6740 * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
6741 * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
6742 * function first restores and invokes the original iocb's callback function
6743 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
6744 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
6747 lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
6748 struct lpfc_iocbq *rspiocb)
6752 if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC)
6755 switch (rspiocb->iocb.ulpStatus) {
6756 case IOSTAT_NPORT_RJT:
6757 case IOSTAT_FABRIC_RJT:
6758 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
6759 lpfc_block_fabric_iocbs(phba);
6763 case IOSTAT_NPORT_BSY:
6764 case IOSTAT_FABRIC_BSY:
6765 lpfc_block_fabric_iocbs(phba);
6769 stat.un.lsRjtError =
6770 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
6771 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
6772 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
6773 lpfc_block_fabric_iocbs(phba);
6777 if (atomic_read(&phba->fabric_iocb_count) == 0)
6780 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
6781 cmdiocb->fabric_iocb_cmpl = NULL;
6782 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
6783 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
6785 atomic_dec(&phba->fabric_iocb_count);
6786 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
6787 /* Post any pending iocbs to HBA */
6788 lpfc_resume_fabric_iocbs(phba);
6793 * lpfc_issue_fabric_iocb - Issue a fabric iocb command
6794 * @phba: pointer to lpfc hba data structure.
6795 * @iocb: pointer to lpfc command iocb data structure.
6797 * This routine is used as the top-level API for issuing a fabric iocb command
6798 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
6799 * function makes sure that only one fabric bound iocb will be outstanding at
6800 * any given time. As such, this function will first check to see whether there
6801 * is already an outstanding fabric iocb on the wire. If so, it will put the
6802 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
6803 * issued later. Otherwise, it will issue the iocb on the wire and update the
6804 * fabric iocb count it indicate that there is one fabric iocb on the wire.
6806 * Note, this implementation has a potential sending out fabric IOCBs out of
6807 * order. The problem is caused by the construction of the "ready" boolen does
6808 * not include the condition that the internal fabric IOCB list is empty. As
6809 * such, it is possible a fabric IOCB issued by this routine might be "jump"
6810 * ahead of the fabric IOCBs in the internal list.
6813 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
6814 * IOCB_ERROR - failed to issue fabric iocb
6817 lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
6819 unsigned long iflags;
6823 if (atomic_read(&phba->fabric_iocb_count) > 1)
6826 spin_lock_irqsave(&phba->hbalock, iflags);
6827 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
6828 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
6831 /* Increment fabric iocb count to hold the position */
6832 atomic_inc(&phba->fabric_iocb_count);
6833 spin_unlock_irqrestore(&phba->hbalock, iflags);
6835 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
6836 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
6837 iocb->iocb_flag |= LPFC_IO_FABRIC;
6839 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
6840 "Fabric sched2: ste:x%x",
6841 iocb->vport->port_state, 0, 0);
6843 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
6845 if (ret == IOCB_ERROR) {
6846 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
6847 iocb->fabric_iocb_cmpl = NULL;
6848 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
6849 atomic_dec(&phba->fabric_iocb_count);
6852 spin_lock_irqsave(&phba->hbalock, iflags);
6853 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
6854 spin_unlock_irqrestore(&phba->hbalock, iflags);
6861 * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
6862 * @vport: pointer to a virtual N_Port data structure.
6864 * This routine aborts all the IOCBs associated with a @vport from the
6865 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
6866 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
6867 * list, removes each IOCB associated with the @vport off the list, set the
6868 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
6869 * associated with the IOCB.
6871 static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
6873 LIST_HEAD(completions);
6874 struct lpfc_hba *phba = vport->phba;
6875 struct lpfc_iocbq *tmp_iocb, *piocb;
6877 spin_lock_irq(&phba->hbalock);
6878 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
6881 if (piocb->vport != vport)
6884 list_move_tail(&piocb->list, &completions);
6886 spin_unlock_irq(&phba->hbalock);
6888 /* Cancel all the IOCBs from the completions list */
6889 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6894 * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
6895 * @ndlp: pointer to a node-list data structure.
6897 * This routine aborts all the IOCBs associated with an @ndlp from the
6898 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
6899 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
6900 * list, removes each IOCB associated with the @ndlp off the list, set the
6901 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
6902 * associated with the IOCB.
6904 void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
6906 LIST_HEAD(completions);
6907 struct lpfc_hba *phba = ndlp->phba;
6908 struct lpfc_iocbq *tmp_iocb, *piocb;
6909 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
6911 spin_lock_irq(&phba->hbalock);
6912 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
6914 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
6916 list_move_tail(&piocb->list, &completions);
6919 spin_unlock_irq(&phba->hbalock);
6921 /* Cancel all the IOCBs from the completions list */
6922 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6927 * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
6928 * @phba: pointer to lpfc hba data structure.
6930 * This routine aborts all the IOCBs currently on the driver internal
6931 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
6932 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
6933 * list, removes IOCBs off the list, set the status feild to
6934 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
6937 void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
6939 LIST_HEAD(completions);
6941 spin_lock_irq(&phba->hbalock);
6942 list_splice_init(&phba->fabric_iocb_list, &completions);
6943 spin_unlock_irq(&phba->hbalock);
6945 /* Cancel all the IOCBs from the completions list */
6946 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6951 * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
6952 * @phba: pointer to lpfc hba data structure.
6953 * @axri: pointer to the els xri abort wcqe structure.
6955 * This routine is invoked by the worker thread to process a SLI4 slow-path
6959 lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba,
6960 struct sli4_wcqe_xri_aborted *axri)
6962 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
6963 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
6964 unsigned long iflag = 0;
6965 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
6967 spin_lock_irqsave(&phba->hbalock, iflag);
6968 spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
6969 list_for_each_entry_safe(sglq_entry, sglq_next,
6970 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
6971 if (sglq_entry->sli4_xritag == xri) {
6972 list_del(&sglq_entry->list);
6973 list_add_tail(&sglq_entry->list,
6974 &phba->sli4_hba.lpfc_sgl_list);
6975 sglq_entry->state = SGL_FREED;
6976 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
6977 spin_unlock_irqrestore(&phba->hbalock, iflag);
6979 /* Check if TXQ queue needs to be serviced */
6981 lpfc_worker_wake_up(phba);
6985 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
6986 sglq_entry = __lpfc_get_active_sglq(phba, xri);
6987 if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) {
6988 spin_unlock_irqrestore(&phba->hbalock, iflag);
6991 sglq_entry->state = SGL_XRI_ABORTED;
6992 spin_unlock_irqrestore(&phba->hbalock, iflag);