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_BLP_64;
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_TYPE_BDE_64;
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(np))
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_rscn_disc: Perform rscn discovery for a vport.
1560 * @vport: pointer to a host virtual N_Port data structure.
1562 * This routine performs Registration State Change Notification (RSCN)
1563 * discovery for a @vport. If the @vport's node port recovery count is not
1564 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
1565 * the nodes that need recovery. If none of the PLOGI were needed through
1566 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
1567 * invoked to check and handle possible more RSCN came in during the period
1568 * of processing the current ones.
1571 lpfc_rscn_disc(struct lpfc_vport *vport)
1573 lpfc_can_disctmo(vport);
1575 /* RSCN discovery */
1576 /* go thru NPR nodes and issue ELS PLOGIs */
1577 if (vport->fc_npr_cnt)
1578 if (lpfc_els_disc_plogi(vport))
1581 lpfc_end_rscn(vport);
1585 * lpfc_adisc_done: Complete the adisc phase of discovery.
1586 * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
1588 * This function is called when the final ADISC is completed during discovery.
1589 * This function handles clearing link attention or issuing reg_vpi depending
1590 * on whether npiv is enabled. This function also kicks off the PLOGI phase of
1592 * This function is called with no locks held.
1595 lpfc_adisc_done(struct lpfc_vport *vport)
1597 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1598 struct lpfc_hba *phba = vport->phba;
1601 * For NPIV, cmpl_reg_vpi will set port_state to READY,
1602 * and continue discovery.
1604 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
1605 !(vport->fc_flag & FC_RSCN_MODE)) {
1606 lpfc_issue_reg_vpi(phba, vport);
1610 * For SLI2, we need to set port_state to READY
1611 * and continue discovery.
1613 if (vport->port_state < LPFC_VPORT_READY) {
1614 /* If we get here, there is nothing to ADISC */
1615 if (vport->port_type == LPFC_PHYSICAL_PORT)
1616 lpfc_issue_clear_la(phba, vport);
1617 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
1618 vport->num_disc_nodes = 0;
1619 /* go thru NPR list, issue ELS PLOGIs */
1620 if (vport->fc_npr_cnt)
1621 lpfc_els_disc_plogi(vport);
1622 if (!vport->num_disc_nodes) {
1623 spin_lock_irq(shost->host_lock);
1624 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1625 spin_unlock_irq(shost->host_lock);
1626 lpfc_can_disctmo(vport);
1627 lpfc_end_rscn(vport);
1630 vport->port_state = LPFC_VPORT_READY;
1632 lpfc_rscn_disc(vport);
1636 * lpfc_more_adisc: Issue more adisc as needed.
1637 * @vport: pointer to a host virtual N_Port data structure.
1639 * This routine determines whether there are more ndlps on a @vport
1640 * node list need to have Address Discover (ADISC) issued. If so, it will
1641 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
1642 * remaining nodes which need to have ADISC sent.
1645 lpfc_more_adisc(struct lpfc_vport *vport)
1649 if (vport->num_disc_nodes)
1650 vport->num_disc_nodes--;
1651 /* Continue discovery with <num_disc_nodes> ADISCs to go */
1652 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1653 "0210 Continue discovery with %d ADISCs to go "
1654 "Data: x%x x%x x%x\n",
1655 vport->num_disc_nodes, vport->fc_adisc_cnt,
1656 vport->fc_flag, vport->port_state);
1657 /* Check to see if there are more ADISCs to be sent */
1658 if (vport->fc_flag & FC_NLP_MORE) {
1659 lpfc_set_disctmo(vport);
1660 /* go thru NPR nodes and issue any remaining ELS ADISCs */
1661 sentadisc = lpfc_els_disc_adisc(vport);
1663 if (!vport->num_disc_nodes)
1664 lpfc_adisc_done(vport);
1669 * lpfc_cmpl_els_adisc: Completion callback function for adisc.
1670 * @phba: pointer to lpfc hba data structure.
1671 * @cmdiocb: pointer to lpfc command iocb data structure.
1672 * @rspiocb: pointer to lpfc response iocb data structure.
1674 * This routine is the completion function for issuing the Address Discover
1675 * (ADISC) command. It first checks to see whether link went down during
1676 * the discovery process. If so, the node will be marked as node port
1677 * recovery for issuing discover IOCB by the link attention handler and
1678 * exit. Otherwise, the response status is checked. If error was reported
1679 * in the response status, the ADISC command shall be retried by invoking
1680 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
1681 * the response status, the state machine is invoked to set transition
1682 * with respect to NLP_EVT_CMPL_ADISC event.
1685 lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1686 struct lpfc_iocbq *rspiocb)
1688 struct lpfc_vport *vport = cmdiocb->vport;
1689 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1691 struct lpfc_nodelist *ndlp;
1694 /* we pass cmdiocb to state machine which needs rspiocb as well */
1695 cmdiocb->context_un.rsp_iocb = rspiocb;
1697 irsp = &(rspiocb->iocb);
1698 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1700 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1701 "ADISC cmpl: status:x%x/x%x did:x%x",
1702 irsp->ulpStatus, irsp->un.ulpWord[4],
1705 /* Since ndlp can be freed in the disc state machine, note if this node
1706 * is being used during discovery.
1708 spin_lock_irq(shost->host_lock);
1709 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
1710 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
1711 spin_unlock_irq(shost->host_lock);
1712 /* ADISC completes to NPort <nlp_DID> */
1713 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1714 "0104 ADISC completes to NPort x%x "
1715 "Data: x%x x%x x%x x%x x%x\n",
1716 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1717 irsp->ulpTimeout, disc, vport->num_disc_nodes);
1718 /* Check to see if link went down during discovery */
1719 if (lpfc_els_chk_latt(vport)) {
1720 spin_lock_irq(shost->host_lock);
1721 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1722 spin_unlock_irq(shost->host_lock);
1726 if (irsp->ulpStatus) {
1727 /* Check for retry */
1728 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1729 /* ELS command is being retried */
1731 spin_lock_irq(shost->host_lock);
1732 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1733 spin_unlock_irq(shost->host_lock);
1734 lpfc_set_disctmo(vport);
1739 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1740 if (!lpfc_error_lost_link(irsp))
1741 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1742 NLP_EVT_CMPL_ADISC);
1744 /* Good status, call state machine */
1745 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1746 NLP_EVT_CMPL_ADISC);
1748 /* Check to see if there are more ADISCs to be sent */
1749 if (disc && vport->num_disc_nodes)
1750 lpfc_more_adisc(vport);
1752 lpfc_els_free_iocb(phba, cmdiocb);
1757 * lpfc_issue_els_adisc: Issue an address discover iocb to an node on a vport.
1758 * @vport: pointer to a virtual N_Port data structure.
1759 * @ndlp: pointer to a node-list data structure.
1760 * @retry: number of retries to the command IOCB.
1762 * This routine issues an Address Discover (ADISC) for an @ndlp on a
1763 * @vport. It prepares the payload of the ADISC ELS command, updates the
1764 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
1765 * to issue the ADISC ELS command.
1767 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1768 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1769 * will be stored into the context1 field of the IOCB for the completion
1770 * callback function to the ADISC ELS command.
1773 * 0 - successfully issued adisc
1774 * 1 - failed to issue adisc
1777 lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1780 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1781 struct lpfc_hba *phba = vport->phba;
1784 struct lpfc_iocbq *elsiocb;
1785 struct lpfc_sli *psli = &phba->sli;
1786 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
1790 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
1791 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1792 ndlp->nlp_DID, ELS_CMD_ADISC);
1796 icmd = &elsiocb->iocb;
1797 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1799 /* For ADISC request, remainder of payload is service parameters */
1800 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
1801 pcmd += sizeof(uint32_t);
1803 /* Fill in ADISC payload */
1804 ap = (ADISC *) pcmd;
1805 ap->hardAL_PA = phba->fc_pref_ALPA;
1806 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
1807 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
1808 ap->DID = be32_to_cpu(vport->fc_myDID);
1810 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1811 "Issue ADISC: did:x%x",
1812 ndlp->nlp_DID, 0, 0);
1814 phba->fc_stat.elsXmitADISC++;
1815 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
1816 spin_lock_irq(shost->host_lock);
1817 ndlp->nlp_flag |= NLP_ADISC_SND;
1818 spin_unlock_irq(shost->host_lock);
1819 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
1820 spin_lock_irq(shost->host_lock);
1821 ndlp->nlp_flag &= ~NLP_ADISC_SND;
1822 spin_unlock_irq(shost->host_lock);
1823 lpfc_els_free_iocb(phba, elsiocb);
1830 * lpfc_cmpl_els_logo: Completion callback function for logo.
1831 * @phba: pointer to lpfc hba data structure.
1832 * @cmdiocb: pointer to lpfc command iocb data structure.
1833 * @rspiocb: pointer to lpfc response iocb data structure.
1835 * This routine is the completion function for issuing the ELS Logout (LOGO)
1836 * command. If no error status was reported from the LOGO response, the
1837 * state machine of the associated ndlp shall be invoked for transition with
1838 * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
1839 * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
1842 lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1843 struct lpfc_iocbq *rspiocb)
1845 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1846 struct lpfc_vport *vport = ndlp->vport;
1847 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1849 struct lpfc_sli *psli;
1852 /* we pass cmdiocb to state machine which needs rspiocb as well */
1853 cmdiocb->context_un.rsp_iocb = rspiocb;
1855 irsp = &(rspiocb->iocb);
1856 spin_lock_irq(shost->host_lock);
1857 ndlp->nlp_flag &= ~NLP_LOGO_SND;
1858 spin_unlock_irq(shost->host_lock);
1860 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1861 "LOGO cmpl: status:x%x/x%x did:x%x",
1862 irsp->ulpStatus, irsp->un.ulpWord[4],
1864 /* LOGO completes to NPort <nlp_DID> */
1865 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1866 "0105 LOGO completes to NPort x%x "
1867 "Data: x%x x%x x%x x%x\n",
1868 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1869 irsp->ulpTimeout, vport->num_disc_nodes);
1870 /* Check to see if link went down during discovery */
1871 if (lpfc_els_chk_latt(vport))
1874 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
1875 /* NLP_EVT_DEVICE_RM should unregister the RPI
1876 * which should abort all outstanding IOs.
1878 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1883 if (irsp->ulpStatus) {
1884 /* Check for retry */
1885 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
1886 /* ELS command is being retried */
1889 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1890 if (lpfc_error_lost_link(irsp))
1893 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1896 /* Good status, call state machine.
1897 * This will unregister the rpi if needed.
1899 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1902 lpfc_els_free_iocb(phba, cmdiocb);
1907 * lpfc_issue_els_logo: Issue a logo to an node on a vport.
1908 * @vport: pointer to a virtual N_Port data structure.
1909 * @ndlp: pointer to a node-list data structure.
1910 * @retry: number of retries to the command IOCB.
1912 * This routine constructs and issues an ELS Logout (LOGO) iocb command
1913 * to a remote node, referred by an @ndlp on a @vport. It constructs the
1914 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
1915 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
1917 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1918 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1919 * will be stored into the context1 field of the IOCB for the completion
1920 * callback function to the LOGO ELS command.
1923 * 0 - successfully issued logo
1924 * 1 - failed to issue logo
1927 lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1930 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1931 struct lpfc_hba *phba = vport->phba;
1933 struct lpfc_iocbq *elsiocb;
1934 struct lpfc_sli_ring *pring;
1935 struct lpfc_sli *psli;
1941 pring = &psli->ring[LPFC_ELS_RING];
1943 spin_lock_irq(shost->host_lock);
1944 if (ndlp->nlp_flag & NLP_LOGO_SND) {
1945 spin_unlock_irq(shost->host_lock);
1948 spin_unlock_irq(shost->host_lock);
1950 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
1951 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1952 ndlp->nlp_DID, ELS_CMD_LOGO);
1956 icmd = &elsiocb->iocb;
1957 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1958 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
1959 pcmd += sizeof(uint32_t);
1961 /* Fill in LOGO payload */
1962 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
1963 pcmd += sizeof(uint32_t);
1964 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
1966 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1967 "Issue LOGO: did:x%x",
1968 ndlp->nlp_DID, 0, 0);
1970 phba->fc_stat.elsXmitLOGO++;
1971 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
1972 spin_lock_irq(shost->host_lock);
1973 ndlp->nlp_flag |= NLP_LOGO_SND;
1974 spin_unlock_irq(shost->host_lock);
1975 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
1977 if (rc == IOCB_ERROR) {
1978 spin_lock_irq(shost->host_lock);
1979 ndlp->nlp_flag &= ~NLP_LOGO_SND;
1980 spin_unlock_irq(shost->host_lock);
1981 lpfc_els_free_iocb(phba, elsiocb);
1988 * lpfc_cmpl_els_cmd: Completion callback function for generic els command.
1989 * @phba: pointer to lpfc hba data structure.
1990 * @cmdiocb: pointer to lpfc command iocb data structure.
1991 * @rspiocb: pointer to lpfc response iocb data structure.
1993 * This routine is a generic completion callback function for ELS commands.
1994 * Specifically, it is the callback function which does not need to perform
1995 * any command specific operations. It is currently used by the ELS command
1996 * issuing routines for the ELS State Change Request (SCR),
1997 * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution
1998 * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than
1999 * certain debug loggings, this callback function simply invokes the
2000 * lpfc_els_chk_latt() routine to check whether link went down during the
2001 * discovery process.
2004 lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2005 struct lpfc_iocbq *rspiocb)
2007 struct lpfc_vport *vport = cmdiocb->vport;
2010 irsp = &rspiocb->iocb;
2012 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2013 "ELS cmd cmpl: status:x%x/x%x did:x%x",
2014 irsp->ulpStatus, irsp->un.ulpWord[4],
2015 irsp->un.elsreq64.remoteID);
2016 /* ELS cmd tag <ulpIoTag> completes */
2017 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2018 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
2019 irsp->ulpIoTag, irsp->ulpStatus,
2020 irsp->un.ulpWord[4], irsp->ulpTimeout);
2021 /* Check to see if link went down during discovery */
2022 lpfc_els_chk_latt(vport);
2023 lpfc_els_free_iocb(phba, cmdiocb);
2028 * lpfc_issue_els_scr: Issue a scr to an node on a vport.
2029 * @vport: pointer to a host virtual N_Port data structure.
2030 * @nportid: N_Port identifier to the remote node.
2031 * @retry: number of retries to the command IOCB.
2033 * This routine issues a State Change Request (SCR) to a fabric node
2034 * on a @vport. The remote node @nportid is passed into the function. It
2035 * first search the @vport node list to find the matching ndlp. If no such
2036 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
2037 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
2038 * routine is invoked to send the SCR IOCB.
2040 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2041 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2042 * will be stored into the context1 field of the IOCB for the completion
2043 * callback function to the SCR ELS command.
2046 * 0 - Successfully issued scr command
2047 * 1 - Failed to issue scr command
2050 lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
2052 struct lpfc_hba *phba = vport->phba;
2054 struct lpfc_iocbq *elsiocb;
2055 struct lpfc_sli_ring *pring;
2056 struct lpfc_sli *psli;
2059 struct lpfc_nodelist *ndlp;
2062 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
2063 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
2065 ndlp = lpfc_findnode_did(vport, nportid);
2067 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2070 lpfc_nlp_init(vport, ndlp, nportid);
2071 lpfc_enqueue_node(vport, ndlp);
2072 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2073 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2078 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2079 ndlp->nlp_DID, ELS_CMD_SCR);
2082 /* This will trigger the release of the node just
2089 icmd = &elsiocb->iocb;
2090 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2092 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
2093 pcmd += sizeof(uint32_t);
2095 /* For SCR, remainder of payload is SCR parameter page */
2096 memset(pcmd, 0, sizeof(SCR));
2097 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
2099 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2100 "Issue SCR: did:x%x",
2101 ndlp->nlp_DID, 0, 0);
2103 phba->fc_stat.elsXmitSCR++;
2104 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
2105 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
2106 /* The additional lpfc_nlp_put will cause the following
2107 * lpfc_els_free_iocb routine to trigger the rlease of
2111 lpfc_els_free_iocb(phba, elsiocb);
2114 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2115 * trigger the release of node.
2122 * lpfc_issue_els_farpr: Issue a farp to an node on a vport.
2123 * @vport: pointer to a host virtual N_Port data structure.
2124 * @nportid: N_Port identifier to the remote node.
2125 * @retry: number of retries to the command IOCB.
2127 * This routine issues a Fibre Channel Address Resolution Response
2128 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
2129 * is passed into the function. It first search the @vport node list to find
2130 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
2131 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
2132 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
2134 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2135 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2136 * will be stored into the context1 field of the IOCB for the completion
2137 * callback function to the PARPR ELS command.
2140 * 0 - Successfully issued farpr command
2141 * 1 - Failed to issue farpr command
2144 lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
2146 struct lpfc_hba *phba = vport->phba;
2148 struct lpfc_iocbq *elsiocb;
2149 struct lpfc_sli_ring *pring;
2150 struct lpfc_sli *psli;
2155 struct lpfc_nodelist *ondlp;
2156 struct lpfc_nodelist *ndlp;
2159 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
2160 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
2162 ndlp = lpfc_findnode_did(vport, nportid);
2164 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2167 lpfc_nlp_init(vport, ndlp, nportid);
2168 lpfc_enqueue_node(vport, ndlp);
2169 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2170 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2175 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2176 ndlp->nlp_DID, ELS_CMD_RNID);
2178 /* This will trigger the release of the node just
2185 icmd = &elsiocb->iocb;
2186 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2188 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
2189 pcmd += sizeof(uint32_t);
2191 /* Fill in FARPR payload */
2192 fp = (FARP *) (pcmd);
2193 memset(fp, 0, sizeof(FARP));
2194 lp = (uint32_t *) pcmd;
2195 *lp++ = be32_to_cpu(nportid);
2196 *lp++ = be32_to_cpu(vport->fc_myDID);
2198 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
2200 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
2201 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
2202 ondlp = lpfc_findnode_did(vport, nportid);
2203 if (ondlp && NLP_CHK_NODE_ACT(ondlp)) {
2204 memcpy(&fp->OportName, &ondlp->nlp_portname,
2205 sizeof(struct lpfc_name));
2206 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
2207 sizeof(struct lpfc_name));
2210 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2211 "Issue FARPR: did:x%x",
2212 ndlp->nlp_DID, 0, 0);
2214 phba->fc_stat.elsXmitFARPR++;
2215 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
2216 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
2217 /* The additional lpfc_nlp_put will cause the following
2218 * lpfc_els_free_iocb routine to trigger the release of
2222 lpfc_els_free_iocb(phba, elsiocb);
2225 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2226 * trigger the release of the node.
2233 * lpfc_cancel_retry_delay_tmo: Cancel the timer with delayed iocb-cmd retry.
2234 * @vport: pointer to a host virtual N_Port data structure.
2235 * @nlp: pointer to a node-list data structure.
2237 * This routine cancels the timer with a delayed IOCB-command retry for
2238 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
2239 * removes the ELS retry event if it presents. In addition, if the
2240 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
2241 * commands are sent for the @vport's nodes that require issuing discovery
2245 lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
2247 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2248 struct lpfc_work_evt *evtp;
2250 if (!(nlp->nlp_flag & NLP_DELAY_TMO))
2252 spin_lock_irq(shost->host_lock);
2253 nlp->nlp_flag &= ~NLP_DELAY_TMO;
2254 spin_unlock_irq(shost->host_lock);
2255 del_timer_sync(&nlp->nlp_delayfunc);
2256 nlp->nlp_last_elscmd = 0;
2257 if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
2258 list_del_init(&nlp->els_retry_evt.evt_listp);
2259 /* Decrement nlp reference count held for the delayed retry */
2260 evtp = &nlp->els_retry_evt;
2261 lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
2263 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
2264 spin_lock_irq(shost->host_lock);
2265 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
2266 spin_unlock_irq(shost->host_lock);
2267 if (vport->num_disc_nodes) {
2268 if (vport->port_state < LPFC_VPORT_READY) {
2269 /* Check if there are more ADISCs to be sent */
2270 lpfc_more_adisc(vport);
2272 /* Check if there are more PLOGIs to be sent */
2273 lpfc_more_plogi(vport);
2274 if (vport->num_disc_nodes == 0) {
2275 spin_lock_irq(shost->host_lock);
2276 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2277 spin_unlock_irq(shost->host_lock);
2278 lpfc_can_disctmo(vport);
2279 lpfc_end_rscn(vport);
2288 * lpfc_els_retry_delay: Timer function with a ndlp delayed function timer.
2289 * @ptr: holder for the pointer to the timer function associated data (ndlp).
2291 * This routine is invoked by the ndlp delayed-function timer to check
2292 * whether there is any pending ELS retry event(s) with the node. If not, it
2293 * simply returns. Otherwise, if there is at least one ELS delayed event, it
2294 * adds the delayed events to the HBA work list and invokes the
2295 * lpfc_worker_wake_up() routine to wake up worker thread to process the
2296 * event. Note that lpfc_nlp_get() is called before posting the event to
2297 * the work list to hold reference count of ndlp so that it guarantees the
2298 * reference to ndlp will still be available when the worker thread gets
2299 * to the event associated with the ndlp.
2302 lpfc_els_retry_delay(unsigned long ptr)
2304 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr;
2305 struct lpfc_vport *vport = ndlp->vport;
2306 struct lpfc_hba *phba = vport->phba;
2307 unsigned long flags;
2308 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
2310 spin_lock_irqsave(&phba->hbalock, flags);
2311 if (!list_empty(&evtp->evt_listp)) {
2312 spin_unlock_irqrestore(&phba->hbalock, flags);
2316 /* We need to hold the node by incrementing the reference
2317 * count until the queued work is done
2319 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
2320 if (evtp->evt_arg1) {
2321 evtp->evt = LPFC_EVT_ELS_RETRY;
2322 list_add_tail(&evtp->evt_listp, &phba->work_list);
2323 lpfc_worker_wake_up(phba);
2325 spin_unlock_irqrestore(&phba->hbalock, flags);
2330 * lpfc_els_retry_delay_handler: Work thread handler for ndlp delayed function.
2331 * @ndlp: pointer to a node-list data structure.
2333 * This routine is the worker-thread handler for processing the @ndlp delayed
2334 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
2335 * the last ELS command from the associated ndlp and invokes the proper ELS
2336 * function according to the delayed ELS command to retry the command.
2339 lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
2341 struct lpfc_vport *vport = ndlp->vport;
2342 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2343 uint32_t cmd, did, retry;
2345 spin_lock_irq(shost->host_lock);
2346 did = ndlp->nlp_DID;
2347 cmd = ndlp->nlp_last_elscmd;
2348 ndlp->nlp_last_elscmd = 0;
2350 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
2351 spin_unlock_irq(shost->host_lock);
2355 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
2356 spin_unlock_irq(shost->host_lock);
2358 * If a discovery event readded nlp_delayfunc after timer
2359 * firing and before processing the timer, cancel the
2362 del_timer_sync(&ndlp->nlp_delayfunc);
2363 retry = ndlp->nlp_retry;
2367 lpfc_issue_els_flogi(vport, ndlp, retry);
2370 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
2371 ndlp->nlp_prev_state = ndlp->nlp_state;
2372 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2376 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
2377 ndlp->nlp_prev_state = ndlp->nlp_state;
2378 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2382 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
2383 ndlp->nlp_prev_state = ndlp->nlp_state;
2384 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
2388 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
2389 ndlp->nlp_prev_state = ndlp->nlp_state;
2390 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2394 lpfc_issue_els_fdisc(vport, ndlp, retry);
2401 * lpfc_els_retry: Make retry decision on an els command iocb.
2402 * @phba: pointer to lpfc hba data structure.
2403 * @cmdiocb: pointer to lpfc command iocb data structure.
2404 * @rspiocb: pointer to lpfc response iocb data structure.
2406 * This routine makes a retry decision on an ELS command IOCB, which has
2407 * failed. The following ELS IOCBs use this function for retrying the command
2408 * when previously issued command responsed with error status: FLOGI, PLOGI,
2409 * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
2410 * returned error status, it makes the decision whether a retry shall be
2411 * issued for the command, and whether a retry shall be made immediately or
2412 * delayed. In the former case, the corresponding ELS command issuing-function
2413 * is called to retry the command. In the later case, the ELS command shall
2414 * be posted to the ndlp delayed event and delayed function timer set to the
2415 * ndlp for the delayed command issusing.
2418 * 0 - No retry of els command is made
2419 * 1 - Immediate or delayed retry of els command is made
2422 lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2423 struct lpfc_iocbq *rspiocb)
2425 struct lpfc_vport *vport = cmdiocb->vport;
2426 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2427 IOCB_t *irsp = &rspiocb->iocb;
2428 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2429 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
2432 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
2438 /* Note: context2 may be 0 for internal driver abort
2439 * of delays ELS command.
2442 if (pcmd && pcmd->virt) {
2443 elscmd = (uint32_t *) (pcmd->virt);
2447 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
2448 did = ndlp->nlp_DID;
2450 /* We should only hit this case for retrying PLOGI */
2451 did = irsp->un.elsreq64.remoteID;
2452 ndlp = lpfc_findnode_did(vport, did);
2453 if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp))
2454 && (cmd != ELS_CMD_PLOGI))
2458 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2459 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
2460 *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
2462 switch (irsp->ulpStatus) {
2463 case IOSTAT_FCP_RSP_ERROR:
2464 case IOSTAT_REMOTE_STOP:
2467 case IOSTAT_LOCAL_REJECT:
2468 switch ((irsp->un.ulpWord[4] & 0xff)) {
2469 case IOERR_LOOP_OPEN_FAILURE:
2470 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
2475 case IOERR_ILLEGAL_COMMAND:
2476 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2477 "0124 Retry illegal cmd x%x "
2478 "retry:x%x delay:x%x\n",
2479 cmd, cmdiocb->retry, delay);
2481 /* All command's retry policy */
2483 if (cmdiocb->retry > 2)
2487 case IOERR_NO_RESOURCES:
2488 logerr = 1; /* HBA out of resources */
2490 if (cmdiocb->retry > 100)
2495 case IOERR_ILLEGAL_FRAME:
2500 case IOERR_SEQUENCE_TIMEOUT:
2501 case IOERR_INVALID_RPI:
2507 case IOSTAT_NPORT_RJT:
2508 case IOSTAT_FABRIC_RJT:
2509 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
2515 case IOSTAT_NPORT_BSY:
2516 case IOSTAT_FABRIC_BSY:
2517 logerr = 1; /* Fabric / Remote NPort out of resources */
2522 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
2523 /* Added for Vendor specifc support
2524 * Just keep retrying for these Rsn / Exp codes
2526 switch (stat.un.b.lsRjtRsnCode) {
2527 case LSRJT_UNABLE_TPC:
2528 if (stat.un.b.lsRjtRsnCodeExp ==
2529 LSEXP_CMD_IN_PROGRESS) {
2530 if (cmd == ELS_CMD_PLOGI) {
2537 if (cmd == ELS_CMD_PLOGI) {
2539 maxretry = lpfc_max_els_tries + 1;
2543 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2544 (cmd == ELS_CMD_FDISC) &&
2545 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
2546 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2547 "0125 FDISC Failed (x%x). "
2548 "Fabric out of resources\n",
2549 stat.un.lsRjtError);
2550 lpfc_vport_set_state(vport,
2551 FC_VPORT_NO_FABRIC_RSCS);
2555 case LSRJT_LOGICAL_BSY:
2556 if ((cmd == ELS_CMD_PLOGI) ||
2557 (cmd == ELS_CMD_PRLI)) {
2560 } else if (cmd == ELS_CMD_FDISC) {
2561 /* FDISC retry policy */
2563 if (cmdiocb->retry >= 32)
2569 case LSRJT_LOGICAL_ERR:
2570 /* There are some cases where switches return this
2571 * error when they are not ready and should be returning
2572 * Logical Busy. We should delay every time.
2574 if (cmd == ELS_CMD_FDISC &&
2575 stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
2581 case LSRJT_PROTOCOL_ERR:
2582 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2583 (cmd == ELS_CMD_FDISC) &&
2584 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
2585 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
2587 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2588 "0122 FDISC Failed (x%x). "
2589 "Fabric Detected Bad WWN\n",
2590 stat.un.lsRjtError);
2591 lpfc_vport_set_state(vport,
2592 FC_VPORT_FABRIC_REJ_WWN);
2598 case IOSTAT_INTERMED_RSP:
2606 if (did == FDMI_DID)
2609 if ((cmd == ELS_CMD_FLOGI) &&
2610 (phba->fc_topology != TOPOLOGY_LOOP) &&
2611 !lpfc_error_lost_link(irsp)) {
2612 /* FLOGI retry policy */
2615 if (cmdiocb->retry >= 32)
2619 if ((++cmdiocb->retry) >= maxretry) {
2620 phba->fc_stat.elsRetryExceeded++;
2624 if ((vport->load_flag & FC_UNLOADING) != 0)
2629 /* Retry ELS command <elsCmd> to remote NPORT <did> */
2630 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2631 "0107 Retry ELS command x%x to remote "
2632 "NPORT x%x Data: x%x x%x\n",
2633 cmd, did, cmdiocb->retry, delay);
2635 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
2636 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
2637 ((irsp->un.ulpWord[4] & 0xff) != IOERR_NO_RESOURCES))) {
2638 /* Don't reset timer for no resources */
2640 /* If discovery / RSCN timer is running, reset it */
2641 if (timer_pending(&vport->fc_disctmo) ||
2642 (vport->fc_flag & FC_RSCN_MODE))
2643 lpfc_set_disctmo(vport);
2646 phba->fc_stat.elsXmitRetry++;
2647 if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) {
2648 phba->fc_stat.elsDelayRetry++;
2649 ndlp->nlp_retry = cmdiocb->retry;
2651 /* delay is specified in milliseconds */
2652 mod_timer(&ndlp->nlp_delayfunc,
2653 jiffies + msecs_to_jiffies(delay));
2654 spin_lock_irq(shost->host_lock);
2655 ndlp->nlp_flag |= NLP_DELAY_TMO;
2656 spin_unlock_irq(shost->host_lock);
2658 ndlp->nlp_prev_state = ndlp->nlp_state;
2659 if (cmd == ELS_CMD_PRLI)
2660 lpfc_nlp_set_state(vport, ndlp,
2661 NLP_STE_REG_LOGIN_ISSUE);
2663 lpfc_nlp_set_state(vport, ndlp,
2665 ndlp->nlp_last_elscmd = cmd;
2671 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
2674 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
2677 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
2678 ndlp->nlp_prev_state = ndlp->nlp_state;
2679 lpfc_nlp_set_state(vport, ndlp,
2680 NLP_STE_PLOGI_ISSUE);
2682 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
2685 ndlp->nlp_prev_state = ndlp->nlp_state;
2686 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2687 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
2690 ndlp->nlp_prev_state = ndlp->nlp_state;
2691 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
2692 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
2695 ndlp->nlp_prev_state = ndlp->nlp_state;
2696 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2697 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
2701 /* No retry ELS command <elsCmd> to remote NPORT <did> */
2703 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2704 "0137 No retry ELS command x%x to remote "
2705 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
2706 cmd, did, irsp->ulpStatus,
2707 irsp->un.ulpWord[4]);
2710 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2711 "0108 No retry ELS command x%x to remote "
2712 "NPORT x%x Retried:%d Error:x%x/%x\n",
2713 cmd, did, cmdiocb->retry, irsp->ulpStatus,
2714 irsp->un.ulpWord[4]);
2720 * lpfc_els_free_data: Free lpfc dma buffer and data structure with an iocb.
2721 * @phba: pointer to lpfc hba data structure.
2722 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
2724 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
2725 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
2726 * checks to see whether there is a lpfc DMA buffer associated with the
2727 * response of the command IOCB. If so, it will be released before releasing
2728 * the lpfc DMA buffer associated with the IOCB itself.
2731 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
2734 lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
2736 struct lpfc_dmabuf *buf_ptr;
2738 /* Free the response before processing the command. */
2739 if (!list_empty(&buf_ptr1->list)) {
2740 list_remove_head(&buf_ptr1->list, buf_ptr,
2743 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
2746 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
2752 * lpfc_els_free_bpl: Free lpfc dma buffer and data structure with bpl.
2753 * @phba: pointer to lpfc hba data structure.
2754 * @buf_ptr: pointer to the lpfc dma buffer data structure.
2756 * This routine releases the lpfc Direct Memory Access (DMA) buffer
2757 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
2761 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
2764 lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
2766 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
2772 * lpfc_els_free_iocb: Free a command iocb and its associated resources.
2773 * @phba: pointer to lpfc hba data structure.
2774 * @elsiocb: pointer to lpfc els command iocb data structure.
2776 * This routine frees a command IOCB and its associated resources. The
2777 * command IOCB data structure contains the reference to various associated
2778 * resources, these fields must be set to NULL if the associated reference
2780 * context1 - reference to ndlp
2781 * context2 - reference to cmd
2782 * context2->next - reference to rsp
2783 * context3 - reference to bpl
2785 * It first properly decrements the reference count held on ndlp for the
2786 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
2787 * set, it invokes the lpfc_els_free_data() routine to release the Direct
2788 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
2789 * adds the DMA buffer the @phba data structure for the delayed release.
2790 * If reference to the Buffer Pointer List (BPL) is present, the
2791 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
2792 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
2793 * invoked to release the IOCB data structure back to @phba IOCBQ list.
2796 * 0 - Success (currently, always return 0)
2799 lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
2801 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
2802 struct lpfc_nodelist *ndlp;
2804 ndlp = (struct lpfc_nodelist *)elsiocb->context1;
2806 if (ndlp->nlp_flag & NLP_DEFER_RM) {
2809 /* If the ndlp is not being used by another discovery
2812 if (!lpfc_nlp_not_used(ndlp)) {
2813 /* If ndlp is being used by another discovery
2814 * thread, just clear NLP_DEFER_RM
2816 ndlp->nlp_flag &= ~NLP_DEFER_RM;
2821 elsiocb->context1 = NULL;
2823 /* context2 = cmd, context2->next = rsp, context3 = bpl */
2824 if (elsiocb->context2) {
2825 if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
2826 /* Firmware could still be in progress of DMAing
2827 * payload, so don't free data buffer till after
2830 elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
2831 buf_ptr = elsiocb->context2;
2832 elsiocb->context2 = NULL;
2835 spin_lock_irq(&phba->hbalock);
2836 if (!list_empty(&buf_ptr->list)) {
2837 list_remove_head(&buf_ptr->list,
2838 buf_ptr1, struct lpfc_dmabuf,
2840 INIT_LIST_HEAD(&buf_ptr1->list);
2841 list_add_tail(&buf_ptr1->list,
2845 INIT_LIST_HEAD(&buf_ptr->list);
2846 list_add_tail(&buf_ptr->list, &phba->elsbuf);
2848 spin_unlock_irq(&phba->hbalock);
2851 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
2852 lpfc_els_free_data(phba, buf_ptr1);
2856 if (elsiocb->context3) {
2857 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
2858 lpfc_els_free_bpl(phba, buf_ptr);
2860 lpfc_sli_release_iocbq(phba, elsiocb);
2865 * lpfc_cmpl_els_logo_acc: Completion callback function to logo acc response.
2866 * @phba: pointer to lpfc hba data structure.
2867 * @cmdiocb: pointer to lpfc command iocb data structure.
2868 * @rspiocb: pointer to lpfc response iocb data structure.
2870 * This routine is the completion callback function to the Logout (LOGO)
2871 * Accept (ACC) Response ELS command. This routine is invoked to indicate
2872 * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
2873 * release the ndlp if it has the last reference remaining (reference count
2874 * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
2875 * field to NULL to inform the following lpfc_els_free_iocb() routine no
2876 * ndlp reference count needs to be decremented. Otherwise, the ndlp
2877 * reference use-count shall be decremented by the lpfc_els_free_iocb()
2878 * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
2879 * IOCB data structure.
2882 lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2883 struct lpfc_iocbq *rspiocb)
2885 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2886 struct lpfc_vport *vport = cmdiocb->vport;
2889 irsp = &rspiocb->iocb;
2890 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2891 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
2892 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
2893 /* ACC to LOGO completes to NPort <nlp_DID> */
2894 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2895 "0109 ACC to LOGO completes to NPort x%x "
2896 "Data: x%x x%x x%x\n",
2897 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
2900 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
2901 /* NPort Recovery mode or node is just allocated */
2902 if (!lpfc_nlp_not_used(ndlp)) {
2903 /* If the ndlp is being used by another discovery
2904 * thread, just unregister the RPI.
2906 lpfc_unreg_rpi(vport, ndlp);
2908 /* Indicate the node has already released, should
2909 * not reference to it from within lpfc_els_free_iocb.
2911 cmdiocb->context1 = NULL;
2914 lpfc_els_free_iocb(phba, cmdiocb);
2919 * lpfc_mbx_cmpl_dflt_rpi: Completion callbk func for unreg dflt rpi mbox cmd.
2920 * @phba: pointer to lpfc hba data structure.
2921 * @pmb: pointer to the driver internal queue element for mailbox command.
2923 * This routine is the completion callback function for unregister default
2924 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
2925 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
2926 * decrements the ndlp reference count held for this completion callback
2927 * function. After that, it invokes the lpfc_nlp_not_used() to check
2928 * whether there is only one reference left on the ndlp. If so, it will
2929 * perform one more decrement and trigger the release of the ndlp.
2932 lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
2934 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
2935 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
2937 pmb->context1 = NULL;
2938 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2940 mempool_free(pmb, phba->mbox_mem_pool);
2941 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
2943 /* This is the end of the default RPI cleanup logic for this
2944 * ndlp. If no other discovery threads are using this ndlp.
2945 * we should free all resources associated with it.
2947 lpfc_nlp_not_used(ndlp);
2953 * lpfc_cmpl_els_rsp: Completion callback function for els response iocb cmd.
2954 * @phba: pointer to lpfc hba data structure.
2955 * @cmdiocb: pointer to lpfc command iocb data structure.
2956 * @rspiocb: pointer to lpfc response iocb data structure.
2958 * This routine is the completion callback function for ELS Response IOCB
2959 * command. In normal case, this callback function just properly sets the
2960 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
2961 * field in the command IOCB is not NULL, the referred mailbox command will
2962 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
2963 * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
2964 * link down event occurred during the discovery, the lpfc_nlp_not_used()
2965 * routine shall be invoked trying to release the ndlp if no other threads
2966 * are currently referring it.
2969 lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2970 struct lpfc_iocbq *rspiocb)
2972 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2973 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
2974 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
2977 LPFC_MBOXQ_t *mbox = NULL;
2978 struct lpfc_dmabuf *mp = NULL;
2979 uint32_t ls_rjt = 0;
2981 irsp = &rspiocb->iocb;
2983 if (cmdiocb->context_un.mbox)
2984 mbox = cmdiocb->context_un.mbox;
2986 /* First determine if this is a LS_RJT cmpl. Note, this callback
2987 * function can have cmdiocb->contest1 (ndlp) field set to NULL.
2989 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
2990 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
2991 (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) {
2992 /* A LS_RJT associated with Default RPI cleanup has its own
2993 * seperate code path.
2995 if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
2999 /* Check to see if link went down during discovery */
3000 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) {
3002 mp = (struct lpfc_dmabuf *) mbox->context1;
3004 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3007 mempool_free(mbox, phba->mbox_mem_pool);
3009 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3010 (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
3011 if (lpfc_nlp_not_used(ndlp)) {
3013 /* Indicate the node has already released,
3014 * should not reference to it from within
3015 * the routine lpfc_els_free_iocb.
3017 cmdiocb->context1 = NULL;
3022 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3023 "ELS rsp cmpl: status:x%x/x%x did:x%x",
3024 irsp->ulpStatus, irsp->un.ulpWord[4],
3025 cmdiocb->iocb.un.elsreq64.remoteID);
3026 /* ELS response tag <ulpIoTag> completes */
3027 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3028 "0110 ELS response tag x%x completes "
3029 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
3030 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
3031 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
3032 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3035 if ((rspiocb->iocb.ulpStatus == 0)
3036 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
3037 lpfc_unreg_rpi(vport, ndlp);
3038 /* Increment reference count to ndlp to hold the
3039 * reference to ndlp for the callback function.
3041 mbox->context2 = lpfc_nlp_get(ndlp);
3042 mbox->vport = vport;
3043 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
3044 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
3045 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
3048 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
3049 ndlp->nlp_prev_state = ndlp->nlp_state;
3050 lpfc_nlp_set_state(vport, ndlp,
3051 NLP_STE_REG_LOGIN_ISSUE);
3053 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
3054 != MBX_NOT_FINISHED)
3057 /* Decrement the ndlp reference count we
3058 * set for this failed mailbox command.
3062 /* ELS rsp: Cannot issue reg_login for <NPortid> */
3063 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3064 "0138 ELS rsp: Cannot issue reg_login for x%x "
3065 "Data: x%x x%x x%x\n",
3066 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3069 if (lpfc_nlp_not_used(ndlp)) {
3071 /* Indicate node has already been released,
3072 * should not reference to it from within
3073 * the routine lpfc_els_free_iocb.
3075 cmdiocb->context1 = NULL;
3078 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
3079 if (!lpfc_error_lost_link(irsp) &&
3080 ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
3081 if (lpfc_nlp_not_used(ndlp)) {
3083 /* Indicate node has already been
3084 * released, should not reference
3085 * to it from within the routine
3086 * lpfc_els_free_iocb.
3088 cmdiocb->context1 = NULL;
3092 mp = (struct lpfc_dmabuf *) mbox->context1;
3094 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3097 mempool_free(mbox, phba->mbox_mem_pool);
3100 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
3101 spin_lock_irq(shost->host_lock);
3102 ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI);
3103 spin_unlock_irq(shost->host_lock);
3105 /* If the node is not being used by another discovery thread,
3106 * and we are sending a reject, we are done with it.
3107 * Release driver reference count here and free associated
3111 if (lpfc_nlp_not_used(ndlp))
3112 /* Indicate node has already been released,
3113 * should not reference to it from within
3114 * the routine lpfc_els_free_iocb.
3116 cmdiocb->context1 = NULL;
3119 lpfc_els_free_iocb(phba, cmdiocb);
3124 * lpfc_els_rsp_acc: Prepare and issue an acc response iocb command.
3125 * @vport: pointer to a host virtual N_Port data structure.
3126 * @flag: the els command code to be accepted.
3127 * @oldiocb: pointer to the original lpfc command iocb data structure.
3128 * @ndlp: pointer to a node-list data structure.
3129 * @mbox: pointer to the driver internal queue element for mailbox command.
3131 * This routine prepares and issues an Accept (ACC) response IOCB
3132 * command. It uses the @flag to properly set up the IOCB field for the
3133 * specific ACC response command to be issued and invokes the
3134 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
3135 * @mbox pointer is passed in, it will be put into the context_un.mbox
3136 * field of the IOCB for the completion callback function to issue the
3137 * mailbox command to the HBA later when callback is invoked.
3139 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3140 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3141 * will be stored into the context1 field of the IOCB for the completion
3142 * callback function to the corresponding response ELS IOCB command.
3145 * 0 - Successfully issued acc response
3146 * 1 - Failed to issue acc response
3149 lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
3150 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
3153 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3154 struct lpfc_hba *phba = vport->phba;
3157 struct lpfc_iocbq *elsiocb;
3158 struct lpfc_sli_ring *pring;
3159 struct lpfc_sli *psli;
3163 ELS_PKT *els_pkt_ptr;
3166 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
3167 oldcmd = &oldiocb->iocb;
3171 cmdsize = sizeof(uint32_t);
3172 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3173 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
3175 spin_lock_irq(shost->host_lock);
3176 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
3177 spin_unlock_irq(shost->host_lock);
3181 icmd = &elsiocb->iocb;
3182 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3183 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3184 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
3185 pcmd += sizeof(uint32_t);
3187 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3188 "Issue ACC: did:x%x flg:x%x",
3189 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3192 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
3193 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3194 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
3198 icmd = &elsiocb->iocb;
3199 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3200 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3203 elsiocb->context_un.mbox = mbox;
3205 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
3206 pcmd += sizeof(uint32_t);
3207 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
3209 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3210 "Issue ACC PLOGI: did:x%x flg:x%x",
3211 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3214 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
3215 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3216 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
3220 icmd = &elsiocb->iocb;
3221 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3222 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3224 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
3225 sizeof(uint32_t) + sizeof(PRLO));
3226 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
3227 els_pkt_ptr = (ELS_PKT *) pcmd;
3228 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
3230 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3231 "Issue ACC PRLO: did:x%x flg:x%x",
3232 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3237 /* Xmit ELS ACC response tag <ulpIoTag> */
3238 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3239 "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
3240 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n",
3241 elsiocb->iotag, elsiocb->iocb.ulpContext,
3242 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3244 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
3245 spin_lock_irq(shost->host_lock);
3246 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
3247 spin_unlock_irq(shost->host_lock);
3248 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
3250 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
3253 phba->fc_stat.elsXmitACC++;
3254 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
3255 if (rc == IOCB_ERROR) {
3256 lpfc_els_free_iocb(phba, elsiocb);
3263 * lpfc_els_rsp_reject: Propare and issue a rjt response iocb command.
3264 * @vport: pointer to a virtual N_Port data structure.
3266 * @oldiocb: pointer to the original lpfc command iocb data structure.
3267 * @ndlp: pointer to a node-list data structure.
3268 * @mbox: pointer to the driver internal queue element for mailbox command.
3270 * This routine prepares and issue an Reject (RJT) response IOCB
3271 * command. If a @mbox pointer is passed in, it will be put into the
3272 * context_un.mbox field of the IOCB for the completion callback function
3273 * to issue to the HBA later.
3275 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3276 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3277 * will be stored into the context1 field of the IOCB for the completion
3278 * callback function to the reject response ELS IOCB command.
3281 * 0 - Successfully issued reject response
3282 * 1 - Failed to issue reject response
3285 lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
3286 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
3289 struct lpfc_hba *phba = vport->phba;
3292 struct lpfc_iocbq *elsiocb;
3293 struct lpfc_sli_ring *pring;
3294 struct lpfc_sli *psli;
3300 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
3302 cmdsize = 2 * sizeof(uint32_t);
3303 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3304 ndlp->nlp_DID, ELS_CMD_LS_RJT);
3308 icmd = &elsiocb->iocb;
3309 oldcmd = &oldiocb->iocb;
3310 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3311 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3313 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
3314 pcmd += sizeof(uint32_t);
3315 *((uint32_t *) (pcmd)) = rejectError;
3318 elsiocb->context_un.mbox = mbox;
3320 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
3321 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3322 "0129 Xmit ELS RJT x%x response tag x%x "
3323 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
3325 rejectError, elsiocb->iotag,
3326 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
3327 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
3328 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3329 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
3330 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
3332 phba->fc_stat.elsXmitLSRJT++;
3333 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
3334 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
3336 if (rc == IOCB_ERROR) {
3337 lpfc_els_free_iocb(phba, elsiocb);
3344 * lpfc_els_rsp_adisc_acc: Prepare and issue acc response to adisc iocb cmd.
3345 * @vport: pointer to a virtual N_Port data structure.
3346 * @oldiocb: pointer to the original lpfc command iocb data structure.
3347 * @ndlp: pointer to a node-list data structure.
3349 * This routine prepares and issues an Accept (ACC) response to Address
3350 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
3351 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3353 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3354 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3355 * will be stored into the context1 field of the IOCB for the completion
3356 * callback function to the ADISC Accept response ELS IOCB command.
3359 * 0 - Successfully issued acc adisc response
3360 * 1 - Failed to issue adisc acc response
3363 lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
3364 struct lpfc_nodelist *ndlp)
3366 struct lpfc_hba *phba = vport->phba;
3367 struct lpfc_sli *psli = &phba->sli;
3368 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
3370 IOCB_t *icmd, *oldcmd;
3371 struct lpfc_iocbq *elsiocb;
3376 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
3377 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3378 ndlp->nlp_DID, ELS_CMD_ACC);
3382 icmd = &elsiocb->iocb;
3383 oldcmd = &oldiocb->iocb;
3384 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3386 /* Xmit ADISC ACC response tag <ulpIoTag> */
3387 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3388 "0130 Xmit ADISC ACC response iotag x%x xri: "
3389 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
3390 elsiocb->iotag, elsiocb->iocb.ulpContext,
3391 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3393 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3395 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
3396 pcmd += sizeof(uint32_t);
3398 ap = (ADISC *) (pcmd);
3399 ap->hardAL_PA = phba->fc_pref_ALPA;
3400 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
3401 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
3402 ap->DID = be32_to_cpu(vport->fc_myDID);
3404 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3405 "Issue ACC ADISC: did:x%x flg:x%x",
3406 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3408 phba->fc_stat.elsXmitACC++;
3409 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
3410 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
3411 if (rc == IOCB_ERROR) {
3412 lpfc_els_free_iocb(phba, elsiocb);
3419 * lpfc_els_rsp_prli_acc: Prepare and issue acc response to prli iocb cmd.
3420 * @vport: pointer to a virtual N_Port data structure.
3421 * @oldiocb: pointer to the original lpfc command iocb data structure.
3422 * @ndlp: pointer to a node-list data structure.
3424 * This routine prepares and issues an Accept (ACC) response to Process
3425 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
3426 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3428 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3429 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3430 * will be stored into the context1 field of the IOCB for the completion
3431 * callback function to the PRLI Accept response ELS IOCB command.
3434 * 0 - Successfully issued acc prli response
3435 * 1 - Failed to issue acc prli response
3438 lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
3439 struct lpfc_nodelist *ndlp)
3441 struct lpfc_hba *phba = vport->phba;
3446 struct lpfc_iocbq *elsiocb;
3447 struct lpfc_sli_ring *pring;
3448 struct lpfc_sli *psli;
3454 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
3456 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
3457 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3458 ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)));
3462 icmd = &elsiocb->iocb;
3463 oldcmd = &oldiocb->iocb;
3464 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3465 /* Xmit PRLI ACC response tag <ulpIoTag> */
3466 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3467 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
3468 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
3469 elsiocb->iotag, elsiocb->iocb.ulpContext,
3470 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3472 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3474 *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
3475 pcmd += sizeof(uint32_t);
3477 /* For PRLI, remainder of payload is PRLI parameter page */
3478 memset(pcmd, 0, sizeof(PRLI));
3480 npr = (PRLI *) pcmd;
3483 * If the remote port is a target and our firmware version is 3.20 or
3484 * later, set the following bits for FC-TAPE support.
3486 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
3487 (vpd->rev.feaLevelHigh >= 0x02)) {
3488 npr->ConfmComplAllowed = 1;
3490 npr->TaskRetryIdReq = 1;
3493 npr->acceptRspCode = PRLI_REQ_EXECUTED;
3494 npr->estabImagePair = 1;
3495 npr->readXferRdyDis = 1;
3496 npr->ConfmComplAllowed = 1;
3498 npr->prliType = PRLI_FCP_TYPE;
3499 npr->initiatorFunc = 1;
3501 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3502 "Issue ACC PRLI: did:x%x flg:x%x",
3503 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3505 phba->fc_stat.elsXmitACC++;
3506 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
3508 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
3509 if (rc == IOCB_ERROR) {
3510 lpfc_els_free_iocb(phba, elsiocb);
3517 * lpfc_els_rsp_rnid_acc: Issue rnid acc response iocb command.
3518 * @vport: pointer to a virtual N_Port data structure.
3519 * @format: rnid command format.
3520 * @oldiocb: pointer to the original lpfc command iocb data structure.
3521 * @ndlp: pointer to a node-list data structure.
3523 * This routine issues a Request Node Identification Data (RNID) Accept
3524 * (ACC) response. It constructs the RNID ACC response command according to
3525 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
3526 * issue the response. Note that this command does not need to hold the ndlp
3527 * reference count for the callback. So, the ndlp reference count taken by
3528 * the lpfc_prep_els_iocb() routine is put back and the context1 field of
3529 * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
3530 * there is no ndlp reference available.
3532 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3533 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3534 * will be stored into the context1 field of the IOCB for the completion
3535 * callback function. However, for the RNID Accept Response ELS command,
3536 * this is undone later by this routine after the IOCB is allocated.
3539 * 0 - Successfully issued acc rnid response
3540 * 1 - Failed to issue acc rnid response
3543 lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
3544 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
3546 struct lpfc_hba *phba = vport->phba;
3548 IOCB_t *icmd, *oldcmd;
3549 struct lpfc_iocbq *elsiocb;
3550 struct lpfc_sli_ring *pring;
3551 struct lpfc_sli *psli;
3557 pring = &psli->ring[LPFC_ELS_RING];
3559 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
3560 + (2 * sizeof(struct lpfc_name));
3562 cmdsize += sizeof(RNID_TOP_DISC);
3564 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3565 ndlp->nlp_DID, ELS_CMD_ACC);
3569 icmd = &elsiocb->iocb;
3570 oldcmd = &oldiocb->iocb;
3571 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3572 /* Xmit RNID ACC response tag <ulpIoTag> */
3573 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3574 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
3575 elsiocb->iotag, elsiocb->iocb.ulpContext);
3576 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3577 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
3578 pcmd += sizeof(uint32_t);
3580 memset(pcmd, 0, sizeof(RNID));
3581 rn = (RNID *) (pcmd);
3582 rn->Format = format;
3583 rn->CommonLen = (2 * sizeof(struct lpfc_name));
3584 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
3585 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
3588 rn->SpecificLen = 0;
3590 case RNID_TOPOLOGY_DISC:
3591 rn->SpecificLen = sizeof(RNID_TOP_DISC);
3592 memcpy(&rn->un.topologyDisc.portName,
3593 &vport->fc_portname, sizeof(struct lpfc_name));
3594 rn->un.topologyDisc.unitType = RNID_HBA;
3595 rn->un.topologyDisc.physPort = 0;
3596 rn->un.topologyDisc.attachedNodes = 0;
3600 rn->SpecificLen = 0;
3604 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3605 "Issue ACC RNID: did:x%x flg:x%x",
3606 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3608 phba->fc_stat.elsXmitACC++;
3609 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
3611 elsiocb->context1 = NULL; /* Don't need ndlp for cmpl,
3612 * it could be freed */
3614 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
3615 if (rc == IOCB_ERROR) {
3616 lpfc_els_free_iocb(phba, elsiocb);
3623 * lpfc_els_disc_adisc: Issue remaining adisc iocbs to npr nodes of a vport.
3624 * @vport: pointer to a host virtual N_Port data structure.
3626 * This routine issues Address Discover (ADISC) ELS commands to those
3627 * N_Ports which are in node port recovery state and ADISC has not been issued
3628 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
3629 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
3630 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
3631 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
3632 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
3633 * IOCBs quit for later pick up. On the other hand, after walking through
3634 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
3635 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
3636 * no more ADISC need to be sent.
3639 * The number of N_Ports with adisc issued.
3642 lpfc_els_disc_adisc(struct lpfc_vport *vport)
3644 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3645 struct lpfc_nodelist *ndlp, *next_ndlp;
3648 /* go thru NPR nodes and issue any remaining ELS ADISCs */
3649 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
3650 if (!NLP_CHK_NODE_ACT(ndlp))
3652 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
3653 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
3654 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
3655 spin_lock_irq(shost->host_lock);
3656 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
3657 spin_unlock_irq(shost->host_lock);
3658 ndlp->nlp_prev_state = ndlp->nlp_state;
3659 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
3660 lpfc_issue_els_adisc(vport, ndlp, 0);
3662 vport->num_disc_nodes++;
3663 if (vport->num_disc_nodes >=
3664 vport->cfg_discovery_threads) {
3665 spin_lock_irq(shost->host_lock);
3666 vport->fc_flag |= FC_NLP_MORE;
3667 spin_unlock_irq(shost->host_lock);
3672 if (sentadisc == 0) {
3673 spin_lock_irq(shost->host_lock);
3674 vport->fc_flag &= ~FC_NLP_MORE;
3675 spin_unlock_irq(shost->host_lock);
3681 * lpfc_els_disc_plogi: Issue plogi for all npr nodes of a vport before adisc.
3682 * @vport: pointer to a host virtual N_Port data structure.
3684 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
3685 * which are in node port recovery state, with a @vport. Each time an ELS
3686 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
3687 * the per @vport number of discover count (num_disc_nodes) shall be
3688 * incremented. If the num_disc_nodes reaches a pre-configured threshold
3689 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
3690 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
3691 * later pick up. On the other hand, after walking through all the ndlps with
3692 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
3693 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
3694 * PLOGI need to be sent.
3697 * The number of N_Ports with plogi issued.
3700 lpfc_els_disc_plogi(struct lpfc_vport *vport)
3702 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3703 struct lpfc_nodelist *ndlp, *next_ndlp;
3706 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
3707 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
3708 if (!NLP_CHK_NODE_ACT(ndlp))
3710 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
3711 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
3712 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
3713 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
3714 ndlp->nlp_prev_state = ndlp->nlp_state;
3715 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
3716 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
3718 vport->num_disc_nodes++;
3719 if (vport->num_disc_nodes >=
3720 vport->cfg_discovery_threads) {
3721 spin_lock_irq(shost->host_lock);
3722 vport->fc_flag |= FC_NLP_MORE;
3723 spin_unlock_irq(shost->host_lock);
3729 lpfc_set_disctmo(vport);
3732 spin_lock_irq(shost->host_lock);
3733 vport->fc_flag &= ~FC_NLP_MORE;
3734 spin_unlock_irq(shost->host_lock);
3740 * lpfc_els_flush_rscn: Clean up any rscn activities with a vport.
3741 * @vport: pointer to a host virtual N_Port data structure.
3743 * This routine cleans up any Registration State Change Notification
3744 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
3745 * @vport together with the host_lock is used to prevent multiple thread
3746 * trying to access the RSCN array on a same @vport at the same time.
3749 lpfc_els_flush_rscn(struct lpfc_vport *vport)
3751 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3752 struct lpfc_hba *phba = vport->phba;
3755 spin_lock_irq(shost->host_lock);
3756 if (vport->fc_rscn_flush) {
3757 /* Another thread is walking fc_rscn_id_list on this vport */
3758 spin_unlock_irq(shost->host_lock);
3761 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
3762 vport->fc_rscn_flush = 1;
3763 spin_unlock_irq(shost->host_lock);
3765 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
3766 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
3767 vport->fc_rscn_id_list[i] = NULL;
3769 spin_lock_irq(shost->host_lock);
3770 vport->fc_rscn_id_cnt = 0;
3771 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
3772 spin_unlock_irq(shost->host_lock);
3773 lpfc_can_disctmo(vport);
3774 /* Indicate we are done walking this fc_rscn_id_list */
3775 vport->fc_rscn_flush = 0;
3779 * lpfc_rscn_payload_check: Check whether there is a pending rscn to a did.
3780 * @vport: pointer to a host virtual N_Port data structure.
3781 * @did: remote destination port identifier.
3783 * This routine checks whether there is any pending Registration State
3784 * Configuration Notification (RSCN) to a @did on @vport.
3787 * None zero - The @did matched with a pending rscn
3788 * 0 - not able to match @did with a pending rscn
3791 lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
3796 uint32_t payload_len, i;
3797 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3799 ns_did.un.word = did;
3801 /* Never match fabric nodes for RSCNs */
3802 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
3805 /* If we are doing a FULL RSCN rediscovery, match everything */
3806 if (vport->fc_flag & FC_RSCN_DISCOVERY)
3809 spin_lock_irq(shost->host_lock);
3810 if (vport->fc_rscn_flush) {
3811 /* Another thread is walking fc_rscn_id_list on this vport */
3812 spin_unlock_irq(shost->host_lock);
3815 /* Indicate we are walking fc_rscn_id_list on this vport */
3816 vport->fc_rscn_flush = 1;
3817 spin_unlock_irq(shost->host_lock);
3818 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
3819 lp = vport->fc_rscn_id_list[i]->virt;
3820 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
3821 payload_len -= sizeof(uint32_t); /* take off word 0 */
3822 while (payload_len) {
3823 rscn_did.un.word = be32_to_cpu(*lp++);
3824 payload_len -= sizeof(uint32_t);
3825 switch (rscn_did.un.b.resv) {
3826 case 0: /* Single N_Port ID effected */
3827 if (ns_did.un.word == rscn_did.un.word)
3828 goto return_did_out;
3830 case 1: /* Whole N_Port Area effected */
3831 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
3832 && (ns_did.un.b.area == rscn_did.un.b.area))
3833 goto return_did_out;
3835 case 2: /* Whole N_Port Domain effected */
3836 if (ns_did.un.b.domain == rscn_did.un.b.domain)
3837 goto return_did_out;
3840 /* Unknown Identifier in RSCN node */
3841 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
3842 "0217 Unknown Identifier in "
3843 "RSCN payload Data: x%x\n",
3845 case 3: /* Whole Fabric effected */
3846 goto return_did_out;
3850 /* Indicate we are done with walking fc_rscn_id_list on this vport */
3851 vport->fc_rscn_flush = 0;
3854 /* Indicate we are done with walking fc_rscn_id_list on this vport */
3855 vport->fc_rscn_flush = 0;
3860 * lpfc_rscn_recovery_check: Send recovery event to vport nodes matching rscn
3861 * @vport: pointer to a host virtual N_Port data structure.
3863 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
3864 * state machine for a @vport's nodes that are with pending RSCN (Registration
3865 * State Change Notification).
3868 * 0 - Successful (currently alway return 0)
3871 lpfc_rscn_recovery_check(struct lpfc_vport *vport)
3873 struct lpfc_nodelist *ndlp = NULL;
3875 /* Move all affected nodes by pending RSCNs to NPR state. */
3876 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
3877 if (!NLP_CHK_NODE_ACT(ndlp) ||
3878 (ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
3879 !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
3881 lpfc_disc_state_machine(vport, ndlp, NULL,
3882 NLP_EVT_DEVICE_RECOVERY);
3883 lpfc_cancel_retry_delay_tmo(vport, ndlp);
3889 * lpfc_els_rcv_rscn: Process an unsolicited rscn iocb.
3890 * @vport: pointer to a host virtual N_Port data structure.
3891 * @cmdiocb: pointer to lpfc command iocb data structure.
3892 * @ndlp: pointer to a node-list data structure.
3894 * This routine processes an unsolicited RSCN (Registration State Change
3895 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
3896 * to invoke fc_host_post_event() routine to the FC transport layer. If the
3897 * discover state machine is about to begin discovery, it just accepts the
3898 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
3899 * contains N_Port IDs for other vports on this HBA, it just accepts the
3900 * RSCN and ignore processing it. If the state machine is in the recovery
3901 * state, the fc_rscn_id_list of this @vport is walked and the
3902 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
3903 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
3904 * routine is invoked to handle the RSCN event.
3907 * 0 - Just sent the acc response
3908 * 1 - Sent the acc response and waited for name server completion
3911 lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3912 struct lpfc_nodelist *ndlp)
3914 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3915 struct lpfc_hba *phba = vport->phba;
3916 struct lpfc_dmabuf *pcmd;
3917 uint32_t *lp, *datap;
3919 uint32_t payload_len, length, nportid, *cmd;
3921 int rscn_id = 0, hba_id = 0;
3924 icmd = &cmdiocb->iocb;
3925 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3926 lp = (uint32_t *) pcmd->virt;
3928 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
3929 payload_len -= sizeof(uint32_t); /* take off word 0 */
3931 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
3932 "0214 RSCN received Data: x%x x%x x%x x%x\n",
3933 vport->fc_flag, payload_len, *lp,
3934 vport->fc_rscn_id_cnt);
3935 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
3936 fc_host_post_event(shost, fc_get_event_number(),
3937 FCH_EVT_RSCN, lp[i]);
3939 /* If we are about to begin discovery, just ACC the RSCN.
3940 * Discovery processing will satisfy it.
3942 if (vport->port_state <= LPFC_NS_QRY) {
3943 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3944 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
3945 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
3947 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
3951 /* If this RSCN just contains NPortIDs for other vports on this HBA,
3952 * just ACC and ignore it.
3954 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
3955 !(vport->cfg_peer_port_login)) {
3960 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
3961 i -= sizeof(uint32_t);
3963 if (lpfc_find_vport_by_did(phba, nportid))
3966 if (rscn_id == hba_id) {
3967 /* ALL NPortIDs in RSCN are on HBA */
3968 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
3970 "Data: x%x x%x x%x x%x\n",
3971 vport->fc_flag, payload_len,
3972 *lp, vport->fc_rscn_id_cnt);
3973 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3974 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
3975 ndlp->nlp_DID, vport->port_state,
3978 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
3984 spin_lock_irq(shost->host_lock);
3985 if (vport->fc_rscn_flush) {
3986 /* Another thread is walking fc_rscn_id_list on this vport */
3987 spin_unlock_irq(shost->host_lock);
3988 vport->fc_flag |= FC_RSCN_DISCOVERY;
3990 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
3993 /* Indicate we are walking fc_rscn_id_list on this vport */
3994 vport->fc_rscn_flush = 1;
3995 spin_unlock_irq(shost->host_lock);
3996 /* Get the array count after sucessfully have the token */
3997 rscn_cnt = vport->fc_rscn_id_cnt;
3998 /* If we are already processing an RSCN, save the received
3999 * RSCN payload buffer, cmdiocb->context2 to process later.
4001 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
4002 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4003 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
4004 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4006 spin_lock_irq(shost->host_lock);
4007 vport->fc_flag |= FC_RSCN_DEFERRED;
4008 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
4009 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
4010 vport->fc_flag |= FC_RSCN_MODE;
4011 spin_unlock_irq(shost->host_lock);
4013 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
4014 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
4017 (payload_len + length <= LPFC_BPL_SIZE)) {
4018 *cmd &= ELS_CMD_MASK;
4019 *cmd |= cpu_to_be32(payload_len + length);
4020 memcpy(((uint8_t *)cmd) + length, lp,
4023 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
4024 vport->fc_rscn_id_cnt++;
4025 /* If we zero, cmdiocb->context2, the calling
4026 * routine will not try to free it.
4028 cmdiocb->context2 = NULL;
4031 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4032 "0235 Deferred RSCN "
4033 "Data: x%x x%x x%x\n",
4034 vport->fc_rscn_id_cnt, vport->fc_flag,
4037 vport->fc_flag |= FC_RSCN_DISCOVERY;
4038 spin_unlock_irq(shost->host_lock);
4039 /* ReDiscovery RSCN */
4040 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4041 "0234 ReDiscovery RSCN "
4042 "Data: x%x x%x x%x\n",
4043 vport->fc_rscn_id_cnt, vport->fc_flag,
4046 /* Indicate we are done walking fc_rscn_id_list on this vport */
4047 vport->fc_rscn_flush = 0;
4049 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
4050 /* send RECOVERY event for ALL nodes that match RSCN payload */
4051 lpfc_rscn_recovery_check(vport);
4052 spin_lock_irq(shost->host_lock);
4053 vport->fc_flag &= ~FC_RSCN_DEFERRED;
4054 spin_unlock_irq(shost->host_lock);
4057 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4058 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
4059 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4061 spin_lock_irq(shost->host_lock);
4062 vport->fc_flag |= FC_RSCN_MODE;
4063 spin_unlock_irq(shost->host_lock);
4064 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
4065 /* Indicate we are done walking fc_rscn_id_list on this vport */
4066 vport->fc_rscn_flush = 0;
4068 * If we zero, cmdiocb->context2, the calling routine will
4069 * not try to free it.
4071 cmdiocb->context2 = NULL;
4072 lpfc_set_disctmo(vport);
4074 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
4075 /* send RECOVERY event for ALL nodes that match RSCN payload */
4076 lpfc_rscn_recovery_check(vport);
4077 return lpfc_els_handle_rscn(vport);
4081 * lpfc_els_handle_rscn: Handle rscn for a vport.
4082 * @vport: pointer to a host virtual N_Port data structure.
4084 * This routine handles the Registration State Configuration Notification
4085 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
4086 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
4087 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
4088 * NameServer shall be issued. If CT command to the NameServer fails to be
4089 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
4090 * RSCN activities with the @vport.
4093 * 0 - Cleaned up rscn on the @vport
4094 * 1 - Wait for plogi to name server before proceed
4097 lpfc_els_handle_rscn(struct lpfc_vport *vport)
4099 struct lpfc_nodelist *ndlp;
4100 struct lpfc_hba *phba = vport->phba;
4102 /* Ignore RSCN if the port is being torn down. */
4103 if (vport->load_flag & FC_UNLOADING) {
4104 lpfc_els_flush_rscn(vport);
4108 /* Start timer for RSCN processing */
4109 lpfc_set_disctmo(vport);
4111 /* RSCN processed */
4112 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4113 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
4114 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
4117 /* To process RSCN, first compare RSCN data with NameServer */
4118 vport->fc_ns_retry = 0;
4119 vport->num_disc_nodes = 0;
4121 ndlp = lpfc_findnode_did(vport, NameServer_DID);
4122 if (ndlp && NLP_CHK_NODE_ACT(ndlp)
4123 && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
4124 /* Good ndlp, issue CT Request to NameServer */
4125 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0)
4126 /* Wait for NameServer query cmpl before we can
4130 /* If login to NameServer does not exist, issue one */
4131 /* Good status, issue PLOGI to NameServer */
4132 ndlp = lpfc_findnode_did(vport, NameServer_DID);
4133 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
4134 /* Wait for NameServer login cmpl before we can
4139 ndlp = lpfc_enable_node(vport, ndlp,
4140 NLP_STE_PLOGI_ISSUE);
4142 lpfc_els_flush_rscn(vport);
4145 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
4147 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
4149 lpfc_els_flush_rscn(vport);
4152 lpfc_nlp_init(vport, ndlp, NameServer_DID);
4153 ndlp->nlp_prev_state = ndlp->nlp_state;
4154 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
4156 ndlp->nlp_type |= NLP_FABRIC;
4157 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
4158 /* Wait for NameServer login cmpl before we can
4164 lpfc_els_flush_rscn(vport);
4169 * lpfc_els_rcv_flogi: Process an unsolicited flogi iocb.
4170 * @vport: pointer to a host virtual N_Port data structure.
4171 * @cmdiocb: pointer to lpfc command iocb data structure.
4172 * @ndlp: pointer to a node-list data structure.
4174 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
4175 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
4176 * point topology. As an unsolicited FLOGI should not be received in a loop
4177 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
4178 * lpfc_check_sparm() routine is invoked to check the parameters in the
4179 * unsolicited FLOGI. If parameters validation failed, the routine
4180 * lpfc_els_rsp_reject() shall be called with reject reason code set to
4181 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
4182 * FLOGI shall be compared with the Port WWN of the @vport to determine who
4183 * will initiate PLOGI. The higher lexicographical value party shall has
4184 * higher priority (as the winning port) and will initiate PLOGI and
4185 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
4186 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
4187 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
4190 * 0 - Successfully processed the unsolicited flogi
4191 * 1 - Failed to process the unsolicited flogi
4194 lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4195 struct lpfc_nodelist *ndlp)
4197 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4198 struct lpfc_hba *phba = vport->phba;
4199 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4200 uint32_t *lp = (uint32_t *) pcmd->virt;
4201 IOCB_t *icmd = &cmdiocb->iocb;
4202 struct serv_parm *sp;
4209 sp = (struct serv_parm *) lp;
4211 /* FLOGI received */
4213 lpfc_set_disctmo(vport);
4215 if (phba->fc_topology == TOPOLOGY_LOOP) {
4216 /* We should never receive a FLOGI in loop mode, ignore it */
4217 did = icmd->un.elsreq64.remoteID;
4219 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
4221 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4222 "0113 An FLOGI ELS command x%x was "
4223 "received from DID x%x in Loop Mode\n",
4230 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3))) {
4231 /* For a FLOGI we accept, then if our portname is greater
4232 * then the remote portname we initiate Nport login.
4235 rc = memcmp(&vport->fc_portname, &sp->portName,
4236 sizeof(struct lpfc_name));
4239 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4243 lpfc_linkdown(phba);
4244 lpfc_init_link(phba, mbox,
4246 phba->cfg_link_speed);
4247 mbox->mb.un.varInitLnk.lipsr_AL_PA = 0;
4248 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
4249 mbox->vport = vport;
4250 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
4251 lpfc_set_loopback_flag(phba);
4252 if (rc == MBX_NOT_FINISHED) {
4253 mempool_free(mbox, phba->mbox_mem_pool);
4256 } else if (rc > 0) { /* greater than */
4257 spin_lock_irq(shost->host_lock);
4258 vport->fc_flag |= FC_PT2PT_PLOGI;
4259 spin_unlock_irq(shost->host_lock);
4261 spin_lock_irq(shost->host_lock);
4262 vport->fc_flag |= FC_PT2PT;
4263 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
4264 spin_unlock_irq(shost->host_lock);
4266 /* Reject this request because invalid parameters */
4267 stat.un.b.lsRjtRsvd0 = 0;
4268 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4269 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
4270 stat.un.b.vendorUnique = 0;
4271 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4277 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
4283 * lpfc_els_rcv_rnid: Process an unsolicited rnid iocb.
4284 * @vport: pointer to a host virtual N_Port data structure.
4285 * @cmdiocb: pointer to lpfc command iocb data structure.
4286 * @ndlp: pointer to a node-list data structure.
4288 * This routine processes Request Node Identification Data (RNID) IOCB
4289 * received as an ELS unsolicited event. Only when the RNID specified format
4290 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
4291 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
4292 * Accept (ACC) the RNID ELS command. All the other RNID formats are
4293 * rejected by invoking the lpfc_els_rsp_reject() routine.
4296 * 0 - Successfully processed rnid iocb (currently always return 0)
4299 lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4300 struct lpfc_nodelist *ndlp)
4302 struct lpfc_dmabuf *pcmd;
4309 icmd = &cmdiocb->iocb;
4310 did = icmd->un.elsreq64.remoteID;
4311 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4312 lp = (uint32_t *) pcmd->virt;
4319 switch (rn->Format) {
4321 case RNID_TOPOLOGY_DISC:
4323 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
4326 /* Reject this request because format not supported */
4327 stat.un.b.lsRjtRsvd0 = 0;
4328 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4329 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4330 stat.un.b.vendorUnique = 0;
4331 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4338 * lpfc_els_rcv_lirr: Process an unsolicited lirr iocb.
4339 * @vport: pointer to a host virtual N_Port data structure.
4340 * @cmdiocb: pointer to lpfc command iocb data structure.
4341 * @ndlp: pointer to a node-list data structure.
4343 * This routine processes a Link Incident Report Registration(LIRR) IOCB
4344 * received as an ELS unsolicited event. Currently, this function just invokes
4345 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
4348 * 0 - Successfully processed lirr iocb (currently always return 0)
4351 lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4352 struct lpfc_nodelist *ndlp)
4356 /* For now, unconditionally reject this command */
4357 stat.un.b.lsRjtRsvd0 = 0;
4358 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4359 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4360 stat.un.b.vendorUnique = 0;
4361 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
4366 * lpfc_els_rsp_rps_acc: Completion callbk func for MBX_READ_LNK_STAT mbox cmd.
4367 * @phba: pointer to lpfc hba data structure.
4368 * @pmb: pointer to the driver internal queue element for mailbox command.
4370 * This routine is the completion callback function for the MBX_READ_LNK_STAT
4371 * mailbox command. This callback function is to actually send the Accept
4372 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
4373 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
4374 * mailbox command, constructs the RPS response with the link statistics
4375 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
4376 * response to the RPS.
4378 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4379 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4380 * will be stored into the context1 field of the IOCB for the completion
4381 * callback function to the RPS Accept Response ELS IOCB command.
4385 lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4387 struct lpfc_sli *psli = &phba->sli;
4388 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
4393 struct lpfc_iocbq *elsiocb;
4394 struct lpfc_nodelist *ndlp;
4395 uint16_t xri, status;
4400 ndlp = (struct lpfc_nodelist *) pmb->context2;
4401 xri = (uint16_t) ((unsigned long)(pmb->context1));
4402 pmb->context1 = NULL;
4403 pmb->context2 = NULL;
4405 if (mb->mbxStatus) {
4406 mempool_free(pmb, phba->mbox_mem_pool);
4410 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
4411 mempool_free(pmb, phba->mbox_mem_pool);
4412 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
4413 lpfc_max_els_tries, ndlp,
4414 ndlp->nlp_DID, ELS_CMD_ACC);
4416 /* Decrement the ndlp reference count from previous mbox command */
4422 icmd = &elsiocb->iocb;
4423 icmd->ulpContext = xri;
4425 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4426 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4427 pcmd += sizeof(uint32_t); /* Skip past command */
4428 rps_rsp = (RPS_RSP *)pcmd;
4430 if (phba->fc_topology != TOPOLOGY_LOOP)
4434 if (phba->pport->fc_flag & FC_FABRIC)
4438 rps_rsp->portStatus = cpu_to_be16(status);
4439 rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
4440 rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
4441 rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
4442 rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
4443 rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
4444 rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
4445 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
4446 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
4447 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
4448 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
4449 elsiocb->iotag, elsiocb->iocb.ulpContext,
4450 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4452 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4453 phba->fc_stat.elsXmitACC++;
4454 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR)
4455 lpfc_els_free_iocb(phba, elsiocb);
4460 * lpfc_els_rcv_rps: Process an unsolicited rps iocb.
4461 * @vport: pointer to a host virtual N_Port data structure.
4462 * @cmdiocb: pointer to lpfc command iocb data structure.
4463 * @ndlp: pointer to a node-list data structure.
4465 * This routine processes Read Port Status (RPS) IOCB received as an
4466 * ELS unsolicited event. It first checks the remote port state. If the
4467 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
4468 * state, it invokes the lpfc_els_rsp_reject() routine to send the reject
4469 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
4470 * for reading the HBA link statistics. It is for the callback function,
4471 * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command
4472 * to actually sending out RPS Accept (ACC) response.
4475 * 0 - Successfully processed rps iocb (currently always return 0)
4478 lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4479 struct lpfc_nodelist *ndlp)
4481 struct lpfc_hba *phba = vport->phba;
4485 struct lpfc_dmabuf *pcmd;
4489 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
4490 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
4491 /* reject the unsolicited RPS request and done with it */
4494 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4495 lp = (uint32_t *) pcmd->virt;
4496 flag = (be32_to_cpu(*lp++) & 0xf);
4500 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
4501 ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
4502 sizeof(struct lpfc_name)) == 0))) {
4504 printk("Fix me....\n");
4506 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
4508 lpfc_read_lnk_stat(phba, mbox);
4510 (void *)((unsigned long) cmdiocb->iocb.ulpContext);
4511 mbox->context2 = lpfc_nlp_get(ndlp);
4512 mbox->vport = vport;
4513 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
4514 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
4515 != MBX_NOT_FINISHED)
4516 /* Mbox completion will send ELS Response */
4518 /* Decrement reference count used for the failed mbox
4522 mempool_free(mbox, phba->mbox_mem_pool);
4527 /* issue rejection response */
4528 stat.un.b.lsRjtRsvd0 = 0;
4529 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4530 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4531 stat.un.b.vendorUnique = 0;
4532 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
4537 * lpfc_els_rsp_rpl_acc: Issue an accept rpl els command.
4538 * @vport: pointer to a host virtual N_Port data structure.
4539 * @cmdsize: size of the ELS command.
4540 * @oldiocb: pointer to the original lpfc command iocb data structure.
4541 * @ndlp: pointer to a node-list data structure.
4543 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
4544 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
4546 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4547 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4548 * will be stored into the context1 field of the IOCB for the completion
4549 * callback function to the RPL Accept Response ELS command.
4552 * 0 - Successfully issued ACC RPL ELS command
4553 * 1 - Failed to issue ACC RPL ELS command
4556 lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
4557 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
4559 struct lpfc_hba *phba = vport->phba;
4560 IOCB_t *icmd, *oldcmd;
4562 struct lpfc_iocbq *elsiocb;
4563 struct lpfc_sli *psli = &phba->sli;
4564 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
4567 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4568 ndlp->nlp_DID, ELS_CMD_ACC);
4573 icmd = &elsiocb->iocb;
4574 oldcmd = &oldiocb->iocb;
4575 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
4577 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4578 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4579 pcmd += sizeof(uint16_t);
4580 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
4581 pcmd += sizeof(uint16_t);
4583 /* Setup the RPL ACC payload */
4584 rpl_rsp.listLen = be32_to_cpu(1);
4586 rpl_rsp.port_num_blk.portNum = 0;
4587 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
4588 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
4589 sizeof(struct lpfc_name));
4590 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
4591 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
4592 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4593 "0120 Xmit ELS RPL ACC response tag x%x "
4594 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
4596 elsiocb->iotag, elsiocb->iocb.ulpContext,
4597 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4599 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4600 phba->fc_stat.elsXmitACC++;
4601 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
4602 lpfc_els_free_iocb(phba, elsiocb);
4609 * lpfc_els_rcv_rpl: Process an unsolicited rpl iocb.
4610 * @vport: pointer to a host virtual N_Port data structure.
4611 * @cmdiocb: pointer to lpfc command iocb data structure.
4612 * @ndlp: pointer to a node-list data structure.
4614 * This routine processes Read Port List (RPL) IOCB received as an ELS
4615 * unsolicited event. It first checks the remote port state. If the remote
4616 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
4617 * invokes the lpfc_els_rsp_reject() routine to send reject response.
4618 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
4619 * to accept the RPL.
4622 * 0 - Successfully processed rpl iocb (currently always return 0)
4625 lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4626 struct lpfc_nodelist *ndlp)
4628 struct lpfc_dmabuf *pcmd;
4635 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
4636 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
4637 /* issue rejection response */
4638 stat.un.b.lsRjtRsvd0 = 0;
4639 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4640 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4641 stat.un.b.vendorUnique = 0;
4642 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4644 /* rejected the unsolicited RPL request and done with it */
4648 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4649 lp = (uint32_t *) pcmd->virt;
4650 rpl = (RPL *) (lp + 1);
4652 maxsize = be32_to_cpu(rpl->maxsize);
4654 /* We support only one port */
4655 if ((rpl->index == 0) &&
4657 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
4658 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
4660 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
4662 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
4668 * lpfc_els_rcv_farp: Process an unsolicited farp request els command.
4669 * @vport: pointer to a virtual N_Port data structure.
4670 * @cmdiocb: pointer to lpfc command iocb data structure.
4671 * @ndlp: pointer to a node-list data structure.
4673 * This routine processes Fibre Channel Address Resolution Protocol
4674 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
4675 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
4676 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
4677 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
4678 * remote PortName is compared against the FC PortName stored in the @vport
4679 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
4680 * compared against the FC NodeName stored in the @vport data structure.
4681 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
4682 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
4683 * invoked to send out FARP Response to the remote node. Before sending the
4684 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
4685 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
4686 * routine is invoked to log into the remote port first.
4689 * 0 - Either the FARP Match Mode not supported or successfully processed
4692 lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4693 struct lpfc_nodelist *ndlp)
4695 struct lpfc_dmabuf *pcmd;
4699 uint32_t cmd, cnt, did;
4701 icmd = &cmdiocb->iocb;
4702 did = icmd->un.elsreq64.remoteID;
4703 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4704 lp = (uint32_t *) pcmd->virt;
4708 /* FARP-REQ received from DID <did> */
4709 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4710 "0601 FARP-REQ received from DID x%x\n", did);
4711 /* We will only support match on WWPN or WWNN */
4712 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
4717 /* If this FARP command is searching for my portname */
4718 if (fp->Mflags & FARP_MATCH_PORT) {
4719 if (memcmp(&fp->RportName, &vport->fc_portname,
4720 sizeof(struct lpfc_name)) == 0)
4724 /* If this FARP command is searching for my nodename */
4725 if (fp->Mflags & FARP_MATCH_NODE) {
4726 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
4727 sizeof(struct lpfc_name)) == 0)
4732 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
4733 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
4734 /* Log back into the node before sending the FARP. */
4735 if (fp->Rflags & FARP_REQUEST_PLOGI) {
4736 ndlp->nlp_prev_state = ndlp->nlp_state;
4737 lpfc_nlp_set_state(vport, ndlp,
4738 NLP_STE_PLOGI_ISSUE);
4739 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
4742 /* Send a FARP response to that node */
4743 if (fp->Rflags & FARP_REQUEST_FARPR)
4744 lpfc_issue_els_farpr(vport, did, 0);
4751 * lpfc_els_rcv_farpr: Process an unsolicited farp response iocb.
4752 * @vport: pointer to a host virtual N_Port data structure.
4753 * @cmdiocb: pointer to lpfc command iocb data structure.
4754 * @ndlp: pointer to a node-list data structure.
4756 * This routine processes Fibre Channel Address Resolution Protocol
4757 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
4758 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
4759 * the FARP response request.
4762 * 0 - Successfully processed FARPR IOCB (currently always return 0)
4765 lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4766 struct lpfc_nodelist *ndlp)
4768 struct lpfc_dmabuf *pcmd;
4773 icmd = &cmdiocb->iocb;
4774 did = icmd->un.elsreq64.remoteID;
4775 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4776 lp = (uint32_t *) pcmd->virt;
4779 /* FARP-RSP received from DID <did> */
4780 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4781 "0600 FARP-RSP received from DID x%x\n", did);
4782 /* ACCEPT the Farp resp request */
4783 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
4789 * lpfc_els_rcv_fan: Process an unsolicited fan iocb command.
4790 * @vport: pointer to a host virtual N_Port data structure.
4791 * @cmdiocb: pointer to lpfc command iocb data structure.
4792 * @fan_ndlp: pointer to a node-list data structure.
4794 * This routine processes a Fabric Address Notification (FAN) IOCB
4795 * command received as an ELS unsolicited event. The FAN ELS command will
4796 * only be processed on a physical port (i.e., the @vport represents the
4797 * physical port). The fabric NodeName and PortName from the FAN IOCB are
4798 * compared against those in the phba data structure. If any of those is
4799 * different, the lpfc_initial_flogi() routine is invoked to initialize
4800 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
4801 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
4802 * is invoked to register login to the fabric.
4805 * 0 - Successfully processed fan iocb (currently always return 0).
4808 lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4809 struct lpfc_nodelist *fan_ndlp)
4811 struct lpfc_hba *phba = vport->phba;
4815 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
4816 lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
4818 /* FAN received; Fan does not have a reply sequence */
4819 if ((vport == phba->pport) &&
4820 (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
4821 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
4822 sizeof(struct lpfc_name))) ||
4823 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
4824 sizeof(struct lpfc_name)))) {
4825 /* This port has switched fabrics. FLOGI is required */
4826 lpfc_initial_flogi(vport);
4828 /* FAN verified - skip FLOGI */
4829 vport->fc_myDID = vport->fc_prevDID;
4830 lpfc_issue_fabric_reglogin(vport);
4837 * lpfc_els_timeout: Handler funciton to the els timer.
4838 * @ptr: holder for the timer function associated data.
4840 * This routine is invoked by the ELS timer after timeout. It posts the ELS
4841 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
4842 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
4843 * up the worker thread. It is for the worker thread to invoke the routine
4844 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
4847 lpfc_els_timeout(unsigned long ptr)
4849 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
4850 struct lpfc_hba *phba = vport->phba;
4851 uint32_t tmo_posted;
4852 unsigned long iflag;
4854 spin_lock_irqsave(&vport->work_port_lock, iflag);
4855 tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
4857 vport->work_port_events |= WORKER_ELS_TMO;
4858 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
4861 lpfc_worker_wake_up(phba);
4866 * lpfc_els_timeout_handler: Process an els timeout event.
4867 * @vport: pointer to a virtual N_Port data structure.
4869 * This routine is the actual handler function that processes an ELS timeout
4870 * event. It walks the ELS ring to get and abort all the IOCBs (except the
4871 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
4872 * invoking the lpfc_sli_issue_abort_iotag() routine.
4875 lpfc_els_timeout_handler(struct lpfc_vport *vport)
4877 struct lpfc_hba *phba = vport->phba;
4878 struct lpfc_sli_ring *pring;
4879 struct lpfc_iocbq *tmp_iocb, *piocb;
4881 struct lpfc_dmabuf *pcmd;
4882 uint32_t els_command = 0;
4884 uint32_t remote_ID = 0xffffffff;
4886 /* If the timer is already canceled do nothing */
4887 if ((vport->work_port_events & WORKER_ELS_TMO) == 0) {
4890 spin_lock_irq(&phba->hbalock);
4891 timeout = (uint32_t)(phba->fc_ratov << 1);
4893 pring = &phba->sli.ring[LPFC_ELS_RING];
4895 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
4898 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
4899 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
4900 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
4903 if (piocb->vport != vport)
4906 pcmd = (struct lpfc_dmabuf *) piocb->context2;
4908 els_command = *(uint32_t *) (pcmd->virt);
4910 if (els_command == ELS_CMD_FARP ||
4911 els_command == ELS_CMD_FARPR ||
4912 els_command == ELS_CMD_FDISC)
4915 if (piocb->drvrTimeout > 0) {
4916 if (piocb->drvrTimeout >= timeout)
4917 piocb->drvrTimeout -= timeout;
4919 piocb->drvrTimeout = 0;
4923 remote_ID = 0xffffffff;
4924 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
4925 remote_ID = cmd->un.elsreq64.remoteID;
4927 struct lpfc_nodelist *ndlp;
4928 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
4929 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
4930 remote_ID = ndlp->nlp_DID;
4932 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4933 "0127 ELS timeout Data: x%x x%x x%x "
4934 "x%x\n", els_command,
4935 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
4936 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
4938 spin_unlock_irq(&phba->hbalock);
4940 if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt)
4941 mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
4945 * lpfc_els_flush_cmd: Clean up the outstanding els commands to a vport.
4946 * @vport: pointer to a host virtual N_Port data structure.
4948 * This routine is used to clean up all the outstanding ELS commands on a
4949 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
4950 * routine. After that, it walks the ELS transmit queue to remove all the
4951 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
4952 * the IOCBs with a non-NULL completion callback function, the callback
4953 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
4954 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
4955 * callback function, the IOCB will simply be released. Finally, it walks
4956 * the ELS transmit completion queue to issue an abort IOCB to any transmit
4957 * completion queue IOCB that is associated with the @vport and is not
4958 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
4959 * part of the discovery state machine) out to HBA by invoking the
4960 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
4961 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
4962 * the IOCBs are aborted when this function returns.
4965 lpfc_els_flush_cmd(struct lpfc_vport *vport)
4967 LIST_HEAD(completions);
4968 struct lpfc_hba *phba = vport->phba;
4969 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
4970 struct lpfc_iocbq *tmp_iocb, *piocb;
4973 lpfc_fabric_abort_vport(vport);
4975 spin_lock_irq(&phba->hbalock);
4976 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
4979 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
4983 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
4984 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
4985 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
4986 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
4987 cmd->ulpCommand == CMD_ABORT_XRI_CN)
4990 if (piocb->vport != vport)
4993 list_move_tail(&piocb->list, &completions);
4997 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
4998 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
5002 if (piocb->vport != vport)
5005 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
5007 spin_unlock_irq(&phba->hbalock);
5009 while (!list_empty(&completions)) {
5010 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
5012 list_del_init(&piocb->list);
5014 if (!piocb->iocb_cmpl)
5015 lpfc_sli_release_iocbq(phba, piocb);
5017 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
5018 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
5019 (piocb->iocb_cmpl) (phba, piocb, piocb);
5027 * lpfc_els_flush_all_cmd: Clean up all the outstanding els commands to a HBA.
5028 * @phba: pointer to lpfc hba data structure.
5030 * This routine is used to clean up all the outstanding ELS commands on a
5031 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
5032 * routine. After that, it walks the ELS transmit queue to remove all the
5033 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
5034 * the IOCBs with the completion callback function associated, the callback
5035 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
5036 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
5037 * callback function associated, the IOCB will simply be released. Finally,
5038 * it walks the ELS transmit completion queue to issue an abort IOCB to any
5039 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
5040 * management plane IOCBs that are not part of the discovery state machine)
5041 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
5044 lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
5046 LIST_HEAD(completions);
5047 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
5048 struct lpfc_iocbq *tmp_iocb, *piocb;
5051 lpfc_fabric_abort_hba(phba);
5052 spin_lock_irq(&phba->hbalock);
5053 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
5055 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
5057 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
5058 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
5059 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
5060 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
5061 cmd->ulpCommand == CMD_ABORT_XRI_CN)
5063 list_move_tail(&piocb->list, &completions);
5066 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
5067 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
5069 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
5071 spin_unlock_irq(&phba->hbalock);
5072 while (!list_empty(&completions)) {
5073 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
5075 list_del_init(&piocb->list);
5076 if (!piocb->iocb_cmpl)
5077 lpfc_sli_release_iocbq(phba, piocb);
5079 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
5080 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
5081 (piocb->iocb_cmpl) (phba, piocb, piocb);
5088 * lpfc_els_unsol_buffer: Process an unsolicited event data buffer.
5089 * @phba: pointer to lpfc hba data structure.
5090 * @pring: pointer to a SLI ring.
5091 * @vport: pointer to a host virtual N_Port data structure.
5092 * @elsiocb: pointer to lpfc els command iocb data structure.
5094 * This routine is used for processing the IOCB associated with a unsolicited
5095 * event. It first determines whether there is an existing ndlp that matches
5096 * the DID from the unsolicited IOCB. If not, it will create a new one with
5097 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
5098 * IOCB is then used to invoke the proper routine and to set up proper state
5099 * of the discovery state machine.
5102 lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
5103 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
5105 struct Scsi_Host *shost;
5106 struct lpfc_nodelist *ndlp;
5109 uint32_t cmd, did, newnode, rjt_err = 0;
5110 IOCB_t *icmd = &elsiocb->iocb;
5112 if (!vport || !(elsiocb->context2))
5116 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
5118 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
5119 lpfc_post_buffer(phba, pring, 1);
5121 did = icmd->un.rcvels.remoteID;
5122 if (icmd->ulpStatus) {
5123 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5124 "RCV Unsol ELS: status:x%x/x%x did:x%x",
5125 icmd->ulpStatus, icmd->un.ulpWord[4], did);
5129 /* Check to see if link went down during discovery */
5130 if (lpfc_els_chk_latt(vport))
5133 /* Ignore traffic recevied during vport shutdown. */
5134 if (vport->load_flag & FC_UNLOADING)
5137 ndlp = lpfc_findnode_did(vport, did);
5139 /* Cannot find existing Fabric ndlp, so allocate a new one */
5140 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
5144 lpfc_nlp_init(vport, ndlp, did);
5145 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5147 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
5148 ndlp->nlp_type |= NLP_FABRIC;
5149 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
5150 ndlp = lpfc_enable_node(vport, ndlp,
5151 NLP_STE_UNUSED_NODE);
5154 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5156 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
5157 ndlp->nlp_type |= NLP_FABRIC;
5158 } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
5159 /* This is similar to the new node path */
5160 ndlp = lpfc_nlp_get(ndlp);
5163 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5167 phba->fc_stat.elsRcvFrame++;
5169 elsiocb->context1 = lpfc_nlp_get(ndlp);
5170 elsiocb->vport = vport;
5172 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
5173 cmd &= ELS_CMD_MASK;
5175 /* ELS command <elsCmd> received from NPORT <did> */
5176 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5177 "0112 ELS command x%x received from NPORT x%x "
5178 "Data: x%x\n", cmd, did, vport->port_state);
5181 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5182 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
5183 did, vport->port_state, ndlp->nlp_flag);
5185 phba->fc_stat.elsRcvPLOGI++;
5186 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
5188 if (vport->port_state < LPFC_DISC_AUTH) {
5189 if (!(phba->pport->fc_flag & FC_PT2PT) ||
5190 (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
5191 rjt_err = LSRJT_UNABLE_TPC;
5194 /* We get here, and drop thru, if we are PT2PT with
5195 * another NPort and the other side has initiated
5196 * the PLOGI before responding to our FLOGI.
5200 shost = lpfc_shost_from_vport(vport);
5201 spin_lock_irq(shost->host_lock);
5202 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
5203 spin_unlock_irq(shost->host_lock);
5205 lpfc_disc_state_machine(vport, ndlp, elsiocb,
5210 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5211 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
5212 did, vport->port_state, ndlp->nlp_flag);
5214 phba->fc_stat.elsRcvFLOGI++;
5215 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
5220 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5221 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
5222 did, vport->port_state, ndlp->nlp_flag);
5224 phba->fc_stat.elsRcvLOGO++;
5225 if (vport->port_state < LPFC_DISC_AUTH) {
5226 rjt_err = LSRJT_UNABLE_TPC;
5229 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
5232 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5233 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
5234 did, vport->port_state, ndlp->nlp_flag);
5236 phba->fc_stat.elsRcvPRLO++;
5237 if (vport->port_state < LPFC_DISC_AUTH) {
5238 rjt_err = LSRJT_UNABLE_TPC;
5241 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
5244 phba->fc_stat.elsRcvRSCN++;
5245 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
5250 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5251 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
5252 did, vport->port_state, ndlp->nlp_flag);
5254 phba->fc_stat.elsRcvADISC++;
5255 if (vport->port_state < LPFC_DISC_AUTH) {
5256 rjt_err = LSRJT_UNABLE_TPC;
5259 lpfc_disc_state_machine(vport, ndlp, elsiocb,
5263 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5264 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
5265 did, vport->port_state, ndlp->nlp_flag);
5267 phba->fc_stat.elsRcvPDISC++;
5268 if (vport->port_state < LPFC_DISC_AUTH) {
5269 rjt_err = LSRJT_UNABLE_TPC;
5272 lpfc_disc_state_machine(vport, ndlp, elsiocb,
5276 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5277 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
5278 did, vport->port_state, ndlp->nlp_flag);
5280 phba->fc_stat.elsRcvFARPR++;
5281 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
5284 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5285 "RCV FARP: did:x%x/ste:x%x flg:x%x",
5286 did, vport->port_state, ndlp->nlp_flag);
5288 phba->fc_stat.elsRcvFARP++;
5289 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
5292 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5293 "RCV FAN: did:x%x/ste:x%x flg:x%x",
5294 did, vport->port_state, ndlp->nlp_flag);
5296 phba->fc_stat.elsRcvFAN++;
5297 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
5300 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5301 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
5302 did, vport->port_state, ndlp->nlp_flag);
5304 phba->fc_stat.elsRcvPRLI++;
5305 if (vport->port_state < LPFC_DISC_AUTH) {
5306 rjt_err = LSRJT_UNABLE_TPC;
5309 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
5312 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5313 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
5314 did, vport->port_state, ndlp->nlp_flag);
5316 phba->fc_stat.elsRcvLIRR++;
5317 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
5322 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5323 "RCV RPS: did:x%x/ste:x%x flg:x%x",
5324 did, vport->port_state, ndlp->nlp_flag);
5326 phba->fc_stat.elsRcvRPS++;
5327 lpfc_els_rcv_rps(vport, elsiocb, ndlp);
5332 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5333 "RCV RPL: did:x%x/ste:x%x flg:x%x",
5334 did, vport->port_state, ndlp->nlp_flag);
5336 phba->fc_stat.elsRcvRPL++;
5337 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
5342 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5343 "RCV RNID: did:x%x/ste:x%x flg:x%x",
5344 did, vport->port_state, ndlp->nlp_flag);
5346 phba->fc_stat.elsRcvRNID++;
5347 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
5352 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5353 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
5354 cmd, did, vport->port_state);
5356 /* Unsupported ELS command, reject */
5357 rjt_err = LSRJT_INVALID_CMD;
5359 /* Unknown ELS command <elsCmd> received from NPORT <did> */
5360 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5361 "0115 Unknown ELS command x%x "
5362 "received from NPORT x%x\n", cmd, did);
5368 /* check if need to LS_RJT received ELS cmd */
5370 memset(&stat, 0, sizeof(stat));
5371 stat.un.b.lsRjtRsnCode = rjt_err;
5372 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
5373 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
5377 lpfc_nlp_put(elsiocb->context1);
5378 elsiocb->context1 = NULL;
5382 if (vport && !(vport->load_flag & FC_UNLOADING))
5383 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
5384 "(%d):0111 Dropping received ELS cmd "
5385 "Data: x%x x%x x%x\n",
5386 vport->vpi, icmd->ulpStatus,
5387 icmd->un.ulpWord[4], icmd->ulpTimeout);
5388 phba->fc_stat.elsRcvDrop++;
5392 * lpfc_find_vport_by_vpid: Find a vport on a HBA through vport identifier.
5393 * @phba: pointer to lpfc hba data structure.
5394 * @vpi: host virtual N_Port identifier.
5396 * This routine finds a vport on a HBA (referred by @phba) through a
5397 * @vpi. The function walks the HBA's vport list and returns the address
5398 * of the vport with the matching @vpi.
5401 * NULL - No vport with the matching @vpi found
5402 * Otherwise - Address to the vport with the matching @vpi.
5404 static struct lpfc_vport *
5405 lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi)
5407 struct lpfc_vport *vport;
5408 unsigned long flags;
5410 spin_lock_irqsave(&phba->hbalock, flags);
5411 list_for_each_entry(vport, &phba->port_list, listentry) {
5412 if (vport->vpi == vpi) {
5413 spin_unlock_irqrestore(&phba->hbalock, flags);
5417 spin_unlock_irqrestore(&phba->hbalock, flags);
5422 * lpfc_els_unsol_event: Process an unsolicited event from an els sli ring.
5423 * @phba: pointer to lpfc hba data structure.
5424 * @pring: pointer to a SLI ring.
5425 * @elsiocb: pointer to lpfc els iocb data structure.
5427 * This routine is used to process an unsolicited event received from a SLI
5428 * (Service Level Interface) ring. The actual processing of the data buffer
5429 * associated with the unsolicited event is done by invoking the routine
5430 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
5431 * SLI ring on which the unsolicited event was received.
5434 lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
5435 struct lpfc_iocbq *elsiocb)
5437 struct lpfc_vport *vport = phba->pport;
5438 IOCB_t *icmd = &elsiocb->iocb;
5440 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
5441 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
5443 elsiocb->context1 = NULL;
5444 elsiocb->context2 = NULL;
5445 elsiocb->context3 = NULL;
5447 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
5448 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
5449 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
5450 (icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING) {
5451 phba->fc_stat.NoRcvBuf++;
5452 /* Not enough posted buffers; Try posting more buffers */
5453 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
5454 lpfc_post_buffer(phba, pring, 0);
5458 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
5459 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
5460 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
5461 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
5462 vport = phba->pport;
5464 uint16_t vpi = icmd->unsli3.rcvsli3.vpi;
5465 vport = lpfc_find_vport_by_vpid(phba, vpi);
5468 /* If there are no BDEs associated
5469 * with this IOCB, there is nothing to do.
5471 if (icmd->ulpBdeCount == 0)
5474 /* type of ELS cmd is first 32bit word
5477 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
5478 elsiocb->context2 = bdeBuf1;
5480 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
5481 icmd->un.cont64[0].addrLow);
5482 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
5486 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
5488 * The different unsolicited event handlers would tell us
5489 * if they are done with "mp" by setting context2 to NULL.
5491 if (elsiocb->context2) {
5492 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
5493 elsiocb->context2 = NULL;
5496 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
5497 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
5498 icmd->ulpBdeCount == 2) {
5499 elsiocb->context2 = bdeBuf2;
5500 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
5501 /* free mp if we are done with it */
5502 if (elsiocb->context2) {
5503 lpfc_in_buf_free(phba, elsiocb->context2);
5504 elsiocb->context2 = NULL;
5510 * lpfc_do_scr_ns_plogi: Issue a plogi to the name server for scr.
5511 * @phba: pointer to lpfc hba data structure.
5512 * @vport: pointer to a virtual N_Port data structure.
5514 * This routine issues a Port Login (PLOGI) to the Name Server with
5515 * State Change Request (SCR) for a @vport. This routine will create an
5516 * ndlp for the Name Server associated to the @vport if such node does
5517 * not already exist. The PLOGI to Name Server is issued by invoking the
5518 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
5519 * (FDMI) is configured to the @vport, a FDMI node will be created and
5520 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
5523 lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
5525 struct lpfc_nodelist *ndlp, *ndlp_fdmi;
5527 ndlp = lpfc_findnode_did(vport, NameServer_DID);
5529 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
5531 if (phba->fc_topology == TOPOLOGY_LOOP) {
5532 lpfc_disc_start(vport);
5535 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
5536 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5537 "0251 NameServer login: no memory\n");
5540 lpfc_nlp_init(vport, ndlp, NameServer_DID);
5541 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
5542 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
5544 if (phba->fc_topology == TOPOLOGY_LOOP) {
5545 lpfc_disc_start(vport);
5548 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
5549 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5550 "0348 NameServer login: node freed\n");
5554 ndlp->nlp_type |= NLP_FABRIC;
5556 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
5558 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
5559 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
5560 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5561 "0252 Cannot issue NameServer login\n");
5565 if (vport->cfg_fdmi_on) {
5566 ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
5569 lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID);
5570 ndlp_fdmi->nlp_type |= NLP_FABRIC;
5571 lpfc_nlp_set_state(vport, ndlp_fdmi,
5572 NLP_STE_PLOGI_ISSUE);
5573 lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID,
5581 * lpfc_cmpl_reg_new_vport: Completion callback function to register new vport.
5582 * @phba: pointer to lpfc hba data structure.
5583 * @pmb: pointer to the driver internal queue element for mailbox command.
5585 * This routine is the completion callback function to register new vport
5586 * mailbox command. If the new vport mailbox command completes successfully,
5587 * the fabric registration login shall be performed on physical port (the
5588 * new vport created is actually a physical port, with VPI 0) or the port
5589 * login to Name Server for State Change Request (SCR) will be performed
5590 * on virtual port (real virtual port, with VPI greater than 0).
5593 lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
5595 struct lpfc_vport *vport = pmb->vport;
5596 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5597 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
5598 MAILBOX_t *mb = &pmb->mb;
5600 spin_lock_irq(shost->host_lock);
5601 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
5602 spin_unlock_irq(shost->host_lock);
5604 if (mb->mbxStatus) {
5605 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
5606 "0915 Register VPI failed: 0x%x\n",
5609 switch (mb->mbxStatus) {
5610 case 0x11: /* unsupported feature */
5611 case 0x9603: /* max_vpi exceeded */
5612 case 0x9602: /* Link event since CLEAR_LA */
5613 /* giving up on vport registration */
5614 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
5615 spin_lock_irq(shost->host_lock);
5616 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
5617 spin_unlock_irq(shost->host_lock);
5618 lpfc_can_disctmo(vport);
5621 /* Try to recover from this error */
5622 lpfc_mbx_unreg_vpi(vport);
5623 spin_lock_irq(shost->host_lock);
5624 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
5625 spin_unlock_irq(shost->host_lock);
5626 if (vport->port_type == LPFC_PHYSICAL_PORT)
5627 lpfc_initial_flogi(vport);
5629 lpfc_initial_fdisc(vport);
5634 if (vport == phba->pport)
5635 lpfc_issue_fabric_reglogin(vport);
5637 lpfc_do_scr_ns_plogi(phba, vport);
5640 /* Now, we decrement the ndlp reference count held for this
5645 mempool_free(pmb, phba->mbox_mem_pool);
5650 * lpfc_register_new_vport: Register a new vport with a HBA.
5651 * @phba: pointer to lpfc hba data structure.
5652 * @vport: pointer to a host virtual N_Port data structure.
5653 * @ndlp: pointer to a node-list data structure.
5655 * This routine registers the @vport as a new virtual port with a HBA.
5656 * It is done through a registering vpi mailbox command.
5659 lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
5660 struct lpfc_nodelist *ndlp)
5662 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5665 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5667 lpfc_reg_vpi(phba, vport->vpi, vport->fc_myDID, mbox);
5668 mbox->vport = vport;
5669 mbox->context2 = lpfc_nlp_get(ndlp);
5670 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
5671 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
5672 == MBX_NOT_FINISHED) {
5673 /* mailbox command not success, decrement ndlp
5674 * reference count for this command
5677 mempool_free(mbox, phba->mbox_mem_pool);
5679 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
5680 "0253 Register VPI: Can't send mbox\n");
5684 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
5685 "0254 Register VPI: no memory\n");
5691 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
5692 spin_lock_irq(shost->host_lock);
5693 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
5694 spin_unlock_irq(shost->host_lock);
5699 * lpfc_cmpl_els_fdisc: Completion function for fdisc iocb command.
5700 * @phba: pointer to lpfc hba data structure.
5701 * @cmdiocb: pointer to lpfc command iocb data structure.
5702 * @rspiocb: pointer to lpfc response iocb data structure.
5704 * This routine is the completion callback function to a Fabric Discover
5705 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
5706 * single threaded, each FDISC completion callback function will reset
5707 * the discovery timer for all vports such that the timers will not get
5708 * unnecessary timeout. The function checks the FDISC IOCB status. If error
5709 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
5710 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
5711 * assigned to the vport has been changed with the completion of the FDISC
5712 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
5713 * are unregistered from the HBA, and then the lpfc_register_new_vport()
5714 * routine is invoked to register new vport with the HBA. Otherwise, the
5715 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
5716 * Server for State Change Request (SCR).
5719 lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
5720 struct lpfc_iocbq *rspiocb)
5722 struct lpfc_vport *vport = cmdiocb->vport;
5723 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5724 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
5725 struct lpfc_nodelist *np;
5726 struct lpfc_nodelist *next_np;
5727 IOCB_t *irsp = &rspiocb->iocb;
5728 struct lpfc_iocbq *piocb;
5730 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5731 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
5732 irsp->ulpStatus, irsp->un.ulpWord[4],
5734 /* Since all FDISCs are being single threaded, we
5735 * must reset the discovery timer for ALL vports
5736 * waiting to send FDISC when one completes.
5738 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
5739 lpfc_set_disctmo(piocb->vport);
5742 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
5743 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
5744 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
5746 if (irsp->ulpStatus) {
5747 /* Check for retry */
5748 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
5751 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5752 "0126 FDISC failed. (%d/%d)\n",
5753 irsp->ulpStatus, irsp->un.ulpWord[4]);
5756 if (vport->fc_vport->vport_state == FC_VPORT_INITIALIZING)
5757 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
5759 /* giving up on FDISC. Cancel discovery timer */
5760 lpfc_can_disctmo(vport);
5761 spin_lock_irq(shost->host_lock);
5762 vport->fc_flag |= FC_FABRIC;
5763 if (vport->phba->fc_topology == TOPOLOGY_LOOP)
5764 vport->fc_flag |= FC_PUBLIC_LOOP;
5765 spin_unlock_irq(shost->host_lock);
5767 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
5768 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
5769 if ((vport->fc_prevDID != vport->fc_myDID) &&
5770 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
5771 /* If our NportID changed, we need to ensure all
5772 * remaining NPORTs get unreg_login'ed so we can
5775 list_for_each_entry_safe(np, next_np,
5776 &vport->fc_nodes, nlp_listp) {
5777 if (!NLP_CHK_NODE_ACT(ndlp) ||
5778 (np->nlp_state != NLP_STE_NPR_NODE) ||
5779 !(np->nlp_flag & NLP_NPR_ADISC))
5781 spin_lock_irq(shost->host_lock);
5782 np->nlp_flag &= ~NLP_NPR_ADISC;
5783 spin_unlock_irq(shost->host_lock);
5784 lpfc_unreg_rpi(vport, np);
5786 lpfc_mbx_unreg_vpi(vport);
5787 spin_lock_irq(shost->host_lock);
5788 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
5789 spin_unlock_irq(shost->host_lock);
5792 if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
5793 lpfc_register_new_vport(phba, vport, ndlp);
5795 lpfc_do_scr_ns_plogi(phba, vport);
5798 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
5799 /* Cancel discovery timer */
5800 lpfc_can_disctmo(vport);
5803 lpfc_els_free_iocb(phba, cmdiocb);
5807 * lpfc_issue_els_fdisc: Issue a fdisc iocb command.
5808 * @vport: pointer to a virtual N_Port data structure.
5809 * @ndlp: pointer to a node-list data structure.
5810 * @retry: number of retries to the command IOCB.
5812 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
5813 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
5814 * routine to issue the IOCB, which makes sure only one outstanding fabric
5815 * IOCB will be sent off HBA at any given time.
5817 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5818 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5819 * will be stored into the context1 field of the IOCB for the completion
5820 * callback function to the FDISC ELS command.
5823 * 0 - Successfully issued fdisc iocb command
5824 * 1 - Failed to issue fdisc iocb command
5827 lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
5830 struct lpfc_hba *phba = vport->phba;
5832 struct lpfc_iocbq *elsiocb;
5833 struct serv_parm *sp;
5836 int did = ndlp->nlp_DID;
5839 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
5840 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
5843 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
5844 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5845 "0255 Issue FDISC: no IOCB\n");
5849 icmd = &elsiocb->iocb;
5850 icmd->un.elsreq64.myID = 0;
5851 icmd->un.elsreq64.fl = 1;
5853 /* For FDISC, Let FDISC rsp set the NPortID for this VPI */
5857 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5858 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
5859 pcmd += sizeof(uint32_t); /* CSP Word 1 */
5860 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
5861 sp = (struct serv_parm *) pcmd;
5862 /* Setup CSPs accordingly for Fabric */
5863 sp->cmn.e_d_tov = 0;
5864 sp->cmn.w2.r_a_tov = 0;
5865 sp->cls1.classValid = 0;
5866 sp->cls2.seqDelivery = 1;
5867 sp->cls3.seqDelivery = 1;
5869 pcmd += sizeof(uint32_t); /* CSP Word 2 */
5870 pcmd += sizeof(uint32_t); /* CSP Word 3 */
5871 pcmd += sizeof(uint32_t); /* CSP Word 4 */
5872 pcmd += sizeof(uint32_t); /* Port Name */
5873 memcpy(pcmd, &vport->fc_portname, 8);
5874 pcmd += sizeof(uint32_t); /* Node Name */
5875 pcmd += sizeof(uint32_t); /* Node Name */
5876 memcpy(pcmd, &vport->fc_nodename, 8);
5878 lpfc_set_disctmo(vport);
5880 phba->fc_stat.elsXmitFDISC++;
5881 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
5883 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
5884 "Issue FDISC: did:x%x",
5887 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
5888 if (rc == IOCB_ERROR) {
5889 lpfc_els_free_iocb(phba, elsiocb);
5890 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
5891 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5892 "0256 Issue FDISC: Cannot send IOCB\n");
5895 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
5896 vport->port_state = LPFC_FDISC;
5901 * lpfc_cmpl_els_npiv_logo: Completion function with vport logo.
5902 * @phba: pointer to lpfc hba data structure.
5903 * @cmdiocb: pointer to lpfc command iocb data structure.
5904 * @rspiocb: pointer to lpfc response iocb data structure.
5906 * This routine is the completion callback function to the issuing of a LOGO
5907 * ELS command off a vport. It frees the command IOCB and then decrement the
5908 * reference count held on ndlp for this completion function, indicating that
5909 * the reference to the ndlp is no long needed. Note that the
5910 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
5911 * callback function and an additional explicit ndlp reference decrementation
5912 * will trigger the actual release of the ndlp.
5915 lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
5916 struct lpfc_iocbq *rspiocb)
5918 struct lpfc_vport *vport = cmdiocb->vport;
5920 struct lpfc_nodelist *ndlp;
5921 ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
5923 irsp = &rspiocb->iocb;
5924 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
5925 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
5926 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
5928 lpfc_els_free_iocb(phba, cmdiocb);
5929 vport->unreg_vpi_cmpl = VPORT_ERROR;
5931 /* Trigger the release of the ndlp after logo */
5936 * lpfc_issue_els_npiv_logo: Issue a logo off a vport.
5937 * @vport: pointer to a virtual N_Port data structure.
5938 * @ndlp: pointer to a node-list data structure.
5940 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
5942 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5943 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5944 * will be stored into the context1 field of the IOCB for the completion
5945 * callback function to the LOGO ELS command.
5948 * 0 - Successfully issued logo off the @vport
5949 * 1 - Failed to issue logo off the @vport
5952 lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
5954 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5955 struct lpfc_hba *phba = vport->phba;
5956 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
5958 struct lpfc_iocbq *elsiocb;
5962 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
5963 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
5968 icmd = &elsiocb->iocb;
5969 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5970 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
5971 pcmd += sizeof(uint32_t);
5973 /* Fill in LOGO payload */
5974 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
5975 pcmd += sizeof(uint32_t);
5976 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
5978 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
5979 "Issue LOGO npiv did:x%x flg:x%x",
5980 ndlp->nlp_DID, ndlp->nlp_flag, 0);
5982 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
5983 spin_lock_irq(shost->host_lock);
5984 ndlp->nlp_flag |= NLP_LOGO_SND;
5985 spin_unlock_irq(shost->host_lock);
5986 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
5987 spin_lock_irq(shost->host_lock);
5988 ndlp->nlp_flag &= ~NLP_LOGO_SND;
5989 spin_unlock_irq(shost->host_lock);
5990 lpfc_els_free_iocb(phba, elsiocb);
5997 * lpfc_fabric_block_timeout: Handler function to the fabric block timer.
5998 * @ptr: holder for the timer function associated data.
6000 * This routine is invoked by the fabric iocb block timer after
6001 * timeout. It posts the fabric iocb block timeout event by setting the
6002 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
6003 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
6004 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
6005 * posted event WORKER_FABRIC_BLOCK_TMO.
6008 lpfc_fabric_block_timeout(unsigned long ptr)
6010 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
6011 unsigned long iflags;
6012 uint32_t tmo_posted;
6014 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
6015 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
6017 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
6018 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
6021 lpfc_worker_wake_up(phba);
6026 * lpfc_resume_fabric_iocbs: Issue a fabric iocb from driver internal list.
6027 * @phba: pointer to lpfc hba data structure.
6029 * This routine issues one fabric iocb from the driver internal list to
6030 * the HBA. It first checks whether it's ready to issue one fabric iocb to
6031 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
6032 * remove one pending fabric iocb from the driver internal list and invokes
6033 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
6036 lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
6038 struct lpfc_iocbq *iocb;
6039 unsigned long iflags;
6041 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
6046 spin_lock_irqsave(&phba->hbalock, iflags);
6047 /* Post any pending iocb to the SLI layer */
6048 if (atomic_read(&phba->fabric_iocb_count) == 0) {
6049 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
6052 /* Increment fabric iocb count to hold the position */
6053 atomic_inc(&phba->fabric_iocb_count);
6055 spin_unlock_irqrestore(&phba->hbalock, iflags);
6057 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
6058 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
6059 iocb->iocb_flag |= LPFC_IO_FABRIC;
6061 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
6062 "Fabric sched1: ste:x%x",
6063 iocb->vport->port_state, 0, 0);
6065 ret = lpfc_sli_issue_iocb(phba, pring, iocb, 0);
6067 if (ret == IOCB_ERROR) {
6068 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
6069 iocb->fabric_iocb_cmpl = NULL;
6070 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
6072 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
6073 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
6074 iocb->iocb_cmpl(phba, iocb, iocb);
6076 atomic_dec(&phba->fabric_iocb_count);
6085 * lpfc_unblock_fabric_iocbs: Unblock issuing fabric iocb command.
6086 * @phba: pointer to lpfc hba data structure.
6088 * This routine unblocks the issuing fabric iocb command. The function
6089 * will clear the fabric iocb block bit and then invoke the routine
6090 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
6091 * from the driver internal fabric iocb list.
6094 lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
6096 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
6098 lpfc_resume_fabric_iocbs(phba);
6103 * lpfc_block_fabric_iocbs: Block issuing fabric iocb command.
6104 * @phba: pointer to lpfc hba data structure.
6106 * This routine blocks the issuing fabric iocb for a specified amount of
6107 * time (currently 100 ms). This is done by set the fabric iocb block bit
6108 * and set up a timeout timer for 100ms. When the block bit is set, no more
6109 * fabric iocb will be issued out of the HBA.
6112 lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
6116 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
6117 /* Start a timer to unblock fabric iocbs after 100ms */
6119 mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 );
6125 * lpfc_cmpl_fabric_iocb: Completion callback function for fabric iocb.
6126 * @phba: pointer to lpfc hba data structure.
6127 * @cmdiocb: pointer to lpfc command iocb data structure.
6128 * @rspiocb: pointer to lpfc response iocb data structure.
6130 * This routine is the callback function that is put to the fabric iocb's
6131 * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
6132 * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
6133 * function first restores and invokes the original iocb's callback function
6134 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
6135 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
6138 lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
6139 struct lpfc_iocbq *rspiocb)
6143 if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC)
6146 switch (rspiocb->iocb.ulpStatus) {
6147 case IOSTAT_NPORT_RJT:
6148 case IOSTAT_FABRIC_RJT:
6149 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
6150 lpfc_block_fabric_iocbs(phba);
6154 case IOSTAT_NPORT_BSY:
6155 case IOSTAT_FABRIC_BSY:
6156 lpfc_block_fabric_iocbs(phba);
6160 stat.un.lsRjtError =
6161 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
6162 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
6163 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
6164 lpfc_block_fabric_iocbs(phba);
6168 if (atomic_read(&phba->fabric_iocb_count) == 0)
6171 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
6172 cmdiocb->fabric_iocb_cmpl = NULL;
6173 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
6174 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
6176 atomic_dec(&phba->fabric_iocb_count);
6177 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
6178 /* Post any pending iocbs to HBA */
6179 lpfc_resume_fabric_iocbs(phba);
6184 * lpfc_issue_fabric_iocb: Issue a fabric iocb command.
6185 * @phba: pointer to lpfc hba data structure.
6186 * @iocb: pointer to lpfc command iocb data structure.
6188 * This routine is used as the top-level API for issuing a fabric iocb command
6189 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
6190 * function makes sure that only one fabric bound iocb will be outstanding at
6191 * any given time. As such, this function will first check to see whether there
6192 * is already an outstanding fabric iocb on the wire. If so, it will put the
6193 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
6194 * issued later. Otherwise, it will issue the iocb on the wire and update the
6195 * fabric iocb count it indicate that there is one fabric iocb on the wire.
6197 * Note, this implementation has a potential sending out fabric IOCBs out of
6198 * order. The problem is caused by the construction of the "ready" boolen does
6199 * not include the condition that the internal fabric IOCB list is empty. As
6200 * such, it is possible a fabric IOCB issued by this routine might be "jump"
6201 * ahead of the fabric IOCBs in the internal list.
6204 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
6205 * IOCB_ERROR - failed to issue fabric iocb
6208 lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
6210 unsigned long iflags;
6211 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
6215 if (atomic_read(&phba->fabric_iocb_count) > 1)
6218 spin_lock_irqsave(&phba->hbalock, iflags);
6219 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
6220 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
6223 /* Increment fabric iocb count to hold the position */
6224 atomic_inc(&phba->fabric_iocb_count);
6225 spin_unlock_irqrestore(&phba->hbalock, iflags);
6227 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
6228 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
6229 iocb->iocb_flag |= LPFC_IO_FABRIC;
6231 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
6232 "Fabric sched2: ste:x%x",
6233 iocb->vport->port_state, 0, 0);
6235 ret = lpfc_sli_issue_iocb(phba, pring, iocb, 0);
6237 if (ret == IOCB_ERROR) {
6238 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
6239 iocb->fabric_iocb_cmpl = NULL;
6240 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
6241 atomic_dec(&phba->fabric_iocb_count);
6244 spin_lock_irqsave(&phba->hbalock, iflags);
6245 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
6246 spin_unlock_irqrestore(&phba->hbalock, iflags);
6253 * lpfc_fabric_abort_vport: Abort a vport's iocbs from driver fabric iocb list.
6254 * @vport: pointer to a virtual N_Port data structure.
6256 * This routine aborts all the IOCBs associated with a @vport from the
6257 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
6258 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
6259 * list, removes each IOCB associated with the @vport off the list, set the
6260 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
6261 * associated with the IOCB.
6263 static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
6265 LIST_HEAD(completions);
6266 struct lpfc_hba *phba = vport->phba;
6267 struct lpfc_iocbq *tmp_iocb, *piocb;
6270 spin_lock_irq(&phba->hbalock);
6271 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
6274 if (piocb->vport != vport)
6277 list_move_tail(&piocb->list, &completions);
6279 spin_unlock_irq(&phba->hbalock);
6281 while (!list_empty(&completions)) {
6282 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
6283 list_del_init(&piocb->list);
6286 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
6287 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
6288 (piocb->iocb_cmpl) (phba, piocb, piocb);
6293 * lpfc_fabric_abort_nport: Abort a ndlp's iocbs from driver fabric iocb list.
6294 * @ndlp: pointer to a node-list data structure.
6296 * This routine aborts all the IOCBs associated with an @ndlp from the
6297 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
6298 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
6299 * list, removes each IOCB associated with the @ndlp off the list, set the
6300 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
6301 * associated with the IOCB.
6303 void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
6305 LIST_HEAD(completions);
6306 struct lpfc_hba *phba = ndlp->vport->phba;
6307 struct lpfc_iocbq *tmp_iocb, *piocb;
6308 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
6311 spin_lock_irq(&phba->hbalock);
6312 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
6314 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
6316 list_move_tail(&piocb->list, &completions);
6319 spin_unlock_irq(&phba->hbalock);
6321 while (!list_empty(&completions)) {
6322 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
6323 list_del_init(&piocb->list);
6326 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
6327 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
6328 (piocb->iocb_cmpl) (phba, piocb, piocb);
6333 * lpfc_fabric_abort_hba: Abort all iocbs on driver fabric iocb list.
6334 * @phba: pointer to lpfc hba data structure.
6336 * This routine aborts all the IOCBs currently on the driver internal
6337 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
6338 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
6339 * list, removes IOCBs off the list, set the status feild to
6340 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
6343 void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
6345 LIST_HEAD(completions);
6346 struct lpfc_iocbq *piocb;
6349 spin_lock_irq(&phba->hbalock);
6350 list_splice_init(&phba->fabric_iocb_list, &completions);
6351 spin_unlock_irq(&phba->hbalock);
6353 while (!list_empty(&completions)) {
6354 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
6355 list_del_init(&piocb->list);
6358 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
6359 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
6360 (piocb->iocb_cmpl) (phba, piocb, piocb);