1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2008 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/interrupt.h>
26 #include <scsi/scsi.h>
27 #include <scsi/scsi_device.h>
28 #include <scsi/scsi_host.h>
29 #include <scsi/scsi_transport_fc.h>
33 #include "lpfc_disc.h"
34 #include "lpfc_scsi.h"
36 #include "lpfc_logmsg.h"
37 #include "lpfc_crtn.h"
38 #include "lpfc_vport.h"
39 #include "lpfc_debugfs.h"
41 static int lpfc_els_retry(struct lpfc_hba *, struct lpfc_iocbq *,
43 static void lpfc_cmpl_fabric_iocb(struct lpfc_hba *, struct lpfc_iocbq *,
45 static void lpfc_fabric_abort_vport(struct lpfc_vport *vport);
46 static int lpfc_issue_els_fdisc(struct lpfc_vport *vport,
47 struct lpfc_nodelist *ndlp, uint8_t retry);
48 static int lpfc_issue_fabric_iocb(struct lpfc_hba *phba,
49 struct lpfc_iocbq *iocb);
50 static void lpfc_register_new_vport(struct lpfc_hba *phba,
51 struct lpfc_vport *vport,
52 struct lpfc_nodelist *ndlp);
54 static int lpfc_max_els_tries = 3;
57 * lpfc_els_chk_latt: Check host link attention event for a vport.
58 * @vport: pointer to a host virtual N_Port data structure.
60 * This routine checks whether there is an outstanding host link
61 * attention event during the discovery process with the @vport. It is done
62 * by reading the HBA's Host Attention (HA) register. If there is any host
63 * link attention events during this @vport's discovery process, the @vport
64 * shall be marked as FC_ABORT_DISCOVERY, a host link attention clear shall
65 * be issued if the link state is not already in host link cleared state,
66 * and a return code shall indicate whether the host link attention event
69 * Note that, if either the host link is in state LPFC_LINK_DOWN or @vport
70 * state in LPFC_VPORT_READY, the request for checking host link attention
71 * event will be ignored and a return code shall indicate no host link
72 * attention event had happened.
75 * 0 - no host link attention event happened
76 * 1 - host link attention event happened
79 lpfc_els_chk_latt(struct lpfc_vport *vport)
81 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
82 struct lpfc_hba *phba = vport->phba;
85 if (vport->port_state >= LPFC_VPORT_READY ||
86 phba->link_state == LPFC_LINK_DOWN)
89 /* Read the HBA Host Attention Register */
90 ha_copy = readl(phba->HAregaddr);
92 if (!(ha_copy & HA_LATT))
95 /* Pending Link Event during Discovery */
96 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
97 "0237 Pending Link Event during "
98 "Discovery: State x%x\n",
99 phba->pport->port_state);
101 /* CLEAR_LA should re-enable link attention events and
102 * we should then imediately take a LATT event. The
103 * LATT processing should call lpfc_linkdown() which
104 * will cleanup any left over in-progress discovery
107 spin_lock_irq(shost->host_lock);
108 vport->fc_flag |= FC_ABORT_DISCOVERY;
109 spin_unlock_irq(shost->host_lock);
111 if (phba->link_state != LPFC_CLEAR_LA)
112 lpfc_issue_clear_la(phba, vport);
118 * lpfc_prep_els_iocb: Allocate and prepare a lpfc iocb data structure.
119 * @vport: pointer to a host virtual N_Port data structure.
120 * @expectRsp: flag indicating whether response is expected.
121 * @cmdSize: size of the ELS command.
122 * @retry: number of retries to the command IOCB when it fails.
123 * @ndlp: pointer to a node-list data structure.
124 * @did: destination identifier.
125 * @elscmd: the ELS command code.
127 * This routine is used for allocating a lpfc-IOCB data structure from
128 * the driver lpfc-IOCB free-list and prepare the IOCB with the parameters
129 * passed into the routine for discovery state machine to issue an Extended
130 * Link Service (ELS) commands. It is a generic lpfc-IOCB allocation
131 * and preparation routine that is used by all the discovery state machine
132 * routines and the ELS command-specific fields will be later set up by
133 * the individual discovery machine routines after calling this routine
134 * allocating and preparing a generic IOCB data structure. It fills in the
135 * Buffer Descriptor Entries (BDEs), allocates buffers for both command
136 * payload and response payload (if expected). The reference count on the
137 * ndlp is incremented by 1 and the reference to the ndlp is put into
138 * context1 of the IOCB data structure for this IOCB to hold the ndlp
139 * reference for the command's callback function to access later.
142 * Pointer to the newly allocated/prepared els iocb data structure
143 * NULL - when els iocb data structure allocation/preparation failed
145 static struct lpfc_iocbq *
146 lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp,
147 uint16_t cmdSize, uint8_t retry,
148 struct lpfc_nodelist *ndlp, uint32_t did,
151 struct lpfc_hba *phba = vport->phba;
152 struct lpfc_iocbq *elsiocb;
153 struct lpfc_dmabuf *pcmd, *prsp, *pbuflist;
154 struct ulp_bde64 *bpl;
158 if (!lpfc_is_link_up(phba))
161 /* Allocate buffer for command iocb */
162 elsiocb = lpfc_sli_get_iocbq(phba);
167 icmd = &elsiocb->iocb;
169 /* fill in BDEs for command */
170 /* Allocate buffer for command payload */
171 pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
173 pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys);
174 if (!pcmd || !pcmd->virt)
175 goto els_iocb_free_pcmb_exit;
177 INIT_LIST_HEAD(&pcmd->list);
179 /* Allocate buffer for response payload */
181 prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
183 prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
185 if (!prsp || !prsp->virt)
186 goto els_iocb_free_prsp_exit;
187 INIT_LIST_HEAD(&prsp->list);
191 /* Allocate buffer for Buffer ptr list */
192 pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
194 pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
196 if (!pbuflist || !pbuflist->virt)
197 goto els_iocb_free_pbuf_exit;
199 INIT_LIST_HEAD(&pbuflist->list);
201 icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
202 icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
203 icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BDL;
204 icmd->un.elsreq64.remoteID = did; /* DID */
206 icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64));
207 icmd->ulpCommand = CMD_ELS_REQUEST64_CR;
208 icmd->ulpTimeout = phba->fc_ratov * 2;
210 icmd->un.elsreq64.bdl.bdeSize = sizeof(struct ulp_bde64);
211 icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX;
213 icmd->ulpBdeCount = 1;
215 icmd->ulpClass = CLASS3;
217 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
218 icmd->un.elsreq64.myID = vport->fc_myDID;
220 /* For ELS_REQUEST64_CR, use the VPI by default */
221 icmd->ulpContext = vport->vpi;
226 bpl = (struct ulp_bde64 *) pbuflist->virt;
227 bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys));
228 bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys));
229 bpl->tus.f.bdeSize = cmdSize;
230 bpl->tus.f.bdeFlags = 0;
231 bpl->tus.w = le32_to_cpu(bpl->tus.w);
235 bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys));
236 bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys));
237 bpl->tus.f.bdeSize = FCELSSIZE;
238 bpl->tus.f.bdeFlags = BUFF_USE_RCV;
239 bpl->tus.w = le32_to_cpu(bpl->tus.w);
242 /* prevent preparing iocb with NULL ndlp reference */
243 elsiocb->context1 = lpfc_nlp_get(ndlp);
244 if (!elsiocb->context1)
245 goto els_iocb_free_pbuf_exit;
246 elsiocb->context2 = pcmd;
247 elsiocb->context3 = pbuflist;
248 elsiocb->retry = retry;
249 elsiocb->vport = vport;
250 elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT;
253 list_add(&prsp->list, &pcmd->list);
256 /* Xmit ELS command <elsCmd> to remote NPORT <did> */
257 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
258 "0116 Xmit ELS command x%x to remote "
259 "NPORT x%x I/O tag: x%x, port state: x%x\n",
260 elscmd, did, elsiocb->iotag,
263 /* Xmit ELS response <elsCmd> to remote NPORT <did> */
264 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
265 "0117 Xmit ELS response x%x to remote "
266 "NPORT x%x I/O tag: x%x, size: x%x\n",
267 elscmd, ndlp->nlp_DID, elsiocb->iotag,
272 els_iocb_free_pbuf_exit:
273 lpfc_mbuf_free(phba, prsp->virt, prsp->phys);
276 els_iocb_free_prsp_exit:
277 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
280 els_iocb_free_pcmb_exit:
282 lpfc_sli_release_iocbq(phba, elsiocb);
287 * lpfc_issue_fabric_reglogin: Issue fabric registration login for a vport.
288 * @vport: pointer to a host virtual N_Port data structure.
290 * This routine issues a fabric registration login for a @vport. An
291 * active ndlp node with Fabric_DID must already exist for this @vport.
292 * The routine invokes two mailbox commands to carry out fabric registration
293 * login through the HBA firmware: the first mailbox command requests the
294 * HBA to perform link configuration for the @vport; and the second mailbox
295 * command requests the HBA to perform the actual fabric registration login
299 * 0 - successfully issued fabric registration login for @vport
300 * -ENXIO -- failed to issue fabric registration login for @vport
303 lpfc_issue_fabric_reglogin(struct lpfc_vport *vport)
305 struct lpfc_hba *phba = vport->phba;
307 struct lpfc_dmabuf *mp;
308 struct lpfc_nodelist *ndlp;
309 struct serv_parm *sp;
313 sp = &phba->fc_fabparam;
314 ndlp = lpfc_findnode_did(vport, Fabric_DID);
315 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
320 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
326 vport->port_state = LPFC_FABRIC_CFG_LINK;
327 lpfc_config_link(phba, mbox);
328 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
331 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
332 if (rc == MBX_NOT_FINISHED) {
337 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
342 rc = lpfc_reg_login(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox,
349 mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login;
351 /* increment the reference count on ndlp to hold reference
352 * for the callback routine.
354 mbox->context2 = lpfc_nlp_get(ndlp);
356 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
357 if (rc == MBX_NOT_FINISHED) {
359 goto fail_issue_reg_login;
364 fail_issue_reg_login:
365 /* decrement the reference count on ndlp just incremented
366 * for the failed mbox command.
369 mp = (struct lpfc_dmabuf *) mbox->context1;
370 lpfc_mbuf_free(phba, mp->virt, mp->phys);
373 mempool_free(mbox, phba->mbox_mem_pool);
376 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
377 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
378 "0249 Cannot issue Register Fabric login: Err %d\n", err);
383 * lpfc_cmpl_els_flogi_fabric: Completion function for flogi to a fabric port.
384 * @vport: pointer to a host virtual N_Port data structure.
385 * @ndlp: pointer to a node-list data structure.
386 * @sp: pointer to service parameter data structure.
387 * @irsp: pointer to the IOCB within the lpfc response IOCB.
389 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
390 * function to handle the completion of a Fabric Login (FLOGI) into a fabric
391 * port in a fabric topology. It properly sets up the parameters to the @ndlp
392 * from the IOCB response. It also check the newly assigned N_Port ID to the
393 * @vport against the previously assigned N_Port ID. If it is different from
394 * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine
395 * is invoked on all the remaining nodes with the @vport to unregister the
396 * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin()
397 * is invoked to register login to the fabric.
400 * 0 - Success (currently, always return 0)
403 lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
404 struct serv_parm *sp, IOCB_t *irsp)
406 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
407 struct lpfc_hba *phba = vport->phba;
408 struct lpfc_nodelist *np;
409 struct lpfc_nodelist *next_np;
411 spin_lock_irq(shost->host_lock);
412 vport->fc_flag |= FC_FABRIC;
413 spin_unlock_irq(shost->host_lock);
415 phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
416 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
417 phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
419 phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
421 if (phba->fc_topology == TOPOLOGY_LOOP) {
422 spin_lock_irq(shost->host_lock);
423 vport->fc_flag |= FC_PUBLIC_LOOP;
424 spin_unlock_irq(shost->host_lock);
427 * If we are a N-port connected to a Fabric, fixup sparam's so
428 * logins to devices on remote loops work.
430 vport->fc_sparam.cmn.altBbCredit = 1;
433 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
434 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
435 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name));
436 ndlp->nlp_class_sup = 0;
437 if (sp->cls1.classValid)
438 ndlp->nlp_class_sup |= FC_COS_CLASS1;
439 if (sp->cls2.classValid)
440 ndlp->nlp_class_sup |= FC_COS_CLASS2;
441 if (sp->cls3.classValid)
442 ndlp->nlp_class_sup |= FC_COS_CLASS3;
443 if (sp->cls4.classValid)
444 ndlp->nlp_class_sup |= FC_COS_CLASS4;
445 ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
446 sp->cmn.bbRcvSizeLsb;
447 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
449 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
450 if (sp->cmn.response_multiple_NPort) {
451 lpfc_printf_vlog(vport, KERN_WARNING,
453 "1816 FLOGI NPIV supported, "
454 "response data 0x%x\n",
455 sp->cmn.response_multiple_NPort);
456 phba->link_flag |= LS_NPIV_FAB_SUPPORTED;
458 /* Because we asked f/w for NPIV it still expects us
459 to call reg_vnpid atleast for the physcial host */
460 lpfc_printf_vlog(vport, KERN_WARNING,
462 "1817 Fabric does not support NPIV "
463 "- configuring single port mode.\n");
464 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
468 if ((vport->fc_prevDID != vport->fc_myDID) &&
469 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
471 /* If our NportID changed, we need to ensure all
472 * remaining NPORTs get unreg_login'ed.
474 list_for_each_entry_safe(np, next_np,
475 &vport->fc_nodes, nlp_listp) {
476 if (!NLP_CHK_NODE_ACT(ndlp))
478 if ((np->nlp_state != NLP_STE_NPR_NODE) ||
479 !(np->nlp_flag & NLP_NPR_ADISC))
481 spin_lock_irq(shost->host_lock);
482 np->nlp_flag &= ~NLP_NPR_ADISC;
483 spin_unlock_irq(shost->host_lock);
484 lpfc_unreg_rpi(vport, np);
486 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
487 lpfc_mbx_unreg_vpi(vport);
488 spin_lock_irq(shost->host_lock);
489 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
490 spin_unlock_irq(shost->host_lock);
494 lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
496 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED &&
497 vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) {
498 lpfc_register_new_vport(phba, vport, ndlp);
501 lpfc_issue_fabric_reglogin(vport);
506 * lpfc_cmpl_els_flogi_nport: Completion function for flogi to an N_Port.
507 * @vport: pointer to a host virtual N_Port data structure.
508 * @ndlp: pointer to a node-list data structure.
509 * @sp: pointer to service parameter data structure.
511 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
512 * function to handle the completion of a Fabric Login (FLOGI) into an N_Port
513 * in a point-to-point topology. First, the @vport's N_Port Name is compared
514 * with the received N_Port Name: if the @vport's N_Port Name is greater than
515 * the received N_Port Name lexicographically, this node shall assign local
516 * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and
517 * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise,
518 * this node shall just wait for the remote node to issue PLOGI and assign
526 lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
527 struct serv_parm *sp)
529 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
530 struct lpfc_hba *phba = vport->phba;
534 spin_lock_irq(shost->host_lock);
535 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
536 spin_unlock_irq(shost->host_lock);
538 phba->fc_edtov = FF_DEF_EDTOV;
539 phba->fc_ratov = FF_DEF_RATOV;
540 rc = memcmp(&vport->fc_portname, &sp->portName,
541 sizeof(vport->fc_portname));
543 /* This side will initiate the PLOGI */
544 spin_lock_irq(shost->host_lock);
545 vport->fc_flag |= FC_PT2PT_PLOGI;
546 spin_unlock_irq(shost->host_lock);
549 * N_Port ID cannot be 0, set our to LocalID the other
550 * side will be RemoteID.
555 vport->fc_myDID = PT2PT_LocalID;
557 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
561 lpfc_config_link(phba, mbox);
563 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
565 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
566 if (rc == MBX_NOT_FINISHED) {
567 mempool_free(mbox, phba->mbox_mem_pool);
570 /* Decrement ndlp reference count indicating that ndlp can be
571 * safely released when other references to it are done.
575 ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
578 * Cannot find existing Fabric ndlp, so allocate a
581 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
584 lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID);
585 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
586 ndlp = lpfc_enable_node(vport, ndlp,
587 NLP_STE_UNUSED_NODE);
592 memcpy(&ndlp->nlp_portname, &sp->portName,
593 sizeof(struct lpfc_name));
594 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
595 sizeof(struct lpfc_name));
596 /* Set state will put ndlp onto node list if not already done */
597 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
598 spin_lock_irq(shost->host_lock);
599 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
600 spin_unlock_irq(shost->host_lock);
602 /* This side will wait for the PLOGI, decrement ndlp reference
603 * count indicating that ndlp can be released when other
604 * references to it are done.
608 /* If we are pt2pt with another NPort, force NPIV off! */
609 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
611 spin_lock_irq(shost->host_lock);
612 vport->fc_flag |= FC_PT2PT;
613 spin_unlock_irq(shost->host_lock);
615 /* Start discovery - this should just do CLEAR_LA */
616 lpfc_disc_start(vport);
623 * lpfc_cmpl_els_flogi: Completion callback function for flogi.
624 * @phba: pointer to lpfc hba data structure.
625 * @cmdiocb: pointer to lpfc command iocb data structure.
626 * @rspiocb: pointer to lpfc response iocb data structure.
628 * This routine is the top-level completion callback function for issuing
629 * a Fabric Login (FLOGI) command. If the response IOCB reported error,
630 * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If
631 * retry has been made (either immediately or delayed with lpfc_els_retry()
632 * returning 1), the command IOCB will be released and function returned.
633 * If the retry attempt has been given up (possibly reach the maximum
634 * number of retries), one additional decrement of ndlp reference shall be
635 * invoked before going out after releasing the command IOCB. This will
636 * actually release the remote node (Note, lpfc_els_free_iocb() will also
637 * invoke one decrement of ndlp reference count). If no error reported in
638 * the IOCB status, the command Port ID field is used to determine whether
639 * this is a point-to-point topology or a fabric topology: if the Port ID
640 * field is assigned, it is a fabric topology; otherwise, it is a
641 * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or
642 * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the
643 * specific topology completion conditions.
646 lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
647 struct lpfc_iocbq *rspiocb)
649 struct lpfc_vport *vport = cmdiocb->vport;
650 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
651 IOCB_t *irsp = &rspiocb->iocb;
652 struct lpfc_nodelist *ndlp = cmdiocb->context1;
653 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
654 struct serv_parm *sp;
657 /* Check to see if link went down during discovery */
658 if (lpfc_els_chk_latt(vport)) {
659 /* One additional decrement on node reference count to
660 * trigger the release of the node
666 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
667 "FLOGI cmpl: status:x%x/x%x state:x%x",
668 irsp->ulpStatus, irsp->un.ulpWord[4],
671 if (irsp->ulpStatus) {
672 /* Check for retry */
673 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
676 /* FLOGI failed, so there is no fabric */
677 spin_lock_irq(shost->host_lock);
678 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
679 spin_unlock_irq(shost->host_lock);
681 /* If private loop, then allow max outstanding els to be
682 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
683 * alpa map would take too long otherwise.
685 if (phba->alpa_map[0] == 0) {
686 vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
690 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
691 "0100 FLOGI failure Data: x%x x%x "
693 irsp->ulpStatus, irsp->un.ulpWord[4],
699 * The FLogI succeeded. Sync the data for the CPU before
702 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
704 sp = prsp->virt + sizeof(uint32_t);
706 /* FLOGI completes successfully */
707 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
708 "0101 FLOGI completes sucessfully "
709 "Data: x%x x%x x%x x%x\n",
710 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
711 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution);
713 if (vport->port_state == LPFC_FLOGI) {
715 * If Common Service Parameters indicate Nport
716 * we are point to point, if Fport we are Fabric.
719 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
721 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
730 if (!lpfc_error_lost_link(irsp)) {
731 /* FLOGI failed, so just use loop map to make discovery list */
732 lpfc_disc_list_loopmap(vport);
734 /* Start discovery */
735 lpfc_disc_start(vport);
736 } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
737 ((irsp->un.ulpWord[4] != IOERR_SLI_ABORTED) &&
738 (irsp->un.ulpWord[4] != IOERR_SLI_DOWN))) &&
739 (phba->link_state != LPFC_CLEAR_LA)) {
740 /* If FLOGI failed enable link interrupt. */
741 lpfc_issue_clear_la(phba, vport);
744 lpfc_els_free_iocb(phba, cmdiocb);
748 * lpfc_issue_els_flogi: Issue an flogi iocb command for a vport.
749 * @vport: pointer to a host virtual N_Port data structure.
750 * @ndlp: pointer to a node-list data structure.
751 * @retry: number of retries to the command IOCB.
753 * This routine issues a Fabric Login (FLOGI) Request ELS command
754 * for a @vport. The initiator service parameters are put into the payload
755 * of the FLOGI Request IOCB and the top-level callback function pointer
756 * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
757 * function field. The lpfc_issue_fabric_iocb routine is invoked to send
758 * out FLOGI ELS command with one outstanding fabric IOCB at a time.
760 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
761 * will be incremented by 1 for holding the ndlp and the reference to ndlp
762 * will be stored into the context1 field of the IOCB for the completion
763 * callback function to the FLOGI ELS command.
766 * 0 - successfully issued flogi iocb for @vport
767 * 1 - failed to issue flogi iocb for @vport
770 lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
773 struct lpfc_hba *phba = vport->phba;
774 struct serv_parm *sp;
776 struct lpfc_iocbq *elsiocb;
777 struct lpfc_sli_ring *pring;
783 pring = &phba->sli.ring[LPFC_ELS_RING];
785 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
786 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
787 ndlp->nlp_DID, ELS_CMD_FLOGI);
792 icmd = &elsiocb->iocb;
793 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
795 /* For FLOGI request, remainder of payload is service parameters */
796 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
797 pcmd += sizeof(uint32_t);
798 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
799 sp = (struct serv_parm *) pcmd;
801 /* Setup CSPs accordingly for Fabric */
803 sp->cmn.w2.r_a_tov = 0;
804 sp->cls1.classValid = 0;
805 sp->cls2.seqDelivery = 1;
806 sp->cls3.seqDelivery = 1;
807 if (sp->cmn.fcphLow < FC_PH3)
808 sp->cmn.fcphLow = FC_PH3;
809 if (sp->cmn.fcphHigh < FC_PH3)
810 sp->cmn.fcphHigh = FC_PH3;
812 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
813 sp->cmn.request_multiple_Nport = 1;
815 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
820 if (phba->fc_topology != TOPOLOGY_LOOP) {
821 icmd->un.elsreq64.myID = 0;
822 icmd->un.elsreq64.fl = 1;
825 tmo = phba->fc_ratov;
826 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
827 lpfc_set_disctmo(vport);
828 phba->fc_ratov = tmo;
830 phba->fc_stat.elsXmitFLOGI++;
831 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
833 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
834 "Issue FLOGI: opt:x%x",
835 phba->sli3_options, 0, 0);
837 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
838 if (rc == IOCB_ERROR) {
839 lpfc_els_free_iocb(phba, elsiocb);
846 * lpfc_els_abort_flogi: Abort all outstanding flogi iocbs.
847 * @phba: pointer to lpfc hba data structure.
849 * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
850 * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
851 * list and issues an abort IOCB commond on each outstanding IOCB that
852 * contains a active Fabric_DID ndlp. Note that this function is to issue
853 * the abort IOCB command on all the outstanding IOCBs, thus when this
854 * function returns, it does not guarantee all the IOCBs are actually aborted.
857 * 0 - Sucessfully issued abort iocb on all outstanding flogis (Always 0)
860 lpfc_els_abort_flogi(struct lpfc_hba *phba)
862 struct lpfc_sli_ring *pring;
863 struct lpfc_iocbq *iocb, *next_iocb;
864 struct lpfc_nodelist *ndlp;
867 /* Abort outstanding I/O on NPort <nlp_DID> */
868 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
869 "0201 Abort outstanding I/O on NPort x%x\n",
872 pring = &phba->sli.ring[LPFC_ELS_RING];
875 * Check the txcmplq for an iocb that matches the nport the driver is
878 spin_lock_irq(&phba->hbalock);
879 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
881 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR &&
882 icmd->un.elsreq64.bdl.ulpIoTag32) {
883 ndlp = (struct lpfc_nodelist *)(iocb->context1);
884 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
885 (ndlp->nlp_DID == Fabric_DID))
886 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
889 spin_unlock_irq(&phba->hbalock);
895 * lpfc_initial_flogi: Issue an initial fabric login for a vport.
896 * @vport: pointer to a host virtual N_Port data structure.
898 * This routine issues an initial Fabric Login (FLOGI) for the @vport
899 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
900 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
901 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
902 * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
903 * is then invoked with the @vport and the ndlp to perform the FLOGI for the
907 * 0 - failed to issue initial flogi for @vport
908 * 1 - successfully issued initial flogi for @vport
911 lpfc_initial_flogi(struct lpfc_vport *vport)
913 struct lpfc_hba *phba = vport->phba;
914 struct lpfc_nodelist *ndlp;
916 vport->port_state = LPFC_FLOGI;
917 lpfc_set_disctmo(vport);
919 /* First look for the Fabric ndlp */
920 ndlp = lpfc_findnode_did(vport, Fabric_DID);
922 /* Cannot find existing Fabric ndlp, so allocate a new one */
923 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
926 lpfc_nlp_init(vport, ndlp, Fabric_DID);
927 /* Put ndlp onto node list */
928 lpfc_enqueue_node(vport, ndlp);
929 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
930 /* re-setup ndlp without removing from node list */
931 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
936 if (lpfc_issue_els_flogi(vport, ndlp, 0))
937 /* This decrement of reference count to node shall kick off
938 * the release of the node.
946 * lpfc_initial_fdisc: Issue an initial fabric discovery for a vport.
947 * @vport: pointer to a host virtual N_Port data structure.
949 * This routine issues an initial Fabric Discover (FDISC) for the @vport
950 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
951 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
952 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
953 * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
954 * is then invoked with the @vport and the ndlp to perform the FDISC for the
958 * 0 - failed to issue initial fdisc for @vport
959 * 1 - successfully issued initial fdisc for @vport
962 lpfc_initial_fdisc(struct lpfc_vport *vport)
964 struct lpfc_hba *phba = vport->phba;
965 struct lpfc_nodelist *ndlp;
967 /* First look for the Fabric ndlp */
968 ndlp = lpfc_findnode_did(vport, Fabric_DID);
970 /* Cannot find existing Fabric ndlp, so allocate a new one */
971 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
974 lpfc_nlp_init(vport, ndlp, Fabric_DID);
975 /* Put ndlp onto node list */
976 lpfc_enqueue_node(vport, ndlp);
977 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
978 /* re-setup ndlp without removing from node list */
979 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
984 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
985 /* decrement node reference count to trigger the release of
995 * lpfc_more_plogi: Check and issue remaining plogis for a vport.
996 * @vport: pointer to a host virtual N_Port data structure.
998 * This routine checks whether there are more remaining Port Logins
999 * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
1000 * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
1001 * to issue ELS PLOGIs up to the configured discover threads with the
1002 * @vport (@vport->cfg_discovery_threads). The function also decrement
1003 * the @vport's num_disc_node by 1 if it is not already 0.
1006 lpfc_more_plogi(struct lpfc_vport *vport)
1010 if (vport->num_disc_nodes)
1011 vport->num_disc_nodes--;
1013 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
1014 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1015 "0232 Continue discovery with %d PLOGIs to go "
1016 "Data: x%x x%x x%x\n",
1017 vport->num_disc_nodes, vport->fc_plogi_cnt,
1018 vport->fc_flag, vport->port_state);
1019 /* Check to see if there are more PLOGIs to be sent */
1020 if (vport->fc_flag & FC_NLP_MORE)
1021 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
1022 sentplogi = lpfc_els_disc_plogi(vport);
1028 * lpfc_plogi_confirm_nport: Confirm pologi wwpn matches stored ndlp.
1029 * @phba: pointer to lpfc hba data structure.
1030 * @prsp: pointer to response IOCB payload.
1031 * @ndlp: pointer to a node-list data structure.
1033 * This routine checks and indicates whether the WWPN of an N_Port, retrieved
1034 * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
1035 * The following cases are considered N_Port confirmed:
1036 * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
1037 * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
1038 * it does not have WWPN assigned either. If the WWPN is confirmed, the
1039 * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
1040 * 1) if there is a node on vport list other than the @ndlp with the same
1041 * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
1042 * on that node to release the RPI associated with the node; 2) if there is
1043 * no node found on vport list with the same WWPN of the N_Port PLOGI logged
1044 * into, a new node shall be allocated (or activated). In either case, the
1045 * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
1046 * be released and the new_ndlp shall be put on to the vport node list and
1047 * its pointer returned as the confirmed node.
1049 * Note that before the @ndlp got "released", the keepDID from not-matching
1050 * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
1051 * of the @ndlp. This is because the release of @ndlp is actually to put it
1052 * into an inactive state on the vport node list and the vport node list
1053 * management algorithm does not allow two node with a same DID.
1056 * pointer to the PLOGI N_Port @ndlp
1058 static struct lpfc_nodelist *
1059 lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
1060 struct lpfc_nodelist *ndlp)
1062 struct lpfc_vport *vport = ndlp->vport;
1063 struct lpfc_nodelist *new_ndlp;
1064 struct lpfc_rport_data *rdata;
1065 struct fc_rport *rport;
1066 struct serv_parm *sp;
1067 uint8_t name[sizeof(struct lpfc_name)];
1068 uint32_t rc, keepDID = 0;
1070 /* Fabric nodes can have the same WWPN so we don't bother searching
1071 * by WWPN. Just return the ndlp that was given to us.
1073 if (ndlp->nlp_type & NLP_FABRIC)
1076 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
1077 memset(name, 0, sizeof(struct lpfc_name));
1079 /* Now we find out if the NPort we are logging into, matches the WWPN
1080 * we have for that ndlp. If not, we have some work to do.
1082 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
1084 if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp))
1088 rc = memcmp(&ndlp->nlp_portname, name,
1089 sizeof(struct lpfc_name));
1092 new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
1095 lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID);
1096 } else if (!NLP_CHK_NODE_ACT(new_ndlp)) {
1097 rc = memcmp(&ndlp->nlp_portname, name,
1098 sizeof(struct lpfc_name));
1101 new_ndlp = lpfc_enable_node(vport, new_ndlp,
1102 NLP_STE_UNUSED_NODE);
1105 keepDID = new_ndlp->nlp_DID;
1107 keepDID = new_ndlp->nlp_DID;
1109 lpfc_unreg_rpi(vport, new_ndlp);
1110 new_ndlp->nlp_DID = ndlp->nlp_DID;
1111 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
1113 if (ndlp->nlp_flag & NLP_NPR_2B_DISC)
1114 new_ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1115 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1117 /* Set state will put new_ndlp on to node list if not already done */
1118 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
1120 /* Move this back to NPR state */
1121 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
1122 /* The new_ndlp is replacing ndlp totally, so we need
1123 * to put ndlp on UNUSED list and try to free it.
1126 /* Fix up the rport accordingly */
1127 rport = ndlp->rport;
1129 rdata = rport->dd_data;
1130 if (rdata->pnode == ndlp) {
1133 rdata->pnode = lpfc_nlp_get(new_ndlp);
1134 new_ndlp->rport = rport;
1136 new_ndlp->nlp_type = ndlp->nlp_type;
1138 /* We shall actually free the ndlp with both nlp_DID and
1139 * nlp_portname fields equals 0 to avoid any ndlp on the
1140 * nodelist never to be used.
1142 if (ndlp->nlp_DID == 0) {
1143 spin_lock_irq(&phba->ndlp_lock);
1144 NLP_SET_FREE_REQ(ndlp);
1145 spin_unlock_irq(&phba->ndlp_lock);
1148 /* Two ndlps cannot have the same did on the nodelist */
1149 ndlp->nlp_DID = keepDID;
1150 lpfc_drop_node(vport, ndlp);
1153 lpfc_unreg_rpi(vport, ndlp);
1154 /* Two ndlps cannot have the same did */
1155 ndlp->nlp_DID = keepDID;
1156 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1162 * lpfc_end_rscn: Check and handle more rscn for a vport.
1163 * @vport: pointer to a host virtual N_Port data structure.
1165 * This routine checks whether more Registration State Change
1166 * Notifications (RSCNs) came in while the discovery state machine was in
1167 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1168 * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1169 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1170 * handling the RSCNs.
1173 lpfc_end_rscn(struct lpfc_vport *vport)
1175 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1177 if (vport->fc_flag & FC_RSCN_MODE) {
1179 * Check to see if more RSCNs came in while we were
1180 * processing this one.
1182 if (vport->fc_rscn_id_cnt ||
1183 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
1184 lpfc_els_handle_rscn(vport);
1186 spin_lock_irq(shost->host_lock);
1187 vport->fc_flag &= ~FC_RSCN_MODE;
1188 spin_unlock_irq(shost->host_lock);
1194 * lpfc_cmpl_els_plogi: Completion callback function for plogi.
1195 * @phba: pointer to lpfc hba data structure.
1196 * @cmdiocb: pointer to lpfc command iocb data structure.
1197 * @rspiocb: pointer to lpfc response iocb data structure.
1199 * This routine is the completion callback function for issuing the Port
1200 * Login (PLOGI) command. For PLOGI completion, there must be an active
1201 * ndlp on the vport node list that matches the remote node ID from the
1202 * PLOGI reponse IOCB. If such ndlp does not exist, the PLOGI is simply
1203 * ignored and command IOCB released. The PLOGI response IOCB status is
1204 * checked for error conditons. If there is error status reported, PLOGI
1205 * retry shall be attempted by invoking the lpfc_els_retry() routine.
1206 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1207 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1208 * (DSM) is set for this PLOGI completion. Finally, it checks whether
1209 * there are additional N_Port nodes with the vport that need to perform
1210 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
1214 lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1215 struct lpfc_iocbq *rspiocb)
1217 struct lpfc_vport *vport = cmdiocb->vport;
1218 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1220 struct lpfc_nodelist *ndlp;
1221 struct lpfc_dmabuf *prsp;
1222 int disc, rc, did, type;
1224 /* we pass cmdiocb to state machine which needs rspiocb as well */
1225 cmdiocb->context_un.rsp_iocb = rspiocb;
1227 irsp = &rspiocb->iocb;
1228 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1229 "PLOGI cmpl: status:x%x/x%x did:x%x",
1230 irsp->ulpStatus, irsp->un.ulpWord[4],
1231 irsp->un.elsreq64.remoteID);
1233 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
1234 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
1235 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1236 "0136 PLOGI completes to NPort x%x "
1237 "with no ndlp. Data: x%x x%x x%x\n",
1238 irsp->un.elsreq64.remoteID,
1239 irsp->ulpStatus, irsp->un.ulpWord[4],
1244 /* Since ndlp can be freed in the disc state machine, note if this node
1245 * is being used during discovery.
1247 spin_lock_irq(shost->host_lock);
1248 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
1249 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1250 spin_unlock_irq(shost->host_lock);
1253 /* PLOGI completes to NPort <nlp_DID> */
1254 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1255 "0102 PLOGI completes to NPort x%x "
1256 "Data: x%x x%x x%x x%x x%x\n",
1257 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1258 irsp->ulpTimeout, disc, vport->num_disc_nodes);
1259 /* Check to see if link went down during discovery */
1260 if (lpfc_els_chk_latt(vport)) {
1261 spin_lock_irq(shost->host_lock);
1262 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1263 spin_unlock_irq(shost->host_lock);
1267 /* ndlp could be freed in DSM, save these values now */
1268 type = ndlp->nlp_type;
1269 did = ndlp->nlp_DID;
1271 if (irsp->ulpStatus) {
1272 /* Check for retry */
1273 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1274 /* ELS command is being retried */
1276 spin_lock_irq(shost->host_lock);
1277 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1278 spin_unlock_irq(shost->host_lock);
1283 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1284 if (lpfc_error_lost_link(irsp))
1285 rc = NLP_STE_FREED_NODE;
1287 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1288 NLP_EVT_CMPL_PLOGI);
1290 /* Good status, call state machine */
1291 prsp = list_entry(((struct lpfc_dmabuf *)
1292 cmdiocb->context2)->list.next,
1293 struct lpfc_dmabuf, list);
1294 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
1295 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1296 NLP_EVT_CMPL_PLOGI);
1299 if (disc && vport->num_disc_nodes) {
1300 /* Check to see if there are more PLOGIs to be sent */
1301 lpfc_more_plogi(vport);
1303 if (vport->num_disc_nodes == 0) {
1304 spin_lock_irq(shost->host_lock);
1305 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1306 spin_unlock_irq(shost->host_lock);
1308 lpfc_can_disctmo(vport);
1309 lpfc_end_rscn(vport);
1314 lpfc_els_free_iocb(phba, cmdiocb);
1319 * lpfc_issue_els_plogi: Issue an plogi iocb command for a vport.
1320 * @vport: pointer to a host virtual N_Port data structure.
1321 * @did: destination port identifier.
1322 * @retry: number of retries to the command IOCB.
1324 * This routine issues a Port Login (PLOGI) command to a remote N_Port
1325 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
1326 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
1327 * This routine constructs the proper feilds of the PLOGI IOCB and invokes
1328 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
1330 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1331 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1332 * will be stored into the context1 field of the IOCB for the completion
1333 * callback function to the PLOGI ELS command.
1336 * 0 - Successfully issued a plogi for @vport
1337 * 1 - failed to issue a plogi for @vport
1340 lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
1342 struct lpfc_hba *phba = vport->phba;
1343 struct serv_parm *sp;
1345 struct lpfc_nodelist *ndlp;
1346 struct lpfc_iocbq *elsiocb;
1347 struct lpfc_sli_ring *pring;
1348 struct lpfc_sli *psli;
1354 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
1356 ndlp = lpfc_findnode_did(vport, did);
1357 if (ndlp && !NLP_CHK_NODE_ACT(ndlp))
1360 /* If ndlp is not NULL, we will bump the reference count on it */
1361 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
1362 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
1367 icmd = &elsiocb->iocb;
1368 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1370 /* For PLOGI request, remainder of payload is service parameters */
1371 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
1372 pcmd += sizeof(uint32_t);
1373 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
1374 sp = (struct serv_parm *) pcmd;
1376 if (sp->cmn.fcphLow < FC_PH_4_3)
1377 sp->cmn.fcphLow = FC_PH_4_3;
1379 if (sp->cmn.fcphHigh < FC_PH3)
1380 sp->cmn.fcphHigh = FC_PH3;
1382 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1383 "Issue PLOGI: did:x%x",
1386 phba->fc_stat.elsXmitPLOGI++;
1387 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
1388 ret = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
1390 if (ret == IOCB_ERROR) {
1391 lpfc_els_free_iocb(phba, elsiocb);
1398 * lpfc_cmpl_els_prli: Completion callback function for prli.
1399 * @phba: pointer to lpfc hba data structure.
1400 * @cmdiocb: pointer to lpfc command iocb data structure.
1401 * @rspiocb: pointer to lpfc response iocb data structure.
1403 * This routine is the completion callback function for a Process Login
1404 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
1405 * status. If there is error status reported, PRLI retry shall be attempted
1406 * by invoking the lpfc_els_retry() routine. Otherwise, the state
1407 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
1408 * ndlp to mark the PRLI completion.
1411 lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1412 struct lpfc_iocbq *rspiocb)
1414 struct lpfc_vport *vport = cmdiocb->vport;
1415 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1417 struct lpfc_sli *psli;
1418 struct lpfc_nodelist *ndlp;
1421 /* we pass cmdiocb to state machine which needs rspiocb as well */
1422 cmdiocb->context_un.rsp_iocb = rspiocb;
1424 irsp = &(rspiocb->iocb);
1425 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1426 spin_lock_irq(shost->host_lock);
1427 ndlp->nlp_flag &= ~NLP_PRLI_SND;
1428 spin_unlock_irq(shost->host_lock);
1430 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1431 "PRLI cmpl: status:x%x/x%x did:x%x",
1432 irsp->ulpStatus, irsp->un.ulpWord[4],
1434 /* PRLI completes to NPort <nlp_DID> */
1435 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1436 "0103 PRLI completes to NPort x%x "
1437 "Data: x%x x%x x%x x%x\n",
1438 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1439 irsp->ulpTimeout, vport->num_disc_nodes);
1441 vport->fc_prli_sent--;
1442 /* Check to see if link went down during discovery */
1443 if (lpfc_els_chk_latt(vport))
1446 if (irsp->ulpStatus) {
1447 /* Check for retry */
1448 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1449 /* ELS command is being retried */
1453 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1454 if (lpfc_error_lost_link(irsp))
1457 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1460 /* Good status, call state machine */
1461 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1464 lpfc_els_free_iocb(phba, cmdiocb);
1469 * lpfc_issue_els_prli: Issue a prli iocb command for a vport.
1470 * @vport: pointer to a host virtual N_Port data structure.
1471 * @ndlp: pointer to a node-list data structure.
1472 * @retry: number of retries to the command IOCB.
1474 * This routine issues a Process Login (PRLI) ELS command for the
1475 * @vport. The PRLI service parameters are set up in the payload of the
1476 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
1477 * is put to the IOCB completion callback func field before invoking the
1478 * routine lpfc_sli_issue_iocb() to send out PRLI command.
1480 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1481 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1482 * will be stored into the context1 field of the IOCB for the completion
1483 * callback function to the PRLI ELS command.
1486 * 0 - successfully issued prli iocb command for @vport
1487 * 1 - failed to issue prli iocb command for @vport
1490 lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1493 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1494 struct lpfc_hba *phba = vport->phba;
1497 struct lpfc_iocbq *elsiocb;
1498 struct lpfc_sli_ring *pring;
1499 struct lpfc_sli *psli;
1504 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
1506 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
1507 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1508 ndlp->nlp_DID, ELS_CMD_PRLI);
1512 icmd = &elsiocb->iocb;
1513 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1515 /* For PRLI request, remainder of payload is service parameters */
1516 memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t)));
1517 *((uint32_t *) (pcmd)) = ELS_CMD_PRLI;
1518 pcmd += sizeof(uint32_t);
1520 /* For PRLI, remainder of payload is PRLI parameter page */
1521 npr = (PRLI *) pcmd;
1523 * If our firmware version is 3.20 or later,
1524 * set the following bits for FC-TAPE support.
1526 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
1527 npr->ConfmComplAllowed = 1;
1529 npr->TaskRetryIdReq = 1;
1531 npr->estabImagePair = 1;
1532 npr->readXferRdyDis = 1;
1534 /* For FCP support */
1535 npr->prliType = PRLI_FCP_TYPE;
1536 npr->initiatorFunc = 1;
1538 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1539 "Issue PRLI: did:x%x",
1540 ndlp->nlp_DID, 0, 0);
1542 phba->fc_stat.elsXmitPRLI++;
1543 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
1544 spin_lock_irq(shost->host_lock);
1545 ndlp->nlp_flag |= NLP_PRLI_SND;
1546 spin_unlock_irq(shost->host_lock);
1547 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
1548 spin_lock_irq(shost->host_lock);
1549 ndlp->nlp_flag &= ~NLP_PRLI_SND;
1550 spin_unlock_irq(shost->host_lock);
1551 lpfc_els_free_iocb(phba, elsiocb);
1554 vport->fc_prli_sent++;
1559 * lpfc_more_adisc: Issue more adisc as needed.
1560 * @vport: pointer to a host virtual N_Port data structure.
1562 * This routine determines whether there are more ndlps on a @vport
1563 * node list need to have Address Discover (ADISC) issued. If so, it will
1564 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
1565 * remaining nodes which need to have ADISC sent.
1568 lpfc_more_adisc(struct lpfc_vport *vport)
1572 if (vport->num_disc_nodes)
1573 vport->num_disc_nodes--;
1574 /* Continue discovery with <num_disc_nodes> ADISCs to go */
1575 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1576 "0210 Continue discovery with %d ADISCs to go "
1577 "Data: x%x x%x x%x\n",
1578 vport->num_disc_nodes, vport->fc_adisc_cnt,
1579 vport->fc_flag, vport->port_state);
1580 /* Check to see if there are more ADISCs to be sent */
1581 if (vport->fc_flag & FC_NLP_MORE) {
1582 lpfc_set_disctmo(vport);
1583 /* go thru NPR nodes and issue any remaining ELS ADISCs */
1584 sentadisc = lpfc_els_disc_adisc(vport);
1590 * lpfc_rscn_disc: Perform rscn discovery for a vport.
1591 * @vport: pointer to a host virtual N_Port data structure.
1593 * This routine performs Registration State Change Notification (RSCN)
1594 * discovery for a @vport. If the @vport's node port recovery count is not
1595 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
1596 * the nodes that need recovery. If none of the PLOGI were needed through
1597 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
1598 * invoked to check and handle possible more RSCN came in during the period
1599 * of processing the current ones.
1602 lpfc_rscn_disc(struct lpfc_vport *vport)
1604 lpfc_can_disctmo(vport);
1606 /* RSCN discovery */
1607 /* go thru NPR nodes and issue ELS PLOGIs */
1608 if (vport->fc_npr_cnt)
1609 if (lpfc_els_disc_plogi(vport))
1612 lpfc_end_rscn(vport);
1616 * lpfc_cmpl_els_adisc: Completion callback function for adisc.
1617 * @phba: pointer to lpfc hba data structure.
1618 * @cmdiocb: pointer to lpfc command iocb data structure.
1619 * @rspiocb: pointer to lpfc response iocb data structure.
1621 * This routine is the completion function for issuing the Address Discover
1622 * (ADISC) command. It first checks to see whether link went down during
1623 * the discovery process. If so, the node will be marked as node port
1624 * recovery for issuing discover IOCB by the link attention handler and
1625 * exit. Otherwise, the response status is checked. If error was reported
1626 * in the response status, the ADISC command shall be retried by invoking
1627 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
1628 * the response status, the state machine is invoked to set transition
1629 * with respect to NLP_EVT_CMPL_ADISC event.
1632 lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1633 struct lpfc_iocbq *rspiocb)
1635 struct lpfc_vport *vport = cmdiocb->vport;
1636 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1638 struct lpfc_nodelist *ndlp;
1641 /* we pass cmdiocb to state machine which needs rspiocb as well */
1642 cmdiocb->context_un.rsp_iocb = rspiocb;
1644 irsp = &(rspiocb->iocb);
1645 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1647 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1648 "ADISC cmpl: status:x%x/x%x did:x%x",
1649 irsp->ulpStatus, irsp->un.ulpWord[4],
1652 /* Since ndlp can be freed in the disc state machine, note if this node
1653 * is being used during discovery.
1655 spin_lock_irq(shost->host_lock);
1656 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
1657 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
1658 spin_unlock_irq(shost->host_lock);
1659 /* ADISC completes to NPort <nlp_DID> */
1660 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1661 "0104 ADISC completes to NPort x%x "
1662 "Data: x%x x%x x%x x%x x%x\n",
1663 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1664 irsp->ulpTimeout, disc, vport->num_disc_nodes);
1665 /* Check to see if link went down during discovery */
1666 if (lpfc_els_chk_latt(vport)) {
1667 spin_lock_irq(shost->host_lock);
1668 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1669 spin_unlock_irq(shost->host_lock);
1673 if (irsp->ulpStatus) {
1674 /* Check for retry */
1675 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1676 /* ELS command is being retried */
1678 spin_lock_irq(shost->host_lock);
1679 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1680 spin_unlock_irq(shost->host_lock);
1681 lpfc_set_disctmo(vport);
1686 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1687 if (!lpfc_error_lost_link(irsp))
1688 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1689 NLP_EVT_CMPL_ADISC);
1691 /* Good status, call state machine */
1692 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1693 NLP_EVT_CMPL_ADISC);
1695 if (disc && vport->num_disc_nodes) {
1696 /* Check to see if there are more ADISCs to be sent */
1697 lpfc_more_adisc(vport);
1699 /* Check to see if we are done with ADISC authentication */
1700 if (vport->num_disc_nodes == 0) {
1701 /* If we get here, there is nothing left to ADISC */
1703 * For NPIV, cmpl_reg_vpi will set port_state to READY,
1704 * and continue discovery.
1706 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
1707 !(vport->fc_flag & FC_RSCN_MODE)) {
1708 lpfc_issue_reg_vpi(phba, vport);
1712 * For SLI2, we need to set port_state to READY
1713 * and continue discovery.
1715 if (vport->port_state < LPFC_VPORT_READY) {
1716 /* If we get here, there is nothing to ADISC */
1717 if (vport->port_type == LPFC_PHYSICAL_PORT)
1718 lpfc_issue_clear_la(phba, vport);
1720 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
1721 vport->num_disc_nodes = 0;
1722 /* go thru NPR list, issue ELS PLOGIs */
1723 if (vport->fc_npr_cnt)
1724 lpfc_els_disc_plogi(vport);
1726 if (!vport->num_disc_nodes) {
1727 spin_lock_irq(shost->host_lock);
1732 lpfc_can_disctmo(vport);
1735 vport->port_state = LPFC_VPORT_READY;
1737 lpfc_rscn_disc(vport);
1742 lpfc_els_free_iocb(phba, cmdiocb);
1747 * lpfc_issue_els_adisc: Issue an address discover iocb to an node on a vport.
1748 * @vport: pointer to a virtual N_Port data structure.
1749 * @ndlp: pointer to a node-list data structure.
1750 * @retry: number of retries to the command IOCB.
1752 * This routine issues an Address Discover (ADISC) for an @ndlp on a
1753 * @vport. It prepares the payload of the ADISC ELS command, updates the
1754 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
1755 * to issue the ADISC ELS command.
1757 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1758 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1759 * will be stored into the context1 field of the IOCB for the completion
1760 * callback function to the ADISC ELS command.
1763 * 0 - successfully issued adisc
1764 * 1 - failed to issue adisc
1767 lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1770 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1771 struct lpfc_hba *phba = vport->phba;
1774 struct lpfc_iocbq *elsiocb;
1775 struct lpfc_sli *psli = &phba->sli;
1776 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
1780 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
1781 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1782 ndlp->nlp_DID, ELS_CMD_ADISC);
1786 icmd = &elsiocb->iocb;
1787 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1789 /* For ADISC request, remainder of payload is service parameters */
1790 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
1791 pcmd += sizeof(uint32_t);
1793 /* Fill in ADISC payload */
1794 ap = (ADISC *) pcmd;
1795 ap->hardAL_PA = phba->fc_pref_ALPA;
1796 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
1797 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
1798 ap->DID = be32_to_cpu(vport->fc_myDID);
1800 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1801 "Issue ADISC: did:x%x",
1802 ndlp->nlp_DID, 0, 0);
1804 phba->fc_stat.elsXmitADISC++;
1805 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
1806 spin_lock_irq(shost->host_lock);
1807 ndlp->nlp_flag |= NLP_ADISC_SND;
1808 spin_unlock_irq(shost->host_lock);
1809 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
1810 spin_lock_irq(shost->host_lock);
1811 ndlp->nlp_flag &= ~NLP_ADISC_SND;
1812 spin_unlock_irq(shost->host_lock);
1813 lpfc_els_free_iocb(phba, elsiocb);
1820 * lpfc_cmpl_els_logo: Completion callback function for logo.
1821 * @phba: pointer to lpfc hba data structure.
1822 * @cmdiocb: pointer to lpfc command iocb data structure.
1823 * @rspiocb: pointer to lpfc response iocb data structure.
1825 * This routine is the completion function for issuing the ELS Logout (LOGO)
1826 * command. If no error status was reported from the LOGO response, the
1827 * state machine of the associated ndlp shall be invoked for transition with
1828 * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
1829 * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
1832 lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1833 struct lpfc_iocbq *rspiocb)
1835 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1836 struct lpfc_vport *vport = ndlp->vport;
1837 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1839 struct lpfc_sli *psli;
1842 /* we pass cmdiocb to state machine which needs rspiocb as well */
1843 cmdiocb->context_un.rsp_iocb = rspiocb;
1845 irsp = &(rspiocb->iocb);
1846 spin_lock_irq(shost->host_lock);
1847 ndlp->nlp_flag &= ~NLP_LOGO_SND;
1848 spin_unlock_irq(shost->host_lock);
1850 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1851 "LOGO cmpl: status:x%x/x%x did:x%x",
1852 irsp->ulpStatus, irsp->un.ulpWord[4],
1854 /* LOGO completes to NPort <nlp_DID> */
1855 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1856 "0105 LOGO completes to NPort x%x "
1857 "Data: x%x x%x x%x x%x\n",
1858 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1859 irsp->ulpTimeout, vport->num_disc_nodes);
1860 /* Check to see if link went down during discovery */
1861 if (lpfc_els_chk_latt(vport))
1864 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
1865 /* NLP_EVT_DEVICE_RM should unregister the RPI
1866 * which should abort all outstanding IOs.
1868 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1873 if (irsp->ulpStatus) {
1874 /* Check for retry */
1875 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
1876 /* ELS command is being retried */
1879 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1880 if (lpfc_error_lost_link(irsp))
1883 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1886 /* Good status, call state machine.
1887 * This will unregister the rpi if needed.
1889 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1892 lpfc_els_free_iocb(phba, cmdiocb);
1897 * lpfc_issue_els_logo: Issue a logo to an node on a vport.
1898 * @vport: pointer to a virtual N_Port data structure.
1899 * @ndlp: pointer to a node-list data structure.
1900 * @retry: number of retries to the command IOCB.
1902 * This routine constructs and issues an ELS Logout (LOGO) iocb command
1903 * to a remote node, referred by an @ndlp on a @vport. It constructs the
1904 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
1905 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
1907 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1908 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1909 * will be stored into the context1 field of the IOCB for the completion
1910 * callback function to the LOGO ELS command.
1913 * 0 - successfully issued logo
1914 * 1 - failed to issue logo
1917 lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1920 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1921 struct lpfc_hba *phba = vport->phba;
1923 struct lpfc_iocbq *elsiocb;
1924 struct lpfc_sli_ring *pring;
1925 struct lpfc_sli *psli;
1931 pring = &psli->ring[LPFC_ELS_RING];
1933 spin_lock_irq(shost->host_lock);
1934 if (ndlp->nlp_flag & NLP_LOGO_SND) {
1935 spin_unlock_irq(shost->host_lock);
1938 spin_unlock_irq(shost->host_lock);
1940 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
1941 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1942 ndlp->nlp_DID, ELS_CMD_LOGO);
1946 icmd = &elsiocb->iocb;
1947 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1948 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
1949 pcmd += sizeof(uint32_t);
1951 /* Fill in LOGO payload */
1952 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
1953 pcmd += sizeof(uint32_t);
1954 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
1956 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1957 "Issue LOGO: did:x%x",
1958 ndlp->nlp_DID, 0, 0);
1960 phba->fc_stat.elsXmitLOGO++;
1961 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
1962 spin_lock_irq(shost->host_lock);
1963 ndlp->nlp_flag |= NLP_LOGO_SND;
1964 spin_unlock_irq(shost->host_lock);
1965 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
1967 if (rc == IOCB_ERROR) {
1968 spin_lock_irq(shost->host_lock);
1969 ndlp->nlp_flag &= ~NLP_LOGO_SND;
1970 spin_unlock_irq(shost->host_lock);
1971 lpfc_els_free_iocb(phba, elsiocb);
1978 * lpfc_cmpl_els_cmd: Completion callback function for generic els command.
1979 * @phba: pointer to lpfc hba data structure.
1980 * @cmdiocb: pointer to lpfc command iocb data structure.
1981 * @rspiocb: pointer to lpfc response iocb data structure.
1983 * This routine is a generic completion callback function for ELS commands.
1984 * Specifically, it is the callback function which does not need to perform
1985 * any command specific operations. It is currently used by the ELS command
1986 * issuing routines for the ELS State Change Request (SCR),
1987 * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution
1988 * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than
1989 * certain debug loggings, this callback function simply invokes the
1990 * lpfc_els_chk_latt() routine to check whether link went down during the
1991 * discovery process.
1994 lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1995 struct lpfc_iocbq *rspiocb)
1997 struct lpfc_vport *vport = cmdiocb->vport;
2000 irsp = &rspiocb->iocb;
2002 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2003 "ELS cmd cmpl: status:x%x/x%x did:x%x",
2004 irsp->ulpStatus, irsp->un.ulpWord[4],
2005 irsp->un.elsreq64.remoteID);
2006 /* ELS cmd tag <ulpIoTag> completes */
2007 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2008 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
2009 irsp->ulpIoTag, irsp->ulpStatus,
2010 irsp->un.ulpWord[4], irsp->ulpTimeout);
2011 /* Check to see if link went down during discovery */
2012 lpfc_els_chk_latt(vport);
2013 lpfc_els_free_iocb(phba, cmdiocb);
2018 * lpfc_issue_els_scr: Issue a scr to an node on a vport.
2019 * @vport: pointer to a host virtual N_Port data structure.
2020 * @nportid: N_Port identifier to the remote node.
2021 * @retry: number of retries to the command IOCB.
2023 * This routine issues a State Change Request (SCR) to a fabric node
2024 * on a @vport. The remote node @nportid is passed into the function. It
2025 * first search the @vport node list to find the matching ndlp. If no such
2026 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
2027 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
2028 * routine is invoked to send the SCR IOCB.
2030 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2031 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2032 * will be stored into the context1 field of the IOCB for the completion
2033 * callback function to the SCR ELS command.
2036 * 0 - Successfully issued scr command
2037 * 1 - Failed to issue scr command
2040 lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
2042 struct lpfc_hba *phba = vport->phba;
2044 struct lpfc_iocbq *elsiocb;
2045 struct lpfc_sli_ring *pring;
2046 struct lpfc_sli *psli;
2049 struct lpfc_nodelist *ndlp;
2052 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
2053 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
2055 ndlp = lpfc_findnode_did(vport, nportid);
2057 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2060 lpfc_nlp_init(vport, ndlp, nportid);
2061 lpfc_enqueue_node(vport, ndlp);
2062 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2063 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2068 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2069 ndlp->nlp_DID, ELS_CMD_SCR);
2072 /* This will trigger the release of the node just
2079 icmd = &elsiocb->iocb;
2080 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2082 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
2083 pcmd += sizeof(uint32_t);
2085 /* For SCR, remainder of payload is SCR parameter page */
2086 memset(pcmd, 0, sizeof(SCR));
2087 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
2089 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2090 "Issue SCR: did:x%x",
2091 ndlp->nlp_DID, 0, 0);
2093 phba->fc_stat.elsXmitSCR++;
2094 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
2095 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
2096 /* The additional lpfc_nlp_put will cause the following
2097 * lpfc_els_free_iocb routine to trigger the rlease of
2101 lpfc_els_free_iocb(phba, elsiocb);
2104 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2105 * trigger the release of node.
2112 * lpfc_issue_els_farpr: Issue a farp to an node on a vport.
2113 * @vport: pointer to a host virtual N_Port data structure.
2114 * @nportid: N_Port identifier to the remote node.
2115 * @retry: number of retries to the command IOCB.
2117 * This routine issues a Fibre Channel Address Resolution Response
2118 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
2119 * is passed into the function. It first search the @vport node list to find
2120 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
2121 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
2122 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
2124 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2125 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2126 * will be stored into the context1 field of the IOCB for the completion
2127 * callback function to the PARPR ELS command.
2130 * 0 - Successfully issued farpr command
2131 * 1 - Failed to issue farpr command
2134 lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
2136 struct lpfc_hba *phba = vport->phba;
2138 struct lpfc_iocbq *elsiocb;
2139 struct lpfc_sli_ring *pring;
2140 struct lpfc_sli *psli;
2145 struct lpfc_nodelist *ondlp;
2146 struct lpfc_nodelist *ndlp;
2149 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
2150 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
2152 ndlp = lpfc_findnode_did(vport, nportid);
2154 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2157 lpfc_nlp_init(vport, ndlp, nportid);
2158 lpfc_enqueue_node(vport, ndlp);
2159 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2160 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2165 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2166 ndlp->nlp_DID, ELS_CMD_RNID);
2168 /* This will trigger the release of the node just
2175 icmd = &elsiocb->iocb;
2176 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2178 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
2179 pcmd += sizeof(uint32_t);
2181 /* Fill in FARPR payload */
2182 fp = (FARP *) (pcmd);
2183 memset(fp, 0, sizeof(FARP));
2184 lp = (uint32_t *) pcmd;
2185 *lp++ = be32_to_cpu(nportid);
2186 *lp++ = be32_to_cpu(vport->fc_myDID);
2188 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
2190 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
2191 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
2192 ondlp = lpfc_findnode_did(vport, nportid);
2193 if (ondlp && NLP_CHK_NODE_ACT(ondlp)) {
2194 memcpy(&fp->OportName, &ondlp->nlp_portname,
2195 sizeof(struct lpfc_name));
2196 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
2197 sizeof(struct lpfc_name));
2200 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2201 "Issue FARPR: did:x%x",
2202 ndlp->nlp_DID, 0, 0);
2204 phba->fc_stat.elsXmitFARPR++;
2205 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
2206 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
2207 /* The additional lpfc_nlp_put will cause the following
2208 * lpfc_els_free_iocb routine to trigger the release of
2212 lpfc_els_free_iocb(phba, elsiocb);
2215 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2216 * trigger the release of the node.
2223 * lpfc_cancel_retry_delay_tmo: Cancel the timer with delayed iocb-cmd retry.
2224 * @vport: pointer to a host virtual N_Port data structure.
2225 * @nlp: pointer to a node-list data structure.
2227 * This routine cancels the timer with a delayed IOCB-command retry for
2228 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
2229 * removes the ELS retry event if it presents. In addition, if the
2230 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
2231 * commands are sent for the @vport's nodes that require issuing discovery
2235 lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
2237 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2238 struct lpfc_work_evt *evtp;
2240 if (!(nlp->nlp_flag & NLP_DELAY_TMO))
2242 spin_lock_irq(shost->host_lock);
2243 nlp->nlp_flag &= ~NLP_DELAY_TMO;
2244 spin_unlock_irq(shost->host_lock);
2245 del_timer_sync(&nlp->nlp_delayfunc);
2246 nlp->nlp_last_elscmd = 0;
2247 if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
2248 list_del_init(&nlp->els_retry_evt.evt_listp);
2249 /* Decrement nlp reference count held for the delayed retry */
2250 evtp = &nlp->els_retry_evt;
2251 lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
2253 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
2254 spin_lock_irq(shost->host_lock);
2255 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
2256 spin_unlock_irq(shost->host_lock);
2257 if (vport->num_disc_nodes) {
2258 if (vport->port_state < LPFC_VPORT_READY) {
2259 /* Check if there are more ADISCs to be sent */
2260 lpfc_more_adisc(vport);
2261 if ((vport->num_disc_nodes == 0) &&
2262 (vport->fc_npr_cnt))
2263 lpfc_els_disc_plogi(vport);
2265 /* Check if there are more PLOGIs to be sent */
2266 lpfc_more_plogi(vport);
2268 if (vport->num_disc_nodes == 0) {
2269 spin_lock_irq(shost->host_lock);
2270 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2271 spin_unlock_irq(shost->host_lock);
2272 lpfc_can_disctmo(vport);
2273 lpfc_end_rscn(vport);
2281 * lpfc_els_retry_delay: Timer function with a ndlp delayed function timer.
2282 * @ptr: holder for the pointer to the timer function associated data (ndlp).
2284 * This routine is invoked by the ndlp delayed-function timer to check
2285 * whether there is any pending ELS retry event(s) with the node. If not, it
2286 * simply returns. Otherwise, if there is at least one ELS delayed event, it
2287 * adds the delayed events to the HBA work list and invokes the
2288 * lpfc_worker_wake_up() routine to wake up worker thread to process the
2289 * event. Note that lpfc_nlp_get() is called before posting the event to
2290 * the work list to hold reference count of ndlp so that it guarantees the
2291 * reference to ndlp will still be available when the worker thread gets
2292 * to the event associated with the ndlp.
2295 lpfc_els_retry_delay(unsigned long ptr)
2297 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr;
2298 struct lpfc_vport *vport = ndlp->vport;
2299 struct lpfc_hba *phba = vport->phba;
2300 unsigned long flags;
2301 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
2303 spin_lock_irqsave(&phba->hbalock, flags);
2304 if (!list_empty(&evtp->evt_listp)) {
2305 spin_unlock_irqrestore(&phba->hbalock, flags);
2309 /* We need to hold the node by incrementing the reference
2310 * count until the queued work is done
2312 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
2313 if (evtp->evt_arg1) {
2314 evtp->evt = LPFC_EVT_ELS_RETRY;
2315 list_add_tail(&evtp->evt_listp, &phba->work_list);
2316 lpfc_worker_wake_up(phba);
2318 spin_unlock_irqrestore(&phba->hbalock, flags);
2323 * lpfc_els_retry_delay_handler: Work thread handler for ndlp delayed function.
2324 * @ndlp: pointer to a node-list data structure.
2326 * This routine is the worker-thread handler for processing the @ndlp delayed
2327 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
2328 * the last ELS command from the associated ndlp and invokes the proper ELS
2329 * function according to the delayed ELS command to retry the command.
2332 lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
2334 struct lpfc_vport *vport = ndlp->vport;
2335 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2336 uint32_t cmd, did, retry;
2338 spin_lock_irq(shost->host_lock);
2339 did = ndlp->nlp_DID;
2340 cmd = ndlp->nlp_last_elscmd;
2341 ndlp->nlp_last_elscmd = 0;
2343 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
2344 spin_unlock_irq(shost->host_lock);
2348 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
2349 spin_unlock_irq(shost->host_lock);
2351 * If a discovery event readded nlp_delayfunc after timer
2352 * firing and before processing the timer, cancel the
2355 del_timer_sync(&ndlp->nlp_delayfunc);
2356 retry = ndlp->nlp_retry;
2360 lpfc_issue_els_flogi(vport, ndlp, retry);
2363 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
2364 ndlp->nlp_prev_state = ndlp->nlp_state;
2365 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2369 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
2370 ndlp->nlp_prev_state = ndlp->nlp_state;
2371 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2375 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
2376 ndlp->nlp_prev_state = ndlp->nlp_state;
2377 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
2381 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
2382 ndlp->nlp_prev_state = ndlp->nlp_state;
2383 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2387 lpfc_issue_els_fdisc(vport, ndlp, retry);
2394 * lpfc_els_retry: Make retry decision on an els command iocb.
2395 * @phba: pointer to lpfc hba data structure.
2396 * @cmdiocb: pointer to lpfc command iocb data structure.
2397 * @rspiocb: pointer to lpfc response iocb data structure.
2399 * This routine makes a retry decision on an ELS command IOCB, which has
2400 * failed. The following ELS IOCBs use this function for retrying the command
2401 * when previously issued command responsed with error status: FLOGI, PLOGI,
2402 * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
2403 * returned error status, it makes the decision whether a retry shall be
2404 * issued for the command, and whether a retry shall be made immediately or
2405 * delayed. In the former case, the corresponding ELS command issuing-function
2406 * is called to retry the command. In the later case, the ELS command shall
2407 * be posted to the ndlp delayed event and delayed function timer set to the
2408 * ndlp for the delayed command issusing.
2411 * 0 - No retry of els command is made
2412 * 1 - Immediate or delayed retry of els command is made
2415 lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2416 struct lpfc_iocbq *rspiocb)
2418 struct lpfc_vport *vport = cmdiocb->vport;
2419 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2420 IOCB_t *irsp = &rspiocb->iocb;
2421 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2422 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
2425 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
2431 /* Note: context2 may be 0 for internal driver abort
2432 * of delays ELS command.
2435 if (pcmd && pcmd->virt) {
2436 elscmd = (uint32_t *) (pcmd->virt);
2440 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
2441 did = ndlp->nlp_DID;
2443 /* We should only hit this case for retrying PLOGI */
2444 did = irsp->un.elsreq64.remoteID;
2445 ndlp = lpfc_findnode_did(vport, did);
2446 if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp))
2447 && (cmd != ELS_CMD_PLOGI))
2451 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2452 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
2453 *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
2455 switch (irsp->ulpStatus) {
2456 case IOSTAT_FCP_RSP_ERROR:
2457 case IOSTAT_REMOTE_STOP:
2460 case IOSTAT_LOCAL_REJECT:
2461 switch ((irsp->un.ulpWord[4] & 0xff)) {
2462 case IOERR_LOOP_OPEN_FAILURE:
2463 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
2468 case IOERR_ILLEGAL_COMMAND:
2469 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2470 "0124 Retry illegal cmd x%x "
2471 "retry:x%x delay:x%x\n",
2472 cmd, cmdiocb->retry, delay);
2474 /* All command's retry policy */
2476 if (cmdiocb->retry > 2)
2480 case IOERR_NO_RESOURCES:
2481 logerr = 1; /* HBA out of resources */
2483 if (cmdiocb->retry > 100)
2488 case IOERR_ILLEGAL_FRAME:
2493 case IOERR_SEQUENCE_TIMEOUT:
2494 case IOERR_INVALID_RPI:
2500 case IOSTAT_NPORT_RJT:
2501 case IOSTAT_FABRIC_RJT:
2502 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
2508 case IOSTAT_NPORT_BSY:
2509 case IOSTAT_FABRIC_BSY:
2510 logerr = 1; /* Fabric / Remote NPort out of resources */
2515 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
2516 /* Added for Vendor specifc support
2517 * Just keep retrying for these Rsn / Exp codes
2519 switch (stat.un.b.lsRjtRsnCode) {
2520 case LSRJT_UNABLE_TPC:
2521 if (stat.un.b.lsRjtRsnCodeExp ==
2522 LSEXP_CMD_IN_PROGRESS) {
2523 if (cmd == ELS_CMD_PLOGI) {
2530 if (cmd == ELS_CMD_PLOGI) {
2532 maxretry = lpfc_max_els_tries + 1;
2536 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2537 (cmd == ELS_CMD_FDISC) &&
2538 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
2539 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2540 "0125 FDISC Failed (x%x). "
2541 "Fabric out of resources\n",
2542 stat.un.lsRjtError);
2543 lpfc_vport_set_state(vport,
2544 FC_VPORT_NO_FABRIC_RSCS);
2548 case LSRJT_LOGICAL_BSY:
2549 if ((cmd == ELS_CMD_PLOGI) ||
2550 (cmd == ELS_CMD_PRLI)) {
2553 } else if (cmd == ELS_CMD_FDISC) {
2554 /* FDISC retry policy */
2556 if (cmdiocb->retry >= 32)
2562 case LSRJT_LOGICAL_ERR:
2563 /* There are some cases where switches return this
2564 * error when they are not ready and should be returning
2565 * Logical Busy. We should delay every time.
2567 if (cmd == ELS_CMD_FDISC &&
2568 stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
2574 case LSRJT_PROTOCOL_ERR:
2575 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2576 (cmd == ELS_CMD_FDISC) &&
2577 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
2578 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
2580 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2581 "0123 FDISC Failed (x%x). "
2582 "Fabric Detected Bad WWN\n",
2583 stat.un.lsRjtError);
2584 lpfc_vport_set_state(vport,
2585 FC_VPORT_FABRIC_REJ_WWN);
2591 case IOSTAT_INTERMED_RSP:
2599 if (did == FDMI_DID)
2602 if ((cmd == ELS_CMD_FLOGI) &&
2603 (phba->fc_topology != TOPOLOGY_LOOP) &&
2604 !lpfc_error_lost_link(irsp)) {
2605 /* FLOGI retry policy */
2608 if (cmdiocb->retry >= 32)
2612 if ((++cmdiocb->retry) >= maxretry) {
2613 phba->fc_stat.elsRetryExceeded++;
2617 if ((vport->load_flag & FC_UNLOADING) != 0)
2622 /* Retry ELS command <elsCmd> to remote NPORT <did> */
2623 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2624 "0107 Retry ELS command x%x to remote "
2625 "NPORT x%x Data: x%x x%x\n",
2626 cmd, did, cmdiocb->retry, delay);
2628 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
2629 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
2630 ((irsp->un.ulpWord[4] & 0xff) != IOERR_NO_RESOURCES))) {
2631 /* Don't reset timer for no resources */
2633 /* If discovery / RSCN timer is running, reset it */
2634 if (timer_pending(&vport->fc_disctmo) ||
2635 (vport->fc_flag & FC_RSCN_MODE))
2636 lpfc_set_disctmo(vport);
2639 phba->fc_stat.elsXmitRetry++;
2640 if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) {
2641 phba->fc_stat.elsDelayRetry++;
2642 ndlp->nlp_retry = cmdiocb->retry;
2644 /* delay is specified in milliseconds */
2645 mod_timer(&ndlp->nlp_delayfunc,
2646 jiffies + msecs_to_jiffies(delay));
2647 spin_lock_irq(shost->host_lock);
2648 ndlp->nlp_flag |= NLP_DELAY_TMO;
2649 spin_unlock_irq(shost->host_lock);
2651 ndlp->nlp_prev_state = ndlp->nlp_state;
2652 if (cmd == ELS_CMD_PRLI)
2653 lpfc_nlp_set_state(vport, ndlp,
2654 NLP_STE_REG_LOGIN_ISSUE);
2656 lpfc_nlp_set_state(vport, ndlp,
2658 ndlp->nlp_last_elscmd = cmd;
2664 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
2667 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
2670 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
2671 ndlp->nlp_prev_state = ndlp->nlp_state;
2672 lpfc_nlp_set_state(vport, ndlp,
2673 NLP_STE_PLOGI_ISSUE);
2675 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
2678 ndlp->nlp_prev_state = ndlp->nlp_state;
2679 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2680 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
2683 ndlp->nlp_prev_state = ndlp->nlp_state;
2684 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
2685 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
2688 ndlp->nlp_prev_state = ndlp->nlp_state;
2689 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2690 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
2694 /* No retry ELS command <elsCmd> to remote NPORT <did> */
2696 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2697 "0137 No retry ELS command x%x to remote "
2698 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
2699 cmd, did, irsp->ulpStatus,
2700 irsp->un.ulpWord[4]);
2703 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2704 "0108 No retry ELS command x%x to remote "
2705 "NPORT x%x Retried:%d Error:x%x/%x\n",
2706 cmd, did, cmdiocb->retry, irsp->ulpStatus,
2707 irsp->un.ulpWord[4]);
2713 * lpfc_els_free_data: Free lpfc dma buffer and data structure with an iocb.
2714 * @phba: pointer to lpfc hba data structure.
2715 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
2717 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
2718 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
2719 * checks to see whether there is a lpfc DMA buffer associated with the
2720 * response of the command IOCB. If so, it will be released before releasing
2721 * the lpfc DMA buffer associated with the IOCB itself.
2724 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
2727 lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
2729 struct lpfc_dmabuf *buf_ptr;
2731 /* Free the response before processing the command. */
2732 if (!list_empty(&buf_ptr1->list)) {
2733 list_remove_head(&buf_ptr1->list, buf_ptr,
2736 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
2739 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
2745 * lpfc_els_free_bpl: Free lpfc dma buffer and data structure with bpl.
2746 * @phba: pointer to lpfc hba data structure.
2747 * @buf_ptr: pointer to the lpfc dma buffer data structure.
2749 * This routine releases the lpfc Direct Memory Access (DMA) buffer
2750 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
2754 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
2757 lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
2759 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
2765 * lpfc_els_free_iocb: Free a command iocb and its associated resources.
2766 * @phba: pointer to lpfc hba data structure.
2767 * @elsiocb: pointer to lpfc els command iocb data structure.
2769 * This routine frees a command IOCB and its associated resources. The
2770 * command IOCB data structure contains the reference to various associated
2771 * resources, these fields must be set to NULL if the associated reference
2773 * context1 - reference to ndlp
2774 * context2 - reference to cmd
2775 * context2->next - reference to rsp
2776 * context3 - reference to bpl
2778 * It first properly decrements the reference count held on ndlp for the
2779 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
2780 * set, it invokes the lpfc_els_free_data() routine to release the Direct
2781 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
2782 * adds the DMA buffer the @phba data structure for the delayed release.
2783 * If reference to the Buffer Pointer List (BPL) is present, the
2784 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
2785 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
2786 * invoked to release the IOCB data structure back to @phba IOCBQ list.
2789 * 0 - Success (currently, always return 0)
2792 lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
2794 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
2795 struct lpfc_nodelist *ndlp;
2797 ndlp = (struct lpfc_nodelist *)elsiocb->context1;
2799 if (ndlp->nlp_flag & NLP_DEFER_RM) {
2802 /* If the ndlp is not being used by another discovery
2805 if (!lpfc_nlp_not_used(ndlp)) {
2806 /* If ndlp is being used by another discovery
2807 * thread, just clear NLP_DEFER_RM
2809 ndlp->nlp_flag &= ~NLP_DEFER_RM;
2814 elsiocb->context1 = NULL;
2816 /* context2 = cmd, context2->next = rsp, context3 = bpl */
2817 if (elsiocb->context2) {
2818 if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
2819 /* Firmware could still be in progress of DMAing
2820 * payload, so don't free data buffer till after
2823 elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
2824 buf_ptr = elsiocb->context2;
2825 elsiocb->context2 = NULL;
2828 spin_lock_irq(&phba->hbalock);
2829 if (!list_empty(&buf_ptr->list)) {
2830 list_remove_head(&buf_ptr->list,
2831 buf_ptr1, struct lpfc_dmabuf,
2833 INIT_LIST_HEAD(&buf_ptr1->list);
2834 list_add_tail(&buf_ptr1->list,
2838 INIT_LIST_HEAD(&buf_ptr->list);
2839 list_add_tail(&buf_ptr->list, &phba->elsbuf);
2841 spin_unlock_irq(&phba->hbalock);
2844 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
2845 lpfc_els_free_data(phba, buf_ptr1);
2849 if (elsiocb->context3) {
2850 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
2851 lpfc_els_free_bpl(phba, buf_ptr);
2853 lpfc_sli_release_iocbq(phba, elsiocb);
2858 * lpfc_cmpl_els_logo_acc: Completion callback function to logo acc response.
2859 * @phba: pointer to lpfc hba data structure.
2860 * @cmdiocb: pointer to lpfc command iocb data structure.
2861 * @rspiocb: pointer to lpfc response iocb data structure.
2863 * This routine is the completion callback function to the Logout (LOGO)
2864 * Accept (ACC) Response ELS command. This routine is invoked to indicate
2865 * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
2866 * release the ndlp if it has the last reference remaining (reference count
2867 * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
2868 * field to NULL to inform the following lpfc_els_free_iocb() routine no
2869 * ndlp reference count needs to be decremented. Otherwise, the ndlp
2870 * reference use-count shall be decremented by the lpfc_els_free_iocb()
2871 * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
2872 * IOCB data structure.
2875 lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2876 struct lpfc_iocbq *rspiocb)
2878 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2879 struct lpfc_vport *vport = cmdiocb->vport;
2882 irsp = &rspiocb->iocb;
2883 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2884 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
2885 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
2886 /* ACC to LOGO completes to NPort <nlp_DID> */
2887 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2888 "0109 ACC to LOGO completes to NPort x%x "
2889 "Data: x%x x%x x%x\n",
2890 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
2893 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
2894 /* NPort Recovery mode or node is just allocated */
2895 if (!lpfc_nlp_not_used(ndlp)) {
2896 /* If the ndlp is being used by another discovery
2897 * thread, just unregister the RPI.
2899 lpfc_unreg_rpi(vport, ndlp);
2901 /* Indicate the node has already released, should
2902 * not reference to it from within lpfc_els_free_iocb.
2904 cmdiocb->context1 = NULL;
2907 lpfc_els_free_iocb(phba, cmdiocb);
2912 * lpfc_mbx_cmpl_dflt_rpi: Completion callbk func for unreg dflt rpi mbox cmd.
2913 * @phba: pointer to lpfc hba data structure.
2914 * @pmb: pointer to the driver internal queue element for mailbox command.
2916 * This routine is the completion callback function for unregister default
2917 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
2918 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
2919 * decrements the ndlp reference count held for this completion callback
2920 * function. After that, it invokes the lpfc_nlp_not_used() to check
2921 * whether there is only one reference left on the ndlp. If so, it will
2922 * perform one more decrement and trigger the release of the ndlp.
2925 lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
2927 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
2928 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
2930 pmb->context1 = NULL;
2931 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2933 mempool_free(pmb, phba->mbox_mem_pool);
2934 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
2936 /* This is the end of the default RPI cleanup logic for this
2937 * ndlp. If no other discovery threads are using this ndlp.
2938 * we should free all resources associated with it.
2940 lpfc_nlp_not_used(ndlp);
2946 * lpfc_cmpl_els_rsp: Completion callback function for els response iocb cmd.
2947 * @phba: pointer to lpfc hba data structure.
2948 * @cmdiocb: pointer to lpfc command iocb data structure.
2949 * @rspiocb: pointer to lpfc response iocb data structure.
2951 * This routine is the completion callback function for ELS Response IOCB
2952 * command. In normal case, this callback function just properly sets the
2953 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
2954 * field in the command IOCB is not NULL, the referred mailbox command will
2955 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
2956 * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
2957 * link down event occurred during the discovery, the lpfc_nlp_not_used()
2958 * routine shall be invoked trying to release the ndlp if no other threads
2959 * are currently referring it.
2962 lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2963 struct lpfc_iocbq *rspiocb)
2965 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2966 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
2967 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
2970 LPFC_MBOXQ_t *mbox = NULL;
2971 struct lpfc_dmabuf *mp = NULL;
2972 uint32_t ls_rjt = 0;
2974 irsp = &rspiocb->iocb;
2976 if (cmdiocb->context_un.mbox)
2977 mbox = cmdiocb->context_un.mbox;
2979 /* First determine if this is a LS_RJT cmpl. Note, this callback
2980 * function can have cmdiocb->contest1 (ndlp) field set to NULL.
2982 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
2983 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
2984 (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) {
2985 /* A LS_RJT associated with Default RPI cleanup has its own
2986 * seperate code path.
2988 if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
2992 /* Check to see if link went down during discovery */
2993 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) {
2995 mp = (struct lpfc_dmabuf *) mbox->context1;
2997 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3000 mempool_free(mbox, phba->mbox_mem_pool);
3002 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3003 (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
3004 if (lpfc_nlp_not_used(ndlp)) {
3006 /* Indicate the node has already released,
3007 * should not reference to it from within
3008 * the routine lpfc_els_free_iocb.
3010 cmdiocb->context1 = NULL;
3015 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3016 "ELS rsp cmpl: status:x%x/x%x did:x%x",
3017 irsp->ulpStatus, irsp->un.ulpWord[4],
3018 cmdiocb->iocb.un.elsreq64.remoteID);
3019 /* ELS response tag <ulpIoTag> completes */
3020 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3021 "0110 ELS response tag x%x completes "
3022 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
3023 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
3024 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
3025 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3028 if ((rspiocb->iocb.ulpStatus == 0)
3029 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
3030 lpfc_unreg_rpi(vport, ndlp);
3031 /* Increment reference count to ndlp to hold the
3032 * reference to ndlp for the callback function.
3034 mbox->context2 = lpfc_nlp_get(ndlp);
3035 mbox->vport = vport;
3036 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
3037 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
3038 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
3041 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
3042 ndlp->nlp_prev_state = ndlp->nlp_state;
3043 lpfc_nlp_set_state(vport, ndlp,
3044 NLP_STE_REG_LOGIN_ISSUE);
3046 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
3047 != MBX_NOT_FINISHED)
3050 /* Decrement the ndlp reference count we
3051 * set for this failed mailbox command.
3055 /* ELS rsp: Cannot issue reg_login for <NPortid> */
3056 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3057 "0138 ELS rsp: Cannot issue reg_login for x%x "
3058 "Data: x%x x%x x%x\n",
3059 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3062 if (lpfc_nlp_not_used(ndlp)) {
3064 /* Indicate node has already been released,
3065 * should not reference to it from within
3066 * the routine lpfc_els_free_iocb.
3068 cmdiocb->context1 = NULL;
3071 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
3072 if (!lpfc_error_lost_link(irsp) &&
3073 ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
3074 if (lpfc_nlp_not_used(ndlp)) {
3076 /* Indicate node has already been
3077 * released, should not reference
3078 * to it from within the routine
3079 * lpfc_els_free_iocb.
3081 cmdiocb->context1 = NULL;
3085 mp = (struct lpfc_dmabuf *) mbox->context1;
3087 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3090 mempool_free(mbox, phba->mbox_mem_pool);
3093 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
3094 spin_lock_irq(shost->host_lock);
3095 ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI);
3096 spin_unlock_irq(shost->host_lock);
3098 /* If the node is not being used by another discovery thread,
3099 * and we are sending a reject, we are done with it.
3100 * Release driver reference count here and free associated
3104 if (lpfc_nlp_not_used(ndlp))
3105 /* Indicate node has already been released,
3106 * should not reference to it from within
3107 * the routine lpfc_els_free_iocb.
3109 cmdiocb->context1 = NULL;
3112 lpfc_els_free_iocb(phba, cmdiocb);
3117 * lpfc_els_rsp_acc: Prepare and issue an acc response iocb command.
3118 * @vport: pointer to a host virtual N_Port data structure.
3119 * @flag: the els command code to be accepted.
3120 * @oldiocb: pointer to the original lpfc command iocb data structure.
3121 * @ndlp: pointer to a node-list data structure.
3122 * @mbox: pointer to the driver internal queue element for mailbox command.
3124 * This routine prepares and issues an Accept (ACC) response IOCB
3125 * command. It uses the @flag to properly set up the IOCB field for the
3126 * specific ACC response command to be issued and invokes the
3127 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
3128 * @mbox pointer is passed in, it will be put into the context_un.mbox
3129 * field of the IOCB for the completion callback function to issue the
3130 * mailbox command to the HBA later when callback is invoked.
3132 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3133 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3134 * will be stored into the context1 field of the IOCB for the completion
3135 * callback function to the corresponding response ELS IOCB command.
3138 * 0 - Successfully issued acc response
3139 * 1 - Failed to issue acc response
3142 lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
3143 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
3146 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3147 struct lpfc_hba *phba = vport->phba;
3150 struct lpfc_iocbq *elsiocb;
3151 struct lpfc_sli_ring *pring;
3152 struct lpfc_sli *psli;
3156 ELS_PKT *els_pkt_ptr;
3159 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
3160 oldcmd = &oldiocb->iocb;
3164 cmdsize = sizeof(uint32_t);
3165 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3166 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
3168 spin_lock_irq(shost->host_lock);
3169 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
3170 spin_unlock_irq(shost->host_lock);
3174 icmd = &elsiocb->iocb;
3175 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3176 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3177 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
3178 pcmd += sizeof(uint32_t);
3180 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3181 "Issue ACC: did:x%x flg:x%x",
3182 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3185 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
3186 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3187 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
3191 icmd = &elsiocb->iocb;
3192 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3193 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3196 elsiocb->context_un.mbox = mbox;
3198 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
3199 pcmd += sizeof(uint32_t);
3200 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
3202 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3203 "Issue ACC PLOGI: did:x%x flg:x%x",
3204 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3207 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
3208 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3209 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
3213 icmd = &elsiocb->iocb;
3214 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3215 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3217 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
3218 sizeof(uint32_t) + sizeof(PRLO));
3219 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
3220 els_pkt_ptr = (ELS_PKT *) pcmd;
3221 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
3223 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3224 "Issue ACC PRLO: did:x%x flg:x%x",
3225 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3230 /* Xmit ELS ACC response tag <ulpIoTag> */
3231 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3232 "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
3233 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n",
3234 elsiocb->iotag, elsiocb->iocb.ulpContext,
3235 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3237 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
3238 spin_lock_irq(shost->host_lock);
3239 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
3240 spin_unlock_irq(shost->host_lock);
3241 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
3243 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
3246 phba->fc_stat.elsXmitACC++;
3247 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
3248 if (rc == IOCB_ERROR) {
3249 lpfc_els_free_iocb(phba, elsiocb);
3256 * lpfc_els_rsp_reject: Propare and issue a rjt response iocb command.
3257 * @vport: pointer to a virtual N_Port data structure.
3259 * @oldiocb: pointer to the original lpfc command iocb data structure.
3260 * @ndlp: pointer to a node-list data structure.
3261 * @mbox: pointer to the driver internal queue element for mailbox command.
3263 * This routine prepares and issue an Reject (RJT) response IOCB
3264 * command. If a @mbox pointer is passed in, it will be put into the
3265 * context_un.mbox field of the IOCB for the completion callback function
3266 * to issue to the HBA later.
3268 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3269 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3270 * will be stored into the context1 field of the IOCB for the completion
3271 * callback function to the reject response ELS IOCB command.
3274 * 0 - Successfully issued reject response
3275 * 1 - Failed to issue reject response
3278 lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
3279 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
3282 struct lpfc_hba *phba = vport->phba;
3285 struct lpfc_iocbq *elsiocb;
3286 struct lpfc_sli_ring *pring;
3287 struct lpfc_sli *psli;
3293 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
3295 cmdsize = 2 * sizeof(uint32_t);
3296 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3297 ndlp->nlp_DID, ELS_CMD_LS_RJT);
3301 icmd = &elsiocb->iocb;
3302 oldcmd = &oldiocb->iocb;
3303 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3304 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3306 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
3307 pcmd += sizeof(uint32_t);
3308 *((uint32_t *) (pcmd)) = rejectError;
3311 elsiocb->context_un.mbox = mbox;
3313 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
3314 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3315 "0129 Xmit ELS RJT x%x response tag x%x "
3316 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
3318 rejectError, elsiocb->iotag,
3319 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
3320 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
3321 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3322 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
3323 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
3325 phba->fc_stat.elsXmitLSRJT++;
3326 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
3327 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
3329 if (rc == IOCB_ERROR) {
3330 lpfc_els_free_iocb(phba, elsiocb);
3337 * lpfc_els_rsp_adisc_acc: Prepare and issue acc response to adisc iocb cmd.
3338 * @vport: pointer to a virtual N_Port data structure.
3339 * @oldiocb: pointer to the original lpfc command iocb data structure.
3340 * @ndlp: pointer to a node-list data structure.
3342 * This routine prepares and issues an Accept (ACC) response to Address
3343 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
3344 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3346 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3347 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3348 * will be stored into the context1 field of the IOCB for the completion
3349 * callback function to the ADISC Accept response ELS IOCB command.
3352 * 0 - Successfully issued acc adisc response
3353 * 1 - Failed to issue adisc acc response
3356 lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
3357 struct lpfc_nodelist *ndlp)
3359 struct lpfc_hba *phba = vport->phba;
3360 struct lpfc_sli *psli = &phba->sli;
3361 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
3363 IOCB_t *icmd, *oldcmd;
3364 struct lpfc_iocbq *elsiocb;
3369 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
3370 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3371 ndlp->nlp_DID, ELS_CMD_ACC);
3375 icmd = &elsiocb->iocb;
3376 oldcmd = &oldiocb->iocb;
3377 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3379 /* Xmit ADISC ACC response tag <ulpIoTag> */
3380 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3381 "0130 Xmit ADISC ACC response iotag x%x xri: "
3382 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
3383 elsiocb->iotag, elsiocb->iocb.ulpContext,
3384 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3386 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3388 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
3389 pcmd += sizeof(uint32_t);
3391 ap = (ADISC *) (pcmd);
3392 ap->hardAL_PA = phba->fc_pref_ALPA;
3393 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
3394 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
3395 ap->DID = be32_to_cpu(vport->fc_myDID);
3397 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3398 "Issue ACC ADISC: did:x%x flg:x%x",
3399 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3401 phba->fc_stat.elsXmitACC++;
3402 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
3403 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
3404 if (rc == IOCB_ERROR) {
3405 lpfc_els_free_iocb(phba, elsiocb);
3412 * lpfc_els_rsp_prli_acc: Prepare and issue acc response to prli iocb cmd.
3413 * @vport: pointer to a virtual N_Port data structure.
3414 * @oldiocb: pointer to the original lpfc command iocb data structure.
3415 * @ndlp: pointer to a node-list data structure.
3417 * This routine prepares and issues an Accept (ACC) response to Process
3418 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
3419 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3421 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3422 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3423 * will be stored into the context1 field of the IOCB for the completion
3424 * callback function to the PRLI Accept response ELS IOCB command.
3427 * 0 - Successfully issued acc prli response
3428 * 1 - Failed to issue acc prli response
3431 lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
3432 struct lpfc_nodelist *ndlp)
3434 struct lpfc_hba *phba = vport->phba;
3439 struct lpfc_iocbq *elsiocb;
3440 struct lpfc_sli_ring *pring;
3441 struct lpfc_sli *psli;
3447 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
3449 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
3450 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3451 ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)));
3455 icmd = &elsiocb->iocb;
3456 oldcmd = &oldiocb->iocb;
3457 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3458 /* Xmit PRLI ACC response tag <ulpIoTag> */
3459 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3460 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
3461 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
3462 elsiocb->iotag, elsiocb->iocb.ulpContext,
3463 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3465 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3467 *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
3468 pcmd += sizeof(uint32_t);
3470 /* For PRLI, remainder of payload is PRLI parameter page */
3471 memset(pcmd, 0, sizeof(PRLI));
3473 npr = (PRLI *) pcmd;
3476 * If the remote port is a target and our firmware version is 3.20 or
3477 * later, set the following bits for FC-TAPE support.
3479 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
3480 (vpd->rev.feaLevelHigh >= 0x02)) {
3481 npr->ConfmComplAllowed = 1;
3483 npr->TaskRetryIdReq = 1;
3486 npr->acceptRspCode = PRLI_REQ_EXECUTED;
3487 npr->estabImagePair = 1;
3488 npr->readXferRdyDis = 1;
3489 npr->ConfmComplAllowed = 1;
3491 npr->prliType = PRLI_FCP_TYPE;
3492 npr->initiatorFunc = 1;
3494 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3495 "Issue ACC PRLI: did:x%x flg:x%x",
3496 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3498 phba->fc_stat.elsXmitACC++;
3499 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
3501 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
3502 if (rc == IOCB_ERROR) {
3503 lpfc_els_free_iocb(phba, elsiocb);
3510 * lpfc_els_rsp_rnid_acc: Issue rnid acc response iocb command.
3511 * @vport: pointer to a virtual N_Port data structure.
3512 * @format: rnid command format.
3513 * @oldiocb: pointer to the original lpfc command iocb data structure.
3514 * @ndlp: pointer to a node-list data structure.
3516 * This routine issues a Request Node Identification Data (RNID) Accept
3517 * (ACC) response. It constructs the RNID ACC response command according to
3518 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
3519 * issue the response. Note that this command does not need to hold the ndlp
3520 * reference count for the callback. So, the ndlp reference count taken by
3521 * the lpfc_prep_els_iocb() routine is put back and the context1 field of
3522 * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
3523 * there is no ndlp reference available.
3525 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3526 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3527 * will be stored into the context1 field of the IOCB for the completion
3528 * callback function. However, for the RNID Accept Response ELS command,
3529 * this is undone later by this routine after the IOCB is allocated.
3532 * 0 - Successfully issued acc rnid response
3533 * 1 - Failed to issue acc rnid response
3536 lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
3537 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
3539 struct lpfc_hba *phba = vport->phba;
3541 IOCB_t *icmd, *oldcmd;
3542 struct lpfc_iocbq *elsiocb;
3543 struct lpfc_sli_ring *pring;
3544 struct lpfc_sli *psli;
3550 pring = &psli->ring[LPFC_ELS_RING];
3552 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
3553 + (2 * sizeof(struct lpfc_name));
3555 cmdsize += sizeof(RNID_TOP_DISC);
3557 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3558 ndlp->nlp_DID, ELS_CMD_ACC);
3562 icmd = &elsiocb->iocb;
3563 oldcmd = &oldiocb->iocb;
3564 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3565 /* Xmit RNID ACC response tag <ulpIoTag> */
3566 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3567 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
3568 elsiocb->iotag, elsiocb->iocb.ulpContext);
3569 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3570 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
3571 pcmd += sizeof(uint32_t);
3573 memset(pcmd, 0, sizeof(RNID));
3574 rn = (RNID *) (pcmd);
3575 rn->Format = format;
3576 rn->CommonLen = (2 * sizeof(struct lpfc_name));
3577 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
3578 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
3581 rn->SpecificLen = 0;
3583 case RNID_TOPOLOGY_DISC:
3584 rn->SpecificLen = sizeof(RNID_TOP_DISC);
3585 memcpy(&rn->un.topologyDisc.portName,
3586 &vport->fc_portname, sizeof(struct lpfc_name));
3587 rn->un.topologyDisc.unitType = RNID_HBA;
3588 rn->un.topologyDisc.physPort = 0;
3589 rn->un.topologyDisc.attachedNodes = 0;
3593 rn->SpecificLen = 0;
3597 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3598 "Issue ACC RNID: did:x%x flg:x%x",
3599 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3601 phba->fc_stat.elsXmitACC++;
3602 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
3604 elsiocb->context1 = NULL; /* Don't need ndlp for cmpl,
3605 * it could be freed */
3607 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
3608 if (rc == IOCB_ERROR) {
3609 lpfc_els_free_iocb(phba, elsiocb);
3616 * lpfc_els_disc_adisc: Issue remaining adisc iocbs to npr nodes of a vport.
3617 * @vport: pointer to a host virtual N_Port data structure.
3619 * This routine issues Address Discover (ADISC) ELS commands to those
3620 * N_Ports which are in node port recovery state and ADISC has not been issued
3621 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
3622 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
3623 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
3624 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
3625 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
3626 * IOCBs quit for later pick up. On the other hand, after walking through
3627 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
3628 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
3629 * no more ADISC need to be sent.
3632 * The number of N_Ports with adisc issued.
3635 lpfc_els_disc_adisc(struct lpfc_vport *vport)
3637 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3638 struct lpfc_nodelist *ndlp, *next_ndlp;
3641 /* go thru NPR nodes and issue any remaining ELS ADISCs */
3642 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
3643 if (!NLP_CHK_NODE_ACT(ndlp))
3645 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
3646 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
3647 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
3648 spin_lock_irq(shost->host_lock);
3649 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
3650 spin_unlock_irq(shost->host_lock);
3651 ndlp->nlp_prev_state = ndlp->nlp_state;
3652 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
3653 lpfc_issue_els_adisc(vport, ndlp, 0);
3655 vport->num_disc_nodes++;
3656 if (vport->num_disc_nodes >=
3657 vport->cfg_discovery_threads) {
3658 spin_lock_irq(shost->host_lock);
3659 vport->fc_flag |= FC_NLP_MORE;
3660 spin_unlock_irq(shost->host_lock);
3665 if (sentadisc == 0) {
3666 spin_lock_irq(shost->host_lock);
3667 vport->fc_flag &= ~FC_NLP_MORE;
3668 spin_unlock_irq(shost->host_lock);
3674 * lpfc_els_disc_plogi: Issue plogi for all npr nodes of a vport before adisc.
3675 * @vport: pointer to a host virtual N_Port data structure.
3677 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
3678 * which are in node port recovery state, with a @vport. Each time an ELS
3679 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
3680 * the per @vport number of discover count (num_disc_nodes) shall be
3681 * incremented. If the num_disc_nodes reaches a pre-configured threshold
3682 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
3683 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
3684 * later pick up. On the other hand, after walking through all the ndlps with
3685 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
3686 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
3687 * PLOGI need to be sent.
3690 * The number of N_Ports with plogi issued.
3693 lpfc_els_disc_plogi(struct lpfc_vport *vport)
3695 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3696 struct lpfc_nodelist *ndlp, *next_ndlp;
3699 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
3700 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
3701 if (!NLP_CHK_NODE_ACT(ndlp))
3703 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
3704 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
3705 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
3706 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
3707 ndlp->nlp_prev_state = ndlp->nlp_state;
3708 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
3709 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
3711 vport->num_disc_nodes++;
3712 if (vport->num_disc_nodes >=
3713 vport->cfg_discovery_threads) {
3714 spin_lock_irq(shost->host_lock);
3715 vport->fc_flag |= FC_NLP_MORE;
3716 spin_unlock_irq(shost->host_lock);
3722 lpfc_set_disctmo(vport);
3725 spin_lock_irq(shost->host_lock);
3726 vport->fc_flag &= ~FC_NLP_MORE;
3727 spin_unlock_irq(shost->host_lock);
3733 * lpfc_els_flush_rscn: Clean up any rscn activities with a vport.
3734 * @vport: pointer to a host virtual N_Port data structure.
3736 * This routine cleans up any Registration State Change Notification
3737 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
3738 * @vport together with the host_lock is used to prevent multiple thread
3739 * trying to access the RSCN array on a same @vport at the same time.
3742 lpfc_els_flush_rscn(struct lpfc_vport *vport)
3744 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3745 struct lpfc_hba *phba = vport->phba;
3748 spin_lock_irq(shost->host_lock);
3749 if (vport->fc_rscn_flush) {
3750 /* Another thread is walking fc_rscn_id_list on this vport */
3751 spin_unlock_irq(shost->host_lock);
3754 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
3755 vport->fc_rscn_flush = 1;
3756 spin_unlock_irq(shost->host_lock);
3758 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
3759 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
3760 vport->fc_rscn_id_list[i] = NULL;
3762 spin_lock_irq(shost->host_lock);
3763 vport->fc_rscn_id_cnt = 0;
3764 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
3765 spin_unlock_irq(shost->host_lock);
3766 lpfc_can_disctmo(vport);
3767 /* Indicate we are done walking this fc_rscn_id_list */
3768 vport->fc_rscn_flush = 0;
3772 * lpfc_rscn_payload_check: Check whether there is a pending rscn to a did.
3773 * @vport: pointer to a host virtual N_Port data structure.
3774 * @did: remote destination port identifier.
3776 * This routine checks whether there is any pending Registration State
3777 * Configuration Notification (RSCN) to a @did on @vport.
3780 * None zero - The @did matched with a pending rscn
3781 * 0 - not able to match @did with a pending rscn
3784 lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
3789 uint32_t payload_len, i;
3790 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3792 ns_did.un.word = did;
3794 /* Never match fabric nodes for RSCNs */
3795 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
3798 /* If we are doing a FULL RSCN rediscovery, match everything */
3799 if (vport->fc_flag & FC_RSCN_DISCOVERY)
3802 spin_lock_irq(shost->host_lock);
3803 if (vport->fc_rscn_flush) {
3804 /* Another thread is walking fc_rscn_id_list on this vport */
3805 spin_unlock_irq(shost->host_lock);
3808 /* Indicate we are walking fc_rscn_id_list on this vport */
3809 vport->fc_rscn_flush = 1;
3810 spin_unlock_irq(shost->host_lock);
3811 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
3812 lp = vport->fc_rscn_id_list[i]->virt;
3813 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
3814 payload_len -= sizeof(uint32_t); /* take off word 0 */
3815 while (payload_len) {
3816 rscn_did.un.word = be32_to_cpu(*lp++);
3817 payload_len -= sizeof(uint32_t);
3818 switch (rscn_did.un.b.resv) {
3819 case 0: /* Single N_Port ID effected */
3820 if (ns_did.un.word == rscn_did.un.word)
3821 goto return_did_out;
3823 case 1: /* Whole N_Port Area effected */
3824 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
3825 && (ns_did.un.b.area == rscn_did.un.b.area))
3826 goto return_did_out;
3828 case 2: /* Whole N_Port Domain effected */
3829 if (ns_did.un.b.domain == rscn_did.un.b.domain)
3830 goto return_did_out;
3833 /* Unknown Identifier in RSCN node */
3834 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
3835 "0217 Unknown Identifier in "
3836 "RSCN payload Data: x%x\n",
3838 case 3: /* Whole Fabric effected */
3839 goto return_did_out;
3843 /* Indicate we are done with walking fc_rscn_id_list on this vport */
3844 vport->fc_rscn_flush = 0;
3847 /* Indicate we are done with walking fc_rscn_id_list on this vport */
3848 vport->fc_rscn_flush = 0;
3853 * lpfc_rscn_recovery_check: Send recovery event to vport nodes matching rscn
3854 * @vport: pointer to a host virtual N_Port data structure.
3856 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
3857 * state machine for a @vport's nodes that are with pending RSCN (Registration
3858 * State Change Notification).
3861 * 0 - Successful (currently alway return 0)
3864 lpfc_rscn_recovery_check(struct lpfc_vport *vport)
3866 struct lpfc_nodelist *ndlp = NULL;
3868 /* Move all affected nodes by pending RSCNs to NPR state. */
3869 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
3870 if (!NLP_CHK_NODE_ACT(ndlp) ||
3871 (ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
3872 !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
3874 lpfc_disc_state_machine(vport, ndlp, NULL,
3875 NLP_EVT_DEVICE_RECOVERY);
3876 lpfc_cancel_retry_delay_tmo(vport, ndlp);
3882 * lpfc_els_rcv_rscn: Process an unsolicited rscn iocb.
3883 * @vport: pointer to a host virtual N_Port data structure.
3884 * @cmdiocb: pointer to lpfc command iocb data structure.
3885 * @ndlp: pointer to a node-list data structure.
3887 * This routine processes an unsolicited RSCN (Registration State Change
3888 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
3889 * to invoke fc_host_post_event() routine to the FC transport layer. If the
3890 * discover state machine is about to begin discovery, it just accepts the
3891 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
3892 * contains N_Port IDs for other vports on this HBA, it just accepts the
3893 * RSCN and ignore processing it. If the state machine is in the recovery
3894 * state, the fc_rscn_id_list of this @vport is walked and the
3895 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
3896 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
3897 * routine is invoked to handle the RSCN event.
3900 * 0 - Just sent the acc response
3901 * 1 - Sent the acc response and waited for name server completion
3904 lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3905 struct lpfc_nodelist *ndlp)
3907 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3908 struct lpfc_hba *phba = vport->phba;
3909 struct lpfc_dmabuf *pcmd;
3910 uint32_t *lp, *datap;
3912 uint32_t payload_len, length, nportid, *cmd;
3914 int rscn_id = 0, hba_id = 0;
3917 icmd = &cmdiocb->iocb;
3918 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3919 lp = (uint32_t *) pcmd->virt;
3921 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
3922 payload_len -= sizeof(uint32_t); /* take off word 0 */
3924 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
3925 "0214 RSCN received Data: x%x x%x x%x x%x\n",
3926 vport->fc_flag, payload_len, *lp,
3927 vport->fc_rscn_id_cnt);
3928 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
3929 fc_host_post_event(shost, fc_get_event_number(),
3930 FCH_EVT_RSCN, lp[i]);
3932 /* If we are about to begin discovery, just ACC the RSCN.
3933 * Discovery processing will satisfy it.
3935 if (vport->port_state <= LPFC_NS_QRY) {
3936 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3937 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
3938 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
3940 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
3944 /* If this RSCN just contains NPortIDs for other vports on this HBA,
3945 * just ACC and ignore it.
3947 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
3948 !(vport->cfg_peer_port_login)) {
3953 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
3954 i -= sizeof(uint32_t);
3956 if (lpfc_find_vport_by_did(phba, nportid))
3959 if (rscn_id == hba_id) {
3960 /* ALL NPortIDs in RSCN are on HBA */
3961 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
3963 "Data: x%x x%x x%x x%x\n",
3964 vport->fc_flag, payload_len,
3965 *lp, vport->fc_rscn_id_cnt);
3966 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3967 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
3968 ndlp->nlp_DID, vport->port_state,
3971 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
3977 spin_lock_irq(shost->host_lock);
3978 if (vport->fc_rscn_flush) {
3979 /* Another thread is walking fc_rscn_id_list on this vport */
3980 spin_unlock_irq(shost->host_lock);
3981 vport->fc_flag |= FC_RSCN_DISCOVERY;
3983 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
3986 /* Indicate we are walking fc_rscn_id_list on this vport */
3987 vport->fc_rscn_flush = 1;
3988 spin_unlock_irq(shost->host_lock);
3989 /* Get the array count after sucessfully have the token */
3990 rscn_cnt = vport->fc_rscn_id_cnt;
3991 /* If we are already processing an RSCN, save the received
3992 * RSCN payload buffer, cmdiocb->context2 to process later.
3994 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
3995 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3996 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
3997 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
3999 spin_lock_irq(shost->host_lock);
4000 vport->fc_flag |= FC_RSCN_DEFERRED;
4001 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
4002 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
4003 vport->fc_flag |= FC_RSCN_MODE;
4004 spin_unlock_irq(shost->host_lock);
4006 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
4007 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
4010 (payload_len + length <= LPFC_BPL_SIZE)) {
4011 *cmd &= ELS_CMD_MASK;
4012 *cmd |= cpu_to_be32(payload_len + length);
4013 memcpy(((uint8_t *)cmd) + length, lp,
4016 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
4017 vport->fc_rscn_id_cnt++;
4018 /* If we zero, cmdiocb->context2, the calling
4019 * routine will not try to free it.
4021 cmdiocb->context2 = NULL;
4024 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4025 "0235 Deferred RSCN "
4026 "Data: x%x x%x x%x\n",
4027 vport->fc_rscn_id_cnt, vport->fc_flag,
4030 vport->fc_flag |= FC_RSCN_DISCOVERY;
4031 spin_unlock_irq(shost->host_lock);
4032 /* ReDiscovery RSCN */
4033 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4034 "0234 ReDiscovery RSCN "
4035 "Data: x%x x%x x%x\n",
4036 vport->fc_rscn_id_cnt, vport->fc_flag,
4039 /* Indicate we are done walking fc_rscn_id_list on this vport */
4040 vport->fc_rscn_flush = 0;
4042 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
4043 /* send RECOVERY event for ALL nodes that match RSCN payload */
4044 lpfc_rscn_recovery_check(vport);
4045 spin_lock_irq(shost->host_lock);
4046 vport->fc_flag &= ~FC_RSCN_DEFERRED;
4047 spin_unlock_irq(shost->host_lock);
4050 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4051 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
4052 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4054 spin_lock_irq(shost->host_lock);
4055 vport->fc_flag |= FC_RSCN_MODE;
4056 spin_unlock_irq(shost->host_lock);
4057 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
4058 /* Indicate we are done walking fc_rscn_id_list on this vport */
4059 vport->fc_rscn_flush = 0;
4061 * If we zero, cmdiocb->context2, the calling routine will
4062 * not try to free it.
4064 cmdiocb->context2 = NULL;
4065 lpfc_set_disctmo(vport);
4067 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
4068 /* send RECOVERY event for ALL nodes that match RSCN payload */
4069 lpfc_rscn_recovery_check(vport);
4070 return lpfc_els_handle_rscn(vport);
4074 * lpfc_els_handle_rscn: Handle rscn for a vport.
4075 * @vport: pointer to a host virtual N_Port data structure.
4077 * This routine handles the Registration State Configuration Notification
4078 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
4079 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
4080 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
4081 * NameServer shall be issued. If CT command to the NameServer fails to be
4082 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
4083 * RSCN activities with the @vport.
4086 * 0 - Cleaned up rscn on the @vport
4087 * 1 - Wait for plogi to name server before proceed
4090 lpfc_els_handle_rscn(struct lpfc_vport *vport)
4092 struct lpfc_nodelist *ndlp;
4093 struct lpfc_hba *phba = vport->phba;
4095 /* Ignore RSCN if the port is being torn down. */
4096 if (vport->load_flag & FC_UNLOADING) {
4097 lpfc_els_flush_rscn(vport);
4101 /* Start timer for RSCN processing */
4102 lpfc_set_disctmo(vport);
4104 /* RSCN processed */
4105 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4106 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
4107 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
4110 /* To process RSCN, first compare RSCN data with NameServer */
4111 vport->fc_ns_retry = 0;
4112 vport->num_disc_nodes = 0;
4114 ndlp = lpfc_findnode_did(vport, NameServer_DID);
4115 if (ndlp && NLP_CHK_NODE_ACT(ndlp)
4116 && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
4117 /* Good ndlp, issue CT Request to NameServer */
4118 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0)
4119 /* Wait for NameServer query cmpl before we can
4123 /* If login to NameServer does not exist, issue one */
4124 /* Good status, issue PLOGI to NameServer */
4125 ndlp = lpfc_findnode_did(vport, NameServer_DID);
4126 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
4127 /* Wait for NameServer login cmpl before we can
4132 ndlp = lpfc_enable_node(vport, ndlp,
4133 NLP_STE_PLOGI_ISSUE);
4135 lpfc_els_flush_rscn(vport);
4138 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
4140 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
4142 lpfc_els_flush_rscn(vport);
4145 lpfc_nlp_init(vport, ndlp, NameServer_DID);
4146 ndlp->nlp_prev_state = ndlp->nlp_state;
4147 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
4149 ndlp->nlp_type |= NLP_FABRIC;
4150 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
4151 /* Wait for NameServer login cmpl before we can
4157 lpfc_els_flush_rscn(vport);
4162 * lpfc_els_rcv_flogi: Process an unsolicited flogi iocb.
4163 * @vport: pointer to a host virtual N_Port data structure.
4164 * @cmdiocb: pointer to lpfc command iocb data structure.
4165 * @ndlp: pointer to a node-list data structure.
4167 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
4168 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
4169 * point topology. As an unsolicited FLOGI should not be received in a loop
4170 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
4171 * lpfc_check_sparm() routine is invoked to check the parameters in the
4172 * unsolicited FLOGI. If parameters validation failed, the routine
4173 * lpfc_els_rsp_reject() shall be called with reject reason code set to
4174 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
4175 * FLOGI shall be compared with the Port WWN of the @vport to determine who
4176 * will initiate PLOGI. The higher lexicographical value party shall has
4177 * higher priority (as the winning port) and will initiate PLOGI and
4178 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
4179 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
4180 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
4183 * 0 - Successfully processed the unsolicited flogi
4184 * 1 - Failed to process the unsolicited flogi
4187 lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4188 struct lpfc_nodelist *ndlp)
4190 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4191 struct lpfc_hba *phba = vport->phba;
4192 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4193 uint32_t *lp = (uint32_t *) pcmd->virt;
4194 IOCB_t *icmd = &cmdiocb->iocb;
4195 struct serv_parm *sp;
4202 sp = (struct serv_parm *) lp;
4204 /* FLOGI received */
4206 lpfc_set_disctmo(vport);
4208 if (phba->fc_topology == TOPOLOGY_LOOP) {
4209 /* We should never receive a FLOGI in loop mode, ignore it */
4210 did = icmd->un.elsreq64.remoteID;
4212 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
4214 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4215 "0113 An FLOGI ELS command x%x was "
4216 "received from DID x%x in Loop Mode\n",
4223 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3))) {
4224 /* For a FLOGI we accept, then if our portname is greater
4225 * then the remote portname we initiate Nport login.
4228 rc = memcmp(&vport->fc_portname, &sp->portName,
4229 sizeof(struct lpfc_name));
4232 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4236 lpfc_linkdown(phba);
4237 lpfc_init_link(phba, mbox,
4239 phba->cfg_link_speed);
4240 mbox->mb.un.varInitLnk.lipsr_AL_PA = 0;
4241 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
4242 mbox->vport = vport;
4243 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
4244 lpfc_set_loopback_flag(phba);
4245 if (rc == MBX_NOT_FINISHED) {
4246 mempool_free(mbox, phba->mbox_mem_pool);
4249 } else if (rc > 0) { /* greater than */
4250 spin_lock_irq(shost->host_lock);
4251 vport->fc_flag |= FC_PT2PT_PLOGI;
4252 spin_unlock_irq(shost->host_lock);
4254 spin_lock_irq(shost->host_lock);
4255 vport->fc_flag |= FC_PT2PT;
4256 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
4257 spin_unlock_irq(shost->host_lock);
4259 /* Reject this request because invalid parameters */
4260 stat.un.b.lsRjtRsvd0 = 0;
4261 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4262 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
4263 stat.un.b.vendorUnique = 0;
4264 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4270 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
4276 * lpfc_els_rcv_rnid: Process an unsolicited rnid iocb.
4277 * @vport: pointer to a host virtual N_Port data structure.
4278 * @cmdiocb: pointer to lpfc command iocb data structure.
4279 * @ndlp: pointer to a node-list data structure.
4281 * This routine processes Request Node Identification Data (RNID) IOCB
4282 * received as an ELS unsolicited event. Only when the RNID specified format
4283 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
4284 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
4285 * Accept (ACC) the RNID ELS command. All the other RNID formats are
4286 * rejected by invoking the lpfc_els_rsp_reject() routine.
4289 * 0 - Successfully processed rnid iocb (currently always return 0)
4292 lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4293 struct lpfc_nodelist *ndlp)
4295 struct lpfc_dmabuf *pcmd;
4302 icmd = &cmdiocb->iocb;
4303 did = icmd->un.elsreq64.remoteID;
4304 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4305 lp = (uint32_t *) pcmd->virt;
4312 switch (rn->Format) {
4314 case RNID_TOPOLOGY_DISC:
4316 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
4319 /* Reject this request because format not supported */
4320 stat.un.b.lsRjtRsvd0 = 0;
4321 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4322 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4323 stat.un.b.vendorUnique = 0;
4324 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4331 * lpfc_els_rcv_lirr: Process an unsolicited lirr iocb.
4332 * @vport: pointer to a host virtual N_Port data structure.
4333 * @cmdiocb: pointer to lpfc command iocb data structure.
4334 * @ndlp: pointer to a node-list data structure.
4336 * This routine processes a Link Incident Report Registration(LIRR) IOCB
4337 * received as an ELS unsolicited event. Currently, this function just invokes
4338 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
4341 * 0 - Successfully processed lirr iocb (currently always return 0)
4344 lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4345 struct lpfc_nodelist *ndlp)
4349 /* For now, unconditionally reject this command */
4350 stat.un.b.lsRjtRsvd0 = 0;
4351 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4352 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4353 stat.un.b.vendorUnique = 0;
4354 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
4359 * lpfc_els_rsp_rps_acc: Completion callbk func for MBX_READ_LNK_STAT mbox cmd.
4360 * @phba: pointer to lpfc hba data structure.
4361 * @pmb: pointer to the driver internal queue element for mailbox command.
4363 * This routine is the completion callback function for the MBX_READ_LNK_STAT
4364 * mailbox command. This callback function is to actually send the Accept
4365 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
4366 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
4367 * mailbox command, constructs the RPS response with the link statistics
4368 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
4369 * response to the RPS.
4371 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4372 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4373 * will be stored into the context1 field of the IOCB for the completion
4374 * callback function to the RPS Accept Response ELS IOCB command.
4378 lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4380 struct lpfc_sli *psli = &phba->sli;
4381 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
4386 struct lpfc_iocbq *elsiocb;
4387 struct lpfc_nodelist *ndlp;
4388 uint16_t xri, status;
4393 ndlp = (struct lpfc_nodelist *) pmb->context2;
4394 xri = (uint16_t) ((unsigned long)(pmb->context1));
4395 pmb->context1 = NULL;
4396 pmb->context2 = NULL;
4398 if (mb->mbxStatus) {
4399 mempool_free(pmb, phba->mbox_mem_pool);
4403 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
4404 mempool_free(pmb, phba->mbox_mem_pool);
4405 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
4406 lpfc_max_els_tries, ndlp,
4407 ndlp->nlp_DID, ELS_CMD_ACC);
4409 /* Decrement the ndlp reference count from previous mbox command */
4415 icmd = &elsiocb->iocb;
4416 icmd->ulpContext = xri;
4418 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4419 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4420 pcmd += sizeof(uint32_t); /* Skip past command */
4421 rps_rsp = (RPS_RSP *)pcmd;
4423 if (phba->fc_topology != TOPOLOGY_LOOP)
4427 if (phba->pport->fc_flag & FC_FABRIC)
4431 rps_rsp->portStatus = cpu_to_be16(status);
4432 rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
4433 rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
4434 rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
4435 rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
4436 rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
4437 rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
4438 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
4439 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
4440 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
4441 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
4442 elsiocb->iotag, elsiocb->iocb.ulpContext,
4443 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4445 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4446 phba->fc_stat.elsXmitACC++;
4447 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR)
4448 lpfc_els_free_iocb(phba, elsiocb);
4453 * lpfc_els_rcv_rps: Process an unsolicited rps iocb.
4454 * @vport: pointer to a host virtual N_Port data structure.
4455 * @cmdiocb: pointer to lpfc command iocb data structure.
4456 * @ndlp: pointer to a node-list data structure.
4458 * This routine processes Read Port Status (RPS) IOCB received as an
4459 * ELS unsolicited event. It first checks the remote port state. If the
4460 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
4461 * state, it invokes the lpfc_els_rsp_reject() routine to send the reject
4462 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
4463 * for reading the HBA link statistics. It is for the callback function,
4464 * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command
4465 * to actually sending out RPS Accept (ACC) response.
4468 * 0 - Successfully processed rps iocb (currently always return 0)
4471 lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4472 struct lpfc_nodelist *ndlp)
4474 struct lpfc_hba *phba = vport->phba;
4478 struct lpfc_dmabuf *pcmd;
4482 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
4483 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
4484 stat.un.b.lsRjtRsvd0 = 0;
4485 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4486 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4487 stat.un.b.vendorUnique = 0;
4488 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4492 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4493 lp = (uint32_t *) pcmd->virt;
4494 flag = (be32_to_cpu(*lp++) & 0xf);
4498 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
4499 ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
4500 sizeof(struct lpfc_name)) == 0))) {
4502 printk("Fix me....\n");
4504 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
4506 lpfc_read_lnk_stat(phba, mbox);
4508 (void *)((unsigned long) cmdiocb->iocb.ulpContext);
4509 mbox->context2 = lpfc_nlp_get(ndlp);
4510 mbox->vport = vport;
4511 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
4512 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
4513 != MBX_NOT_FINISHED)
4514 /* Mbox completion will send ELS Response */
4516 /* Decrement reference count used for the failed mbox
4520 mempool_free(mbox, phba->mbox_mem_pool);
4523 stat.un.b.lsRjtRsvd0 = 0;
4524 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4525 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4526 stat.un.b.vendorUnique = 0;
4527 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
4532 * lpfc_els_rsp_rpl_acc: Issue an accept rpl els command.
4533 * @vport: pointer to a host virtual N_Port data structure.
4534 * @cmdsize: size of the ELS command.
4535 * @oldiocb: pointer to the original lpfc command iocb data structure.
4536 * @ndlp: pointer to a node-list data structure.
4538 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
4539 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
4541 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4542 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4543 * will be stored into the context1 field of the IOCB for the completion
4544 * callback function to the RPL Accept Response ELS command.
4547 * 0 - Successfully issued ACC RPL ELS command
4548 * 1 - Failed to issue ACC RPL ELS command
4551 lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
4552 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
4554 struct lpfc_hba *phba = vport->phba;
4555 IOCB_t *icmd, *oldcmd;
4557 struct lpfc_iocbq *elsiocb;
4558 struct lpfc_sli *psli = &phba->sli;
4559 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
4562 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4563 ndlp->nlp_DID, ELS_CMD_ACC);
4568 icmd = &elsiocb->iocb;
4569 oldcmd = &oldiocb->iocb;
4570 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
4572 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4573 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4574 pcmd += sizeof(uint16_t);
4575 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
4576 pcmd += sizeof(uint16_t);
4578 /* Setup the RPL ACC payload */
4579 rpl_rsp.listLen = be32_to_cpu(1);
4581 rpl_rsp.port_num_blk.portNum = 0;
4582 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
4583 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
4584 sizeof(struct lpfc_name));
4585 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
4586 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
4587 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4588 "0120 Xmit ELS RPL ACC response tag x%x "
4589 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
4591 elsiocb->iotag, elsiocb->iocb.ulpContext,
4592 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4594 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4595 phba->fc_stat.elsXmitACC++;
4596 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
4597 lpfc_els_free_iocb(phba, elsiocb);
4604 * lpfc_els_rcv_rpl: Process an unsolicited rpl iocb.
4605 * @vport: pointer to a host virtual N_Port data structure.
4606 * @cmdiocb: pointer to lpfc command iocb data structure.
4607 * @ndlp: pointer to a node-list data structure.
4609 * This routine processes Read Port List (RPL) IOCB received as an ELS
4610 * unsolicited event. It first checks the remote port state. If the remote
4611 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
4612 * invokes the lpfc_els_rsp_reject() routine to send reject response.
4613 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
4614 * to accept the RPL.
4617 * 0 - Successfully processed rpl iocb (currently always return 0)
4620 lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4621 struct lpfc_nodelist *ndlp)
4623 struct lpfc_dmabuf *pcmd;
4630 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
4631 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
4632 stat.un.b.lsRjtRsvd0 = 0;
4633 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4634 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4635 stat.un.b.vendorUnique = 0;
4636 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4640 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4641 lp = (uint32_t *) pcmd->virt;
4642 rpl = (RPL *) (lp + 1);
4644 maxsize = be32_to_cpu(rpl->maxsize);
4646 /* We support only one port */
4647 if ((rpl->index == 0) &&
4649 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
4650 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
4652 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
4654 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
4660 * lpfc_els_rcv_farp: Process an unsolicited farp request els command.
4661 * @vport: pointer to a virtual N_Port data structure.
4662 * @cmdiocb: pointer to lpfc command iocb data structure.
4663 * @ndlp: pointer to a node-list data structure.
4665 * This routine processes Fibre Channel Address Resolution Protocol
4666 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
4667 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
4668 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
4669 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
4670 * remote PortName is compared against the FC PortName stored in the @vport
4671 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
4672 * compared against the FC NodeName stored in the @vport data structure.
4673 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
4674 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
4675 * invoked to send out FARP Response to the remote node. Before sending the
4676 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
4677 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
4678 * routine is invoked to log into the remote port first.
4681 * 0 - Either the FARP Match Mode not supported or successfully processed
4684 lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4685 struct lpfc_nodelist *ndlp)
4687 struct lpfc_dmabuf *pcmd;
4691 uint32_t cmd, cnt, did;
4693 icmd = &cmdiocb->iocb;
4694 did = icmd->un.elsreq64.remoteID;
4695 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4696 lp = (uint32_t *) pcmd->virt;
4700 /* FARP-REQ received from DID <did> */
4701 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4702 "0601 FARP-REQ received from DID x%x\n", did);
4703 /* We will only support match on WWPN or WWNN */
4704 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
4709 /* If this FARP command is searching for my portname */
4710 if (fp->Mflags & FARP_MATCH_PORT) {
4711 if (memcmp(&fp->RportName, &vport->fc_portname,
4712 sizeof(struct lpfc_name)) == 0)
4716 /* If this FARP command is searching for my nodename */
4717 if (fp->Mflags & FARP_MATCH_NODE) {
4718 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
4719 sizeof(struct lpfc_name)) == 0)
4724 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
4725 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
4726 /* Log back into the node before sending the FARP. */
4727 if (fp->Rflags & FARP_REQUEST_PLOGI) {
4728 ndlp->nlp_prev_state = ndlp->nlp_state;
4729 lpfc_nlp_set_state(vport, ndlp,
4730 NLP_STE_PLOGI_ISSUE);
4731 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
4734 /* Send a FARP response to that node */
4735 if (fp->Rflags & FARP_REQUEST_FARPR)
4736 lpfc_issue_els_farpr(vport, did, 0);
4743 * lpfc_els_rcv_farpr: Process an unsolicited farp response iocb.
4744 * @vport: pointer to a host virtual N_Port data structure.
4745 * @cmdiocb: pointer to lpfc command iocb data structure.
4746 * @ndlp: pointer to a node-list data structure.
4748 * This routine processes Fibre Channel Address Resolution Protocol
4749 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
4750 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
4751 * the FARP response request.
4754 * 0 - Successfully processed FARPR IOCB (currently always return 0)
4757 lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4758 struct lpfc_nodelist *ndlp)
4760 struct lpfc_dmabuf *pcmd;
4765 icmd = &cmdiocb->iocb;
4766 did = icmd->un.elsreq64.remoteID;
4767 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4768 lp = (uint32_t *) pcmd->virt;
4771 /* FARP-RSP received from DID <did> */
4772 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4773 "0600 FARP-RSP received from DID x%x\n", did);
4774 /* ACCEPT the Farp resp request */
4775 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
4781 * lpfc_els_rcv_fan: Process an unsolicited fan iocb command.
4782 * @vport: pointer to a host virtual N_Port data structure.
4783 * @cmdiocb: pointer to lpfc command iocb data structure.
4784 * @fan_ndlp: pointer to a node-list data structure.
4786 * This routine processes a Fabric Address Notification (FAN) IOCB
4787 * command received as an ELS unsolicited event. The FAN ELS command will
4788 * only be processed on a physical port (i.e., the @vport represents the
4789 * physical port). The fabric NodeName and PortName from the FAN IOCB are
4790 * compared against those in the phba data structure. If any of those is
4791 * different, the lpfc_initial_flogi() routine is invoked to initialize
4792 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
4793 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
4794 * is invoked to register login to the fabric.
4797 * 0 - Successfully processed fan iocb (currently always return 0).
4800 lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4801 struct lpfc_nodelist *fan_ndlp)
4803 struct lpfc_hba *phba = vport->phba;
4807 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
4808 lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
4810 /* FAN received; Fan does not have a reply sequence */
4811 if ((vport == phba->pport) &&
4812 (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
4813 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
4814 sizeof(struct lpfc_name))) ||
4815 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
4816 sizeof(struct lpfc_name)))) {
4817 /* This port has switched fabrics. FLOGI is required */
4818 lpfc_initial_flogi(vport);
4820 /* FAN verified - skip FLOGI */
4821 vport->fc_myDID = vport->fc_prevDID;
4822 lpfc_issue_fabric_reglogin(vport);
4829 * lpfc_els_timeout: Handler funciton to the els timer.
4830 * @ptr: holder for the timer function associated data.
4832 * This routine is invoked by the ELS timer after timeout. It posts the ELS
4833 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
4834 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
4835 * up the worker thread. It is for the worker thread to invoke the routine
4836 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
4839 lpfc_els_timeout(unsigned long ptr)
4841 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
4842 struct lpfc_hba *phba = vport->phba;
4843 uint32_t tmo_posted;
4844 unsigned long iflag;
4846 spin_lock_irqsave(&vport->work_port_lock, iflag);
4847 tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
4849 vport->work_port_events |= WORKER_ELS_TMO;
4850 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
4853 lpfc_worker_wake_up(phba);
4858 * lpfc_els_timeout_handler: Process an els timeout event.
4859 * @vport: pointer to a virtual N_Port data structure.
4861 * This routine is the actual handler function that processes an ELS timeout
4862 * event. It walks the ELS ring to get and abort all the IOCBs (except the
4863 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
4864 * invoking the lpfc_sli_issue_abort_iotag() routine.
4867 lpfc_els_timeout_handler(struct lpfc_vport *vport)
4869 struct lpfc_hba *phba = vport->phba;
4870 struct lpfc_sli_ring *pring;
4871 struct lpfc_iocbq *tmp_iocb, *piocb;
4873 struct lpfc_dmabuf *pcmd;
4874 uint32_t els_command = 0;
4876 uint32_t remote_ID = 0xffffffff;
4878 /* If the timer is already canceled do nothing */
4879 if ((vport->work_port_events & WORKER_ELS_TMO) == 0) {
4882 spin_lock_irq(&phba->hbalock);
4883 timeout = (uint32_t)(phba->fc_ratov << 1);
4885 pring = &phba->sli.ring[LPFC_ELS_RING];
4887 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
4890 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
4891 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
4892 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
4895 if (piocb->vport != vport)
4898 pcmd = (struct lpfc_dmabuf *) piocb->context2;
4900 els_command = *(uint32_t *) (pcmd->virt);
4902 if (els_command == ELS_CMD_FARP ||
4903 els_command == ELS_CMD_FARPR ||
4904 els_command == ELS_CMD_FDISC)
4907 if (piocb->drvrTimeout > 0) {
4908 if (piocb->drvrTimeout >= timeout)
4909 piocb->drvrTimeout -= timeout;
4911 piocb->drvrTimeout = 0;
4915 remote_ID = 0xffffffff;
4916 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
4917 remote_ID = cmd->un.elsreq64.remoteID;
4919 struct lpfc_nodelist *ndlp;
4920 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
4921 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
4922 remote_ID = ndlp->nlp_DID;
4924 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4925 "0127 ELS timeout Data: x%x x%x x%x "
4926 "x%x\n", els_command,
4927 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
4928 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
4930 spin_unlock_irq(&phba->hbalock);
4932 if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt)
4933 mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
4937 * lpfc_els_flush_cmd: Clean up the outstanding els commands to a vport.
4938 * @vport: pointer to a host virtual N_Port data structure.
4940 * This routine is used to clean up all the outstanding ELS commands on a
4941 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
4942 * routine. After that, it walks the ELS transmit queue to remove all the
4943 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
4944 * the IOCBs with a non-NULL completion callback function, the callback
4945 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
4946 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
4947 * callback function, the IOCB will simply be released. Finally, it walks
4948 * the ELS transmit completion queue to issue an abort IOCB to any transmit
4949 * completion queue IOCB that is associated with the @vport and is not
4950 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
4951 * part of the discovery state machine) out to HBA by invoking the
4952 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
4953 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
4954 * the IOCBs are aborted when this function returns.
4957 lpfc_els_flush_cmd(struct lpfc_vport *vport)
4959 LIST_HEAD(completions);
4960 struct lpfc_hba *phba = vport->phba;
4961 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
4962 struct lpfc_iocbq *tmp_iocb, *piocb;
4965 lpfc_fabric_abort_vport(vport);
4967 spin_lock_irq(&phba->hbalock);
4968 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
4971 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
4975 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
4976 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
4977 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
4978 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
4979 cmd->ulpCommand == CMD_ABORT_XRI_CN)
4982 if (piocb->vport != vport)
4985 list_move_tail(&piocb->list, &completions);
4989 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
4990 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
4994 if (piocb->vport != vport)
4997 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
4999 spin_unlock_irq(&phba->hbalock);
5001 while (!list_empty(&completions)) {
5002 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
5004 list_del_init(&piocb->list);
5006 if (!piocb->iocb_cmpl)
5007 lpfc_sli_release_iocbq(phba, piocb);
5009 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
5010 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
5011 (piocb->iocb_cmpl) (phba, piocb, piocb);
5019 * lpfc_els_flush_all_cmd: Clean up all the outstanding els commands to a HBA.
5020 * @phba: pointer to lpfc hba data structure.
5022 * This routine is used to clean up all the outstanding ELS commands on a
5023 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
5024 * routine. After that, it walks the ELS transmit queue to remove all the
5025 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
5026 * the IOCBs with the completion callback function associated, the callback
5027 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
5028 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
5029 * callback function associated, the IOCB will simply be released. Finally,
5030 * it walks the ELS transmit completion queue to issue an abort IOCB to any
5031 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
5032 * management plane IOCBs that are not part of the discovery state machine)
5033 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
5036 lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
5038 LIST_HEAD(completions);
5039 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
5040 struct lpfc_iocbq *tmp_iocb, *piocb;
5043 lpfc_fabric_abort_hba(phba);
5044 spin_lock_irq(&phba->hbalock);
5045 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
5047 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
5049 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
5050 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
5051 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
5052 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
5053 cmd->ulpCommand == CMD_ABORT_XRI_CN)
5055 list_move_tail(&piocb->list, &completions);
5058 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
5059 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
5061 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
5063 spin_unlock_irq(&phba->hbalock);
5064 while (!list_empty(&completions)) {
5065 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
5067 list_del_init(&piocb->list);
5068 if (!piocb->iocb_cmpl)
5069 lpfc_sli_release_iocbq(phba, piocb);
5071 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
5072 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
5073 (piocb->iocb_cmpl) (phba, piocb, piocb);
5080 * lpfc_els_unsol_buffer: Process an unsolicited event data buffer.
5081 * @phba: pointer to lpfc hba data structure.
5082 * @pring: pointer to a SLI ring.
5083 * @vport: pointer to a host virtual N_Port data structure.
5084 * @elsiocb: pointer to lpfc els command iocb data structure.
5086 * This routine is used for processing the IOCB associated with a unsolicited
5087 * event. It first determines whether there is an existing ndlp that matches
5088 * the DID from the unsolicited IOCB. If not, it will create a new one with
5089 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
5090 * IOCB is then used to invoke the proper routine and to set up proper state
5091 * of the discovery state machine.
5094 lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
5095 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
5097 struct Scsi_Host *shost;
5098 struct lpfc_nodelist *ndlp;
5101 uint32_t cmd, did, newnode, rjt_err = 0;
5102 IOCB_t *icmd = &elsiocb->iocb;
5104 if (!vport || !(elsiocb->context2))
5108 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
5110 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
5111 lpfc_post_buffer(phba, pring, 1);
5113 did = icmd->un.rcvels.remoteID;
5114 if (icmd->ulpStatus) {
5115 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5116 "RCV Unsol ELS: status:x%x/x%x did:x%x",
5117 icmd->ulpStatus, icmd->un.ulpWord[4], did);
5121 /* Check to see if link went down during discovery */
5122 if (lpfc_els_chk_latt(vport))
5125 /* Ignore traffic recevied during vport shutdown. */
5126 if (vport->load_flag & FC_UNLOADING)
5129 ndlp = lpfc_findnode_did(vport, did);
5131 /* Cannot find existing Fabric ndlp, so allocate a new one */
5132 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
5136 lpfc_nlp_init(vport, ndlp, did);
5137 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5139 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
5140 ndlp->nlp_type |= NLP_FABRIC;
5141 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
5142 ndlp = lpfc_enable_node(vport, ndlp,
5143 NLP_STE_UNUSED_NODE);
5146 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5148 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
5149 ndlp->nlp_type |= NLP_FABRIC;
5150 } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
5151 /* This is similar to the new node path */
5152 ndlp = lpfc_nlp_get(ndlp);
5155 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5159 phba->fc_stat.elsRcvFrame++;
5160 if (elsiocb->context1)
5161 lpfc_nlp_put(elsiocb->context1);
5163 elsiocb->context1 = lpfc_nlp_get(ndlp);
5164 elsiocb->vport = vport;
5166 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
5167 cmd &= ELS_CMD_MASK;
5169 /* ELS command <elsCmd> received from NPORT <did> */
5170 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5171 "0112 ELS command x%x received from NPORT x%x "
5172 "Data: x%x\n", cmd, did, vport->port_state);
5175 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5176 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
5177 did, vport->port_state, ndlp->nlp_flag);
5179 phba->fc_stat.elsRcvPLOGI++;
5180 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
5182 if (vport->port_state < LPFC_DISC_AUTH) {
5183 if (!(phba->pport->fc_flag & FC_PT2PT) ||
5184 (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
5185 rjt_err = LSRJT_UNABLE_TPC;
5188 /* We get here, and drop thru, if we are PT2PT with
5189 * another NPort and the other side has initiated
5190 * the PLOGI before responding to our FLOGI.
5194 shost = lpfc_shost_from_vport(vport);
5195 spin_lock_irq(shost->host_lock);
5196 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
5197 spin_unlock_irq(shost->host_lock);
5199 lpfc_disc_state_machine(vport, ndlp, elsiocb,
5204 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5205 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
5206 did, vport->port_state, ndlp->nlp_flag);
5208 phba->fc_stat.elsRcvFLOGI++;
5209 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
5214 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5215 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
5216 did, vport->port_state, ndlp->nlp_flag);
5218 phba->fc_stat.elsRcvLOGO++;
5219 if (vport->port_state < LPFC_DISC_AUTH) {
5220 rjt_err = LSRJT_UNABLE_TPC;
5223 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
5226 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5227 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
5228 did, vport->port_state, ndlp->nlp_flag);
5230 phba->fc_stat.elsRcvPRLO++;
5231 if (vport->port_state < LPFC_DISC_AUTH) {
5232 rjt_err = LSRJT_UNABLE_TPC;
5235 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
5238 phba->fc_stat.elsRcvRSCN++;
5239 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
5244 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5245 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
5246 did, vport->port_state, ndlp->nlp_flag);
5248 phba->fc_stat.elsRcvADISC++;
5249 if (vport->port_state < LPFC_DISC_AUTH) {
5250 rjt_err = LSRJT_UNABLE_TPC;
5253 lpfc_disc_state_machine(vport, ndlp, elsiocb,
5257 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5258 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
5259 did, vport->port_state, ndlp->nlp_flag);
5261 phba->fc_stat.elsRcvPDISC++;
5262 if (vport->port_state < LPFC_DISC_AUTH) {
5263 rjt_err = LSRJT_UNABLE_TPC;
5266 lpfc_disc_state_machine(vport, ndlp, elsiocb,
5270 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5271 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
5272 did, vport->port_state, ndlp->nlp_flag);
5274 phba->fc_stat.elsRcvFARPR++;
5275 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
5278 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5279 "RCV FARP: did:x%x/ste:x%x flg:x%x",
5280 did, vport->port_state, ndlp->nlp_flag);
5282 phba->fc_stat.elsRcvFARP++;
5283 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
5286 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5287 "RCV FAN: did:x%x/ste:x%x flg:x%x",
5288 did, vport->port_state, ndlp->nlp_flag);
5290 phba->fc_stat.elsRcvFAN++;
5291 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
5294 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5295 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
5296 did, vport->port_state, ndlp->nlp_flag);
5298 phba->fc_stat.elsRcvPRLI++;
5299 if (vport->port_state < LPFC_DISC_AUTH) {
5300 rjt_err = LSRJT_UNABLE_TPC;
5303 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
5306 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5307 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
5308 did, vport->port_state, ndlp->nlp_flag);
5310 phba->fc_stat.elsRcvLIRR++;
5311 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
5316 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5317 "RCV RPS: did:x%x/ste:x%x flg:x%x",
5318 did, vport->port_state, ndlp->nlp_flag);
5320 phba->fc_stat.elsRcvRPS++;
5321 lpfc_els_rcv_rps(vport, elsiocb, ndlp);
5326 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5327 "RCV RPL: did:x%x/ste:x%x flg:x%x",
5328 did, vport->port_state, ndlp->nlp_flag);
5330 phba->fc_stat.elsRcvRPL++;
5331 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
5336 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5337 "RCV RNID: did:x%x/ste:x%x flg:x%x",
5338 did, vport->port_state, ndlp->nlp_flag);
5340 phba->fc_stat.elsRcvRNID++;
5341 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
5346 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5347 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
5348 cmd, did, vport->port_state);
5350 /* Unsupported ELS command, reject */
5351 rjt_err = LSRJT_INVALID_CMD;
5353 /* Unknown ELS command <elsCmd> received from NPORT <did> */
5354 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5355 "0115 Unknown ELS command x%x "
5356 "received from NPORT x%x\n", cmd, did);
5362 /* check if need to LS_RJT received ELS cmd */
5364 memset(&stat, 0, sizeof(stat));
5365 stat.un.b.lsRjtRsnCode = rjt_err;
5366 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
5367 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
5374 if (vport && !(vport->load_flag & FC_UNLOADING))
5375 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
5376 "(%d):0111 Dropping received ELS cmd "
5377 "Data: x%x x%x x%x\n",
5378 vport->vpi, icmd->ulpStatus,
5379 icmd->un.ulpWord[4], icmd->ulpTimeout);
5380 phba->fc_stat.elsRcvDrop++;
5384 * lpfc_find_vport_by_vpid: Find a vport on a HBA through vport identifier.
5385 * @phba: pointer to lpfc hba data structure.
5386 * @vpi: host virtual N_Port identifier.
5388 * This routine finds a vport on a HBA (referred by @phba) through a
5389 * @vpi. The function walks the HBA's vport list and returns the address
5390 * of the vport with the matching @vpi.
5393 * NULL - No vport with the matching @vpi found
5394 * Otherwise - Address to the vport with the matching @vpi.
5396 static struct lpfc_vport *
5397 lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi)
5399 struct lpfc_vport *vport;
5400 unsigned long flags;
5402 spin_lock_irqsave(&phba->hbalock, flags);
5403 list_for_each_entry(vport, &phba->port_list, listentry) {
5404 if (vport->vpi == vpi) {
5405 spin_unlock_irqrestore(&phba->hbalock, flags);
5409 spin_unlock_irqrestore(&phba->hbalock, flags);
5414 * lpfc_els_unsol_event: Process an unsolicited event from an els sli ring.
5415 * @phba: pointer to lpfc hba data structure.
5416 * @pring: pointer to a SLI ring.
5417 * @elsiocb: pointer to lpfc els iocb data structure.
5419 * This routine is used to process an unsolicited event received from a SLI
5420 * (Service Level Interface) ring. The actual processing of the data buffer
5421 * associated with the unsolicited event is done by invoking the routine
5422 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
5423 * SLI ring on which the unsolicited event was received.
5426 lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
5427 struct lpfc_iocbq *elsiocb)
5429 struct lpfc_vport *vport = phba->pport;
5430 IOCB_t *icmd = &elsiocb->iocb;
5432 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
5433 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
5435 elsiocb->context2 = NULL;
5436 elsiocb->context3 = NULL;
5438 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
5439 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
5440 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
5441 (icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING) {
5442 phba->fc_stat.NoRcvBuf++;
5443 /* Not enough posted buffers; Try posting more buffers */
5444 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
5445 lpfc_post_buffer(phba, pring, 0);
5449 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
5450 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
5451 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
5452 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
5453 vport = phba->pport;
5455 uint16_t vpi = icmd->unsli3.rcvsli3.vpi;
5456 vport = lpfc_find_vport_by_vpid(phba, vpi);
5459 /* If there are no BDEs associated
5460 * with this IOCB, there is nothing to do.
5462 if (icmd->ulpBdeCount == 0)
5465 /* type of ELS cmd is first 32bit word
5468 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
5469 elsiocb->context2 = bdeBuf1;
5471 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
5472 icmd->un.cont64[0].addrLow);
5473 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
5477 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
5479 * The different unsolicited event handlers would tell us
5480 * if they are done with "mp" by setting context2 to NULL.
5482 lpfc_nlp_put(elsiocb->context1);
5483 elsiocb->context1 = NULL;
5484 if (elsiocb->context2) {
5485 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
5486 elsiocb->context2 = NULL;
5489 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
5490 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
5491 icmd->ulpBdeCount == 2) {
5492 elsiocb->context2 = bdeBuf2;
5493 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
5494 /* free mp if we are done with it */
5495 if (elsiocb->context2) {
5496 lpfc_in_buf_free(phba, elsiocb->context2);
5497 elsiocb->context2 = NULL;
5503 * lpfc_do_scr_ns_plogi: Issue a plogi to the name server for scr.
5504 * @phba: pointer to lpfc hba data structure.
5505 * @vport: pointer to a virtual N_Port data structure.
5507 * This routine issues a Port Login (PLOGI) to the Name Server with
5508 * State Change Request (SCR) for a @vport. This routine will create an
5509 * ndlp for the Name Server associated to the @vport if such node does
5510 * not already exist. The PLOGI to Name Server is issued by invoking the
5511 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
5512 * (FDMI) is configured to the @vport, a FDMI node will be created and
5513 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
5516 lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
5518 struct lpfc_nodelist *ndlp, *ndlp_fdmi;
5520 ndlp = lpfc_findnode_did(vport, NameServer_DID);
5522 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
5524 if (phba->fc_topology == TOPOLOGY_LOOP) {
5525 lpfc_disc_start(vport);
5528 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
5529 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5530 "0251 NameServer login: no memory\n");
5533 lpfc_nlp_init(vport, ndlp, NameServer_DID);
5534 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
5535 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
5537 if (phba->fc_topology == TOPOLOGY_LOOP) {
5538 lpfc_disc_start(vport);
5541 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
5542 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5543 "0348 NameServer login: node freed\n");
5547 ndlp->nlp_type |= NLP_FABRIC;
5549 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
5551 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
5552 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
5553 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5554 "0252 Cannot issue NameServer login\n");
5558 if (vport->cfg_fdmi_on) {
5559 ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
5562 lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID);
5563 ndlp_fdmi->nlp_type |= NLP_FABRIC;
5564 lpfc_nlp_set_state(vport, ndlp_fdmi,
5565 NLP_STE_PLOGI_ISSUE);
5566 lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID,
5574 * lpfc_cmpl_reg_new_vport: Completion callback function to register new vport.
5575 * @phba: pointer to lpfc hba data structure.
5576 * @pmb: pointer to the driver internal queue element for mailbox command.
5578 * This routine is the completion callback function to register new vport
5579 * mailbox command. If the new vport mailbox command completes successfully,
5580 * the fabric registration login shall be performed on physical port (the
5581 * new vport created is actually a physical port, with VPI 0) or the port
5582 * login to Name Server for State Change Request (SCR) will be performed
5583 * on virtual port (real virtual port, with VPI greater than 0).
5586 lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
5588 struct lpfc_vport *vport = pmb->vport;
5589 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5590 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
5591 MAILBOX_t *mb = &pmb->mb;
5593 spin_lock_irq(shost->host_lock);
5594 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
5595 spin_unlock_irq(shost->host_lock);
5597 if (mb->mbxStatus) {
5598 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
5599 "0915 Register VPI failed: 0x%x\n",
5602 switch (mb->mbxStatus) {
5603 case 0x11: /* unsupported feature */
5604 case 0x9603: /* max_vpi exceeded */
5605 case 0x9602: /* Link event since CLEAR_LA */
5606 /* giving up on vport registration */
5607 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
5608 spin_lock_irq(shost->host_lock);
5609 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
5610 spin_unlock_irq(shost->host_lock);
5611 lpfc_can_disctmo(vport);
5614 /* Try to recover from this error */
5615 lpfc_mbx_unreg_vpi(vport);
5616 spin_lock_irq(shost->host_lock);
5617 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
5618 spin_unlock_irq(shost->host_lock);
5619 if (vport->port_type == LPFC_PHYSICAL_PORT)
5620 lpfc_initial_flogi(vport);
5622 lpfc_initial_fdisc(vport);
5627 if (vport == phba->pport)
5628 lpfc_issue_fabric_reglogin(vport);
5630 lpfc_do_scr_ns_plogi(phba, vport);
5633 /* Now, we decrement the ndlp reference count held for this
5638 mempool_free(pmb, phba->mbox_mem_pool);
5643 * lpfc_register_new_vport: Register a new vport with a HBA.
5644 * @phba: pointer to lpfc hba data structure.
5645 * @vport: pointer to a host virtual N_Port data structure.
5646 * @ndlp: pointer to a node-list data structure.
5648 * This routine registers the @vport as a new virtual port with a HBA.
5649 * It is done through a registering vpi mailbox command.
5652 lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
5653 struct lpfc_nodelist *ndlp)
5655 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5658 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5660 lpfc_reg_vpi(phba, vport->vpi, vport->fc_myDID, mbox);
5661 mbox->vport = vport;
5662 mbox->context2 = lpfc_nlp_get(ndlp);
5663 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
5664 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
5665 == MBX_NOT_FINISHED) {
5666 /* mailbox command not success, decrement ndlp
5667 * reference count for this command
5670 mempool_free(mbox, phba->mbox_mem_pool);
5672 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
5673 "0253 Register VPI: Can't send mbox\n");
5677 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
5678 "0254 Register VPI: no memory\n");
5684 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
5685 spin_lock_irq(shost->host_lock);
5686 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
5687 spin_unlock_irq(shost->host_lock);
5692 * lpfc_cmpl_els_fdisc: Completion function for fdisc iocb command.
5693 * @phba: pointer to lpfc hba data structure.
5694 * @cmdiocb: pointer to lpfc command iocb data structure.
5695 * @rspiocb: pointer to lpfc response iocb data structure.
5697 * This routine is the completion callback function to a Fabric Discover
5698 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
5699 * single threaded, each FDISC completion callback function will reset
5700 * the discovery timer for all vports such that the timers will not get
5701 * unnecessary timeout. The function checks the FDISC IOCB status. If error
5702 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
5703 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
5704 * assigned to the vport has been changed with the completion of the FDISC
5705 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
5706 * are unregistered from the HBA, and then the lpfc_register_new_vport()
5707 * routine is invoked to register new vport with the HBA. Otherwise, the
5708 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
5709 * Server for State Change Request (SCR).
5712 lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
5713 struct lpfc_iocbq *rspiocb)
5715 struct lpfc_vport *vport = cmdiocb->vport;
5716 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5717 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
5718 struct lpfc_nodelist *np;
5719 struct lpfc_nodelist *next_np;
5720 IOCB_t *irsp = &rspiocb->iocb;
5721 struct lpfc_iocbq *piocb;
5723 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5724 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
5725 irsp->ulpStatus, irsp->un.ulpWord[4],
5727 /* Since all FDISCs are being single threaded, we
5728 * must reset the discovery timer for ALL vports
5729 * waiting to send FDISC when one completes.
5731 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
5732 lpfc_set_disctmo(piocb->vport);
5735 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
5736 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
5737 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
5739 if (irsp->ulpStatus) {
5740 /* Check for retry */
5741 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
5744 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5745 "0124 FDISC failed. (%d/%d)\n",
5746 irsp->ulpStatus, irsp->un.ulpWord[4]);
5747 if (vport->fc_vport->vport_state == FC_VPORT_INITIALIZING)
5748 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
5750 /* giving up on FDISC. Cancel discovery timer */
5751 lpfc_can_disctmo(vport);
5753 spin_lock_irq(shost->host_lock);
5754 vport->fc_flag |= FC_FABRIC;
5755 if (vport->phba->fc_topology == TOPOLOGY_LOOP)
5756 vport->fc_flag |= FC_PUBLIC_LOOP;
5757 spin_unlock_irq(shost->host_lock);
5759 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
5760 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
5761 if ((vport->fc_prevDID != vport->fc_myDID) &&
5762 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
5763 /* If our NportID changed, we need to ensure all
5764 * remaining NPORTs get unreg_login'ed so we can
5767 list_for_each_entry_safe(np, next_np,
5768 &vport->fc_nodes, nlp_listp) {
5769 if (!NLP_CHK_NODE_ACT(ndlp) ||
5770 (np->nlp_state != NLP_STE_NPR_NODE) ||
5771 !(np->nlp_flag & NLP_NPR_ADISC))
5773 spin_lock_irq(shost->host_lock);
5774 np->nlp_flag &= ~NLP_NPR_ADISC;
5775 spin_unlock_irq(shost->host_lock);
5776 lpfc_unreg_rpi(vport, np);
5778 lpfc_mbx_unreg_vpi(vport);
5779 spin_lock_irq(shost->host_lock);
5780 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
5781 spin_unlock_irq(shost->host_lock);
5784 if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
5785 lpfc_register_new_vport(phba, vport, ndlp);
5787 lpfc_do_scr_ns_plogi(phba, vport);
5789 /* Unconditionaly kick off releasing fabric node for vports */
5794 lpfc_els_free_iocb(phba, cmdiocb);
5798 * lpfc_issue_els_fdisc: Issue a fdisc iocb command.
5799 * @vport: pointer to a virtual N_Port data structure.
5800 * @ndlp: pointer to a node-list data structure.
5801 * @retry: number of retries to the command IOCB.
5803 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
5804 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
5805 * routine to issue the IOCB, which makes sure only one outstanding fabric
5806 * IOCB will be sent off HBA at any given time.
5808 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5809 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5810 * will be stored into the context1 field of the IOCB for the completion
5811 * callback function to the FDISC ELS command.
5814 * 0 - Successfully issued fdisc iocb command
5815 * 1 - Failed to issue fdisc iocb command
5818 lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
5821 struct lpfc_hba *phba = vport->phba;
5823 struct lpfc_iocbq *elsiocb;
5824 struct serv_parm *sp;
5827 int did = ndlp->nlp_DID;
5830 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
5831 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
5834 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
5835 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5836 "0255 Issue FDISC: no IOCB\n");
5840 icmd = &elsiocb->iocb;
5841 icmd->un.elsreq64.myID = 0;
5842 icmd->un.elsreq64.fl = 1;
5844 /* For FDISC, Let FDISC rsp set the NPortID for this VPI */
5848 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5849 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
5850 pcmd += sizeof(uint32_t); /* CSP Word 1 */
5851 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
5852 sp = (struct serv_parm *) pcmd;
5853 /* Setup CSPs accordingly for Fabric */
5854 sp->cmn.e_d_tov = 0;
5855 sp->cmn.w2.r_a_tov = 0;
5856 sp->cls1.classValid = 0;
5857 sp->cls2.seqDelivery = 1;
5858 sp->cls3.seqDelivery = 1;
5860 pcmd += sizeof(uint32_t); /* CSP Word 2 */
5861 pcmd += sizeof(uint32_t); /* CSP Word 3 */
5862 pcmd += sizeof(uint32_t); /* CSP Word 4 */
5863 pcmd += sizeof(uint32_t); /* Port Name */
5864 memcpy(pcmd, &vport->fc_portname, 8);
5865 pcmd += sizeof(uint32_t); /* Node Name */
5866 pcmd += sizeof(uint32_t); /* Node Name */
5867 memcpy(pcmd, &vport->fc_nodename, 8);
5869 lpfc_set_disctmo(vport);
5871 phba->fc_stat.elsXmitFDISC++;
5872 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
5874 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
5875 "Issue FDISC: did:x%x",
5878 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
5879 if (rc == IOCB_ERROR) {
5880 lpfc_els_free_iocb(phba, elsiocb);
5881 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
5882 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5883 "0256 Issue FDISC: Cannot send IOCB\n");
5886 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
5887 vport->port_state = LPFC_FDISC;
5892 * lpfc_cmpl_els_npiv_logo: Completion function with vport logo.
5893 * @phba: pointer to lpfc hba data structure.
5894 * @cmdiocb: pointer to lpfc command iocb data structure.
5895 * @rspiocb: pointer to lpfc response iocb data structure.
5897 * This routine is the completion callback function to the issuing of a LOGO
5898 * ELS command off a vport. It frees the command IOCB and then decrement the
5899 * reference count held on ndlp for this completion function, indicating that
5900 * the reference to the ndlp is no long needed. Note that the
5901 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
5902 * callback function and an additional explicit ndlp reference decrementation
5903 * will trigger the actual release of the ndlp.
5906 lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
5907 struct lpfc_iocbq *rspiocb)
5909 struct lpfc_vport *vport = cmdiocb->vport;
5911 struct lpfc_nodelist *ndlp;
5912 ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
5914 irsp = &rspiocb->iocb;
5915 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
5916 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
5917 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
5919 lpfc_els_free_iocb(phba, cmdiocb);
5920 vport->unreg_vpi_cmpl = VPORT_ERROR;
5922 /* Trigger the release of the ndlp after logo */
5927 * lpfc_issue_els_npiv_logo: Issue a logo off a vport.
5928 * @vport: pointer to a virtual N_Port data structure.
5929 * @ndlp: pointer to a node-list data structure.
5931 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
5933 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5934 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5935 * will be stored into the context1 field of the IOCB for the completion
5936 * callback function to the LOGO ELS command.
5939 * 0 - Successfully issued logo off the @vport
5940 * 1 - Failed to issue logo off the @vport
5943 lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
5945 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5946 struct lpfc_hba *phba = vport->phba;
5947 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
5949 struct lpfc_iocbq *elsiocb;
5953 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
5954 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
5959 icmd = &elsiocb->iocb;
5960 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5961 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
5962 pcmd += sizeof(uint32_t);
5964 /* Fill in LOGO payload */
5965 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
5966 pcmd += sizeof(uint32_t);
5967 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
5969 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
5970 "Issue LOGO npiv did:x%x flg:x%x",
5971 ndlp->nlp_DID, ndlp->nlp_flag, 0);
5973 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
5974 spin_lock_irq(shost->host_lock);
5975 ndlp->nlp_flag |= NLP_LOGO_SND;
5976 spin_unlock_irq(shost->host_lock);
5977 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
5978 spin_lock_irq(shost->host_lock);
5979 ndlp->nlp_flag &= ~NLP_LOGO_SND;
5980 spin_unlock_irq(shost->host_lock);
5981 lpfc_els_free_iocb(phba, elsiocb);
5988 * lpfc_fabric_block_timeout: Handler function to the fabric block timer.
5989 * @ptr: holder for the timer function associated data.
5991 * This routine is invoked by the fabric iocb block timer after
5992 * timeout. It posts the fabric iocb block timeout event by setting the
5993 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
5994 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
5995 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
5996 * posted event WORKER_FABRIC_BLOCK_TMO.
5999 lpfc_fabric_block_timeout(unsigned long ptr)
6001 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
6002 unsigned long iflags;
6003 uint32_t tmo_posted;
6005 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
6006 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
6008 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
6009 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
6012 lpfc_worker_wake_up(phba);
6017 * lpfc_resume_fabric_iocbs: Issue a fabric iocb from driver internal list.
6018 * @phba: pointer to lpfc hba data structure.
6020 * This routine issues one fabric iocb from the driver internal list to
6021 * the HBA. It first checks whether it's ready to issue one fabric iocb to
6022 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
6023 * remove one pending fabric iocb from the driver internal list and invokes
6024 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
6027 lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
6029 struct lpfc_iocbq *iocb;
6030 unsigned long iflags;
6032 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
6037 spin_lock_irqsave(&phba->hbalock, iflags);
6038 /* Post any pending iocb to the SLI layer */
6039 if (atomic_read(&phba->fabric_iocb_count) == 0) {
6040 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
6043 /* Increment fabric iocb count to hold the position */
6044 atomic_inc(&phba->fabric_iocb_count);
6046 spin_unlock_irqrestore(&phba->hbalock, iflags);
6048 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
6049 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
6050 iocb->iocb_flag |= LPFC_IO_FABRIC;
6052 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
6053 "Fabric sched1: ste:x%x",
6054 iocb->vport->port_state, 0, 0);
6056 ret = lpfc_sli_issue_iocb(phba, pring, iocb, 0);
6058 if (ret == IOCB_ERROR) {
6059 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
6060 iocb->fabric_iocb_cmpl = NULL;
6061 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
6063 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
6064 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
6065 iocb->iocb_cmpl(phba, iocb, iocb);
6067 atomic_dec(&phba->fabric_iocb_count);
6076 * lpfc_unblock_fabric_iocbs: Unblock issuing fabric iocb command.
6077 * @phba: pointer to lpfc hba data structure.
6079 * This routine unblocks the issuing fabric iocb command. The function
6080 * will clear the fabric iocb block bit and then invoke the routine
6081 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
6082 * from the driver internal fabric iocb list.
6085 lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
6087 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
6089 lpfc_resume_fabric_iocbs(phba);
6094 * lpfc_block_fabric_iocbs: Block issuing fabric iocb command.
6095 * @phba: pointer to lpfc hba data structure.
6097 * This routine blocks the issuing fabric iocb for a specified amount of
6098 * time (currently 100 ms). This is done by set the fabric iocb block bit
6099 * and set up a timeout timer for 100ms. When the block bit is set, no more
6100 * fabric iocb will be issued out of the HBA.
6103 lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
6107 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
6108 /* Start a timer to unblock fabric iocbs after 100ms */
6110 mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 );
6116 * lpfc_cmpl_fabric_iocb: Completion callback function for fabric iocb.
6117 * @phba: pointer to lpfc hba data structure.
6118 * @cmdiocb: pointer to lpfc command iocb data structure.
6119 * @rspiocb: pointer to lpfc response iocb data structure.
6121 * This routine is the callback function that is put to the fabric iocb's
6122 * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
6123 * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
6124 * function first restores and invokes the original iocb's callback function
6125 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
6126 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
6129 lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
6130 struct lpfc_iocbq *rspiocb)
6134 if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC)
6137 switch (rspiocb->iocb.ulpStatus) {
6138 case IOSTAT_NPORT_RJT:
6139 case IOSTAT_FABRIC_RJT:
6140 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
6141 lpfc_block_fabric_iocbs(phba);
6145 case IOSTAT_NPORT_BSY:
6146 case IOSTAT_FABRIC_BSY:
6147 lpfc_block_fabric_iocbs(phba);
6151 stat.un.lsRjtError =
6152 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
6153 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
6154 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
6155 lpfc_block_fabric_iocbs(phba);
6159 if (atomic_read(&phba->fabric_iocb_count) == 0)
6162 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
6163 cmdiocb->fabric_iocb_cmpl = NULL;
6164 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
6165 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
6167 atomic_dec(&phba->fabric_iocb_count);
6168 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
6169 /* Post any pending iocbs to HBA */
6170 lpfc_resume_fabric_iocbs(phba);
6175 * lpfc_issue_fabric_iocb: Issue a fabric iocb command.
6176 * @phba: pointer to lpfc hba data structure.
6177 * @iocb: pointer to lpfc command iocb data structure.
6179 * This routine is used as the top-level API for issuing a fabric iocb command
6180 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
6181 * function makes sure that only one fabric bound iocb will be outstanding at
6182 * any given time. As such, this function will first check to see whether there
6183 * is already an outstanding fabric iocb on the wire. If so, it will put the
6184 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
6185 * issued later. Otherwise, it will issue the iocb on the wire and update the
6186 * fabric iocb count it indicate that there is one fabric iocb on the wire.
6188 * Note, this implementation has a potential sending out fabric IOCBs out of
6189 * order. The problem is caused by the construction of the "ready" boolen does
6190 * not include the condition that the internal fabric IOCB list is empty. As
6191 * such, it is possible a fabric IOCB issued by this routine might be "jump"
6192 * ahead of the fabric IOCBs in the internal list.
6195 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
6196 * IOCB_ERROR - failed to issue fabric iocb
6199 lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
6201 unsigned long iflags;
6202 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
6206 if (atomic_read(&phba->fabric_iocb_count) > 1)
6209 spin_lock_irqsave(&phba->hbalock, iflags);
6210 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
6211 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
6214 /* Increment fabric iocb count to hold the position */
6215 atomic_inc(&phba->fabric_iocb_count);
6216 spin_unlock_irqrestore(&phba->hbalock, iflags);
6218 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
6219 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
6220 iocb->iocb_flag |= LPFC_IO_FABRIC;
6222 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
6223 "Fabric sched2: ste:x%x",
6224 iocb->vport->port_state, 0, 0);
6226 ret = lpfc_sli_issue_iocb(phba, pring, iocb, 0);
6228 if (ret == IOCB_ERROR) {
6229 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
6230 iocb->fabric_iocb_cmpl = NULL;
6231 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
6232 atomic_dec(&phba->fabric_iocb_count);
6235 spin_lock_irqsave(&phba->hbalock, iflags);
6236 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
6237 spin_unlock_irqrestore(&phba->hbalock, iflags);
6244 * lpfc_fabric_abort_vport: Abort a vport's iocbs from driver fabric iocb list.
6245 * @vport: pointer to a virtual N_Port data structure.
6247 * This routine aborts all the IOCBs associated with a @vport from the
6248 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
6249 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
6250 * list, removes each IOCB associated with the @vport off the list, set the
6251 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
6252 * associated with the IOCB.
6254 static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
6256 LIST_HEAD(completions);
6257 struct lpfc_hba *phba = vport->phba;
6258 struct lpfc_iocbq *tmp_iocb, *piocb;
6261 spin_lock_irq(&phba->hbalock);
6262 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
6265 if (piocb->vport != vport)
6268 list_move_tail(&piocb->list, &completions);
6270 spin_unlock_irq(&phba->hbalock);
6272 while (!list_empty(&completions)) {
6273 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
6274 list_del_init(&piocb->list);
6277 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
6278 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
6279 (piocb->iocb_cmpl) (phba, piocb, piocb);
6284 * lpfc_fabric_abort_nport: Abort a ndlp's iocbs from driver fabric iocb list.
6285 * @ndlp: pointer to a node-list data structure.
6287 * This routine aborts all the IOCBs associated with an @ndlp from the
6288 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
6289 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
6290 * list, removes each IOCB associated with the @ndlp off the list, set the
6291 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
6292 * associated with the IOCB.
6294 void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
6296 LIST_HEAD(completions);
6297 struct lpfc_hba *phba = ndlp->vport->phba;
6298 struct lpfc_iocbq *tmp_iocb, *piocb;
6299 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
6302 spin_lock_irq(&phba->hbalock);
6303 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
6305 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
6307 list_move_tail(&piocb->list, &completions);
6310 spin_unlock_irq(&phba->hbalock);
6312 while (!list_empty(&completions)) {
6313 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
6314 list_del_init(&piocb->list);
6317 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
6318 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
6319 (piocb->iocb_cmpl) (phba, piocb, piocb);
6324 * lpfc_fabric_abort_hba: Abort all iocbs on driver fabric iocb list.
6325 * @phba: pointer to lpfc hba data structure.
6327 * This routine aborts all the IOCBs currently on the driver internal
6328 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
6329 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
6330 * list, removes IOCBs off the list, set the status feild to
6331 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
6334 void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
6336 LIST_HEAD(completions);
6337 struct lpfc_iocbq *piocb;
6340 spin_lock_irq(&phba->hbalock);
6341 list_splice_init(&phba->fabric_iocb_list, &completions);
6342 spin_unlock_irq(&phba->hbalock);
6344 while (!list_empty(&completions)) {
6345 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
6346 list_del_init(&piocb->list);
6349 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
6350 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
6351 (piocb->iocb_cmpl) (phba, piocb, piocb);