1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2009 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. *
7 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
9 * This program is free software; you can redistribute it and/or *
10 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
20 *******************************************************************/
21 /* See Fibre Channel protocol T11 FC-LS for details */
22 #include <linux/blkdev.h>
23 #include <linux/pci.h>
24 #include <linux/slab.h>
25 #include <linux/interrupt.h>
27 #include <scsi/scsi.h>
28 #include <scsi/scsi_device.h>
29 #include <scsi/scsi_host.h>
30 #include <scsi/scsi_transport_fc.h>
35 #include "lpfc_sli4.h"
37 #include "lpfc_disc.h"
38 #include "lpfc_scsi.h"
40 #include "lpfc_logmsg.h"
41 #include "lpfc_crtn.h"
42 #include "lpfc_vport.h"
43 #include "lpfc_debugfs.h"
45 static int lpfc_els_retry(struct lpfc_hba
*, struct lpfc_iocbq
*,
47 static void lpfc_cmpl_fabric_iocb(struct lpfc_hba
*, struct lpfc_iocbq
*,
49 static void lpfc_fabric_abort_vport(struct lpfc_vport
*vport
);
50 static int lpfc_issue_els_fdisc(struct lpfc_vport
*vport
,
51 struct lpfc_nodelist
*ndlp
, uint8_t retry
);
52 static int lpfc_issue_fabric_iocb(struct lpfc_hba
*phba
,
53 struct lpfc_iocbq
*iocb
);
55 static int lpfc_max_els_tries
= 3;
58 * lpfc_els_chk_latt - Check host link attention event for a vport
59 * @vport: pointer to a host virtual N_Port data structure.
61 * This routine checks whether there is an outstanding host link
62 * attention event during the discovery process with the @vport. It is done
63 * by reading the HBA's Host Attention (HA) register. If there is any host
64 * link attention events during this @vport's discovery process, the @vport
65 * shall be marked as FC_ABORT_DISCOVERY, a host link attention clear shall
66 * be issued if the link state is not already in host link cleared state,
67 * and a return code shall indicate whether the host link attention event
70 * Note that, if either the host link is in state LPFC_LINK_DOWN or @vport
71 * state in LPFC_VPORT_READY, the request for checking host link attention
72 * event will be ignored and a return code shall indicate no host link
73 * attention event had happened.
76 * 0 - no host link attention event happened
77 * 1 - host link attention event happened
80 lpfc_els_chk_latt(struct lpfc_vport
*vport
)
82 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
83 struct lpfc_hba
*phba
= vport
->phba
;
86 if (vport
->port_state
>= LPFC_VPORT_READY
||
87 phba
->link_state
== LPFC_LINK_DOWN
||
88 phba
->sli_rev
> LPFC_SLI_REV3
)
91 /* Read the HBA Host Attention Register */
92 ha_copy
= readl(phba
->HAregaddr
);
94 if (!(ha_copy
& HA_LATT
))
97 /* Pending Link Event during Discovery */
98 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
99 "0237 Pending Link Event during "
100 "Discovery: State x%x\n",
101 phba
->pport
->port_state
);
103 /* CLEAR_LA should re-enable link attention events and
104 * we should then imediately take a LATT event. The
105 * LATT processing should call lpfc_linkdown() which
106 * will cleanup any left over in-progress discovery
109 spin_lock_irq(shost
->host_lock
);
110 vport
->fc_flag
|= FC_ABORT_DISCOVERY
;
111 spin_unlock_irq(shost
->host_lock
);
113 if (phba
->link_state
!= LPFC_CLEAR_LA
)
114 lpfc_issue_clear_la(phba
, vport
);
120 * lpfc_prep_els_iocb - Allocate and prepare a lpfc iocb data structure
121 * @vport: pointer to a host virtual N_Port data structure.
122 * @expectRsp: flag indicating whether response is expected.
123 * @cmdSize: size of the ELS command.
124 * @retry: number of retries to the command IOCB when it fails.
125 * @ndlp: pointer to a node-list data structure.
126 * @did: destination identifier.
127 * @elscmd: the ELS command code.
129 * This routine is used for allocating a lpfc-IOCB data structure from
130 * the driver lpfc-IOCB free-list and prepare the IOCB with the parameters
131 * passed into the routine for discovery state machine to issue an Extended
132 * Link Service (ELS) commands. It is a generic lpfc-IOCB allocation
133 * and preparation routine that is used by all the discovery state machine
134 * routines and the ELS command-specific fields will be later set up by
135 * the individual discovery machine routines after calling this routine
136 * allocating and preparing a generic IOCB data structure. It fills in the
137 * Buffer Descriptor Entries (BDEs), allocates buffers for both command
138 * payload and response payload (if expected). The reference count on the
139 * ndlp is incremented by 1 and the reference to the ndlp is put into
140 * context1 of the IOCB data structure for this IOCB to hold the ndlp
141 * reference for the command's callback function to access later.
144 * Pointer to the newly allocated/prepared els iocb data structure
145 * NULL - when els iocb data structure allocation/preparation failed
148 lpfc_prep_els_iocb(struct lpfc_vport
*vport
, uint8_t expectRsp
,
149 uint16_t cmdSize
, uint8_t retry
,
150 struct lpfc_nodelist
*ndlp
, uint32_t did
,
153 struct lpfc_hba
*phba
= vport
->phba
;
154 struct lpfc_iocbq
*elsiocb
;
155 struct lpfc_dmabuf
*pcmd
, *prsp
, *pbuflist
;
156 struct ulp_bde64
*bpl
;
160 if (!lpfc_is_link_up(phba
))
163 /* Allocate buffer for command iocb */
164 elsiocb
= lpfc_sli_get_iocbq(phba
);
170 * If this command is for fabric controller and HBA running
171 * in FIP mode send FLOGI, FDISC and LOGO as FIP frames.
173 if ((did
== Fabric_DID
) &&
174 (phba
->hba_flag
& HBA_FIP_SUPPORT
) &&
175 ((elscmd
== ELS_CMD_FLOGI
) ||
176 (elscmd
== ELS_CMD_FDISC
) ||
177 (elscmd
== ELS_CMD_LOGO
)))
180 elsiocb
->iocb_flag
|= ((ELS_ID_FLOGI
<< LPFC_FIP_ELS_ID_SHIFT
)
181 & LPFC_FIP_ELS_ID_MASK
);
184 elsiocb
->iocb_flag
|= ((ELS_ID_FDISC
<< LPFC_FIP_ELS_ID_SHIFT
)
185 & LPFC_FIP_ELS_ID_MASK
);
188 elsiocb
->iocb_flag
|= ((ELS_ID_LOGO
<< LPFC_FIP_ELS_ID_SHIFT
)
189 & LPFC_FIP_ELS_ID_MASK
);
193 elsiocb
->iocb_flag
&= ~LPFC_FIP_ELS_ID_MASK
;
195 icmd
= &elsiocb
->iocb
;
197 /* fill in BDEs for command */
198 /* Allocate buffer for command payload */
199 pcmd
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
201 pcmd
->virt
= lpfc_mbuf_alloc(phba
, MEM_PRI
, &pcmd
->phys
);
202 if (!pcmd
|| !pcmd
->virt
)
203 goto els_iocb_free_pcmb_exit
;
205 INIT_LIST_HEAD(&pcmd
->list
);
207 /* Allocate buffer for response payload */
209 prsp
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
211 prsp
->virt
= lpfc_mbuf_alloc(phba
, MEM_PRI
,
213 if (!prsp
|| !prsp
->virt
)
214 goto els_iocb_free_prsp_exit
;
215 INIT_LIST_HEAD(&prsp
->list
);
219 /* Allocate buffer for Buffer ptr list */
220 pbuflist
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
222 pbuflist
->virt
= lpfc_mbuf_alloc(phba
, MEM_PRI
,
224 if (!pbuflist
|| !pbuflist
->virt
)
225 goto els_iocb_free_pbuf_exit
;
227 INIT_LIST_HEAD(&pbuflist
->list
);
229 icmd
->un
.elsreq64
.bdl
.addrHigh
= putPaddrHigh(pbuflist
->phys
);
230 icmd
->un
.elsreq64
.bdl
.addrLow
= putPaddrLow(pbuflist
->phys
);
231 icmd
->un
.elsreq64
.bdl
.bdeFlags
= BUFF_TYPE_BLP_64
;
232 icmd
->un
.elsreq64
.remoteID
= did
; /* DID */
234 icmd
->un
.elsreq64
.bdl
.bdeSize
= (2 * sizeof(struct ulp_bde64
));
235 icmd
->ulpCommand
= CMD_ELS_REQUEST64_CR
;
236 icmd
->ulpTimeout
= phba
->fc_ratov
* 2;
238 icmd
->un
.elsreq64
.bdl
.bdeSize
= sizeof(struct ulp_bde64
);
239 icmd
->ulpCommand
= CMD_XMIT_ELS_RSP64_CX
;
241 icmd
->ulpBdeCount
= 1;
243 icmd
->ulpClass
= CLASS3
;
245 if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) {
246 icmd
->un
.elsreq64
.myID
= vport
->fc_myDID
;
248 /* For ELS_REQUEST64_CR, use the VPI by default */
249 icmd
->ulpContext
= vport
->vpi
+ phba
->vpi_base
;
251 /* The CT field must be 0=INVALID_RPI for the ECHO cmd */
252 if (elscmd
== ELS_CMD_ECHO
)
253 icmd
->ulpCt_l
= 0; /* context = invalid RPI */
255 icmd
->ulpCt_l
= 1; /* context = VPI */
258 bpl
= (struct ulp_bde64
*) pbuflist
->virt
;
259 bpl
->addrLow
= le32_to_cpu(putPaddrLow(pcmd
->phys
));
260 bpl
->addrHigh
= le32_to_cpu(putPaddrHigh(pcmd
->phys
));
261 bpl
->tus
.f
.bdeSize
= cmdSize
;
262 bpl
->tus
.f
.bdeFlags
= 0;
263 bpl
->tus
.w
= le32_to_cpu(bpl
->tus
.w
);
267 bpl
->addrLow
= le32_to_cpu(putPaddrLow(prsp
->phys
));
268 bpl
->addrHigh
= le32_to_cpu(putPaddrHigh(prsp
->phys
));
269 bpl
->tus
.f
.bdeSize
= FCELSSIZE
;
270 bpl
->tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64
;
271 bpl
->tus
.w
= le32_to_cpu(bpl
->tus
.w
);
274 /* prevent preparing iocb with NULL ndlp reference */
275 elsiocb
->context1
= lpfc_nlp_get(ndlp
);
276 if (!elsiocb
->context1
)
277 goto els_iocb_free_pbuf_exit
;
278 elsiocb
->context2
= pcmd
;
279 elsiocb
->context3
= pbuflist
;
280 elsiocb
->retry
= retry
;
281 elsiocb
->vport
= vport
;
282 elsiocb
->drvrTimeout
= (phba
->fc_ratov
<< 1) + LPFC_DRVR_TIMEOUT
;
285 list_add(&prsp
->list
, &pcmd
->list
);
288 /* Xmit ELS command <elsCmd> to remote NPORT <did> */
289 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
290 "0116 Xmit ELS command x%x to remote "
291 "NPORT x%x I/O tag: x%x, port state: x%x\n",
292 elscmd
, did
, elsiocb
->iotag
,
295 /* Xmit ELS response <elsCmd> to remote NPORT <did> */
296 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
297 "0117 Xmit ELS response x%x to remote "
298 "NPORT x%x I/O tag: x%x, size: x%x\n",
299 elscmd
, ndlp
->nlp_DID
, elsiocb
->iotag
,
304 els_iocb_free_pbuf_exit
:
306 lpfc_mbuf_free(phba
, prsp
->virt
, prsp
->phys
);
309 els_iocb_free_prsp_exit
:
310 lpfc_mbuf_free(phba
, pcmd
->virt
, pcmd
->phys
);
313 els_iocb_free_pcmb_exit
:
315 lpfc_sli_release_iocbq(phba
, elsiocb
);
320 * lpfc_issue_fabric_reglogin - Issue fabric registration login for a vport
321 * @vport: pointer to a host virtual N_Port data structure.
323 * This routine issues a fabric registration login for a @vport. An
324 * active ndlp node with Fabric_DID must already exist for this @vport.
325 * The routine invokes two mailbox commands to carry out fabric registration
326 * login through the HBA firmware: the first mailbox command requests the
327 * HBA to perform link configuration for the @vport; and the second mailbox
328 * command requests the HBA to perform the actual fabric registration login
332 * 0 - successfully issued fabric registration login for @vport
333 * -ENXIO -- failed to issue fabric registration login for @vport
336 lpfc_issue_fabric_reglogin(struct lpfc_vport
*vport
)
338 struct lpfc_hba
*phba
= vport
->phba
;
340 struct lpfc_dmabuf
*mp
;
341 struct lpfc_nodelist
*ndlp
;
342 struct serv_parm
*sp
;
346 sp
= &phba
->fc_fabparam
;
347 ndlp
= lpfc_findnode_did(vport
, Fabric_DID
);
348 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
)) {
353 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
359 vport
->port_state
= LPFC_FABRIC_CFG_LINK
;
360 lpfc_config_link(phba
, mbox
);
361 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
364 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
365 if (rc
== MBX_NOT_FINISHED
) {
370 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
375 rc
= lpfc_reg_rpi(phba
, vport
->vpi
, Fabric_DID
, (uint8_t *)sp
, mbox
, 0);
381 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_fabric_reg_login
;
383 /* increment the reference count on ndlp to hold reference
384 * for the callback routine.
386 mbox
->context2
= lpfc_nlp_get(ndlp
);
388 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
389 if (rc
== MBX_NOT_FINISHED
) {
391 goto fail_issue_reg_login
;
396 fail_issue_reg_login
:
397 /* decrement the reference count on ndlp just incremented
398 * for the failed mbox command.
401 mp
= (struct lpfc_dmabuf
*) mbox
->context1
;
402 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
405 mempool_free(mbox
, phba
->mbox_mem_pool
);
408 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
409 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
410 "0249 Cannot issue Register Fabric login: Err %d\n", err
);
415 * lpfc_issue_reg_vfi - Register VFI for this vport's fabric login
416 * @vport: pointer to a host virtual N_Port data structure.
418 * This routine issues a REG_VFI mailbox for the vfi, vpi, fcfi triplet for
419 * the @vport. This mailbox command is necessary for FCoE only.
422 * 0 - successfully issued REG_VFI for @vport
423 * A failure code otherwise.
426 lpfc_issue_reg_vfi(struct lpfc_vport
*vport
)
428 struct lpfc_hba
*phba
= vport
->phba
;
430 struct lpfc_nodelist
*ndlp
;
431 struct serv_parm
*sp
;
432 struct lpfc_dmabuf
*dmabuf
;
435 sp
= &phba
->fc_fabparam
;
436 ndlp
= lpfc_findnode_did(vport
, Fabric_DID
);
437 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
)) {
442 dmabuf
= kzalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
447 dmabuf
->virt
= lpfc_mbuf_alloc(phba
, MEM_PRI
, &dmabuf
->phys
);
450 goto fail_free_dmabuf
;
452 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
455 goto fail_free_coherent
;
457 vport
->port_state
= LPFC_FABRIC_CFG_LINK
;
458 memcpy(dmabuf
->virt
, &phba
->fc_fabparam
, sizeof(vport
->fc_sparam
));
459 lpfc_reg_vfi(mboxq
, vport
, dmabuf
->phys
);
460 mboxq
->mbox_cmpl
= lpfc_mbx_cmpl_reg_vfi
;
461 mboxq
->vport
= vport
;
462 mboxq
->context1
= dmabuf
;
463 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
464 if (rc
== MBX_NOT_FINISHED
) {
471 mempool_free(mboxq
, phba
->mbox_mem_pool
);
473 lpfc_mbuf_free(phba
, dmabuf
->virt
, dmabuf
->phys
);
477 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
478 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
479 "0289 Issue Register VFI failed: Err %d\n", rc
);
484 * lpfc_cmpl_els_flogi_fabric - Completion function for flogi to a fabric port
485 * @vport: pointer to a host virtual N_Port data structure.
486 * @ndlp: pointer to a node-list data structure.
487 * @sp: pointer to service parameter data structure.
488 * @irsp: pointer to the IOCB within the lpfc response IOCB.
490 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
491 * function to handle the completion of a Fabric Login (FLOGI) into a fabric
492 * port in a fabric topology. It properly sets up the parameters to the @ndlp
493 * from the IOCB response. It also check the newly assigned N_Port ID to the
494 * @vport against the previously assigned N_Port ID. If it is different from
495 * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine
496 * is invoked on all the remaining nodes with the @vport to unregister the
497 * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin()
498 * is invoked to register login to the fabric.
501 * 0 - Success (currently, always return 0)
504 lpfc_cmpl_els_flogi_fabric(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
505 struct serv_parm
*sp
, IOCB_t
*irsp
)
507 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
508 struct lpfc_hba
*phba
= vport
->phba
;
509 struct lpfc_nodelist
*np
;
510 struct lpfc_nodelist
*next_np
;
512 spin_lock_irq(shost
->host_lock
);
513 vport
->fc_flag
|= FC_FABRIC
;
514 spin_unlock_irq(shost
->host_lock
);
516 phba
->fc_edtov
= be32_to_cpu(sp
->cmn
.e_d_tov
);
517 if (sp
->cmn
.edtovResolution
) /* E_D_TOV ticks are in nanoseconds */
518 phba
->fc_edtov
= (phba
->fc_edtov
+ 999999) / 1000000;
520 phba
->fc_ratov
= (be32_to_cpu(sp
->cmn
.w2
.r_a_tov
) + 999) / 1000;
522 if (phba
->fc_topology
== TOPOLOGY_LOOP
) {
523 spin_lock_irq(shost
->host_lock
);
524 vport
->fc_flag
|= FC_PUBLIC_LOOP
;
525 spin_unlock_irq(shost
->host_lock
);
528 vport
->fc_myDID
= irsp
->un
.ulpWord
[4] & Mask_DID
;
529 memcpy(&ndlp
->nlp_portname
, &sp
->portName
, sizeof(struct lpfc_name
));
530 memcpy(&ndlp
->nlp_nodename
, &sp
->nodeName
, sizeof(struct lpfc_name
));
531 ndlp
->nlp_class_sup
= 0;
532 if (sp
->cls1
.classValid
)
533 ndlp
->nlp_class_sup
|= FC_COS_CLASS1
;
534 if (sp
->cls2
.classValid
)
535 ndlp
->nlp_class_sup
|= FC_COS_CLASS2
;
536 if (sp
->cls3
.classValid
)
537 ndlp
->nlp_class_sup
|= FC_COS_CLASS3
;
538 if (sp
->cls4
.classValid
)
539 ndlp
->nlp_class_sup
|= FC_COS_CLASS4
;
540 ndlp
->nlp_maxframe
= ((sp
->cmn
.bbRcvSizeMsb
& 0x0F) << 8) |
541 sp
->cmn
.bbRcvSizeLsb
;
542 memcpy(&phba
->fc_fabparam
, sp
, sizeof(struct serv_parm
));
544 if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) {
545 if (sp
->cmn
.response_multiple_NPort
) {
546 lpfc_printf_vlog(vport
, KERN_WARNING
,
548 "1816 FLOGI NPIV supported, "
549 "response data 0x%x\n",
550 sp
->cmn
.response_multiple_NPort
);
551 phba
->link_flag
|= LS_NPIV_FAB_SUPPORTED
;
553 /* Because we asked f/w for NPIV it still expects us
554 to call reg_vnpid atleast for the physcial host */
555 lpfc_printf_vlog(vport
, KERN_WARNING
,
557 "1817 Fabric does not support NPIV "
558 "- configuring single port mode.\n");
559 phba
->link_flag
&= ~LS_NPIV_FAB_SUPPORTED
;
563 if ((vport
->fc_prevDID
!= vport
->fc_myDID
) &&
564 !(vport
->fc_flag
& FC_VPORT_NEEDS_REG_VPI
)) {
566 /* If our NportID changed, we need to ensure all
567 * remaining NPORTs get unreg_login'ed.
569 list_for_each_entry_safe(np
, next_np
,
570 &vport
->fc_nodes
, nlp_listp
) {
571 if (!NLP_CHK_NODE_ACT(np
))
573 if ((np
->nlp_state
!= NLP_STE_NPR_NODE
) ||
574 !(np
->nlp_flag
& NLP_NPR_ADISC
))
576 spin_lock_irq(shost
->host_lock
);
577 np
->nlp_flag
&= ~NLP_NPR_ADISC
;
578 spin_unlock_irq(shost
->host_lock
);
579 lpfc_unreg_rpi(vport
, np
);
581 lpfc_cleanup_pending_mbox(vport
);
582 if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) {
583 lpfc_mbx_unreg_vpi(vport
);
584 spin_lock_irq(shost
->host_lock
);
585 vport
->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
586 spin_unlock_irq(shost
->host_lock
);
589 * If VPI is unreged, driver need to do INIT_VPI
590 * before re-registering
592 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
593 spin_lock_irq(shost
->host_lock
);
594 vport
->fc_flag
|= FC_VPORT_NEEDS_INIT_VPI
;
595 spin_unlock_irq(shost
->host_lock
);
597 } else if ((phba
->sli_rev
== LPFC_SLI_REV4
) &&
598 !(vport
->fc_flag
& FC_VPORT_NEEDS_REG_VPI
)) {
600 * Driver needs to re-reg VPI in order for f/w
601 * to update the MAC address.
603 lpfc_register_new_vport(phba
, vport
, ndlp
);
607 if (phba
->sli_rev
< LPFC_SLI_REV4
) {
608 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_REG_LOGIN_ISSUE
);
609 if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
&&
610 vport
->fc_flag
& FC_VPORT_NEEDS_REG_VPI
)
611 lpfc_register_new_vport(phba
, vport
, ndlp
);
613 lpfc_issue_fabric_reglogin(vport
);
615 ndlp
->nlp_type
|= NLP_FABRIC
;
616 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
617 if ((!(vport
->fc_flag
& FC_VPORT_NEEDS_REG_VPI
)) &&
618 (vport
->vpi_state
& LPFC_VPI_REGISTERED
)) {
619 lpfc_start_fdiscs(phba
);
620 lpfc_do_scr_ns_plogi(phba
, vport
);
621 } else if (vport
->fc_flag
& FC_VFI_REGISTERED
)
622 lpfc_issue_init_vpi(vport
);
624 lpfc_issue_reg_vfi(vport
);
629 * lpfc_cmpl_els_flogi_nport - Completion function for flogi to an N_Port
630 * @vport: pointer to a host virtual N_Port data structure.
631 * @ndlp: pointer to a node-list data structure.
632 * @sp: pointer to service parameter data structure.
634 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
635 * function to handle the completion of a Fabric Login (FLOGI) into an N_Port
636 * in a point-to-point topology. First, the @vport's N_Port Name is compared
637 * with the received N_Port Name: if the @vport's N_Port Name is greater than
638 * the received N_Port Name lexicographically, this node shall assign local
639 * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and
640 * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise,
641 * this node shall just wait for the remote node to issue PLOGI and assign
649 lpfc_cmpl_els_flogi_nport(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
650 struct serv_parm
*sp
)
652 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
653 struct lpfc_hba
*phba
= vport
->phba
;
657 spin_lock_irq(shost
->host_lock
);
658 vport
->fc_flag
&= ~(FC_FABRIC
| FC_PUBLIC_LOOP
);
659 spin_unlock_irq(shost
->host_lock
);
661 phba
->fc_edtov
= FF_DEF_EDTOV
;
662 phba
->fc_ratov
= FF_DEF_RATOV
;
663 rc
= memcmp(&vport
->fc_portname
, &sp
->portName
,
664 sizeof(vport
->fc_portname
));
666 /* This side will initiate the PLOGI */
667 spin_lock_irq(shost
->host_lock
);
668 vport
->fc_flag
|= FC_PT2PT_PLOGI
;
669 spin_unlock_irq(shost
->host_lock
);
672 * N_Port ID cannot be 0, set our to LocalID the other
673 * side will be RemoteID.
678 vport
->fc_myDID
= PT2PT_LocalID
;
680 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
684 lpfc_config_link(phba
, mbox
);
686 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
688 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
689 if (rc
== MBX_NOT_FINISHED
) {
690 mempool_free(mbox
, phba
->mbox_mem_pool
);
693 /* Decrement ndlp reference count indicating that ndlp can be
694 * safely released when other references to it are done.
698 ndlp
= lpfc_findnode_did(vport
, PT2PT_RemoteID
);
701 * Cannot find existing Fabric ndlp, so allocate a
704 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
707 lpfc_nlp_init(vport
, ndlp
, PT2PT_RemoteID
);
708 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
709 ndlp
= lpfc_enable_node(vport
, ndlp
,
710 NLP_STE_UNUSED_NODE
);
715 memcpy(&ndlp
->nlp_portname
, &sp
->portName
,
716 sizeof(struct lpfc_name
));
717 memcpy(&ndlp
->nlp_nodename
, &sp
->nodeName
,
718 sizeof(struct lpfc_name
));
719 /* Set state will put ndlp onto node list if not already done */
720 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
721 spin_lock_irq(shost
->host_lock
);
722 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
723 spin_unlock_irq(shost
->host_lock
);
725 /* This side will wait for the PLOGI, decrement ndlp reference
726 * count indicating that ndlp can be released when other
727 * references to it are done.
731 /* If we are pt2pt with another NPort, force NPIV off! */
732 phba
->sli3_options
&= ~LPFC_SLI3_NPIV_ENABLED
;
734 spin_lock_irq(shost
->host_lock
);
735 vport
->fc_flag
|= FC_PT2PT
;
736 spin_unlock_irq(shost
->host_lock
);
738 /* Start discovery - this should just do CLEAR_LA */
739 lpfc_disc_start(vport
);
746 * lpfc_cmpl_els_flogi - Completion callback function for flogi
747 * @phba: pointer to lpfc hba data structure.
748 * @cmdiocb: pointer to lpfc command iocb data structure.
749 * @rspiocb: pointer to lpfc response iocb data structure.
751 * This routine is the top-level completion callback function for issuing
752 * a Fabric Login (FLOGI) command. If the response IOCB reported error,
753 * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If
754 * retry has been made (either immediately or delayed with lpfc_els_retry()
755 * returning 1), the command IOCB will be released and function returned.
756 * If the retry attempt has been given up (possibly reach the maximum
757 * number of retries), one additional decrement of ndlp reference shall be
758 * invoked before going out after releasing the command IOCB. This will
759 * actually release the remote node (Note, lpfc_els_free_iocb() will also
760 * invoke one decrement of ndlp reference count). If no error reported in
761 * the IOCB status, the command Port ID field is used to determine whether
762 * this is a point-to-point topology or a fabric topology: if the Port ID
763 * field is assigned, it is a fabric topology; otherwise, it is a
764 * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or
765 * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the
766 * specific topology completion conditions.
769 lpfc_cmpl_els_flogi(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
770 struct lpfc_iocbq
*rspiocb
)
772 struct lpfc_vport
*vport
= cmdiocb
->vport
;
773 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
774 IOCB_t
*irsp
= &rspiocb
->iocb
;
775 struct lpfc_nodelist
*ndlp
= cmdiocb
->context1
;
776 struct lpfc_dmabuf
*pcmd
= cmdiocb
->context2
, *prsp
;
777 struct serv_parm
*sp
;
781 /* Check to see if link went down during discovery */
782 if (lpfc_els_chk_latt(vport
)) {
783 /* One additional decrement on node reference count to
784 * trigger the release of the node
790 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
791 "FLOGI cmpl: status:x%x/x%x state:x%x",
792 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
795 if (irsp
->ulpStatus
) {
797 * In case of FIP mode, perform round robin FCF failover
798 * due to new FCF discovery
800 if ((phba
->hba_flag
& HBA_FIP_SUPPORT
) &&
801 (phba
->fcf
.fcf_flag
& FCF_DISCOVERY
) &&
802 (irsp
->ulpStatus
!= IOSTAT_LOCAL_REJECT
) &&
803 (irsp
->un
.ulpWord
[4] != IOERR_SLI_ABORTED
)) {
804 lpfc_printf_log(phba
, KERN_WARNING
, LOG_FIP
| LOG_ELS
,
805 "2611 FLOGI failed on registered "
806 "FCF record fcf_index(%d), status: "
807 "x%x/x%x, tmo:x%x, trying to perform "
808 "round robin failover\n",
809 phba
->fcf
.current_rec
.fcf_indx
,
810 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
812 fcf_index
= lpfc_sli4_fcf_rr_next_index_get(phba
);
813 if (fcf_index
== LPFC_FCOE_FCF_NEXT_NONE
) {
815 * Exhausted the eligible FCF record list,
816 * fail through to retry FLOGI on current
819 lpfc_printf_log(phba
, KERN_WARNING
,
821 "2760 Completed one round "
822 "of FLOGI FCF round robin "
823 "failover list, retry FLOGI "
824 "on currently registered "
826 phba
->fcf
.current_rec
.fcf_indx
);
828 lpfc_printf_log(phba
, KERN_INFO
,
830 "2794 FLOGI FCF round robin "
831 "failover to FCF index x%x\n",
833 rc
= lpfc_sli4_fcf_rr_read_fcf_rec(phba
,
836 lpfc_printf_log(phba
, KERN_WARNING
,
839 "robin FCF failover "
843 phba
->fcf
.current_rec
.fcf_indx
);
850 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
851 "2858 FLOGI failure Status:x%x/x%x TMO:x%x\n",
852 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
855 /* Check for retry */
856 if (lpfc_els_retry(phba
, cmdiocb
, rspiocb
))
859 /* FLOGI failed, so there is no fabric */
860 spin_lock_irq(shost
->host_lock
);
861 vport
->fc_flag
&= ~(FC_FABRIC
| FC_PUBLIC_LOOP
);
862 spin_unlock_irq(shost
->host_lock
);
864 /* If private loop, then allow max outstanding els to be
865 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
866 * alpa map would take too long otherwise.
868 if (phba
->alpa_map
[0] == 0) {
869 vport
->cfg_discovery_threads
= LPFC_MAX_DISC_THREADS
;
873 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
874 "0100 FLOGI failure Status:x%x/x%x TMO:x%x\n",
875 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
879 spin_lock_irq(shost
->host_lock
);
880 vport
->fc_flag
&= ~FC_VPORT_CVL_RCVD
;
881 vport
->fc_flag
&= ~FC_VPORT_LOGO_RCVD
;
882 spin_unlock_irq(shost
->host_lock
);
885 * The FLogI succeeded. Sync the data for the CPU before
888 prsp
= list_get_first(&pcmd
->list
, struct lpfc_dmabuf
, list
);
890 sp
= prsp
->virt
+ sizeof(uint32_t);
892 /* FLOGI completes successfully */
893 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
894 "0101 FLOGI completes successfully "
895 "Data: x%x x%x x%x x%x\n",
896 irsp
->un
.ulpWord
[4], sp
->cmn
.e_d_tov
,
897 sp
->cmn
.w2
.r_a_tov
, sp
->cmn
.edtovResolution
);
899 if (vport
->port_state
== LPFC_FLOGI
) {
901 * If Common Service Parameters indicate Nport
902 * we are point to point, if Fport we are Fabric.
905 rc
= lpfc_cmpl_els_flogi_fabric(vport
, ndlp
, sp
, irsp
);
906 else if (!(phba
->hba_flag
& HBA_FCOE_SUPPORT
))
907 rc
= lpfc_cmpl_els_flogi_nport(vport
, ndlp
, sp
);
909 lpfc_printf_vlog(vport
, KERN_ERR
,
911 "2831 FLOGI response with cleared Fabric "
912 "bit fcf_index 0x%x "
913 "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x "
915 "%02x%02x%02x%02x%02x%02x%02x%02x\n",
916 phba
->fcf
.current_rec
.fcf_indx
,
917 phba
->fcf
.current_rec
.switch_name
[0],
918 phba
->fcf
.current_rec
.switch_name
[1],
919 phba
->fcf
.current_rec
.switch_name
[2],
920 phba
->fcf
.current_rec
.switch_name
[3],
921 phba
->fcf
.current_rec
.switch_name
[4],
922 phba
->fcf
.current_rec
.switch_name
[5],
923 phba
->fcf
.current_rec
.switch_name
[6],
924 phba
->fcf
.current_rec
.switch_name
[7],
925 phba
->fcf
.current_rec
.fabric_name
[0],
926 phba
->fcf
.current_rec
.fabric_name
[1],
927 phba
->fcf
.current_rec
.fabric_name
[2],
928 phba
->fcf
.current_rec
.fabric_name
[3],
929 phba
->fcf
.current_rec
.fabric_name
[4],
930 phba
->fcf
.current_rec
.fabric_name
[5],
931 phba
->fcf
.current_rec
.fabric_name
[6],
932 phba
->fcf
.current_rec
.fabric_name
[7]);
934 spin_lock_irq(&phba
->hbalock
);
935 phba
->fcf
.fcf_flag
&= ~FCF_DISCOVERY
;
936 spin_unlock_irq(&phba
->hbalock
);
940 /* Mark the FCF discovery process done */
941 if (phba
->hba_flag
& HBA_FIP_SUPPORT
)
942 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_FIP
|
944 "2769 FLOGI successful on FCF "
945 "record: current_fcf_index:"
946 "x%x, terminate FCF round "
947 "robin failover process\n",
948 phba
->fcf
.current_rec
.fcf_indx
);
949 spin_lock_irq(&phba
->hbalock
);
950 phba
->fcf
.fcf_flag
&= ~FCF_DISCOVERY
;
951 spin_unlock_irq(&phba
->hbalock
);
959 if (!lpfc_error_lost_link(irsp
)) {
960 /* FLOGI failed, so just use loop map to make discovery list */
961 lpfc_disc_list_loopmap(vport
);
963 /* Start discovery */
964 lpfc_disc_start(vport
);
965 } else if (((irsp
->ulpStatus
!= IOSTAT_LOCAL_REJECT
) ||
966 ((irsp
->un
.ulpWord
[4] != IOERR_SLI_ABORTED
) &&
967 (irsp
->un
.ulpWord
[4] != IOERR_SLI_DOWN
))) &&
968 (phba
->link_state
!= LPFC_CLEAR_LA
)) {
969 /* If FLOGI failed enable link interrupt. */
970 lpfc_issue_clear_la(phba
, vport
);
973 lpfc_els_free_iocb(phba
, cmdiocb
);
977 * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport
978 * @vport: pointer to a host virtual N_Port data structure.
979 * @ndlp: pointer to a node-list data structure.
980 * @retry: number of retries to the command IOCB.
982 * This routine issues a Fabric Login (FLOGI) Request ELS command
983 * for a @vport. The initiator service parameters are put into the payload
984 * of the FLOGI Request IOCB and the top-level callback function pointer
985 * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
986 * function field. The lpfc_issue_fabric_iocb routine is invoked to send
987 * out FLOGI ELS command with one outstanding fabric IOCB at a time.
989 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
990 * will be incremented by 1 for holding the ndlp and the reference to ndlp
991 * will be stored into the context1 field of the IOCB for the completion
992 * callback function to the FLOGI ELS command.
995 * 0 - successfully issued flogi iocb for @vport
996 * 1 - failed to issue flogi iocb for @vport
999 lpfc_issue_els_flogi(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1002 struct lpfc_hba
*phba
= vport
->phba
;
1003 struct serv_parm
*sp
;
1005 struct lpfc_iocbq
*elsiocb
;
1006 struct lpfc_sli_ring
*pring
;
1012 pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
1014 cmdsize
= (sizeof(uint32_t) + sizeof(struct serv_parm
));
1015 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
,
1016 ndlp
->nlp_DID
, ELS_CMD_FLOGI
);
1021 icmd
= &elsiocb
->iocb
;
1022 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
1024 /* For FLOGI request, remainder of payload is service parameters */
1025 *((uint32_t *) (pcmd
)) = ELS_CMD_FLOGI
;
1026 pcmd
+= sizeof(uint32_t);
1027 memcpy(pcmd
, &vport
->fc_sparam
, sizeof(struct serv_parm
));
1028 sp
= (struct serv_parm
*) pcmd
;
1030 /* Setup CSPs accordingly for Fabric */
1031 sp
->cmn
.e_d_tov
= 0;
1032 sp
->cmn
.w2
.r_a_tov
= 0;
1033 sp
->cls1
.classValid
= 0;
1034 sp
->cls2
.seqDelivery
= 1;
1035 sp
->cls3
.seqDelivery
= 1;
1036 if (sp
->cmn
.fcphLow
< FC_PH3
)
1037 sp
->cmn
.fcphLow
= FC_PH3
;
1038 if (sp
->cmn
.fcphHigh
< FC_PH3
)
1039 sp
->cmn
.fcphHigh
= FC_PH3
;
1041 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
1042 elsiocb
->iocb
.ulpCt_h
= ((SLI4_CT_FCFI
>> 1) & 1);
1043 elsiocb
->iocb
.ulpCt_l
= (SLI4_CT_FCFI
& 1);
1044 /* FLOGI needs to be 3 for WQE FCFI */
1045 /* Set the fcfi to the fcfi we registered with */
1046 elsiocb
->iocb
.ulpContext
= phba
->fcf
.fcfi
;
1047 } else if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) {
1048 sp
->cmn
.request_multiple_Nport
= 1;
1049 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
1054 if (phba
->fc_topology
!= TOPOLOGY_LOOP
) {
1055 icmd
->un
.elsreq64
.myID
= 0;
1056 icmd
->un
.elsreq64
.fl
= 1;
1059 tmo
= phba
->fc_ratov
;
1060 phba
->fc_ratov
= LPFC_DISC_FLOGI_TMO
;
1061 lpfc_set_disctmo(vport
);
1062 phba
->fc_ratov
= tmo
;
1064 phba
->fc_stat
.elsXmitFLOGI
++;
1065 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_flogi
;
1067 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
1068 "Issue FLOGI: opt:x%x",
1069 phba
->sli3_options
, 0, 0);
1071 rc
= lpfc_issue_fabric_iocb(phba
, elsiocb
);
1072 if (rc
== IOCB_ERROR
) {
1073 lpfc_els_free_iocb(phba
, elsiocb
);
1080 * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs
1081 * @phba: pointer to lpfc hba data structure.
1083 * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
1084 * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
1085 * list and issues an abort IOCB commond on each outstanding IOCB that
1086 * contains a active Fabric_DID ndlp. Note that this function is to issue
1087 * the abort IOCB command on all the outstanding IOCBs, thus when this
1088 * function returns, it does not guarantee all the IOCBs are actually aborted.
1091 * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0)
1094 lpfc_els_abort_flogi(struct lpfc_hba
*phba
)
1096 struct lpfc_sli_ring
*pring
;
1097 struct lpfc_iocbq
*iocb
, *next_iocb
;
1098 struct lpfc_nodelist
*ndlp
;
1101 /* Abort outstanding I/O on NPort <nlp_DID> */
1102 lpfc_printf_log(phba
, KERN_INFO
, LOG_DISCOVERY
,
1103 "0201 Abort outstanding I/O on NPort x%x\n",
1106 pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
1109 * Check the txcmplq for an iocb that matches the nport the driver is
1112 spin_lock_irq(&phba
->hbalock
);
1113 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txcmplq
, list
) {
1115 if (icmd
->ulpCommand
== CMD_ELS_REQUEST64_CR
&&
1116 icmd
->un
.elsreq64
.bdl
.ulpIoTag32
) {
1117 ndlp
= (struct lpfc_nodelist
*)(iocb
->context1
);
1118 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
) &&
1119 (ndlp
->nlp_DID
== Fabric_DID
))
1120 lpfc_sli_issue_abort_iotag(phba
, pring
, iocb
);
1123 spin_unlock_irq(&phba
->hbalock
);
1129 * lpfc_initial_flogi - Issue an initial fabric login for a vport
1130 * @vport: pointer to a host virtual N_Port data structure.
1132 * This routine issues an initial Fabric Login (FLOGI) for the @vport
1133 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1134 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1135 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1136 * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
1137 * is then invoked with the @vport and the ndlp to perform the FLOGI for the
1141 * 0 - failed to issue initial flogi for @vport
1142 * 1 - successfully issued initial flogi for @vport
1145 lpfc_initial_flogi(struct lpfc_vport
*vport
)
1147 struct lpfc_hba
*phba
= vport
->phba
;
1148 struct lpfc_nodelist
*ndlp
;
1150 vport
->port_state
= LPFC_FLOGI
;
1151 lpfc_set_disctmo(vport
);
1153 /* First look for the Fabric ndlp */
1154 ndlp
= lpfc_findnode_did(vport
, Fabric_DID
);
1156 /* Cannot find existing Fabric ndlp, so allocate a new one */
1157 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
1160 lpfc_nlp_init(vport
, ndlp
, Fabric_DID
);
1161 /* Set the node type */
1162 ndlp
->nlp_type
|= NLP_FABRIC
;
1163 /* Put ndlp onto node list */
1164 lpfc_enqueue_node(vport
, ndlp
);
1165 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
1166 /* re-setup ndlp without removing from node list */
1167 ndlp
= lpfc_enable_node(vport
, ndlp
, NLP_STE_UNUSED_NODE
);
1172 if (lpfc_issue_els_flogi(vport
, ndlp
, 0)) {
1173 /* This decrement of reference count to node shall kick off
1174 * the release of the node.
1183 * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport
1184 * @vport: pointer to a host virtual N_Port data structure.
1186 * This routine issues an initial Fabric Discover (FDISC) for the @vport
1187 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1188 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1189 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1190 * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
1191 * is then invoked with the @vport and the ndlp to perform the FDISC for the
1195 * 0 - failed to issue initial fdisc for @vport
1196 * 1 - successfully issued initial fdisc for @vport
1199 lpfc_initial_fdisc(struct lpfc_vport
*vport
)
1201 struct lpfc_hba
*phba
= vport
->phba
;
1202 struct lpfc_nodelist
*ndlp
;
1204 /* First look for the Fabric ndlp */
1205 ndlp
= lpfc_findnode_did(vport
, Fabric_DID
);
1207 /* Cannot find existing Fabric ndlp, so allocate a new one */
1208 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
1211 lpfc_nlp_init(vport
, ndlp
, Fabric_DID
);
1212 /* Put ndlp onto node list */
1213 lpfc_enqueue_node(vport
, ndlp
);
1214 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
1215 /* re-setup ndlp without removing from node list */
1216 ndlp
= lpfc_enable_node(vport
, ndlp
, NLP_STE_UNUSED_NODE
);
1221 if (lpfc_issue_els_fdisc(vport
, ndlp
, 0)) {
1222 /* decrement node reference count to trigger the release of
1232 * lpfc_more_plogi - Check and issue remaining plogis for a vport
1233 * @vport: pointer to a host virtual N_Port data structure.
1235 * This routine checks whether there are more remaining Port Logins
1236 * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
1237 * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
1238 * to issue ELS PLOGIs up to the configured discover threads with the
1239 * @vport (@vport->cfg_discovery_threads). The function also decrement
1240 * the @vport's num_disc_node by 1 if it is not already 0.
1243 lpfc_more_plogi(struct lpfc_vport
*vport
)
1247 if (vport
->num_disc_nodes
)
1248 vport
->num_disc_nodes
--;
1250 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
1251 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
1252 "0232 Continue discovery with %d PLOGIs to go "
1253 "Data: x%x x%x x%x\n",
1254 vport
->num_disc_nodes
, vport
->fc_plogi_cnt
,
1255 vport
->fc_flag
, vport
->port_state
);
1256 /* Check to see if there are more PLOGIs to be sent */
1257 if (vport
->fc_flag
& FC_NLP_MORE
)
1258 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
1259 sentplogi
= lpfc_els_disc_plogi(vport
);
1265 * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp
1266 * @phba: pointer to lpfc hba data structure.
1267 * @prsp: pointer to response IOCB payload.
1268 * @ndlp: pointer to a node-list data structure.
1270 * This routine checks and indicates whether the WWPN of an N_Port, retrieved
1271 * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
1272 * The following cases are considered N_Port confirmed:
1273 * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
1274 * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
1275 * it does not have WWPN assigned either. If the WWPN is confirmed, the
1276 * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
1277 * 1) if there is a node on vport list other than the @ndlp with the same
1278 * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
1279 * on that node to release the RPI associated with the node; 2) if there is
1280 * no node found on vport list with the same WWPN of the N_Port PLOGI logged
1281 * into, a new node shall be allocated (or activated). In either case, the
1282 * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
1283 * be released and the new_ndlp shall be put on to the vport node list and
1284 * its pointer returned as the confirmed node.
1286 * Note that before the @ndlp got "released", the keepDID from not-matching
1287 * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
1288 * of the @ndlp. This is because the release of @ndlp is actually to put it
1289 * into an inactive state on the vport node list and the vport node list
1290 * management algorithm does not allow two node with a same DID.
1293 * pointer to the PLOGI N_Port @ndlp
1295 static struct lpfc_nodelist
*
1296 lpfc_plogi_confirm_nport(struct lpfc_hba
*phba
, uint32_t *prsp
,
1297 struct lpfc_nodelist
*ndlp
)
1299 struct lpfc_vport
*vport
= ndlp
->vport
;
1300 struct lpfc_nodelist
*new_ndlp
;
1301 struct lpfc_rport_data
*rdata
;
1302 struct fc_rport
*rport
;
1303 struct serv_parm
*sp
;
1304 uint8_t name
[sizeof(struct lpfc_name
)];
1305 uint32_t rc
, keepDID
= 0;
1309 /* Fabric nodes can have the same WWPN so we don't bother searching
1310 * by WWPN. Just return the ndlp that was given to us.
1312 if (ndlp
->nlp_type
& NLP_FABRIC
)
1315 sp
= (struct serv_parm
*) ((uint8_t *) prsp
+ sizeof(uint32_t));
1316 memset(name
, 0, sizeof(struct lpfc_name
));
1318 /* Now we find out if the NPort we are logging into, matches the WWPN
1319 * we have for that ndlp. If not, we have some work to do.
1321 new_ndlp
= lpfc_findnode_wwpn(vport
, &sp
->portName
);
1323 if (new_ndlp
== ndlp
&& NLP_CHK_NODE_ACT(new_ndlp
))
1327 rc
= memcmp(&ndlp
->nlp_portname
, name
,
1328 sizeof(struct lpfc_name
));
1331 new_ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_ATOMIC
);
1334 lpfc_nlp_init(vport
, new_ndlp
, ndlp
->nlp_DID
);
1335 } else if (!NLP_CHK_NODE_ACT(new_ndlp
)) {
1336 rc
= memcmp(&ndlp
->nlp_portname
, name
,
1337 sizeof(struct lpfc_name
));
1340 new_ndlp
= lpfc_enable_node(vport
, new_ndlp
,
1341 NLP_STE_UNUSED_NODE
);
1344 keepDID
= new_ndlp
->nlp_DID
;
1346 keepDID
= new_ndlp
->nlp_DID
;
1348 lpfc_unreg_rpi(vport
, new_ndlp
);
1349 new_ndlp
->nlp_DID
= ndlp
->nlp_DID
;
1350 new_ndlp
->nlp_prev_state
= ndlp
->nlp_prev_state
;
1352 if (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
)
1353 new_ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
1354 ndlp
->nlp_flag
&= ~NLP_NPR_2B_DISC
;
1356 /* Set state will put new_ndlp on to node list if not already done */
1357 lpfc_nlp_set_state(vport
, new_ndlp
, ndlp
->nlp_state
);
1359 /* Move this back to NPR state */
1360 if (memcmp(&ndlp
->nlp_portname
, name
, sizeof(struct lpfc_name
)) == 0) {
1361 /* The new_ndlp is replacing ndlp totally, so we need
1362 * to put ndlp on UNUSED list and try to free it.
1365 /* Fix up the rport accordingly */
1366 rport
= ndlp
->rport
;
1368 rdata
= rport
->dd_data
;
1369 if (rdata
->pnode
== ndlp
) {
1372 rdata
->pnode
= lpfc_nlp_get(new_ndlp
);
1373 new_ndlp
->rport
= rport
;
1375 new_ndlp
->nlp_type
= ndlp
->nlp_type
;
1377 /* We shall actually free the ndlp with both nlp_DID and
1378 * nlp_portname fields equals 0 to avoid any ndlp on the
1379 * nodelist never to be used.
1381 if (ndlp
->nlp_DID
== 0) {
1382 spin_lock_irq(&phba
->ndlp_lock
);
1383 NLP_SET_FREE_REQ(ndlp
);
1384 spin_unlock_irq(&phba
->ndlp_lock
);
1387 /* Two ndlps cannot have the same did on the nodelist */
1388 ndlp
->nlp_DID
= keepDID
;
1389 lpfc_drop_node(vport
, ndlp
);
1392 lpfc_unreg_rpi(vport
, ndlp
);
1393 /* Two ndlps cannot have the same did */
1394 ndlp
->nlp_DID
= keepDID
;
1395 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
1396 /* Since we are swapping the ndlp passed in with the new one
1397 * and the did has already been swapped, copy over the
1400 memcpy(&new_ndlp
->nlp_portname
, &ndlp
->nlp_portname
,
1401 sizeof(struct lpfc_name
));
1402 memcpy(&new_ndlp
->nlp_nodename
, &ndlp
->nlp_nodename
,
1403 sizeof(struct lpfc_name
));
1404 new_ndlp
->nlp_state
= ndlp
->nlp_state
;
1405 /* Fix up the rport accordingly */
1406 rport
= ndlp
->rport
;
1408 rdata
= rport
->dd_data
;
1409 put_node
= rdata
->pnode
!= NULL
;
1410 put_rport
= ndlp
->rport
!= NULL
;
1411 rdata
->pnode
= NULL
;
1416 put_device(&rport
->dev
);
1423 * lpfc_end_rscn - Check and handle more rscn for a vport
1424 * @vport: pointer to a host virtual N_Port data structure.
1426 * This routine checks whether more Registration State Change
1427 * Notifications (RSCNs) came in while the discovery state machine was in
1428 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1429 * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1430 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1431 * handling the RSCNs.
1434 lpfc_end_rscn(struct lpfc_vport
*vport
)
1436 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1438 if (vport
->fc_flag
& FC_RSCN_MODE
) {
1440 * Check to see if more RSCNs came in while we were
1441 * processing this one.
1443 if (vport
->fc_rscn_id_cnt
||
1444 (vport
->fc_flag
& FC_RSCN_DISCOVERY
) != 0)
1445 lpfc_els_handle_rscn(vport
);
1447 spin_lock_irq(shost
->host_lock
);
1448 vport
->fc_flag
&= ~FC_RSCN_MODE
;
1449 spin_unlock_irq(shost
->host_lock
);
1455 * lpfc_cmpl_els_plogi - Completion callback function for plogi
1456 * @phba: pointer to lpfc hba data structure.
1457 * @cmdiocb: pointer to lpfc command iocb data structure.
1458 * @rspiocb: pointer to lpfc response iocb data structure.
1460 * This routine is the completion callback function for issuing the Port
1461 * Login (PLOGI) command. For PLOGI completion, there must be an active
1462 * ndlp on the vport node list that matches the remote node ID from the
1463 * PLOGI reponse IOCB. If such ndlp does not exist, the PLOGI is simply
1464 * ignored and command IOCB released. The PLOGI response IOCB status is
1465 * checked for error conditons. If there is error status reported, PLOGI
1466 * retry shall be attempted by invoking the lpfc_els_retry() routine.
1467 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1468 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1469 * (DSM) is set for this PLOGI completion. Finally, it checks whether
1470 * there are additional N_Port nodes with the vport that need to perform
1471 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
1475 lpfc_cmpl_els_plogi(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
1476 struct lpfc_iocbq
*rspiocb
)
1478 struct lpfc_vport
*vport
= cmdiocb
->vport
;
1479 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1481 struct lpfc_nodelist
*ndlp
;
1482 struct lpfc_dmabuf
*prsp
;
1483 int disc
, rc
, did
, type
;
1485 /* we pass cmdiocb to state machine which needs rspiocb as well */
1486 cmdiocb
->context_un
.rsp_iocb
= rspiocb
;
1488 irsp
= &rspiocb
->iocb
;
1489 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
1490 "PLOGI cmpl: status:x%x/x%x did:x%x",
1491 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1492 irsp
->un
.elsreq64
.remoteID
);
1494 ndlp
= lpfc_findnode_did(vport
, irsp
->un
.elsreq64
.remoteID
);
1495 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
)) {
1496 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
1497 "0136 PLOGI completes to NPort x%x "
1498 "with no ndlp. Data: x%x x%x x%x\n",
1499 irsp
->un
.elsreq64
.remoteID
,
1500 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1505 /* Since ndlp can be freed in the disc state machine, note if this node
1506 * is being used during discovery.
1508 spin_lock_irq(shost
->host_lock
);
1509 disc
= (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
);
1510 ndlp
->nlp_flag
&= ~NLP_NPR_2B_DISC
;
1511 spin_unlock_irq(shost
->host_lock
);
1514 /* PLOGI completes to NPort <nlp_DID> */
1515 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
1516 "0102 PLOGI completes to NPort x%x "
1517 "Data: x%x x%x x%x x%x x%x\n",
1518 ndlp
->nlp_DID
, irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1519 irsp
->ulpTimeout
, disc
, vport
->num_disc_nodes
);
1520 /* Check to see if link went down during discovery */
1521 if (lpfc_els_chk_latt(vport
)) {
1522 spin_lock_irq(shost
->host_lock
);
1523 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
1524 spin_unlock_irq(shost
->host_lock
);
1528 /* ndlp could be freed in DSM, save these values now */
1529 type
= ndlp
->nlp_type
;
1530 did
= ndlp
->nlp_DID
;
1532 if (irsp
->ulpStatus
) {
1533 /* Check for retry */
1534 if (lpfc_els_retry(phba
, cmdiocb
, rspiocb
)) {
1535 /* ELS command is being retried */
1537 spin_lock_irq(shost
->host_lock
);
1538 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
1539 spin_unlock_irq(shost
->host_lock
);
1543 /* PLOGI failed Don't print the vport to vport rjts */
1544 if (irsp
->ulpStatus
!= IOSTAT_LS_RJT
||
1545 (((irsp
->un
.ulpWord
[4]) >> 16 != LSRJT_INVALID_CMD
) &&
1546 ((irsp
->un
.ulpWord
[4]) >> 16 != LSRJT_UNABLE_TPC
)) ||
1547 (phba
)->pport
->cfg_log_verbose
& LOG_ELS
)
1548 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
1549 "2753 PLOGI failure DID:%06X Status:x%x/x%x\n",
1550 ndlp
->nlp_DID
, irsp
->ulpStatus
,
1551 irsp
->un
.ulpWord
[4]);
1552 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1553 if (lpfc_error_lost_link(irsp
))
1554 rc
= NLP_STE_FREED_NODE
;
1556 rc
= lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
1557 NLP_EVT_CMPL_PLOGI
);
1559 /* Good status, call state machine */
1560 prsp
= list_entry(((struct lpfc_dmabuf
*)
1561 cmdiocb
->context2
)->list
.next
,
1562 struct lpfc_dmabuf
, list
);
1563 ndlp
= lpfc_plogi_confirm_nport(phba
, prsp
->virt
, ndlp
);
1564 rc
= lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
1565 NLP_EVT_CMPL_PLOGI
);
1568 if (disc
&& vport
->num_disc_nodes
) {
1569 /* Check to see if there are more PLOGIs to be sent */
1570 lpfc_more_plogi(vport
);
1572 if (vport
->num_disc_nodes
== 0) {
1573 spin_lock_irq(shost
->host_lock
);
1574 vport
->fc_flag
&= ~FC_NDISC_ACTIVE
;
1575 spin_unlock_irq(shost
->host_lock
);
1577 lpfc_can_disctmo(vport
);
1578 lpfc_end_rscn(vport
);
1583 lpfc_els_free_iocb(phba
, cmdiocb
);
1588 * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
1589 * @vport: pointer to a host virtual N_Port data structure.
1590 * @did: destination port identifier.
1591 * @retry: number of retries to the command IOCB.
1593 * This routine issues a Port Login (PLOGI) command to a remote N_Port
1594 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
1595 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
1596 * This routine constructs the proper feilds of the PLOGI IOCB and invokes
1597 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
1599 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1600 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1601 * will be stored into the context1 field of the IOCB for the completion
1602 * callback function to the PLOGI ELS command.
1605 * 0 - Successfully issued a plogi for @vport
1606 * 1 - failed to issue a plogi for @vport
1609 lpfc_issue_els_plogi(struct lpfc_vport
*vport
, uint32_t did
, uint8_t retry
)
1611 struct lpfc_hba
*phba
= vport
->phba
;
1612 struct serv_parm
*sp
;
1614 struct lpfc_nodelist
*ndlp
;
1615 struct lpfc_iocbq
*elsiocb
;
1616 struct lpfc_sli
*psli
;
1623 ndlp
= lpfc_findnode_did(vport
, did
);
1624 if (ndlp
&& !NLP_CHK_NODE_ACT(ndlp
))
1627 /* If ndlp is not NULL, we will bump the reference count on it */
1628 cmdsize
= (sizeof(uint32_t) + sizeof(struct serv_parm
));
1629 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
, did
,
1634 icmd
= &elsiocb
->iocb
;
1635 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
1637 /* For PLOGI request, remainder of payload is service parameters */
1638 *((uint32_t *) (pcmd
)) = ELS_CMD_PLOGI
;
1639 pcmd
+= sizeof(uint32_t);
1640 memcpy(pcmd
, &vport
->fc_sparam
, sizeof(struct serv_parm
));
1641 sp
= (struct serv_parm
*) pcmd
;
1644 * If we are a N-port connected to a Fabric, fix-up paramm's so logins
1645 * to device on remote loops work.
1647 if ((vport
->fc_flag
& FC_FABRIC
) && !(vport
->fc_flag
& FC_PUBLIC_LOOP
))
1648 sp
->cmn
.altBbCredit
= 1;
1650 if (sp
->cmn
.fcphLow
< FC_PH_4_3
)
1651 sp
->cmn
.fcphLow
= FC_PH_4_3
;
1653 if (sp
->cmn
.fcphHigh
< FC_PH3
)
1654 sp
->cmn
.fcphHigh
= FC_PH3
;
1656 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
1657 "Issue PLOGI: did:x%x",
1660 phba
->fc_stat
.elsXmitPLOGI
++;
1661 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_plogi
;
1662 ret
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
1664 if (ret
== IOCB_ERROR
) {
1665 lpfc_els_free_iocb(phba
, elsiocb
);
1672 * lpfc_cmpl_els_prli - Completion callback function for prli
1673 * @phba: pointer to lpfc hba data structure.
1674 * @cmdiocb: pointer to lpfc command iocb data structure.
1675 * @rspiocb: pointer to lpfc response iocb data structure.
1677 * This routine is the completion callback function for a Process Login
1678 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
1679 * status. If there is error status reported, PRLI retry shall be attempted
1680 * by invoking the lpfc_els_retry() routine. Otherwise, the state
1681 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
1682 * ndlp to mark the PRLI completion.
1685 lpfc_cmpl_els_prli(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
1686 struct lpfc_iocbq
*rspiocb
)
1688 struct lpfc_vport
*vport
= cmdiocb
->vport
;
1689 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1691 struct lpfc_sli
*psli
;
1692 struct lpfc_nodelist
*ndlp
;
1695 /* we pass cmdiocb to state machine which needs rspiocb as well */
1696 cmdiocb
->context_un
.rsp_iocb
= rspiocb
;
1698 irsp
= &(rspiocb
->iocb
);
1699 ndlp
= (struct lpfc_nodelist
*) cmdiocb
->context1
;
1700 spin_lock_irq(shost
->host_lock
);
1701 ndlp
->nlp_flag
&= ~NLP_PRLI_SND
;
1702 spin_unlock_irq(shost
->host_lock
);
1704 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
1705 "PRLI cmpl: status:x%x/x%x did:x%x",
1706 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1708 /* PRLI completes to NPort <nlp_DID> */
1709 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
1710 "0103 PRLI completes to NPort x%x "
1711 "Data: x%x x%x x%x x%x\n",
1712 ndlp
->nlp_DID
, irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1713 irsp
->ulpTimeout
, vport
->num_disc_nodes
);
1715 vport
->fc_prli_sent
--;
1716 /* Check to see if link went down during discovery */
1717 if (lpfc_els_chk_latt(vport
))
1720 if (irsp
->ulpStatus
) {
1721 /* Check for retry */
1722 if (lpfc_els_retry(phba
, cmdiocb
, rspiocb
)) {
1723 /* ELS command is being retried */
1727 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
1728 "2754 PRLI failure DID:%06X Status:x%x/x%x\n",
1729 ndlp
->nlp_DID
, irsp
->ulpStatus
,
1730 irsp
->un
.ulpWord
[4]);
1731 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1732 if (lpfc_error_lost_link(irsp
))
1735 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
1738 /* Good status, call state machine */
1739 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
1742 lpfc_els_free_iocb(phba
, cmdiocb
);
1747 * lpfc_issue_els_prli - Issue a prli iocb command for a vport
1748 * @vport: pointer to a host virtual N_Port data structure.
1749 * @ndlp: pointer to a node-list data structure.
1750 * @retry: number of retries to the command IOCB.
1752 * This routine issues a Process Login (PRLI) ELS command for the
1753 * @vport. The PRLI service parameters are set up in the payload of the
1754 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
1755 * is put to the IOCB completion callback func field before invoking the
1756 * routine lpfc_sli_issue_iocb() to send out PRLI command.
1758 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1759 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1760 * will be stored into the context1 field of the IOCB for the completion
1761 * callback function to the PRLI ELS command.
1764 * 0 - successfully issued prli iocb command for @vport
1765 * 1 - failed to issue prli iocb command for @vport
1768 lpfc_issue_els_prli(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1771 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1772 struct lpfc_hba
*phba
= vport
->phba
;
1775 struct lpfc_iocbq
*elsiocb
;
1779 cmdsize
= (sizeof(uint32_t) + sizeof(PRLI
));
1780 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
,
1781 ndlp
->nlp_DID
, ELS_CMD_PRLI
);
1785 icmd
= &elsiocb
->iocb
;
1786 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
1788 /* For PRLI request, remainder of payload is service parameters */
1789 memset(pcmd
, 0, (sizeof(PRLI
) + sizeof(uint32_t)));
1790 *((uint32_t *) (pcmd
)) = ELS_CMD_PRLI
;
1791 pcmd
+= sizeof(uint32_t);
1793 /* For PRLI, remainder of payload is PRLI parameter page */
1794 npr
= (PRLI
*) pcmd
;
1796 * If our firmware version is 3.20 or later,
1797 * set the following bits for FC-TAPE support.
1799 if (phba
->vpd
.rev
.feaLevelHigh
>= 0x02) {
1800 npr
->ConfmComplAllowed
= 1;
1802 npr
->TaskRetryIdReq
= 1;
1804 npr
->estabImagePair
= 1;
1805 npr
->readXferRdyDis
= 1;
1807 /* For FCP support */
1808 npr
->prliType
= PRLI_FCP_TYPE
;
1809 npr
->initiatorFunc
= 1;
1811 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
1812 "Issue PRLI: did:x%x",
1813 ndlp
->nlp_DID
, 0, 0);
1815 phba
->fc_stat
.elsXmitPRLI
++;
1816 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_prli
;
1817 spin_lock_irq(shost
->host_lock
);
1818 ndlp
->nlp_flag
|= NLP_PRLI_SND
;
1819 spin_unlock_irq(shost
->host_lock
);
1820 if (lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0) ==
1822 spin_lock_irq(shost
->host_lock
);
1823 ndlp
->nlp_flag
&= ~NLP_PRLI_SND
;
1824 spin_unlock_irq(shost
->host_lock
);
1825 lpfc_els_free_iocb(phba
, elsiocb
);
1828 vport
->fc_prli_sent
++;
1833 * lpfc_rscn_disc - Perform rscn discovery for a vport
1834 * @vport: pointer to a host virtual N_Port data structure.
1836 * This routine performs Registration State Change Notification (RSCN)
1837 * discovery for a @vport. If the @vport's node port recovery count is not
1838 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
1839 * the nodes that need recovery. If none of the PLOGI were needed through
1840 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
1841 * invoked to check and handle possible more RSCN came in during the period
1842 * of processing the current ones.
1845 lpfc_rscn_disc(struct lpfc_vport
*vport
)
1847 lpfc_can_disctmo(vport
);
1849 /* RSCN discovery */
1850 /* go thru NPR nodes and issue ELS PLOGIs */
1851 if (vport
->fc_npr_cnt
)
1852 if (lpfc_els_disc_plogi(vport
))
1855 lpfc_end_rscn(vport
);
1859 * lpfc_adisc_done - Complete the adisc phase of discovery
1860 * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
1862 * This function is called when the final ADISC is completed during discovery.
1863 * This function handles clearing link attention or issuing reg_vpi depending
1864 * on whether npiv is enabled. This function also kicks off the PLOGI phase of
1866 * This function is called with no locks held.
1869 lpfc_adisc_done(struct lpfc_vport
*vport
)
1871 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1872 struct lpfc_hba
*phba
= vport
->phba
;
1875 * For NPIV, cmpl_reg_vpi will set port_state to READY,
1876 * and continue discovery.
1878 if ((phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
1879 !(vport
->fc_flag
& FC_RSCN_MODE
) &&
1880 (phba
->sli_rev
< LPFC_SLI_REV4
)) {
1881 lpfc_issue_reg_vpi(phba
, vport
);
1885 * For SLI2, we need to set port_state to READY
1886 * and continue discovery.
1888 if (vport
->port_state
< LPFC_VPORT_READY
) {
1889 /* If we get here, there is nothing to ADISC */
1890 if (vport
->port_type
== LPFC_PHYSICAL_PORT
)
1891 lpfc_issue_clear_la(phba
, vport
);
1892 if (!(vport
->fc_flag
& FC_ABORT_DISCOVERY
)) {
1893 vport
->num_disc_nodes
= 0;
1894 /* go thru NPR list, issue ELS PLOGIs */
1895 if (vport
->fc_npr_cnt
)
1896 lpfc_els_disc_plogi(vport
);
1897 if (!vport
->num_disc_nodes
) {
1898 spin_lock_irq(shost
->host_lock
);
1899 vport
->fc_flag
&= ~FC_NDISC_ACTIVE
;
1900 spin_unlock_irq(shost
->host_lock
);
1901 lpfc_can_disctmo(vport
);
1902 lpfc_end_rscn(vport
);
1905 vport
->port_state
= LPFC_VPORT_READY
;
1907 lpfc_rscn_disc(vport
);
1911 * lpfc_more_adisc - Issue more adisc as needed
1912 * @vport: pointer to a host virtual N_Port data structure.
1914 * This routine determines whether there are more ndlps on a @vport
1915 * node list need to have Address Discover (ADISC) issued. If so, it will
1916 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
1917 * remaining nodes which need to have ADISC sent.
1920 lpfc_more_adisc(struct lpfc_vport
*vport
)
1924 if (vport
->num_disc_nodes
)
1925 vport
->num_disc_nodes
--;
1926 /* Continue discovery with <num_disc_nodes> ADISCs to go */
1927 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
1928 "0210 Continue discovery with %d ADISCs to go "
1929 "Data: x%x x%x x%x\n",
1930 vport
->num_disc_nodes
, vport
->fc_adisc_cnt
,
1931 vport
->fc_flag
, vport
->port_state
);
1932 /* Check to see if there are more ADISCs to be sent */
1933 if (vport
->fc_flag
& FC_NLP_MORE
) {
1934 lpfc_set_disctmo(vport
);
1935 /* go thru NPR nodes and issue any remaining ELS ADISCs */
1936 sentadisc
= lpfc_els_disc_adisc(vport
);
1938 if (!vport
->num_disc_nodes
)
1939 lpfc_adisc_done(vport
);
1944 * lpfc_cmpl_els_adisc - Completion callback function for adisc
1945 * @phba: pointer to lpfc hba data structure.
1946 * @cmdiocb: pointer to lpfc command iocb data structure.
1947 * @rspiocb: pointer to lpfc response iocb data structure.
1949 * This routine is the completion function for issuing the Address Discover
1950 * (ADISC) command. It first checks to see whether link went down during
1951 * the discovery process. If so, the node will be marked as node port
1952 * recovery for issuing discover IOCB by the link attention handler and
1953 * exit. Otherwise, the response status is checked. If error was reported
1954 * in the response status, the ADISC command shall be retried by invoking
1955 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
1956 * the response status, the state machine is invoked to set transition
1957 * with respect to NLP_EVT_CMPL_ADISC event.
1960 lpfc_cmpl_els_adisc(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
1961 struct lpfc_iocbq
*rspiocb
)
1963 struct lpfc_vport
*vport
= cmdiocb
->vport
;
1964 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1966 struct lpfc_nodelist
*ndlp
;
1969 /* we pass cmdiocb to state machine which needs rspiocb as well */
1970 cmdiocb
->context_un
.rsp_iocb
= rspiocb
;
1972 irsp
= &(rspiocb
->iocb
);
1973 ndlp
= (struct lpfc_nodelist
*) cmdiocb
->context1
;
1975 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
1976 "ADISC cmpl: status:x%x/x%x did:x%x",
1977 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1980 /* Since ndlp can be freed in the disc state machine, note if this node
1981 * is being used during discovery.
1983 spin_lock_irq(shost
->host_lock
);
1984 disc
= (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
);
1985 ndlp
->nlp_flag
&= ~(NLP_ADISC_SND
| NLP_NPR_2B_DISC
);
1986 spin_unlock_irq(shost
->host_lock
);
1987 /* ADISC completes to NPort <nlp_DID> */
1988 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
1989 "0104 ADISC completes to NPort x%x "
1990 "Data: x%x x%x x%x x%x x%x\n",
1991 ndlp
->nlp_DID
, irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1992 irsp
->ulpTimeout
, disc
, vport
->num_disc_nodes
);
1993 /* Check to see if link went down during discovery */
1994 if (lpfc_els_chk_latt(vport
)) {
1995 spin_lock_irq(shost
->host_lock
);
1996 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
1997 spin_unlock_irq(shost
->host_lock
);
2001 if (irsp
->ulpStatus
) {
2002 /* Check for retry */
2003 if (lpfc_els_retry(phba
, cmdiocb
, rspiocb
)) {
2004 /* ELS command is being retried */
2006 spin_lock_irq(shost
->host_lock
);
2007 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
2008 spin_unlock_irq(shost
->host_lock
);
2009 lpfc_set_disctmo(vport
);
2014 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
2015 "2755 ADISC failure DID:%06X Status:x%x/x%x\n",
2016 ndlp
->nlp_DID
, irsp
->ulpStatus
,
2017 irsp
->un
.ulpWord
[4]);
2018 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2019 if (!lpfc_error_lost_link(irsp
))
2020 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
2021 NLP_EVT_CMPL_ADISC
);
2023 /* Good status, call state machine */
2024 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
2025 NLP_EVT_CMPL_ADISC
);
2027 /* Check to see if there are more ADISCs to be sent */
2028 if (disc
&& vport
->num_disc_nodes
)
2029 lpfc_more_adisc(vport
);
2031 lpfc_els_free_iocb(phba
, cmdiocb
);
2036 * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
2037 * @vport: pointer to a virtual N_Port data structure.
2038 * @ndlp: pointer to a node-list data structure.
2039 * @retry: number of retries to the command IOCB.
2041 * This routine issues an Address Discover (ADISC) for an @ndlp on a
2042 * @vport. It prepares the payload of the ADISC ELS command, updates the
2043 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
2044 * to issue the ADISC ELS command.
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 ADISC ELS command.
2052 * 0 - successfully issued adisc
2053 * 1 - failed to issue adisc
2056 lpfc_issue_els_adisc(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2059 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2060 struct lpfc_hba
*phba
= vport
->phba
;
2063 struct lpfc_iocbq
*elsiocb
;
2067 cmdsize
= (sizeof(uint32_t) + sizeof(ADISC
));
2068 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
,
2069 ndlp
->nlp_DID
, ELS_CMD_ADISC
);
2073 icmd
= &elsiocb
->iocb
;
2074 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
2076 /* For ADISC request, remainder of payload is service parameters */
2077 *((uint32_t *) (pcmd
)) = ELS_CMD_ADISC
;
2078 pcmd
+= sizeof(uint32_t);
2080 /* Fill in ADISC payload */
2081 ap
= (ADISC
*) pcmd
;
2082 ap
->hardAL_PA
= phba
->fc_pref_ALPA
;
2083 memcpy(&ap
->portName
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
2084 memcpy(&ap
->nodeName
, &vport
->fc_nodename
, sizeof(struct lpfc_name
));
2085 ap
->DID
= be32_to_cpu(vport
->fc_myDID
);
2087 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
2088 "Issue ADISC: did:x%x",
2089 ndlp
->nlp_DID
, 0, 0);
2091 phba
->fc_stat
.elsXmitADISC
++;
2092 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_adisc
;
2093 spin_lock_irq(shost
->host_lock
);
2094 ndlp
->nlp_flag
|= NLP_ADISC_SND
;
2095 spin_unlock_irq(shost
->host_lock
);
2096 if (lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0) ==
2098 spin_lock_irq(shost
->host_lock
);
2099 ndlp
->nlp_flag
&= ~NLP_ADISC_SND
;
2100 spin_unlock_irq(shost
->host_lock
);
2101 lpfc_els_free_iocb(phba
, elsiocb
);
2108 * lpfc_cmpl_els_logo - Completion callback function for logo
2109 * @phba: pointer to lpfc hba data structure.
2110 * @cmdiocb: pointer to lpfc command iocb data structure.
2111 * @rspiocb: pointer to lpfc response iocb data structure.
2113 * This routine is the completion function for issuing the ELS Logout (LOGO)
2114 * command. If no error status was reported from the LOGO response, the
2115 * state machine of the associated ndlp shall be invoked for transition with
2116 * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
2117 * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
2120 lpfc_cmpl_els_logo(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
2121 struct lpfc_iocbq
*rspiocb
)
2123 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) cmdiocb
->context1
;
2124 struct lpfc_vport
*vport
= ndlp
->vport
;
2125 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2127 struct lpfc_sli
*psli
;
2130 /* we pass cmdiocb to state machine which needs rspiocb as well */
2131 cmdiocb
->context_un
.rsp_iocb
= rspiocb
;
2133 irsp
= &(rspiocb
->iocb
);
2134 spin_lock_irq(shost
->host_lock
);
2135 ndlp
->nlp_flag
&= ~NLP_LOGO_SND
;
2136 spin_unlock_irq(shost
->host_lock
);
2138 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
2139 "LOGO cmpl: status:x%x/x%x did:x%x",
2140 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
2142 /* LOGO completes to NPort <nlp_DID> */
2143 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
2144 "0105 LOGO completes to NPort x%x "
2145 "Data: x%x x%x x%x x%x\n",
2146 ndlp
->nlp_DID
, irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
2147 irsp
->ulpTimeout
, vport
->num_disc_nodes
);
2148 /* Check to see if link went down during discovery */
2149 if (lpfc_els_chk_latt(vport
))
2152 if (ndlp
->nlp_flag
& NLP_TARGET_REMOVE
) {
2153 /* NLP_EVT_DEVICE_RM should unregister the RPI
2154 * which should abort all outstanding IOs.
2156 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
2161 if (irsp
->ulpStatus
) {
2162 /* Check for retry */
2163 if (lpfc_els_retry(phba
, cmdiocb
, rspiocb
))
2164 /* ELS command is being retried */
2167 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
2168 "2756 LOGO failure DID:%06X Status:x%x/x%x\n",
2169 ndlp
->nlp_DID
, irsp
->ulpStatus
,
2170 irsp
->un
.ulpWord
[4]);
2171 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2172 if (lpfc_error_lost_link(irsp
))
2175 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
2178 /* Good status, call state machine.
2179 * This will unregister the rpi if needed.
2181 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
2184 lpfc_els_free_iocb(phba
, cmdiocb
);
2189 * lpfc_issue_els_logo - Issue a logo to an node on a vport
2190 * @vport: pointer to a virtual N_Port data structure.
2191 * @ndlp: pointer to a node-list data structure.
2192 * @retry: number of retries to the command IOCB.
2194 * This routine constructs and issues an ELS Logout (LOGO) iocb command
2195 * to a remote node, referred by an @ndlp on a @vport. It constructs the
2196 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
2197 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
2199 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2200 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2201 * will be stored into the context1 field of the IOCB for the completion
2202 * callback function to the LOGO ELS command.
2205 * 0 - successfully issued logo
2206 * 1 - failed to issue logo
2209 lpfc_issue_els_logo(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2212 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2213 struct lpfc_hba
*phba
= vport
->phba
;
2215 struct lpfc_iocbq
*elsiocb
;
2220 spin_lock_irq(shost
->host_lock
);
2221 if (ndlp
->nlp_flag
& NLP_LOGO_SND
) {
2222 spin_unlock_irq(shost
->host_lock
);
2225 spin_unlock_irq(shost
->host_lock
);
2227 cmdsize
= (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name
);
2228 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
,
2229 ndlp
->nlp_DID
, ELS_CMD_LOGO
);
2233 icmd
= &elsiocb
->iocb
;
2234 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
2235 *((uint32_t *) (pcmd
)) = ELS_CMD_LOGO
;
2236 pcmd
+= sizeof(uint32_t);
2238 /* Fill in LOGO payload */
2239 *((uint32_t *) (pcmd
)) = be32_to_cpu(vport
->fc_myDID
);
2240 pcmd
+= sizeof(uint32_t);
2241 memcpy(pcmd
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
2243 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
2244 "Issue LOGO: did:x%x",
2245 ndlp
->nlp_DID
, 0, 0);
2247 phba
->fc_stat
.elsXmitLOGO
++;
2248 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_logo
;
2249 spin_lock_irq(shost
->host_lock
);
2250 ndlp
->nlp_flag
|= NLP_LOGO_SND
;
2251 spin_unlock_irq(shost
->host_lock
);
2252 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
2254 if (rc
== IOCB_ERROR
) {
2255 spin_lock_irq(shost
->host_lock
);
2256 ndlp
->nlp_flag
&= ~NLP_LOGO_SND
;
2257 spin_unlock_irq(shost
->host_lock
);
2258 lpfc_els_free_iocb(phba
, elsiocb
);
2265 * lpfc_cmpl_els_cmd - Completion callback function for generic els command
2266 * @phba: pointer to lpfc hba data structure.
2267 * @cmdiocb: pointer to lpfc command iocb data structure.
2268 * @rspiocb: pointer to lpfc response iocb data structure.
2270 * This routine is a generic completion callback function for ELS commands.
2271 * Specifically, it is the callback function which does not need to perform
2272 * any command specific operations. It is currently used by the ELS command
2273 * issuing routines for the ELS State Change Request (SCR),
2274 * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution
2275 * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than
2276 * certain debug loggings, this callback function simply invokes the
2277 * lpfc_els_chk_latt() routine to check whether link went down during the
2278 * discovery process.
2281 lpfc_cmpl_els_cmd(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
2282 struct lpfc_iocbq
*rspiocb
)
2284 struct lpfc_vport
*vport
= cmdiocb
->vport
;
2287 irsp
= &rspiocb
->iocb
;
2289 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
2290 "ELS cmd cmpl: status:x%x/x%x did:x%x",
2291 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
2292 irsp
->un
.elsreq64
.remoteID
);
2293 /* ELS cmd tag <ulpIoTag> completes */
2294 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
2295 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
2296 irsp
->ulpIoTag
, irsp
->ulpStatus
,
2297 irsp
->un
.ulpWord
[4], irsp
->ulpTimeout
);
2298 /* Check to see if link went down during discovery */
2299 lpfc_els_chk_latt(vport
);
2300 lpfc_els_free_iocb(phba
, cmdiocb
);
2305 * lpfc_issue_els_scr - Issue a scr to an node on a vport
2306 * @vport: pointer to a host virtual N_Port data structure.
2307 * @nportid: N_Port identifier to the remote node.
2308 * @retry: number of retries to the command IOCB.
2310 * This routine issues a State Change Request (SCR) to a fabric node
2311 * on a @vport. The remote node @nportid is passed into the function. It
2312 * first search the @vport node list to find the matching ndlp. If no such
2313 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
2314 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
2315 * routine is invoked to send the SCR IOCB.
2317 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2318 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2319 * will be stored into the context1 field of the IOCB for the completion
2320 * callback function to the SCR ELS command.
2323 * 0 - Successfully issued scr command
2324 * 1 - Failed to issue scr command
2327 lpfc_issue_els_scr(struct lpfc_vport
*vport
, uint32_t nportid
, uint8_t retry
)
2329 struct lpfc_hba
*phba
= vport
->phba
;
2331 struct lpfc_iocbq
*elsiocb
;
2332 struct lpfc_sli
*psli
;
2335 struct lpfc_nodelist
*ndlp
;
2338 cmdsize
= (sizeof(uint32_t) + sizeof(SCR
));
2340 ndlp
= lpfc_findnode_did(vport
, nportid
);
2342 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
2345 lpfc_nlp_init(vport
, ndlp
, nportid
);
2346 lpfc_enqueue_node(vport
, ndlp
);
2347 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
2348 ndlp
= lpfc_enable_node(vport
, ndlp
, NLP_STE_UNUSED_NODE
);
2353 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
,
2354 ndlp
->nlp_DID
, ELS_CMD_SCR
);
2357 /* This will trigger the release of the node just
2364 icmd
= &elsiocb
->iocb
;
2365 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
2367 *((uint32_t *) (pcmd
)) = ELS_CMD_SCR
;
2368 pcmd
+= sizeof(uint32_t);
2370 /* For SCR, remainder of payload is SCR parameter page */
2371 memset(pcmd
, 0, sizeof(SCR
));
2372 ((SCR
*) pcmd
)->Function
= SCR_FUNC_FULL
;
2374 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
2375 "Issue SCR: did:x%x",
2376 ndlp
->nlp_DID
, 0, 0);
2378 phba
->fc_stat
.elsXmitSCR
++;
2379 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_cmd
;
2380 if (lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0) ==
2382 /* The additional lpfc_nlp_put will cause the following
2383 * lpfc_els_free_iocb routine to trigger the rlease of
2387 lpfc_els_free_iocb(phba
, elsiocb
);
2390 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2391 * trigger the release of node.
2398 * lpfc_issue_els_farpr - Issue a farp to an node on a vport
2399 * @vport: pointer to a host virtual N_Port data structure.
2400 * @nportid: N_Port identifier to the remote node.
2401 * @retry: number of retries to the command IOCB.
2403 * This routine issues a Fibre Channel Address Resolution Response
2404 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
2405 * is passed into the function. It first search the @vport node list to find
2406 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
2407 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
2408 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
2410 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2411 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2412 * will be stored into the context1 field of the IOCB for the completion
2413 * callback function to the PARPR ELS command.
2416 * 0 - Successfully issued farpr command
2417 * 1 - Failed to issue farpr command
2420 lpfc_issue_els_farpr(struct lpfc_vport
*vport
, uint32_t nportid
, uint8_t retry
)
2422 struct lpfc_hba
*phba
= vport
->phba
;
2424 struct lpfc_iocbq
*elsiocb
;
2425 struct lpfc_sli
*psli
;
2430 struct lpfc_nodelist
*ondlp
;
2431 struct lpfc_nodelist
*ndlp
;
2434 cmdsize
= (sizeof(uint32_t) + sizeof(FARP
));
2436 ndlp
= lpfc_findnode_did(vport
, nportid
);
2438 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
2441 lpfc_nlp_init(vport
, ndlp
, nportid
);
2442 lpfc_enqueue_node(vport
, ndlp
);
2443 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
2444 ndlp
= lpfc_enable_node(vport
, ndlp
, NLP_STE_UNUSED_NODE
);
2449 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
,
2450 ndlp
->nlp_DID
, ELS_CMD_RNID
);
2452 /* This will trigger the release of the node just
2459 icmd
= &elsiocb
->iocb
;
2460 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
2462 *((uint32_t *) (pcmd
)) = ELS_CMD_FARPR
;
2463 pcmd
+= sizeof(uint32_t);
2465 /* Fill in FARPR payload */
2466 fp
= (FARP
*) (pcmd
);
2467 memset(fp
, 0, sizeof(FARP
));
2468 lp
= (uint32_t *) pcmd
;
2469 *lp
++ = be32_to_cpu(nportid
);
2470 *lp
++ = be32_to_cpu(vport
->fc_myDID
);
2472 fp
->Mflags
= (FARP_MATCH_PORT
| FARP_MATCH_NODE
);
2474 memcpy(&fp
->RportName
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
2475 memcpy(&fp
->RnodeName
, &vport
->fc_nodename
, sizeof(struct lpfc_name
));
2476 ondlp
= lpfc_findnode_did(vport
, nportid
);
2477 if (ondlp
&& NLP_CHK_NODE_ACT(ondlp
)) {
2478 memcpy(&fp
->OportName
, &ondlp
->nlp_portname
,
2479 sizeof(struct lpfc_name
));
2480 memcpy(&fp
->OnodeName
, &ondlp
->nlp_nodename
,
2481 sizeof(struct lpfc_name
));
2484 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
2485 "Issue FARPR: did:x%x",
2486 ndlp
->nlp_DID
, 0, 0);
2488 phba
->fc_stat
.elsXmitFARPR
++;
2489 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_cmd
;
2490 if (lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0) ==
2492 /* The additional lpfc_nlp_put will cause the following
2493 * lpfc_els_free_iocb routine to trigger the release of
2497 lpfc_els_free_iocb(phba
, elsiocb
);
2500 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2501 * trigger the release of the node.
2508 * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
2509 * @vport: pointer to a host virtual N_Port data structure.
2510 * @nlp: pointer to a node-list data structure.
2512 * This routine cancels the timer with a delayed IOCB-command retry for
2513 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
2514 * removes the ELS retry event if it presents. In addition, if the
2515 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
2516 * commands are sent for the @vport's nodes that require issuing discovery
2520 lpfc_cancel_retry_delay_tmo(struct lpfc_vport
*vport
, struct lpfc_nodelist
*nlp
)
2522 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2523 struct lpfc_work_evt
*evtp
;
2525 if (!(nlp
->nlp_flag
& NLP_DELAY_TMO
))
2527 spin_lock_irq(shost
->host_lock
);
2528 nlp
->nlp_flag
&= ~NLP_DELAY_TMO
;
2529 spin_unlock_irq(shost
->host_lock
);
2530 del_timer_sync(&nlp
->nlp_delayfunc
);
2531 nlp
->nlp_last_elscmd
= 0;
2532 if (!list_empty(&nlp
->els_retry_evt
.evt_listp
)) {
2533 list_del_init(&nlp
->els_retry_evt
.evt_listp
);
2534 /* Decrement nlp reference count held for the delayed retry */
2535 evtp
= &nlp
->els_retry_evt
;
2536 lpfc_nlp_put((struct lpfc_nodelist
*)evtp
->evt_arg1
);
2538 if (nlp
->nlp_flag
& NLP_NPR_2B_DISC
) {
2539 spin_lock_irq(shost
->host_lock
);
2540 nlp
->nlp_flag
&= ~NLP_NPR_2B_DISC
;
2541 spin_unlock_irq(shost
->host_lock
);
2542 if (vport
->num_disc_nodes
) {
2543 if (vport
->port_state
< LPFC_VPORT_READY
) {
2544 /* Check if there are more ADISCs to be sent */
2545 lpfc_more_adisc(vport
);
2547 /* Check if there are more PLOGIs to be sent */
2548 lpfc_more_plogi(vport
);
2549 if (vport
->num_disc_nodes
== 0) {
2550 spin_lock_irq(shost
->host_lock
);
2551 vport
->fc_flag
&= ~FC_NDISC_ACTIVE
;
2552 spin_unlock_irq(shost
->host_lock
);
2553 lpfc_can_disctmo(vport
);
2554 lpfc_end_rscn(vport
);
2563 * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
2564 * @ptr: holder for the pointer to the timer function associated data (ndlp).
2566 * This routine is invoked by the ndlp delayed-function timer to check
2567 * whether there is any pending ELS retry event(s) with the node. If not, it
2568 * simply returns. Otherwise, if there is at least one ELS delayed event, it
2569 * adds the delayed events to the HBA work list and invokes the
2570 * lpfc_worker_wake_up() routine to wake up worker thread to process the
2571 * event. Note that lpfc_nlp_get() is called before posting the event to
2572 * the work list to hold reference count of ndlp so that it guarantees the
2573 * reference to ndlp will still be available when the worker thread gets
2574 * to the event associated with the ndlp.
2577 lpfc_els_retry_delay(unsigned long ptr
)
2579 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) ptr
;
2580 struct lpfc_vport
*vport
= ndlp
->vport
;
2581 struct lpfc_hba
*phba
= vport
->phba
;
2582 unsigned long flags
;
2583 struct lpfc_work_evt
*evtp
= &ndlp
->els_retry_evt
;
2585 spin_lock_irqsave(&phba
->hbalock
, flags
);
2586 if (!list_empty(&evtp
->evt_listp
)) {
2587 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
2591 /* We need to hold the node by incrementing the reference
2592 * count until the queued work is done
2594 evtp
->evt_arg1
= lpfc_nlp_get(ndlp
);
2595 if (evtp
->evt_arg1
) {
2596 evtp
->evt
= LPFC_EVT_ELS_RETRY
;
2597 list_add_tail(&evtp
->evt_listp
, &phba
->work_list
);
2598 lpfc_worker_wake_up(phba
);
2600 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
2605 * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
2606 * @ndlp: pointer to a node-list data structure.
2608 * This routine is the worker-thread handler for processing the @ndlp delayed
2609 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
2610 * the last ELS command from the associated ndlp and invokes the proper ELS
2611 * function according to the delayed ELS command to retry the command.
2614 lpfc_els_retry_delay_handler(struct lpfc_nodelist
*ndlp
)
2616 struct lpfc_vport
*vport
= ndlp
->vport
;
2617 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2618 uint32_t cmd
, did
, retry
;
2620 spin_lock_irq(shost
->host_lock
);
2621 did
= ndlp
->nlp_DID
;
2622 cmd
= ndlp
->nlp_last_elscmd
;
2623 ndlp
->nlp_last_elscmd
= 0;
2625 if (!(ndlp
->nlp_flag
& NLP_DELAY_TMO
)) {
2626 spin_unlock_irq(shost
->host_lock
);
2630 ndlp
->nlp_flag
&= ~NLP_DELAY_TMO
;
2631 spin_unlock_irq(shost
->host_lock
);
2633 * If a discovery event readded nlp_delayfunc after timer
2634 * firing and before processing the timer, cancel the
2637 del_timer_sync(&ndlp
->nlp_delayfunc
);
2638 retry
= ndlp
->nlp_retry
;
2639 ndlp
->nlp_retry
= 0;
2643 lpfc_issue_els_flogi(vport
, ndlp
, retry
);
2646 if (!lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, retry
)) {
2647 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
2648 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
2652 if (!lpfc_issue_els_adisc(vport
, ndlp
, retry
)) {
2653 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
2654 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_ADISC_ISSUE
);
2658 if (!lpfc_issue_els_prli(vport
, ndlp
, retry
)) {
2659 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
2660 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PRLI_ISSUE
);
2664 if (!lpfc_issue_els_logo(vport
, ndlp
, retry
)) {
2665 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
2666 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
2670 lpfc_issue_els_fdisc(vport
, ndlp
, retry
);
2677 * lpfc_els_retry - Make retry decision on an els command iocb
2678 * @phba: pointer to lpfc hba data structure.
2679 * @cmdiocb: pointer to lpfc command iocb data structure.
2680 * @rspiocb: pointer to lpfc response iocb data structure.
2682 * This routine makes a retry decision on an ELS command IOCB, which has
2683 * failed. The following ELS IOCBs use this function for retrying the command
2684 * when previously issued command responsed with error status: FLOGI, PLOGI,
2685 * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
2686 * returned error status, it makes the decision whether a retry shall be
2687 * issued for the command, and whether a retry shall be made immediately or
2688 * delayed. In the former case, the corresponding ELS command issuing-function
2689 * is called to retry the command. In the later case, the ELS command shall
2690 * be posted to the ndlp delayed event and delayed function timer set to the
2691 * ndlp for the delayed command issusing.
2694 * 0 - No retry of els command is made
2695 * 1 - Immediate or delayed retry of els command is made
2698 lpfc_els_retry(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
2699 struct lpfc_iocbq
*rspiocb
)
2701 struct lpfc_vport
*vport
= cmdiocb
->vport
;
2702 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2703 IOCB_t
*irsp
= &rspiocb
->iocb
;
2704 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) cmdiocb
->context1
;
2705 struct lpfc_dmabuf
*pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
2708 int retry
= 0, maxretry
= lpfc_max_els_tries
, delay
= 0;
2714 /* Note: context2 may be 0 for internal driver abort
2715 * of delays ELS command.
2718 if (pcmd
&& pcmd
->virt
) {
2719 elscmd
= (uint32_t *) (pcmd
->virt
);
2723 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
))
2724 did
= ndlp
->nlp_DID
;
2726 /* We should only hit this case for retrying PLOGI */
2727 did
= irsp
->un
.elsreq64
.remoteID
;
2728 ndlp
= lpfc_findnode_did(vport
, did
);
2729 if ((!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
))
2730 && (cmd
!= ELS_CMD_PLOGI
))
2734 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
2735 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
2736 *(((uint32_t *) irsp
) + 7), irsp
->un
.ulpWord
[4], ndlp
->nlp_DID
);
2738 switch (irsp
->ulpStatus
) {
2739 case IOSTAT_FCP_RSP_ERROR
:
2740 case IOSTAT_REMOTE_STOP
:
2743 case IOSTAT_LOCAL_REJECT
:
2744 switch ((irsp
->un
.ulpWord
[4] & 0xff)) {
2745 case IOERR_LOOP_OPEN_FAILURE
:
2746 if (cmd
== ELS_CMD_FLOGI
) {
2747 if (PCI_DEVICE_ID_HORNET
==
2748 phba
->pcidev
->device
) {
2749 phba
->fc_topology
= TOPOLOGY_LOOP
;
2750 phba
->pport
->fc_myDID
= 0;
2751 phba
->alpa_map
[0] = 0;
2752 phba
->alpa_map
[1] = 0;
2755 if (cmd
== ELS_CMD_PLOGI
&& cmdiocb
->retry
== 0)
2760 case IOERR_ILLEGAL_COMMAND
:
2761 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
2762 "0124 Retry illegal cmd x%x "
2763 "retry:x%x delay:x%x\n",
2764 cmd
, cmdiocb
->retry
, delay
);
2766 /* All command's retry policy */
2768 if (cmdiocb
->retry
> 2)
2772 case IOERR_NO_RESOURCES
:
2773 logerr
= 1; /* HBA out of resources */
2775 if (cmdiocb
->retry
> 100)
2780 case IOERR_ILLEGAL_FRAME
:
2785 case IOERR_SEQUENCE_TIMEOUT
:
2786 case IOERR_INVALID_RPI
:
2792 case IOSTAT_NPORT_RJT
:
2793 case IOSTAT_FABRIC_RJT
:
2794 if (irsp
->un
.ulpWord
[4] & RJT_UNAVAIL_TEMP
) {
2800 case IOSTAT_NPORT_BSY
:
2801 case IOSTAT_FABRIC_BSY
:
2802 logerr
= 1; /* Fabric / Remote NPort out of resources */
2807 stat
.un
.lsRjtError
= be32_to_cpu(irsp
->un
.ulpWord
[4]);
2808 /* Added for Vendor specifc support
2809 * Just keep retrying for these Rsn / Exp codes
2811 switch (stat
.un
.b
.lsRjtRsnCode
) {
2812 case LSRJT_UNABLE_TPC
:
2813 if (stat
.un
.b
.lsRjtRsnCodeExp
==
2814 LSEXP_CMD_IN_PROGRESS
) {
2815 if (cmd
== ELS_CMD_PLOGI
) {
2822 if (stat
.un
.b
.lsRjtRsnCodeExp
==
2823 LSEXP_CANT_GIVE_DATA
) {
2824 if (cmd
== ELS_CMD_PLOGI
) {
2831 if (cmd
== ELS_CMD_PLOGI
) {
2833 maxretry
= lpfc_max_els_tries
+ 1;
2837 if ((phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
2838 (cmd
== ELS_CMD_FDISC
) &&
2839 (stat
.un
.b
.lsRjtRsnCodeExp
== LSEXP_OUT_OF_RESOURCE
)){
2840 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
2841 "0125 FDISC Failed (x%x). "
2842 "Fabric out of resources\n",
2843 stat
.un
.lsRjtError
);
2844 lpfc_vport_set_state(vport
,
2845 FC_VPORT_NO_FABRIC_RSCS
);
2849 case LSRJT_LOGICAL_BSY
:
2850 if ((cmd
== ELS_CMD_PLOGI
) ||
2851 (cmd
== ELS_CMD_PRLI
)) {
2854 } else if (cmd
== ELS_CMD_FDISC
) {
2855 /* FDISC retry policy */
2857 if (cmdiocb
->retry
>= 32)
2863 case LSRJT_LOGICAL_ERR
:
2864 /* There are some cases where switches return this
2865 * error when they are not ready and should be returning
2866 * Logical Busy. We should delay every time.
2868 if (cmd
== ELS_CMD_FDISC
&&
2869 stat
.un
.b
.lsRjtRsnCodeExp
== LSEXP_PORT_LOGIN_REQ
) {
2875 case LSRJT_PROTOCOL_ERR
:
2876 if ((phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
2877 (cmd
== ELS_CMD_FDISC
) &&
2878 ((stat
.un
.b
.lsRjtRsnCodeExp
== LSEXP_INVALID_PNAME
) ||
2879 (stat
.un
.b
.lsRjtRsnCodeExp
== LSEXP_INVALID_NPORT_ID
))
2881 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
2882 "0122 FDISC Failed (x%x). "
2883 "Fabric Detected Bad WWN\n",
2884 stat
.un
.lsRjtError
);
2885 lpfc_vport_set_state(vport
,
2886 FC_VPORT_FABRIC_REJ_WWN
);
2892 case IOSTAT_INTERMED_RSP
:
2900 if (did
== FDMI_DID
)
2903 if (((cmd
== ELS_CMD_FLOGI
) || (cmd
== ELS_CMD_FDISC
)) &&
2904 (phba
->fc_topology
!= TOPOLOGY_LOOP
) &&
2905 !lpfc_error_lost_link(irsp
)) {
2906 /* FLOGI retry policy */
2910 if (cmdiocb
->retry
>= 100)
2912 else if (cmdiocb
->retry
>= 32)
2917 if (maxretry
&& (cmdiocb
->retry
>= maxretry
)) {
2918 phba
->fc_stat
.elsRetryExceeded
++;
2922 if ((vport
->load_flag
& FC_UNLOADING
) != 0)
2926 if ((cmd
== ELS_CMD_PLOGI
) || (cmd
== ELS_CMD_FDISC
)) {
2927 /* Stop retrying PLOGI and FDISC if in FCF discovery */
2928 if (phba
->fcf
.fcf_flag
& FCF_DISCOVERY
) {
2929 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
2930 "2849 Stop retry ELS command "
2931 "x%x to remote NPORT x%x, "
2932 "Data: x%x x%x\n", cmd
, did
,
2933 cmdiocb
->retry
, delay
);
2938 /* Retry ELS command <elsCmd> to remote NPORT <did> */
2939 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
2940 "0107 Retry ELS command x%x to remote "
2941 "NPORT x%x Data: x%x x%x\n",
2942 cmd
, did
, cmdiocb
->retry
, delay
);
2944 if (((cmd
== ELS_CMD_PLOGI
) || (cmd
== ELS_CMD_ADISC
)) &&
2945 ((irsp
->ulpStatus
!= IOSTAT_LOCAL_REJECT
) ||
2946 ((irsp
->un
.ulpWord
[4] & 0xff) != IOERR_NO_RESOURCES
))) {
2947 /* Don't reset timer for no resources */
2949 /* If discovery / RSCN timer is running, reset it */
2950 if (timer_pending(&vport
->fc_disctmo
) ||
2951 (vport
->fc_flag
& FC_RSCN_MODE
))
2952 lpfc_set_disctmo(vport
);
2955 phba
->fc_stat
.elsXmitRetry
++;
2956 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
) && delay
) {
2957 phba
->fc_stat
.elsDelayRetry
++;
2958 ndlp
->nlp_retry
= cmdiocb
->retry
;
2960 /* delay is specified in milliseconds */
2961 mod_timer(&ndlp
->nlp_delayfunc
,
2962 jiffies
+ msecs_to_jiffies(delay
));
2963 spin_lock_irq(shost
->host_lock
);
2964 ndlp
->nlp_flag
|= NLP_DELAY_TMO
;
2965 spin_unlock_irq(shost
->host_lock
);
2967 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
2968 if (cmd
== ELS_CMD_PRLI
)
2969 lpfc_nlp_set_state(vport
, ndlp
,
2970 NLP_STE_REG_LOGIN_ISSUE
);
2972 lpfc_nlp_set_state(vport
, ndlp
,
2974 ndlp
->nlp_last_elscmd
= cmd
;
2980 lpfc_issue_els_flogi(vport
, ndlp
, cmdiocb
->retry
);
2983 lpfc_issue_els_fdisc(vport
, ndlp
, cmdiocb
->retry
);
2986 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
)) {
2987 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
2988 lpfc_nlp_set_state(vport
, ndlp
,
2989 NLP_STE_PLOGI_ISSUE
);
2991 lpfc_issue_els_plogi(vport
, did
, cmdiocb
->retry
);
2994 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
2995 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_ADISC_ISSUE
);
2996 lpfc_issue_els_adisc(vport
, ndlp
, cmdiocb
->retry
);
2999 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
3000 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PRLI_ISSUE
);
3001 lpfc_issue_els_prli(vport
, ndlp
, cmdiocb
->retry
);
3004 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
3005 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
3006 lpfc_issue_els_logo(vport
, ndlp
, cmdiocb
->retry
);
3010 /* No retry ELS command <elsCmd> to remote NPORT <did> */
3012 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
3013 "0137 No retry ELS command x%x to remote "
3014 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
3015 cmd
, did
, irsp
->ulpStatus
,
3016 irsp
->un
.ulpWord
[4]);
3019 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
3020 "0108 No retry ELS command x%x to remote "
3021 "NPORT x%x Retried:%d Error:x%x/%x\n",
3022 cmd
, did
, cmdiocb
->retry
, irsp
->ulpStatus
,
3023 irsp
->un
.ulpWord
[4]);
3029 * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
3030 * @phba: pointer to lpfc hba data structure.
3031 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
3033 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
3034 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
3035 * checks to see whether there is a lpfc DMA buffer associated with the
3036 * response of the command IOCB. If so, it will be released before releasing
3037 * the lpfc DMA buffer associated with the IOCB itself.
3040 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3043 lpfc_els_free_data(struct lpfc_hba
*phba
, struct lpfc_dmabuf
*buf_ptr1
)
3045 struct lpfc_dmabuf
*buf_ptr
;
3047 /* Free the response before processing the command. */
3048 if (!list_empty(&buf_ptr1
->list
)) {
3049 list_remove_head(&buf_ptr1
->list
, buf_ptr
,
3052 lpfc_mbuf_free(phba
, buf_ptr
->virt
, buf_ptr
->phys
);
3055 lpfc_mbuf_free(phba
, buf_ptr1
->virt
, buf_ptr1
->phys
);
3061 * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
3062 * @phba: pointer to lpfc hba data structure.
3063 * @buf_ptr: pointer to the lpfc dma buffer data structure.
3065 * This routine releases the lpfc Direct Memory Access (DMA) buffer
3066 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
3070 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3073 lpfc_els_free_bpl(struct lpfc_hba
*phba
, struct lpfc_dmabuf
*buf_ptr
)
3075 lpfc_mbuf_free(phba
, buf_ptr
->virt
, buf_ptr
->phys
);
3081 * lpfc_els_free_iocb - Free a command iocb and its associated resources
3082 * @phba: pointer to lpfc hba data structure.
3083 * @elsiocb: pointer to lpfc els command iocb data structure.
3085 * This routine frees a command IOCB and its associated resources. The
3086 * command IOCB data structure contains the reference to various associated
3087 * resources, these fields must be set to NULL if the associated reference
3089 * context1 - reference to ndlp
3090 * context2 - reference to cmd
3091 * context2->next - reference to rsp
3092 * context3 - reference to bpl
3094 * It first properly decrements the reference count held on ndlp for the
3095 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
3096 * set, it invokes the lpfc_els_free_data() routine to release the Direct
3097 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
3098 * adds the DMA buffer the @phba data structure for the delayed release.
3099 * If reference to the Buffer Pointer List (BPL) is present, the
3100 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
3101 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
3102 * invoked to release the IOCB data structure back to @phba IOCBQ list.
3105 * 0 - Success (currently, always return 0)
3108 lpfc_els_free_iocb(struct lpfc_hba
*phba
, struct lpfc_iocbq
*elsiocb
)
3110 struct lpfc_dmabuf
*buf_ptr
, *buf_ptr1
;
3111 struct lpfc_nodelist
*ndlp
;
3113 ndlp
= (struct lpfc_nodelist
*)elsiocb
->context1
;
3115 if (ndlp
->nlp_flag
& NLP_DEFER_RM
) {
3118 /* If the ndlp is not being used by another discovery
3121 if (!lpfc_nlp_not_used(ndlp
)) {
3122 /* If ndlp is being used by another discovery
3123 * thread, just clear NLP_DEFER_RM
3125 ndlp
->nlp_flag
&= ~NLP_DEFER_RM
;
3130 elsiocb
->context1
= NULL
;
3132 /* context2 = cmd, context2->next = rsp, context3 = bpl */
3133 if (elsiocb
->context2
) {
3134 if (elsiocb
->iocb_flag
& LPFC_DELAY_MEM_FREE
) {
3135 /* Firmware could still be in progress of DMAing
3136 * payload, so don't free data buffer till after
3139 elsiocb
->iocb_flag
&= ~LPFC_DELAY_MEM_FREE
;
3140 buf_ptr
= elsiocb
->context2
;
3141 elsiocb
->context2
= NULL
;
3144 spin_lock_irq(&phba
->hbalock
);
3145 if (!list_empty(&buf_ptr
->list
)) {
3146 list_remove_head(&buf_ptr
->list
,
3147 buf_ptr1
, struct lpfc_dmabuf
,
3149 INIT_LIST_HEAD(&buf_ptr1
->list
);
3150 list_add_tail(&buf_ptr1
->list
,
3154 INIT_LIST_HEAD(&buf_ptr
->list
);
3155 list_add_tail(&buf_ptr
->list
, &phba
->elsbuf
);
3157 spin_unlock_irq(&phba
->hbalock
);
3160 buf_ptr1
= (struct lpfc_dmabuf
*) elsiocb
->context2
;
3161 lpfc_els_free_data(phba
, buf_ptr1
);
3165 if (elsiocb
->context3
) {
3166 buf_ptr
= (struct lpfc_dmabuf
*) elsiocb
->context3
;
3167 lpfc_els_free_bpl(phba
, buf_ptr
);
3169 lpfc_sli_release_iocbq(phba
, elsiocb
);
3174 * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
3175 * @phba: pointer to lpfc hba data structure.
3176 * @cmdiocb: pointer to lpfc command iocb data structure.
3177 * @rspiocb: pointer to lpfc response iocb data structure.
3179 * This routine is the completion callback function to the Logout (LOGO)
3180 * Accept (ACC) Response ELS command. This routine is invoked to indicate
3181 * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
3182 * release the ndlp if it has the last reference remaining (reference count
3183 * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
3184 * field to NULL to inform the following lpfc_els_free_iocb() routine no
3185 * ndlp reference count needs to be decremented. Otherwise, the ndlp
3186 * reference use-count shall be decremented by the lpfc_els_free_iocb()
3187 * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
3188 * IOCB data structure.
3191 lpfc_cmpl_els_logo_acc(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
3192 struct lpfc_iocbq
*rspiocb
)
3194 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) cmdiocb
->context1
;
3195 struct lpfc_vport
*vport
= cmdiocb
->vport
;
3198 irsp
= &rspiocb
->iocb
;
3199 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
3200 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
3201 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4], ndlp
->nlp_DID
);
3202 /* ACC to LOGO completes to NPort <nlp_DID> */
3203 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
3204 "0109 ACC to LOGO completes to NPort x%x "
3205 "Data: x%x x%x x%x\n",
3206 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
3209 if (ndlp
->nlp_state
== NLP_STE_NPR_NODE
) {
3210 /* NPort Recovery mode or node is just allocated */
3211 if (!lpfc_nlp_not_used(ndlp
)) {
3212 /* If the ndlp is being used by another discovery
3213 * thread, just unregister the RPI.
3215 lpfc_unreg_rpi(vport
, ndlp
);
3217 /* Indicate the node has already released, should
3218 * not reference to it from within lpfc_els_free_iocb.
3220 cmdiocb
->context1
= NULL
;
3223 lpfc_els_free_iocb(phba
, cmdiocb
);
3228 * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
3229 * @phba: pointer to lpfc hba data structure.
3230 * @pmb: pointer to the driver internal queue element for mailbox command.
3232 * This routine is the completion callback function for unregister default
3233 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
3234 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
3235 * decrements the ndlp reference count held for this completion callback
3236 * function. After that, it invokes the lpfc_nlp_not_used() to check
3237 * whether there is only one reference left on the ndlp. If so, it will
3238 * perform one more decrement and trigger the release of the ndlp.
3241 lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
3243 struct lpfc_dmabuf
*mp
= (struct lpfc_dmabuf
*) (pmb
->context1
);
3244 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) pmb
->context2
;
3247 * This routine is used to register and unregister in previous SLI
3250 if ((pmb
->u
.mb
.mbxCommand
== MBX_UNREG_LOGIN
) &&
3251 (phba
->sli_rev
== LPFC_SLI_REV4
))
3252 lpfc_sli4_free_rpi(phba
, pmb
->u
.mb
.un
.varUnregLogin
.rpi
);
3254 pmb
->context1
= NULL
;
3255 pmb
->context2
= NULL
;
3257 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
3259 mempool_free(pmb
, phba
->mbox_mem_pool
);
3260 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
)) {
3262 /* This is the end of the default RPI cleanup logic for this
3263 * ndlp. If no other discovery threads are using this ndlp.
3264 * we should free all resources associated with it.
3266 lpfc_nlp_not_used(ndlp
);
3273 * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
3274 * @phba: pointer to lpfc hba data structure.
3275 * @cmdiocb: pointer to lpfc command iocb data structure.
3276 * @rspiocb: pointer to lpfc response iocb data structure.
3278 * This routine is the completion callback function for ELS Response IOCB
3279 * command. In normal case, this callback function just properly sets the
3280 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
3281 * field in the command IOCB is not NULL, the referred mailbox command will
3282 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
3283 * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
3284 * link down event occurred during the discovery, the lpfc_nlp_not_used()
3285 * routine shall be invoked trying to release the ndlp if no other threads
3286 * are currently referring it.
3289 lpfc_cmpl_els_rsp(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
3290 struct lpfc_iocbq
*rspiocb
)
3292 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) cmdiocb
->context1
;
3293 struct lpfc_vport
*vport
= ndlp
? ndlp
->vport
: NULL
;
3294 struct Scsi_Host
*shost
= vport
? lpfc_shost_from_vport(vport
) : NULL
;
3297 LPFC_MBOXQ_t
*mbox
= NULL
;
3298 struct lpfc_dmabuf
*mp
= NULL
;
3299 uint32_t ls_rjt
= 0;
3301 irsp
= &rspiocb
->iocb
;
3303 if (cmdiocb
->context_un
.mbox
)
3304 mbox
= cmdiocb
->context_un
.mbox
;
3306 /* First determine if this is a LS_RJT cmpl. Note, this callback
3307 * function can have cmdiocb->contest1 (ndlp) field set to NULL.
3309 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) cmdiocb
->context2
)->virt
);
3310 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
) &&
3311 (*((uint32_t *) (pcmd
)) == ELS_CMD_LS_RJT
)) {
3312 /* A LS_RJT associated with Default RPI cleanup has its own
3313 * separate code path.
3315 if (!(ndlp
->nlp_flag
& NLP_RM_DFLT_RPI
))
3319 /* Check to see if link went down during discovery */
3320 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
) || lpfc_els_chk_latt(vport
)) {
3322 mp
= (struct lpfc_dmabuf
*) mbox
->context1
;
3324 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
3327 mempool_free(mbox
, phba
->mbox_mem_pool
);
3329 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
) &&
3330 (ndlp
->nlp_flag
& NLP_RM_DFLT_RPI
))
3331 if (lpfc_nlp_not_used(ndlp
)) {
3333 /* Indicate the node has already released,
3334 * should not reference to it from within
3335 * the routine lpfc_els_free_iocb.
3337 cmdiocb
->context1
= NULL
;
3342 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
3343 "ELS rsp cmpl: status:x%x/x%x did:x%x",
3344 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
3345 cmdiocb
->iocb
.un
.elsreq64
.remoteID
);
3346 /* ELS response tag <ulpIoTag> completes */
3347 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
3348 "0110 ELS response tag x%x completes "
3349 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
3350 cmdiocb
->iocb
.ulpIoTag
, rspiocb
->iocb
.ulpStatus
,
3351 rspiocb
->iocb
.un
.ulpWord
[4], rspiocb
->iocb
.ulpTimeout
,
3352 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
3355 if ((rspiocb
->iocb
.ulpStatus
== 0)
3356 && (ndlp
->nlp_flag
& NLP_ACC_REGLOGIN
)) {
3357 lpfc_unreg_rpi(vport
, ndlp
);
3358 /* Increment reference count to ndlp to hold the
3359 * reference to ndlp for the callback function.
3361 mbox
->context2
= lpfc_nlp_get(ndlp
);
3362 mbox
->vport
= vport
;
3363 if (ndlp
->nlp_flag
& NLP_RM_DFLT_RPI
) {
3364 mbox
->mbox_flag
|= LPFC_MBX_IMED_UNREG
;
3365 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_dflt_rpi
;
3368 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_reg_login
;
3369 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
3370 lpfc_nlp_set_state(vport
, ndlp
,
3371 NLP_STE_REG_LOGIN_ISSUE
);
3373 if (lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
)
3374 != MBX_NOT_FINISHED
)
3377 /* Decrement the ndlp reference count we
3378 * set for this failed mailbox command.
3382 /* ELS rsp: Cannot issue reg_login for <NPortid> */
3383 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
3384 "0138 ELS rsp: Cannot issue reg_login for x%x "
3385 "Data: x%x x%x x%x\n",
3386 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
3389 if (lpfc_nlp_not_used(ndlp
)) {
3391 /* Indicate node has already been released,
3392 * should not reference to it from within
3393 * the routine lpfc_els_free_iocb.
3395 cmdiocb
->context1
= NULL
;
3398 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
3399 if (!lpfc_error_lost_link(irsp
) &&
3400 ndlp
->nlp_flag
& NLP_ACC_REGLOGIN
) {
3401 if (lpfc_nlp_not_used(ndlp
)) {
3403 /* Indicate node has already been
3404 * released, should not reference
3405 * to it from within the routine
3406 * lpfc_els_free_iocb.
3408 cmdiocb
->context1
= NULL
;
3412 mp
= (struct lpfc_dmabuf
*) mbox
->context1
;
3414 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
3417 mempool_free(mbox
, phba
->mbox_mem_pool
);
3420 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
)) {
3421 spin_lock_irq(shost
->host_lock
);
3422 ndlp
->nlp_flag
&= ~(NLP_ACC_REGLOGIN
| NLP_RM_DFLT_RPI
);
3423 spin_unlock_irq(shost
->host_lock
);
3425 /* If the node is not being used by another discovery thread,
3426 * and we are sending a reject, we are done with it.
3427 * Release driver reference count here and free associated
3431 if (lpfc_nlp_not_used(ndlp
))
3432 /* Indicate node has already been released,
3433 * should not reference to it from within
3434 * the routine lpfc_els_free_iocb.
3436 cmdiocb
->context1
= NULL
;
3439 lpfc_els_free_iocb(phba
, cmdiocb
);
3444 * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
3445 * @vport: pointer to a host virtual N_Port data structure.
3446 * @flag: the els command code to be accepted.
3447 * @oldiocb: pointer to the original lpfc command iocb data structure.
3448 * @ndlp: pointer to a node-list data structure.
3449 * @mbox: pointer to the driver internal queue element for mailbox command.
3451 * This routine prepares and issues an Accept (ACC) response IOCB
3452 * command. It uses the @flag to properly set up the IOCB field for the
3453 * specific ACC response command to be issued and invokes the
3454 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
3455 * @mbox pointer is passed in, it will be put into the context_un.mbox
3456 * field of the IOCB for the completion callback function to issue the
3457 * mailbox command to the HBA later when callback is invoked.
3459 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3460 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3461 * will be stored into the context1 field of the IOCB for the completion
3462 * callback function to the corresponding response ELS IOCB command.
3465 * 0 - Successfully issued acc response
3466 * 1 - Failed to issue acc response
3469 lpfc_els_rsp_acc(struct lpfc_vport
*vport
, uint32_t flag
,
3470 struct lpfc_iocbq
*oldiocb
, struct lpfc_nodelist
*ndlp
,
3473 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
3474 struct lpfc_hba
*phba
= vport
->phba
;
3477 struct lpfc_iocbq
*elsiocb
;
3478 struct lpfc_sli
*psli
;
3482 ELS_PKT
*els_pkt_ptr
;
3485 oldcmd
= &oldiocb
->iocb
;
3489 cmdsize
= sizeof(uint32_t);
3490 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
,
3491 ndlp
, ndlp
->nlp_DID
, ELS_CMD_ACC
);
3493 spin_lock_irq(shost
->host_lock
);
3494 ndlp
->nlp_flag
&= ~NLP_LOGO_ACC
;
3495 spin_unlock_irq(shost
->host_lock
);
3499 icmd
= &elsiocb
->iocb
;
3500 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri */
3501 pcmd
= (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
3502 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
3503 pcmd
+= sizeof(uint32_t);
3505 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
3506 "Issue ACC: did:x%x flg:x%x",
3507 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
3510 cmdsize
= (sizeof(struct serv_parm
) + sizeof(uint32_t));
3511 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
,
3512 ndlp
, ndlp
->nlp_DID
, ELS_CMD_ACC
);
3516 icmd
= &elsiocb
->iocb
;
3517 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri */
3518 pcmd
= (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
3521 elsiocb
->context_un
.mbox
= mbox
;
3523 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
3524 pcmd
+= sizeof(uint32_t);
3525 memcpy(pcmd
, &vport
->fc_sparam
, sizeof(struct serv_parm
));
3527 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
3528 "Issue ACC PLOGI: did:x%x flg:x%x",
3529 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
3532 cmdsize
= sizeof(uint32_t) + sizeof(PRLO
);
3533 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
,
3534 ndlp
, ndlp
->nlp_DID
, ELS_CMD_PRLO
);
3538 icmd
= &elsiocb
->iocb
;
3539 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri */
3540 pcmd
= (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
3542 memcpy(pcmd
, ((struct lpfc_dmabuf
*) oldiocb
->context2
)->virt
,
3543 sizeof(uint32_t) + sizeof(PRLO
));
3544 *((uint32_t *) (pcmd
)) = ELS_CMD_PRLO_ACC
;
3545 els_pkt_ptr
= (ELS_PKT
*) pcmd
;
3546 els_pkt_ptr
->un
.prlo
.acceptRspCode
= PRLO_REQ_EXECUTED
;
3548 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
3549 "Issue ACC PRLO: did:x%x flg:x%x",
3550 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
3555 /* Xmit ELS ACC response tag <ulpIoTag> */
3556 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
3557 "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
3558 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n",
3559 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
,
3560 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
3562 if (ndlp
->nlp_flag
& NLP_LOGO_ACC
) {
3563 spin_lock_irq(shost
->host_lock
);
3564 ndlp
->nlp_flag
&= ~NLP_LOGO_ACC
;
3565 spin_unlock_irq(shost
->host_lock
);
3566 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_logo_acc
;
3568 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
3571 phba
->fc_stat
.elsXmitACC
++;
3572 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
3573 if (rc
== IOCB_ERROR
) {
3574 lpfc_els_free_iocb(phba
, elsiocb
);
3581 * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command
3582 * @vport: pointer to a virtual N_Port data structure.
3584 * @oldiocb: pointer to the original lpfc command iocb data structure.
3585 * @ndlp: pointer to a node-list data structure.
3586 * @mbox: pointer to the driver internal queue element for mailbox command.
3588 * This routine prepares and issue an Reject (RJT) response IOCB
3589 * command. If a @mbox pointer is passed in, it will be put into the
3590 * context_un.mbox field of the IOCB for the completion callback function
3591 * to issue to the HBA later.
3593 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3594 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3595 * will be stored into the context1 field of the IOCB for the completion
3596 * callback function to the reject response ELS IOCB command.
3599 * 0 - Successfully issued reject response
3600 * 1 - Failed to issue reject response
3603 lpfc_els_rsp_reject(struct lpfc_vport
*vport
, uint32_t rejectError
,
3604 struct lpfc_iocbq
*oldiocb
, struct lpfc_nodelist
*ndlp
,
3607 struct lpfc_hba
*phba
= vport
->phba
;
3610 struct lpfc_iocbq
*elsiocb
;
3611 struct lpfc_sli
*psli
;
3617 cmdsize
= 2 * sizeof(uint32_t);
3618 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
, ndlp
,
3619 ndlp
->nlp_DID
, ELS_CMD_LS_RJT
);
3623 icmd
= &elsiocb
->iocb
;
3624 oldcmd
= &oldiocb
->iocb
;
3625 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri */
3626 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
3628 *((uint32_t *) (pcmd
)) = ELS_CMD_LS_RJT
;
3629 pcmd
+= sizeof(uint32_t);
3630 *((uint32_t *) (pcmd
)) = rejectError
;
3633 elsiocb
->context_un
.mbox
= mbox
;
3635 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
3636 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
3637 "0129 Xmit ELS RJT x%x response tag x%x "
3638 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
3640 rejectError
, elsiocb
->iotag
,
3641 elsiocb
->iocb
.ulpContext
, ndlp
->nlp_DID
,
3642 ndlp
->nlp_flag
, ndlp
->nlp_state
, ndlp
->nlp_rpi
);
3643 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
3644 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
3645 ndlp
->nlp_DID
, ndlp
->nlp_flag
, rejectError
);
3647 phba
->fc_stat
.elsXmitLSRJT
++;
3648 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
3649 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
3651 if (rc
== IOCB_ERROR
) {
3652 lpfc_els_free_iocb(phba
, elsiocb
);
3659 * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
3660 * @vport: pointer to a virtual N_Port data structure.
3661 * @oldiocb: pointer to the original lpfc command iocb data structure.
3662 * @ndlp: pointer to a node-list data structure.
3664 * This routine prepares and issues an Accept (ACC) response to Address
3665 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
3666 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3668 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3669 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3670 * will be stored into the context1 field of the IOCB for the completion
3671 * callback function to the ADISC Accept response ELS IOCB command.
3674 * 0 - Successfully issued acc adisc response
3675 * 1 - Failed to issue adisc acc response
3678 lpfc_els_rsp_adisc_acc(struct lpfc_vport
*vport
, struct lpfc_iocbq
*oldiocb
,
3679 struct lpfc_nodelist
*ndlp
)
3681 struct lpfc_hba
*phba
= vport
->phba
;
3683 IOCB_t
*icmd
, *oldcmd
;
3684 struct lpfc_iocbq
*elsiocb
;
3689 cmdsize
= sizeof(uint32_t) + sizeof(ADISC
);
3690 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
, ndlp
,
3691 ndlp
->nlp_DID
, ELS_CMD_ACC
);
3695 icmd
= &elsiocb
->iocb
;
3696 oldcmd
= &oldiocb
->iocb
;
3697 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri */
3699 /* Xmit ADISC ACC response tag <ulpIoTag> */
3700 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
3701 "0130 Xmit ADISC ACC response iotag x%x xri: "
3702 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
3703 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
,
3704 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
3706 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
3708 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
3709 pcmd
+= sizeof(uint32_t);
3711 ap
= (ADISC
*) (pcmd
);
3712 ap
->hardAL_PA
= phba
->fc_pref_ALPA
;
3713 memcpy(&ap
->portName
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
3714 memcpy(&ap
->nodeName
, &vport
->fc_nodename
, sizeof(struct lpfc_name
));
3715 ap
->DID
= be32_to_cpu(vport
->fc_myDID
);
3717 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
3718 "Issue ACC ADISC: did:x%x flg:x%x",
3719 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
3721 phba
->fc_stat
.elsXmitACC
++;
3722 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
3723 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
3724 if (rc
== IOCB_ERROR
) {
3725 lpfc_els_free_iocb(phba
, elsiocb
);
3732 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
3733 * @vport: pointer to a virtual N_Port data structure.
3734 * @oldiocb: pointer to the original lpfc command iocb data structure.
3735 * @ndlp: pointer to a node-list data structure.
3737 * This routine prepares and issues an Accept (ACC) response to Process
3738 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
3739 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3741 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3742 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3743 * will be stored into the context1 field of the IOCB for the completion
3744 * callback function to the PRLI Accept response ELS IOCB command.
3747 * 0 - Successfully issued acc prli response
3748 * 1 - Failed to issue acc prli response
3751 lpfc_els_rsp_prli_acc(struct lpfc_vport
*vport
, struct lpfc_iocbq
*oldiocb
,
3752 struct lpfc_nodelist
*ndlp
)
3754 struct lpfc_hba
*phba
= vport
->phba
;
3759 struct lpfc_iocbq
*elsiocb
;
3760 struct lpfc_sli
*psli
;
3767 cmdsize
= sizeof(uint32_t) + sizeof(PRLI
);
3768 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
, ndlp
,
3769 ndlp
->nlp_DID
, (ELS_CMD_ACC
| (ELS_CMD_PRLI
& ~ELS_RSP_MASK
)));
3773 icmd
= &elsiocb
->iocb
;
3774 oldcmd
= &oldiocb
->iocb
;
3775 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri */
3776 /* Xmit PRLI ACC response tag <ulpIoTag> */
3777 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
3778 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
3779 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
3780 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
,
3781 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
3783 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
3785 *((uint32_t *) (pcmd
)) = (ELS_CMD_ACC
| (ELS_CMD_PRLI
& ~ELS_RSP_MASK
));
3786 pcmd
+= sizeof(uint32_t);
3788 /* For PRLI, remainder of payload is PRLI parameter page */
3789 memset(pcmd
, 0, sizeof(PRLI
));
3791 npr
= (PRLI
*) pcmd
;
3794 * If the remote port is a target and our firmware version is 3.20 or
3795 * later, set the following bits for FC-TAPE support.
3797 if ((ndlp
->nlp_type
& NLP_FCP_TARGET
) &&
3798 (vpd
->rev
.feaLevelHigh
>= 0x02)) {
3799 npr
->ConfmComplAllowed
= 1;
3801 npr
->TaskRetryIdReq
= 1;
3804 npr
->acceptRspCode
= PRLI_REQ_EXECUTED
;
3805 npr
->estabImagePair
= 1;
3806 npr
->readXferRdyDis
= 1;
3807 npr
->ConfmComplAllowed
= 1;
3809 npr
->prliType
= PRLI_FCP_TYPE
;
3810 npr
->initiatorFunc
= 1;
3812 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
3813 "Issue ACC PRLI: did:x%x flg:x%x",
3814 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
3816 phba
->fc_stat
.elsXmitACC
++;
3817 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
3819 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
3820 if (rc
== IOCB_ERROR
) {
3821 lpfc_els_free_iocb(phba
, elsiocb
);
3828 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
3829 * @vport: pointer to a virtual N_Port data structure.
3830 * @format: rnid command format.
3831 * @oldiocb: pointer to the original lpfc command iocb data structure.
3832 * @ndlp: pointer to a node-list data structure.
3834 * This routine issues a Request Node Identification Data (RNID) Accept
3835 * (ACC) response. It constructs the RNID ACC response command according to
3836 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
3837 * issue the response. Note that this command does not need to hold the ndlp
3838 * reference count for the callback. So, the ndlp reference count taken by
3839 * the lpfc_prep_els_iocb() routine is put back and the context1 field of
3840 * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
3841 * there is no ndlp reference available.
3843 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3844 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3845 * will be stored into the context1 field of the IOCB for the completion
3846 * callback function. However, for the RNID Accept Response ELS command,
3847 * this is undone later by this routine after the IOCB is allocated.
3850 * 0 - Successfully issued acc rnid response
3851 * 1 - Failed to issue acc rnid response
3854 lpfc_els_rsp_rnid_acc(struct lpfc_vport
*vport
, uint8_t format
,
3855 struct lpfc_iocbq
*oldiocb
, struct lpfc_nodelist
*ndlp
)
3857 struct lpfc_hba
*phba
= vport
->phba
;
3859 IOCB_t
*icmd
, *oldcmd
;
3860 struct lpfc_iocbq
*elsiocb
;
3861 struct lpfc_sli
*psli
;
3867 cmdsize
= sizeof(uint32_t) + sizeof(uint32_t)
3868 + (2 * sizeof(struct lpfc_name
));
3870 cmdsize
+= sizeof(RNID_TOP_DISC
);
3872 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
, ndlp
,
3873 ndlp
->nlp_DID
, ELS_CMD_ACC
);
3877 icmd
= &elsiocb
->iocb
;
3878 oldcmd
= &oldiocb
->iocb
;
3879 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri */
3880 /* Xmit RNID ACC response tag <ulpIoTag> */
3881 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
3882 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
3883 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
);
3884 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
3885 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
3886 pcmd
+= sizeof(uint32_t);
3888 memset(pcmd
, 0, sizeof(RNID
));
3889 rn
= (RNID
*) (pcmd
);
3890 rn
->Format
= format
;
3891 rn
->CommonLen
= (2 * sizeof(struct lpfc_name
));
3892 memcpy(&rn
->portName
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
3893 memcpy(&rn
->nodeName
, &vport
->fc_nodename
, sizeof(struct lpfc_name
));
3896 rn
->SpecificLen
= 0;
3898 case RNID_TOPOLOGY_DISC
:
3899 rn
->SpecificLen
= sizeof(RNID_TOP_DISC
);
3900 memcpy(&rn
->un
.topologyDisc
.portName
,
3901 &vport
->fc_portname
, sizeof(struct lpfc_name
));
3902 rn
->un
.topologyDisc
.unitType
= RNID_HBA
;
3903 rn
->un
.topologyDisc
.physPort
= 0;
3904 rn
->un
.topologyDisc
.attachedNodes
= 0;
3908 rn
->SpecificLen
= 0;
3912 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
3913 "Issue ACC RNID: did:x%x flg:x%x",
3914 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
3916 phba
->fc_stat
.elsXmitACC
++;
3917 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
3919 elsiocb
->context1
= NULL
; /* Don't need ndlp for cmpl,
3920 * it could be freed */
3922 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
3923 if (rc
== IOCB_ERROR
) {
3924 lpfc_els_free_iocb(phba
, elsiocb
);
3931 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
3932 * @vport: pointer to a host virtual N_Port data structure.
3934 * This routine issues Address Discover (ADISC) ELS commands to those
3935 * N_Ports which are in node port recovery state and ADISC has not been issued
3936 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
3937 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
3938 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
3939 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
3940 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
3941 * IOCBs quit for later pick up. On the other hand, after walking through
3942 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
3943 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
3944 * no more ADISC need to be sent.
3947 * The number of N_Ports with adisc issued.
3950 lpfc_els_disc_adisc(struct lpfc_vport
*vport
)
3952 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
3953 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
3956 /* go thru NPR nodes and issue any remaining ELS ADISCs */
3957 list_for_each_entry_safe(ndlp
, next_ndlp
, &vport
->fc_nodes
, nlp_listp
) {
3958 if (!NLP_CHK_NODE_ACT(ndlp
))
3960 if (ndlp
->nlp_state
== NLP_STE_NPR_NODE
&&
3961 (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
) != 0 &&
3962 (ndlp
->nlp_flag
& NLP_NPR_ADISC
) != 0) {
3963 spin_lock_irq(shost
->host_lock
);
3964 ndlp
->nlp_flag
&= ~NLP_NPR_ADISC
;
3965 spin_unlock_irq(shost
->host_lock
);
3966 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
3967 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_ADISC_ISSUE
);
3968 lpfc_issue_els_adisc(vport
, ndlp
, 0);
3970 vport
->num_disc_nodes
++;
3971 if (vport
->num_disc_nodes
>=
3972 vport
->cfg_discovery_threads
) {
3973 spin_lock_irq(shost
->host_lock
);
3974 vport
->fc_flag
|= FC_NLP_MORE
;
3975 spin_unlock_irq(shost
->host_lock
);
3980 if (sentadisc
== 0) {
3981 spin_lock_irq(shost
->host_lock
);
3982 vport
->fc_flag
&= ~FC_NLP_MORE
;
3983 spin_unlock_irq(shost
->host_lock
);
3989 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
3990 * @vport: pointer to a host virtual N_Port data structure.
3992 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
3993 * which are in node port recovery state, with a @vport. Each time an ELS
3994 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
3995 * the per @vport number of discover count (num_disc_nodes) shall be
3996 * incremented. If the num_disc_nodes reaches a pre-configured threshold
3997 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
3998 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
3999 * later pick up. On the other hand, after walking through all the ndlps with
4000 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
4001 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
4002 * PLOGI need to be sent.
4005 * The number of N_Ports with plogi issued.
4008 lpfc_els_disc_plogi(struct lpfc_vport
*vport
)
4010 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4011 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
4014 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
4015 list_for_each_entry_safe(ndlp
, next_ndlp
, &vport
->fc_nodes
, nlp_listp
) {
4016 if (!NLP_CHK_NODE_ACT(ndlp
))
4018 if (ndlp
->nlp_state
== NLP_STE_NPR_NODE
&&
4019 (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
) != 0 &&
4020 (ndlp
->nlp_flag
& NLP_DELAY_TMO
) == 0 &&
4021 (ndlp
->nlp_flag
& NLP_NPR_ADISC
) == 0) {
4022 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
4023 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
4024 lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, 0);
4026 vport
->num_disc_nodes
++;
4027 if (vport
->num_disc_nodes
>=
4028 vport
->cfg_discovery_threads
) {
4029 spin_lock_irq(shost
->host_lock
);
4030 vport
->fc_flag
|= FC_NLP_MORE
;
4031 spin_unlock_irq(shost
->host_lock
);
4037 lpfc_set_disctmo(vport
);
4040 spin_lock_irq(shost
->host_lock
);
4041 vport
->fc_flag
&= ~FC_NLP_MORE
;
4042 spin_unlock_irq(shost
->host_lock
);
4048 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
4049 * @vport: pointer to a host virtual N_Port data structure.
4051 * This routine cleans up any Registration State Change Notification
4052 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
4053 * @vport together with the host_lock is used to prevent multiple thread
4054 * trying to access the RSCN array on a same @vport at the same time.
4057 lpfc_els_flush_rscn(struct lpfc_vport
*vport
)
4059 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4060 struct lpfc_hba
*phba
= vport
->phba
;
4063 spin_lock_irq(shost
->host_lock
);
4064 if (vport
->fc_rscn_flush
) {
4065 /* Another thread is walking fc_rscn_id_list on this vport */
4066 spin_unlock_irq(shost
->host_lock
);
4069 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
4070 vport
->fc_rscn_flush
= 1;
4071 spin_unlock_irq(shost
->host_lock
);
4073 for (i
= 0; i
< vport
->fc_rscn_id_cnt
; i
++) {
4074 lpfc_in_buf_free(phba
, vport
->fc_rscn_id_list
[i
]);
4075 vport
->fc_rscn_id_list
[i
] = NULL
;
4077 spin_lock_irq(shost
->host_lock
);
4078 vport
->fc_rscn_id_cnt
= 0;
4079 vport
->fc_flag
&= ~(FC_RSCN_MODE
| FC_RSCN_DISCOVERY
);
4080 spin_unlock_irq(shost
->host_lock
);
4081 lpfc_can_disctmo(vport
);
4082 /* Indicate we are done walking this fc_rscn_id_list */
4083 vport
->fc_rscn_flush
= 0;
4087 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
4088 * @vport: pointer to a host virtual N_Port data structure.
4089 * @did: remote destination port identifier.
4091 * This routine checks whether there is any pending Registration State
4092 * Configuration Notification (RSCN) to a @did on @vport.
4095 * None zero - The @did matched with a pending rscn
4096 * 0 - not able to match @did with a pending rscn
4099 lpfc_rscn_payload_check(struct lpfc_vport
*vport
, uint32_t did
)
4104 uint32_t payload_len
, i
;
4105 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4107 ns_did
.un
.word
= did
;
4109 /* Never match fabric nodes for RSCNs */
4110 if ((did
& Fabric_DID_MASK
) == Fabric_DID_MASK
)
4113 /* If we are doing a FULL RSCN rediscovery, match everything */
4114 if (vport
->fc_flag
& FC_RSCN_DISCOVERY
)
4117 spin_lock_irq(shost
->host_lock
);
4118 if (vport
->fc_rscn_flush
) {
4119 /* Another thread is walking fc_rscn_id_list on this vport */
4120 spin_unlock_irq(shost
->host_lock
);
4123 /* Indicate we are walking fc_rscn_id_list on this vport */
4124 vport
->fc_rscn_flush
= 1;
4125 spin_unlock_irq(shost
->host_lock
);
4126 for (i
= 0; i
< vport
->fc_rscn_id_cnt
; i
++) {
4127 lp
= vport
->fc_rscn_id_list
[i
]->virt
;
4128 payload_len
= be32_to_cpu(*lp
++ & ~ELS_CMD_MASK
);
4129 payload_len
-= sizeof(uint32_t); /* take off word 0 */
4130 while (payload_len
) {
4131 rscn_did
.un
.word
= be32_to_cpu(*lp
++);
4132 payload_len
-= sizeof(uint32_t);
4133 switch (rscn_did
.un
.b
.resv
& RSCN_ADDRESS_FORMAT_MASK
) {
4134 case RSCN_ADDRESS_FORMAT_PORT
:
4135 if ((ns_did
.un
.b
.domain
== rscn_did
.un
.b
.domain
)
4136 && (ns_did
.un
.b
.area
== rscn_did
.un
.b
.area
)
4137 && (ns_did
.un
.b
.id
== rscn_did
.un
.b
.id
))
4138 goto return_did_out
;
4140 case RSCN_ADDRESS_FORMAT_AREA
:
4141 if ((ns_did
.un
.b
.domain
== rscn_did
.un
.b
.domain
)
4142 && (ns_did
.un
.b
.area
== rscn_did
.un
.b
.area
))
4143 goto return_did_out
;
4145 case RSCN_ADDRESS_FORMAT_DOMAIN
:
4146 if (ns_did
.un
.b
.domain
== rscn_did
.un
.b
.domain
)
4147 goto return_did_out
;
4149 case RSCN_ADDRESS_FORMAT_FABRIC
:
4150 goto return_did_out
;
4154 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4155 vport
->fc_rscn_flush
= 0;
4158 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4159 vport
->fc_rscn_flush
= 0;
4164 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
4165 * @vport: pointer to a host virtual N_Port data structure.
4167 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
4168 * state machine for a @vport's nodes that are with pending RSCN (Registration
4169 * State Change Notification).
4172 * 0 - Successful (currently alway return 0)
4175 lpfc_rscn_recovery_check(struct lpfc_vport
*vport
)
4177 struct lpfc_nodelist
*ndlp
= NULL
;
4179 /* Move all affected nodes by pending RSCNs to NPR state. */
4180 list_for_each_entry(ndlp
, &vport
->fc_nodes
, nlp_listp
) {
4181 if (!NLP_CHK_NODE_ACT(ndlp
) ||
4182 (ndlp
->nlp_state
== NLP_STE_UNUSED_NODE
) ||
4183 !lpfc_rscn_payload_check(vport
, ndlp
->nlp_DID
))
4185 lpfc_disc_state_machine(vport
, ndlp
, NULL
,
4186 NLP_EVT_DEVICE_RECOVERY
);
4187 lpfc_cancel_retry_delay_tmo(vport
, ndlp
);
4193 * lpfc_send_rscn_event - Send an RSCN event to management application
4194 * @vport: pointer to a host virtual N_Port data structure.
4195 * @cmdiocb: pointer to lpfc command iocb data structure.
4197 * lpfc_send_rscn_event sends an RSCN netlink event to management
4201 lpfc_send_rscn_event(struct lpfc_vport
*vport
,
4202 struct lpfc_iocbq
*cmdiocb
)
4204 struct lpfc_dmabuf
*pcmd
;
4205 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4206 uint32_t *payload_ptr
;
4207 uint32_t payload_len
;
4208 struct lpfc_rscn_event_header
*rscn_event_data
;
4210 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
4211 payload_ptr
= (uint32_t *) pcmd
->virt
;
4212 payload_len
= be32_to_cpu(*payload_ptr
& ~ELS_CMD_MASK
);
4214 rscn_event_data
= kmalloc(sizeof(struct lpfc_rscn_event_header
) +
4215 payload_len
, GFP_KERNEL
);
4216 if (!rscn_event_data
) {
4217 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
4218 "0147 Failed to allocate memory for RSCN event\n");
4221 rscn_event_data
->event_type
= FC_REG_RSCN_EVENT
;
4222 rscn_event_data
->payload_length
= payload_len
;
4223 memcpy(rscn_event_data
->rscn_payload
, payload_ptr
,
4226 fc_host_post_vendor_event(shost
,
4227 fc_get_event_number(),
4228 sizeof(struct lpfc_els_event_header
) + payload_len
,
4229 (char *)rscn_event_data
,
4232 kfree(rscn_event_data
);
4236 * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
4237 * @vport: pointer to a host virtual N_Port data structure.
4238 * @cmdiocb: pointer to lpfc command iocb data structure.
4239 * @ndlp: pointer to a node-list data structure.
4241 * This routine processes an unsolicited RSCN (Registration State Change
4242 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
4243 * to invoke fc_host_post_event() routine to the FC transport layer. If the
4244 * discover state machine is about to begin discovery, it just accepts the
4245 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
4246 * contains N_Port IDs for other vports on this HBA, it just accepts the
4247 * RSCN and ignore processing it. If the state machine is in the recovery
4248 * state, the fc_rscn_id_list of this @vport is walked and the
4249 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
4250 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
4251 * routine is invoked to handle the RSCN event.
4254 * 0 - Just sent the acc response
4255 * 1 - Sent the acc response and waited for name server completion
4258 lpfc_els_rcv_rscn(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
4259 struct lpfc_nodelist
*ndlp
)
4261 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4262 struct lpfc_hba
*phba
= vport
->phba
;
4263 struct lpfc_dmabuf
*pcmd
;
4264 uint32_t *lp
, *datap
;
4266 uint32_t payload_len
, length
, nportid
, *cmd
;
4268 int rscn_id
= 0, hba_id
= 0;
4271 icmd
= &cmdiocb
->iocb
;
4272 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
4273 lp
= (uint32_t *) pcmd
->virt
;
4275 payload_len
= be32_to_cpu(*lp
++ & ~ELS_CMD_MASK
);
4276 payload_len
-= sizeof(uint32_t); /* take off word 0 */
4278 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
4279 "0214 RSCN received Data: x%x x%x x%x x%x\n",
4280 vport
->fc_flag
, payload_len
, *lp
,
4281 vport
->fc_rscn_id_cnt
);
4283 /* Send an RSCN event to the management application */
4284 lpfc_send_rscn_event(vport
, cmdiocb
);
4286 for (i
= 0; i
< payload_len
/sizeof(uint32_t); i
++)
4287 fc_host_post_event(shost
, fc_get_event_number(),
4288 FCH_EVT_RSCN
, lp
[i
]);
4290 /* If we are about to begin discovery, just ACC the RSCN.
4291 * Discovery processing will satisfy it.
4293 if (vport
->port_state
<= LPFC_NS_QRY
) {
4294 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
4295 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
4296 ndlp
->nlp_DID
, vport
->port_state
, ndlp
->nlp_flag
);
4298 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
4302 /* If this RSCN just contains NPortIDs for other vports on this HBA,
4303 * just ACC and ignore it.
4305 if ((phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
4306 !(vport
->cfg_peer_port_login
)) {
4311 nportid
= ((be32_to_cpu(nportid
)) & Mask_DID
);
4312 i
-= sizeof(uint32_t);
4314 if (lpfc_find_vport_by_did(phba
, nportid
))
4317 if (rscn_id
== hba_id
) {
4318 /* ALL NPortIDs in RSCN are on HBA */
4319 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
4321 "Data: x%x x%x x%x x%x\n",
4322 vport
->fc_flag
, payload_len
,
4323 *lp
, vport
->fc_rscn_id_cnt
);
4324 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
4325 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
4326 ndlp
->nlp_DID
, vport
->port_state
,
4329 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
,
4335 spin_lock_irq(shost
->host_lock
);
4336 if (vport
->fc_rscn_flush
) {
4337 /* Another thread is walking fc_rscn_id_list on this vport */
4338 vport
->fc_flag
|= FC_RSCN_DISCOVERY
;
4339 spin_unlock_irq(shost
->host_lock
);
4341 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
4344 /* Indicate we are walking fc_rscn_id_list on this vport */
4345 vport
->fc_rscn_flush
= 1;
4346 spin_unlock_irq(shost
->host_lock
);
4347 /* Get the array count after successfully have the token */
4348 rscn_cnt
= vport
->fc_rscn_id_cnt
;
4349 /* If we are already processing an RSCN, save the received
4350 * RSCN payload buffer, cmdiocb->context2 to process later.
4352 if (vport
->fc_flag
& (FC_RSCN_MODE
| FC_NDISC_ACTIVE
)) {
4353 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
4354 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
4355 ndlp
->nlp_DID
, vport
->port_state
, ndlp
->nlp_flag
);
4357 spin_lock_irq(shost
->host_lock
);
4358 vport
->fc_flag
|= FC_RSCN_DEFERRED
;
4359 if ((rscn_cnt
< FC_MAX_HOLD_RSCN
) &&
4360 !(vport
->fc_flag
& FC_RSCN_DISCOVERY
)) {
4361 vport
->fc_flag
|= FC_RSCN_MODE
;
4362 spin_unlock_irq(shost
->host_lock
);
4364 cmd
= vport
->fc_rscn_id_list
[rscn_cnt
-1]->virt
;
4365 length
= be32_to_cpu(*cmd
& ~ELS_CMD_MASK
);
4368 (payload_len
+ length
<= LPFC_BPL_SIZE
)) {
4369 *cmd
&= ELS_CMD_MASK
;
4370 *cmd
|= cpu_to_be32(payload_len
+ length
);
4371 memcpy(((uint8_t *)cmd
) + length
, lp
,
4374 vport
->fc_rscn_id_list
[rscn_cnt
] = pcmd
;
4375 vport
->fc_rscn_id_cnt
++;
4376 /* If we zero, cmdiocb->context2, the calling
4377 * routine will not try to free it.
4379 cmdiocb
->context2
= NULL
;
4382 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
4383 "0235 Deferred RSCN "
4384 "Data: x%x x%x x%x\n",
4385 vport
->fc_rscn_id_cnt
, vport
->fc_flag
,
4388 vport
->fc_flag
|= FC_RSCN_DISCOVERY
;
4389 spin_unlock_irq(shost
->host_lock
);
4390 /* ReDiscovery RSCN */
4391 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
4392 "0234 ReDiscovery RSCN "
4393 "Data: x%x x%x x%x\n",
4394 vport
->fc_rscn_id_cnt
, vport
->fc_flag
,
4397 /* Indicate we are done walking fc_rscn_id_list on this vport */
4398 vport
->fc_rscn_flush
= 0;
4400 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
4401 /* send RECOVERY event for ALL nodes that match RSCN payload */
4402 lpfc_rscn_recovery_check(vport
);
4403 spin_lock_irq(shost
->host_lock
);
4404 vport
->fc_flag
&= ~FC_RSCN_DEFERRED
;
4405 spin_unlock_irq(shost
->host_lock
);
4408 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
4409 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
4410 ndlp
->nlp_DID
, vport
->port_state
, ndlp
->nlp_flag
);
4412 spin_lock_irq(shost
->host_lock
);
4413 vport
->fc_flag
|= FC_RSCN_MODE
;
4414 spin_unlock_irq(shost
->host_lock
);
4415 vport
->fc_rscn_id_list
[vport
->fc_rscn_id_cnt
++] = pcmd
;
4416 /* Indicate we are done walking fc_rscn_id_list on this vport */
4417 vport
->fc_rscn_flush
= 0;
4419 * If we zero, cmdiocb->context2, the calling routine will
4420 * not try to free it.
4422 cmdiocb
->context2
= NULL
;
4423 lpfc_set_disctmo(vport
);
4425 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
4426 /* send RECOVERY event for ALL nodes that match RSCN payload */
4427 lpfc_rscn_recovery_check(vport
);
4428 return lpfc_els_handle_rscn(vport
);
4432 * lpfc_els_handle_rscn - Handle rscn for a vport
4433 * @vport: pointer to a host virtual N_Port data structure.
4435 * This routine handles the Registration State Configuration Notification
4436 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
4437 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
4438 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
4439 * NameServer shall be issued. If CT command to the NameServer fails to be
4440 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
4441 * RSCN activities with the @vport.
4444 * 0 - Cleaned up rscn on the @vport
4445 * 1 - Wait for plogi to name server before proceed
4448 lpfc_els_handle_rscn(struct lpfc_vport
*vport
)
4450 struct lpfc_nodelist
*ndlp
;
4451 struct lpfc_hba
*phba
= vport
->phba
;
4453 /* Ignore RSCN if the port is being torn down. */
4454 if (vport
->load_flag
& FC_UNLOADING
) {
4455 lpfc_els_flush_rscn(vport
);
4459 /* Start timer for RSCN processing */
4460 lpfc_set_disctmo(vport
);
4462 /* RSCN processed */
4463 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
4464 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
4465 vport
->fc_flag
, 0, vport
->fc_rscn_id_cnt
,
4468 /* To process RSCN, first compare RSCN data with NameServer */
4469 vport
->fc_ns_retry
= 0;
4470 vport
->num_disc_nodes
= 0;
4472 ndlp
= lpfc_findnode_did(vport
, NameServer_DID
);
4473 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
)
4474 && ndlp
->nlp_state
== NLP_STE_UNMAPPED_NODE
) {
4475 /* Good ndlp, issue CT Request to NameServer */
4476 if (lpfc_ns_cmd(vport
, SLI_CTNS_GID_FT
, 0, 0) == 0)
4477 /* Wait for NameServer query cmpl before we can
4481 /* If login to NameServer does not exist, issue one */
4482 /* Good status, issue PLOGI to NameServer */
4483 ndlp
= lpfc_findnode_did(vport
, NameServer_DID
);
4484 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
))
4485 /* Wait for NameServer login cmpl before we can
4490 ndlp
= lpfc_enable_node(vport
, ndlp
,
4491 NLP_STE_PLOGI_ISSUE
);
4493 lpfc_els_flush_rscn(vport
);
4496 ndlp
->nlp_prev_state
= NLP_STE_UNUSED_NODE
;
4498 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
4500 lpfc_els_flush_rscn(vport
);
4503 lpfc_nlp_init(vport
, ndlp
, NameServer_DID
);
4504 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
4505 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
4507 ndlp
->nlp_type
|= NLP_FABRIC
;
4508 lpfc_issue_els_plogi(vport
, NameServer_DID
, 0);
4509 /* Wait for NameServer login cmpl before we can
4515 lpfc_els_flush_rscn(vport
);
4520 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
4521 * @vport: pointer to a host virtual N_Port data structure.
4522 * @cmdiocb: pointer to lpfc command iocb data structure.
4523 * @ndlp: pointer to a node-list data structure.
4525 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
4526 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
4527 * point topology. As an unsolicited FLOGI should not be received in a loop
4528 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
4529 * lpfc_check_sparm() routine is invoked to check the parameters in the
4530 * unsolicited FLOGI. If parameters validation failed, the routine
4531 * lpfc_els_rsp_reject() shall be called with reject reason code set to
4532 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
4533 * FLOGI shall be compared with the Port WWN of the @vport to determine who
4534 * will initiate PLOGI. The higher lexicographical value party shall has
4535 * higher priority (as the winning port) and will initiate PLOGI and
4536 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
4537 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
4538 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
4541 * 0 - Successfully processed the unsolicited flogi
4542 * 1 - Failed to process the unsolicited flogi
4545 lpfc_els_rcv_flogi(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
4546 struct lpfc_nodelist
*ndlp
)
4548 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4549 struct lpfc_hba
*phba
= vport
->phba
;
4550 struct lpfc_dmabuf
*pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
4551 uint32_t *lp
= (uint32_t *) pcmd
->virt
;
4552 IOCB_t
*icmd
= &cmdiocb
->iocb
;
4553 struct serv_parm
*sp
;
4560 sp
= (struct serv_parm
*) lp
;
4562 /* FLOGI received */
4564 lpfc_set_disctmo(vport
);
4566 if (phba
->fc_topology
== TOPOLOGY_LOOP
) {
4567 /* We should never receive a FLOGI in loop mode, ignore it */
4568 did
= icmd
->un
.elsreq64
.remoteID
;
4570 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
4572 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
4573 "0113 An FLOGI ELS command x%x was "
4574 "received from DID x%x in Loop Mode\n",
4581 if ((lpfc_check_sparm(vport
, ndlp
, sp
, CLASS3
, 1))) {
4582 /* For a FLOGI we accept, then if our portname is greater
4583 * then the remote portname we initiate Nport login.
4586 rc
= memcmp(&vport
->fc_portname
, &sp
->portName
,
4587 sizeof(struct lpfc_name
));
4590 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4594 lpfc_linkdown(phba
);
4595 lpfc_init_link(phba
, mbox
,
4597 phba
->cfg_link_speed
);
4598 mbox
->u
.mb
.un
.varInitLnk
.lipsr_AL_PA
= 0;
4599 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
4600 mbox
->vport
= vport
;
4601 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
4602 lpfc_set_loopback_flag(phba
);
4603 if (rc
== MBX_NOT_FINISHED
) {
4604 mempool_free(mbox
, phba
->mbox_mem_pool
);
4607 } else if (rc
> 0) { /* greater than */
4608 spin_lock_irq(shost
->host_lock
);
4609 vport
->fc_flag
|= FC_PT2PT_PLOGI
;
4610 spin_unlock_irq(shost
->host_lock
);
4612 spin_lock_irq(shost
->host_lock
);
4613 vport
->fc_flag
|= FC_PT2PT
;
4614 vport
->fc_flag
&= ~(FC_FABRIC
| FC_PUBLIC_LOOP
);
4615 spin_unlock_irq(shost
->host_lock
);
4617 /* Reject this request because invalid parameters */
4618 stat
.un
.b
.lsRjtRsvd0
= 0;
4619 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
4620 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_SPARM_OPTIONS
;
4621 stat
.un
.b
.vendorUnique
= 0;
4622 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
,
4628 lpfc_els_rsp_acc(vport
, ELS_CMD_PLOGI
, cmdiocb
, ndlp
, NULL
);
4634 * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
4635 * @vport: pointer to a host virtual N_Port data structure.
4636 * @cmdiocb: pointer to lpfc command iocb data structure.
4637 * @ndlp: pointer to a node-list data structure.
4639 * This routine processes Request Node Identification Data (RNID) IOCB
4640 * received as an ELS unsolicited event. Only when the RNID specified format
4641 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
4642 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
4643 * Accept (ACC) the RNID ELS command. All the other RNID formats are
4644 * rejected by invoking the lpfc_els_rsp_reject() routine.
4647 * 0 - Successfully processed rnid iocb (currently always return 0)
4650 lpfc_els_rcv_rnid(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
4651 struct lpfc_nodelist
*ndlp
)
4653 struct lpfc_dmabuf
*pcmd
;
4660 icmd
= &cmdiocb
->iocb
;
4661 did
= icmd
->un
.elsreq64
.remoteID
;
4662 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
4663 lp
= (uint32_t *) pcmd
->virt
;
4670 switch (rn
->Format
) {
4672 case RNID_TOPOLOGY_DISC
:
4674 lpfc_els_rsp_rnid_acc(vport
, rn
->Format
, cmdiocb
, ndlp
);
4677 /* Reject this request because format not supported */
4678 stat
.un
.b
.lsRjtRsvd0
= 0;
4679 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
4680 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_CANT_GIVE_DATA
;
4681 stat
.un
.b
.vendorUnique
= 0;
4682 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
,
4689 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
4690 * @vport: pointer to a host virtual N_Port data structure.
4691 * @cmdiocb: pointer to lpfc command iocb data structure.
4692 * @ndlp: pointer to a node-list data structure.
4694 * This routine processes a Link Incident Report Registration(LIRR) IOCB
4695 * received as an ELS unsolicited event. Currently, this function just invokes
4696 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
4699 * 0 - Successfully processed lirr iocb (currently always return 0)
4702 lpfc_els_rcv_lirr(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
4703 struct lpfc_nodelist
*ndlp
)
4707 /* For now, unconditionally reject this command */
4708 stat
.un
.b
.lsRjtRsvd0
= 0;
4709 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
4710 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_CANT_GIVE_DATA
;
4711 stat
.un
.b
.vendorUnique
= 0;
4712 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
4717 * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb
4718 * @vport: pointer to a host virtual N_Port data structure.
4719 * @cmdiocb: pointer to lpfc command iocb data structure.
4720 * @ndlp: pointer to a node-list data structure.
4722 * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB
4723 * received as an ELS unsolicited event. A request to RRQ shall only
4724 * be accepted if the Originator Nx_Port N_Port_ID or the Responder
4725 * Nx_Port N_Port_ID of the target Exchange is the same as the
4726 * N_Port_ID of the Nx_Port that makes the request. If the RRQ is
4727 * not accepted, an LS_RJT with reason code "Unable to perform
4728 * command request" and reason code explanation "Invalid Originator
4729 * S_ID" shall be returned. For now, we just unconditionally accept
4730 * RRQ from the target.
4733 lpfc_els_rcv_rrq(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
4734 struct lpfc_nodelist
*ndlp
)
4736 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
4740 * lpfc_els_rsp_rps_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
4741 * @phba: pointer to lpfc hba data structure.
4742 * @pmb: pointer to the driver internal queue element for mailbox command.
4744 * This routine is the completion callback function for the MBX_READ_LNK_STAT
4745 * mailbox command. This callback function is to actually send the Accept
4746 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
4747 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
4748 * mailbox command, constructs the RPS response with the link statistics
4749 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
4750 * response to the RPS.
4752 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4753 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4754 * will be stored into the context1 field of the IOCB for the completion
4755 * callback function to the RPS Accept Response ELS IOCB command.
4759 lpfc_els_rsp_rps_acc(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
4765 struct lpfc_iocbq
*elsiocb
;
4766 struct lpfc_nodelist
*ndlp
;
4767 uint16_t xri
, status
;
4772 ndlp
= (struct lpfc_nodelist
*) pmb
->context2
;
4773 xri
= (uint16_t) ((unsigned long)(pmb
->context1
));
4774 pmb
->context1
= NULL
;
4775 pmb
->context2
= NULL
;
4777 if (mb
->mbxStatus
) {
4778 mempool_free(pmb
, phba
->mbox_mem_pool
);
4782 cmdsize
= sizeof(RPS_RSP
) + sizeof(uint32_t);
4783 mempool_free(pmb
, phba
->mbox_mem_pool
);
4784 elsiocb
= lpfc_prep_els_iocb(phba
->pport
, 0, cmdsize
,
4785 lpfc_max_els_tries
, ndlp
,
4786 ndlp
->nlp_DID
, ELS_CMD_ACC
);
4788 /* Decrement the ndlp reference count from previous mbox command */
4794 icmd
= &elsiocb
->iocb
;
4795 icmd
->ulpContext
= xri
;
4797 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
4798 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
4799 pcmd
+= sizeof(uint32_t); /* Skip past command */
4800 rps_rsp
= (RPS_RSP
*)pcmd
;
4802 if (phba
->fc_topology
!= TOPOLOGY_LOOP
)
4806 if (phba
->pport
->fc_flag
& FC_FABRIC
)
4810 rps_rsp
->portStatus
= cpu_to_be16(status
);
4811 rps_rsp
->linkFailureCnt
= cpu_to_be32(mb
->un
.varRdLnk
.linkFailureCnt
);
4812 rps_rsp
->lossSyncCnt
= cpu_to_be32(mb
->un
.varRdLnk
.lossSyncCnt
);
4813 rps_rsp
->lossSignalCnt
= cpu_to_be32(mb
->un
.varRdLnk
.lossSignalCnt
);
4814 rps_rsp
->primSeqErrCnt
= cpu_to_be32(mb
->un
.varRdLnk
.primSeqErrCnt
);
4815 rps_rsp
->invalidXmitWord
= cpu_to_be32(mb
->un
.varRdLnk
.invalidXmitWord
);
4816 rps_rsp
->crcCnt
= cpu_to_be32(mb
->un
.varRdLnk
.crcCnt
);
4817 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
4818 lpfc_printf_vlog(ndlp
->vport
, KERN_INFO
, LOG_ELS
,
4819 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
4820 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
4821 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
,
4822 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
4824 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
4825 phba
->fc_stat
.elsXmitACC
++;
4826 if (lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0) == IOCB_ERROR
)
4827 lpfc_els_free_iocb(phba
, elsiocb
);
4832 * lpfc_els_rcv_rps - Process an unsolicited rps iocb
4833 * @vport: pointer to a host virtual N_Port data structure.
4834 * @cmdiocb: pointer to lpfc command iocb data structure.
4835 * @ndlp: pointer to a node-list data structure.
4837 * This routine processes Read Port Status (RPS) IOCB received as an
4838 * ELS unsolicited event. It first checks the remote port state. If the
4839 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
4840 * state, it invokes the lpfc_els_rsp_reject() routine to send the reject
4841 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
4842 * for reading the HBA link statistics. It is for the callback function,
4843 * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command
4844 * to actually sending out RPS Accept (ACC) response.
4847 * 0 - Successfully processed rps iocb (currently always return 0)
4850 lpfc_els_rcv_rps(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
4851 struct lpfc_nodelist
*ndlp
)
4853 struct lpfc_hba
*phba
= vport
->phba
;
4857 struct lpfc_dmabuf
*pcmd
;
4861 if ((ndlp
->nlp_state
!= NLP_STE_UNMAPPED_NODE
) &&
4862 (ndlp
->nlp_state
!= NLP_STE_MAPPED_NODE
))
4863 /* reject the unsolicited RPS request and done with it */
4866 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
4867 lp
= (uint32_t *) pcmd
->virt
;
4868 flag
= (be32_to_cpu(*lp
++) & 0xf);
4872 ((flag
== 1) && (be32_to_cpu(rps
->un
.portNum
) == 0)) ||
4873 ((flag
== 2) && (memcmp(&rps
->un
.portName
, &vport
->fc_portname
,
4874 sizeof(struct lpfc_name
)) == 0))) {
4876 printk("Fix me....\n");
4878 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_ATOMIC
);
4880 lpfc_read_lnk_stat(phba
, mbox
);
4882 (void *)((unsigned long) cmdiocb
->iocb
.ulpContext
);
4883 mbox
->context2
= lpfc_nlp_get(ndlp
);
4884 mbox
->vport
= vport
;
4885 mbox
->mbox_cmpl
= lpfc_els_rsp_rps_acc
;
4886 if (lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
)
4887 != MBX_NOT_FINISHED
)
4888 /* Mbox completion will send ELS Response */
4890 /* Decrement reference count used for the failed mbox
4894 mempool_free(mbox
, phba
->mbox_mem_pool
);
4899 /* issue rejection response */
4900 stat
.un
.b
.lsRjtRsvd0
= 0;
4901 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
4902 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_CANT_GIVE_DATA
;
4903 stat
.un
.b
.vendorUnique
= 0;
4904 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
4909 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
4910 * @vport: pointer to a host virtual N_Port data structure.
4911 * @cmdsize: size of the ELS command.
4912 * @oldiocb: pointer to the original lpfc command iocb data structure.
4913 * @ndlp: pointer to a node-list data structure.
4915 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
4916 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
4918 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4919 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4920 * will be stored into the context1 field of the IOCB for the completion
4921 * callback function to the RPL Accept Response ELS command.
4924 * 0 - Successfully issued ACC RPL ELS command
4925 * 1 - Failed to issue ACC RPL ELS command
4928 lpfc_els_rsp_rpl_acc(struct lpfc_vport
*vport
, uint16_t cmdsize
,
4929 struct lpfc_iocbq
*oldiocb
, struct lpfc_nodelist
*ndlp
)
4931 struct lpfc_hba
*phba
= vport
->phba
;
4932 IOCB_t
*icmd
, *oldcmd
;
4934 struct lpfc_iocbq
*elsiocb
;
4937 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
, ndlp
,
4938 ndlp
->nlp_DID
, ELS_CMD_ACC
);
4943 icmd
= &elsiocb
->iocb
;
4944 oldcmd
= &oldiocb
->iocb
;
4945 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri */
4947 pcmd
= (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
4948 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
4949 pcmd
+= sizeof(uint16_t);
4950 *((uint16_t *)(pcmd
)) = be16_to_cpu(cmdsize
);
4951 pcmd
+= sizeof(uint16_t);
4953 /* Setup the RPL ACC payload */
4954 rpl_rsp
.listLen
= be32_to_cpu(1);
4956 rpl_rsp
.port_num_blk
.portNum
= 0;
4957 rpl_rsp
.port_num_blk
.portID
= be32_to_cpu(vport
->fc_myDID
);
4958 memcpy(&rpl_rsp
.port_num_blk
.portName
, &vport
->fc_portname
,
4959 sizeof(struct lpfc_name
));
4960 memcpy(pcmd
, &rpl_rsp
, cmdsize
- sizeof(uint32_t));
4961 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
4962 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
4963 "0120 Xmit ELS RPL ACC response tag x%x "
4964 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
4966 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
,
4967 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
4969 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
4970 phba
->fc_stat
.elsXmitACC
++;
4971 if (lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0) ==
4973 lpfc_els_free_iocb(phba
, elsiocb
);
4980 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
4981 * @vport: pointer to a host virtual N_Port data structure.
4982 * @cmdiocb: pointer to lpfc command iocb data structure.
4983 * @ndlp: pointer to a node-list data structure.
4985 * This routine processes Read Port List (RPL) IOCB received as an ELS
4986 * unsolicited event. It first checks the remote port state. If the remote
4987 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
4988 * invokes the lpfc_els_rsp_reject() routine to send reject response.
4989 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
4990 * to accept the RPL.
4993 * 0 - Successfully processed rpl iocb (currently always return 0)
4996 lpfc_els_rcv_rpl(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
4997 struct lpfc_nodelist
*ndlp
)
4999 struct lpfc_dmabuf
*pcmd
;
5006 if ((ndlp
->nlp_state
!= NLP_STE_UNMAPPED_NODE
) &&
5007 (ndlp
->nlp_state
!= NLP_STE_MAPPED_NODE
)) {
5008 /* issue rejection response */
5009 stat
.un
.b
.lsRjtRsvd0
= 0;
5010 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
5011 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_CANT_GIVE_DATA
;
5012 stat
.un
.b
.vendorUnique
= 0;
5013 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
,
5015 /* rejected the unsolicited RPL request and done with it */
5019 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
5020 lp
= (uint32_t *) pcmd
->virt
;
5021 rpl
= (RPL
*) (lp
+ 1);
5023 maxsize
= be32_to_cpu(rpl
->maxsize
);
5025 /* We support only one port */
5026 if ((rpl
->index
== 0) &&
5028 ((maxsize
* sizeof(uint32_t)) >= sizeof(RPL_RSP
)))) {
5029 cmdsize
= sizeof(uint32_t) + sizeof(RPL_RSP
);
5031 cmdsize
= sizeof(uint32_t) + maxsize
* sizeof(uint32_t);
5033 lpfc_els_rsp_rpl_acc(vport
, cmdsize
, cmdiocb
, ndlp
);
5039 * lpfc_els_rcv_farp - Process an unsolicited farp request els command
5040 * @vport: pointer to a virtual N_Port data structure.
5041 * @cmdiocb: pointer to lpfc command iocb data structure.
5042 * @ndlp: pointer to a node-list data structure.
5044 * This routine processes Fibre Channel Address Resolution Protocol
5045 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
5046 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
5047 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
5048 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
5049 * remote PortName is compared against the FC PortName stored in the @vport
5050 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
5051 * compared against the FC NodeName stored in the @vport data structure.
5052 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
5053 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
5054 * invoked to send out FARP Response to the remote node. Before sending the
5055 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
5056 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
5057 * routine is invoked to log into the remote port first.
5060 * 0 - Either the FARP Match Mode not supported or successfully processed
5063 lpfc_els_rcv_farp(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
5064 struct lpfc_nodelist
*ndlp
)
5066 struct lpfc_dmabuf
*pcmd
;
5070 uint32_t cmd
, cnt
, did
;
5072 icmd
= &cmdiocb
->iocb
;
5073 did
= icmd
->un
.elsreq64
.remoteID
;
5074 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
5075 lp
= (uint32_t *) pcmd
->virt
;
5079 /* FARP-REQ received from DID <did> */
5080 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
5081 "0601 FARP-REQ received from DID x%x\n", did
);
5082 /* We will only support match on WWPN or WWNN */
5083 if (fp
->Mflags
& ~(FARP_MATCH_NODE
| FARP_MATCH_PORT
)) {
5088 /* If this FARP command is searching for my portname */
5089 if (fp
->Mflags
& FARP_MATCH_PORT
) {
5090 if (memcmp(&fp
->RportName
, &vport
->fc_portname
,
5091 sizeof(struct lpfc_name
)) == 0)
5095 /* If this FARP command is searching for my nodename */
5096 if (fp
->Mflags
& FARP_MATCH_NODE
) {
5097 if (memcmp(&fp
->RnodeName
, &vport
->fc_nodename
,
5098 sizeof(struct lpfc_name
)) == 0)
5103 if ((ndlp
->nlp_state
== NLP_STE_UNMAPPED_NODE
) ||
5104 (ndlp
->nlp_state
== NLP_STE_MAPPED_NODE
)) {
5105 /* Log back into the node before sending the FARP. */
5106 if (fp
->Rflags
& FARP_REQUEST_PLOGI
) {
5107 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
5108 lpfc_nlp_set_state(vport
, ndlp
,
5109 NLP_STE_PLOGI_ISSUE
);
5110 lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, 0);
5113 /* Send a FARP response to that node */
5114 if (fp
->Rflags
& FARP_REQUEST_FARPR
)
5115 lpfc_issue_els_farpr(vport
, did
, 0);
5122 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
5123 * @vport: pointer to a host virtual N_Port data structure.
5124 * @cmdiocb: pointer to lpfc command iocb data structure.
5125 * @ndlp: pointer to a node-list data structure.
5127 * This routine processes Fibre Channel Address Resolution Protocol
5128 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
5129 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
5130 * the FARP response request.
5133 * 0 - Successfully processed FARPR IOCB (currently always return 0)
5136 lpfc_els_rcv_farpr(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
5137 struct lpfc_nodelist
*ndlp
)
5139 struct lpfc_dmabuf
*pcmd
;
5144 icmd
= &cmdiocb
->iocb
;
5145 did
= icmd
->un
.elsreq64
.remoteID
;
5146 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
5147 lp
= (uint32_t *) pcmd
->virt
;
5150 /* FARP-RSP received from DID <did> */
5151 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
5152 "0600 FARP-RSP received from DID x%x\n", did
);
5153 /* ACCEPT the Farp resp request */
5154 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
5160 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
5161 * @vport: pointer to a host virtual N_Port data structure.
5162 * @cmdiocb: pointer to lpfc command iocb data structure.
5163 * @fan_ndlp: pointer to a node-list data structure.
5165 * This routine processes a Fabric Address Notification (FAN) IOCB
5166 * command received as an ELS unsolicited event. The FAN ELS command will
5167 * only be processed on a physical port (i.e., the @vport represents the
5168 * physical port). The fabric NodeName and PortName from the FAN IOCB are
5169 * compared against those in the phba data structure. If any of those is
5170 * different, the lpfc_initial_flogi() routine is invoked to initialize
5171 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
5172 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
5173 * is invoked to register login to the fabric.
5176 * 0 - Successfully processed fan iocb (currently always return 0).
5179 lpfc_els_rcv_fan(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
5180 struct lpfc_nodelist
*fan_ndlp
)
5182 struct lpfc_hba
*phba
= vport
->phba
;
5186 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
, "0265 FAN received\n");
5187 lp
= (uint32_t *)((struct lpfc_dmabuf
*)cmdiocb
->context2
)->virt
;
5189 /* FAN received; Fan does not have a reply sequence */
5190 if ((vport
== phba
->pport
) &&
5191 (vport
->port_state
== LPFC_LOCAL_CFG_LINK
)) {
5192 if ((memcmp(&phba
->fc_fabparam
.nodeName
, &fp
->FnodeName
,
5193 sizeof(struct lpfc_name
))) ||
5194 (memcmp(&phba
->fc_fabparam
.portName
, &fp
->FportName
,
5195 sizeof(struct lpfc_name
)))) {
5196 /* This port has switched fabrics. FLOGI is required */
5197 lpfc_initial_flogi(vport
);
5199 /* FAN verified - skip FLOGI */
5200 vport
->fc_myDID
= vport
->fc_prevDID
;
5201 if (phba
->sli_rev
< LPFC_SLI_REV4
)
5202 lpfc_issue_fabric_reglogin(vport
);
5204 lpfc_issue_reg_vfi(vport
);
5211 * lpfc_els_timeout - Handler funciton to the els timer
5212 * @ptr: holder for the timer function associated data.
5214 * This routine is invoked by the ELS timer after timeout. It posts the ELS
5215 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
5216 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
5217 * up the worker thread. It is for the worker thread to invoke the routine
5218 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
5221 lpfc_els_timeout(unsigned long ptr
)
5223 struct lpfc_vport
*vport
= (struct lpfc_vport
*) ptr
;
5224 struct lpfc_hba
*phba
= vport
->phba
;
5225 uint32_t tmo_posted
;
5226 unsigned long iflag
;
5228 spin_lock_irqsave(&vport
->work_port_lock
, iflag
);
5229 tmo_posted
= vport
->work_port_events
& WORKER_ELS_TMO
;
5231 vport
->work_port_events
|= WORKER_ELS_TMO
;
5232 spin_unlock_irqrestore(&vport
->work_port_lock
, iflag
);
5235 lpfc_worker_wake_up(phba
);
5241 * lpfc_els_timeout_handler - Process an els timeout event
5242 * @vport: pointer to a virtual N_Port data structure.
5244 * This routine is the actual handler function that processes an ELS timeout
5245 * event. It walks the ELS ring to get and abort all the IOCBs (except the
5246 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
5247 * invoking the lpfc_sli_issue_abort_iotag() routine.
5250 lpfc_els_timeout_handler(struct lpfc_vport
*vport
)
5252 struct lpfc_hba
*phba
= vport
->phba
;
5253 struct lpfc_sli_ring
*pring
;
5254 struct lpfc_iocbq
*tmp_iocb
, *piocb
;
5256 struct lpfc_dmabuf
*pcmd
;
5257 uint32_t els_command
= 0;
5259 uint32_t remote_ID
= 0xffffffff;
5260 LIST_HEAD(txcmplq_completions
);
5261 LIST_HEAD(abort_list
);
5264 timeout
= (uint32_t)(phba
->fc_ratov
<< 1);
5266 pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
5268 spin_lock_irq(&phba
->hbalock
);
5269 list_splice_init(&pring
->txcmplq
, &txcmplq_completions
);
5270 spin_unlock_irq(&phba
->hbalock
);
5272 list_for_each_entry_safe(piocb
, tmp_iocb
, &txcmplq_completions
, list
) {
5275 if ((piocb
->iocb_flag
& LPFC_IO_LIBDFC
) != 0 ||
5276 piocb
->iocb
.ulpCommand
== CMD_ABORT_XRI_CN
||
5277 piocb
->iocb
.ulpCommand
== CMD_CLOSE_XRI_CN
)
5280 if (piocb
->vport
!= vport
)
5283 pcmd
= (struct lpfc_dmabuf
*) piocb
->context2
;
5285 els_command
= *(uint32_t *) (pcmd
->virt
);
5287 if (els_command
== ELS_CMD_FARP
||
5288 els_command
== ELS_CMD_FARPR
||
5289 els_command
== ELS_CMD_FDISC
)
5292 if (piocb
->drvrTimeout
> 0) {
5293 if (piocb
->drvrTimeout
>= timeout
)
5294 piocb
->drvrTimeout
-= timeout
;
5296 piocb
->drvrTimeout
= 0;
5300 remote_ID
= 0xffffffff;
5301 if (cmd
->ulpCommand
!= CMD_GEN_REQUEST64_CR
)
5302 remote_ID
= cmd
->un
.elsreq64
.remoteID
;
5304 struct lpfc_nodelist
*ndlp
;
5305 ndlp
= __lpfc_findnode_rpi(vport
, cmd
->ulpContext
);
5306 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
))
5307 remote_ID
= ndlp
->nlp_DID
;
5309 list_add_tail(&piocb
->dlist
, &abort_list
);
5311 spin_lock_irq(&phba
->hbalock
);
5312 list_splice(&txcmplq_completions
, &pring
->txcmplq
);
5313 spin_unlock_irq(&phba
->hbalock
);
5315 list_for_each_entry_safe(piocb
, tmp_iocb
, &abort_list
, dlist
) {
5316 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
5317 "0127 ELS timeout Data: x%x x%x x%x "
5318 "x%x\n", els_command
,
5319 remote_ID
, cmd
->ulpCommand
, cmd
->ulpIoTag
);
5320 spin_lock_irq(&phba
->hbalock
);
5321 list_del_init(&piocb
->dlist
);
5322 lpfc_sli_issue_abort_iotag(phba
, pring
, piocb
);
5323 spin_unlock_irq(&phba
->hbalock
);
5326 if (phba
->sli
.ring
[LPFC_ELS_RING
].txcmplq_cnt
)
5327 mod_timer(&vport
->els_tmofunc
, jiffies
+ HZ
* timeout
);
5331 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
5332 * @vport: pointer to a host virtual N_Port data structure.
5334 * This routine is used to clean up all the outstanding ELS commands on a
5335 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
5336 * routine. After that, it walks the ELS transmit queue to remove all the
5337 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
5338 * the IOCBs with a non-NULL completion callback function, the callback
5339 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
5340 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
5341 * callback function, the IOCB will simply be released. Finally, it walks
5342 * the ELS transmit completion queue to issue an abort IOCB to any transmit
5343 * completion queue IOCB that is associated with the @vport and is not
5344 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
5345 * part of the discovery state machine) out to HBA by invoking the
5346 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
5347 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
5348 * the IOCBs are aborted when this function returns.
5351 lpfc_els_flush_cmd(struct lpfc_vport
*vport
)
5353 LIST_HEAD(completions
);
5354 struct lpfc_hba
*phba
= vport
->phba
;
5355 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
5356 struct lpfc_iocbq
*tmp_iocb
, *piocb
;
5359 lpfc_fabric_abort_vport(vport
);
5361 spin_lock_irq(&phba
->hbalock
);
5362 list_for_each_entry_safe(piocb
, tmp_iocb
, &pring
->txq
, list
) {
5365 if (piocb
->iocb_flag
& LPFC_IO_LIBDFC
) {
5369 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
5370 if (cmd
->ulpCommand
== CMD_QUE_RING_BUF_CN
||
5371 cmd
->ulpCommand
== CMD_QUE_RING_BUF64_CN
||
5372 cmd
->ulpCommand
== CMD_CLOSE_XRI_CN
||
5373 cmd
->ulpCommand
== CMD_ABORT_XRI_CN
)
5376 if (piocb
->vport
!= vport
)
5379 list_move_tail(&piocb
->list
, &completions
);
5383 list_for_each_entry_safe(piocb
, tmp_iocb
, &pring
->txcmplq
, list
) {
5384 if (piocb
->iocb_flag
& LPFC_IO_LIBDFC
) {
5388 if (piocb
->vport
!= vport
)
5391 lpfc_sli_issue_abort_iotag(phba
, pring
, piocb
);
5393 spin_unlock_irq(&phba
->hbalock
);
5395 /* Cancell all the IOCBs from the completions list */
5396 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
5403 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
5404 * @phba: pointer to lpfc hba data structure.
5406 * This routine is used to clean up all the outstanding ELS commands on a
5407 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
5408 * routine. After that, it walks the ELS transmit queue to remove all the
5409 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
5410 * the IOCBs with the completion callback function associated, the callback
5411 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
5412 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
5413 * callback function associated, the IOCB will simply be released. Finally,
5414 * it walks the ELS transmit completion queue to issue an abort IOCB to any
5415 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
5416 * management plane IOCBs that are not part of the discovery state machine)
5417 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
5420 lpfc_els_flush_all_cmd(struct lpfc_hba
*phba
)
5422 LIST_HEAD(completions
);
5423 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
5424 struct lpfc_iocbq
*tmp_iocb
, *piocb
;
5427 lpfc_fabric_abort_hba(phba
);
5428 spin_lock_irq(&phba
->hbalock
);
5429 list_for_each_entry_safe(piocb
, tmp_iocb
, &pring
->txq
, list
) {
5431 if (piocb
->iocb_flag
& LPFC_IO_LIBDFC
)
5433 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
5434 if (cmd
->ulpCommand
== CMD_QUE_RING_BUF_CN
||
5435 cmd
->ulpCommand
== CMD_QUE_RING_BUF64_CN
||
5436 cmd
->ulpCommand
== CMD_CLOSE_XRI_CN
||
5437 cmd
->ulpCommand
== CMD_ABORT_XRI_CN
)
5439 list_move_tail(&piocb
->list
, &completions
);
5442 list_for_each_entry_safe(piocb
, tmp_iocb
, &pring
->txcmplq
, list
) {
5443 if (piocb
->iocb_flag
& LPFC_IO_LIBDFC
)
5445 lpfc_sli_issue_abort_iotag(phba
, pring
, piocb
);
5447 spin_unlock_irq(&phba
->hbalock
);
5449 /* Cancel all the IOCBs from the completions list */
5450 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
5457 * lpfc_send_els_failure_event - Posts an ELS command failure event
5458 * @phba: Pointer to hba context object.
5459 * @cmdiocbp: Pointer to command iocb which reported error.
5460 * @rspiocbp: Pointer to response iocb which reported error.
5462 * This function sends an event when there is an ELS command
5466 lpfc_send_els_failure_event(struct lpfc_hba
*phba
,
5467 struct lpfc_iocbq
*cmdiocbp
,
5468 struct lpfc_iocbq
*rspiocbp
)
5470 struct lpfc_vport
*vport
= cmdiocbp
->vport
;
5471 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
5472 struct lpfc_lsrjt_event lsrjt_event
;
5473 struct lpfc_fabric_event_header fabric_event
;
5475 struct lpfc_nodelist
*ndlp
;
5478 ndlp
= cmdiocbp
->context1
;
5479 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
))
5482 if (rspiocbp
->iocb
.ulpStatus
== IOSTAT_LS_RJT
) {
5483 lsrjt_event
.header
.event_type
= FC_REG_ELS_EVENT
;
5484 lsrjt_event
.header
.subcategory
= LPFC_EVENT_LSRJT_RCV
;
5485 memcpy(lsrjt_event
.header
.wwpn
, &ndlp
->nlp_portname
,
5486 sizeof(struct lpfc_name
));
5487 memcpy(lsrjt_event
.header
.wwnn
, &ndlp
->nlp_nodename
,
5488 sizeof(struct lpfc_name
));
5489 pcmd
= (uint32_t *) (((struct lpfc_dmabuf
*)
5490 cmdiocbp
->context2
)->virt
);
5491 lsrjt_event
.command
= (pcmd
!= NULL
) ? *pcmd
: 0;
5492 stat
.un
.lsRjtError
= be32_to_cpu(rspiocbp
->iocb
.un
.ulpWord
[4]);
5493 lsrjt_event
.reason_code
= stat
.un
.b
.lsRjtRsnCode
;
5494 lsrjt_event
.explanation
= stat
.un
.b
.lsRjtRsnCodeExp
;
5495 fc_host_post_vendor_event(shost
,
5496 fc_get_event_number(),
5497 sizeof(lsrjt_event
),
5498 (char *)&lsrjt_event
,
5502 if ((rspiocbp
->iocb
.ulpStatus
== IOSTAT_NPORT_BSY
) ||
5503 (rspiocbp
->iocb
.ulpStatus
== IOSTAT_FABRIC_BSY
)) {
5504 fabric_event
.event_type
= FC_REG_FABRIC_EVENT
;
5505 if (rspiocbp
->iocb
.ulpStatus
== IOSTAT_NPORT_BSY
)
5506 fabric_event
.subcategory
= LPFC_EVENT_PORT_BUSY
;
5508 fabric_event
.subcategory
= LPFC_EVENT_FABRIC_BUSY
;
5509 memcpy(fabric_event
.wwpn
, &ndlp
->nlp_portname
,
5510 sizeof(struct lpfc_name
));
5511 memcpy(fabric_event
.wwnn
, &ndlp
->nlp_nodename
,
5512 sizeof(struct lpfc_name
));
5513 fc_host_post_vendor_event(shost
,
5514 fc_get_event_number(),
5515 sizeof(fabric_event
),
5516 (char *)&fabric_event
,
5524 * lpfc_send_els_event - Posts unsolicited els event
5525 * @vport: Pointer to vport object.
5526 * @ndlp: Pointer FC node object.
5527 * @cmd: ELS command code.
5529 * This function posts an event when there is an incoming
5530 * unsolicited ELS command.
5533 lpfc_send_els_event(struct lpfc_vport
*vport
,
5534 struct lpfc_nodelist
*ndlp
,
5537 struct lpfc_els_event_header
*els_data
= NULL
;
5538 struct lpfc_logo_event
*logo_data
= NULL
;
5539 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
5541 if (*payload
== ELS_CMD_LOGO
) {
5542 logo_data
= kmalloc(sizeof(struct lpfc_logo_event
), GFP_KERNEL
);
5544 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
5545 "0148 Failed to allocate memory "
5546 "for LOGO event\n");
5549 els_data
= &logo_data
->header
;
5551 els_data
= kmalloc(sizeof(struct lpfc_els_event_header
),
5554 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
5555 "0149 Failed to allocate memory "
5560 els_data
->event_type
= FC_REG_ELS_EVENT
;
5563 els_data
->subcategory
= LPFC_EVENT_PLOGI_RCV
;
5566 els_data
->subcategory
= LPFC_EVENT_PRLO_RCV
;
5569 els_data
->subcategory
= LPFC_EVENT_ADISC_RCV
;
5572 els_data
->subcategory
= LPFC_EVENT_LOGO_RCV
;
5573 /* Copy the WWPN in the LOGO payload */
5574 memcpy(logo_data
->logo_wwpn
, &payload
[2],
5575 sizeof(struct lpfc_name
));
5581 memcpy(els_data
->wwpn
, &ndlp
->nlp_portname
, sizeof(struct lpfc_name
));
5582 memcpy(els_data
->wwnn
, &ndlp
->nlp_nodename
, sizeof(struct lpfc_name
));
5583 if (*payload
== ELS_CMD_LOGO
) {
5584 fc_host_post_vendor_event(shost
,
5585 fc_get_event_number(),
5586 sizeof(struct lpfc_logo_event
),
5591 fc_host_post_vendor_event(shost
,
5592 fc_get_event_number(),
5593 sizeof(struct lpfc_els_event_header
),
5604 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
5605 * @phba: pointer to lpfc hba data structure.
5606 * @pring: pointer to a SLI ring.
5607 * @vport: pointer to a host virtual N_Port data structure.
5608 * @elsiocb: pointer to lpfc els command iocb data structure.
5610 * This routine is used for processing the IOCB associated with a unsolicited
5611 * event. It first determines whether there is an existing ndlp that matches
5612 * the DID from the unsolicited IOCB. If not, it will create a new one with
5613 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
5614 * IOCB is then used to invoke the proper routine and to set up proper state
5615 * of the discovery state machine.
5618 lpfc_els_unsol_buffer(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
5619 struct lpfc_vport
*vport
, struct lpfc_iocbq
*elsiocb
)
5621 struct Scsi_Host
*shost
;
5622 struct lpfc_nodelist
*ndlp
;
5625 uint32_t cmd
, did
, newnode
, rjt_err
= 0;
5626 IOCB_t
*icmd
= &elsiocb
->iocb
;
5628 if (!vport
|| !(elsiocb
->context2
))
5632 payload
= ((struct lpfc_dmabuf
*)elsiocb
->context2
)->virt
;
5634 if ((phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) == 0)
5635 lpfc_post_buffer(phba
, pring
, 1);
5637 did
= icmd
->un
.rcvels
.remoteID
;
5638 if (icmd
->ulpStatus
) {
5639 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
5640 "RCV Unsol ELS: status:x%x/x%x did:x%x",
5641 icmd
->ulpStatus
, icmd
->un
.ulpWord
[4], did
);
5645 /* Check to see if link went down during discovery */
5646 if (lpfc_els_chk_latt(vport
))
5649 /* Ignore traffic received during vport shutdown. */
5650 if (vport
->load_flag
& FC_UNLOADING
)
5653 ndlp
= lpfc_findnode_did(vport
, did
);
5655 /* Cannot find existing Fabric ndlp, so allocate a new one */
5656 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
5660 lpfc_nlp_init(vport
, ndlp
, did
);
5661 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
5663 if ((did
& Fabric_DID_MASK
) == Fabric_DID_MASK
)
5664 ndlp
->nlp_type
|= NLP_FABRIC
;
5665 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
5666 ndlp
= lpfc_enable_node(vport
, ndlp
,
5667 NLP_STE_UNUSED_NODE
);
5670 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
5672 if ((did
& Fabric_DID_MASK
) == Fabric_DID_MASK
)
5673 ndlp
->nlp_type
|= NLP_FABRIC
;
5674 } else if (ndlp
->nlp_state
== NLP_STE_UNUSED_NODE
) {
5675 /* This is similar to the new node path */
5676 ndlp
= lpfc_nlp_get(ndlp
);
5679 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
5683 phba
->fc_stat
.elsRcvFrame
++;
5685 elsiocb
->context1
= lpfc_nlp_get(ndlp
);
5686 elsiocb
->vport
= vport
;
5688 if ((cmd
& ELS_CMD_MASK
) == ELS_CMD_RSCN
) {
5689 cmd
&= ELS_CMD_MASK
;
5691 /* ELS command <elsCmd> received from NPORT <did> */
5692 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
5693 "0112 ELS command x%x received from NPORT x%x "
5694 "Data: x%x\n", cmd
, did
, vport
->port_state
);
5697 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
5698 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
5699 did
, vport
->port_state
, ndlp
->nlp_flag
);
5701 phba
->fc_stat
.elsRcvPLOGI
++;
5702 ndlp
= lpfc_plogi_confirm_nport(phba
, payload
, ndlp
);
5704 lpfc_send_els_event(vport
, ndlp
, payload
);
5705 if (vport
->port_state
< LPFC_DISC_AUTH
) {
5706 if (!(phba
->pport
->fc_flag
& FC_PT2PT
) ||
5707 (phba
->pport
->fc_flag
& FC_PT2PT_PLOGI
)) {
5708 rjt_err
= LSRJT_UNABLE_TPC
;
5711 /* We get here, and drop thru, if we are PT2PT with
5712 * another NPort and the other side has initiated
5713 * the PLOGI before responding to our FLOGI.
5717 shost
= lpfc_shost_from_vport(vport
);
5718 spin_lock_irq(shost
->host_lock
);
5719 ndlp
->nlp_flag
&= ~NLP_TARGET_REMOVE
;
5720 spin_unlock_irq(shost
->host_lock
);
5722 lpfc_disc_state_machine(vport
, ndlp
, elsiocb
,
5727 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
5728 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
5729 did
, vport
->port_state
, ndlp
->nlp_flag
);
5731 phba
->fc_stat
.elsRcvFLOGI
++;
5732 lpfc_els_rcv_flogi(vport
, elsiocb
, ndlp
);
5737 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
5738 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
5739 did
, vport
->port_state
, ndlp
->nlp_flag
);
5741 phba
->fc_stat
.elsRcvLOGO
++;
5742 lpfc_send_els_event(vport
, ndlp
, payload
);
5743 if (vport
->port_state
< LPFC_DISC_AUTH
) {
5744 rjt_err
= LSRJT_UNABLE_TPC
;
5747 lpfc_disc_state_machine(vport
, ndlp
, elsiocb
, NLP_EVT_RCV_LOGO
);
5750 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
5751 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
5752 did
, vport
->port_state
, ndlp
->nlp_flag
);
5754 phba
->fc_stat
.elsRcvPRLO
++;
5755 lpfc_send_els_event(vport
, ndlp
, payload
);
5756 if (vport
->port_state
< LPFC_DISC_AUTH
) {
5757 rjt_err
= LSRJT_UNABLE_TPC
;
5760 lpfc_disc_state_machine(vport
, ndlp
, elsiocb
, NLP_EVT_RCV_PRLO
);
5763 phba
->fc_stat
.elsRcvRSCN
++;
5764 lpfc_els_rcv_rscn(vport
, elsiocb
, ndlp
);
5769 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
5770 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
5771 did
, vport
->port_state
, ndlp
->nlp_flag
);
5773 lpfc_send_els_event(vport
, ndlp
, payload
);
5774 phba
->fc_stat
.elsRcvADISC
++;
5775 if (vport
->port_state
< LPFC_DISC_AUTH
) {
5776 rjt_err
= LSRJT_UNABLE_TPC
;
5779 lpfc_disc_state_machine(vport
, ndlp
, elsiocb
,
5783 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
5784 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
5785 did
, vport
->port_state
, ndlp
->nlp_flag
);
5787 phba
->fc_stat
.elsRcvPDISC
++;
5788 if (vport
->port_state
< LPFC_DISC_AUTH
) {
5789 rjt_err
= LSRJT_UNABLE_TPC
;
5792 lpfc_disc_state_machine(vport
, ndlp
, elsiocb
,
5796 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
5797 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
5798 did
, vport
->port_state
, ndlp
->nlp_flag
);
5800 phba
->fc_stat
.elsRcvFARPR
++;
5801 lpfc_els_rcv_farpr(vport
, elsiocb
, ndlp
);
5804 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
5805 "RCV FARP: did:x%x/ste:x%x flg:x%x",
5806 did
, vport
->port_state
, ndlp
->nlp_flag
);
5808 phba
->fc_stat
.elsRcvFARP
++;
5809 lpfc_els_rcv_farp(vport
, elsiocb
, ndlp
);
5812 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
5813 "RCV FAN: did:x%x/ste:x%x flg:x%x",
5814 did
, vport
->port_state
, ndlp
->nlp_flag
);
5816 phba
->fc_stat
.elsRcvFAN
++;
5817 lpfc_els_rcv_fan(vport
, elsiocb
, ndlp
);
5820 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
5821 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
5822 did
, vport
->port_state
, ndlp
->nlp_flag
);
5824 phba
->fc_stat
.elsRcvPRLI
++;
5825 if (vport
->port_state
< LPFC_DISC_AUTH
) {
5826 rjt_err
= LSRJT_UNABLE_TPC
;
5829 lpfc_disc_state_machine(vport
, ndlp
, elsiocb
, NLP_EVT_RCV_PRLI
);
5832 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
5833 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
5834 did
, vport
->port_state
, ndlp
->nlp_flag
);
5836 phba
->fc_stat
.elsRcvLIRR
++;
5837 lpfc_els_rcv_lirr(vport
, elsiocb
, ndlp
);
5842 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
5843 "RCV RPS: did:x%x/ste:x%x flg:x%x",
5844 did
, vport
->port_state
, ndlp
->nlp_flag
);
5846 phba
->fc_stat
.elsRcvRPS
++;
5847 lpfc_els_rcv_rps(vport
, elsiocb
, ndlp
);
5852 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
5853 "RCV RPL: did:x%x/ste:x%x flg:x%x",
5854 did
, vport
->port_state
, ndlp
->nlp_flag
);
5856 phba
->fc_stat
.elsRcvRPL
++;
5857 lpfc_els_rcv_rpl(vport
, elsiocb
, ndlp
);
5862 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
5863 "RCV RNID: did:x%x/ste:x%x flg:x%x",
5864 did
, vport
->port_state
, ndlp
->nlp_flag
);
5866 phba
->fc_stat
.elsRcvRNID
++;
5867 lpfc_els_rcv_rnid(vport
, elsiocb
, ndlp
);
5872 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
5873 "RCV RRQ: did:x%x/ste:x%x flg:x%x",
5874 did
, vport
->port_state
, ndlp
->nlp_flag
);
5876 phba
->fc_stat
.elsRcvRRQ
++;
5877 lpfc_els_rcv_rrq(vport
, elsiocb
, ndlp
);
5882 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
5883 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
5884 cmd
, did
, vport
->port_state
);
5886 /* Unsupported ELS command, reject */
5887 rjt_err
= LSRJT_INVALID_CMD
;
5889 /* Unknown ELS command <elsCmd> received from NPORT <did> */
5890 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
5891 "0115 Unknown ELS command x%x "
5892 "received from NPORT x%x\n", cmd
, did
);
5898 /* check if need to LS_RJT received ELS cmd */
5900 memset(&stat
, 0, sizeof(stat
));
5901 stat
.un
.b
.lsRjtRsnCode
= rjt_err
;
5902 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_NOTHING_MORE
;
5903 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, elsiocb
, ndlp
,
5907 lpfc_nlp_put(elsiocb
->context1
);
5908 elsiocb
->context1
= NULL
;
5912 if (vport
&& !(vport
->load_flag
& FC_UNLOADING
))
5913 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
5914 "0111 Dropping received ELS cmd "
5915 "Data: x%x x%x x%x\n",
5916 icmd
->ulpStatus
, icmd
->un
.ulpWord
[4], icmd
->ulpTimeout
);
5917 phba
->fc_stat
.elsRcvDrop
++;
5921 * lpfc_find_vport_by_vpid - Find a vport on a HBA through vport identifier
5922 * @phba: pointer to lpfc hba data structure.
5923 * @vpi: host virtual N_Port identifier.
5925 * This routine finds a vport on a HBA (referred by @phba) through a
5926 * @vpi. The function walks the HBA's vport list and returns the address
5927 * of the vport with the matching @vpi.
5930 * NULL - No vport with the matching @vpi found
5931 * Otherwise - Address to the vport with the matching @vpi.
5934 lpfc_find_vport_by_vpid(struct lpfc_hba
*phba
, uint16_t vpi
)
5936 struct lpfc_vport
*vport
;
5937 unsigned long flags
;
5939 spin_lock_irqsave(&phba
->hbalock
, flags
);
5940 list_for_each_entry(vport
, &phba
->port_list
, listentry
) {
5941 if (vport
->vpi
== vpi
) {
5942 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
5946 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
5951 * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
5952 * @phba: pointer to lpfc hba data structure.
5953 * @pring: pointer to a SLI ring.
5954 * @elsiocb: pointer to lpfc els iocb data structure.
5956 * This routine is used to process an unsolicited event received from a SLI
5957 * (Service Level Interface) ring. The actual processing of the data buffer
5958 * associated with the unsolicited event is done by invoking the routine
5959 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
5960 * SLI ring on which the unsolicited event was received.
5963 lpfc_els_unsol_event(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
5964 struct lpfc_iocbq
*elsiocb
)
5966 struct lpfc_vport
*vport
= phba
->pport
;
5967 IOCB_t
*icmd
= &elsiocb
->iocb
;
5969 struct lpfc_dmabuf
*bdeBuf1
= elsiocb
->context2
;
5970 struct lpfc_dmabuf
*bdeBuf2
= elsiocb
->context3
;
5972 elsiocb
->context1
= NULL
;
5973 elsiocb
->context2
= NULL
;
5974 elsiocb
->context3
= NULL
;
5976 if (icmd
->ulpStatus
== IOSTAT_NEED_BUFFER
) {
5977 lpfc_sli_hbqbuf_add_hbqs(phba
, LPFC_ELS_HBQ
);
5978 } else if (icmd
->ulpStatus
== IOSTAT_LOCAL_REJECT
&&
5979 (icmd
->un
.ulpWord
[4] & 0xff) == IOERR_RCV_BUFFER_WAITING
) {
5980 phba
->fc_stat
.NoRcvBuf
++;
5981 /* Not enough posted buffers; Try posting more buffers */
5982 if (!(phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
))
5983 lpfc_post_buffer(phba
, pring
, 0);
5987 if ((phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
5988 (icmd
->ulpCommand
== CMD_IOCB_RCV_ELS64_CX
||
5989 icmd
->ulpCommand
== CMD_IOCB_RCV_SEQ64_CX
)) {
5990 if (icmd
->unsli3
.rcvsli3
.vpi
== 0xffff)
5991 vport
= phba
->pport
;
5993 vport
= lpfc_find_vport_by_vpid(phba
,
5994 icmd
->unsli3
.rcvsli3
.vpi
- phba
->vpi_base
);
5996 /* If there are no BDEs associated
5997 * with this IOCB, there is nothing to do.
5999 if (icmd
->ulpBdeCount
== 0)
6002 /* type of ELS cmd is first 32bit word
6005 if (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) {
6006 elsiocb
->context2
= bdeBuf1
;
6008 paddr
= getPaddr(icmd
->un
.cont64
[0].addrHigh
,
6009 icmd
->un
.cont64
[0].addrLow
);
6010 elsiocb
->context2
= lpfc_sli_ringpostbuf_get(phba
, pring
,
6014 lpfc_els_unsol_buffer(phba
, pring
, vport
, elsiocb
);
6016 * The different unsolicited event handlers would tell us
6017 * if they are done with "mp" by setting context2 to NULL.
6019 if (elsiocb
->context2
) {
6020 lpfc_in_buf_free(phba
, (struct lpfc_dmabuf
*)elsiocb
->context2
);
6021 elsiocb
->context2
= NULL
;
6024 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
6025 if ((phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) &&
6026 icmd
->ulpBdeCount
== 2) {
6027 elsiocb
->context2
= bdeBuf2
;
6028 lpfc_els_unsol_buffer(phba
, pring
, vport
, elsiocb
);
6029 /* free mp if we are done with it */
6030 if (elsiocb
->context2
) {
6031 lpfc_in_buf_free(phba
, elsiocb
->context2
);
6032 elsiocb
->context2
= NULL
;
6038 * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
6039 * @phba: pointer to lpfc hba data structure.
6040 * @vport: pointer to a virtual N_Port data structure.
6042 * This routine issues a Port Login (PLOGI) to the Name Server with
6043 * State Change Request (SCR) for a @vport. This routine will create an
6044 * ndlp for the Name Server associated to the @vport if such node does
6045 * not already exist. The PLOGI to Name Server is issued by invoking the
6046 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
6047 * (FDMI) is configured to the @vport, a FDMI node will be created and
6048 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
6051 lpfc_do_scr_ns_plogi(struct lpfc_hba
*phba
, struct lpfc_vport
*vport
)
6053 struct lpfc_nodelist
*ndlp
, *ndlp_fdmi
;
6055 ndlp
= lpfc_findnode_did(vport
, NameServer_DID
);
6057 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
6059 if (phba
->fc_topology
== TOPOLOGY_LOOP
) {
6060 lpfc_disc_start(vport
);
6063 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
6064 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
6065 "0251 NameServer login: no memory\n");
6068 lpfc_nlp_init(vport
, ndlp
, NameServer_DID
);
6069 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
6070 ndlp
= lpfc_enable_node(vport
, ndlp
, NLP_STE_UNUSED_NODE
);
6072 if (phba
->fc_topology
== TOPOLOGY_LOOP
) {
6073 lpfc_disc_start(vport
);
6076 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
6077 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
6078 "0348 NameServer login: node freed\n");
6082 ndlp
->nlp_type
|= NLP_FABRIC
;
6084 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
6086 if (lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, 0)) {
6087 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
6088 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
6089 "0252 Cannot issue NameServer login\n");
6093 if (vport
->cfg_fdmi_on
) {
6094 ndlp_fdmi
= mempool_alloc(phba
->nlp_mem_pool
,
6097 lpfc_nlp_init(vport
, ndlp_fdmi
, FDMI_DID
);
6098 ndlp_fdmi
->nlp_type
|= NLP_FABRIC
;
6099 lpfc_nlp_set_state(vport
, ndlp_fdmi
,
6100 NLP_STE_PLOGI_ISSUE
);
6101 lpfc_issue_els_plogi(vport
, ndlp_fdmi
->nlp_DID
,
6109 * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
6110 * @phba: pointer to lpfc hba data structure.
6111 * @pmb: pointer to the driver internal queue element for mailbox command.
6113 * This routine is the completion callback function to register new vport
6114 * mailbox command. If the new vport mailbox command completes successfully,
6115 * the fabric registration login shall be performed on physical port (the
6116 * new vport created is actually a physical port, with VPI 0) or the port
6117 * login to Name Server for State Change Request (SCR) will be performed
6118 * on virtual port (real virtual port, with VPI greater than 0).
6121 lpfc_cmpl_reg_new_vport(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
6123 struct lpfc_vport
*vport
= pmb
->vport
;
6124 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
6125 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) pmb
->context2
;
6126 MAILBOX_t
*mb
= &pmb
->u
.mb
;
6129 spin_lock_irq(shost
->host_lock
);
6130 vport
->fc_flag
&= ~FC_VPORT_NEEDS_REG_VPI
;
6131 spin_unlock_irq(shost
->host_lock
);
6133 if (mb
->mbxStatus
) {
6134 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
6135 "0915 Register VPI failed : Status: x%x"
6136 " upd bit: x%x \n", mb
->mbxStatus
,
6137 mb
->un
.varRegVpi
.upd
);
6138 if (phba
->sli_rev
== LPFC_SLI_REV4
&&
6139 mb
->un
.varRegVpi
.upd
)
6140 goto mbox_err_exit
;
6142 switch (mb
->mbxStatus
) {
6143 case 0x11: /* unsupported feature */
6144 case 0x9603: /* max_vpi exceeded */
6145 case 0x9602: /* Link event since CLEAR_LA */
6146 /* giving up on vport registration */
6147 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
6148 spin_lock_irq(shost
->host_lock
);
6149 vport
->fc_flag
&= ~(FC_FABRIC
| FC_PUBLIC_LOOP
);
6150 spin_unlock_irq(shost
->host_lock
);
6151 lpfc_can_disctmo(vport
);
6153 /* If reg_vpi fail with invalid VPI status, re-init VPI */
6155 spin_lock_irq(shost
->host_lock
);
6156 vport
->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
6157 spin_unlock_irq(shost
->host_lock
);
6158 lpfc_init_vpi(phba
, pmb
, vport
->vpi
);
6160 pmb
->mbox_cmpl
= lpfc_init_vpi_cmpl
;
6161 rc
= lpfc_sli_issue_mbox(phba
, pmb
,
6163 if (rc
== MBX_NOT_FINISHED
) {
6164 lpfc_printf_vlog(vport
,
6166 "2732 Failed to issue INIT_VPI"
6167 " mailbox command\n");
6174 /* Try to recover from this error */
6175 lpfc_mbx_unreg_vpi(vport
);
6176 spin_lock_irq(shost
->host_lock
);
6177 vport
->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
6178 spin_unlock_irq(shost
->host_lock
);
6179 if (vport
->port_type
== LPFC_PHYSICAL_PORT
6180 && !(vport
->fc_flag
& FC_LOGO_RCVD_DID_CHNG
))
6181 lpfc_initial_flogi(vport
);
6183 lpfc_initial_fdisc(vport
);
6187 spin_lock_irq(shost
->host_lock
);
6188 vport
->vpi_state
|= LPFC_VPI_REGISTERED
;
6189 spin_unlock_irq(shost
->host_lock
);
6190 if (vport
== phba
->pport
) {
6191 if (phba
->sli_rev
< LPFC_SLI_REV4
)
6192 lpfc_issue_fabric_reglogin(vport
);
6195 * If the physical port is instantiated using
6196 * FDISC, do not start vport discovery.
6198 if (vport
->port_state
!= LPFC_FDISC
)
6199 lpfc_start_fdiscs(phba
);
6200 lpfc_do_scr_ns_plogi(phba
, vport
);
6203 lpfc_do_scr_ns_plogi(phba
, vport
);
6206 /* Now, we decrement the ndlp reference count held for this
6211 mempool_free(pmb
, phba
->mbox_mem_pool
);
6216 * lpfc_register_new_vport - Register a new vport with a HBA
6217 * @phba: pointer to lpfc hba data structure.
6218 * @vport: pointer to a host virtual N_Port data structure.
6219 * @ndlp: pointer to a node-list data structure.
6221 * This routine registers the @vport as a new virtual port with a HBA.
6222 * It is done through a registering vpi mailbox command.
6225 lpfc_register_new_vport(struct lpfc_hba
*phba
, struct lpfc_vport
*vport
,
6226 struct lpfc_nodelist
*ndlp
)
6228 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
6231 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
6233 lpfc_reg_vpi(vport
, mbox
);
6234 mbox
->vport
= vport
;
6235 mbox
->context2
= lpfc_nlp_get(ndlp
);
6236 mbox
->mbox_cmpl
= lpfc_cmpl_reg_new_vport
;
6237 if (lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
)
6238 == MBX_NOT_FINISHED
) {
6239 /* mailbox command not success, decrement ndlp
6240 * reference count for this command
6243 mempool_free(mbox
, phba
->mbox_mem_pool
);
6245 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
6246 "0253 Register VPI: Can't send mbox\n");
6250 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
6251 "0254 Register VPI: no memory\n");
6257 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
6258 spin_lock_irq(shost
->host_lock
);
6259 vport
->fc_flag
&= ~FC_VPORT_NEEDS_REG_VPI
;
6260 spin_unlock_irq(shost
->host_lock
);
6265 * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer
6266 * @phba: pointer to lpfc hba data structure.
6268 * This routine cancels the retry delay timers to all the vports.
6271 lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba
*phba
)
6273 struct lpfc_vport
**vports
;
6274 struct lpfc_nodelist
*ndlp
;
6275 uint32_t link_state
;
6278 /* Treat this failure as linkdown for all vports */
6279 link_state
= phba
->link_state
;
6280 lpfc_linkdown(phba
);
6281 phba
->link_state
= link_state
;
6283 vports
= lpfc_create_vport_work_array(phba
);
6286 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
6287 ndlp
= lpfc_findnode_did(vports
[i
], Fabric_DID
);
6289 lpfc_cancel_retry_delay_tmo(vports
[i
], ndlp
);
6290 lpfc_els_flush_cmd(vports
[i
]);
6292 lpfc_destroy_vport_work_array(phba
, vports
);
6297 * lpfc_retry_pport_discovery - Start timer to retry FLOGI.
6298 * @phba: pointer to lpfc hba data structure.
6300 * This routine abort all pending discovery commands and
6301 * start a timer to retry FLOGI for the physical port
6305 lpfc_retry_pport_discovery(struct lpfc_hba
*phba
)
6307 struct lpfc_nodelist
*ndlp
;
6308 struct Scsi_Host
*shost
;
6310 /* Cancel the all vports retry delay retry timers */
6311 lpfc_cancel_all_vport_retry_delay_timer(phba
);
6313 /* If fabric require FLOGI, then re-instantiate physical login */
6314 ndlp
= lpfc_findnode_did(phba
->pport
, Fabric_DID
);
6318 shost
= lpfc_shost_from_vport(phba
->pport
);
6319 mod_timer(&ndlp
->nlp_delayfunc
, jiffies
+ HZ
);
6320 spin_lock_irq(shost
->host_lock
);
6321 ndlp
->nlp_flag
|= NLP_DELAY_TMO
;
6322 spin_unlock_irq(shost
->host_lock
);
6323 ndlp
->nlp_last_elscmd
= ELS_CMD_FLOGI
;
6324 phba
->pport
->port_state
= LPFC_FLOGI
;
6329 * lpfc_fabric_login_reqd - Check if FLOGI required.
6330 * @phba: pointer to lpfc hba data structure.
6331 * @cmdiocb: pointer to FDISC command iocb.
6332 * @rspiocb: pointer to FDISC response iocb.
6334 * This routine checks if a FLOGI is reguired for FDISC
6338 lpfc_fabric_login_reqd(struct lpfc_hba
*phba
,
6339 struct lpfc_iocbq
*cmdiocb
,
6340 struct lpfc_iocbq
*rspiocb
)
6343 if ((rspiocb
->iocb
.ulpStatus
!= IOSTAT_FABRIC_RJT
) ||
6344 (rspiocb
->iocb
.un
.ulpWord
[4] != RJT_LOGIN_REQUIRED
))
6351 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
6352 * @phba: pointer to lpfc hba data structure.
6353 * @cmdiocb: pointer to lpfc command iocb data structure.
6354 * @rspiocb: pointer to lpfc response iocb data structure.
6356 * This routine is the completion callback function to a Fabric Discover
6357 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
6358 * single threaded, each FDISC completion callback function will reset
6359 * the discovery timer for all vports such that the timers will not get
6360 * unnecessary timeout. The function checks the FDISC IOCB status. If error
6361 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
6362 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
6363 * assigned to the vport has been changed with the completion of the FDISC
6364 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
6365 * are unregistered from the HBA, and then the lpfc_register_new_vport()
6366 * routine is invoked to register new vport with the HBA. Otherwise, the
6367 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
6368 * Server for State Change Request (SCR).
6371 lpfc_cmpl_els_fdisc(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
6372 struct lpfc_iocbq
*rspiocb
)
6374 struct lpfc_vport
*vport
= cmdiocb
->vport
;
6375 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
6376 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) cmdiocb
->context1
;
6377 struct lpfc_nodelist
*np
;
6378 struct lpfc_nodelist
*next_np
;
6379 IOCB_t
*irsp
= &rspiocb
->iocb
;
6380 struct lpfc_iocbq
*piocb
;
6382 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
6383 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
6384 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
6386 /* Since all FDISCs are being single threaded, we
6387 * must reset the discovery timer for ALL vports
6388 * waiting to send FDISC when one completes.
6390 list_for_each_entry(piocb
, &phba
->fabric_iocb_list
, list
) {
6391 lpfc_set_disctmo(piocb
->vport
);
6394 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
6395 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
6396 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4], vport
->fc_prevDID
);
6398 if (irsp
->ulpStatus
) {
6400 if (lpfc_fabric_login_reqd(phba
, cmdiocb
, rspiocb
)) {
6401 lpfc_retry_pport_discovery(phba
);
6405 /* Check for retry */
6406 if (lpfc_els_retry(phba
, cmdiocb
, rspiocb
))
6409 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
6410 "0126 FDISC failed. (%d/%d)\n",
6411 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4]);
6414 spin_lock_irq(shost
->host_lock
);
6415 vport
->fc_flag
&= ~FC_VPORT_CVL_RCVD
;
6416 vport
->fc_flag
&= ~FC_VPORT_LOGO_RCVD
;
6417 vport
->fc_flag
|= FC_FABRIC
;
6418 if (vport
->phba
->fc_topology
== TOPOLOGY_LOOP
)
6419 vport
->fc_flag
|= FC_PUBLIC_LOOP
;
6420 spin_unlock_irq(shost
->host_lock
);
6422 vport
->fc_myDID
= irsp
->un
.ulpWord
[4] & Mask_DID
;
6423 lpfc_vport_set_state(vport
, FC_VPORT_ACTIVE
);
6424 if ((vport
->fc_prevDID
!= vport
->fc_myDID
) &&
6425 !(vport
->fc_flag
& FC_VPORT_NEEDS_REG_VPI
)) {
6426 /* If our NportID changed, we need to ensure all
6427 * remaining NPORTs get unreg_login'ed so we can
6430 list_for_each_entry_safe(np
, next_np
,
6431 &vport
->fc_nodes
, nlp_listp
) {
6432 if (!NLP_CHK_NODE_ACT(ndlp
) ||
6433 (np
->nlp_state
!= NLP_STE_NPR_NODE
) ||
6434 !(np
->nlp_flag
& NLP_NPR_ADISC
))
6436 spin_lock_irq(shost
->host_lock
);
6437 np
->nlp_flag
&= ~NLP_NPR_ADISC
;
6438 spin_unlock_irq(shost
->host_lock
);
6439 lpfc_unreg_rpi(vport
, np
);
6441 lpfc_cleanup_pending_mbox(vport
);
6442 lpfc_mbx_unreg_vpi(vport
);
6443 spin_lock_irq(shost
->host_lock
);
6444 vport
->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
6445 if (phba
->sli_rev
== LPFC_SLI_REV4
)
6446 vport
->fc_flag
|= FC_VPORT_NEEDS_INIT_VPI
;
6448 vport
->fc_flag
|= FC_LOGO_RCVD_DID_CHNG
;
6449 spin_unlock_irq(shost
->host_lock
);
6450 } else if ((phba
->sli_rev
== LPFC_SLI_REV4
) &&
6451 !(vport
->fc_flag
& FC_VPORT_NEEDS_REG_VPI
)) {
6453 * Driver needs to re-reg VPI in order for f/w
6454 * to update the MAC address.
6456 lpfc_register_new_vport(phba
, vport
, ndlp
);
6460 if (vport
->fc_flag
& FC_VPORT_NEEDS_INIT_VPI
)
6461 lpfc_issue_init_vpi(vport
);
6462 else if (vport
->fc_flag
& FC_VPORT_NEEDS_REG_VPI
)
6463 lpfc_register_new_vport(phba
, vport
, ndlp
);
6465 lpfc_do_scr_ns_plogi(phba
, vport
);
6468 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
6469 /* Cancel discovery timer */
6470 lpfc_can_disctmo(vport
);
6473 lpfc_els_free_iocb(phba
, cmdiocb
);
6477 * lpfc_issue_els_fdisc - Issue a fdisc iocb command
6478 * @vport: pointer to a virtual N_Port data structure.
6479 * @ndlp: pointer to a node-list data structure.
6480 * @retry: number of retries to the command IOCB.
6482 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
6483 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
6484 * routine to issue the IOCB, which makes sure only one outstanding fabric
6485 * IOCB will be sent off HBA at any given time.
6487 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6488 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6489 * will be stored into the context1 field of the IOCB for the completion
6490 * callback function to the FDISC ELS command.
6493 * 0 - Successfully issued fdisc iocb command
6494 * 1 - Failed to issue fdisc iocb command
6497 lpfc_issue_els_fdisc(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
6500 struct lpfc_hba
*phba
= vport
->phba
;
6502 struct lpfc_iocbq
*elsiocb
;
6503 struct serv_parm
*sp
;
6506 int did
= ndlp
->nlp_DID
;
6509 vport
->port_state
= LPFC_FDISC
;
6510 cmdsize
= (sizeof(uint32_t) + sizeof(struct serv_parm
));
6511 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
, did
,
6514 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
6515 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
6516 "0255 Issue FDISC: no IOCB\n");
6520 icmd
= &elsiocb
->iocb
;
6521 icmd
->un
.elsreq64
.myID
= 0;
6522 icmd
->un
.elsreq64
.fl
= 1;
6524 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
6525 /* FDISC needs to be 1 for WQE VPI */
6526 elsiocb
->iocb
.ulpCt_h
= (SLI4_CT_VPI
>> 1) & 1;
6527 elsiocb
->iocb
.ulpCt_l
= SLI4_CT_VPI
& 1 ;
6528 /* Set the ulpContext to the vpi */
6529 elsiocb
->iocb
.ulpContext
= vport
->vpi
+ phba
->vpi_base
;
6531 /* For FDISC, Let FDISC rsp set the NPortID for this VPI */
6536 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
6537 *((uint32_t *) (pcmd
)) = ELS_CMD_FDISC
;
6538 pcmd
+= sizeof(uint32_t); /* CSP Word 1 */
6539 memcpy(pcmd
, &vport
->phba
->pport
->fc_sparam
, sizeof(struct serv_parm
));
6540 sp
= (struct serv_parm
*) pcmd
;
6541 /* Setup CSPs accordingly for Fabric */
6542 sp
->cmn
.e_d_tov
= 0;
6543 sp
->cmn
.w2
.r_a_tov
= 0;
6544 sp
->cls1
.classValid
= 0;
6545 sp
->cls2
.seqDelivery
= 1;
6546 sp
->cls3
.seqDelivery
= 1;
6548 pcmd
+= sizeof(uint32_t); /* CSP Word 2 */
6549 pcmd
+= sizeof(uint32_t); /* CSP Word 3 */
6550 pcmd
+= sizeof(uint32_t); /* CSP Word 4 */
6551 pcmd
+= sizeof(uint32_t); /* Port Name */
6552 memcpy(pcmd
, &vport
->fc_portname
, 8);
6553 pcmd
+= sizeof(uint32_t); /* Node Name */
6554 pcmd
+= sizeof(uint32_t); /* Node Name */
6555 memcpy(pcmd
, &vport
->fc_nodename
, 8);
6557 lpfc_set_disctmo(vport
);
6559 phba
->fc_stat
.elsXmitFDISC
++;
6560 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_fdisc
;
6562 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
6563 "Issue FDISC: did:x%x",
6566 rc
= lpfc_issue_fabric_iocb(phba
, elsiocb
);
6567 if (rc
== IOCB_ERROR
) {
6568 lpfc_els_free_iocb(phba
, elsiocb
);
6569 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
6570 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
6571 "0256 Issue FDISC: Cannot send IOCB\n");
6574 lpfc_vport_set_state(vport
, FC_VPORT_INITIALIZING
);
6579 * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
6580 * @phba: pointer to lpfc hba data structure.
6581 * @cmdiocb: pointer to lpfc command iocb data structure.
6582 * @rspiocb: pointer to lpfc response iocb data structure.
6584 * This routine is the completion callback function to the issuing of a LOGO
6585 * ELS command off a vport. It frees the command IOCB and then decrement the
6586 * reference count held on ndlp for this completion function, indicating that
6587 * the reference to the ndlp is no long needed. Note that the
6588 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
6589 * callback function and an additional explicit ndlp reference decrementation
6590 * will trigger the actual release of the ndlp.
6593 lpfc_cmpl_els_npiv_logo(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
6594 struct lpfc_iocbq
*rspiocb
)
6596 struct lpfc_vport
*vport
= cmdiocb
->vport
;
6598 struct lpfc_nodelist
*ndlp
;
6599 ndlp
= (struct lpfc_nodelist
*)cmdiocb
->context1
;
6601 irsp
= &rspiocb
->iocb
;
6602 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
6603 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
6604 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4], irsp
->un
.rcvels
.remoteID
);
6606 lpfc_els_free_iocb(phba
, cmdiocb
);
6607 vport
->unreg_vpi_cmpl
= VPORT_ERROR
;
6609 /* Trigger the release of the ndlp after logo */
6614 * lpfc_issue_els_npiv_logo - Issue a logo off a vport
6615 * @vport: pointer to a virtual N_Port data structure.
6616 * @ndlp: pointer to a node-list data structure.
6618 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
6620 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6621 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6622 * will be stored into the context1 field of the IOCB for the completion
6623 * callback function to the LOGO ELS command.
6626 * 0 - Successfully issued logo off the @vport
6627 * 1 - Failed to issue logo off the @vport
6630 lpfc_issue_els_npiv_logo(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
6632 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
6633 struct lpfc_hba
*phba
= vport
->phba
;
6635 struct lpfc_iocbq
*elsiocb
;
6639 cmdsize
= 2 * sizeof(uint32_t) + sizeof(struct lpfc_name
);
6640 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, 0, ndlp
, ndlp
->nlp_DID
,
6645 icmd
= &elsiocb
->iocb
;
6646 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
6647 *((uint32_t *) (pcmd
)) = ELS_CMD_LOGO
;
6648 pcmd
+= sizeof(uint32_t);
6650 /* Fill in LOGO payload */
6651 *((uint32_t *) (pcmd
)) = be32_to_cpu(vport
->fc_myDID
);
6652 pcmd
+= sizeof(uint32_t);
6653 memcpy(pcmd
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
6655 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
6656 "Issue LOGO npiv did:x%x flg:x%x",
6657 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
6659 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_npiv_logo
;
6660 spin_lock_irq(shost
->host_lock
);
6661 ndlp
->nlp_flag
|= NLP_LOGO_SND
;
6662 spin_unlock_irq(shost
->host_lock
);
6663 if (lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0) ==
6665 spin_lock_irq(shost
->host_lock
);
6666 ndlp
->nlp_flag
&= ~NLP_LOGO_SND
;
6667 spin_unlock_irq(shost
->host_lock
);
6668 lpfc_els_free_iocb(phba
, elsiocb
);
6675 * lpfc_fabric_block_timeout - Handler function to the fabric block timer
6676 * @ptr: holder for the timer function associated data.
6678 * This routine is invoked by the fabric iocb block timer after
6679 * timeout. It posts the fabric iocb block timeout event by setting the
6680 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
6681 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
6682 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
6683 * posted event WORKER_FABRIC_BLOCK_TMO.
6686 lpfc_fabric_block_timeout(unsigned long ptr
)
6688 struct lpfc_hba
*phba
= (struct lpfc_hba
*) ptr
;
6689 unsigned long iflags
;
6690 uint32_t tmo_posted
;
6692 spin_lock_irqsave(&phba
->pport
->work_port_lock
, iflags
);
6693 tmo_posted
= phba
->pport
->work_port_events
& WORKER_FABRIC_BLOCK_TMO
;
6695 phba
->pport
->work_port_events
|= WORKER_FABRIC_BLOCK_TMO
;
6696 spin_unlock_irqrestore(&phba
->pport
->work_port_lock
, iflags
);
6699 lpfc_worker_wake_up(phba
);
6704 * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
6705 * @phba: pointer to lpfc hba data structure.
6707 * This routine issues one fabric iocb from the driver internal list to
6708 * the HBA. It first checks whether it's ready to issue one fabric iocb to
6709 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
6710 * remove one pending fabric iocb from the driver internal list and invokes
6711 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
6714 lpfc_resume_fabric_iocbs(struct lpfc_hba
*phba
)
6716 struct lpfc_iocbq
*iocb
;
6717 unsigned long iflags
;
6723 spin_lock_irqsave(&phba
->hbalock
, iflags
);
6724 /* Post any pending iocb to the SLI layer */
6725 if (atomic_read(&phba
->fabric_iocb_count
) == 0) {
6726 list_remove_head(&phba
->fabric_iocb_list
, iocb
, typeof(*iocb
),
6729 /* Increment fabric iocb count to hold the position */
6730 atomic_inc(&phba
->fabric_iocb_count
);
6732 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
6734 iocb
->fabric_iocb_cmpl
= iocb
->iocb_cmpl
;
6735 iocb
->iocb_cmpl
= lpfc_cmpl_fabric_iocb
;
6736 iocb
->iocb_flag
|= LPFC_IO_FABRIC
;
6738 lpfc_debugfs_disc_trc(iocb
->vport
, LPFC_DISC_TRC_ELS_CMD
,
6739 "Fabric sched1: ste:x%x",
6740 iocb
->vport
->port_state
, 0, 0);
6742 ret
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, iocb
, 0);
6744 if (ret
== IOCB_ERROR
) {
6745 iocb
->iocb_cmpl
= iocb
->fabric_iocb_cmpl
;
6746 iocb
->fabric_iocb_cmpl
= NULL
;
6747 iocb
->iocb_flag
&= ~LPFC_IO_FABRIC
;
6749 cmd
->ulpStatus
= IOSTAT_LOCAL_REJECT
;
6750 cmd
->un
.ulpWord
[4] = IOERR_SLI_ABORTED
;
6751 iocb
->iocb_cmpl(phba
, iocb
, iocb
);
6753 atomic_dec(&phba
->fabric_iocb_count
);
6762 * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
6763 * @phba: pointer to lpfc hba data structure.
6765 * This routine unblocks the issuing fabric iocb command. The function
6766 * will clear the fabric iocb block bit and then invoke the routine
6767 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
6768 * from the driver internal fabric iocb list.
6771 lpfc_unblock_fabric_iocbs(struct lpfc_hba
*phba
)
6773 clear_bit(FABRIC_COMANDS_BLOCKED
, &phba
->bit_flags
);
6775 lpfc_resume_fabric_iocbs(phba
);
6780 * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
6781 * @phba: pointer to lpfc hba data structure.
6783 * This routine blocks the issuing fabric iocb for a specified amount of
6784 * time (currently 100 ms). This is done by set the fabric iocb block bit
6785 * and set up a timeout timer for 100ms. When the block bit is set, no more
6786 * fabric iocb will be issued out of the HBA.
6789 lpfc_block_fabric_iocbs(struct lpfc_hba
*phba
)
6793 blocked
= test_and_set_bit(FABRIC_COMANDS_BLOCKED
, &phba
->bit_flags
);
6794 /* Start a timer to unblock fabric iocbs after 100ms */
6796 mod_timer(&phba
->fabric_block_timer
, jiffies
+ HZ
/10 );
6802 * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
6803 * @phba: pointer to lpfc hba data structure.
6804 * @cmdiocb: pointer to lpfc command iocb data structure.
6805 * @rspiocb: pointer to lpfc response iocb data structure.
6807 * This routine is the callback function that is put to the fabric iocb's
6808 * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
6809 * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
6810 * function first restores and invokes the original iocb's callback function
6811 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
6812 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
6815 lpfc_cmpl_fabric_iocb(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
6816 struct lpfc_iocbq
*rspiocb
)
6820 if ((cmdiocb
->iocb_flag
& LPFC_IO_FABRIC
) != LPFC_IO_FABRIC
)
6823 switch (rspiocb
->iocb
.ulpStatus
) {
6824 case IOSTAT_NPORT_RJT
:
6825 case IOSTAT_FABRIC_RJT
:
6826 if (rspiocb
->iocb
.un
.ulpWord
[4] & RJT_UNAVAIL_TEMP
) {
6827 lpfc_block_fabric_iocbs(phba
);
6831 case IOSTAT_NPORT_BSY
:
6832 case IOSTAT_FABRIC_BSY
:
6833 lpfc_block_fabric_iocbs(phba
);
6837 stat
.un
.lsRjtError
=
6838 be32_to_cpu(rspiocb
->iocb
.un
.ulpWord
[4]);
6839 if ((stat
.un
.b
.lsRjtRsnCode
== LSRJT_UNABLE_TPC
) ||
6840 (stat
.un
.b
.lsRjtRsnCode
== LSRJT_LOGICAL_BSY
))
6841 lpfc_block_fabric_iocbs(phba
);
6845 if (atomic_read(&phba
->fabric_iocb_count
) == 0)
6848 cmdiocb
->iocb_cmpl
= cmdiocb
->fabric_iocb_cmpl
;
6849 cmdiocb
->fabric_iocb_cmpl
= NULL
;
6850 cmdiocb
->iocb_flag
&= ~LPFC_IO_FABRIC
;
6851 cmdiocb
->iocb_cmpl(phba
, cmdiocb
, rspiocb
);
6853 atomic_dec(&phba
->fabric_iocb_count
);
6854 if (!test_bit(FABRIC_COMANDS_BLOCKED
, &phba
->bit_flags
)) {
6855 /* Post any pending iocbs to HBA */
6856 lpfc_resume_fabric_iocbs(phba
);
6861 * lpfc_issue_fabric_iocb - Issue a fabric iocb command
6862 * @phba: pointer to lpfc hba data structure.
6863 * @iocb: pointer to lpfc command iocb data structure.
6865 * This routine is used as the top-level API for issuing a fabric iocb command
6866 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
6867 * function makes sure that only one fabric bound iocb will be outstanding at
6868 * any given time. As such, this function will first check to see whether there
6869 * is already an outstanding fabric iocb on the wire. If so, it will put the
6870 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
6871 * issued later. Otherwise, it will issue the iocb on the wire and update the
6872 * fabric iocb count it indicate that there is one fabric iocb on the wire.
6874 * Note, this implementation has a potential sending out fabric IOCBs out of
6875 * order. The problem is caused by the construction of the "ready" boolen does
6876 * not include the condition that the internal fabric IOCB list is empty. As
6877 * such, it is possible a fabric IOCB issued by this routine might be "jump"
6878 * ahead of the fabric IOCBs in the internal list.
6881 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
6882 * IOCB_ERROR - failed to issue fabric iocb
6885 lpfc_issue_fabric_iocb(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocb
)
6887 unsigned long iflags
;
6891 if (atomic_read(&phba
->fabric_iocb_count
) > 1)
6894 spin_lock_irqsave(&phba
->hbalock
, iflags
);
6895 ready
= atomic_read(&phba
->fabric_iocb_count
) == 0 &&
6896 !test_bit(FABRIC_COMANDS_BLOCKED
, &phba
->bit_flags
);
6899 /* Increment fabric iocb count to hold the position */
6900 atomic_inc(&phba
->fabric_iocb_count
);
6901 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
6903 iocb
->fabric_iocb_cmpl
= iocb
->iocb_cmpl
;
6904 iocb
->iocb_cmpl
= lpfc_cmpl_fabric_iocb
;
6905 iocb
->iocb_flag
|= LPFC_IO_FABRIC
;
6907 lpfc_debugfs_disc_trc(iocb
->vport
, LPFC_DISC_TRC_ELS_CMD
,
6908 "Fabric sched2: ste:x%x",
6909 iocb
->vport
->port_state
, 0, 0);
6911 ret
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, iocb
, 0);
6913 if (ret
== IOCB_ERROR
) {
6914 iocb
->iocb_cmpl
= iocb
->fabric_iocb_cmpl
;
6915 iocb
->fabric_iocb_cmpl
= NULL
;
6916 iocb
->iocb_flag
&= ~LPFC_IO_FABRIC
;
6917 atomic_dec(&phba
->fabric_iocb_count
);
6920 spin_lock_irqsave(&phba
->hbalock
, iflags
);
6921 list_add_tail(&iocb
->list
, &phba
->fabric_iocb_list
);
6922 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
6929 * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
6930 * @vport: pointer to a virtual N_Port data structure.
6932 * This routine aborts all the IOCBs associated with a @vport from the
6933 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
6934 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
6935 * list, removes each IOCB associated with the @vport off the list, set the
6936 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
6937 * associated with the IOCB.
6939 static void lpfc_fabric_abort_vport(struct lpfc_vport
*vport
)
6941 LIST_HEAD(completions
);
6942 struct lpfc_hba
*phba
= vport
->phba
;
6943 struct lpfc_iocbq
*tmp_iocb
, *piocb
;
6945 spin_lock_irq(&phba
->hbalock
);
6946 list_for_each_entry_safe(piocb
, tmp_iocb
, &phba
->fabric_iocb_list
,
6949 if (piocb
->vport
!= vport
)
6952 list_move_tail(&piocb
->list
, &completions
);
6954 spin_unlock_irq(&phba
->hbalock
);
6956 /* Cancel all the IOCBs from the completions list */
6957 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
6962 * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
6963 * @ndlp: pointer to a node-list data structure.
6965 * This routine aborts all the IOCBs associated with an @ndlp from the
6966 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
6967 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
6968 * list, removes each IOCB associated with the @ndlp off the list, set the
6969 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
6970 * associated with the IOCB.
6972 void lpfc_fabric_abort_nport(struct lpfc_nodelist
*ndlp
)
6974 LIST_HEAD(completions
);
6975 struct lpfc_hba
*phba
= ndlp
->phba
;
6976 struct lpfc_iocbq
*tmp_iocb
, *piocb
;
6977 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
6979 spin_lock_irq(&phba
->hbalock
);
6980 list_for_each_entry_safe(piocb
, tmp_iocb
, &phba
->fabric_iocb_list
,
6982 if ((lpfc_check_sli_ndlp(phba
, pring
, piocb
, ndlp
))) {
6984 list_move_tail(&piocb
->list
, &completions
);
6987 spin_unlock_irq(&phba
->hbalock
);
6989 /* Cancel all the IOCBs from the completions list */
6990 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
6995 * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
6996 * @phba: pointer to lpfc hba data structure.
6998 * This routine aborts all the IOCBs currently on the driver internal
6999 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
7000 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
7001 * list, removes IOCBs off the list, set the status feild to
7002 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
7005 void lpfc_fabric_abort_hba(struct lpfc_hba
*phba
)
7007 LIST_HEAD(completions
);
7009 spin_lock_irq(&phba
->hbalock
);
7010 list_splice_init(&phba
->fabric_iocb_list
, &completions
);
7011 spin_unlock_irq(&phba
->hbalock
);
7013 /* Cancel all the IOCBs from the completions list */
7014 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
7019 * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
7020 * @phba: pointer to lpfc hba data structure.
7021 * @axri: pointer to the els xri abort wcqe structure.
7023 * This routine is invoked by the worker thread to process a SLI4 slow-path
7027 lpfc_sli4_els_xri_aborted(struct lpfc_hba
*phba
,
7028 struct sli4_wcqe_xri_aborted
*axri
)
7030 uint16_t xri
= bf_get(lpfc_wcqe_xa_xri
, axri
);
7031 struct lpfc_sglq
*sglq_entry
= NULL
, *sglq_next
= NULL
;
7032 unsigned long iflag
= 0;
7033 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
7035 spin_lock_irqsave(&phba
->hbalock
, iflag
);
7036 spin_lock(&phba
->sli4_hba
.abts_sgl_list_lock
);
7037 list_for_each_entry_safe(sglq_entry
, sglq_next
,
7038 &phba
->sli4_hba
.lpfc_abts_els_sgl_list
, list
) {
7039 if (sglq_entry
->sli4_xritag
== xri
) {
7040 list_del(&sglq_entry
->list
);
7041 list_add_tail(&sglq_entry
->list
,
7042 &phba
->sli4_hba
.lpfc_sgl_list
);
7043 sglq_entry
->state
= SGL_FREED
;
7044 spin_unlock(&phba
->sli4_hba
.abts_sgl_list_lock
);
7045 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
7047 /* Check if TXQ queue needs to be serviced */
7049 lpfc_worker_wake_up(phba
);
7053 spin_unlock(&phba
->sli4_hba
.abts_sgl_list_lock
);
7054 sglq_entry
= __lpfc_get_active_sglq(phba
, xri
);
7055 if (!sglq_entry
|| (sglq_entry
->sli4_xritag
!= xri
)) {
7056 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
7059 sglq_entry
->state
= SGL_XRI_ABORTED
;
7060 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);