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>
34 #include "lpfc_disc.h"
35 #include "lpfc_scsi.h"
37 #include "lpfc_logmsg.h"
38 #include "lpfc_crtn.h"
39 #include "lpfc_vport.h"
40 #include "lpfc_debugfs.h"
42 static int lpfc_els_retry(struct lpfc_hba *, struct lpfc_iocbq *,
44 static void lpfc_cmpl_fabric_iocb(struct lpfc_hba *, struct lpfc_iocbq *,
46 static void lpfc_fabric_abort_vport(struct lpfc_vport *vport);
47 static int lpfc_issue_els_fdisc(struct lpfc_vport *vport,
48 struct lpfc_nodelist *ndlp, uint8_t retry);
49 static int lpfc_issue_fabric_iocb(struct lpfc_hba *phba,
50 struct lpfc_iocbq *iocb);
51 static void lpfc_register_new_vport(struct lpfc_hba *phba,
52 struct lpfc_vport *vport,
53 struct lpfc_nodelist *ndlp);
55 static int lpfc_max_els_tries = 3;
58 * lpfc_els_chk_latt: Check host link attention event for a vport.
59 * @vport: pointer to a host virtual N_Port data structure.
61 * This routine checks whether there is an outstanding host link
62 * attention event during the discovery process with the @vport. It is done
63 * by reading the HBA's Host Attention (HA) register. If there is any host
64 * link attention events during this @vport's discovery process, the @vport
65 * shall be marked as FC_ABORT_DISCOVERY, a host link attention clear shall
66 * be issued if the link state is not already in host link cleared state,
67 * and a return code shall indicate whether the host link attention event
70 * Note that, if either the host link is in state LPFC_LINK_DOWN or @vport
71 * state in LPFC_VPORT_READY, the request for checking host link attention
72 * event will be ignored and a return code shall indicate no host link
73 * attention event had happened.
76 * 0 - no host link attention event happened
77 * 1 - host link attention event happened
80 lpfc_els_chk_latt(struct lpfc_vport *vport)
82 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
83 struct lpfc_hba *phba = vport->phba;
86 if (vport->port_state >= LPFC_VPORT_READY ||
87 phba->link_state == LPFC_LINK_DOWN)
90 /* Read the HBA Host Attention Register */
91 ha_copy = readl(phba->HAregaddr);
93 if (!(ha_copy & HA_LATT))
96 /* Pending Link Event during Discovery */
97 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
98 "0237 Pending Link Event during "
99 "Discovery: State x%x\n",
100 phba->pport->port_state);
102 /* CLEAR_LA should re-enable link attention events and
103 * we should then imediately take a LATT event. The
104 * LATT processing should call lpfc_linkdown() which
105 * will cleanup any left over in-progress discovery
108 spin_lock_irq(shost->host_lock);
109 vport->fc_flag |= FC_ABORT_DISCOVERY;
110 spin_unlock_irq(shost->host_lock);
112 if (phba->link_state != LPFC_CLEAR_LA)
113 lpfc_issue_clear_la(phba, vport);
119 * lpfc_prep_els_iocb: Allocate and prepare a lpfc iocb data structure.
120 * @vport: pointer to a host virtual N_Port data structure.
121 * @expectRsp: flag indicating whether response is expected.
122 * @cmdSize: size of the ELS command.
123 * @retry: number of retries to the command IOCB when it fails.
124 * @ndlp: pointer to a node-list data structure.
125 * @did: destination identifier.
126 * @elscmd: the ELS command code.
128 * This routine is used for allocating a lpfc-IOCB data structure from
129 * the driver lpfc-IOCB free-list and prepare the IOCB with the parameters
130 * passed into the routine for discovery state machine to issue an Extended
131 * Link Service (ELS) commands. It is a generic lpfc-IOCB allocation
132 * and preparation routine that is used by all the discovery state machine
133 * routines and the ELS command-specific fields will be later set up by
134 * the individual discovery machine routines after calling this routine
135 * allocating and preparing a generic IOCB data structure. It fills in the
136 * Buffer Descriptor Entries (BDEs), allocates buffers for both command
137 * payload and response payload (if expected). The reference count on the
138 * ndlp is incremented by 1 and the reference to the ndlp is put into
139 * context1 of the IOCB data structure for this IOCB to hold the ndlp
140 * reference for the command's callback function to access later.
143 * Pointer to the newly allocated/prepared els iocb data structure
144 * NULL - when els iocb data structure allocation/preparation failed
146 static struct lpfc_iocbq *
147 lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp,
148 uint16_t cmdSize, uint8_t retry,
149 struct lpfc_nodelist *ndlp, uint32_t did,
152 struct lpfc_hba *phba = vport->phba;
153 struct lpfc_iocbq *elsiocb;
154 struct lpfc_dmabuf *pcmd, *prsp, *pbuflist;
155 struct ulp_bde64 *bpl;
159 if (!lpfc_is_link_up(phba))
162 /* Allocate buffer for command iocb */
163 elsiocb = lpfc_sli_get_iocbq(phba);
168 icmd = &elsiocb->iocb;
170 /* fill in BDEs for command */
171 /* Allocate buffer for command payload */
172 pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
174 pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys);
175 if (!pcmd || !pcmd->virt)
176 goto els_iocb_free_pcmb_exit;
178 INIT_LIST_HEAD(&pcmd->list);
180 /* Allocate buffer for response payload */
182 prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
184 prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
186 if (!prsp || !prsp->virt)
187 goto els_iocb_free_prsp_exit;
188 INIT_LIST_HEAD(&prsp->list);
192 /* Allocate buffer for Buffer ptr list */
193 pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
195 pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
197 if (!pbuflist || !pbuflist->virt)
198 goto els_iocb_free_pbuf_exit;
200 INIT_LIST_HEAD(&pbuflist->list);
202 icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
203 icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
204 icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
205 icmd->un.elsreq64.remoteID = did; /* DID */
207 icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64));
208 icmd->ulpCommand = CMD_ELS_REQUEST64_CR;
209 icmd->ulpTimeout = phba->fc_ratov * 2;
211 icmd->un.elsreq64.bdl.bdeSize = sizeof(struct ulp_bde64);
212 icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX;
214 icmd->ulpBdeCount = 1;
216 icmd->ulpClass = CLASS3;
218 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
219 icmd->un.elsreq64.myID = vport->fc_myDID;
221 /* For ELS_REQUEST64_CR, use the VPI by default */
222 icmd->ulpContext = vport->vpi;
224 /* The CT field must be 0=INVALID_RPI for the ECHO cmd */
225 if (elscmd == ELS_CMD_ECHO)
226 icmd->ulpCt_l = 0; /* context = invalid RPI */
228 icmd->ulpCt_l = 1; /* context = VPI */
231 bpl = (struct ulp_bde64 *) pbuflist->virt;
232 bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys));
233 bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys));
234 bpl->tus.f.bdeSize = cmdSize;
235 bpl->tus.f.bdeFlags = 0;
236 bpl->tus.w = le32_to_cpu(bpl->tus.w);
240 bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys));
241 bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys));
242 bpl->tus.f.bdeSize = FCELSSIZE;
243 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
244 bpl->tus.w = le32_to_cpu(bpl->tus.w);
247 /* prevent preparing iocb with NULL ndlp reference */
248 elsiocb->context1 = lpfc_nlp_get(ndlp);
249 if (!elsiocb->context1)
250 goto els_iocb_free_pbuf_exit;
251 elsiocb->context2 = pcmd;
252 elsiocb->context3 = pbuflist;
253 elsiocb->retry = retry;
254 elsiocb->vport = vport;
255 elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT;
258 list_add(&prsp->list, &pcmd->list);
261 /* Xmit ELS command <elsCmd> to remote NPORT <did> */
262 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
263 "0116 Xmit ELS command x%x to remote "
264 "NPORT x%x I/O tag: x%x, port state: x%x\n",
265 elscmd, did, elsiocb->iotag,
268 /* Xmit ELS response <elsCmd> to remote NPORT <did> */
269 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
270 "0117 Xmit ELS response x%x to remote "
271 "NPORT x%x I/O tag: x%x, size: x%x\n",
272 elscmd, ndlp->nlp_DID, elsiocb->iotag,
277 els_iocb_free_pbuf_exit:
279 lpfc_mbuf_free(phba, prsp->virt, prsp->phys);
282 els_iocb_free_prsp_exit:
283 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
286 els_iocb_free_pcmb_exit:
288 lpfc_sli_release_iocbq(phba, elsiocb);
293 * lpfc_issue_fabric_reglogin: Issue fabric registration login for a vport.
294 * @vport: pointer to a host virtual N_Port data structure.
296 * This routine issues a fabric registration login for a @vport. An
297 * active ndlp node with Fabric_DID must already exist for this @vport.
298 * The routine invokes two mailbox commands to carry out fabric registration
299 * login through the HBA firmware: the first mailbox command requests the
300 * HBA to perform link configuration for the @vport; and the second mailbox
301 * command requests the HBA to perform the actual fabric registration login
305 * 0 - successfully issued fabric registration login for @vport
306 * -ENXIO -- failed to issue fabric registration login for @vport
309 lpfc_issue_fabric_reglogin(struct lpfc_vport *vport)
311 struct lpfc_hba *phba = vport->phba;
313 struct lpfc_dmabuf *mp;
314 struct lpfc_nodelist *ndlp;
315 struct serv_parm *sp;
319 sp = &phba->fc_fabparam;
320 ndlp = lpfc_findnode_did(vport, Fabric_DID);
321 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
326 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
332 vport->port_state = LPFC_FABRIC_CFG_LINK;
333 lpfc_config_link(phba, mbox);
334 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
337 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
338 if (rc == MBX_NOT_FINISHED) {
343 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
348 rc = lpfc_reg_login(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox,
355 mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login;
357 /* increment the reference count on ndlp to hold reference
358 * for the callback routine.
360 mbox->context2 = lpfc_nlp_get(ndlp);
362 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
363 if (rc == MBX_NOT_FINISHED) {
365 goto fail_issue_reg_login;
370 fail_issue_reg_login:
371 /* decrement the reference count on ndlp just incremented
372 * for the failed mbox command.
375 mp = (struct lpfc_dmabuf *) mbox->context1;
376 lpfc_mbuf_free(phba, mp->virt, mp->phys);
379 mempool_free(mbox, phba->mbox_mem_pool);
382 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
383 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
384 "0249 Cannot issue Register Fabric login: Err %d\n", err);
389 * lpfc_cmpl_els_flogi_fabric: Completion function for flogi to a fabric port.
390 * @vport: pointer to a host virtual N_Port data structure.
391 * @ndlp: pointer to a node-list data structure.
392 * @sp: pointer to service parameter data structure.
393 * @irsp: pointer to the IOCB within the lpfc response IOCB.
395 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
396 * function to handle the completion of a Fabric Login (FLOGI) into a fabric
397 * port in a fabric topology. It properly sets up the parameters to the @ndlp
398 * from the IOCB response. It also check the newly assigned N_Port ID to the
399 * @vport against the previously assigned N_Port ID. If it is different from
400 * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine
401 * is invoked on all the remaining nodes with the @vport to unregister the
402 * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin()
403 * is invoked to register login to the fabric.
406 * 0 - Success (currently, always return 0)
409 lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
410 struct serv_parm *sp, IOCB_t *irsp)
412 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
413 struct lpfc_hba *phba = vport->phba;
414 struct lpfc_nodelist *np;
415 struct lpfc_nodelist *next_np;
417 spin_lock_irq(shost->host_lock);
418 vport->fc_flag |= FC_FABRIC;
419 spin_unlock_irq(shost->host_lock);
421 phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
422 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
423 phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
425 phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
427 if (phba->fc_topology == TOPOLOGY_LOOP) {
428 spin_lock_irq(shost->host_lock);
429 vport->fc_flag |= FC_PUBLIC_LOOP;
430 spin_unlock_irq(shost->host_lock);
433 * If we are a N-port connected to a Fabric, fixup sparam's so
434 * logins to devices on remote loops work.
436 vport->fc_sparam.cmn.altBbCredit = 1;
439 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
440 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
441 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name));
442 ndlp->nlp_class_sup = 0;
443 if (sp->cls1.classValid)
444 ndlp->nlp_class_sup |= FC_COS_CLASS1;
445 if (sp->cls2.classValid)
446 ndlp->nlp_class_sup |= FC_COS_CLASS2;
447 if (sp->cls3.classValid)
448 ndlp->nlp_class_sup |= FC_COS_CLASS3;
449 if (sp->cls4.classValid)
450 ndlp->nlp_class_sup |= FC_COS_CLASS4;
451 ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
452 sp->cmn.bbRcvSizeLsb;
453 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
455 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
456 if (sp->cmn.response_multiple_NPort) {
457 lpfc_printf_vlog(vport, KERN_WARNING,
459 "1816 FLOGI NPIV supported, "
460 "response data 0x%x\n",
461 sp->cmn.response_multiple_NPort);
462 phba->link_flag |= LS_NPIV_FAB_SUPPORTED;
464 /* Because we asked f/w for NPIV it still expects us
465 to call reg_vnpid atleast for the physcial host */
466 lpfc_printf_vlog(vport, KERN_WARNING,
468 "1817 Fabric does not support NPIV "
469 "- configuring single port mode.\n");
470 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
474 if ((vport->fc_prevDID != vport->fc_myDID) &&
475 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
477 /* If our NportID changed, we need to ensure all
478 * remaining NPORTs get unreg_login'ed.
480 list_for_each_entry_safe(np, next_np,
481 &vport->fc_nodes, nlp_listp) {
482 if (!NLP_CHK_NODE_ACT(np))
484 if ((np->nlp_state != NLP_STE_NPR_NODE) ||
485 !(np->nlp_flag & NLP_NPR_ADISC))
487 spin_lock_irq(shost->host_lock);
488 np->nlp_flag &= ~NLP_NPR_ADISC;
489 spin_unlock_irq(shost->host_lock);
490 lpfc_unreg_rpi(vport, np);
492 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
493 lpfc_mbx_unreg_vpi(vport);
494 spin_lock_irq(shost->host_lock);
495 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
496 spin_unlock_irq(shost->host_lock);
500 lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
502 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED &&
503 vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) {
504 lpfc_register_new_vport(phba, vport, ndlp);
507 lpfc_issue_fabric_reglogin(vport);
512 * lpfc_cmpl_els_flogi_nport: Completion function for flogi to an N_Port.
513 * @vport: pointer to a host virtual N_Port data structure.
514 * @ndlp: pointer to a node-list data structure.
515 * @sp: pointer to service parameter data structure.
517 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
518 * function to handle the completion of a Fabric Login (FLOGI) into an N_Port
519 * in a point-to-point topology. First, the @vport's N_Port Name is compared
520 * with the received N_Port Name: if the @vport's N_Port Name is greater than
521 * the received N_Port Name lexicographically, this node shall assign local
522 * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and
523 * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise,
524 * this node shall just wait for the remote node to issue PLOGI and assign
532 lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
533 struct serv_parm *sp)
535 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
536 struct lpfc_hba *phba = vport->phba;
540 spin_lock_irq(shost->host_lock);
541 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
542 spin_unlock_irq(shost->host_lock);
544 phba->fc_edtov = FF_DEF_EDTOV;
545 phba->fc_ratov = FF_DEF_RATOV;
546 rc = memcmp(&vport->fc_portname, &sp->portName,
547 sizeof(vport->fc_portname));
549 /* This side will initiate the PLOGI */
550 spin_lock_irq(shost->host_lock);
551 vport->fc_flag |= FC_PT2PT_PLOGI;
552 spin_unlock_irq(shost->host_lock);
555 * N_Port ID cannot be 0, set our to LocalID the other
556 * side will be RemoteID.
561 vport->fc_myDID = PT2PT_LocalID;
563 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
567 lpfc_config_link(phba, mbox);
569 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
571 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
572 if (rc == MBX_NOT_FINISHED) {
573 mempool_free(mbox, phba->mbox_mem_pool);
576 /* Decrement ndlp reference count indicating that ndlp can be
577 * safely released when other references to it are done.
581 ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
584 * Cannot find existing Fabric ndlp, so allocate a
587 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
590 lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID);
591 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
592 ndlp = lpfc_enable_node(vport, ndlp,
593 NLP_STE_UNUSED_NODE);
598 memcpy(&ndlp->nlp_portname, &sp->portName,
599 sizeof(struct lpfc_name));
600 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
601 sizeof(struct lpfc_name));
602 /* Set state will put ndlp onto node list if not already done */
603 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
604 spin_lock_irq(shost->host_lock);
605 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
606 spin_unlock_irq(shost->host_lock);
608 /* This side will wait for the PLOGI, decrement ndlp reference
609 * count indicating that ndlp can be released when other
610 * references to it are done.
614 /* If we are pt2pt with another NPort, force NPIV off! */
615 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
617 spin_lock_irq(shost->host_lock);
618 vport->fc_flag |= FC_PT2PT;
619 spin_unlock_irq(shost->host_lock);
621 /* Start discovery - this should just do CLEAR_LA */
622 lpfc_disc_start(vport);
629 * lpfc_cmpl_els_flogi: Completion callback function for flogi.
630 * @phba: pointer to lpfc hba data structure.
631 * @cmdiocb: pointer to lpfc command iocb data structure.
632 * @rspiocb: pointer to lpfc response iocb data structure.
634 * This routine is the top-level completion callback function for issuing
635 * a Fabric Login (FLOGI) command. If the response IOCB reported error,
636 * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If
637 * retry has been made (either immediately or delayed with lpfc_els_retry()
638 * returning 1), the command IOCB will be released and function returned.
639 * If the retry attempt has been given up (possibly reach the maximum
640 * number of retries), one additional decrement of ndlp reference shall be
641 * invoked before going out after releasing the command IOCB. This will
642 * actually release the remote node (Note, lpfc_els_free_iocb() will also
643 * invoke one decrement of ndlp reference count). If no error reported in
644 * the IOCB status, the command Port ID field is used to determine whether
645 * this is a point-to-point topology or a fabric topology: if the Port ID
646 * field is assigned, it is a fabric topology; otherwise, it is a
647 * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or
648 * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the
649 * specific topology completion conditions.
652 lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
653 struct lpfc_iocbq *rspiocb)
655 struct lpfc_vport *vport = cmdiocb->vport;
656 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
657 IOCB_t *irsp = &rspiocb->iocb;
658 struct lpfc_nodelist *ndlp = cmdiocb->context1;
659 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
660 struct serv_parm *sp;
663 /* Check to see if link went down during discovery */
664 if (lpfc_els_chk_latt(vport)) {
665 /* One additional decrement on node reference count to
666 * trigger the release of the node
672 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
673 "FLOGI cmpl: status:x%x/x%x state:x%x",
674 irsp->ulpStatus, irsp->un.ulpWord[4],
677 if (irsp->ulpStatus) {
678 /* Check for retry */
679 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
682 /* FLOGI failed, so there is no fabric */
683 spin_lock_irq(shost->host_lock);
684 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
685 spin_unlock_irq(shost->host_lock);
687 /* If private loop, then allow max outstanding els to be
688 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
689 * alpa map would take too long otherwise.
691 if (phba->alpa_map[0] == 0) {
692 vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
696 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
697 "0100 FLOGI failure Data: x%x x%x "
699 irsp->ulpStatus, irsp->un.ulpWord[4],
705 * The FLogI succeeded. Sync the data for the CPU before
708 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
710 sp = prsp->virt + sizeof(uint32_t);
712 /* FLOGI completes successfully */
713 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
714 "0101 FLOGI completes sucessfully "
715 "Data: x%x x%x x%x x%x\n",
716 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
717 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution);
719 if (vport->port_state == LPFC_FLOGI) {
721 * If Common Service Parameters indicate Nport
722 * we are point to point, if Fport we are Fabric.
725 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
727 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
736 if (!lpfc_error_lost_link(irsp)) {
737 /* FLOGI failed, so just use loop map to make discovery list */
738 lpfc_disc_list_loopmap(vport);
740 /* Start discovery */
741 lpfc_disc_start(vport);
742 } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
743 ((irsp->un.ulpWord[4] != IOERR_SLI_ABORTED) &&
744 (irsp->un.ulpWord[4] != IOERR_SLI_DOWN))) &&
745 (phba->link_state != LPFC_CLEAR_LA)) {
746 /* If FLOGI failed enable link interrupt. */
747 lpfc_issue_clear_la(phba, vport);
750 lpfc_els_free_iocb(phba, cmdiocb);
754 * lpfc_issue_els_flogi: Issue an flogi iocb command for a vport.
755 * @vport: pointer to a host virtual N_Port data structure.
756 * @ndlp: pointer to a node-list data structure.
757 * @retry: number of retries to the command IOCB.
759 * This routine issues a Fabric Login (FLOGI) Request ELS command
760 * for a @vport. The initiator service parameters are put into the payload
761 * of the FLOGI Request IOCB and the top-level callback function pointer
762 * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
763 * function field. The lpfc_issue_fabric_iocb routine is invoked to send
764 * out FLOGI ELS command with one outstanding fabric IOCB at a time.
766 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
767 * will be incremented by 1 for holding the ndlp and the reference to ndlp
768 * will be stored into the context1 field of the IOCB for the completion
769 * callback function to the FLOGI ELS command.
772 * 0 - successfully issued flogi iocb for @vport
773 * 1 - failed to issue flogi iocb for @vport
776 lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
779 struct lpfc_hba *phba = vport->phba;
780 struct serv_parm *sp;
782 struct lpfc_iocbq *elsiocb;
783 struct lpfc_sli_ring *pring;
789 pring = &phba->sli.ring[LPFC_ELS_RING];
791 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
792 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
793 ndlp->nlp_DID, ELS_CMD_FLOGI);
798 icmd = &elsiocb->iocb;
799 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
801 /* For FLOGI request, remainder of payload is service parameters */
802 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
803 pcmd += sizeof(uint32_t);
804 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
805 sp = (struct serv_parm *) pcmd;
807 /* Setup CSPs accordingly for Fabric */
809 sp->cmn.w2.r_a_tov = 0;
810 sp->cls1.classValid = 0;
811 sp->cls2.seqDelivery = 1;
812 sp->cls3.seqDelivery = 1;
813 if (sp->cmn.fcphLow < FC_PH3)
814 sp->cmn.fcphLow = FC_PH3;
815 if (sp->cmn.fcphHigh < FC_PH3)
816 sp->cmn.fcphHigh = FC_PH3;
818 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
819 sp->cmn.request_multiple_Nport = 1;
821 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
826 if (phba->fc_topology != TOPOLOGY_LOOP) {
827 icmd->un.elsreq64.myID = 0;
828 icmd->un.elsreq64.fl = 1;
831 tmo = phba->fc_ratov;
832 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
833 lpfc_set_disctmo(vport);
834 phba->fc_ratov = tmo;
836 phba->fc_stat.elsXmitFLOGI++;
837 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
839 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
840 "Issue FLOGI: opt:x%x",
841 phba->sli3_options, 0, 0);
843 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
844 if (rc == IOCB_ERROR) {
845 lpfc_els_free_iocb(phba, elsiocb);
852 * lpfc_els_abort_flogi: Abort all outstanding flogi iocbs.
853 * @phba: pointer to lpfc hba data structure.
855 * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
856 * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
857 * list and issues an abort IOCB commond on each outstanding IOCB that
858 * contains a active Fabric_DID ndlp. Note that this function is to issue
859 * the abort IOCB command on all the outstanding IOCBs, thus when this
860 * function returns, it does not guarantee all the IOCBs are actually aborted.
863 * 0 - Sucessfully issued abort iocb on all outstanding flogis (Always 0)
866 lpfc_els_abort_flogi(struct lpfc_hba *phba)
868 struct lpfc_sli_ring *pring;
869 struct lpfc_iocbq *iocb, *next_iocb;
870 struct lpfc_nodelist *ndlp;
873 /* Abort outstanding I/O on NPort <nlp_DID> */
874 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
875 "0201 Abort outstanding I/O on NPort x%x\n",
878 pring = &phba->sli.ring[LPFC_ELS_RING];
881 * Check the txcmplq for an iocb that matches the nport the driver is
884 spin_lock_irq(&phba->hbalock);
885 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
887 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR &&
888 icmd->un.elsreq64.bdl.ulpIoTag32) {
889 ndlp = (struct lpfc_nodelist *)(iocb->context1);
890 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
891 (ndlp->nlp_DID == Fabric_DID))
892 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
895 spin_unlock_irq(&phba->hbalock);
901 * lpfc_initial_flogi: Issue an initial fabric login for a vport.
902 * @vport: pointer to a host virtual N_Port data structure.
904 * This routine issues an initial Fabric Login (FLOGI) for the @vport
905 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
906 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
907 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
908 * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
909 * is then invoked with the @vport and the ndlp to perform the FLOGI for the
913 * 0 - failed to issue initial flogi for @vport
914 * 1 - successfully issued initial flogi for @vport
917 lpfc_initial_flogi(struct lpfc_vport *vport)
919 struct lpfc_hba *phba = vport->phba;
920 struct lpfc_nodelist *ndlp;
922 vport->port_state = LPFC_FLOGI;
923 lpfc_set_disctmo(vport);
925 /* First look for the Fabric ndlp */
926 ndlp = lpfc_findnode_did(vport, Fabric_DID);
928 /* Cannot find existing Fabric ndlp, so allocate a new one */
929 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
932 lpfc_nlp_init(vport, ndlp, Fabric_DID);
933 /* Put ndlp onto node list */
934 lpfc_enqueue_node(vport, ndlp);
935 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
936 /* re-setup ndlp without removing from node list */
937 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
942 if (lpfc_issue_els_flogi(vport, ndlp, 0))
943 /* This decrement of reference count to node shall kick off
944 * the release of the node.
952 * lpfc_initial_fdisc: Issue an initial fabric discovery for a vport.
953 * @vport: pointer to a host virtual N_Port data structure.
955 * This routine issues an initial Fabric Discover (FDISC) for the @vport
956 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
957 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
958 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
959 * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
960 * is then invoked with the @vport and the ndlp to perform the FDISC for the
964 * 0 - failed to issue initial fdisc for @vport
965 * 1 - successfully issued initial fdisc for @vport
968 lpfc_initial_fdisc(struct lpfc_vport *vport)
970 struct lpfc_hba *phba = vport->phba;
971 struct lpfc_nodelist *ndlp;
973 /* First look for the Fabric ndlp */
974 ndlp = lpfc_findnode_did(vport, Fabric_DID);
976 /* Cannot find existing Fabric ndlp, so allocate a new one */
977 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
980 lpfc_nlp_init(vport, ndlp, Fabric_DID);
981 /* Put ndlp onto node list */
982 lpfc_enqueue_node(vport, ndlp);
983 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
984 /* re-setup ndlp without removing from node list */
985 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
990 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
991 /* decrement node reference count to trigger the release of
1001 * lpfc_more_plogi: Check and issue remaining plogis for a vport.
1002 * @vport: pointer to a host virtual N_Port data structure.
1004 * This routine checks whether there are more remaining Port Logins
1005 * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
1006 * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
1007 * to issue ELS PLOGIs up to the configured discover threads with the
1008 * @vport (@vport->cfg_discovery_threads). The function also decrement
1009 * the @vport's num_disc_node by 1 if it is not already 0.
1012 lpfc_more_plogi(struct lpfc_vport *vport)
1016 if (vport->num_disc_nodes)
1017 vport->num_disc_nodes--;
1019 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
1020 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1021 "0232 Continue discovery with %d PLOGIs to go "
1022 "Data: x%x x%x x%x\n",
1023 vport->num_disc_nodes, vport->fc_plogi_cnt,
1024 vport->fc_flag, vport->port_state);
1025 /* Check to see if there are more PLOGIs to be sent */
1026 if (vport->fc_flag & FC_NLP_MORE)
1027 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
1028 sentplogi = lpfc_els_disc_plogi(vport);
1034 * lpfc_plogi_confirm_nport: Confirm pologi wwpn matches stored ndlp.
1035 * @phba: pointer to lpfc hba data structure.
1036 * @prsp: pointer to response IOCB payload.
1037 * @ndlp: pointer to a node-list data structure.
1039 * This routine checks and indicates whether the WWPN of an N_Port, retrieved
1040 * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
1041 * The following cases are considered N_Port confirmed:
1042 * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
1043 * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
1044 * it does not have WWPN assigned either. If the WWPN is confirmed, the
1045 * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
1046 * 1) if there is a node on vport list other than the @ndlp with the same
1047 * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
1048 * on that node to release the RPI associated with the node; 2) if there is
1049 * no node found on vport list with the same WWPN of the N_Port PLOGI logged
1050 * into, a new node shall be allocated (or activated). In either case, the
1051 * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
1052 * be released and the new_ndlp shall be put on to the vport node list and
1053 * its pointer returned as the confirmed node.
1055 * Note that before the @ndlp got "released", the keepDID from not-matching
1056 * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
1057 * of the @ndlp. This is because the release of @ndlp is actually to put it
1058 * into an inactive state on the vport node list and the vport node list
1059 * management algorithm does not allow two node with a same DID.
1062 * pointer to the PLOGI N_Port @ndlp
1064 static struct lpfc_nodelist *
1065 lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
1066 struct lpfc_nodelist *ndlp)
1068 struct lpfc_vport *vport = ndlp->vport;
1069 struct lpfc_nodelist *new_ndlp;
1070 struct lpfc_rport_data *rdata;
1071 struct fc_rport *rport;
1072 struct serv_parm *sp;
1073 uint8_t name[sizeof(struct lpfc_name)];
1074 uint32_t rc, keepDID = 0;
1076 /* Fabric nodes can have the same WWPN so we don't bother searching
1077 * by WWPN. Just return the ndlp that was given to us.
1079 if (ndlp->nlp_type & NLP_FABRIC)
1082 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
1083 memset(name, 0, sizeof(struct lpfc_name));
1085 /* Now we find out if the NPort we are logging into, matches the WWPN
1086 * we have for that ndlp. If not, we have some work to do.
1088 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
1090 if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp))
1094 rc = memcmp(&ndlp->nlp_portname, name,
1095 sizeof(struct lpfc_name));
1098 new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
1101 lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID);
1102 } else if (!NLP_CHK_NODE_ACT(new_ndlp)) {
1103 rc = memcmp(&ndlp->nlp_portname, name,
1104 sizeof(struct lpfc_name));
1107 new_ndlp = lpfc_enable_node(vport, new_ndlp,
1108 NLP_STE_UNUSED_NODE);
1111 keepDID = new_ndlp->nlp_DID;
1113 keepDID = new_ndlp->nlp_DID;
1115 lpfc_unreg_rpi(vport, new_ndlp);
1116 new_ndlp->nlp_DID = ndlp->nlp_DID;
1117 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
1119 if (ndlp->nlp_flag & NLP_NPR_2B_DISC)
1120 new_ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1121 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1123 /* Set state will put new_ndlp on to node list if not already done */
1124 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
1126 /* Move this back to NPR state */
1127 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
1128 /* The new_ndlp is replacing ndlp totally, so we need
1129 * to put ndlp on UNUSED list and try to free it.
1132 /* Fix up the rport accordingly */
1133 rport = ndlp->rport;
1135 rdata = rport->dd_data;
1136 if (rdata->pnode == ndlp) {
1139 rdata->pnode = lpfc_nlp_get(new_ndlp);
1140 new_ndlp->rport = rport;
1142 new_ndlp->nlp_type = ndlp->nlp_type;
1144 /* We shall actually free the ndlp with both nlp_DID and
1145 * nlp_portname fields equals 0 to avoid any ndlp on the
1146 * nodelist never to be used.
1148 if (ndlp->nlp_DID == 0) {
1149 spin_lock_irq(&phba->ndlp_lock);
1150 NLP_SET_FREE_REQ(ndlp);
1151 spin_unlock_irq(&phba->ndlp_lock);
1154 /* Two ndlps cannot have the same did on the nodelist */
1155 ndlp->nlp_DID = keepDID;
1156 lpfc_drop_node(vport, ndlp);
1159 lpfc_unreg_rpi(vport, ndlp);
1160 /* Two ndlps cannot have the same did */
1161 ndlp->nlp_DID = keepDID;
1162 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1168 * lpfc_end_rscn: Check and handle more rscn for a vport.
1169 * @vport: pointer to a host virtual N_Port data structure.
1171 * This routine checks whether more Registration State Change
1172 * Notifications (RSCNs) came in while the discovery state machine was in
1173 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1174 * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1175 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1176 * handling the RSCNs.
1179 lpfc_end_rscn(struct lpfc_vport *vport)
1181 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1183 if (vport->fc_flag & FC_RSCN_MODE) {
1185 * Check to see if more RSCNs came in while we were
1186 * processing this one.
1188 if (vport->fc_rscn_id_cnt ||
1189 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
1190 lpfc_els_handle_rscn(vport);
1192 spin_lock_irq(shost->host_lock);
1193 vport->fc_flag &= ~FC_RSCN_MODE;
1194 spin_unlock_irq(shost->host_lock);
1200 * lpfc_cmpl_els_plogi: Completion callback function for plogi.
1201 * @phba: pointer to lpfc hba data structure.
1202 * @cmdiocb: pointer to lpfc command iocb data structure.
1203 * @rspiocb: pointer to lpfc response iocb data structure.
1205 * This routine is the completion callback function for issuing the Port
1206 * Login (PLOGI) command. For PLOGI completion, there must be an active
1207 * ndlp on the vport node list that matches the remote node ID from the
1208 * PLOGI reponse IOCB. If such ndlp does not exist, the PLOGI is simply
1209 * ignored and command IOCB released. The PLOGI response IOCB status is
1210 * checked for error conditons. If there is error status reported, PLOGI
1211 * retry shall be attempted by invoking the lpfc_els_retry() routine.
1212 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1213 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1214 * (DSM) is set for this PLOGI completion. Finally, it checks whether
1215 * there are additional N_Port nodes with the vport that need to perform
1216 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
1220 lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1221 struct lpfc_iocbq *rspiocb)
1223 struct lpfc_vport *vport = cmdiocb->vport;
1224 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1226 struct lpfc_nodelist *ndlp;
1227 struct lpfc_dmabuf *prsp;
1228 int disc, rc, did, type;
1230 /* we pass cmdiocb to state machine which needs rspiocb as well */
1231 cmdiocb->context_un.rsp_iocb = rspiocb;
1233 irsp = &rspiocb->iocb;
1234 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1235 "PLOGI cmpl: status:x%x/x%x did:x%x",
1236 irsp->ulpStatus, irsp->un.ulpWord[4],
1237 irsp->un.elsreq64.remoteID);
1239 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
1240 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
1241 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1242 "0136 PLOGI completes to NPort x%x "
1243 "with no ndlp. Data: x%x x%x x%x\n",
1244 irsp->un.elsreq64.remoteID,
1245 irsp->ulpStatus, irsp->un.ulpWord[4],
1250 /* Since ndlp can be freed in the disc state machine, note if this node
1251 * is being used during discovery.
1253 spin_lock_irq(shost->host_lock);
1254 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
1255 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1256 spin_unlock_irq(shost->host_lock);
1259 /* PLOGI completes to NPort <nlp_DID> */
1260 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1261 "0102 PLOGI completes to NPort x%x "
1262 "Data: x%x x%x x%x x%x x%x\n",
1263 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1264 irsp->ulpTimeout, disc, vport->num_disc_nodes);
1265 /* Check to see if link went down during discovery */
1266 if (lpfc_els_chk_latt(vport)) {
1267 spin_lock_irq(shost->host_lock);
1268 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1269 spin_unlock_irq(shost->host_lock);
1273 /* ndlp could be freed in DSM, save these values now */
1274 type = ndlp->nlp_type;
1275 did = ndlp->nlp_DID;
1277 if (irsp->ulpStatus) {
1278 /* Check for retry */
1279 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1280 /* ELS command is being retried */
1282 spin_lock_irq(shost->host_lock);
1283 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1284 spin_unlock_irq(shost->host_lock);
1289 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1290 if (lpfc_error_lost_link(irsp))
1291 rc = NLP_STE_FREED_NODE;
1293 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1294 NLP_EVT_CMPL_PLOGI);
1296 /* Good status, call state machine */
1297 prsp = list_entry(((struct lpfc_dmabuf *)
1298 cmdiocb->context2)->list.next,
1299 struct lpfc_dmabuf, list);
1300 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
1301 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1302 NLP_EVT_CMPL_PLOGI);
1305 if (disc && vport->num_disc_nodes) {
1306 /* Check to see if there are more PLOGIs to be sent */
1307 lpfc_more_plogi(vport);
1309 if (vport->num_disc_nodes == 0) {
1310 spin_lock_irq(shost->host_lock);
1311 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1312 spin_unlock_irq(shost->host_lock);
1314 lpfc_can_disctmo(vport);
1315 lpfc_end_rscn(vport);
1320 lpfc_els_free_iocb(phba, cmdiocb);
1325 * lpfc_issue_els_plogi: Issue an plogi iocb command for a vport.
1326 * @vport: pointer to a host virtual N_Port data structure.
1327 * @did: destination port identifier.
1328 * @retry: number of retries to the command IOCB.
1330 * This routine issues a Port Login (PLOGI) command to a remote N_Port
1331 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
1332 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
1333 * This routine constructs the proper feilds of the PLOGI IOCB and invokes
1334 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
1336 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1337 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1338 * will be stored into the context1 field of the IOCB for the completion
1339 * callback function to the PLOGI ELS command.
1342 * 0 - Successfully issued a plogi for @vport
1343 * 1 - failed to issue a plogi for @vport
1346 lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
1348 struct lpfc_hba *phba = vport->phba;
1349 struct serv_parm *sp;
1351 struct lpfc_nodelist *ndlp;
1352 struct lpfc_iocbq *elsiocb;
1353 struct lpfc_sli_ring *pring;
1354 struct lpfc_sli *psli;
1360 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
1362 ndlp = lpfc_findnode_did(vport, did);
1363 if (ndlp && !NLP_CHK_NODE_ACT(ndlp))
1366 /* If ndlp is not NULL, we will bump the reference count on it */
1367 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
1368 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
1373 icmd = &elsiocb->iocb;
1374 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1376 /* For PLOGI request, remainder of payload is service parameters */
1377 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
1378 pcmd += sizeof(uint32_t);
1379 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
1380 sp = (struct serv_parm *) pcmd;
1382 if (sp->cmn.fcphLow < FC_PH_4_3)
1383 sp->cmn.fcphLow = FC_PH_4_3;
1385 if (sp->cmn.fcphHigh < FC_PH3)
1386 sp->cmn.fcphHigh = FC_PH3;
1388 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1389 "Issue PLOGI: did:x%x",
1392 phba->fc_stat.elsXmitPLOGI++;
1393 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
1394 ret = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
1396 if (ret == IOCB_ERROR) {
1397 lpfc_els_free_iocb(phba, elsiocb);
1404 * lpfc_cmpl_els_prli: Completion callback function for prli.
1405 * @phba: pointer to lpfc hba data structure.
1406 * @cmdiocb: pointer to lpfc command iocb data structure.
1407 * @rspiocb: pointer to lpfc response iocb data structure.
1409 * This routine is the completion callback function for a Process Login
1410 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
1411 * status. If there is error status reported, PRLI retry shall be attempted
1412 * by invoking the lpfc_els_retry() routine. Otherwise, the state
1413 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
1414 * ndlp to mark the PRLI completion.
1417 lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1418 struct lpfc_iocbq *rspiocb)
1420 struct lpfc_vport *vport = cmdiocb->vport;
1421 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1423 struct lpfc_sli *psli;
1424 struct lpfc_nodelist *ndlp;
1427 /* we pass cmdiocb to state machine which needs rspiocb as well */
1428 cmdiocb->context_un.rsp_iocb = rspiocb;
1430 irsp = &(rspiocb->iocb);
1431 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1432 spin_lock_irq(shost->host_lock);
1433 ndlp->nlp_flag &= ~NLP_PRLI_SND;
1434 spin_unlock_irq(shost->host_lock);
1436 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1437 "PRLI cmpl: status:x%x/x%x did:x%x",
1438 irsp->ulpStatus, irsp->un.ulpWord[4],
1440 /* PRLI completes to NPort <nlp_DID> */
1441 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1442 "0103 PRLI completes to NPort x%x "
1443 "Data: x%x x%x x%x x%x\n",
1444 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1445 irsp->ulpTimeout, vport->num_disc_nodes);
1447 vport->fc_prli_sent--;
1448 /* Check to see if link went down during discovery */
1449 if (lpfc_els_chk_latt(vport))
1452 if (irsp->ulpStatus) {
1453 /* Check for retry */
1454 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1455 /* ELS command is being retried */
1459 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1460 if (lpfc_error_lost_link(irsp))
1463 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1466 /* Good status, call state machine */
1467 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1470 lpfc_els_free_iocb(phba, cmdiocb);
1475 * lpfc_issue_els_prli: Issue a prli iocb command for a vport.
1476 * @vport: pointer to a host virtual N_Port data structure.
1477 * @ndlp: pointer to a node-list data structure.
1478 * @retry: number of retries to the command IOCB.
1480 * This routine issues a Process Login (PRLI) ELS command for the
1481 * @vport. The PRLI service parameters are set up in the payload of the
1482 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
1483 * is put to the IOCB completion callback func field before invoking the
1484 * routine lpfc_sli_issue_iocb() to send out PRLI command.
1486 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1487 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1488 * will be stored into the context1 field of the IOCB for the completion
1489 * callback function to the PRLI ELS command.
1492 * 0 - successfully issued prli iocb command for @vport
1493 * 1 - failed to issue prli iocb command for @vport
1496 lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1499 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1500 struct lpfc_hba *phba = vport->phba;
1503 struct lpfc_iocbq *elsiocb;
1504 struct lpfc_sli_ring *pring;
1505 struct lpfc_sli *psli;
1510 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
1512 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
1513 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1514 ndlp->nlp_DID, ELS_CMD_PRLI);
1518 icmd = &elsiocb->iocb;
1519 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1521 /* For PRLI request, remainder of payload is service parameters */
1522 memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t)));
1523 *((uint32_t *) (pcmd)) = ELS_CMD_PRLI;
1524 pcmd += sizeof(uint32_t);
1526 /* For PRLI, remainder of payload is PRLI parameter page */
1527 npr = (PRLI *) pcmd;
1529 * If our firmware version is 3.20 or later,
1530 * set the following bits for FC-TAPE support.
1532 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
1533 npr->ConfmComplAllowed = 1;
1535 npr->TaskRetryIdReq = 1;
1537 npr->estabImagePair = 1;
1538 npr->readXferRdyDis = 1;
1540 /* For FCP support */
1541 npr->prliType = PRLI_FCP_TYPE;
1542 npr->initiatorFunc = 1;
1544 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1545 "Issue PRLI: did:x%x",
1546 ndlp->nlp_DID, 0, 0);
1548 phba->fc_stat.elsXmitPRLI++;
1549 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
1550 spin_lock_irq(shost->host_lock);
1551 ndlp->nlp_flag |= NLP_PRLI_SND;
1552 spin_unlock_irq(shost->host_lock);
1553 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
1554 spin_lock_irq(shost->host_lock);
1555 ndlp->nlp_flag &= ~NLP_PRLI_SND;
1556 spin_unlock_irq(shost->host_lock);
1557 lpfc_els_free_iocb(phba, elsiocb);
1560 vport->fc_prli_sent++;
1565 * lpfc_rscn_disc: Perform rscn discovery for a vport.
1566 * @vport: pointer to a host virtual N_Port data structure.
1568 * This routine performs Registration State Change Notification (RSCN)
1569 * discovery for a @vport. If the @vport's node port recovery count is not
1570 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
1571 * the nodes that need recovery. If none of the PLOGI were needed through
1572 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
1573 * invoked to check and handle possible more RSCN came in during the period
1574 * of processing the current ones.
1577 lpfc_rscn_disc(struct lpfc_vport *vport)
1579 lpfc_can_disctmo(vport);
1581 /* RSCN discovery */
1582 /* go thru NPR nodes and issue ELS PLOGIs */
1583 if (vport->fc_npr_cnt)
1584 if (lpfc_els_disc_plogi(vport))
1587 lpfc_end_rscn(vport);
1591 * lpfc_adisc_done: Complete the adisc phase of discovery.
1592 * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
1594 * This function is called when the final ADISC is completed during discovery.
1595 * This function handles clearing link attention or issuing reg_vpi depending
1596 * on whether npiv is enabled. This function also kicks off the PLOGI phase of
1598 * This function is called with no locks held.
1601 lpfc_adisc_done(struct lpfc_vport *vport)
1603 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1604 struct lpfc_hba *phba = vport->phba;
1607 * For NPIV, cmpl_reg_vpi will set port_state to READY,
1608 * and continue discovery.
1610 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
1611 !(vport->fc_flag & FC_RSCN_MODE)) {
1612 lpfc_issue_reg_vpi(phba, vport);
1616 * For SLI2, we need to set port_state to READY
1617 * and continue discovery.
1619 if (vport->port_state < LPFC_VPORT_READY) {
1620 /* If we get here, there is nothing to ADISC */
1621 if (vport->port_type == LPFC_PHYSICAL_PORT)
1622 lpfc_issue_clear_la(phba, vport);
1623 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
1624 vport->num_disc_nodes = 0;
1625 /* go thru NPR list, issue ELS PLOGIs */
1626 if (vport->fc_npr_cnt)
1627 lpfc_els_disc_plogi(vport);
1628 if (!vport->num_disc_nodes) {
1629 spin_lock_irq(shost->host_lock);
1630 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1631 spin_unlock_irq(shost->host_lock);
1632 lpfc_can_disctmo(vport);
1633 lpfc_end_rscn(vport);
1636 vport->port_state = LPFC_VPORT_READY;
1638 lpfc_rscn_disc(vport);
1642 * lpfc_more_adisc: Issue more adisc as needed.
1643 * @vport: pointer to a host virtual N_Port data structure.
1645 * This routine determines whether there are more ndlps on a @vport
1646 * node list need to have Address Discover (ADISC) issued. If so, it will
1647 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
1648 * remaining nodes which need to have ADISC sent.
1651 lpfc_more_adisc(struct lpfc_vport *vport)
1655 if (vport->num_disc_nodes)
1656 vport->num_disc_nodes--;
1657 /* Continue discovery with <num_disc_nodes> ADISCs to go */
1658 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1659 "0210 Continue discovery with %d ADISCs to go "
1660 "Data: x%x x%x x%x\n",
1661 vport->num_disc_nodes, vport->fc_adisc_cnt,
1662 vport->fc_flag, vport->port_state);
1663 /* Check to see if there are more ADISCs to be sent */
1664 if (vport->fc_flag & FC_NLP_MORE) {
1665 lpfc_set_disctmo(vport);
1666 /* go thru NPR nodes and issue any remaining ELS ADISCs */
1667 sentadisc = lpfc_els_disc_adisc(vport);
1669 if (!vport->num_disc_nodes)
1670 lpfc_adisc_done(vport);
1675 * lpfc_cmpl_els_adisc: Completion callback function for adisc.
1676 * @phba: pointer to lpfc hba data structure.
1677 * @cmdiocb: pointer to lpfc command iocb data structure.
1678 * @rspiocb: pointer to lpfc response iocb data structure.
1680 * This routine is the completion function for issuing the Address Discover
1681 * (ADISC) command. It first checks to see whether link went down during
1682 * the discovery process. If so, the node will be marked as node port
1683 * recovery for issuing discover IOCB by the link attention handler and
1684 * exit. Otherwise, the response status is checked. If error was reported
1685 * in the response status, the ADISC command shall be retried by invoking
1686 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
1687 * the response status, the state machine is invoked to set transition
1688 * with respect to NLP_EVT_CMPL_ADISC event.
1691 lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1692 struct lpfc_iocbq *rspiocb)
1694 struct lpfc_vport *vport = cmdiocb->vport;
1695 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1697 struct lpfc_nodelist *ndlp;
1700 /* we pass cmdiocb to state machine which needs rspiocb as well */
1701 cmdiocb->context_un.rsp_iocb = rspiocb;
1703 irsp = &(rspiocb->iocb);
1704 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1706 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1707 "ADISC cmpl: status:x%x/x%x did:x%x",
1708 irsp->ulpStatus, irsp->un.ulpWord[4],
1711 /* Since ndlp can be freed in the disc state machine, note if this node
1712 * is being used during discovery.
1714 spin_lock_irq(shost->host_lock);
1715 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
1716 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
1717 spin_unlock_irq(shost->host_lock);
1718 /* ADISC completes to NPort <nlp_DID> */
1719 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1720 "0104 ADISC completes to NPort x%x "
1721 "Data: x%x x%x x%x x%x x%x\n",
1722 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1723 irsp->ulpTimeout, disc, vport->num_disc_nodes);
1724 /* Check to see if link went down during discovery */
1725 if (lpfc_els_chk_latt(vport)) {
1726 spin_lock_irq(shost->host_lock);
1727 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1728 spin_unlock_irq(shost->host_lock);
1732 if (irsp->ulpStatus) {
1733 /* Check for retry */
1734 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1735 /* ELS command is being retried */
1737 spin_lock_irq(shost->host_lock);
1738 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1739 spin_unlock_irq(shost->host_lock);
1740 lpfc_set_disctmo(vport);
1745 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1746 if (!lpfc_error_lost_link(irsp))
1747 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1748 NLP_EVT_CMPL_ADISC);
1750 /* Good status, call state machine */
1751 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1752 NLP_EVT_CMPL_ADISC);
1754 /* Check to see if there are more ADISCs to be sent */
1755 if (disc && vport->num_disc_nodes)
1756 lpfc_more_adisc(vport);
1758 lpfc_els_free_iocb(phba, cmdiocb);
1763 * lpfc_issue_els_adisc: Issue an address discover iocb to an node on a vport.
1764 * @vport: pointer to a virtual N_Port data structure.
1765 * @ndlp: pointer to a node-list data structure.
1766 * @retry: number of retries to the command IOCB.
1768 * This routine issues an Address Discover (ADISC) for an @ndlp on a
1769 * @vport. It prepares the payload of the ADISC ELS command, updates the
1770 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
1771 * to issue the ADISC ELS command.
1773 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1774 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1775 * will be stored into the context1 field of the IOCB for the completion
1776 * callback function to the ADISC ELS command.
1779 * 0 - successfully issued adisc
1780 * 1 - failed to issue adisc
1783 lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1786 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1787 struct lpfc_hba *phba = vport->phba;
1790 struct lpfc_iocbq *elsiocb;
1791 struct lpfc_sli *psli = &phba->sli;
1792 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
1796 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
1797 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1798 ndlp->nlp_DID, ELS_CMD_ADISC);
1802 icmd = &elsiocb->iocb;
1803 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1805 /* For ADISC request, remainder of payload is service parameters */
1806 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
1807 pcmd += sizeof(uint32_t);
1809 /* Fill in ADISC payload */
1810 ap = (ADISC *) pcmd;
1811 ap->hardAL_PA = phba->fc_pref_ALPA;
1812 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
1813 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
1814 ap->DID = be32_to_cpu(vport->fc_myDID);
1816 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1817 "Issue ADISC: did:x%x",
1818 ndlp->nlp_DID, 0, 0);
1820 phba->fc_stat.elsXmitADISC++;
1821 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
1822 spin_lock_irq(shost->host_lock);
1823 ndlp->nlp_flag |= NLP_ADISC_SND;
1824 spin_unlock_irq(shost->host_lock);
1825 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
1826 spin_lock_irq(shost->host_lock);
1827 ndlp->nlp_flag &= ~NLP_ADISC_SND;
1828 spin_unlock_irq(shost->host_lock);
1829 lpfc_els_free_iocb(phba, elsiocb);
1836 * lpfc_cmpl_els_logo: Completion callback function for logo.
1837 * @phba: pointer to lpfc hba data structure.
1838 * @cmdiocb: pointer to lpfc command iocb data structure.
1839 * @rspiocb: pointer to lpfc response iocb data structure.
1841 * This routine is the completion function for issuing the ELS Logout (LOGO)
1842 * command. If no error status was reported from the LOGO response, the
1843 * state machine of the associated ndlp shall be invoked for transition with
1844 * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
1845 * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
1848 lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1849 struct lpfc_iocbq *rspiocb)
1851 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1852 struct lpfc_vport *vport = ndlp->vport;
1853 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1855 struct lpfc_sli *psli;
1858 /* we pass cmdiocb to state machine which needs rspiocb as well */
1859 cmdiocb->context_un.rsp_iocb = rspiocb;
1861 irsp = &(rspiocb->iocb);
1862 spin_lock_irq(shost->host_lock);
1863 ndlp->nlp_flag &= ~NLP_LOGO_SND;
1864 spin_unlock_irq(shost->host_lock);
1866 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1867 "LOGO cmpl: status:x%x/x%x did:x%x",
1868 irsp->ulpStatus, irsp->un.ulpWord[4],
1870 /* LOGO completes to NPort <nlp_DID> */
1871 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1872 "0105 LOGO completes to NPort x%x "
1873 "Data: x%x x%x x%x x%x\n",
1874 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1875 irsp->ulpTimeout, vport->num_disc_nodes);
1876 /* Check to see if link went down during discovery */
1877 if (lpfc_els_chk_latt(vport))
1880 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
1881 /* NLP_EVT_DEVICE_RM should unregister the RPI
1882 * which should abort all outstanding IOs.
1884 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1889 if (irsp->ulpStatus) {
1890 /* Check for retry */
1891 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
1892 /* ELS command is being retried */
1895 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1896 if (lpfc_error_lost_link(irsp))
1899 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1902 /* Good status, call state machine.
1903 * This will unregister the rpi if needed.
1905 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1908 lpfc_els_free_iocb(phba, cmdiocb);
1913 * lpfc_issue_els_logo: Issue a logo to an node on a vport.
1914 * @vport: pointer to a virtual N_Port data structure.
1915 * @ndlp: pointer to a node-list data structure.
1916 * @retry: number of retries to the command IOCB.
1918 * This routine constructs and issues an ELS Logout (LOGO) iocb command
1919 * to a remote node, referred by an @ndlp on a @vport. It constructs the
1920 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
1921 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
1923 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1924 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1925 * will be stored into the context1 field of the IOCB for the completion
1926 * callback function to the LOGO ELS command.
1929 * 0 - successfully issued logo
1930 * 1 - failed to issue logo
1933 lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1936 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1937 struct lpfc_hba *phba = vport->phba;
1939 struct lpfc_iocbq *elsiocb;
1940 struct lpfc_sli_ring *pring;
1941 struct lpfc_sli *psli;
1947 pring = &psli->ring[LPFC_ELS_RING];
1949 spin_lock_irq(shost->host_lock);
1950 if (ndlp->nlp_flag & NLP_LOGO_SND) {
1951 spin_unlock_irq(shost->host_lock);
1954 spin_unlock_irq(shost->host_lock);
1956 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
1957 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1958 ndlp->nlp_DID, ELS_CMD_LOGO);
1962 icmd = &elsiocb->iocb;
1963 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1964 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
1965 pcmd += sizeof(uint32_t);
1967 /* Fill in LOGO payload */
1968 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
1969 pcmd += sizeof(uint32_t);
1970 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
1972 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1973 "Issue LOGO: did:x%x",
1974 ndlp->nlp_DID, 0, 0);
1976 phba->fc_stat.elsXmitLOGO++;
1977 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
1978 spin_lock_irq(shost->host_lock);
1979 ndlp->nlp_flag |= NLP_LOGO_SND;
1980 spin_unlock_irq(shost->host_lock);
1981 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
1983 if (rc == IOCB_ERROR) {
1984 spin_lock_irq(shost->host_lock);
1985 ndlp->nlp_flag &= ~NLP_LOGO_SND;
1986 spin_unlock_irq(shost->host_lock);
1987 lpfc_els_free_iocb(phba, elsiocb);
1994 * lpfc_cmpl_els_cmd: Completion callback function for generic els command.
1995 * @phba: pointer to lpfc hba data structure.
1996 * @cmdiocb: pointer to lpfc command iocb data structure.
1997 * @rspiocb: pointer to lpfc response iocb data structure.
1999 * This routine is a generic completion callback function for ELS commands.
2000 * Specifically, it is the callback function which does not need to perform
2001 * any command specific operations. It is currently used by the ELS command
2002 * issuing routines for the ELS State Change Request (SCR),
2003 * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution
2004 * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than
2005 * certain debug loggings, this callback function simply invokes the
2006 * lpfc_els_chk_latt() routine to check whether link went down during the
2007 * discovery process.
2010 lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2011 struct lpfc_iocbq *rspiocb)
2013 struct lpfc_vport *vport = cmdiocb->vport;
2016 irsp = &rspiocb->iocb;
2018 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2019 "ELS cmd cmpl: status:x%x/x%x did:x%x",
2020 irsp->ulpStatus, irsp->un.ulpWord[4],
2021 irsp->un.elsreq64.remoteID);
2022 /* ELS cmd tag <ulpIoTag> completes */
2023 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2024 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
2025 irsp->ulpIoTag, irsp->ulpStatus,
2026 irsp->un.ulpWord[4], irsp->ulpTimeout);
2027 /* Check to see if link went down during discovery */
2028 lpfc_els_chk_latt(vport);
2029 lpfc_els_free_iocb(phba, cmdiocb);
2034 * lpfc_issue_els_scr: Issue a scr to an node on a vport.
2035 * @vport: pointer to a host virtual N_Port data structure.
2036 * @nportid: N_Port identifier to the remote node.
2037 * @retry: number of retries to the command IOCB.
2039 * This routine issues a State Change Request (SCR) to a fabric node
2040 * on a @vport. The remote node @nportid is passed into the function. It
2041 * first search the @vport node list to find the matching ndlp. If no such
2042 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
2043 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
2044 * routine is invoked to send the SCR IOCB.
2046 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2047 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2048 * will be stored into the context1 field of the IOCB for the completion
2049 * callback function to the SCR ELS command.
2052 * 0 - Successfully issued scr command
2053 * 1 - Failed to issue scr command
2056 lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
2058 struct lpfc_hba *phba = vport->phba;
2060 struct lpfc_iocbq *elsiocb;
2061 struct lpfc_sli_ring *pring;
2062 struct lpfc_sli *psli;
2065 struct lpfc_nodelist *ndlp;
2068 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
2069 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
2071 ndlp = lpfc_findnode_did(vport, nportid);
2073 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2076 lpfc_nlp_init(vport, ndlp, nportid);
2077 lpfc_enqueue_node(vport, ndlp);
2078 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2079 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2084 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2085 ndlp->nlp_DID, ELS_CMD_SCR);
2088 /* This will trigger the release of the node just
2095 icmd = &elsiocb->iocb;
2096 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2098 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
2099 pcmd += sizeof(uint32_t);
2101 /* For SCR, remainder of payload is SCR parameter page */
2102 memset(pcmd, 0, sizeof(SCR));
2103 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
2105 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2106 "Issue SCR: did:x%x",
2107 ndlp->nlp_DID, 0, 0);
2109 phba->fc_stat.elsXmitSCR++;
2110 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
2111 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
2112 /* The additional lpfc_nlp_put will cause the following
2113 * lpfc_els_free_iocb routine to trigger the rlease of
2117 lpfc_els_free_iocb(phba, elsiocb);
2120 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2121 * trigger the release of node.
2128 * lpfc_issue_els_farpr: Issue a farp to an node on a vport.
2129 * @vport: pointer to a host virtual N_Port data structure.
2130 * @nportid: N_Port identifier to the remote node.
2131 * @retry: number of retries to the command IOCB.
2133 * This routine issues a Fibre Channel Address Resolution Response
2134 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
2135 * is passed into the function. It first search the @vport node list to find
2136 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
2137 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
2138 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
2140 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2141 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2142 * will be stored into the context1 field of the IOCB for the completion
2143 * callback function to the PARPR ELS command.
2146 * 0 - Successfully issued farpr command
2147 * 1 - Failed to issue farpr command
2150 lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
2152 struct lpfc_hba *phba = vport->phba;
2154 struct lpfc_iocbq *elsiocb;
2155 struct lpfc_sli_ring *pring;
2156 struct lpfc_sli *psli;
2161 struct lpfc_nodelist *ondlp;
2162 struct lpfc_nodelist *ndlp;
2165 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
2166 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
2168 ndlp = lpfc_findnode_did(vport, nportid);
2170 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2173 lpfc_nlp_init(vport, ndlp, nportid);
2174 lpfc_enqueue_node(vport, ndlp);
2175 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2176 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2181 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2182 ndlp->nlp_DID, ELS_CMD_RNID);
2184 /* This will trigger the release of the node just
2191 icmd = &elsiocb->iocb;
2192 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2194 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
2195 pcmd += sizeof(uint32_t);
2197 /* Fill in FARPR payload */
2198 fp = (FARP *) (pcmd);
2199 memset(fp, 0, sizeof(FARP));
2200 lp = (uint32_t *) pcmd;
2201 *lp++ = be32_to_cpu(nportid);
2202 *lp++ = be32_to_cpu(vport->fc_myDID);
2204 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
2206 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
2207 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
2208 ondlp = lpfc_findnode_did(vport, nportid);
2209 if (ondlp && NLP_CHK_NODE_ACT(ondlp)) {
2210 memcpy(&fp->OportName, &ondlp->nlp_portname,
2211 sizeof(struct lpfc_name));
2212 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
2213 sizeof(struct lpfc_name));
2216 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2217 "Issue FARPR: did:x%x",
2218 ndlp->nlp_DID, 0, 0);
2220 phba->fc_stat.elsXmitFARPR++;
2221 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
2222 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
2223 /* The additional lpfc_nlp_put will cause the following
2224 * lpfc_els_free_iocb routine to trigger the release of
2228 lpfc_els_free_iocb(phba, elsiocb);
2231 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2232 * trigger the release of the node.
2239 * lpfc_cancel_retry_delay_tmo: Cancel the timer with delayed iocb-cmd retry.
2240 * @vport: pointer to a host virtual N_Port data structure.
2241 * @nlp: pointer to a node-list data structure.
2243 * This routine cancels the timer with a delayed IOCB-command retry for
2244 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
2245 * removes the ELS retry event if it presents. In addition, if the
2246 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
2247 * commands are sent for the @vport's nodes that require issuing discovery
2251 lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
2253 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2254 struct lpfc_work_evt *evtp;
2256 if (!(nlp->nlp_flag & NLP_DELAY_TMO))
2258 spin_lock_irq(shost->host_lock);
2259 nlp->nlp_flag &= ~NLP_DELAY_TMO;
2260 spin_unlock_irq(shost->host_lock);
2261 del_timer_sync(&nlp->nlp_delayfunc);
2262 nlp->nlp_last_elscmd = 0;
2263 if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
2264 list_del_init(&nlp->els_retry_evt.evt_listp);
2265 /* Decrement nlp reference count held for the delayed retry */
2266 evtp = &nlp->els_retry_evt;
2267 lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
2269 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
2270 spin_lock_irq(shost->host_lock);
2271 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
2272 spin_unlock_irq(shost->host_lock);
2273 if (vport->num_disc_nodes) {
2274 if (vport->port_state < LPFC_VPORT_READY) {
2275 /* Check if there are more ADISCs to be sent */
2276 lpfc_more_adisc(vport);
2278 /* Check if there are more PLOGIs to be sent */
2279 lpfc_more_plogi(vport);
2280 if (vport->num_disc_nodes == 0) {
2281 spin_lock_irq(shost->host_lock);
2282 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2283 spin_unlock_irq(shost->host_lock);
2284 lpfc_can_disctmo(vport);
2285 lpfc_end_rscn(vport);
2294 * lpfc_els_retry_delay: Timer function with a ndlp delayed function timer.
2295 * @ptr: holder for the pointer to the timer function associated data (ndlp).
2297 * This routine is invoked by the ndlp delayed-function timer to check
2298 * whether there is any pending ELS retry event(s) with the node. If not, it
2299 * simply returns. Otherwise, if there is at least one ELS delayed event, it
2300 * adds the delayed events to the HBA work list and invokes the
2301 * lpfc_worker_wake_up() routine to wake up worker thread to process the
2302 * event. Note that lpfc_nlp_get() is called before posting the event to
2303 * the work list to hold reference count of ndlp so that it guarantees the
2304 * reference to ndlp will still be available when the worker thread gets
2305 * to the event associated with the ndlp.
2308 lpfc_els_retry_delay(unsigned long ptr)
2310 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr;
2311 struct lpfc_vport *vport = ndlp->vport;
2312 struct lpfc_hba *phba = vport->phba;
2313 unsigned long flags;
2314 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
2316 spin_lock_irqsave(&phba->hbalock, flags);
2317 if (!list_empty(&evtp->evt_listp)) {
2318 spin_unlock_irqrestore(&phba->hbalock, flags);
2322 /* We need to hold the node by incrementing the reference
2323 * count until the queued work is done
2325 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
2326 if (evtp->evt_arg1) {
2327 evtp->evt = LPFC_EVT_ELS_RETRY;
2328 list_add_tail(&evtp->evt_listp, &phba->work_list);
2329 lpfc_worker_wake_up(phba);
2331 spin_unlock_irqrestore(&phba->hbalock, flags);
2336 * lpfc_els_retry_delay_handler: Work thread handler for ndlp delayed function.
2337 * @ndlp: pointer to a node-list data structure.
2339 * This routine is the worker-thread handler for processing the @ndlp delayed
2340 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
2341 * the last ELS command from the associated ndlp and invokes the proper ELS
2342 * function according to the delayed ELS command to retry the command.
2345 lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
2347 struct lpfc_vport *vport = ndlp->vport;
2348 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2349 uint32_t cmd, did, retry;
2351 spin_lock_irq(shost->host_lock);
2352 did = ndlp->nlp_DID;
2353 cmd = ndlp->nlp_last_elscmd;
2354 ndlp->nlp_last_elscmd = 0;
2356 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
2357 spin_unlock_irq(shost->host_lock);
2361 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
2362 spin_unlock_irq(shost->host_lock);
2364 * If a discovery event readded nlp_delayfunc after timer
2365 * firing and before processing the timer, cancel the
2368 del_timer_sync(&ndlp->nlp_delayfunc);
2369 retry = ndlp->nlp_retry;
2373 lpfc_issue_els_flogi(vport, ndlp, retry);
2376 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
2377 ndlp->nlp_prev_state = ndlp->nlp_state;
2378 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2382 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
2383 ndlp->nlp_prev_state = ndlp->nlp_state;
2384 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2388 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
2389 ndlp->nlp_prev_state = ndlp->nlp_state;
2390 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
2394 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
2395 ndlp->nlp_prev_state = ndlp->nlp_state;
2396 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2400 lpfc_issue_els_fdisc(vport, ndlp, retry);
2407 * lpfc_els_retry: Make retry decision on an els command iocb.
2408 * @phba: pointer to lpfc hba data structure.
2409 * @cmdiocb: pointer to lpfc command iocb data structure.
2410 * @rspiocb: pointer to lpfc response iocb data structure.
2412 * This routine makes a retry decision on an ELS command IOCB, which has
2413 * failed. The following ELS IOCBs use this function for retrying the command
2414 * when previously issued command responsed with error status: FLOGI, PLOGI,
2415 * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
2416 * returned error status, it makes the decision whether a retry shall be
2417 * issued for the command, and whether a retry shall be made immediately or
2418 * delayed. In the former case, the corresponding ELS command issuing-function
2419 * is called to retry the command. In the later case, the ELS command shall
2420 * be posted to the ndlp delayed event and delayed function timer set to the
2421 * ndlp for the delayed command issusing.
2424 * 0 - No retry of els command is made
2425 * 1 - Immediate or delayed retry of els command is made
2428 lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2429 struct lpfc_iocbq *rspiocb)
2431 struct lpfc_vport *vport = cmdiocb->vport;
2432 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2433 IOCB_t *irsp = &rspiocb->iocb;
2434 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2435 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
2438 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
2444 /* Note: context2 may be 0 for internal driver abort
2445 * of delays ELS command.
2448 if (pcmd && pcmd->virt) {
2449 elscmd = (uint32_t *) (pcmd->virt);
2453 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
2454 did = ndlp->nlp_DID;
2456 /* We should only hit this case for retrying PLOGI */
2457 did = irsp->un.elsreq64.remoteID;
2458 ndlp = lpfc_findnode_did(vport, did);
2459 if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp))
2460 && (cmd != ELS_CMD_PLOGI))
2464 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2465 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
2466 *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
2468 switch (irsp->ulpStatus) {
2469 case IOSTAT_FCP_RSP_ERROR:
2470 case IOSTAT_REMOTE_STOP:
2473 case IOSTAT_LOCAL_REJECT:
2474 switch ((irsp->un.ulpWord[4] & 0xff)) {
2475 case IOERR_LOOP_OPEN_FAILURE:
2476 if (cmd == ELS_CMD_FLOGI) {
2477 if (PCI_DEVICE_ID_HORNET ==
2478 phba->pcidev->device) {
2479 phba->fc_topology = TOPOLOGY_LOOP;
2480 phba->pport->fc_myDID = 0;
2481 phba->alpa_map[0] = 0;
2482 phba->alpa_map[1] = 0;
2485 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
2490 case IOERR_ILLEGAL_COMMAND:
2491 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2492 "0124 Retry illegal cmd x%x "
2493 "retry:x%x delay:x%x\n",
2494 cmd, cmdiocb->retry, delay);
2496 /* All command's retry policy */
2498 if (cmdiocb->retry > 2)
2502 case IOERR_NO_RESOURCES:
2503 logerr = 1; /* HBA out of resources */
2505 if (cmdiocb->retry > 100)
2510 case IOERR_ILLEGAL_FRAME:
2515 case IOERR_SEQUENCE_TIMEOUT:
2516 case IOERR_INVALID_RPI:
2522 case IOSTAT_NPORT_RJT:
2523 case IOSTAT_FABRIC_RJT:
2524 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
2530 case IOSTAT_NPORT_BSY:
2531 case IOSTAT_FABRIC_BSY:
2532 logerr = 1; /* Fabric / Remote NPort out of resources */
2537 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
2538 /* Added for Vendor specifc support
2539 * Just keep retrying for these Rsn / Exp codes
2541 switch (stat.un.b.lsRjtRsnCode) {
2542 case LSRJT_UNABLE_TPC:
2543 if (stat.un.b.lsRjtRsnCodeExp ==
2544 LSEXP_CMD_IN_PROGRESS) {
2545 if (cmd == ELS_CMD_PLOGI) {
2552 if (cmd == ELS_CMD_PLOGI) {
2554 maxretry = lpfc_max_els_tries + 1;
2558 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2559 (cmd == ELS_CMD_FDISC) &&
2560 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
2561 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2562 "0125 FDISC Failed (x%x). "
2563 "Fabric out of resources\n",
2564 stat.un.lsRjtError);
2565 lpfc_vport_set_state(vport,
2566 FC_VPORT_NO_FABRIC_RSCS);
2570 case LSRJT_LOGICAL_BSY:
2571 if ((cmd == ELS_CMD_PLOGI) ||
2572 (cmd == ELS_CMD_PRLI)) {
2575 } else if (cmd == ELS_CMD_FDISC) {
2576 /* FDISC retry policy */
2578 if (cmdiocb->retry >= 32)
2584 case LSRJT_LOGICAL_ERR:
2585 /* There are some cases where switches return this
2586 * error when they are not ready and should be returning
2587 * Logical Busy. We should delay every time.
2589 if (cmd == ELS_CMD_FDISC &&
2590 stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
2596 case LSRJT_PROTOCOL_ERR:
2597 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2598 (cmd == ELS_CMD_FDISC) &&
2599 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
2600 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
2602 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2603 "0122 FDISC Failed (x%x). "
2604 "Fabric Detected Bad WWN\n",
2605 stat.un.lsRjtError);
2606 lpfc_vport_set_state(vport,
2607 FC_VPORT_FABRIC_REJ_WWN);
2613 case IOSTAT_INTERMED_RSP:
2621 if (did == FDMI_DID)
2624 if ((cmd == ELS_CMD_FLOGI) &&
2625 (phba->fc_topology != TOPOLOGY_LOOP) &&
2626 !lpfc_error_lost_link(irsp)) {
2627 /* FLOGI retry policy */
2630 if (cmdiocb->retry >= 32)
2634 if ((++cmdiocb->retry) >= maxretry) {
2635 phba->fc_stat.elsRetryExceeded++;
2639 if ((vport->load_flag & FC_UNLOADING) != 0)
2644 /* Retry ELS command <elsCmd> to remote NPORT <did> */
2645 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2646 "0107 Retry ELS command x%x to remote "
2647 "NPORT x%x Data: x%x x%x\n",
2648 cmd, did, cmdiocb->retry, delay);
2650 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
2651 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
2652 ((irsp->un.ulpWord[4] & 0xff) != IOERR_NO_RESOURCES))) {
2653 /* Don't reset timer for no resources */
2655 /* If discovery / RSCN timer is running, reset it */
2656 if (timer_pending(&vport->fc_disctmo) ||
2657 (vport->fc_flag & FC_RSCN_MODE))
2658 lpfc_set_disctmo(vport);
2661 phba->fc_stat.elsXmitRetry++;
2662 if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) {
2663 phba->fc_stat.elsDelayRetry++;
2664 ndlp->nlp_retry = cmdiocb->retry;
2666 /* delay is specified in milliseconds */
2667 mod_timer(&ndlp->nlp_delayfunc,
2668 jiffies + msecs_to_jiffies(delay));
2669 spin_lock_irq(shost->host_lock);
2670 ndlp->nlp_flag |= NLP_DELAY_TMO;
2671 spin_unlock_irq(shost->host_lock);
2673 ndlp->nlp_prev_state = ndlp->nlp_state;
2674 if (cmd == ELS_CMD_PRLI)
2675 lpfc_nlp_set_state(vport, ndlp,
2676 NLP_STE_REG_LOGIN_ISSUE);
2678 lpfc_nlp_set_state(vport, ndlp,
2680 ndlp->nlp_last_elscmd = cmd;
2686 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
2689 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
2692 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
2693 ndlp->nlp_prev_state = ndlp->nlp_state;
2694 lpfc_nlp_set_state(vport, ndlp,
2695 NLP_STE_PLOGI_ISSUE);
2697 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
2700 ndlp->nlp_prev_state = ndlp->nlp_state;
2701 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2702 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
2705 ndlp->nlp_prev_state = ndlp->nlp_state;
2706 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
2707 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
2710 ndlp->nlp_prev_state = ndlp->nlp_state;
2711 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2712 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
2716 /* No retry ELS command <elsCmd> to remote NPORT <did> */
2718 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2719 "0137 No retry ELS command x%x to remote "
2720 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
2721 cmd, did, irsp->ulpStatus,
2722 irsp->un.ulpWord[4]);
2725 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2726 "0108 No retry ELS command x%x to remote "
2727 "NPORT x%x Retried:%d Error:x%x/%x\n",
2728 cmd, did, cmdiocb->retry, irsp->ulpStatus,
2729 irsp->un.ulpWord[4]);
2735 * lpfc_els_free_data: Free lpfc dma buffer and data structure with an iocb.
2736 * @phba: pointer to lpfc hba data structure.
2737 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
2739 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
2740 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
2741 * checks to see whether there is a lpfc DMA buffer associated with the
2742 * response of the command IOCB. If so, it will be released before releasing
2743 * the lpfc DMA buffer associated with the IOCB itself.
2746 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
2749 lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
2751 struct lpfc_dmabuf *buf_ptr;
2753 /* Free the response before processing the command. */
2754 if (!list_empty(&buf_ptr1->list)) {
2755 list_remove_head(&buf_ptr1->list, buf_ptr,
2758 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
2761 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
2767 * lpfc_els_free_bpl: Free lpfc dma buffer and data structure with bpl.
2768 * @phba: pointer to lpfc hba data structure.
2769 * @buf_ptr: pointer to the lpfc dma buffer data structure.
2771 * This routine releases the lpfc Direct Memory Access (DMA) buffer
2772 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
2776 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
2779 lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
2781 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
2787 * lpfc_els_free_iocb: Free a command iocb and its associated resources.
2788 * @phba: pointer to lpfc hba data structure.
2789 * @elsiocb: pointer to lpfc els command iocb data structure.
2791 * This routine frees a command IOCB and its associated resources. The
2792 * command IOCB data structure contains the reference to various associated
2793 * resources, these fields must be set to NULL if the associated reference
2795 * context1 - reference to ndlp
2796 * context2 - reference to cmd
2797 * context2->next - reference to rsp
2798 * context3 - reference to bpl
2800 * It first properly decrements the reference count held on ndlp for the
2801 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
2802 * set, it invokes the lpfc_els_free_data() routine to release the Direct
2803 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
2804 * adds the DMA buffer the @phba data structure for the delayed release.
2805 * If reference to the Buffer Pointer List (BPL) is present, the
2806 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
2807 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
2808 * invoked to release the IOCB data structure back to @phba IOCBQ list.
2811 * 0 - Success (currently, always return 0)
2814 lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
2816 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
2817 struct lpfc_nodelist *ndlp;
2819 ndlp = (struct lpfc_nodelist *)elsiocb->context1;
2821 if (ndlp->nlp_flag & NLP_DEFER_RM) {
2824 /* If the ndlp is not being used by another discovery
2827 if (!lpfc_nlp_not_used(ndlp)) {
2828 /* If ndlp is being used by another discovery
2829 * thread, just clear NLP_DEFER_RM
2831 ndlp->nlp_flag &= ~NLP_DEFER_RM;
2836 elsiocb->context1 = NULL;
2838 /* context2 = cmd, context2->next = rsp, context3 = bpl */
2839 if (elsiocb->context2) {
2840 if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
2841 /* Firmware could still be in progress of DMAing
2842 * payload, so don't free data buffer till after
2845 elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
2846 buf_ptr = elsiocb->context2;
2847 elsiocb->context2 = NULL;
2850 spin_lock_irq(&phba->hbalock);
2851 if (!list_empty(&buf_ptr->list)) {
2852 list_remove_head(&buf_ptr->list,
2853 buf_ptr1, struct lpfc_dmabuf,
2855 INIT_LIST_HEAD(&buf_ptr1->list);
2856 list_add_tail(&buf_ptr1->list,
2860 INIT_LIST_HEAD(&buf_ptr->list);
2861 list_add_tail(&buf_ptr->list, &phba->elsbuf);
2863 spin_unlock_irq(&phba->hbalock);
2866 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
2867 lpfc_els_free_data(phba, buf_ptr1);
2871 if (elsiocb->context3) {
2872 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
2873 lpfc_els_free_bpl(phba, buf_ptr);
2875 lpfc_sli_release_iocbq(phba, elsiocb);
2880 * lpfc_cmpl_els_logo_acc: Completion callback function to logo acc response.
2881 * @phba: pointer to lpfc hba data structure.
2882 * @cmdiocb: pointer to lpfc command iocb data structure.
2883 * @rspiocb: pointer to lpfc response iocb data structure.
2885 * This routine is the completion callback function to the Logout (LOGO)
2886 * Accept (ACC) Response ELS command. This routine is invoked to indicate
2887 * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
2888 * release the ndlp if it has the last reference remaining (reference count
2889 * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
2890 * field to NULL to inform the following lpfc_els_free_iocb() routine no
2891 * ndlp reference count needs to be decremented. Otherwise, the ndlp
2892 * reference use-count shall be decremented by the lpfc_els_free_iocb()
2893 * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
2894 * IOCB data structure.
2897 lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2898 struct lpfc_iocbq *rspiocb)
2900 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2901 struct lpfc_vport *vport = cmdiocb->vport;
2904 irsp = &rspiocb->iocb;
2905 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2906 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
2907 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
2908 /* ACC to LOGO completes to NPort <nlp_DID> */
2909 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2910 "0109 ACC to LOGO completes to NPort x%x "
2911 "Data: x%x x%x x%x\n",
2912 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
2915 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
2916 /* NPort Recovery mode or node is just allocated */
2917 if (!lpfc_nlp_not_used(ndlp)) {
2918 /* If the ndlp is being used by another discovery
2919 * thread, just unregister the RPI.
2921 lpfc_unreg_rpi(vport, ndlp);
2923 /* Indicate the node has already released, should
2924 * not reference to it from within lpfc_els_free_iocb.
2926 cmdiocb->context1 = NULL;
2929 lpfc_els_free_iocb(phba, cmdiocb);
2934 * lpfc_mbx_cmpl_dflt_rpi: Completion callbk func for unreg dflt rpi mbox cmd.
2935 * @phba: pointer to lpfc hba data structure.
2936 * @pmb: pointer to the driver internal queue element for mailbox command.
2938 * This routine is the completion callback function for unregister default
2939 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
2940 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
2941 * decrements the ndlp reference count held for this completion callback
2942 * function. After that, it invokes the lpfc_nlp_not_used() to check
2943 * whether there is only one reference left on the ndlp. If so, it will
2944 * perform one more decrement and trigger the release of the ndlp.
2947 lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
2949 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
2950 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
2952 pmb->context1 = NULL;
2953 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2955 mempool_free(pmb, phba->mbox_mem_pool);
2956 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
2958 /* This is the end of the default RPI cleanup logic for this
2959 * ndlp. If no other discovery threads are using this ndlp.
2960 * we should free all resources associated with it.
2962 lpfc_nlp_not_used(ndlp);
2968 * lpfc_cmpl_els_rsp: Completion callback function for els response iocb cmd.
2969 * @phba: pointer to lpfc hba data structure.
2970 * @cmdiocb: pointer to lpfc command iocb data structure.
2971 * @rspiocb: pointer to lpfc response iocb data structure.
2973 * This routine is the completion callback function for ELS Response IOCB
2974 * command. In normal case, this callback function just properly sets the
2975 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
2976 * field in the command IOCB is not NULL, the referred mailbox command will
2977 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
2978 * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
2979 * link down event occurred during the discovery, the lpfc_nlp_not_used()
2980 * routine shall be invoked trying to release the ndlp if no other threads
2981 * are currently referring it.
2984 lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2985 struct lpfc_iocbq *rspiocb)
2987 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2988 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
2989 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
2992 LPFC_MBOXQ_t *mbox = NULL;
2993 struct lpfc_dmabuf *mp = NULL;
2994 uint32_t ls_rjt = 0;
2996 irsp = &rspiocb->iocb;
2998 if (cmdiocb->context_un.mbox)
2999 mbox = cmdiocb->context_un.mbox;
3001 /* First determine if this is a LS_RJT cmpl. Note, this callback
3002 * function can have cmdiocb->contest1 (ndlp) field set to NULL.
3004 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
3005 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3006 (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) {
3007 /* A LS_RJT associated with Default RPI cleanup has its own
3008 * seperate code path.
3010 if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
3014 /* Check to see if link went down during discovery */
3015 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) {
3017 mp = (struct lpfc_dmabuf *) mbox->context1;
3019 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3022 mempool_free(mbox, phba->mbox_mem_pool);
3024 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3025 (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
3026 if (lpfc_nlp_not_used(ndlp)) {
3028 /* Indicate the node has already released,
3029 * should not reference to it from within
3030 * the routine lpfc_els_free_iocb.
3032 cmdiocb->context1 = NULL;
3037 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3038 "ELS rsp cmpl: status:x%x/x%x did:x%x",
3039 irsp->ulpStatus, irsp->un.ulpWord[4],
3040 cmdiocb->iocb.un.elsreq64.remoteID);
3041 /* ELS response tag <ulpIoTag> completes */
3042 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3043 "0110 ELS response tag x%x completes "
3044 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
3045 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
3046 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
3047 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3050 if ((rspiocb->iocb.ulpStatus == 0)
3051 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
3052 lpfc_unreg_rpi(vport, ndlp);
3053 /* Increment reference count to ndlp to hold the
3054 * reference to ndlp for the callback function.
3056 mbox->context2 = lpfc_nlp_get(ndlp);
3057 mbox->vport = vport;
3058 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
3059 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
3060 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
3063 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
3064 ndlp->nlp_prev_state = ndlp->nlp_state;
3065 lpfc_nlp_set_state(vport, ndlp,
3066 NLP_STE_REG_LOGIN_ISSUE);
3068 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
3069 != MBX_NOT_FINISHED)
3072 /* Decrement the ndlp reference count we
3073 * set for this failed mailbox command.
3077 /* ELS rsp: Cannot issue reg_login for <NPortid> */
3078 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3079 "0138 ELS rsp: Cannot issue reg_login for x%x "
3080 "Data: x%x x%x x%x\n",
3081 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3084 if (lpfc_nlp_not_used(ndlp)) {
3086 /* Indicate node has already been released,
3087 * should not reference to it from within
3088 * the routine lpfc_els_free_iocb.
3090 cmdiocb->context1 = NULL;
3093 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
3094 if (!lpfc_error_lost_link(irsp) &&
3095 ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
3096 if (lpfc_nlp_not_used(ndlp)) {
3098 /* Indicate node has already been
3099 * released, should not reference
3100 * to it from within the routine
3101 * lpfc_els_free_iocb.
3103 cmdiocb->context1 = NULL;
3107 mp = (struct lpfc_dmabuf *) mbox->context1;
3109 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3112 mempool_free(mbox, phba->mbox_mem_pool);
3115 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
3116 spin_lock_irq(shost->host_lock);
3117 ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI);
3118 spin_unlock_irq(shost->host_lock);
3120 /* If the node is not being used by another discovery thread,
3121 * and we are sending a reject, we are done with it.
3122 * Release driver reference count here and free associated
3126 if (lpfc_nlp_not_used(ndlp))
3127 /* Indicate node has already been released,
3128 * should not reference to it from within
3129 * the routine lpfc_els_free_iocb.
3131 cmdiocb->context1 = NULL;
3134 lpfc_els_free_iocb(phba, cmdiocb);
3139 * lpfc_els_rsp_acc: Prepare and issue an acc response iocb command.
3140 * @vport: pointer to a host virtual N_Port data structure.
3141 * @flag: the els command code to be accepted.
3142 * @oldiocb: pointer to the original lpfc command iocb data structure.
3143 * @ndlp: pointer to a node-list data structure.
3144 * @mbox: pointer to the driver internal queue element for mailbox command.
3146 * This routine prepares and issues an Accept (ACC) response IOCB
3147 * command. It uses the @flag to properly set up the IOCB field for the
3148 * specific ACC response command to be issued and invokes the
3149 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
3150 * @mbox pointer is passed in, it will be put into the context_un.mbox
3151 * field of the IOCB for the completion callback function to issue the
3152 * mailbox command to the HBA later when callback is invoked.
3154 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3155 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3156 * will be stored into the context1 field of the IOCB for the completion
3157 * callback function to the corresponding response ELS IOCB command.
3160 * 0 - Successfully issued acc response
3161 * 1 - Failed to issue acc response
3164 lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
3165 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
3168 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3169 struct lpfc_hba *phba = vport->phba;
3172 struct lpfc_iocbq *elsiocb;
3173 struct lpfc_sli_ring *pring;
3174 struct lpfc_sli *psli;
3178 ELS_PKT *els_pkt_ptr;
3181 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
3182 oldcmd = &oldiocb->iocb;
3186 cmdsize = sizeof(uint32_t);
3187 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3188 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
3190 spin_lock_irq(shost->host_lock);
3191 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
3192 spin_unlock_irq(shost->host_lock);
3196 icmd = &elsiocb->iocb;
3197 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3198 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3199 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
3200 pcmd += sizeof(uint32_t);
3202 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3203 "Issue ACC: did:x%x flg:x%x",
3204 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3207 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
3208 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3209 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
3213 icmd = &elsiocb->iocb;
3214 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3215 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3218 elsiocb->context_un.mbox = mbox;
3220 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
3221 pcmd += sizeof(uint32_t);
3222 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
3224 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3225 "Issue ACC PLOGI: did:x%x flg:x%x",
3226 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3229 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
3230 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3231 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
3235 icmd = &elsiocb->iocb;
3236 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3237 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3239 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
3240 sizeof(uint32_t) + sizeof(PRLO));
3241 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
3242 els_pkt_ptr = (ELS_PKT *) pcmd;
3243 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
3245 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3246 "Issue ACC PRLO: did:x%x flg:x%x",
3247 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3252 /* Xmit ELS ACC response tag <ulpIoTag> */
3253 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3254 "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
3255 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n",
3256 elsiocb->iotag, elsiocb->iocb.ulpContext,
3257 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3259 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
3260 spin_lock_irq(shost->host_lock);
3261 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
3262 spin_unlock_irq(shost->host_lock);
3263 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
3265 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
3268 phba->fc_stat.elsXmitACC++;
3269 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
3270 if (rc == IOCB_ERROR) {
3271 lpfc_els_free_iocb(phba, elsiocb);
3278 * lpfc_els_rsp_reject: Propare and issue a rjt response iocb command.
3279 * @vport: pointer to a virtual N_Port data structure.
3281 * @oldiocb: pointer to the original lpfc command iocb data structure.
3282 * @ndlp: pointer to a node-list data structure.
3283 * @mbox: pointer to the driver internal queue element for mailbox command.
3285 * This routine prepares and issue an Reject (RJT) response IOCB
3286 * command. If a @mbox pointer is passed in, it will be put into the
3287 * context_un.mbox field of the IOCB for the completion callback function
3288 * to issue to the HBA later.
3290 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3291 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3292 * will be stored into the context1 field of the IOCB for the completion
3293 * callback function to the reject response ELS IOCB command.
3296 * 0 - Successfully issued reject response
3297 * 1 - Failed to issue reject response
3300 lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
3301 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
3304 struct lpfc_hba *phba = vport->phba;
3307 struct lpfc_iocbq *elsiocb;
3308 struct lpfc_sli_ring *pring;
3309 struct lpfc_sli *psli;
3315 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
3317 cmdsize = 2 * sizeof(uint32_t);
3318 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3319 ndlp->nlp_DID, ELS_CMD_LS_RJT);
3323 icmd = &elsiocb->iocb;
3324 oldcmd = &oldiocb->iocb;
3325 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3326 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3328 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
3329 pcmd += sizeof(uint32_t);
3330 *((uint32_t *) (pcmd)) = rejectError;
3333 elsiocb->context_un.mbox = mbox;
3335 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
3336 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3337 "0129 Xmit ELS RJT x%x response tag x%x "
3338 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
3340 rejectError, elsiocb->iotag,
3341 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
3342 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
3343 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3344 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
3345 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
3347 phba->fc_stat.elsXmitLSRJT++;
3348 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
3349 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
3351 if (rc == IOCB_ERROR) {
3352 lpfc_els_free_iocb(phba, elsiocb);
3359 * lpfc_els_rsp_adisc_acc: Prepare and issue acc response to adisc iocb cmd.
3360 * @vport: pointer to a virtual N_Port data structure.
3361 * @oldiocb: pointer to the original lpfc command iocb data structure.
3362 * @ndlp: pointer to a node-list data structure.
3364 * This routine prepares and issues an Accept (ACC) response to Address
3365 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
3366 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3368 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3369 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3370 * will be stored into the context1 field of the IOCB for the completion
3371 * callback function to the ADISC Accept response ELS IOCB command.
3374 * 0 - Successfully issued acc adisc response
3375 * 1 - Failed to issue adisc acc response
3378 lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
3379 struct lpfc_nodelist *ndlp)
3381 struct lpfc_hba *phba = vport->phba;
3382 struct lpfc_sli *psli = &phba->sli;
3383 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
3385 IOCB_t *icmd, *oldcmd;
3386 struct lpfc_iocbq *elsiocb;
3391 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
3392 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3393 ndlp->nlp_DID, ELS_CMD_ACC);
3397 icmd = &elsiocb->iocb;
3398 oldcmd = &oldiocb->iocb;
3399 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3401 /* Xmit ADISC ACC response tag <ulpIoTag> */
3402 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3403 "0130 Xmit ADISC ACC response iotag x%x xri: "
3404 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
3405 elsiocb->iotag, elsiocb->iocb.ulpContext,
3406 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3408 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3410 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
3411 pcmd += sizeof(uint32_t);
3413 ap = (ADISC *) (pcmd);
3414 ap->hardAL_PA = phba->fc_pref_ALPA;
3415 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
3416 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
3417 ap->DID = be32_to_cpu(vport->fc_myDID);
3419 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3420 "Issue ACC ADISC: did:x%x flg:x%x",
3421 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3423 phba->fc_stat.elsXmitACC++;
3424 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
3425 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
3426 if (rc == IOCB_ERROR) {
3427 lpfc_els_free_iocb(phba, elsiocb);
3434 * lpfc_els_rsp_prli_acc: Prepare and issue acc response to prli iocb cmd.
3435 * @vport: pointer to a virtual N_Port data structure.
3436 * @oldiocb: pointer to the original lpfc command iocb data structure.
3437 * @ndlp: pointer to a node-list data structure.
3439 * This routine prepares and issues an Accept (ACC) response to Process
3440 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
3441 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3443 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3444 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3445 * will be stored into the context1 field of the IOCB for the completion
3446 * callback function to the PRLI Accept response ELS IOCB command.
3449 * 0 - Successfully issued acc prli response
3450 * 1 - Failed to issue acc prli response
3453 lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
3454 struct lpfc_nodelist *ndlp)
3456 struct lpfc_hba *phba = vport->phba;
3461 struct lpfc_iocbq *elsiocb;
3462 struct lpfc_sli_ring *pring;
3463 struct lpfc_sli *psli;
3469 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
3471 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
3472 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3473 ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)));
3477 icmd = &elsiocb->iocb;
3478 oldcmd = &oldiocb->iocb;
3479 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3480 /* Xmit PRLI ACC response tag <ulpIoTag> */
3481 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3482 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
3483 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
3484 elsiocb->iotag, elsiocb->iocb.ulpContext,
3485 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3487 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3489 *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
3490 pcmd += sizeof(uint32_t);
3492 /* For PRLI, remainder of payload is PRLI parameter page */
3493 memset(pcmd, 0, sizeof(PRLI));
3495 npr = (PRLI *) pcmd;
3498 * If the remote port is a target and our firmware version is 3.20 or
3499 * later, set the following bits for FC-TAPE support.
3501 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
3502 (vpd->rev.feaLevelHigh >= 0x02)) {
3503 npr->ConfmComplAllowed = 1;
3505 npr->TaskRetryIdReq = 1;
3508 npr->acceptRspCode = PRLI_REQ_EXECUTED;
3509 npr->estabImagePair = 1;
3510 npr->readXferRdyDis = 1;
3511 npr->ConfmComplAllowed = 1;
3513 npr->prliType = PRLI_FCP_TYPE;
3514 npr->initiatorFunc = 1;
3516 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3517 "Issue ACC PRLI: did:x%x flg:x%x",
3518 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3520 phba->fc_stat.elsXmitACC++;
3521 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
3523 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
3524 if (rc == IOCB_ERROR) {
3525 lpfc_els_free_iocb(phba, elsiocb);
3532 * lpfc_els_rsp_rnid_acc: Issue rnid acc response iocb command.
3533 * @vport: pointer to a virtual N_Port data structure.
3534 * @format: rnid command format.
3535 * @oldiocb: pointer to the original lpfc command iocb data structure.
3536 * @ndlp: pointer to a node-list data structure.
3538 * This routine issues a Request Node Identification Data (RNID) Accept
3539 * (ACC) response. It constructs the RNID ACC response command according to
3540 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
3541 * issue the response. Note that this command does not need to hold the ndlp
3542 * reference count for the callback. So, the ndlp reference count taken by
3543 * the lpfc_prep_els_iocb() routine is put back and the context1 field of
3544 * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
3545 * there is no ndlp reference available.
3547 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3548 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3549 * will be stored into the context1 field of the IOCB for the completion
3550 * callback function. However, for the RNID Accept Response ELS command,
3551 * this is undone later by this routine after the IOCB is allocated.
3554 * 0 - Successfully issued acc rnid response
3555 * 1 - Failed to issue acc rnid response
3558 lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
3559 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
3561 struct lpfc_hba *phba = vport->phba;
3563 IOCB_t *icmd, *oldcmd;
3564 struct lpfc_iocbq *elsiocb;
3565 struct lpfc_sli_ring *pring;
3566 struct lpfc_sli *psli;
3572 pring = &psli->ring[LPFC_ELS_RING];
3574 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
3575 + (2 * sizeof(struct lpfc_name));
3577 cmdsize += sizeof(RNID_TOP_DISC);
3579 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3580 ndlp->nlp_DID, ELS_CMD_ACC);
3584 icmd = &elsiocb->iocb;
3585 oldcmd = &oldiocb->iocb;
3586 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3587 /* Xmit RNID ACC response tag <ulpIoTag> */
3588 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3589 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
3590 elsiocb->iotag, elsiocb->iocb.ulpContext);
3591 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3592 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
3593 pcmd += sizeof(uint32_t);
3595 memset(pcmd, 0, sizeof(RNID));
3596 rn = (RNID *) (pcmd);
3597 rn->Format = format;
3598 rn->CommonLen = (2 * sizeof(struct lpfc_name));
3599 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
3600 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
3603 rn->SpecificLen = 0;
3605 case RNID_TOPOLOGY_DISC:
3606 rn->SpecificLen = sizeof(RNID_TOP_DISC);
3607 memcpy(&rn->un.topologyDisc.portName,
3608 &vport->fc_portname, sizeof(struct lpfc_name));
3609 rn->un.topologyDisc.unitType = RNID_HBA;
3610 rn->un.topologyDisc.physPort = 0;
3611 rn->un.topologyDisc.attachedNodes = 0;
3615 rn->SpecificLen = 0;
3619 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3620 "Issue ACC RNID: did:x%x flg:x%x",
3621 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3623 phba->fc_stat.elsXmitACC++;
3624 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
3626 elsiocb->context1 = NULL; /* Don't need ndlp for cmpl,
3627 * it could be freed */
3629 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
3630 if (rc == IOCB_ERROR) {
3631 lpfc_els_free_iocb(phba, elsiocb);
3638 * lpfc_els_disc_adisc: Issue remaining adisc iocbs to npr nodes of a vport.
3639 * @vport: pointer to a host virtual N_Port data structure.
3641 * This routine issues Address Discover (ADISC) ELS commands to those
3642 * N_Ports which are in node port recovery state and ADISC has not been issued
3643 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
3644 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
3645 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
3646 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
3647 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
3648 * IOCBs quit for later pick up. On the other hand, after walking through
3649 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
3650 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
3651 * no more ADISC need to be sent.
3654 * The number of N_Ports with adisc issued.
3657 lpfc_els_disc_adisc(struct lpfc_vport *vport)
3659 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3660 struct lpfc_nodelist *ndlp, *next_ndlp;
3663 /* go thru NPR nodes and issue any remaining ELS ADISCs */
3664 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
3665 if (!NLP_CHK_NODE_ACT(ndlp))
3667 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
3668 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
3669 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
3670 spin_lock_irq(shost->host_lock);
3671 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
3672 spin_unlock_irq(shost->host_lock);
3673 ndlp->nlp_prev_state = ndlp->nlp_state;
3674 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
3675 lpfc_issue_els_adisc(vport, ndlp, 0);
3677 vport->num_disc_nodes++;
3678 if (vport->num_disc_nodes >=
3679 vport->cfg_discovery_threads) {
3680 spin_lock_irq(shost->host_lock);
3681 vport->fc_flag |= FC_NLP_MORE;
3682 spin_unlock_irq(shost->host_lock);
3687 if (sentadisc == 0) {
3688 spin_lock_irq(shost->host_lock);
3689 vport->fc_flag &= ~FC_NLP_MORE;
3690 spin_unlock_irq(shost->host_lock);
3696 * lpfc_els_disc_plogi: Issue plogi for all npr nodes of a vport before adisc.
3697 * @vport: pointer to a host virtual N_Port data structure.
3699 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
3700 * which are in node port recovery state, with a @vport. Each time an ELS
3701 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
3702 * the per @vport number of discover count (num_disc_nodes) shall be
3703 * incremented. If the num_disc_nodes reaches a pre-configured threshold
3704 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
3705 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
3706 * later pick up. On the other hand, after walking through all the ndlps with
3707 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
3708 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
3709 * PLOGI need to be sent.
3712 * The number of N_Ports with plogi issued.
3715 lpfc_els_disc_plogi(struct lpfc_vport *vport)
3717 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3718 struct lpfc_nodelist *ndlp, *next_ndlp;
3721 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
3722 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
3723 if (!NLP_CHK_NODE_ACT(ndlp))
3725 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
3726 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
3727 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
3728 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
3729 ndlp->nlp_prev_state = ndlp->nlp_state;
3730 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
3731 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
3733 vport->num_disc_nodes++;
3734 if (vport->num_disc_nodes >=
3735 vport->cfg_discovery_threads) {
3736 spin_lock_irq(shost->host_lock);
3737 vport->fc_flag |= FC_NLP_MORE;
3738 spin_unlock_irq(shost->host_lock);
3744 lpfc_set_disctmo(vport);
3747 spin_lock_irq(shost->host_lock);
3748 vport->fc_flag &= ~FC_NLP_MORE;
3749 spin_unlock_irq(shost->host_lock);
3755 * lpfc_els_flush_rscn: Clean up any rscn activities with a vport.
3756 * @vport: pointer to a host virtual N_Port data structure.
3758 * This routine cleans up any Registration State Change Notification
3759 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
3760 * @vport together with the host_lock is used to prevent multiple thread
3761 * trying to access the RSCN array on a same @vport at the same time.
3764 lpfc_els_flush_rscn(struct lpfc_vport *vport)
3766 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3767 struct lpfc_hba *phba = vport->phba;
3770 spin_lock_irq(shost->host_lock);
3771 if (vport->fc_rscn_flush) {
3772 /* Another thread is walking fc_rscn_id_list on this vport */
3773 spin_unlock_irq(shost->host_lock);
3776 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
3777 vport->fc_rscn_flush = 1;
3778 spin_unlock_irq(shost->host_lock);
3780 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
3781 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
3782 vport->fc_rscn_id_list[i] = NULL;
3784 spin_lock_irq(shost->host_lock);
3785 vport->fc_rscn_id_cnt = 0;
3786 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
3787 spin_unlock_irq(shost->host_lock);
3788 lpfc_can_disctmo(vport);
3789 /* Indicate we are done walking this fc_rscn_id_list */
3790 vport->fc_rscn_flush = 0;
3794 * lpfc_rscn_payload_check: Check whether there is a pending rscn to a did.
3795 * @vport: pointer to a host virtual N_Port data structure.
3796 * @did: remote destination port identifier.
3798 * This routine checks whether there is any pending Registration State
3799 * Configuration Notification (RSCN) to a @did on @vport.
3802 * None zero - The @did matched with a pending rscn
3803 * 0 - not able to match @did with a pending rscn
3806 lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
3811 uint32_t payload_len, i;
3812 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3814 ns_did.un.word = did;
3816 /* Never match fabric nodes for RSCNs */
3817 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
3820 /* If we are doing a FULL RSCN rediscovery, match everything */
3821 if (vport->fc_flag & FC_RSCN_DISCOVERY)
3824 spin_lock_irq(shost->host_lock);
3825 if (vport->fc_rscn_flush) {
3826 /* Another thread is walking fc_rscn_id_list on this vport */
3827 spin_unlock_irq(shost->host_lock);
3830 /* Indicate we are walking fc_rscn_id_list on this vport */
3831 vport->fc_rscn_flush = 1;
3832 spin_unlock_irq(shost->host_lock);
3833 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
3834 lp = vport->fc_rscn_id_list[i]->virt;
3835 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
3836 payload_len -= sizeof(uint32_t); /* take off word 0 */
3837 while (payload_len) {
3838 rscn_did.un.word = be32_to_cpu(*lp++);
3839 payload_len -= sizeof(uint32_t);
3840 switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) {
3841 case RSCN_ADDRESS_FORMAT_PORT:
3842 if (ns_did.un.word == rscn_did.un.word)
3843 goto return_did_out;
3845 case RSCN_ADDRESS_FORMAT_AREA:
3846 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
3847 && (ns_did.un.b.area == rscn_did.un.b.area))
3848 goto return_did_out;
3850 case RSCN_ADDRESS_FORMAT_DOMAIN:
3851 if (ns_did.un.b.domain == rscn_did.un.b.domain)
3852 goto return_did_out;
3854 case RSCN_ADDRESS_FORMAT_FABRIC:
3855 goto return_did_out;
3859 /* Indicate we are done with walking fc_rscn_id_list on this vport */
3860 vport->fc_rscn_flush = 0;
3863 /* Indicate we are done with walking fc_rscn_id_list on this vport */
3864 vport->fc_rscn_flush = 0;
3869 * lpfc_rscn_recovery_check: Send recovery event to vport nodes matching rscn
3870 * @vport: pointer to a host virtual N_Port data structure.
3872 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
3873 * state machine for a @vport's nodes that are with pending RSCN (Registration
3874 * State Change Notification).
3877 * 0 - Successful (currently alway return 0)
3880 lpfc_rscn_recovery_check(struct lpfc_vport *vport)
3882 struct lpfc_nodelist *ndlp = NULL;
3884 /* Move all affected nodes by pending RSCNs to NPR state. */
3885 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
3886 if (!NLP_CHK_NODE_ACT(ndlp) ||
3887 (ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
3888 !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
3890 lpfc_disc_state_machine(vport, ndlp, NULL,
3891 NLP_EVT_DEVICE_RECOVERY);
3892 lpfc_cancel_retry_delay_tmo(vport, ndlp);
3898 * lpfc_send_rscn_event: Send an RSCN event to management application.
3899 * @vport: pointer to a host virtual N_Port data structure.
3900 * @cmdiocb: pointer to lpfc command iocb data structure.
3902 * lpfc_send_rscn_event sends an RSCN netlink event to management
3906 lpfc_send_rscn_event(struct lpfc_vport *vport,
3907 struct lpfc_iocbq *cmdiocb)
3909 struct lpfc_dmabuf *pcmd;
3910 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3911 uint32_t *payload_ptr;
3912 uint32_t payload_len;
3913 struct lpfc_rscn_event_header *rscn_event_data;
3915 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3916 payload_ptr = (uint32_t *) pcmd->virt;
3917 payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK);
3919 rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) +
3920 payload_len, GFP_KERNEL);
3921 if (!rscn_event_data) {
3922 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3923 "0147 Failed to allocate memory for RSCN event\n");
3926 rscn_event_data->event_type = FC_REG_RSCN_EVENT;
3927 rscn_event_data->payload_length = payload_len;
3928 memcpy(rscn_event_data->rscn_payload, payload_ptr,
3931 fc_host_post_vendor_event(shost,
3932 fc_get_event_number(),
3933 sizeof(struct lpfc_els_event_header) + payload_len,
3934 (char *)rscn_event_data,
3937 kfree(rscn_event_data);
3941 * lpfc_els_rcv_rscn: Process an unsolicited rscn iocb.
3942 * @vport: pointer to a host virtual N_Port data structure.
3943 * @cmdiocb: pointer to lpfc command iocb data structure.
3944 * @ndlp: pointer to a node-list data structure.
3946 * This routine processes an unsolicited RSCN (Registration State Change
3947 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
3948 * to invoke fc_host_post_event() routine to the FC transport layer. If the
3949 * discover state machine is about to begin discovery, it just accepts the
3950 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
3951 * contains N_Port IDs for other vports on this HBA, it just accepts the
3952 * RSCN and ignore processing it. If the state machine is in the recovery
3953 * state, the fc_rscn_id_list of this @vport is walked and the
3954 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
3955 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
3956 * routine is invoked to handle the RSCN event.
3959 * 0 - Just sent the acc response
3960 * 1 - Sent the acc response and waited for name server completion
3963 lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3964 struct lpfc_nodelist *ndlp)
3966 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3967 struct lpfc_hba *phba = vport->phba;
3968 struct lpfc_dmabuf *pcmd;
3969 uint32_t *lp, *datap;
3971 uint32_t payload_len, length, nportid, *cmd;
3973 int rscn_id = 0, hba_id = 0;
3976 icmd = &cmdiocb->iocb;
3977 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3978 lp = (uint32_t *) pcmd->virt;
3980 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
3981 payload_len -= sizeof(uint32_t); /* take off word 0 */
3983 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
3984 "0214 RSCN received Data: x%x x%x x%x x%x\n",
3985 vport->fc_flag, payload_len, *lp,
3986 vport->fc_rscn_id_cnt);
3988 /* Send an RSCN event to the management application */
3989 lpfc_send_rscn_event(vport, cmdiocb);
3991 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
3992 fc_host_post_event(shost, fc_get_event_number(),
3993 FCH_EVT_RSCN, lp[i]);
3995 /* If we are about to begin discovery, just ACC the RSCN.
3996 * Discovery processing will satisfy it.
3998 if (vport->port_state <= LPFC_NS_QRY) {
3999 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4000 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
4001 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4003 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
4007 /* If this RSCN just contains NPortIDs for other vports on this HBA,
4008 * just ACC and ignore it.
4010 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
4011 !(vport->cfg_peer_port_login)) {
4016 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
4017 i -= sizeof(uint32_t);
4019 if (lpfc_find_vport_by_did(phba, nportid))
4022 if (rscn_id == hba_id) {
4023 /* ALL NPortIDs in RSCN are on HBA */
4024 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4026 "Data: x%x x%x x%x x%x\n",
4027 vport->fc_flag, payload_len,
4028 *lp, vport->fc_rscn_id_cnt);
4029 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4030 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
4031 ndlp->nlp_DID, vport->port_state,
4034 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
4040 spin_lock_irq(shost->host_lock);
4041 if (vport->fc_rscn_flush) {
4042 /* Another thread is walking fc_rscn_id_list on this vport */
4043 spin_unlock_irq(shost->host_lock);
4044 vport->fc_flag |= FC_RSCN_DISCOVERY;
4046 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
4049 /* Indicate we are walking fc_rscn_id_list on this vport */
4050 vport->fc_rscn_flush = 1;
4051 spin_unlock_irq(shost->host_lock);
4052 /* Get the array count after sucessfully have the token */
4053 rscn_cnt = vport->fc_rscn_id_cnt;
4054 /* If we are already processing an RSCN, save the received
4055 * RSCN payload buffer, cmdiocb->context2 to process later.
4057 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
4058 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4059 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
4060 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4062 spin_lock_irq(shost->host_lock);
4063 vport->fc_flag |= FC_RSCN_DEFERRED;
4064 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
4065 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
4066 vport->fc_flag |= FC_RSCN_MODE;
4067 spin_unlock_irq(shost->host_lock);
4069 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
4070 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
4073 (payload_len + length <= LPFC_BPL_SIZE)) {
4074 *cmd &= ELS_CMD_MASK;
4075 *cmd |= cpu_to_be32(payload_len + length);
4076 memcpy(((uint8_t *)cmd) + length, lp,
4079 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
4080 vport->fc_rscn_id_cnt++;
4081 /* If we zero, cmdiocb->context2, the calling
4082 * routine will not try to free it.
4084 cmdiocb->context2 = NULL;
4087 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4088 "0235 Deferred RSCN "
4089 "Data: x%x x%x x%x\n",
4090 vport->fc_rscn_id_cnt, vport->fc_flag,
4093 vport->fc_flag |= FC_RSCN_DISCOVERY;
4094 spin_unlock_irq(shost->host_lock);
4095 /* ReDiscovery RSCN */
4096 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4097 "0234 ReDiscovery RSCN "
4098 "Data: x%x x%x x%x\n",
4099 vport->fc_rscn_id_cnt, vport->fc_flag,
4102 /* Indicate we are done walking fc_rscn_id_list on this vport */
4103 vport->fc_rscn_flush = 0;
4105 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
4106 /* send RECOVERY event for ALL nodes that match RSCN payload */
4107 lpfc_rscn_recovery_check(vport);
4108 spin_lock_irq(shost->host_lock);
4109 vport->fc_flag &= ~FC_RSCN_DEFERRED;
4110 spin_unlock_irq(shost->host_lock);
4113 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4114 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
4115 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4117 spin_lock_irq(shost->host_lock);
4118 vport->fc_flag |= FC_RSCN_MODE;
4119 spin_unlock_irq(shost->host_lock);
4120 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
4121 /* Indicate we are done walking fc_rscn_id_list on this vport */
4122 vport->fc_rscn_flush = 0;
4124 * If we zero, cmdiocb->context2, the calling routine will
4125 * not try to free it.
4127 cmdiocb->context2 = NULL;
4128 lpfc_set_disctmo(vport);
4130 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
4131 /* send RECOVERY event for ALL nodes that match RSCN payload */
4132 lpfc_rscn_recovery_check(vport);
4133 return lpfc_els_handle_rscn(vport);
4137 * lpfc_els_handle_rscn: Handle rscn for a vport.
4138 * @vport: pointer to a host virtual N_Port data structure.
4140 * This routine handles the Registration State Configuration Notification
4141 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
4142 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
4143 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
4144 * NameServer shall be issued. If CT command to the NameServer fails to be
4145 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
4146 * RSCN activities with the @vport.
4149 * 0 - Cleaned up rscn on the @vport
4150 * 1 - Wait for plogi to name server before proceed
4153 lpfc_els_handle_rscn(struct lpfc_vport *vport)
4155 struct lpfc_nodelist *ndlp;
4156 struct lpfc_hba *phba = vport->phba;
4158 /* Ignore RSCN if the port is being torn down. */
4159 if (vport->load_flag & FC_UNLOADING) {
4160 lpfc_els_flush_rscn(vport);
4164 /* Start timer for RSCN processing */
4165 lpfc_set_disctmo(vport);
4167 /* RSCN processed */
4168 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4169 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
4170 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
4173 /* To process RSCN, first compare RSCN data with NameServer */
4174 vport->fc_ns_retry = 0;
4175 vport->num_disc_nodes = 0;
4177 ndlp = lpfc_findnode_did(vport, NameServer_DID);
4178 if (ndlp && NLP_CHK_NODE_ACT(ndlp)
4179 && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
4180 /* Good ndlp, issue CT Request to NameServer */
4181 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0)
4182 /* Wait for NameServer query cmpl before we can
4186 /* If login to NameServer does not exist, issue one */
4187 /* Good status, issue PLOGI to NameServer */
4188 ndlp = lpfc_findnode_did(vport, NameServer_DID);
4189 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
4190 /* Wait for NameServer login cmpl before we can
4195 ndlp = lpfc_enable_node(vport, ndlp,
4196 NLP_STE_PLOGI_ISSUE);
4198 lpfc_els_flush_rscn(vport);
4201 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
4203 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
4205 lpfc_els_flush_rscn(vport);
4208 lpfc_nlp_init(vport, ndlp, NameServer_DID);
4209 ndlp->nlp_prev_state = ndlp->nlp_state;
4210 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
4212 ndlp->nlp_type |= NLP_FABRIC;
4213 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
4214 /* Wait for NameServer login cmpl before we can
4220 lpfc_els_flush_rscn(vport);
4225 * lpfc_els_rcv_flogi: Process an unsolicited flogi iocb.
4226 * @vport: pointer to a host virtual N_Port data structure.
4227 * @cmdiocb: pointer to lpfc command iocb data structure.
4228 * @ndlp: pointer to a node-list data structure.
4230 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
4231 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
4232 * point topology. As an unsolicited FLOGI should not be received in a loop
4233 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
4234 * lpfc_check_sparm() routine is invoked to check the parameters in the
4235 * unsolicited FLOGI. If parameters validation failed, the routine
4236 * lpfc_els_rsp_reject() shall be called with reject reason code set to
4237 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
4238 * FLOGI shall be compared with the Port WWN of the @vport to determine who
4239 * will initiate PLOGI. The higher lexicographical value party shall has
4240 * higher priority (as the winning port) and will initiate PLOGI and
4241 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
4242 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
4243 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
4246 * 0 - Successfully processed the unsolicited flogi
4247 * 1 - Failed to process the unsolicited flogi
4250 lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4251 struct lpfc_nodelist *ndlp)
4253 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4254 struct lpfc_hba *phba = vport->phba;
4255 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4256 uint32_t *lp = (uint32_t *) pcmd->virt;
4257 IOCB_t *icmd = &cmdiocb->iocb;
4258 struct serv_parm *sp;
4265 sp = (struct serv_parm *) lp;
4267 /* FLOGI received */
4269 lpfc_set_disctmo(vport);
4271 if (phba->fc_topology == TOPOLOGY_LOOP) {
4272 /* We should never receive a FLOGI in loop mode, ignore it */
4273 did = icmd->un.elsreq64.remoteID;
4275 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
4277 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4278 "0113 An FLOGI ELS command x%x was "
4279 "received from DID x%x in Loop Mode\n",
4286 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3))) {
4287 /* For a FLOGI we accept, then if our portname is greater
4288 * then the remote portname we initiate Nport login.
4291 rc = memcmp(&vport->fc_portname, &sp->portName,
4292 sizeof(struct lpfc_name));
4295 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4299 lpfc_linkdown(phba);
4300 lpfc_init_link(phba, mbox,
4302 phba->cfg_link_speed);
4303 mbox->mb.un.varInitLnk.lipsr_AL_PA = 0;
4304 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
4305 mbox->vport = vport;
4306 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
4307 lpfc_set_loopback_flag(phba);
4308 if (rc == MBX_NOT_FINISHED) {
4309 mempool_free(mbox, phba->mbox_mem_pool);
4312 } else if (rc > 0) { /* greater than */
4313 spin_lock_irq(shost->host_lock);
4314 vport->fc_flag |= FC_PT2PT_PLOGI;
4315 spin_unlock_irq(shost->host_lock);
4317 spin_lock_irq(shost->host_lock);
4318 vport->fc_flag |= FC_PT2PT;
4319 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
4320 spin_unlock_irq(shost->host_lock);
4322 /* Reject this request because invalid parameters */
4323 stat.un.b.lsRjtRsvd0 = 0;
4324 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4325 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
4326 stat.un.b.vendorUnique = 0;
4327 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4333 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
4339 * lpfc_els_rcv_rnid: Process an unsolicited rnid iocb.
4340 * @vport: pointer to a host virtual N_Port data structure.
4341 * @cmdiocb: pointer to lpfc command iocb data structure.
4342 * @ndlp: pointer to a node-list data structure.
4344 * This routine processes Request Node Identification Data (RNID) IOCB
4345 * received as an ELS unsolicited event. Only when the RNID specified format
4346 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
4347 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
4348 * Accept (ACC) the RNID ELS command. All the other RNID formats are
4349 * rejected by invoking the lpfc_els_rsp_reject() routine.
4352 * 0 - Successfully processed rnid iocb (currently always return 0)
4355 lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4356 struct lpfc_nodelist *ndlp)
4358 struct lpfc_dmabuf *pcmd;
4365 icmd = &cmdiocb->iocb;
4366 did = icmd->un.elsreq64.remoteID;
4367 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4368 lp = (uint32_t *) pcmd->virt;
4375 switch (rn->Format) {
4377 case RNID_TOPOLOGY_DISC:
4379 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
4382 /* Reject this request because format not supported */
4383 stat.un.b.lsRjtRsvd0 = 0;
4384 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4385 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4386 stat.un.b.vendorUnique = 0;
4387 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4394 * lpfc_els_rcv_lirr: Process an unsolicited lirr iocb.
4395 * @vport: pointer to a host virtual N_Port data structure.
4396 * @cmdiocb: pointer to lpfc command iocb data structure.
4397 * @ndlp: pointer to a node-list data structure.
4399 * This routine processes a Link Incident Report Registration(LIRR) IOCB
4400 * received as an ELS unsolicited event. Currently, this function just invokes
4401 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
4404 * 0 - Successfully processed lirr iocb (currently always return 0)
4407 lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4408 struct lpfc_nodelist *ndlp)
4412 /* For now, unconditionally reject this command */
4413 stat.un.b.lsRjtRsvd0 = 0;
4414 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4415 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4416 stat.un.b.vendorUnique = 0;
4417 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
4422 * lpfc_els_rsp_rps_acc: Completion callbk func for MBX_READ_LNK_STAT mbox cmd.
4423 * @phba: pointer to lpfc hba data structure.
4424 * @pmb: pointer to the driver internal queue element for mailbox command.
4426 * This routine is the completion callback function for the MBX_READ_LNK_STAT
4427 * mailbox command. This callback function is to actually send the Accept
4428 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
4429 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
4430 * mailbox command, constructs the RPS response with the link statistics
4431 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
4432 * response to the RPS.
4434 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4435 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4436 * will be stored into the context1 field of the IOCB for the completion
4437 * callback function to the RPS Accept Response ELS IOCB command.
4441 lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4443 struct lpfc_sli *psli = &phba->sli;
4444 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
4449 struct lpfc_iocbq *elsiocb;
4450 struct lpfc_nodelist *ndlp;
4451 uint16_t xri, status;
4456 ndlp = (struct lpfc_nodelist *) pmb->context2;
4457 xri = (uint16_t) ((unsigned long)(pmb->context1));
4458 pmb->context1 = NULL;
4459 pmb->context2 = NULL;
4461 if (mb->mbxStatus) {
4462 mempool_free(pmb, phba->mbox_mem_pool);
4466 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
4467 mempool_free(pmb, phba->mbox_mem_pool);
4468 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
4469 lpfc_max_els_tries, ndlp,
4470 ndlp->nlp_DID, ELS_CMD_ACC);
4472 /* Decrement the ndlp reference count from previous mbox command */
4478 icmd = &elsiocb->iocb;
4479 icmd->ulpContext = xri;
4481 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4482 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4483 pcmd += sizeof(uint32_t); /* Skip past command */
4484 rps_rsp = (RPS_RSP *)pcmd;
4486 if (phba->fc_topology != TOPOLOGY_LOOP)
4490 if (phba->pport->fc_flag & FC_FABRIC)
4494 rps_rsp->portStatus = cpu_to_be16(status);
4495 rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
4496 rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
4497 rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
4498 rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
4499 rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
4500 rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
4501 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
4502 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
4503 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
4504 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
4505 elsiocb->iotag, elsiocb->iocb.ulpContext,
4506 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4508 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4509 phba->fc_stat.elsXmitACC++;
4510 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR)
4511 lpfc_els_free_iocb(phba, elsiocb);
4516 * lpfc_els_rcv_rps: Process an unsolicited rps iocb.
4517 * @vport: pointer to a host virtual N_Port data structure.
4518 * @cmdiocb: pointer to lpfc command iocb data structure.
4519 * @ndlp: pointer to a node-list data structure.
4521 * This routine processes Read Port Status (RPS) IOCB received as an
4522 * ELS unsolicited event. It first checks the remote port state. If the
4523 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
4524 * state, it invokes the lpfc_els_rsp_reject() routine to send the reject
4525 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
4526 * for reading the HBA link statistics. It is for the callback function,
4527 * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command
4528 * to actually sending out RPS Accept (ACC) response.
4531 * 0 - Successfully processed rps iocb (currently always return 0)
4534 lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4535 struct lpfc_nodelist *ndlp)
4537 struct lpfc_hba *phba = vport->phba;
4541 struct lpfc_dmabuf *pcmd;
4545 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
4546 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
4547 /* reject the unsolicited RPS request and done with it */
4550 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4551 lp = (uint32_t *) pcmd->virt;
4552 flag = (be32_to_cpu(*lp++) & 0xf);
4556 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
4557 ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
4558 sizeof(struct lpfc_name)) == 0))) {
4560 printk("Fix me....\n");
4562 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
4564 lpfc_read_lnk_stat(phba, mbox);
4566 (void *)((unsigned long) cmdiocb->iocb.ulpContext);
4567 mbox->context2 = lpfc_nlp_get(ndlp);
4568 mbox->vport = vport;
4569 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
4570 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
4571 != MBX_NOT_FINISHED)
4572 /* Mbox completion will send ELS Response */
4574 /* Decrement reference count used for the failed mbox
4578 mempool_free(mbox, phba->mbox_mem_pool);
4583 /* issue rejection response */
4584 stat.un.b.lsRjtRsvd0 = 0;
4585 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4586 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4587 stat.un.b.vendorUnique = 0;
4588 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
4593 * lpfc_els_rsp_rpl_acc: Issue an accept rpl els command.
4594 * @vport: pointer to a host virtual N_Port data structure.
4595 * @cmdsize: size of the ELS command.
4596 * @oldiocb: pointer to the original lpfc command iocb data structure.
4597 * @ndlp: pointer to a node-list data structure.
4599 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
4600 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
4602 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4603 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4604 * will be stored into the context1 field of the IOCB for the completion
4605 * callback function to the RPL Accept Response ELS command.
4608 * 0 - Successfully issued ACC RPL ELS command
4609 * 1 - Failed to issue ACC RPL ELS command
4612 lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
4613 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
4615 struct lpfc_hba *phba = vport->phba;
4616 IOCB_t *icmd, *oldcmd;
4618 struct lpfc_iocbq *elsiocb;
4619 struct lpfc_sli *psli = &phba->sli;
4620 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
4623 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4624 ndlp->nlp_DID, ELS_CMD_ACC);
4629 icmd = &elsiocb->iocb;
4630 oldcmd = &oldiocb->iocb;
4631 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
4633 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4634 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4635 pcmd += sizeof(uint16_t);
4636 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
4637 pcmd += sizeof(uint16_t);
4639 /* Setup the RPL ACC payload */
4640 rpl_rsp.listLen = be32_to_cpu(1);
4642 rpl_rsp.port_num_blk.portNum = 0;
4643 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
4644 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
4645 sizeof(struct lpfc_name));
4646 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
4647 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
4648 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4649 "0120 Xmit ELS RPL ACC response tag x%x "
4650 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
4652 elsiocb->iotag, elsiocb->iocb.ulpContext,
4653 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4655 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4656 phba->fc_stat.elsXmitACC++;
4657 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
4658 lpfc_els_free_iocb(phba, elsiocb);
4665 * lpfc_els_rcv_rpl: Process an unsolicited rpl iocb.
4666 * @vport: pointer to a host virtual N_Port data structure.
4667 * @cmdiocb: pointer to lpfc command iocb data structure.
4668 * @ndlp: pointer to a node-list data structure.
4670 * This routine processes Read Port List (RPL) IOCB received as an ELS
4671 * unsolicited event. It first checks the remote port state. If the remote
4672 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
4673 * invokes the lpfc_els_rsp_reject() routine to send reject response.
4674 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
4675 * to accept the RPL.
4678 * 0 - Successfully processed rpl iocb (currently always return 0)
4681 lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4682 struct lpfc_nodelist *ndlp)
4684 struct lpfc_dmabuf *pcmd;
4691 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
4692 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
4693 /* issue rejection response */
4694 stat.un.b.lsRjtRsvd0 = 0;
4695 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4696 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4697 stat.un.b.vendorUnique = 0;
4698 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4700 /* rejected the unsolicited RPL request and done with it */
4704 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4705 lp = (uint32_t *) pcmd->virt;
4706 rpl = (RPL *) (lp + 1);
4708 maxsize = be32_to_cpu(rpl->maxsize);
4710 /* We support only one port */
4711 if ((rpl->index == 0) &&
4713 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
4714 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
4716 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
4718 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
4724 * lpfc_els_rcv_farp: Process an unsolicited farp request els command.
4725 * @vport: pointer to a virtual N_Port data structure.
4726 * @cmdiocb: pointer to lpfc command iocb data structure.
4727 * @ndlp: pointer to a node-list data structure.
4729 * This routine processes Fibre Channel Address Resolution Protocol
4730 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
4731 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
4732 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
4733 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
4734 * remote PortName is compared against the FC PortName stored in the @vport
4735 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
4736 * compared against the FC NodeName stored in the @vport data structure.
4737 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
4738 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
4739 * invoked to send out FARP Response to the remote node. Before sending the
4740 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
4741 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
4742 * routine is invoked to log into the remote port first.
4745 * 0 - Either the FARP Match Mode not supported or successfully processed
4748 lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4749 struct lpfc_nodelist *ndlp)
4751 struct lpfc_dmabuf *pcmd;
4755 uint32_t cmd, cnt, did;
4757 icmd = &cmdiocb->iocb;
4758 did = icmd->un.elsreq64.remoteID;
4759 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4760 lp = (uint32_t *) pcmd->virt;
4764 /* FARP-REQ received from DID <did> */
4765 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4766 "0601 FARP-REQ received from DID x%x\n", did);
4767 /* We will only support match on WWPN or WWNN */
4768 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
4773 /* If this FARP command is searching for my portname */
4774 if (fp->Mflags & FARP_MATCH_PORT) {
4775 if (memcmp(&fp->RportName, &vport->fc_portname,
4776 sizeof(struct lpfc_name)) == 0)
4780 /* If this FARP command is searching for my nodename */
4781 if (fp->Mflags & FARP_MATCH_NODE) {
4782 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
4783 sizeof(struct lpfc_name)) == 0)
4788 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
4789 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
4790 /* Log back into the node before sending the FARP. */
4791 if (fp->Rflags & FARP_REQUEST_PLOGI) {
4792 ndlp->nlp_prev_state = ndlp->nlp_state;
4793 lpfc_nlp_set_state(vport, ndlp,
4794 NLP_STE_PLOGI_ISSUE);
4795 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
4798 /* Send a FARP response to that node */
4799 if (fp->Rflags & FARP_REQUEST_FARPR)
4800 lpfc_issue_els_farpr(vport, did, 0);
4807 * lpfc_els_rcv_farpr: Process an unsolicited farp response iocb.
4808 * @vport: pointer to a host virtual N_Port data structure.
4809 * @cmdiocb: pointer to lpfc command iocb data structure.
4810 * @ndlp: pointer to a node-list data structure.
4812 * This routine processes Fibre Channel Address Resolution Protocol
4813 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
4814 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
4815 * the FARP response request.
4818 * 0 - Successfully processed FARPR IOCB (currently always return 0)
4821 lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4822 struct lpfc_nodelist *ndlp)
4824 struct lpfc_dmabuf *pcmd;
4829 icmd = &cmdiocb->iocb;
4830 did = icmd->un.elsreq64.remoteID;
4831 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4832 lp = (uint32_t *) pcmd->virt;
4835 /* FARP-RSP received from DID <did> */
4836 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4837 "0600 FARP-RSP received from DID x%x\n", did);
4838 /* ACCEPT the Farp resp request */
4839 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
4845 * lpfc_els_rcv_fan: Process an unsolicited fan iocb command.
4846 * @vport: pointer to a host virtual N_Port data structure.
4847 * @cmdiocb: pointer to lpfc command iocb data structure.
4848 * @fan_ndlp: pointer to a node-list data structure.
4850 * This routine processes a Fabric Address Notification (FAN) IOCB
4851 * command received as an ELS unsolicited event. The FAN ELS command will
4852 * only be processed on a physical port (i.e., the @vport represents the
4853 * physical port). The fabric NodeName and PortName from the FAN IOCB are
4854 * compared against those in the phba data structure. If any of those is
4855 * different, the lpfc_initial_flogi() routine is invoked to initialize
4856 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
4857 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
4858 * is invoked to register login to the fabric.
4861 * 0 - Successfully processed fan iocb (currently always return 0).
4864 lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4865 struct lpfc_nodelist *fan_ndlp)
4867 struct lpfc_hba *phba = vport->phba;
4871 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
4872 lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
4874 /* FAN received; Fan does not have a reply sequence */
4875 if ((vport == phba->pport) &&
4876 (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
4877 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
4878 sizeof(struct lpfc_name))) ||
4879 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
4880 sizeof(struct lpfc_name)))) {
4881 /* This port has switched fabrics. FLOGI is required */
4882 lpfc_initial_flogi(vport);
4884 /* FAN verified - skip FLOGI */
4885 vport->fc_myDID = vport->fc_prevDID;
4886 lpfc_issue_fabric_reglogin(vport);
4893 * lpfc_els_timeout: Handler funciton to the els timer.
4894 * @ptr: holder for the timer function associated data.
4896 * This routine is invoked by the ELS timer after timeout. It posts the ELS
4897 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
4898 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
4899 * up the worker thread. It is for the worker thread to invoke the routine
4900 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
4903 lpfc_els_timeout(unsigned long ptr)
4905 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
4906 struct lpfc_hba *phba = vport->phba;
4907 uint32_t tmo_posted;
4908 unsigned long iflag;
4910 spin_lock_irqsave(&vport->work_port_lock, iflag);
4911 tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
4913 vport->work_port_events |= WORKER_ELS_TMO;
4914 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
4917 lpfc_worker_wake_up(phba);
4922 * lpfc_els_timeout_handler: Process an els timeout event.
4923 * @vport: pointer to a virtual N_Port data structure.
4925 * This routine is the actual handler function that processes an ELS timeout
4926 * event. It walks the ELS ring to get and abort all the IOCBs (except the
4927 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
4928 * invoking the lpfc_sli_issue_abort_iotag() routine.
4931 lpfc_els_timeout_handler(struct lpfc_vport *vport)
4933 struct lpfc_hba *phba = vport->phba;
4934 struct lpfc_sli_ring *pring;
4935 struct lpfc_iocbq *tmp_iocb, *piocb;
4937 struct lpfc_dmabuf *pcmd;
4938 uint32_t els_command = 0;
4940 uint32_t remote_ID = 0xffffffff;
4942 spin_lock_irq(&phba->hbalock);
4943 timeout = (uint32_t)(phba->fc_ratov << 1);
4945 pring = &phba->sli.ring[LPFC_ELS_RING];
4947 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
4950 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
4951 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
4952 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
4955 if (piocb->vport != vport)
4958 pcmd = (struct lpfc_dmabuf *) piocb->context2;
4960 els_command = *(uint32_t *) (pcmd->virt);
4962 if (els_command == ELS_CMD_FARP ||
4963 els_command == ELS_CMD_FARPR ||
4964 els_command == ELS_CMD_FDISC)
4967 if (piocb->drvrTimeout > 0) {
4968 if (piocb->drvrTimeout >= timeout)
4969 piocb->drvrTimeout -= timeout;
4971 piocb->drvrTimeout = 0;
4975 remote_ID = 0xffffffff;
4976 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
4977 remote_ID = cmd->un.elsreq64.remoteID;
4979 struct lpfc_nodelist *ndlp;
4980 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
4981 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
4982 remote_ID = ndlp->nlp_DID;
4984 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4985 "0127 ELS timeout Data: x%x x%x x%x "
4986 "x%x\n", els_command,
4987 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
4988 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
4990 spin_unlock_irq(&phba->hbalock);
4992 if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt)
4993 mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
4997 * lpfc_els_flush_cmd: Clean up the outstanding els commands to a vport.
4998 * @vport: pointer to a host virtual N_Port data structure.
5000 * This routine is used to clean up all the outstanding ELS commands on a
5001 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
5002 * routine. After that, it walks the ELS transmit queue to remove all the
5003 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
5004 * the IOCBs with a non-NULL completion callback function, the callback
5005 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
5006 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
5007 * callback function, the IOCB will simply be released. Finally, it walks
5008 * the ELS transmit completion queue to issue an abort IOCB to any transmit
5009 * completion queue IOCB that is associated with the @vport and is not
5010 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
5011 * part of the discovery state machine) out to HBA by invoking the
5012 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
5013 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
5014 * the IOCBs are aborted when this function returns.
5017 lpfc_els_flush_cmd(struct lpfc_vport *vport)
5019 LIST_HEAD(completions);
5020 struct lpfc_hba *phba = vport->phba;
5021 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
5022 struct lpfc_iocbq *tmp_iocb, *piocb;
5025 lpfc_fabric_abort_vport(vport);
5027 spin_lock_irq(&phba->hbalock);
5028 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
5031 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
5035 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
5036 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
5037 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
5038 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
5039 cmd->ulpCommand == CMD_ABORT_XRI_CN)
5042 if (piocb->vport != vport)
5045 list_move_tail(&piocb->list, &completions);
5049 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
5050 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
5054 if (piocb->vport != vport)
5057 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
5059 spin_unlock_irq(&phba->hbalock);
5061 while (!list_empty(&completions)) {
5062 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
5064 list_del_init(&piocb->list);
5066 if (!piocb->iocb_cmpl)
5067 lpfc_sli_release_iocbq(phba, piocb);
5069 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
5070 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
5071 (piocb->iocb_cmpl) (phba, piocb, piocb);
5079 * lpfc_els_flush_all_cmd: Clean up all the outstanding els commands to a HBA.
5080 * @phba: pointer to lpfc hba data structure.
5082 * This routine is used to clean up all the outstanding ELS commands on a
5083 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
5084 * routine. After that, it walks the ELS transmit queue to remove all the
5085 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
5086 * the IOCBs with the completion callback function associated, the callback
5087 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
5088 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
5089 * callback function associated, the IOCB will simply be released. Finally,
5090 * it walks the ELS transmit completion queue to issue an abort IOCB to any
5091 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
5092 * management plane IOCBs that are not part of the discovery state machine)
5093 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
5096 lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
5098 LIST_HEAD(completions);
5099 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
5100 struct lpfc_iocbq *tmp_iocb, *piocb;
5103 lpfc_fabric_abort_hba(phba);
5104 spin_lock_irq(&phba->hbalock);
5105 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
5107 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
5109 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
5110 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
5111 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
5112 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
5113 cmd->ulpCommand == CMD_ABORT_XRI_CN)
5115 list_move_tail(&piocb->list, &completions);
5118 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
5119 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
5121 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
5123 spin_unlock_irq(&phba->hbalock);
5124 while (!list_empty(&completions)) {
5125 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
5127 list_del_init(&piocb->list);
5128 if (!piocb->iocb_cmpl)
5129 lpfc_sli_release_iocbq(phba, piocb);
5131 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
5132 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
5133 (piocb->iocb_cmpl) (phba, piocb, piocb);
5140 * lpfc_send_els_failure_event: Posts an ELS command failure event.
5141 * @phba: Pointer to hba context object.
5142 * @cmdiocbp: Pointer to command iocb which reported error.
5143 * @rspiocbp: Pointer to response iocb which reported error.
5145 * This function sends an event when there is an ELS command
5149 lpfc_send_els_failure_event(struct lpfc_hba *phba,
5150 struct lpfc_iocbq *cmdiocbp,
5151 struct lpfc_iocbq *rspiocbp)
5153 struct lpfc_vport *vport = cmdiocbp->vport;
5154 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5155 struct lpfc_lsrjt_event lsrjt_event;
5156 struct lpfc_fabric_event_header fabric_event;
5158 struct lpfc_nodelist *ndlp;
5161 ndlp = cmdiocbp->context1;
5162 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
5165 if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) {
5166 lsrjt_event.header.event_type = FC_REG_ELS_EVENT;
5167 lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV;
5168 memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname,
5169 sizeof(struct lpfc_name));
5170 memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename,
5171 sizeof(struct lpfc_name));
5172 pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
5173 cmdiocbp->context2)->virt);
5174 lsrjt_event.command = *pcmd;
5175 stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]);
5176 lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode;
5177 lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp;
5178 fc_host_post_vendor_event(shost,
5179 fc_get_event_number(),
5180 sizeof(lsrjt_event),
5181 (char *)&lsrjt_event,
5185 if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) ||
5186 (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) {
5187 fabric_event.event_type = FC_REG_FABRIC_EVENT;
5188 if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY)
5189 fabric_event.subcategory = LPFC_EVENT_PORT_BUSY;
5191 fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY;
5192 memcpy(fabric_event.wwpn, &ndlp->nlp_portname,
5193 sizeof(struct lpfc_name));
5194 memcpy(fabric_event.wwnn, &ndlp->nlp_nodename,
5195 sizeof(struct lpfc_name));
5196 fc_host_post_vendor_event(shost,
5197 fc_get_event_number(),
5198 sizeof(fabric_event),
5199 (char *)&fabric_event,
5207 * lpfc_send_els_event: Posts unsolicited els event.
5208 * @vport: Pointer to vport object.
5209 * @ndlp: Pointer FC node object.
5210 * @cmd: ELS command code.
5212 * This function posts an event when there is an incoming
5213 * unsolicited ELS command.
5216 lpfc_send_els_event(struct lpfc_vport *vport,
5217 struct lpfc_nodelist *ndlp,
5220 struct lpfc_els_event_header *els_data = NULL;
5221 struct lpfc_logo_event *logo_data = NULL;
5222 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5224 if (*payload == ELS_CMD_LOGO) {
5225 logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL);
5227 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5228 "0148 Failed to allocate memory "
5229 "for LOGO event\n");
5232 els_data = &logo_data->header;
5234 els_data = kmalloc(sizeof(struct lpfc_els_event_header),
5237 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5238 "0149 Failed to allocate memory "
5243 els_data->event_type = FC_REG_ELS_EVENT;
5246 els_data->subcategory = LPFC_EVENT_PLOGI_RCV;
5249 els_data->subcategory = LPFC_EVENT_PRLO_RCV;
5252 els_data->subcategory = LPFC_EVENT_ADISC_RCV;
5255 els_data->subcategory = LPFC_EVENT_LOGO_RCV;
5256 /* Copy the WWPN in the LOGO payload */
5257 memcpy(logo_data->logo_wwpn, &payload[2],
5258 sizeof(struct lpfc_name));
5263 memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name));
5264 memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name));
5265 if (*payload == ELS_CMD_LOGO) {
5266 fc_host_post_vendor_event(shost,
5267 fc_get_event_number(),
5268 sizeof(struct lpfc_logo_event),
5273 fc_host_post_vendor_event(shost,
5274 fc_get_event_number(),
5275 sizeof(struct lpfc_els_event_header),
5286 * lpfc_els_unsol_buffer: Process an unsolicited event data buffer.
5287 * @phba: pointer to lpfc hba data structure.
5288 * @pring: pointer to a SLI ring.
5289 * @vport: pointer to a host virtual N_Port data structure.
5290 * @elsiocb: pointer to lpfc els command iocb data structure.
5292 * This routine is used for processing the IOCB associated with a unsolicited
5293 * event. It first determines whether there is an existing ndlp that matches
5294 * the DID from the unsolicited IOCB. If not, it will create a new one with
5295 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
5296 * IOCB is then used to invoke the proper routine and to set up proper state
5297 * of the discovery state machine.
5300 lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
5301 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
5303 struct Scsi_Host *shost;
5304 struct lpfc_nodelist *ndlp;
5307 uint32_t cmd, did, newnode, rjt_err = 0;
5308 IOCB_t *icmd = &elsiocb->iocb;
5310 if (!vport || !(elsiocb->context2))
5314 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
5316 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
5317 lpfc_post_buffer(phba, pring, 1);
5319 did = icmd->un.rcvels.remoteID;
5320 if (icmd->ulpStatus) {
5321 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5322 "RCV Unsol ELS: status:x%x/x%x did:x%x",
5323 icmd->ulpStatus, icmd->un.ulpWord[4], did);
5327 /* Check to see if link went down during discovery */
5328 if (lpfc_els_chk_latt(vport))
5331 /* Ignore traffic recevied during vport shutdown. */
5332 if (vport->load_flag & FC_UNLOADING)
5335 ndlp = lpfc_findnode_did(vport, did);
5337 /* Cannot find existing Fabric ndlp, so allocate a new one */
5338 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
5342 lpfc_nlp_init(vport, ndlp, did);
5343 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5345 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
5346 ndlp->nlp_type |= NLP_FABRIC;
5347 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
5348 ndlp = lpfc_enable_node(vport, ndlp,
5349 NLP_STE_UNUSED_NODE);
5352 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5354 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
5355 ndlp->nlp_type |= NLP_FABRIC;
5356 } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
5357 /* This is similar to the new node path */
5358 ndlp = lpfc_nlp_get(ndlp);
5361 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5365 phba->fc_stat.elsRcvFrame++;
5367 elsiocb->context1 = lpfc_nlp_get(ndlp);
5368 elsiocb->vport = vport;
5370 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
5371 cmd &= ELS_CMD_MASK;
5373 /* ELS command <elsCmd> received from NPORT <did> */
5374 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5375 "0112 ELS command x%x received from NPORT x%x "
5376 "Data: x%x\n", cmd, did, vport->port_state);
5379 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5380 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
5381 did, vport->port_state, ndlp->nlp_flag);
5383 phba->fc_stat.elsRcvPLOGI++;
5384 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
5386 lpfc_send_els_event(vport, ndlp, payload);
5387 if (vport->port_state < LPFC_DISC_AUTH) {
5388 if (!(phba->pport->fc_flag & FC_PT2PT) ||
5389 (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
5390 rjt_err = LSRJT_UNABLE_TPC;
5393 /* We get here, and drop thru, if we are PT2PT with
5394 * another NPort and the other side has initiated
5395 * the PLOGI before responding to our FLOGI.
5399 shost = lpfc_shost_from_vport(vport);
5400 spin_lock_irq(shost->host_lock);
5401 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
5402 spin_unlock_irq(shost->host_lock);
5404 lpfc_disc_state_machine(vport, ndlp, elsiocb,
5409 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5410 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
5411 did, vport->port_state, ndlp->nlp_flag);
5413 phba->fc_stat.elsRcvFLOGI++;
5414 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
5419 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5420 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
5421 did, vport->port_state, ndlp->nlp_flag);
5423 phba->fc_stat.elsRcvLOGO++;
5424 lpfc_send_els_event(vport, ndlp, payload);
5425 if (vport->port_state < LPFC_DISC_AUTH) {
5426 rjt_err = LSRJT_UNABLE_TPC;
5429 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
5432 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5433 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
5434 did, vport->port_state, ndlp->nlp_flag);
5436 phba->fc_stat.elsRcvPRLO++;
5437 lpfc_send_els_event(vport, ndlp, payload);
5438 if (vport->port_state < LPFC_DISC_AUTH) {
5439 rjt_err = LSRJT_UNABLE_TPC;
5442 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
5445 phba->fc_stat.elsRcvRSCN++;
5446 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
5451 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5452 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
5453 did, vport->port_state, ndlp->nlp_flag);
5455 lpfc_send_els_event(vport, ndlp, payload);
5456 phba->fc_stat.elsRcvADISC++;
5457 if (vport->port_state < LPFC_DISC_AUTH) {
5458 rjt_err = LSRJT_UNABLE_TPC;
5461 lpfc_disc_state_machine(vport, ndlp, elsiocb,
5465 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5466 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
5467 did, vport->port_state, ndlp->nlp_flag);
5469 phba->fc_stat.elsRcvPDISC++;
5470 if (vport->port_state < LPFC_DISC_AUTH) {
5471 rjt_err = LSRJT_UNABLE_TPC;
5474 lpfc_disc_state_machine(vport, ndlp, elsiocb,
5478 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5479 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
5480 did, vport->port_state, ndlp->nlp_flag);
5482 phba->fc_stat.elsRcvFARPR++;
5483 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
5486 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5487 "RCV FARP: did:x%x/ste:x%x flg:x%x",
5488 did, vport->port_state, ndlp->nlp_flag);
5490 phba->fc_stat.elsRcvFARP++;
5491 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
5494 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5495 "RCV FAN: did:x%x/ste:x%x flg:x%x",
5496 did, vport->port_state, ndlp->nlp_flag);
5498 phba->fc_stat.elsRcvFAN++;
5499 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
5502 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5503 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
5504 did, vport->port_state, ndlp->nlp_flag);
5506 phba->fc_stat.elsRcvPRLI++;
5507 if (vport->port_state < LPFC_DISC_AUTH) {
5508 rjt_err = LSRJT_UNABLE_TPC;
5511 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
5514 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5515 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
5516 did, vport->port_state, ndlp->nlp_flag);
5518 phba->fc_stat.elsRcvLIRR++;
5519 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
5524 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5525 "RCV RPS: did:x%x/ste:x%x flg:x%x",
5526 did, vport->port_state, ndlp->nlp_flag);
5528 phba->fc_stat.elsRcvRPS++;
5529 lpfc_els_rcv_rps(vport, elsiocb, ndlp);
5534 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5535 "RCV RPL: did:x%x/ste:x%x flg:x%x",
5536 did, vport->port_state, ndlp->nlp_flag);
5538 phba->fc_stat.elsRcvRPL++;
5539 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
5544 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5545 "RCV RNID: did:x%x/ste:x%x flg:x%x",
5546 did, vport->port_state, ndlp->nlp_flag);
5548 phba->fc_stat.elsRcvRNID++;
5549 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
5554 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5555 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
5556 cmd, did, vport->port_state);
5558 /* Unsupported ELS command, reject */
5559 rjt_err = LSRJT_INVALID_CMD;
5561 /* Unknown ELS command <elsCmd> received from NPORT <did> */
5562 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5563 "0115 Unknown ELS command x%x "
5564 "received from NPORT x%x\n", cmd, did);
5570 /* check if need to LS_RJT received ELS cmd */
5572 memset(&stat, 0, sizeof(stat));
5573 stat.un.b.lsRjtRsnCode = rjt_err;
5574 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
5575 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
5579 lpfc_nlp_put(elsiocb->context1);
5580 elsiocb->context1 = NULL;
5584 if (vport && !(vport->load_flag & FC_UNLOADING))
5585 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
5586 "(%d):0111 Dropping received ELS cmd "
5587 "Data: x%x x%x x%x\n",
5588 vport->vpi, icmd->ulpStatus,
5589 icmd->un.ulpWord[4], icmd->ulpTimeout);
5590 phba->fc_stat.elsRcvDrop++;
5594 * lpfc_find_vport_by_vpid: Find a vport on a HBA through vport identifier.
5595 * @phba: pointer to lpfc hba data structure.
5596 * @vpi: host virtual N_Port identifier.
5598 * This routine finds a vport on a HBA (referred by @phba) through a
5599 * @vpi. The function walks the HBA's vport list and returns the address
5600 * of the vport with the matching @vpi.
5603 * NULL - No vport with the matching @vpi found
5604 * Otherwise - Address to the vport with the matching @vpi.
5606 static struct lpfc_vport *
5607 lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi)
5609 struct lpfc_vport *vport;
5610 unsigned long flags;
5612 spin_lock_irqsave(&phba->hbalock, flags);
5613 list_for_each_entry(vport, &phba->port_list, listentry) {
5614 if (vport->vpi == vpi) {
5615 spin_unlock_irqrestore(&phba->hbalock, flags);
5619 spin_unlock_irqrestore(&phba->hbalock, flags);
5624 * lpfc_els_unsol_event: Process an unsolicited event from an els sli ring.
5625 * @phba: pointer to lpfc hba data structure.
5626 * @pring: pointer to a SLI ring.
5627 * @elsiocb: pointer to lpfc els iocb data structure.
5629 * This routine is used to process an unsolicited event received from a SLI
5630 * (Service Level Interface) ring. The actual processing of the data buffer
5631 * associated with the unsolicited event is done by invoking the routine
5632 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
5633 * SLI ring on which the unsolicited event was received.
5636 lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
5637 struct lpfc_iocbq *elsiocb)
5639 struct lpfc_vport *vport = phba->pport;
5640 IOCB_t *icmd = &elsiocb->iocb;
5642 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
5643 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
5645 elsiocb->context1 = NULL;
5646 elsiocb->context2 = NULL;
5647 elsiocb->context3 = NULL;
5649 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
5650 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
5651 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
5652 (icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING) {
5653 phba->fc_stat.NoRcvBuf++;
5654 /* Not enough posted buffers; Try posting more buffers */
5655 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
5656 lpfc_post_buffer(phba, pring, 0);
5660 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
5661 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
5662 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
5663 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
5664 vport = phba->pport;
5666 uint16_t vpi = icmd->unsli3.rcvsli3.vpi;
5667 vport = lpfc_find_vport_by_vpid(phba, vpi);
5670 /* If there are no BDEs associated
5671 * with this IOCB, there is nothing to do.
5673 if (icmd->ulpBdeCount == 0)
5676 /* type of ELS cmd is first 32bit word
5679 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
5680 elsiocb->context2 = bdeBuf1;
5682 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
5683 icmd->un.cont64[0].addrLow);
5684 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
5688 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
5690 * The different unsolicited event handlers would tell us
5691 * if they are done with "mp" by setting context2 to NULL.
5693 if (elsiocb->context2) {
5694 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
5695 elsiocb->context2 = NULL;
5698 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
5699 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
5700 icmd->ulpBdeCount == 2) {
5701 elsiocb->context2 = bdeBuf2;
5702 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
5703 /* free mp if we are done with it */
5704 if (elsiocb->context2) {
5705 lpfc_in_buf_free(phba, elsiocb->context2);
5706 elsiocb->context2 = NULL;
5712 * lpfc_do_scr_ns_plogi: Issue a plogi to the name server for scr.
5713 * @phba: pointer to lpfc hba data structure.
5714 * @vport: pointer to a virtual N_Port data structure.
5716 * This routine issues a Port Login (PLOGI) to the Name Server with
5717 * State Change Request (SCR) for a @vport. This routine will create an
5718 * ndlp for the Name Server associated to the @vport if such node does
5719 * not already exist. The PLOGI to Name Server is issued by invoking the
5720 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
5721 * (FDMI) is configured to the @vport, a FDMI node will be created and
5722 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
5725 lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
5727 struct lpfc_nodelist *ndlp, *ndlp_fdmi;
5729 ndlp = lpfc_findnode_did(vport, NameServer_DID);
5731 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
5733 if (phba->fc_topology == TOPOLOGY_LOOP) {
5734 lpfc_disc_start(vport);
5737 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
5738 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5739 "0251 NameServer login: no memory\n");
5742 lpfc_nlp_init(vport, ndlp, NameServer_DID);
5743 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
5744 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
5746 if (phba->fc_topology == TOPOLOGY_LOOP) {
5747 lpfc_disc_start(vport);
5750 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
5751 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5752 "0348 NameServer login: node freed\n");
5756 ndlp->nlp_type |= NLP_FABRIC;
5758 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
5760 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
5761 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
5762 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5763 "0252 Cannot issue NameServer login\n");
5767 if (vport->cfg_fdmi_on) {
5768 ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
5771 lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID);
5772 ndlp_fdmi->nlp_type |= NLP_FABRIC;
5773 lpfc_nlp_set_state(vport, ndlp_fdmi,
5774 NLP_STE_PLOGI_ISSUE);
5775 lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID,
5783 * lpfc_cmpl_reg_new_vport: Completion callback function to register new vport.
5784 * @phba: pointer to lpfc hba data structure.
5785 * @pmb: pointer to the driver internal queue element for mailbox command.
5787 * This routine is the completion callback function to register new vport
5788 * mailbox command. If the new vport mailbox command completes successfully,
5789 * the fabric registration login shall be performed on physical port (the
5790 * new vport created is actually a physical port, with VPI 0) or the port
5791 * login to Name Server for State Change Request (SCR) will be performed
5792 * on virtual port (real virtual port, with VPI greater than 0).
5795 lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
5797 struct lpfc_vport *vport = pmb->vport;
5798 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5799 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
5800 MAILBOX_t *mb = &pmb->mb;
5802 spin_lock_irq(shost->host_lock);
5803 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
5804 spin_unlock_irq(shost->host_lock);
5806 if (mb->mbxStatus) {
5807 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
5808 "0915 Register VPI failed: 0x%x\n",
5811 switch (mb->mbxStatus) {
5812 case 0x11: /* unsupported feature */
5813 case 0x9603: /* max_vpi exceeded */
5814 case 0x9602: /* Link event since CLEAR_LA */
5815 /* giving up on vport registration */
5816 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
5817 spin_lock_irq(shost->host_lock);
5818 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
5819 spin_unlock_irq(shost->host_lock);
5820 lpfc_can_disctmo(vport);
5823 /* Try to recover from this error */
5824 lpfc_mbx_unreg_vpi(vport);
5825 spin_lock_irq(shost->host_lock);
5826 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
5827 spin_unlock_irq(shost->host_lock);
5828 if (vport->port_type == LPFC_PHYSICAL_PORT)
5829 lpfc_initial_flogi(vport);
5831 lpfc_initial_fdisc(vport);
5836 if (vport == phba->pport)
5837 lpfc_issue_fabric_reglogin(vport);
5839 lpfc_do_scr_ns_plogi(phba, vport);
5842 /* Now, we decrement the ndlp reference count held for this
5847 mempool_free(pmb, phba->mbox_mem_pool);
5852 * lpfc_register_new_vport: Register a new vport with a HBA.
5853 * @phba: pointer to lpfc hba data structure.
5854 * @vport: pointer to a host virtual N_Port data structure.
5855 * @ndlp: pointer to a node-list data structure.
5857 * This routine registers the @vport as a new virtual port with a HBA.
5858 * It is done through a registering vpi mailbox command.
5861 lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
5862 struct lpfc_nodelist *ndlp)
5864 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5867 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5869 lpfc_reg_vpi(phba, vport->vpi, vport->fc_myDID, mbox);
5870 mbox->vport = vport;
5871 mbox->context2 = lpfc_nlp_get(ndlp);
5872 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
5873 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
5874 == MBX_NOT_FINISHED) {
5875 /* mailbox command not success, decrement ndlp
5876 * reference count for this command
5879 mempool_free(mbox, phba->mbox_mem_pool);
5881 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
5882 "0253 Register VPI: Can't send mbox\n");
5886 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
5887 "0254 Register VPI: no memory\n");
5893 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
5894 spin_lock_irq(shost->host_lock);
5895 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
5896 spin_unlock_irq(shost->host_lock);
5901 * lpfc_cmpl_els_fdisc: Completion function for fdisc iocb command.
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 a Fabric Discover
5907 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
5908 * single threaded, each FDISC completion callback function will reset
5909 * the discovery timer for all vports such that the timers will not get
5910 * unnecessary timeout. The function checks the FDISC IOCB status. If error
5911 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
5912 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
5913 * assigned to the vport has been changed with the completion of the FDISC
5914 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
5915 * are unregistered from the HBA, and then the lpfc_register_new_vport()
5916 * routine is invoked to register new vport with the HBA. Otherwise, the
5917 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
5918 * Server for State Change Request (SCR).
5921 lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
5922 struct lpfc_iocbq *rspiocb)
5924 struct lpfc_vport *vport = cmdiocb->vport;
5925 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5926 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
5927 struct lpfc_nodelist *np;
5928 struct lpfc_nodelist *next_np;
5929 IOCB_t *irsp = &rspiocb->iocb;
5930 struct lpfc_iocbq *piocb;
5932 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5933 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
5934 irsp->ulpStatus, irsp->un.ulpWord[4],
5936 /* Since all FDISCs are being single threaded, we
5937 * must reset the discovery timer for ALL vports
5938 * waiting to send FDISC when one completes.
5940 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
5941 lpfc_set_disctmo(piocb->vport);
5944 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
5945 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
5946 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
5948 if (irsp->ulpStatus) {
5949 /* Check for retry */
5950 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
5953 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5954 "0126 FDISC failed. (%d/%d)\n",
5955 irsp->ulpStatus, irsp->un.ulpWord[4]);
5958 if (vport->fc_vport->vport_state == FC_VPORT_INITIALIZING)
5959 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
5961 /* giving up on FDISC. Cancel discovery timer */
5962 lpfc_can_disctmo(vport);
5963 spin_lock_irq(shost->host_lock);
5964 vport->fc_flag |= FC_FABRIC;
5965 if (vport->phba->fc_topology == TOPOLOGY_LOOP)
5966 vport->fc_flag |= FC_PUBLIC_LOOP;
5967 spin_unlock_irq(shost->host_lock);
5969 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
5970 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
5971 if ((vport->fc_prevDID != vport->fc_myDID) &&
5972 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
5973 /* If our NportID changed, we need to ensure all
5974 * remaining NPORTs get unreg_login'ed so we can
5977 list_for_each_entry_safe(np, next_np,
5978 &vport->fc_nodes, nlp_listp) {
5979 if (!NLP_CHK_NODE_ACT(ndlp) ||
5980 (np->nlp_state != NLP_STE_NPR_NODE) ||
5981 !(np->nlp_flag & NLP_NPR_ADISC))
5983 spin_lock_irq(shost->host_lock);
5984 np->nlp_flag &= ~NLP_NPR_ADISC;
5985 spin_unlock_irq(shost->host_lock);
5986 lpfc_unreg_rpi(vport, np);
5988 lpfc_mbx_unreg_vpi(vport);
5989 spin_lock_irq(shost->host_lock);
5990 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
5991 spin_unlock_irq(shost->host_lock);
5994 if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
5995 lpfc_register_new_vport(phba, vport, ndlp);
5997 lpfc_do_scr_ns_plogi(phba, vport);
6000 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6001 /* Cancel discovery timer */
6002 lpfc_can_disctmo(vport);
6005 lpfc_els_free_iocb(phba, cmdiocb);
6009 * lpfc_issue_els_fdisc: Issue a fdisc iocb command.
6010 * @vport: pointer to a virtual N_Port data structure.
6011 * @ndlp: pointer to a node-list data structure.
6012 * @retry: number of retries to the command IOCB.
6014 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
6015 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
6016 * routine to issue the IOCB, which makes sure only one outstanding fabric
6017 * IOCB will be sent off HBA at any given time.
6019 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6020 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6021 * will be stored into the context1 field of the IOCB for the completion
6022 * callback function to the FDISC ELS command.
6025 * 0 - Successfully issued fdisc iocb command
6026 * 1 - Failed to issue fdisc iocb command
6029 lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
6032 struct lpfc_hba *phba = vport->phba;
6034 struct lpfc_iocbq *elsiocb;
6035 struct serv_parm *sp;
6038 int did = ndlp->nlp_DID;
6041 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
6042 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
6045 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6046 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6047 "0255 Issue FDISC: no IOCB\n");
6051 icmd = &elsiocb->iocb;
6052 icmd->un.elsreq64.myID = 0;
6053 icmd->un.elsreq64.fl = 1;
6055 /* For FDISC, Let FDISC rsp set the NPortID for this VPI */
6059 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6060 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
6061 pcmd += sizeof(uint32_t); /* CSP Word 1 */
6062 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
6063 sp = (struct serv_parm *) pcmd;
6064 /* Setup CSPs accordingly for Fabric */
6065 sp->cmn.e_d_tov = 0;
6066 sp->cmn.w2.r_a_tov = 0;
6067 sp->cls1.classValid = 0;
6068 sp->cls2.seqDelivery = 1;
6069 sp->cls3.seqDelivery = 1;
6071 pcmd += sizeof(uint32_t); /* CSP Word 2 */
6072 pcmd += sizeof(uint32_t); /* CSP Word 3 */
6073 pcmd += sizeof(uint32_t); /* CSP Word 4 */
6074 pcmd += sizeof(uint32_t); /* Port Name */
6075 memcpy(pcmd, &vport->fc_portname, 8);
6076 pcmd += sizeof(uint32_t); /* Node Name */
6077 pcmd += sizeof(uint32_t); /* Node Name */
6078 memcpy(pcmd, &vport->fc_nodename, 8);
6080 lpfc_set_disctmo(vport);
6082 phba->fc_stat.elsXmitFDISC++;
6083 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
6085 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6086 "Issue FDISC: did:x%x",
6089 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
6090 if (rc == IOCB_ERROR) {
6091 lpfc_els_free_iocb(phba, elsiocb);
6092 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6093 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6094 "0256 Issue FDISC: Cannot send IOCB\n");
6097 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
6098 vport->port_state = LPFC_FDISC;
6103 * lpfc_cmpl_els_npiv_logo: Completion function with vport logo.
6104 * @phba: pointer to lpfc hba data structure.
6105 * @cmdiocb: pointer to lpfc command iocb data structure.
6106 * @rspiocb: pointer to lpfc response iocb data structure.
6108 * This routine is the completion callback function to the issuing of a LOGO
6109 * ELS command off a vport. It frees the command IOCB and then decrement the
6110 * reference count held on ndlp for this completion function, indicating that
6111 * the reference to the ndlp is no long needed. Note that the
6112 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
6113 * callback function and an additional explicit ndlp reference decrementation
6114 * will trigger the actual release of the ndlp.
6117 lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
6118 struct lpfc_iocbq *rspiocb)
6120 struct lpfc_vport *vport = cmdiocb->vport;
6122 struct lpfc_nodelist *ndlp;
6123 ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
6125 irsp = &rspiocb->iocb;
6126 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6127 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
6128 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
6130 lpfc_els_free_iocb(phba, cmdiocb);
6131 vport->unreg_vpi_cmpl = VPORT_ERROR;
6133 /* Trigger the release of the ndlp after logo */
6138 * lpfc_issue_els_npiv_logo: Issue a logo off a vport.
6139 * @vport: pointer to a virtual N_Port data structure.
6140 * @ndlp: pointer to a node-list data structure.
6142 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
6144 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6145 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6146 * will be stored into the context1 field of the IOCB for the completion
6147 * callback function to the LOGO ELS command.
6150 * 0 - Successfully issued logo off the @vport
6151 * 1 - Failed to issue logo off the @vport
6154 lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
6156 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6157 struct lpfc_hba *phba = vport->phba;
6158 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
6160 struct lpfc_iocbq *elsiocb;
6164 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
6165 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
6170 icmd = &elsiocb->iocb;
6171 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6172 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
6173 pcmd += sizeof(uint32_t);
6175 /* Fill in LOGO payload */
6176 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
6177 pcmd += sizeof(uint32_t);
6178 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
6180 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6181 "Issue LOGO npiv did:x%x flg:x%x",
6182 ndlp->nlp_DID, ndlp->nlp_flag, 0);
6184 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
6185 spin_lock_irq(shost->host_lock);
6186 ndlp->nlp_flag |= NLP_LOGO_SND;
6187 spin_unlock_irq(shost->host_lock);
6188 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
6189 spin_lock_irq(shost->host_lock);
6190 ndlp->nlp_flag &= ~NLP_LOGO_SND;
6191 spin_unlock_irq(shost->host_lock);
6192 lpfc_els_free_iocb(phba, elsiocb);
6199 * lpfc_fabric_block_timeout: Handler function to the fabric block timer.
6200 * @ptr: holder for the timer function associated data.
6202 * This routine is invoked by the fabric iocb block timer after
6203 * timeout. It posts the fabric iocb block timeout event by setting the
6204 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
6205 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
6206 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
6207 * posted event WORKER_FABRIC_BLOCK_TMO.
6210 lpfc_fabric_block_timeout(unsigned long ptr)
6212 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
6213 unsigned long iflags;
6214 uint32_t tmo_posted;
6216 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
6217 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
6219 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
6220 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
6223 lpfc_worker_wake_up(phba);
6228 * lpfc_resume_fabric_iocbs: Issue a fabric iocb from driver internal list.
6229 * @phba: pointer to lpfc hba data structure.
6231 * This routine issues one fabric iocb from the driver internal list to
6232 * the HBA. It first checks whether it's ready to issue one fabric iocb to
6233 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
6234 * remove one pending fabric iocb from the driver internal list and invokes
6235 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
6238 lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
6240 struct lpfc_iocbq *iocb;
6241 unsigned long iflags;
6243 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
6248 spin_lock_irqsave(&phba->hbalock, iflags);
6249 /* Post any pending iocb to the SLI layer */
6250 if (atomic_read(&phba->fabric_iocb_count) == 0) {
6251 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
6254 /* Increment fabric iocb count to hold the position */
6255 atomic_inc(&phba->fabric_iocb_count);
6257 spin_unlock_irqrestore(&phba->hbalock, iflags);
6259 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
6260 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
6261 iocb->iocb_flag |= LPFC_IO_FABRIC;
6263 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
6264 "Fabric sched1: ste:x%x",
6265 iocb->vport->port_state, 0, 0);
6267 ret = lpfc_sli_issue_iocb(phba, pring, iocb, 0);
6269 if (ret == IOCB_ERROR) {
6270 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
6271 iocb->fabric_iocb_cmpl = NULL;
6272 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
6274 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
6275 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
6276 iocb->iocb_cmpl(phba, iocb, iocb);
6278 atomic_dec(&phba->fabric_iocb_count);
6287 * lpfc_unblock_fabric_iocbs: Unblock issuing fabric iocb command.
6288 * @phba: pointer to lpfc hba data structure.
6290 * This routine unblocks the issuing fabric iocb command. The function
6291 * will clear the fabric iocb block bit and then invoke the routine
6292 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
6293 * from the driver internal fabric iocb list.
6296 lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
6298 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
6300 lpfc_resume_fabric_iocbs(phba);
6305 * lpfc_block_fabric_iocbs: Block issuing fabric iocb command.
6306 * @phba: pointer to lpfc hba data structure.
6308 * This routine blocks the issuing fabric iocb for a specified amount of
6309 * time (currently 100 ms). This is done by set the fabric iocb block bit
6310 * and set up a timeout timer for 100ms. When the block bit is set, no more
6311 * fabric iocb will be issued out of the HBA.
6314 lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
6318 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
6319 /* Start a timer to unblock fabric iocbs after 100ms */
6321 mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 );
6327 * lpfc_cmpl_fabric_iocb: Completion callback function for fabric iocb.
6328 * @phba: pointer to lpfc hba data structure.
6329 * @cmdiocb: pointer to lpfc command iocb data structure.
6330 * @rspiocb: pointer to lpfc response iocb data structure.
6332 * This routine is the callback function that is put to the fabric iocb's
6333 * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
6334 * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
6335 * function first restores and invokes the original iocb's callback function
6336 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
6337 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
6340 lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
6341 struct lpfc_iocbq *rspiocb)
6345 if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC)
6348 switch (rspiocb->iocb.ulpStatus) {
6349 case IOSTAT_NPORT_RJT:
6350 case IOSTAT_FABRIC_RJT:
6351 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
6352 lpfc_block_fabric_iocbs(phba);
6356 case IOSTAT_NPORT_BSY:
6357 case IOSTAT_FABRIC_BSY:
6358 lpfc_block_fabric_iocbs(phba);
6362 stat.un.lsRjtError =
6363 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
6364 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
6365 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
6366 lpfc_block_fabric_iocbs(phba);
6370 if (atomic_read(&phba->fabric_iocb_count) == 0)
6373 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
6374 cmdiocb->fabric_iocb_cmpl = NULL;
6375 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
6376 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
6378 atomic_dec(&phba->fabric_iocb_count);
6379 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
6380 /* Post any pending iocbs to HBA */
6381 lpfc_resume_fabric_iocbs(phba);
6386 * lpfc_issue_fabric_iocb: Issue a fabric iocb command.
6387 * @phba: pointer to lpfc hba data structure.
6388 * @iocb: pointer to lpfc command iocb data structure.
6390 * This routine is used as the top-level API for issuing a fabric iocb command
6391 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
6392 * function makes sure that only one fabric bound iocb will be outstanding at
6393 * any given time. As such, this function will first check to see whether there
6394 * is already an outstanding fabric iocb on the wire. If so, it will put the
6395 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
6396 * issued later. Otherwise, it will issue the iocb on the wire and update the
6397 * fabric iocb count it indicate that there is one fabric iocb on the wire.
6399 * Note, this implementation has a potential sending out fabric IOCBs out of
6400 * order. The problem is caused by the construction of the "ready" boolen does
6401 * not include the condition that the internal fabric IOCB list is empty. As
6402 * such, it is possible a fabric IOCB issued by this routine might be "jump"
6403 * ahead of the fabric IOCBs in the internal list.
6406 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
6407 * IOCB_ERROR - failed to issue fabric iocb
6410 lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
6412 unsigned long iflags;
6413 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
6417 if (atomic_read(&phba->fabric_iocb_count) > 1)
6420 spin_lock_irqsave(&phba->hbalock, iflags);
6421 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
6422 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
6425 /* Increment fabric iocb count to hold the position */
6426 atomic_inc(&phba->fabric_iocb_count);
6427 spin_unlock_irqrestore(&phba->hbalock, iflags);
6429 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
6430 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
6431 iocb->iocb_flag |= LPFC_IO_FABRIC;
6433 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
6434 "Fabric sched2: ste:x%x",
6435 iocb->vport->port_state, 0, 0);
6437 ret = lpfc_sli_issue_iocb(phba, pring, iocb, 0);
6439 if (ret == IOCB_ERROR) {
6440 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
6441 iocb->fabric_iocb_cmpl = NULL;
6442 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
6443 atomic_dec(&phba->fabric_iocb_count);
6446 spin_lock_irqsave(&phba->hbalock, iflags);
6447 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
6448 spin_unlock_irqrestore(&phba->hbalock, iflags);
6455 * lpfc_fabric_abort_vport: Abort a vport's iocbs from driver fabric iocb list.
6456 * @vport: pointer to a virtual N_Port data structure.
6458 * This routine aborts all the IOCBs associated with a @vport from the
6459 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
6460 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
6461 * list, removes each IOCB associated with the @vport off the list, set the
6462 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
6463 * associated with the IOCB.
6465 static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
6467 LIST_HEAD(completions);
6468 struct lpfc_hba *phba = vport->phba;
6469 struct lpfc_iocbq *tmp_iocb, *piocb;
6472 spin_lock_irq(&phba->hbalock);
6473 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
6476 if (piocb->vport != vport)
6479 list_move_tail(&piocb->list, &completions);
6481 spin_unlock_irq(&phba->hbalock);
6483 while (!list_empty(&completions)) {
6484 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
6485 list_del_init(&piocb->list);
6488 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
6489 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
6490 (piocb->iocb_cmpl) (phba, piocb, piocb);
6495 * lpfc_fabric_abort_nport: Abort a ndlp's iocbs from driver fabric iocb list.
6496 * @ndlp: pointer to a node-list data structure.
6498 * This routine aborts all the IOCBs associated with an @ndlp from the
6499 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
6500 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
6501 * list, removes each IOCB associated with the @ndlp off the list, set the
6502 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
6503 * associated with the IOCB.
6505 void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
6507 LIST_HEAD(completions);
6508 struct lpfc_hba *phba = ndlp->vport->phba;
6509 struct lpfc_iocbq *tmp_iocb, *piocb;
6510 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
6513 spin_lock_irq(&phba->hbalock);
6514 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
6516 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
6518 list_move_tail(&piocb->list, &completions);
6521 spin_unlock_irq(&phba->hbalock);
6523 while (!list_empty(&completions)) {
6524 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
6525 list_del_init(&piocb->list);
6528 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
6529 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
6530 (piocb->iocb_cmpl) (phba, piocb, piocb);
6535 * lpfc_fabric_abort_hba: Abort all iocbs on driver fabric iocb list.
6536 * @phba: pointer to lpfc hba data structure.
6538 * This routine aborts all the IOCBs currently on the driver internal
6539 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
6540 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
6541 * list, removes IOCBs off the list, set the status feild to
6542 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
6545 void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
6547 LIST_HEAD(completions);
6548 struct lpfc_iocbq *piocb;
6551 spin_lock_irq(&phba->hbalock);
6552 list_splice_init(&phba->fabric_iocb_list, &completions);
6553 spin_unlock_irq(&phba->hbalock);
6555 while (!list_empty(&completions)) {
6556 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
6557 list_del_init(&piocb->list);
6560 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
6561 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
6562 (piocb->iocb_cmpl) (phba, piocb, piocb);