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/interrupt.h>
26 #include <scsi/scsi.h>
27 #include <scsi/scsi_device.h>
28 #include <scsi/scsi_host.h>
29 #include <scsi/scsi_transport_fc.h>
34 #include "lpfc_sli4.h"
36 #include "lpfc_disc.h"
37 #include "lpfc_scsi.h"
39 #include "lpfc_logmsg.h"
40 #include "lpfc_crtn.h"
41 #include "lpfc_vport.h"
42 #include "lpfc_debugfs.h"
44 static int lpfc_els_retry(struct lpfc_hba
*, struct lpfc_iocbq
*,
46 static void lpfc_cmpl_fabric_iocb(struct lpfc_hba
*, struct lpfc_iocbq
*,
48 static void lpfc_fabric_abort_vport(struct lpfc_vport
*vport
);
49 static int lpfc_issue_els_fdisc(struct lpfc_vport
*vport
,
50 struct lpfc_nodelist
*ndlp
, uint8_t retry
);
51 static int lpfc_issue_fabric_iocb(struct lpfc_hba
*phba
,
52 struct lpfc_iocbq
*iocb
);
53 static void lpfc_register_new_vport(struct lpfc_hba
*phba
,
54 struct lpfc_vport
*vport
,
55 struct lpfc_nodelist
*ndlp
);
57 static int lpfc_max_els_tries
= 3;
60 * lpfc_els_chk_latt - Check host link attention event for a vport
61 * @vport: pointer to a host virtual N_Port data structure.
63 * This routine checks whether there is an outstanding host link
64 * attention event during the discovery process with the @vport. It is done
65 * by reading the HBA's Host Attention (HA) register. If there is any host
66 * link attention events during this @vport's discovery process, the @vport
67 * shall be marked as FC_ABORT_DISCOVERY, a host link attention clear shall
68 * be issued if the link state is not already in host link cleared state,
69 * and a return code shall indicate whether the host link attention event
72 * Note that, if either the host link is in state LPFC_LINK_DOWN or @vport
73 * state in LPFC_VPORT_READY, the request for checking host link attention
74 * event will be ignored and a return code shall indicate no host link
75 * attention event had happened.
78 * 0 - no host link attention event happened
79 * 1 - host link attention event happened
82 lpfc_els_chk_latt(struct lpfc_vport
*vport
)
84 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
85 struct lpfc_hba
*phba
= vport
->phba
;
88 if (vport
->port_state
>= LPFC_VPORT_READY
||
89 phba
->link_state
== LPFC_LINK_DOWN
||
90 phba
->sli_rev
> LPFC_SLI_REV3
)
93 /* Read the HBA Host Attention Register */
94 ha_copy
= readl(phba
->HAregaddr
);
96 if (!(ha_copy
& HA_LATT
))
99 /* Pending Link Event during Discovery */
100 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
101 "0237 Pending Link Event during "
102 "Discovery: State x%x\n",
103 phba
->pport
->port_state
);
105 /* CLEAR_LA should re-enable link attention events and
106 * we should then imediately take a LATT event. The
107 * LATT processing should call lpfc_linkdown() which
108 * will cleanup any left over in-progress discovery
111 spin_lock_irq(shost
->host_lock
);
112 vport
->fc_flag
|= FC_ABORT_DISCOVERY
;
113 spin_unlock_irq(shost
->host_lock
);
115 if (phba
->link_state
!= LPFC_CLEAR_LA
)
116 lpfc_issue_clear_la(phba
, vport
);
122 * lpfc_prep_els_iocb - Allocate and prepare a lpfc iocb data structure
123 * @vport: pointer to a host virtual N_Port data structure.
124 * @expectRsp: flag indicating whether response is expected.
125 * @cmdSize: size of the ELS command.
126 * @retry: number of retries to the command IOCB when it fails.
127 * @ndlp: pointer to a node-list data structure.
128 * @did: destination identifier.
129 * @elscmd: the ELS command code.
131 * This routine is used for allocating a lpfc-IOCB data structure from
132 * the driver lpfc-IOCB free-list and prepare the IOCB with the parameters
133 * passed into the routine for discovery state machine to issue an Extended
134 * Link Service (ELS) commands. It is a generic lpfc-IOCB allocation
135 * and preparation routine that is used by all the discovery state machine
136 * routines and the ELS command-specific fields will be later set up by
137 * the individual discovery machine routines after calling this routine
138 * allocating and preparing a generic IOCB data structure. It fills in the
139 * Buffer Descriptor Entries (BDEs), allocates buffers for both command
140 * payload and response payload (if expected). The reference count on the
141 * ndlp is incremented by 1 and the reference to the ndlp is put into
142 * context1 of the IOCB data structure for this IOCB to hold the ndlp
143 * reference for the command's callback function to access later.
146 * Pointer to the newly allocated/prepared els iocb data structure
147 * NULL - when els iocb data structure allocation/preparation failed
149 static struct lpfc_iocbq
*
150 lpfc_prep_els_iocb(struct lpfc_vport
*vport
, uint8_t expectRsp
,
151 uint16_t cmdSize
, uint8_t retry
,
152 struct lpfc_nodelist
*ndlp
, uint32_t did
,
155 struct lpfc_hba
*phba
= vport
->phba
;
156 struct lpfc_iocbq
*elsiocb
;
157 struct lpfc_dmabuf
*pcmd
, *prsp
, *pbuflist
;
158 struct ulp_bde64
*bpl
;
162 if (!lpfc_is_link_up(phba
))
165 /* Allocate buffer for command iocb */
166 elsiocb
= lpfc_sli_get_iocbq(phba
);
171 icmd
= &elsiocb
->iocb
;
173 /* fill in BDEs for command */
174 /* Allocate buffer for command payload */
175 pcmd
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
177 pcmd
->virt
= lpfc_mbuf_alloc(phba
, MEM_PRI
, &pcmd
->phys
);
178 if (!pcmd
|| !pcmd
->virt
)
179 goto els_iocb_free_pcmb_exit
;
181 INIT_LIST_HEAD(&pcmd
->list
);
183 /* Allocate buffer for response payload */
185 prsp
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
187 prsp
->virt
= lpfc_mbuf_alloc(phba
, MEM_PRI
,
189 if (!prsp
|| !prsp
->virt
)
190 goto els_iocb_free_prsp_exit
;
191 INIT_LIST_HEAD(&prsp
->list
);
195 /* Allocate buffer for Buffer ptr list */
196 pbuflist
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
198 pbuflist
->virt
= lpfc_mbuf_alloc(phba
, MEM_PRI
,
200 if (!pbuflist
|| !pbuflist
->virt
)
201 goto els_iocb_free_pbuf_exit
;
203 INIT_LIST_HEAD(&pbuflist
->list
);
205 icmd
->un
.elsreq64
.bdl
.addrHigh
= putPaddrHigh(pbuflist
->phys
);
206 icmd
->un
.elsreq64
.bdl
.addrLow
= putPaddrLow(pbuflist
->phys
);
207 icmd
->un
.elsreq64
.bdl
.bdeFlags
= BUFF_TYPE_BLP_64
;
208 icmd
->un
.elsreq64
.remoteID
= did
; /* DID */
210 icmd
->un
.elsreq64
.bdl
.bdeSize
= (2 * sizeof(struct ulp_bde64
));
211 icmd
->ulpCommand
= CMD_ELS_REQUEST64_CR
;
212 icmd
->ulpTimeout
= phba
->fc_ratov
* 2;
214 icmd
->un
.elsreq64
.bdl
.bdeSize
= sizeof(struct ulp_bde64
);
215 icmd
->ulpCommand
= CMD_XMIT_ELS_RSP64_CX
;
217 icmd
->ulpBdeCount
= 1;
219 icmd
->ulpClass
= CLASS3
;
221 if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) {
222 icmd
->un
.elsreq64
.myID
= vport
->fc_myDID
;
224 /* For ELS_REQUEST64_CR, use the VPI by default */
225 icmd
->ulpContext
= vport
->vpi
+ phba
->vpi_base
;
227 /* The CT field must be 0=INVALID_RPI for the ECHO cmd */
228 if (elscmd
== ELS_CMD_ECHO
)
229 icmd
->ulpCt_l
= 0; /* context = invalid RPI */
231 icmd
->ulpCt_l
= 1; /* context = VPI */
234 bpl
= (struct ulp_bde64
*) pbuflist
->virt
;
235 bpl
->addrLow
= le32_to_cpu(putPaddrLow(pcmd
->phys
));
236 bpl
->addrHigh
= le32_to_cpu(putPaddrHigh(pcmd
->phys
));
237 bpl
->tus
.f
.bdeSize
= cmdSize
;
238 bpl
->tus
.f
.bdeFlags
= 0;
239 bpl
->tus
.w
= le32_to_cpu(bpl
->tus
.w
);
243 bpl
->addrLow
= le32_to_cpu(putPaddrLow(prsp
->phys
));
244 bpl
->addrHigh
= le32_to_cpu(putPaddrHigh(prsp
->phys
));
245 bpl
->tus
.f
.bdeSize
= FCELSSIZE
;
246 bpl
->tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64
;
247 bpl
->tus
.w
= le32_to_cpu(bpl
->tus
.w
);
250 /* prevent preparing iocb with NULL ndlp reference */
251 elsiocb
->context1
= lpfc_nlp_get(ndlp
);
252 if (!elsiocb
->context1
)
253 goto els_iocb_free_pbuf_exit
;
254 elsiocb
->context2
= pcmd
;
255 elsiocb
->context3
= pbuflist
;
256 elsiocb
->retry
= retry
;
257 elsiocb
->vport
= vport
;
258 elsiocb
->drvrTimeout
= (phba
->fc_ratov
<< 1) + LPFC_DRVR_TIMEOUT
;
261 list_add(&prsp
->list
, &pcmd
->list
);
264 /* Xmit ELS command <elsCmd> to remote NPORT <did> */
265 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
266 "0116 Xmit ELS command x%x to remote "
267 "NPORT x%x I/O tag: x%x, port state: x%x\n",
268 elscmd
, did
, elsiocb
->iotag
,
271 /* Xmit ELS response <elsCmd> to remote NPORT <did> */
272 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
273 "0117 Xmit ELS response x%x to remote "
274 "NPORT x%x I/O tag: x%x, size: x%x\n",
275 elscmd
, ndlp
->nlp_DID
, elsiocb
->iotag
,
280 els_iocb_free_pbuf_exit
:
282 lpfc_mbuf_free(phba
, prsp
->virt
, prsp
->phys
);
285 els_iocb_free_prsp_exit
:
286 lpfc_mbuf_free(phba
, pcmd
->virt
, pcmd
->phys
);
289 els_iocb_free_pcmb_exit
:
291 lpfc_sli_release_iocbq(phba
, elsiocb
);
296 * lpfc_issue_fabric_reglogin - Issue fabric registration login for a vport
297 * @vport: pointer to a host virtual N_Port data structure.
299 * This routine issues a fabric registration login for a @vport. An
300 * active ndlp node with Fabric_DID must already exist for this @vport.
301 * The routine invokes two mailbox commands to carry out fabric registration
302 * login through the HBA firmware: the first mailbox command requests the
303 * HBA to perform link configuration for the @vport; and the second mailbox
304 * command requests the HBA to perform the actual fabric registration login
308 * 0 - successfully issued fabric registration login for @vport
309 * -ENXIO -- failed to issue fabric registration login for @vport
312 lpfc_issue_fabric_reglogin(struct lpfc_vport
*vport
)
314 struct lpfc_hba
*phba
= vport
->phba
;
316 struct lpfc_dmabuf
*mp
;
317 struct lpfc_nodelist
*ndlp
;
318 struct serv_parm
*sp
;
322 sp
= &phba
->fc_fabparam
;
323 ndlp
= lpfc_findnode_did(vport
, Fabric_DID
);
324 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
)) {
329 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
335 vport
->port_state
= LPFC_FABRIC_CFG_LINK
;
336 lpfc_config_link(phba
, mbox
);
337 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
340 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
341 if (rc
== MBX_NOT_FINISHED
) {
346 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
351 rc
= lpfc_reg_rpi(phba
, vport
->vpi
, Fabric_DID
, (uint8_t *)sp
, mbox
, 0);
357 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_fabric_reg_login
;
359 /* increment the reference count on ndlp to hold reference
360 * for the callback routine.
362 mbox
->context2
= lpfc_nlp_get(ndlp
);
364 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
365 if (rc
== MBX_NOT_FINISHED
) {
367 goto fail_issue_reg_login
;
372 fail_issue_reg_login
:
373 /* decrement the reference count on ndlp just incremented
374 * for the failed mbox command.
377 mp
= (struct lpfc_dmabuf
*) mbox
->context1
;
378 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
381 mempool_free(mbox
, phba
->mbox_mem_pool
);
384 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
385 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
386 "0249 Cannot issue Register Fabric login: Err %d\n", err
);
391 * lpfc_issue_reg_vfi - Register VFI for this vport's fabric login
392 * @vport: pointer to a host virtual N_Port data structure.
394 * This routine issues a REG_VFI mailbox for the vfi, vpi, fcfi triplet for
395 * the @vport. This mailbox command is necessary for FCoE only.
398 * 0 - successfully issued REG_VFI for @vport
399 * A failure code otherwise.
402 lpfc_issue_reg_vfi(struct lpfc_vport
*vport
)
404 struct lpfc_hba
*phba
= vport
->phba
;
406 struct lpfc_nodelist
*ndlp
;
407 struct serv_parm
*sp
;
408 struct lpfc_dmabuf
*dmabuf
;
411 sp
= &phba
->fc_fabparam
;
412 ndlp
= lpfc_findnode_did(vport
, Fabric_DID
);
413 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
)) {
418 dmabuf
= kzalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
423 dmabuf
->virt
= lpfc_mbuf_alloc(phba
, MEM_PRI
, &dmabuf
->phys
);
426 goto fail_free_dmabuf
;
428 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
431 goto fail_free_coherent
;
433 vport
->port_state
= LPFC_FABRIC_CFG_LINK
;
434 memcpy(dmabuf
->virt
, &phba
->fc_fabparam
, sizeof(vport
->fc_sparam
));
435 lpfc_reg_vfi(mboxq
, vport
, dmabuf
->phys
);
436 mboxq
->mbox_cmpl
= lpfc_mbx_cmpl_reg_vfi
;
437 mboxq
->vport
= vport
;
438 mboxq
->context1
= dmabuf
;
439 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
440 if (rc
== MBX_NOT_FINISHED
) {
447 mempool_free(mboxq
, phba
->mbox_mem_pool
);
449 lpfc_mbuf_free(phba
, dmabuf
->virt
, dmabuf
->phys
);
453 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
454 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
455 "0289 Issue Register VFI failed: Err %d\n", rc
);
460 * lpfc_cmpl_els_flogi_fabric - Completion function for flogi to a fabric port
461 * @vport: pointer to a host virtual N_Port data structure.
462 * @ndlp: pointer to a node-list data structure.
463 * @sp: pointer to service parameter data structure.
464 * @irsp: pointer to the IOCB within the lpfc response IOCB.
466 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
467 * function to handle the completion of a Fabric Login (FLOGI) into a fabric
468 * port in a fabric topology. It properly sets up the parameters to the @ndlp
469 * from the IOCB response. It also check the newly assigned N_Port ID to the
470 * @vport against the previously assigned N_Port ID. If it is different from
471 * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine
472 * is invoked on all the remaining nodes with the @vport to unregister the
473 * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin()
474 * is invoked to register login to the fabric.
477 * 0 - Success (currently, always return 0)
480 lpfc_cmpl_els_flogi_fabric(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
481 struct serv_parm
*sp
, IOCB_t
*irsp
)
483 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
484 struct lpfc_hba
*phba
= vport
->phba
;
485 struct lpfc_nodelist
*np
;
486 struct lpfc_nodelist
*next_np
;
488 spin_lock_irq(shost
->host_lock
);
489 vport
->fc_flag
|= FC_FABRIC
;
490 spin_unlock_irq(shost
->host_lock
);
492 phba
->fc_edtov
= be32_to_cpu(sp
->cmn
.e_d_tov
);
493 if (sp
->cmn
.edtovResolution
) /* E_D_TOV ticks are in nanoseconds */
494 phba
->fc_edtov
= (phba
->fc_edtov
+ 999999) / 1000000;
496 phba
->fc_ratov
= (be32_to_cpu(sp
->cmn
.w2
.r_a_tov
) + 999) / 1000;
498 if (phba
->fc_topology
== TOPOLOGY_LOOP
) {
499 spin_lock_irq(shost
->host_lock
);
500 vport
->fc_flag
|= FC_PUBLIC_LOOP
;
501 spin_unlock_irq(shost
->host_lock
);
504 * If we are a N-port connected to a Fabric, fixup sparam's so
505 * logins to devices on remote loops work.
507 vport
->fc_sparam
.cmn
.altBbCredit
= 1;
510 vport
->fc_myDID
= irsp
->un
.ulpWord
[4] & Mask_DID
;
511 memcpy(&ndlp
->nlp_portname
, &sp
->portName
, sizeof(struct lpfc_name
));
512 memcpy(&ndlp
->nlp_nodename
, &sp
->nodeName
, sizeof(struct lpfc_name
));
513 ndlp
->nlp_class_sup
= 0;
514 if (sp
->cls1
.classValid
)
515 ndlp
->nlp_class_sup
|= FC_COS_CLASS1
;
516 if (sp
->cls2
.classValid
)
517 ndlp
->nlp_class_sup
|= FC_COS_CLASS2
;
518 if (sp
->cls3
.classValid
)
519 ndlp
->nlp_class_sup
|= FC_COS_CLASS3
;
520 if (sp
->cls4
.classValid
)
521 ndlp
->nlp_class_sup
|= FC_COS_CLASS4
;
522 ndlp
->nlp_maxframe
= ((sp
->cmn
.bbRcvSizeMsb
& 0x0F) << 8) |
523 sp
->cmn
.bbRcvSizeLsb
;
524 memcpy(&phba
->fc_fabparam
, sp
, sizeof(struct serv_parm
));
526 if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) {
527 if (sp
->cmn
.response_multiple_NPort
) {
528 lpfc_printf_vlog(vport
, KERN_WARNING
,
530 "1816 FLOGI NPIV supported, "
531 "response data 0x%x\n",
532 sp
->cmn
.response_multiple_NPort
);
533 phba
->link_flag
|= LS_NPIV_FAB_SUPPORTED
;
535 /* Because we asked f/w for NPIV it still expects us
536 to call reg_vnpid atleast for the physcial host */
537 lpfc_printf_vlog(vport
, KERN_WARNING
,
539 "1817 Fabric does not support NPIV "
540 "- configuring single port mode.\n");
541 phba
->link_flag
&= ~LS_NPIV_FAB_SUPPORTED
;
545 if ((vport
->fc_prevDID
!= vport
->fc_myDID
) &&
546 !(vport
->fc_flag
& FC_VPORT_NEEDS_REG_VPI
)) {
548 /* If our NportID changed, we need to ensure all
549 * remaining NPORTs get unreg_login'ed.
551 list_for_each_entry_safe(np
, next_np
,
552 &vport
->fc_nodes
, nlp_listp
) {
553 if (!NLP_CHK_NODE_ACT(np
))
555 if ((np
->nlp_state
!= NLP_STE_NPR_NODE
) ||
556 !(np
->nlp_flag
& NLP_NPR_ADISC
))
558 spin_lock_irq(shost
->host_lock
);
559 np
->nlp_flag
&= ~NLP_NPR_ADISC
;
560 spin_unlock_irq(shost
->host_lock
);
561 lpfc_unreg_rpi(vport
, np
);
563 if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) {
564 lpfc_mbx_unreg_vpi(vport
);
565 spin_lock_irq(shost
->host_lock
);
566 vport
->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
567 spin_unlock_irq(shost
->host_lock
);
571 if (phba
->sli_rev
< LPFC_SLI_REV4
) {
572 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_REG_LOGIN_ISSUE
);
573 if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
&&
574 vport
->fc_flag
& FC_VPORT_NEEDS_REG_VPI
)
575 lpfc_register_new_vport(phba
, vport
, ndlp
);
577 lpfc_issue_fabric_reglogin(vport
);
579 ndlp
->nlp_type
|= NLP_FABRIC
;
580 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
581 if (vport
->vfi_state
& LPFC_VFI_REGISTERED
) {
582 lpfc_start_fdiscs(phba
);
583 lpfc_do_scr_ns_plogi(phba
, vport
);
585 lpfc_issue_reg_vfi(vport
);
590 * lpfc_cmpl_els_flogi_nport - Completion function for flogi to an N_Port
591 * @vport: pointer to a host virtual N_Port data structure.
592 * @ndlp: pointer to a node-list data structure.
593 * @sp: pointer to service parameter data structure.
595 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
596 * function to handle the completion of a Fabric Login (FLOGI) into an N_Port
597 * in a point-to-point topology. First, the @vport's N_Port Name is compared
598 * with the received N_Port Name: if the @vport's N_Port Name is greater than
599 * the received N_Port Name lexicographically, this node shall assign local
600 * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and
601 * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise,
602 * this node shall just wait for the remote node to issue PLOGI and assign
610 lpfc_cmpl_els_flogi_nport(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
611 struct serv_parm
*sp
)
613 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
614 struct lpfc_hba
*phba
= vport
->phba
;
618 spin_lock_irq(shost
->host_lock
);
619 vport
->fc_flag
&= ~(FC_FABRIC
| FC_PUBLIC_LOOP
);
620 spin_unlock_irq(shost
->host_lock
);
622 phba
->fc_edtov
= FF_DEF_EDTOV
;
623 phba
->fc_ratov
= FF_DEF_RATOV
;
624 rc
= memcmp(&vport
->fc_portname
, &sp
->portName
,
625 sizeof(vport
->fc_portname
));
627 /* This side will initiate the PLOGI */
628 spin_lock_irq(shost
->host_lock
);
629 vport
->fc_flag
|= FC_PT2PT_PLOGI
;
630 spin_unlock_irq(shost
->host_lock
);
633 * N_Port ID cannot be 0, set our to LocalID the other
634 * side will be RemoteID.
639 vport
->fc_myDID
= PT2PT_LocalID
;
641 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
645 lpfc_config_link(phba
, mbox
);
647 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
649 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
650 if (rc
== MBX_NOT_FINISHED
) {
651 mempool_free(mbox
, phba
->mbox_mem_pool
);
654 /* Decrement ndlp reference count indicating that ndlp can be
655 * safely released when other references to it are done.
659 ndlp
= lpfc_findnode_did(vport
, PT2PT_RemoteID
);
662 * Cannot find existing Fabric ndlp, so allocate a
665 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
668 lpfc_nlp_init(vport
, ndlp
, PT2PT_RemoteID
);
669 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
670 ndlp
= lpfc_enable_node(vport
, ndlp
,
671 NLP_STE_UNUSED_NODE
);
676 memcpy(&ndlp
->nlp_portname
, &sp
->portName
,
677 sizeof(struct lpfc_name
));
678 memcpy(&ndlp
->nlp_nodename
, &sp
->nodeName
,
679 sizeof(struct lpfc_name
));
680 /* Set state will put ndlp onto node list if not already done */
681 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
682 spin_lock_irq(shost
->host_lock
);
683 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
684 spin_unlock_irq(shost
->host_lock
);
686 /* This side will wait for the PLOGI, decrement ndlp reference
687 * count indicating that ndlp can be released when other
688 * references to it are done.
692 /* If we are pt2pt with another NPort, force NPIV off! */
693 phba
->sli3_options
&= ~LPFC_SLI3_NPIV_ENABLED
;
695 spin_lock_irq(shost
->host_lock
);
696 vport
->fc_flag
|= FC_PT2PT
;
697 spin_unlock_irq(shost
->host_lock
);
699 /* Start discovery - this should just do CLEAR_LA */
700 lpfc_disc_start(vport
);
707 * lpfc_cmpl_els_flogi - Completion callback function for flogi
708 * @phba: pointer to lpfc hba data structure.
709 * @cmdiocb: pointer to lpfc command iocb data structure.
710 * @rspiocb: pointer to lpfc response iocb data structure.
712 * This routine is the top-level completion callback function for issuing
713 * a Fabric Login (FLOGI) command. If the response IOCB reported error,
714 * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If
715 * retry has been made (either immediately or delayed with lpfc_els_retry()
716 * returning 1), the command IOCB will be released and function returned.
717 * If the retry attempt has been given up (possibly reach the maximum
718 * number of retries), one additional decrement of ndlp reference shall be
719 * invoked before going out after releasing the command IOCB. This will
720 * actually release the remote node (Note, lpfc_els_free_iocb() will also
721 * invoke one decrement of ndlp reference count). If no error reported in
722 * the IOCB status, the command Port ID field is used to determine whether
723 * this is a point-to-point topology or a fabric topology: if the Port ID
724 * field is assigned, it is a fabric topology; otherwise, it is a
725 * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or
726 * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the
727 * specific topology completion conditions.
730 lpfc_cmpl_els_flogi(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
731 struct lpfc_iocbq
*rspiocb
)
733 struct lpfc_vport
*vport
= cmdiocb
->vport
;
734 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
735 IOCB_t
*irsp
= &rspiocb
->iocb
;
736 struct lpfc_nodelist
*ndlp
= cmdiocb
->context1
;
737 struct lpfc_dmabuf
*pcmd
= cmdiocb
->context2
, *prsp
;
738 struct serv_parm
*sp
;
741 /* Check to see if link went down during discovery */
742 if (lpfc_els_chk_latt(vport
)) {
743 /* One additional decrement on node reference count to
744 * trigger the release of the node
750 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
751 "FLOGI cmpl: status:x%x/x%x state:x%x",
752 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
755 if (irsp
->ulpStatus
) {
756 /* Check for retry */
757 if (lpfc_els_retry(phba
, cmdiocb
, rspiocb
))
760 /* FLOGI failed, so there is no fabric */
761 spin_lock_irq(shost
->host_lock
);
762 vport
->fc_flag
&= ~(FC_FABRIC
| FC_PUBLIC_LOOP
);
763 spin_unlock_irq(shost
->host_lock
);
765 /* If private loop, then allow max outstanding els to be
766 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
767 * alpa map would take too long otherwise.
769 if (phba
->alpa_map
[0] == 0) {
770 vport
->cfg_discovery_threads
= LPFC_MAX_DISC_THREADS
;
774 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
775 "0100 FLOGI failure Data: x%x x%x "
777 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
783 * The FLogI succeeded. Sync the data for the CPU before
786 prsp
= list_get_first(&pcmd
->list
, struct lpfc_dmabuf
, list
);
788 sp
= prsp
->virt
+ sizeof(uint32_t);
790 /* FLOGI completes successfully */
791 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
792 "0101 FLOGI completes sucessfully "
793 "Data: x%x x%x x%x x%x\n",
794 irsp
->un
.ulpWord
[4], sp
->cmn
.e_d_tov
,
795 sp
->cmn
.w2
.r_a_tov
, sp
->cmn
.edtovResolution
);
797 if (vport
->port_state
== LPFC_FLOGI
) {
799 * If Common Service Parameters indicate Nport
800 * we are point to point, if Fport we are Fabric.
803 rc
= lpfc_cmpl_els_flogi_fabric(vport
, ndlp
, sp
, irsp
);
805 rc
= lpfc_cmpl_els_flogi_nport(vport
, ndlp
, sp
);
814 if (!lpfc_error_lost_link(irsp
)) {
815 /* FLOGI failed, so just use loop map to make discovery list */
816 lpfc_disc_list_loopmap(vport
);
818 /* Start discovery */
819 lpfc_disc_start(vport
);
820 } else if (((irsp
->ulpStatus
!= IOSTAT_LOCAL_REJECT
) ||
821 ((irsp
->un
.ulpWord
[4] != IOERR_SLI_ABORTED
) &&
822 (irsp
->un
.ulpWord
[4] != IOERR_SLI_DOWN
))) &&
823 (phba
->link_state
!= LPFC_CLEAR_LA
)) {
824 /* If FLOGI failed enable link interrupt. */
825 lpfc_issue_clear_la(phba
, vport
);
828 lpfc_els_free_iocb(phba
, cmdiocb
);
832 * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport
833 * @vport: pointer to a host virtual N_Port data structure.
834 * @ndlp: pointer to a node-list data structure.
835 * @retry: number of retries to the command IOCB.
837 * This routine issues a Fabric Login (FLOGI) Request ELS command
838 * for a @vport. The initiator service parameters are put into the payload
839 * of the FLOGI Request IOCB and the top-level callback function pointer
840 * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
841 * function field. The lpfc_issue_fabric_iocb routine is invoked to send
842 * out FLOGI ELS command with one outstanding fabric IOCB at a time.
844 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
845 * will be incremented by 1 for holding the ndlp and the reference to ndlp
846 * will be stored into the context1 field of the IOCB for the completion
847 * callback function to the FLOGI ELS command.
850 * 0 - successfully issued flogi iocb for @vport
851 * 1 - failed to issue flogi iocb for @vport
854 lpfc_issue_els_flogi(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
857 struct lpfc_hba
*phba
= vport
->phba
;
858 struct serv_parm
*sp
;
860 struct lpfc_iocbq
*elsiocb
;
861 struct lpfc_sli_ring
*pring
;
867 pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
869 cmdsize
= (sizeof(uint32_t) + sizeof(struct serv_parm
));
870 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
,
871 ndlp
->nlp_DID
, ELS_CMD_FLOGI
);
876 icmd
= &elsiocb
->iocb
;
877 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
879 /* For FLOGI request, remainder of payload is service parameters */
880 *((uint32_t *) (pcmd
)) = ELS_CMD_FLOGI
;
881 pcmd
+= sizeof(uint32_t);
882 memcpy(pcmd
, &vport
->fc_sparam
, sizeof(struct serv_parm
));
883 sp
= (struct serv_parm
*) pcmd
;
885 /* Setup CSPs accordingly for Fabric */
887 sp
->cmn
.w2
.r_a_tov
= 0;
888 sp
->cls1
.classValid
= 0;
889 sp
->cls2
.seqDelivery
= 1;
890 sp
->cls3
.seqDelivery
= 1;
891 if (sp
->cmn
.fcphLow
< FC_PH3
)
892 sp
->cmn
.fcphLow
= FC_PH3
;
893 if (sp
->cmn
.fcphHigh
< FC_PH3
)
894 sp
->cmn
.fcphHigh
= FC_PH3
;
896 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
897 elsiocb
->iocb
.ulpCt_h
= ((SLI4_CT_FCFI
>> 1) & 1);
898 elsiocb
->iocb
.ulpCt_l
= (SLI4_CT_FCFI
& 1);
899 /* FLOGI needs to be 3 for WQE FCFI */
900 /* Set the fcfi to the fcfi we registered with */
901 elsiocb
->iocb
.ulpContext
= phba
->fcf
.fcfi
;
902 } else if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) {
903 sp
->cmn
.request_multiple_Nport
= 1;
904 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
909 if (phba
->fc_topology
!= TOPOLOGY_LOOP
) {
910 icmd
->un
.elsreq64
.myID
= 0;
911 icmd
->un
.elsreq64
.fl
= 1;
914 tmo
= phba
->fc_ratov
;
915 phba
->fc_ratov
= LPFC_DISC_FLOGI_TMO
;
916 lpfc_set_disctmo(vport
);
917 phba
->fc_ratov
= tmo
;
919 phba
->fc_stat
.elsXmitFLOGI
++;
920 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_flogi
;
922 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
923 "Issue FLOGI: opt:x%x",
924 phba
->sli3_options
, 0, 0);
926 rc
= lpfc_issue_fabric_iocb(phba
, elsiocb
);
927 if (rc
== IOCB_ERROR
) {
928 lpfc_els_free_iocb(phba
, elsiocb
);
935 * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs
936 * @phba: pointer to lpfc hba data structure.
938 * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
939 * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
940 * list and issues an abort IOCB commond on each outstanding IOCB that
941 * contains a active Fabric_DID ndlp. Note that this function is to issue
942 * the abort IOCB command on all the outstanding IOCBs, thus when this
943 * function returns, it does not guarantee all the IOCBs are actually aborted.
946 * 0 - Sucessfully issued abort iocb on all outstanding flogis (Always 0)
949 lpfc_els_abort_flogi(struct lpfc_hba
*phba
)
951 struct lpfc_sli_ring
*pring
;
952 struct lpfc_iocbq
*iocb
, *next_iocb
;
953 struct lpfc_nodelist
*ndlp
;
956 /* Abort outstanding I/O on NPort <nlp_DID> */
957 lpfc_printf_log(phba
, KERN_INFO
, LOG_DISCOVERY
,
958 "0201 Abort outstanding I/O on NPort x%x\n",
961 pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
964 * Check the txcmplq for an iocb that matches the nport the driver is
967 spin_lock_irq(&phba
->hbalock
);
968 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txcmplq
, list
) {
970 if (icmd
->ulpCommand
== CMD_ELS_REQUEST64_CR
&&
971 icmd
->un
.elsreq64
.bdl
.ulpIoTag32
) {
972 ndlp
= (struct lpfc_nodelist
*)(iocb
->context1
);
973 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
) &&
974 (ndlp
->nlp_DID
== Fabric_DID
))
975 lpfc_sli_issue_abort_iotag(phba
, pring
, iocb
);
978 spin_unlock_irq(&phba
->hbalock
);
984 * lpfc_initial_flogi - Issue an initial fabric login for a vport
985 * @vport: pointer to a host virtual N_Port data structure.
987 * This routine issues an initial Fabric Login (FLOGI) for the @vport
988 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
989 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
990 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
991 * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
992 * is then invoked with the @vport and the ndlp to perform the FLOGI for the
996 * 0 - failed to issue initial flogi for @vport
997 * 1 - successfully issued initial flogi for @vport
1000 lpfc_initial_flogi(struct lpfc_vport
*vport
)
1002 struct lpfc_hba
*phba
= vport
->phba
;
1003 struct lpfc_nodelist
*ndlp
;
1005 vport
->port_state
= LPFC_FLOGI
;
1006 lpfc_set_disctmo(vport
);
1008 /* First look for the Fabric ndlp */
1009 ndlp
= lpfc_findnode_did(vport
, Fabric_DID
);
1011 /* Cannot find existing Fabric ndlp, so allocate a new one */
1012 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
1015 lpfc_nlp_init(vport
, ndlp
, Fabric_DID
);
1016 /* Set the node type */
1017 ndlp
->nlp_type
|= NLP_FABRIC
;
1018 /* Put ndlp onto node list */
1019 lpfc_enqueue_node(vport
, ndlp
);
1020 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
1021 /* re-setup ndlp without removing from node list */
1022 ndlp
= lpfc_enable_node(vport
, ndlp
, NLP_STE_UNUSED_NODE
);
1027 if (lpfc_issue_els_flogi(vport
, ndlp
, 0))
1028 /* This decrement of reference count to node shall kick off
1029 * the release of the node.
1037 * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport
1038 * @vport: pointer to a host virtual N_Port data structure.
1040 * This routine issues an initial Fabric Discover (FDISC) for the @vport
1041 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1042 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1043 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1044 * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
1045 * is then invoked with the @vport and the ndlp to perform the FDISC for the
1049 * 0 - failed to issue initial fdisc for @vport
1050 * 1 - successfully issued initial fdisc for @vport
1053 lpfc_initial_fdisc(struct lpfc_vport
*vport
)
1055 struct lpfc_hba
*phba
= vport
->phba
;
1056 struct lpfc_nodelist
*ndlp
;
1058 /* First look for the Fabric ndlp */
1059 ndlp
= lpfc_findnode_did(vport
, Fabric_DID
);
1061 /* Cannot find existing Fabric ndlp, so allocate a new one */
1062 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
1065 lpfc_nlp_init(vport
, ndlp
, Fabric_DID
);
1066 /* Put ndlp onto node list */
1067 lpfc_enqueue_node(vport
, ndlp
);
1068 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
1069 /* re-setup ndlp without removing from node list */
1070 ndlp
= lpfc_enable_node(vport
, ndlp
, NLP_STE_UNUSED_NODE
);
1075 if (lpfc_issue_els_fdisc(vport
, ndlp
, 0)) {
1076 /* decrement node reference count to trigger the release of
1086 * lpfc_more_plogi - Check and issue remaining plogis for a vport
1087 * @vport: pointer to a host virtual N_Port data structure.
1089 * This routine checks whether there are more remaining Port Logins
1090 * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
1091 * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
1092 * to issue ELS PLOGIs up to the configured discover threads with the
1093 * @vport (@vport->cfg_discovery_threads). The function also decrement
1094 * the @vport's num_disc_node by 1 if it is not already 0.
1097 lpfc_more_plogi(struct lpfc_vport
*vport
)
1101 if (vport
->num_disc_nodes
)
1102 vport
->num_disc_nodes
--;
1104 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
1105 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
1106 "0232 Continue discovery with %d PLOGIs to go "
1107 "Data: x%x x%x x%x\n",
1108 vport
->num_disc_nodes
, vport
->fc_plogi_cnt
,
1109 vport
->fc_flag
, vport
->port_state
);
1110 /* Check to see if there are more PLOGIs to be sent */
1111 if (vport
->fc_flag
& FC_NLP_MORE
)
1112 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
1113 sentplogi
= lpfc_els_disc_plogi(vport
);
1119 * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp
1120 * @phba: pointer to lpfc hba data structure.
1121 * @prsp: pointer to response IOCB payload.
1122 * @ndlp: pointer to a node-list data structure.
1124 * This routine checks and indicates whether the WWPN of an N_Port, retrieved
1125 * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
1126 * The following cases are considered N_Port confirmed:
1127 * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
1128 * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
1129 * it does not have WWPN assigned either. If the WWPN is confirmed, the
1130 * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
1131 * 1) if there is a node on vport list other than the @ndlp with the same
1132 * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
1133 * on that node to release the RPI associated with the node; 2) if there is
1134 * no node found on vport list with the same WWPN of the N_Port PLOGI logged
1135 * into, a new node shall be allocated (or activated). In either case, the
1136 * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
1137 * be released and the new_ndlp shall be put on to the vport node list and
1138 * its pointer returned as the confirmed node.
1140 * Note that before the @ndlp got "released", the keepDID from not-matching
1141 * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
1142 * of the @ndlp. This is because the release of @ndlp is actually to put it
1143 * into an inactive state on the vport node list and the vport node list
1144 * management algorithm does not allow two node with a same DID.
1147 * pointer to the PLOGI N_Port @ndlp
1149 static struct lpfc_nodelist
*
1150 lpfc_plogi_confirm_nport(struct lpfc_hba
*phba
, uint32_t *prsp
,
1151 struct lpfc_nodelist
*ndlp
)
1153 struct lpfc_vport
*vport
= ndlp
->vport
;
1154 struct lpfc_nodelist
*new_ndlp
;
1155 struct lpfc_rport_data
*rdata
;
1156 struct fc_rport
*rport
;
1157 struct serv_parm
*sp
;
1158 uint8_t name
[sizeof(struct lpfc_name
)];
1159 uint32_t rc
, keepDID
= 0;
1161 /* Fabric nodes can have the same WWPN so we don't bother searching
1162 * by WWPN. Just return the ndlp that was given to us.
1164 if (ndlp
->nlp_type
& NLP_FABRIC
)
1167 sp
= (struct serv_parm
*) ((uint8_t *) prsp
+ sizeof(uint32_t));
1168 memset(name
, 0, sizeof(struct lpfc_name
));
1170 /* Now we find out if the NPort we are logging into, matches the WWPN
1171 * we have for that ndlp. If not, we have some work to do.
1173 new_ndlp
= lpfc_findnode_wwpn(vport
, &sp
->portName
);
1175 if (new_ndlp
== ndlp
&& NLP_CHK_NODE_ACT(new_ndlp
))
1179 rc
= memcmp(&ndlp
->nlp_portname
, name
,
1180 sizeof(struct lpfc_name
));
1183 new_ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_ATOMIC
);
1186 lpfc_nlp_init(vport
, new_ndlp
, ndlp
->nlp_DID
);
1187 } else if (!NLP_CHK_NODE_ACT(new_ndlp
)) {
1188 rc
= memcmp(&ndlp
->nlp_portname
, name
,
1189 sizeof(struct lpfc_name
));
1192 new_ndlp
= lpfc_enable_node(vport
, new_ndlp
,
1193 NLP_STE_UNUSED_NODE
);
1196 keepDID
= new_ndlp
->nlp_DID
;
1198 keepDID
= new_ndlp
->nlp_DID
;
1200 lpfc_unreg_rpi(vport
, new_ndlp
);
1201 new_ndlp
->nlp_DID
= ndlp
->nlp_DID
;
1202 new_ndlp
->nlp_prev_state
= ndlp
->nlp_prev_state
;
1204 if (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
)
1205 new_ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
1206 ndlp
->nlp_flag
&= ~NLP_NPR_2B_DISC
;
1208 /* Set state will put new_ndlp on to node list if not already done */
1209 lpfc_nlp_set_state(vport
, new_ndlp
, ndlp
->nlp_state
);
1211 /* Move this back to NPR state */
1212 if (memcmp(&ndlp
->nlp_portname
, name
, sizeof(struct lpfc_name
)) == 0) {
1213 /* The new_ndlp is replacing ndlp totally, so we need
1214 * to put ndlp on UNUSED list and try to free it.
1217 /* Fix up the rport accordingly */
1218 rport
= ndlp
->rport
;
1220 rdata
= rport
->dd_data
;
1221 if (rdata
->pnode
== ndlp
) {
1224 rdata
->pnode
= lpfc_nlp_get(new_ndlp
);
1225 new_ndlp
->rport
= rport
;
1227 new_ndlp
->nlp_type
= ndlp
->nlp_type
;
1229 /* We shall actually free the ndlp with both nlp_DID and
1230 * nlp_portname fields equals 0 to avoid any ndlp on the
1231 * nodelist never to be used.
1233 if (ndlp
->nlp_DID
== 0) {
1234 spin_lock_irq(&phba
->ndlp_lock
);
1235 NLP_SET_FREE_REQ(ndlp
);
1236 spin_unlock_irq(&phba
->ndlp_lock
);
1239 /* Two ndlps cannot have the same did on the nodelist */
1240 ndlp
->nlp_DID
= keepDID
;
1241 lpfc_drop_node(vport
, ndlp
);
1244 lpfc_unreg_rpi(vport
, ndlp
);
1245 /* Two ndlps cannot have the same did */
1246 ndlp
->nlp_DID
= keepDID
;
1247 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
1253 * lpfc_end_rscn - Check and handle more rscn for a vport
1254 * @vport: pointer to a host virtual N_Port data structure.
1256 * This routine checks whether more Registration State Change
1257 * Notifications (RSCNs) came in while the discovery state machine was in
1258 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1259 * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1260 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1261 * handling the RSCNs.
1264 lpfc_end_rscn(struct lpfc_vport
*vport
)
1266 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1268 if (vport
->fc_flag
& FC_RSCN_MODE
) {
1270 * Check to see if more RSCNs came in while we were
1271 * processing this one.
1273 if (vport
->fc_rscn_id_cnt
||
1274 (vport
->fc_flag
& FC_RSCN_DISCOVERY
) != 0)
1275 lpfc_els_handle_rscn(vport
);
1277 spin_lock_irq(shost
->host_lock
);
1278 vport
->fc_flag
&= ~FC_RSCN_MODE
;
1279 spin_unlock_irq(shost
->host_lock
);
1285 * lpfc_cmpl_els_plogi - Completion callback function for plogi
1286 * @phba: pointer to lpfc hba data structure.
1287 * @cmdiocb: pointer to lpfc command iocb data structure.
1288 * @rspiocb: pointer to lpfc response iocb data structure.
1290 * This routine is the completion callback function for issuing the Port
1291 * Login (PLOGI) command. For PLOGI completion, there must be an active
1292 * ndlp on the vport node list that matches the remote node ID from the
1293 * PLOGI reponse IOCB. If such ndlp does not exist, the PLOGI is simply
1294 * ignored and command IOCB released. The PLOGI response IOCB status is
1295 * checked for error conditons. If there is error status reported, PLOGI
1296 * retry shall be attempted by invoking the lpfc_els_retry() routine.
1297 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1298 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1299 * (DSM) is set for this PLOGI completion. Finally, it checks whether
1300 * there are additional N_Port nodes with the vport that need to perform
1301 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
1305 lpfc_cmpl_els_plogi(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
1306 struct lpfc_iocbq
*rspiocb
)
1308 struct lpfc_vport
*vport
= cmdiocb
->vport
;
1309 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1311 struct lpfc_nodelist
*ndlp
;
1312 struct lpfc_dmabuf
*prsp
;
1313 int disc
, rc
, did
, type
;
1315 /* we pass cmdiocb to state machine which needs rspiocb as well */
1316 cmdiocb
->context_un
.rsp_iocb
= rspiocb
;
1318 irsp
= &rspiocb
->iocb
;
1319 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
1320 "PLOGI cmpl: status:x%x/x%x did:x%x",
1321 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1322 irsp
->un
.elsreq64
.remoteID
);
1324 ndlp
= lpfc_findnode_did(vport
, irsp
->un
.elsreq64
.remoteID
);
1325 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
)) {
1326 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
1327 "0136 PLOGI completes to NPort x%x "
1328 "with no ndlp. Data: x%x x%x x%x\n",
1329 irsp
->un
.elsreq64
.remoteID
,
1330 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1335 /* Since ndlp can be freed in the disc state machine, note if this node
1336 * is being used during discovery.
1338 spin_lock_irq(shost
->host_lock
);
1339 disc
= (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
);
1340 ndlp
->nlp_flag
&= ~NLP_NPR_2B_DISC
;
1341 spin_unlock_irq(shost
->host_lock
);
1344 /* PLOGI completes to NPort <nlp_DID> */
1345 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
1346 "0102 PLOGI completes to NPort x%x "
1347 "Data: x%x x%x x%x x%x x%x\n",
1348 ndlp
->nlp_DID
, irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1349 irsp
->ulpTimeout
, disc
, vport
->num_disc_nodes
);
1350 /* Check to see if link went down during discovery */
1351 if (lpfc_els_chk_latt(vport
)) {
1352 spin_lock_irq(shost
->host_lock
);
1353 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
1354 spin_unlock_irq(shost
->host_lock
);
1358 /* ndlp could be freed in DSM, save these values now */
1359 type
= ndlp
->nlp_type
;
1360 did
= ndlp
->nlp_DID
;
1362 if (irsp
->ulpStatus
) {
1363 /* Check for retry */
1364 if (lpfc_els_retry(phba
, cmdiocb
, rspiocb
)) {
1365 /* ELS command is being retried */
1367 spin_lock_irq(shost
->host_lock
);
1368 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
1369 spin_unlock_irq(shost
->host_lock
);
1374 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1375 if (lpfc_error_lost_link(irsp
))
1376 rc
= NLP_STE_FREED_NODE
;
1378 rc
= lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
1379 NLP_EVT_CMPL_PLOGI
);
1381 /* Good status, call state machine */
1382 prsp
= list_entry(((struct lpfc_dmabuf
*)
1383 cmdiocb
->context2
)->list
.next
,
1384 struct lpfc_dmabuf
, list
);
1385 ndlp
= lpfc_plogi_confirm_nport(phba
, prsp
->virt
, ndlp
);
1386 rc
= lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
1387 NLP_EVT_CMPL_PLOGI
);
1390 if (disc
&& vport
->num_disc_nodes
) {
1391 /* Check to see if there are more PLOGIs to be sent */
1392 lpfc_more_plogi(vport
);
1394 if (vport
->num_disc_nodes
== 0) {
1395 spin_lock_irq(shost
->host_lock
);
1396 vport
->fc_flag
&= ~FC_NDISC_ACTIVE
;
1397 spin_unlock_irq(shost
->host_lock
);
1399 lpfc_can_disctmo(vport
);
1400 lpfc_end_rscn(vport
);
1405 lpfc_els_free_iocb(phba
, cmdiocb
);
1410 * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
1411 * @vport: pointer to a host virtual N_Port data structure.
1412 * @did: destination port identifier.
1413 * @retry: number of retries to the command IOCB.
1415 * This routine issues a Port Login (PLOGI) command to a remote N_Port
1416 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
1417 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
1418 * This routine constructs the proper feilds of the PLOGI IOCB and invokes
1419 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
1421 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1422 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1423 * will be stored into the context1 field of the IOCB for the completion
1424 * callback function to the PLOGI ELS command.
1427 * 0 - Successfully issued a plogi for @vport
1428 * 1 - failed to issue a plogi for @vport
1431 lpfc_issue_els_plogi(struct lpfc_vport
*vport
, uint32_t did
, uint8_t retry
)
1433 struct lpfc_hba
*phba
= vport
->phba
;
1434 struct serv_parm
*sp
;
1436 struct lpfc_nodelist
*ndlp
;
1437 struct lpfc_iocbq
*elsiocb
;
1438 struct lpfc_sli
*psli
;
1445 ndlp
= lpfc_findnode_did(vport
, did
);
1446 if (ndlp
&& !NLP_CHK_NODE_ACT(ndlp
))
1449 /* If ndlp is not NULL, we will bump the reference count on it */
1450 cmdsize
= (sizeof(uint32_t) + sizeof(struct serv_parm
));
1451 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
, did
,
1456 icmd
= &elsiocb
->iocb
;
1457 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
1459 /* For PLOGI request, remainder of payload is service parameters */
1460 *((uint32_t *) (pcmd
)) = ELS_CMD_PLOGI
;
1461 pcmd
+= sizeof(uint32_t);
1462 memcpy(pcmd
, &vport
->fc_sparam
, sizeof(struct serv_parm
));
1463 sp
= (struct serv_parm
*) pcmd
;
1465 if (sp
->cmn
.fcphLow
< FC_PH_4_3
)
1466 sp
->cmn
.fcphLow
= FC_PH_4_3
;
1468 if (sp
->cmn
.fcphHigh
< FC_PH3
)
1469 sp
->cmn
.fcphHigh
= FC_PH3
;
1471 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
1472 "Issue PLOGI: did:x%x",
1475 phba
->fc_stat
.elsXmitPLOGI
++;
1476 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_plogi
;
1477 ret
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
1479 if (ret
== IOCB_ERROR
) {
1480 lpfc_els_free_iocb(phba
, elsiocb
);
1487 * lpfc_cmpl_els_prli - Completion callback function for prli
1488 * @phba: pointer to lpfc hba data structure.
1489 * @cmdiocb: pointer to lpfc command iocb data structure.
1490 * @rspiocb: pointer to lpfc response iocb data structure.
1492 * This routine is the completion callback function for a Process Login
1493 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
1494 * status. If there is error status reported, PRLI retry shall be attempted
1495 * by invoking the lpfc_els_retry() routine. Otherwise, the state
1496 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
1497 * ndlp to mark the PRLI completion.
1500 lpfc_cmpl_els_prli(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
1501 struct lpfc_iocbq
*rspiocb
)
1503 struct lpfc_vport
*vport
= cmdiocb
->vport
;
1504 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1506 struct lpfc_sli
*psli
;
1507 struct lpfc_nodelist
*ndlp
;
1510 /* we pass cmdiocb to state machine which needs rspiocb as well */
1511 cmdiocb
->context_un
.rsp_iocb
= rspiocb
;
1513 irsp
= &(rspiocb
->iocb
);
1514 ndlp
= (struct lpfc_nodelist
*) cmdiocb
->context1
;
1515 spin_lock_irq(shost
->host_lock
);
1516 ndlp
->nlp_flag
&= ~NLP_PRLI_SND
;
1517 spin_unlock_irq(shost
->host_lock
);
1519 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
1520 "PRLI cmpl: status:x%x/x%x did:x%x",
1521 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1523 /* PRLI completes to NPort <nlp_DID> */
1524 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
1525 "0103 PRLI completes to NPort x%x "
1526 "Data: x%x x%x x%x x%x\n",
1527 ndlp
->nlp_DID
, irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1528 irsp
->ulpTimeout
, vport
->num_disc_nodes
);
1530 vport
->fc_prli_sent
--;
1531 /* Check to see if link went down during discovery */
1532 if (lpfc_els_chk_latt(vport
))
1535 if (irsp
->ulpStatus
) {
1536 /* Check for retry */
1537 if (lpfc_els_retry(phba
, cmdiocb
, rspiocb
)) {
1538 /* ELS command is being retried */
1542 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1543 if (lpfc_error_lost_link(irsp
))
1546 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
1549 /* Good status, call state machine */
1550 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
1553 lpfc_els_free_iocb(phba
, cmdiocb
);
1558 * lpfc_issue_els_prli - Issue a prli iocb command for a vport
1559 * @vport: pointer to a host virtual N_Port data structure.
1560 * @ndlp: pointer to a node-list data structure.
1561 * @retry: number of retries to the command IOCB.
1563 * This routine issues a Process Login (PRLI) ELS command for the
1564 * @vport. The PRLI service parameters are set up in the payload of the
1565 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
1566 * is put to the IOCB completion callback func field before invoking the
1567 * routine lpfc_sli_issue_iocb() to send out PRLI command.
1569 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1570 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1571 * will be stored into the context1 field of the IOCB for the completion
1572 * callback function to the PRLI ELS command.
1575 * 0 - successfully issued prli iocb command for @vport
1576 * 1 - failed to issue prli iocb command for @vport
1579 lpfc_issue_els_prli(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1582 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1583 struct lpfc_hba
*phba
= vport
->phba
;
1586 struct lpfc_iocbq
*elsiocb
;
1590 cmdsize
= (sizeof(uint32_t) + sizeof(PRLI
));
1591 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
,
1592 ndlp
->nlp_DID
, ELS_CMD_PRLI
);
1596 icmd
= &elsiocb
->iocb
;
1597 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
1599 /* For PRLI request, remainder of payload is service parameters */
1600 memset(pcmd
, 0, (sizeof(PRLI
) + sizeof(uint32_t)));
1601 *((uint32_t *) (pcmd
)) = ELS_CMD_PRLI
;
1602 pcmd
+= sizeof(uint32_t);
1604 /* For PRLI, remainder of payload is PRLI parameter page */
1605 npr
= (PRLI
*) pcmd
;
1607 * If our firmware version is 3.20 or later,
1608 * set the following bits for FC-TAPE support.
1610 if (phba
->vpd
.rev
.feaLevelHigh
>= 0x02) {
1611 npr
->ConfmComplAllowed
= 1;
1613 npr
->TaskRetryIdReq
= 1;
1615 npr
->estabImagePair
= 1;
1616 npr
->readXferRdyDis
= 1;
1618 /* For FCP support */
1619 npr
->prliType
= PRLI_FCP_TYPE
;
1620 npr
->initiatorFunc
= 1;
1622 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
1623 "Issue PRLI: did:x%x",
1624 ndlp
->nlp_DID
, 0, 0);
1626 phba
->fc_stat
.elsXmitPRLI
++;
1627 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_prli
;
1628 spin_lock_irq(shost
->host_lock
);
1629 ndlp
->nlp_flag
|= NLP_PRLI_SND
;
1630 spin_unlock_irq(shost
->host_lock
);
1631 if (lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0) ==
1633 spin_lock_irq(shost
->host_lock
);
1634 ndlp
->nlp_flag
&= ~NLP_PRLI_SND
;
1635 spin_unlock_irq(shost
->host_lock
);
1636 lpfc_els_free_iocb(phba
, elsiocb
);
1639 vport
->fc_prli_sent
++;
1644 * lpfc_rscn_disc - Perform rscn discovery for a vport
1645 * @vport: pointer to a host virtual N_Port data structure.
1647 * This routine performs Registration State Change Notification (RSCN)
1648 * discovery for a @vport. If the @vport's node port recovery count is not
1649 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
1650 * the nodes that need recovery. If none of the PLOGI were needed through
1651 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
1652 * invoked to check and handle possible more RSCN came in during the period
1653 * of processing the current ones.
1656 lpfc_rscn_disc(struct lpfc_vport
*vport
)
1658 lpfc_can_disctmo(vport
);
1660 /* RSCN discovery */
1661 /* go thru NPR nodes and issue ELS PLOGIs */
1662 if (vport
->fc_npr_cnt
)
1663 if (lpfc_els_disc_plogi(vport
))
1666 lpfc_end_rscn(vport
);
1670 * lpfc_adisc_done - Complete the adisc phase of discovery
1671 * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
1673 * This function is called when the final ADISC is completed during discovery.
1674 * This function handles clearing link attention or issuing reg_vpi depending
1675 * on whether npiv is enabled. This function also kicks off the PLOGI phase of
1677 * This function is called with no locks held.
1680 lpfc_adisc_done(struct lpfc_vport
*vport
)
1682 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1683 struct lpfc_hba
*phba
= vport
->phba
;
1686 * For NPIV, cmpl_reg_vpi will set port_state to READY,
1687 * and continue discovery.
1689 if ((phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
1690 !(vport
->fc_flag
& FC_RSCN_MODE
) &&
1691 (phba
->sli_rev
< LPFC_SLI_REV4
)) {
1692 lpfc_issue_reg_vpi(phba
, vport
);
1696 * For SLI2, we need to set port_state to READY
1697 * and continue discovery.
1699 if (vport
->port_state
< LPFC_VPORT_READY
) {
1700 /* If we get here, there is nothing to ADISC */
1701 if (vport
->port_type
== LPFC_PHYSICAL_PORT
)
1702 lpfc_issue_clear_la(phba
, vport
);
1703 if (!(vport
->fc_flag
& FC_ABORT_DISCOVERY
)) {
1704 vport
->num_disc_nodes
= 0;
1705 /* go thru NPR list, issue ELS PLOGIs */
1706 if (vport
->fc_npr_cnt
)
1707 lpfc_els_disc_plogi(vport
);
1708 if (!vport
->num_disc_nodes
) {
1709 spin_lock_irq(shost
->host_lock
);
1710 vport
->fc_flag
&= ~FC_NDISC_ACTIVE
;
1711 spin_unlock_irq(shost
->host_lock
);
1712 lpfc_can_disctmo(vport
);
1713 lpfc_end_rscn(vport
);
1716 vport
->port_state
= LPFC_VPORT_READY
;
1718 lpfc_rscn_disc(vport
);
1722 * lpfc_more_adisc - Issue more adisc as needed
1723 * @vport: pointer to a host virtual N_Port data structure.
1725 * This routine determines whether there are more ndlps on a @vport
1726 * node list need to have Address Discover (ADISC) issued. If so, it will
1727 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
1728 * remaining nodes which need to have ADISC sent.
1731 lpfc_more_adisc(struct lpfc_vport
*vport
)
1735 if (vport
->num_disc_nodes
)
1736 vport
->num_disc_nodes
--;
1737 /* Continue discovery with <num_disc_nodes> ADISCs to go */
1738 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
1739 "0210 Continue discovery with %d ADISCs to go "
1740 "Data: x%x x%x x%x\n",
1741 vport
->num_disc_nodes
, vport
->fc_adisc_cnt
,
1742 vport
->fc_flag
, vport
->port_state
);
1743 /* Check to see if there are more ADISCs to be sent */
1744 if (vport
->fc_flag
& FC_NLP_MORE
) {
1745 lpfc_set_disctmo(vport
);
1746 /* go thru NPR nodes and issue any remaining ELS ADISCs */
1747 sentadisc
= lpfc_els_disc_adisc(vport
);
1749 if (!vport
->num_disc_nodes
)
1750 lpfc_adisc_done(vport
);
1755 * lpfc_cmpl_els_adisc - Completion callback function for adisc
1756 * @phba: pointer to lpfc hba data structure.
1757 * @cmdiocb: pointer to lpfc command iocb data structure.
1758 * @rspiocb: pointer to lpfc response iocb data structure.
1760 * This routine is the completion function for issuing the Address Discover
1761 * (ADISC) command. It first checks to see whether link went down during
1762 * the discovery process. If so, the node will be marked as node port
1763 * recovery for issuing discover IOCB by the link attention handler and
1764 * exit. Otherwise, the response status is checked. If error was reported
1765 * in the response status, the ADISC command shall be retried by invoking
1766 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
1767 * the response status, the state machine is invoked to set transition
1768 * with respect to NLP_EVT_CMPL_ADISC event.
1771 lpfc_cmpl_els_adisc(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
1772 struct lpfc_iocbq
*rspiocb
)
1774 struct lpfc_vport
*vport
= cmdiocb
->vport
;
1775 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1777 struct lpfc_nodelist
*ndlp
;
1780 /* we pass cmdiocb to state machine which needs rspiocb as well */
1781 cmdiocb
->context_un
.rsp_iocb
= rspiocb
;
1783 irsp
= &(rspiocb
->iocb
);
1784 ndlp
= (struct lpfc_nodelist
*) cmdiocb
->context1
;
1786 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
1787 "ADISC cmpl: status:x%x/x%x did:x%x",
1788 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1791 /* Since ndlp can be freed in the disc state machine, note if this node
1792 * is being used during discovery.
1794 spin_lock_irq(shost
->host_lock
);
1795 disc
= (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
);
1796 ndlp
->nlp_flag
&= ~(NLP_ADISC_SND
| NLP_NPR_2B_DISC
);
1797 spin_unlock_irq(shost
->host_lock
);
1798 /* ADISC completes to NPort <nlp_DID> */
1799 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
1800 "0104 ADISC completes to NPort x%x "
1801 "Data: x%x x%x x%x x%x x%x\n",
1802 ndlp
->nlp_DID
, irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1803 irsp
->ulpTimeout
, disc
, vport
->num_disc_nodes
);
1804 /* Check to see if link went down during discovery */
1805 if (lpfc_els_chk_latt(vport
)) {
1806 spin_lock_irq(shost
->host_lock
);
1807 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
1808 spin_unlock_irq(shost
->host_lock
);
1812 if (irsp
->ulpStatus
) {
1813 /* Check for retry */
1814 if (lpfc_els_retry(phba
, cmdiocb
, rspiocb
)) {
1815 /* ELS command is being retried */
1817 spin_lock_irq(shost
->host_lock
);
1818 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
1819 spin_unlock_irq(shost
->host_lock
);
1820 lpfc_set_disctmo(vport
);
1825 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1826 if (!lpfc_error_lost_link(irsp
))
1827 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
1828 NLP_EVT_CMPL_ADISC
);
1830 /* Good status, call state machine */
1831 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
1832 NLP_EVT_CMPL_ADISC
);
1834 /* Check to see if there are more ADISCs to be sent */
1835 if (disc
&& vport
->num_disc_nodes
)
1836 lpfc_more_adisc(vport
);
1838 lpfc_els_free_iocb(phba
, cmdiocb
);
1843 * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
1844 * @vport: pointer to a virtual N_Port data structure.
1845 * @ndlp: pointer to a node-list data structure.
1846 * @retry: number of retries to the command IOCB.
1848 * This routine issues an Address Discover (ADISC) for an @ndlp on a
1849 * @vport. It prepares the payload of the ADISC ELS command, updates the
1850 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
1851 * to issue the ADISC ELS command.
1853 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1854 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1855 * will be stored into the context1 field of the IOCB for the completion
1856 * callback function to the ADISC ELS command.
1859 * 0 - successfully issued adisc
1860 * 1 - failed to issue adisc
1863 lpfc_issue_els_adisc(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1866 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1867 struct lpfc_hba
*phba
= vport
->phba
;
1870 struct lpfc_iocbq
*elsiocb
;
1874 cmdsize
= (sizeof(uint32_t) + sizeof(ADISC
));
1875 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
,
1876 ndlp
->nlp_DID
, ELS_CMD_ADISC
);
1880 icmd
= &elsiocb
->iocb
;
1881 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
1883 /* For ADISC request, remainder of payload is service parameters */
1884 *((uint32_t *) (pcmd
)) = ELS_CMD_ADISC
;
1885 pcmd
+= sizeof(uint32_t);
1887 /* Fill in ADISC payload */
1888 ap
= (ADISC
*) pcmd
;
1889 ap
->hardAL_PA
= phba
->fc_pref_ALPA
;
1890 memcpy(&ap
->portName
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
1891 memcpy(&ap
->nodeName
, &vport
->fc_nodename
, sizeof(struct lpfc_name
));
1892 ap
->DID
= be32_to_cpu(vport
->fc_myDID
);
1894 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
1895 "Issue ADISC: did:x%x",
1896 ndlp
->nlp_DID
, 0, 0);
1898 phba
->fc_stat
.elsXmitADISC
++;
1899 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_adisc
;
1900 spin_lock_irq(shost
->host_lock
);
1901 ndlp
->nlp_flag
|= NLP_ADISC_SND
;
1902 spin_unlock_irq(shost
->host_lock
);
1903 if (lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0) ==
1905 spin_lock_irq(shost
->host_lock
);
1906 ndlp
->nlp_flag
&= ~NLP_ADISC_SND
;
1907 spin_unlock_irq(shost
->host_lock
);
1908 lpfc_els_free_iocb(phba
, elsiocb
);
1915 * lpfc_cmpl_els_logo - Completion callback function for logo
1916 * @phba: pointer to lpfc hba data structure.
1917 * @cmdiocb: pointer to lpfc command iocb data structure.
1918 * @rspiocb: pointer to lpfc response iocb data structure.
1920 * This routine is the completion function for issuing the ELS Logout (LOGO)
1921 * command. If no error status was reported from the LOGO response, the
1922 * state machine of the associated ndlp shall be invoked for transition with
1923 * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
1924 * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
1927 lpfc_cmpl_els_logo(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
1928 struct lpfc_iocbq
*rspiocb
)
1930 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) cmdiocb
->context1
;
1931 struct lpfc_vport
*vport
= ndlp
->vport
;
1932 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1934 struct lpfc_sli
*psli
;
1937 /* we pass cmdiocb to state machine which needs rspiocb as well */
1938 cmdiocb
->context_un
.rsp_iocb
= rspiocb
;
1940 irsp
= &(rspiocb
->iocb
);
1941 spin_lock_irq(shost
->host_lock
);
1942 ndlp
->nlp_flag
&= ~NLP_LOGO_SND
;
1943 spin_unlock_irq(shost
->host_lock
);
1945 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
1946 "LOGO cmpl: status:x%x/x%x did:x%x",
1947 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1949 /* LOGO completes to NPort <nlp_DID> */
1950 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
1951 "0105 LOGO completes to NPort x%x "
1952 "Data: x%x x%x x%x x%x\n",
1953 ndlp
->nlp_DID
, irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1954 irsp
->ulpTimeout
, vport
->num_disc_nodes
);
1955 /* Check to see if link went down during discovery */
1956 if (lpfc_els_chk_latt(vport
))
1959 if (ndlp
->nlp_flag
& NLP_TARGET_REMOVE
) {
1960 /* NLP_EVT_DEVICE_RM should unregister the RPI
1961 * which should abort all outstanding IOs.
1963 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
1968 if (irsp
->ulpStatus
) {
1969 /* Check for retry */
1970 if (lpfc_els_retry(phba
, cmdiocb
, rspiocb
))
1971 /* ELS command is being retried */
1974 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1975 if (lpfc_error_lost_link(irsp
))
1978 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
1981 /* Good status, call state machine.
1982 * This will unregister the rpi if needed.
1984 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
1987 lpfc_els_free_iocb(phba
, cmdiocb
);
1992 * lpfc_issue_els_logo - Issue a logo to an node on a vport
1993 * @vport: pointer to a virtual N_Port data structure.
1994 * @ndlp: pointer to a node-list data structure.
1995 * @retry: number of retries to the command IOCB.
1997 * This routine constructs and issues an ELS Logout (LOGO) iocb command
1998 * to a remote node, referred by an @ndlp on a @vport. It constructs the
1999 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
2000 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
2002 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2003 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2004 * will be stored into the context1 field of the IOCB for the completion
2005 * callback function to the LOGO ELS command.
2008 * 0 - successfully issued logo
2009 * 1 - failed to issue logo
2012 lpfc_issue_els_logo(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2015 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2016 struct lpfc_hba
*phba
= vport
->phba
;
2018 struct lpfc_iocbq
*elsiocb
;
2023 spin_lock_irq(shost
->host_lock
);
2024 if (ndlp
->nlp_flag
& NLP_LOGO_SND
) {
2025 spin_unlock_irq(shost
->host_lock
);
2028 spin_unlock_irq(shost
->host_lock
);
2030 cmdsize
= (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name
);
2031 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
,
2032 ndlp
->nlp_DID
, ELS_CMD_LOGO
);
2036 icmd
= &elsiocb
->iocb
;
2037 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
2038 *((uint32_t *) (pcmd
)) = ELS_CMD_LOGO
;
2039 pcmd
+= sizeof(uint32_t);
2041 /* Fill in LOGO payload */
2042 *((uint32_t *) (pcmd
)) = be32_to_cpu(vport
->fc_myDID
);
2043 pcmd
+= sizeof(uint32_t);
2044 memcpy(pcmd
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
2046 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
2047 "Issue LOGO: did:x%x",
2048 ndlp
->nlp_DID
, 0, 0);
2050 phba
->fc_stat
.elsXmitLOGO
++;
2051 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_logo
;
2052 spin_lock_irq(shost
->host_lock
);
2053 ndlp
->nlp_flag
|= NLP_LOGO_SND
;
2054 spin_unlock_irq(shost
->host_lock
);
2055 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
2057 if (rc
== IOCB_ERROR
) {
2058 spin_lock_irq(shost
->host_lock
);
2059 ndlp
->nlp_flag
&= ~NLP_LOGO_SND
;
2060 spin_unlock_irq(shost
->host_lock
);
2061 lpfc_els_free_iocb(phba
, elsiocb
);
2068 * lpfc_cmpl_els_cmd - Completion callback function for generic els command
2069 * @phba: pointer to lpfc hba data structure.
2070 * @cmdiocb: pointer to lpfc command iocb data structure.
2071 * @rspiocb: pointer to lpfc response iocb data structure.
2073 * This routine is a generic completion callback function for ELS commands.
2074 * Specifically, it is the callback function which does not need to perform
2075 * any command specific operations. It is currently used by the ELS command
2076 * issuing routines for the ELS State Change Request (SCR),
2077 * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution
2078 * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than
2079 * certain debug loggings, this callback function simply invokes the
2080 * lpfc_els_chk_latt() routine to check whether link went down during the
2081 * discovery process.
2084 lpfc_cmpl_els_cmd(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
2085 struct lpfc_iocbq
*rspiocb
)
2087 struct lpfc_vport
*vport
= cmdiocb
->vport
;
2090 irsp
= &rspiocb
->iocb
;
2092 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
2093 "ELS cmd cmpl: status:x%x/x%x did:x%x",
2094 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
2095 irsp
->un
.elsreq64
.remoteID
);
2096 /* ELS cmd tag <ulpIoTag> completes */
2097 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
2098 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
2099 irsp
->ulpIoTag
, irsp
->ulpStatus
,
2100 irsp
->un
.ulpWord
[4], irsp
->ulpTimeout
);
2101 /* Check to see if link went down during discovery */
2102 lpfc_els_chk_latt(vport
);
2103 lpfc_els_free_iocb(phba
, cmdiocb
);
2108 * lpfc_issue_els_scr - Issue a scr to an node on a vport
2109 * @vport: pointer to a host virtual N_Port data structure.
2110 * @nportid: N_Port identifier to the remote node.
2111 * @retry: number of retries to the command IOCB.
2113 * This routine issues a State Change Request (SCR) to a fabric node
2114 * on a @vport. The remote node @nportid is passed into the function. It
2115 * first search the @vport node list to find the matching ndlp. If no such
2116 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
2117 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
2118 * routine is invoked to send the SCR IOCB.
2120 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2121 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2122 * will be stored into the context1 field of the IOCB for the completion
2123 * callback function to the SCR ELS command.
2126 * 0 - Successfully issued scr command
2127 * 1 - Failed to issue scr command
2130 lpfc_issue_els_scr(struct lpfc_vport
*vport
, uint32_t nportid
, uint8_t retry
)
2132 struct lpfc_hba
*phba
= vport
->phba
;
2134 struct lpfc_iocbq
*elsiocb
;
2135 struct lpfc_sli
*psli
;
2138 struct lpfc_nodelist
*ndlp
;
2141 cmdsize
= (sizeof(uint32_t) + sizeof(SCR
));
2143 ndlp
= lpfc_findnode_did(vport
, nportid
);
2145 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
2148 lpfc_nlp_init(vport
, ndlp
, nportid
);
2149 lpfc_enqueue_node(vport
, ndlp
);
2150 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
2151 ndlp
= lpfc_enable_node(vport
, ndlp
, NLP_STE_UNUSED_NODE
);
2156 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
,
2157 ndlp
->nlp_DID
, ELS_CMD_SCR
);
2160 /* This will trigger the release of the node just
2167 icmd
= &elsiocb
->iocb
;
2168 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
2170 *((uint32_t *) (pcmd
)) = ELS_CMD_SCR
;
2171 pcmd
+= sizeof(uint32_t);
2173 /* For SCR, remainder of payload is SCR parameter page */
2174 memset(pcmd
, 0, sizeof(SCR
));
2175 ((SCR
*) pcmd
)->Function
= SCR_FUNC_FULL
;
2177 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
2178 "Issue SCR: did:x%x",
2179 ndlp
->nlp_DID
, 0, 0);
2181 phba
->fc_stat
.elsXmitSCR
++;
2182 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_cmd
;
2183 if (lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0) ==
2185 /* The additional lpfc_nlp_put will cause the following
2186 * lpfc_els_free_iocb routine to trigger the rlease of
2190 lpfc_els_free_iocb(phba
, elsiocb
);
2193 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2194 * trigger the release of node.
2201 * lpfc_issue_els_farpr - Issue a farp to an node on a vport
2202 * @vport: pointer to a host virtual N_Port data structure.
2203 * @nportid: N_Port identifier to the remote node.
2204 * @retry: number of retries to the command IOCB.
2206 * This routine issues a Fibre Channel Address Resolution Response
2207 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
2208 * is passed into the function. It first search the @vport node list to find
2209 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
2210 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
2211 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
2213 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2214 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2215 * will be stored into the context1 field of the IOCB for the completion
2216 * callback function to the PARPR ELS command.
2219 * 0 - Successfully issued farpr command
2220 * 1 - Failed to issue farpr command
2223 lpfc_issue_els_farpr(struct lpfc_vport
*vport
, uint32_t nportid
, uint8_t retry
)
2225 struct lpfc_hba
*phba
= vport
->phba
;
2227 struct lpfc_iocbq
*elsiocb
;
2228 struct lpfc_sli
*psli
;
2233 struct lpfc_nodelist
*ondlp
;
2234 struct lpfc_nodelist
*ndlp
;
2237 cmdsize
= (sizeof(uint32_t) + sizeof(FARP
));
2239 ndlp
= lpfc_findnode_did(vport
, nportid
);
2241 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
2244 lpfc_nlp_init(vport
, ndlp
, nportid
);
2245 lpfc_enqueue_node(vport
, ndlp
);
2246 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
2247 ndlp
= lpfc_enable_node(vport
, ndlp
, NLP_STE_UNUSED_NODE
);
2252 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
,
2253 ndlp
->nlp_DID
, ELS_CMD_RNID
);
2255 /* This will trigger the release of the node just
2262 icmd
= &elsiocb
->iocb
;
2263 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
2265 *((uint32_t *) (pcmd
)) = ELS_CMD_FARPR
;
2266 pcmd
+= sizeof(uint32_t);
2268 /* Fill in FARPR payload */
2269 fp
= (FARP
*) (pcmd
);
2270 memset(fp
, 0, sizeof(FARP
));
2271 lp
= (uint32_t *) pcmd
;
2272 *lp
++ = be32_to_cpu(nportid
);
2273 *lp
++ = be32_to_cpu(vport
->fc_myDID
);
2275 fp
->Mflags
= (FARP_MATCH_PORT
| FARP_MATCH_NODE
);
2277 memcpy(&fp
->RportName
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
2278 memcpy(&fp
->RnodeName
, &vport
->fc_nodename
, sizeof(struct lpfc_name
));
2279 ondlp
= lpfc_findnode_did(vport
, nportid
);
2280 if (ondlp
&& NLP_CHK_NODE_ACT(ondlp
)) {
2281 memcpy(&fp
->OportName
, &ondlp
->nlp_portname
,
2282 sizeof(struct lpfc_name
));
2283 memcpy(&fp
->OnodeName
, &ondlp
->nlp_nodename
,
2284 sizeof(struct lpfc_name
));
2287 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
2288 "Issue FARPR: did:x%x",
2289 ndlp
->nlp_DID
, 0, 0);
2291 phba
->fc_stat
.elsXmitFARPR
++;
2292 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_cmd
;
2293 if (lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0) ==
2295 /* The additional lpfc_nlp_put will cause the following
2296 * lpfc_els_free_iocb routine to trigger the release of
2300 lpfc_els_free_iocb(phba
, elsiocb
);
2303 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2304 * trigger the release of the node.
2311 * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
2312 * @vport: pointer to a host virtual N_Port data structure.
2313 * @nlp: pointer to a node-list data structure.
2315 * This routine cancels the timer with a delayed IOCB-command retry for
2316 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
2317 * removes the ELS retry event if it presents. In addition, if the
2318 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
2319 * commands are sent for the @vport's nodes that require issuing discovery
2323 lpfc_cancel_retry_delay_tmo(struct lpfc_vport
*vport
, struct lpfc_nodelist
*nlp
)
2325 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2326 struct lpfc_work_evt
*evtp
;
2328 if (!(nlp
->nlp_flag
& NLP_DELAY_TMO
))
2330 spin_lock_irq(shost
->host_lock
);
2331 nlp
->nlp_flag
&= ~NLP_DELAY_TMO
;
2332 spin_unlock_irq(shost
->host_lock
);
2333 del_timer_sync(&nlp
->nlp_delayfunc
);
2334 nlp
->nlp_last_elscmd
= 0;
2335 if (!list_empty(&nlp
->els_retry_evt
.evt_listp
)) {
2336 list_del_init(&nlp
->els_retry_evt
.evt_listp
);
2337 /* Decrement nlp reference count held for the delayed retry */
2338 evtp
= &nlp
->els_retry_evt
;
2339 lpfc_nlp_put((struct lpfc_nodelist
*)evtp
->evt_arg1
);
2341 if (nlp
->nlp_flag
& NLP_NPR_2B_DISC
) {
2342 spin_lock_irq(shost
->host_lock
);
2343 nlp
->nlp_flag
&= ~NLP_NPR_2B_DISC
;
2344 spin_unlock_irq(shost
->host_lock
);
2345 if (vport
->num_disc_nodes
) {
2346 if (vport
->port_state
< LPFC_VPORT_READY
) {
2347 /* Check if there are more ADISCs to be sent */
2348 lpfc_more_adisc(vport
);
2350 /* Check if there are more PLOGIs to be sent */
2351 lpfc_more_plogi(vport
);
2352 if (vport
->num_disc_nodes
== 0) {
2353 spin_lock_irq(shost
->host_lock
);
2354 vport
->fc_flag
&= ~FC_NDISC_ACTIVE
;
2355 spin_unlock_irq(shost
->host_lock
);
2356 lpfc_can_disctmo(vport
);
2357 lpfc_end_rscn(vport
);
2366 * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
2367 * @ptr: holder for the pointer to the timer function associated data (ndlp).
2369 * This routine is invoked by the ndlp delayed-function timer to check
2370 * whether there is any pending ELS retry event(s) with the node. If not, it
2371 * simply returns. Otherwise, if there is at least one ELS delayed event, it
2372 * adds the delayed events to the HBA work list and invokes the
2373 * lpfc_worker_wake_up() routine to wake up worker thread to process the
2374 * event. Note that lpfc_nlp_get() is called before posting the event to
2375 * the work list to hold reference count of ndlp so that it guarantees the
2376 * reference to ndlp will still be available when the worker thread gets
2377 * to the event associated with the ndlp.
2380 lpfc_els_retry_delay(unsigned long ptr
)
2382 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) ptr
;
2383 struct lpfc_vport
*vport
= ndlp
->vport
;
2384 struct lpfc_hba
*phba
= vport
->phba
;
2385 unsigned long flags
;
2386 struct lpfc_work_evt
*evtp
= &ndlp
->els_retry_evt
;
2388 spin_lock_irqsave(&phba
->hbalock
, flags
);
2389 if (!list_empty(&evtp
->evt_listp
)) {
2390 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
2394 /* We need to hold the node by incrementing the reference
2395 * count until the queued work is done
2397 evtp
->evt_arg1
= lpfc_nlp_get(ndlp
);
2398 if (evtp
->evt_arg1
) {
2399 evtp
->evt
= LPFC_EVT_ELS_RETRY
;
2400 list_add_tail(&evtp
->evt_listp
, &phba
->work_list
);
2401 lpfc_worker_wake_up(phba
);
2403 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
2408 * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
2409 * @ndlp: pointer to a node-list data structure.
2411 * This routine is the worker-thread handler for processing the @ndlp delayed
2412 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
2413 * the last ELS command from the associated ndlp and invokes the proper ELS
2414 * function according to the delayed ELS command to retry the command.
2417 lpfc_els_retry_delay_handler(struct lpfc_nodelist
*ndlp
)
2419 struct lpfc_vport
*vport
= ndlp
->vport
;
2420 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2421 uint32_t cmd
, did
, retry
;
2423 spin_lock_irq(shost
->host_lock
);
2424 did
= ndlp
->nlp_DID
;
2425 cmd
= ndlp
->nlp_last_elscmd
;
2426 ndlp
->nlp_last_elscmd
= 0;
2428 if (!(ndlp
->nlp_flag
& NLP_DELAY_TMO
)) {
2429 spin_unlock_irq(shost
->host_lock
);
2433 ndlp
->nlp_flag
&= ~NLP_DELAY_TMO
;
2434 spin_unlock_irq(shost
->host_lock
);
2436 * If a discovery event readded nlp_delayfunc after timer
2437 * firing and before processing the timer, cancel the
2440 del_timer_sync(&ndlp
->nlp_delayfunc
);
2441 retry
= ndlp
->nlp_retry
;
2445 lpfc_issue_els_flogi(vport
, ndlp
, retry
);
2448 if (!lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, retry
)) {
2449 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
2450 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
2454 if (!lpfc_issue_els_adisc(vport
, ndlp
, retry
)) {
2455 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
2456 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_ADISC_ISSUE
);
2460 if (!lpfc_issue_els_prli(vport
, ndlp
, retry
)) {
2461 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
2462 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PRLI_ISSUE
);
2466 if (!lpfc_issue_els_logo(vport
, ndlp
, retry
)) {
2467 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
2468 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
2472 lpfc_issue_els_fdisc(vport
, ndlp
, retry
);
2479 * lpfc_els_retry - Make retry decision on an els command iocb
2480 * @phba: pointer to lpfc hba data structure.
2481 * @cmdiocb: pointer to lpfc command iocb data structure.
2482 * @rspiocb: pointer to lpfc response iocb data structure.
2484 * This routine makes a retry decision on an ELS command IOCB, which has
2485 * failed. The following ELS IOCBs use this function for retrying the command
2486 * when previously issued command responsed with error status: FLOGI, PLOGI,
2487 * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
2488 * returned error status, it makes the decision whether a retry shall be
2489 * issued for the command, and whether a retry shall be made immediately or
2490 * delayed. In the former case, the corresponding ELS command issuing-function
2491 * is called to retry the command. In the later case, the ELS command shall
2492 * be posted to the ndlp delayed event and delayed function timer set to the
2493 * ndlp for the delayed command issusing.
2496 * 0 - No retry of els command is made
2497 * 1 - Immediate or delayed retry of els command is made
2500 lpfc_els_retry(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
2501 struct lpfc_iocbq
*rspiocb
)
2503 struct lpfc_vport
*vport
= cmdiocb
->vport
;
2504 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2505 IOCB_t
*irsp
= &rspiocb
->iocb
;
2506 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) cmdiocb
->context1
;
2507 struct lpfc_dmabuf
*pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
2510 int retry
= 0, maxretry
= lpfc_max_els_tries
, delay
= 0;
2516 /* Note: context2 may be 0 for internal driver abort
2517 * of delays ELS command.
2520 if (pcmd
&& pcmd
->virt
) {
2521 elscmd
= (uint32_t *) (pcmd
->virt
);
2525 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
))
2526 did
= ndlp
->nlp_DID
;
2528 /* We should only hit this case for retrying PLOGI */
2529 did
= irsp
->un
.elsreq64
.remoteID
;
2530 ndlp
= lpfc_findnode_did(vport
, did
);
2531 if ((!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
))
2532 && (cmd
!= ELS_CMD_PLOGI
))
2536 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
2537 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
2538 *(((uint32_t *) irsp
) + 7), irsp
->un
.ulpWord
[4], ndlp
->nlp_DID
);
2540 switch (irsp
->ulpStatus
) {
2541 case IOSTAT_FCP_RSP_ERROR
:
2542 case IOSTAT_REMOTE_STOP
:
2545 case IOSTAT_LOCAL_REJECT
:
2546 switch ((irsp
->un
.ulpWord
[4] & 0xff)) {
2547 case IOERR_LOOP_OPEN_FAILURE
:
2548 if (cmd
== ELS_CMD_FLOGI
) {
2549 if (PCI_DEVICE_ID_HORNET
==
2550 phba
->pcidev
->device
) {
2551 phba
->fc_topology
= TOPOLOGY_LOOP
;
2552 phba
->pport
->fc_myDID
= 0;
2553 phba
->alpa_map
[0] = 0;
2554 phba
->alpa_map
[1] = 0;
2557 if (cmd
== ELS_CMD_PLOGI
&& cmdiocb
->retry
== 0)
2562 case IOERR_ILLEGAL_COMMAND
:
2563 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
2564 "0124 Retry illegal cmd x%x "
2565 "retry:x%x delay:x%x\n",
2566 cmd
, cmdiocb
->retry
, delay
);
2568 /* All command's retry policy */
2570 if (cmdiocb
->retry
> 2)
2574 case IOERR_NO_RESOURCES
:
2575 logerr
= 1; /* HBA out of resources */
2577 if (cmdiocb
->retry
> 100)
2582 case IOERR_ILLEGAL_FRAME
:
2587 case IOERR_SEQUENCE_TIMEOUT
:
2588 case IOERR_INVALID_RPI
:
2594 case IOSTAT_NPORT_RJT
:
2595 case IOSTAT_FABRIC_RJT
:
2596 if (irsp
->un
.ulpWord
[4] & RJT_UNAVAIL_TEMP
) {
2602 case IOSTAT_NPORT_BSY
:
2603 case IOSTAT_FABRIC_BSY
:
2604 logerr
= 1; /* Fabric / Remote NPort out of resources */
2609 stat
.un
.lsRjtError
= be32_to_cpu(irsp
->un
.ulpWord
[4]);
2610 /* Added for Vendor specifc support
2611 * Just keep retrying for these Rsn / Exp codes
2613 switch (stat
.un
.b
.lsRjtRsnCode
) {
2614 case LSRJT_UNABLE_TPC
:
2615 if (stat
.un
.b
.lsRjtRsnCodeExp
==
2616 LSEXP_CMD_IN_PROGRESS
) {
2617 if (cmd
== ELS_CMD_PLOGI
) {
2624 if (cmd
== ELS_CMD_PLOGI
) {
2626 maxretry
= lpfc_max_els_tries
+ 1;
2630 if ((phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
2631 (cmd
== ELS_CMD_FDISC
) &&
2632 (stat
.un
.b
.lsRjtRsnCodeExp
== LSEXP_OUT_OF_RESOURCE
)){
2633 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
2634 "0125 FDISC Failed (x%x). "
2635 "Fabric out of resources\n",
2636 stat
.un
.lsRjtError
);
2637 lpfc_vport_set_state(vport
,
2638 FC_VPORT_NO_FABRIC_RSCS
);
2642 case LSRJT_LOGICAL_BSY
:
2643 if ((cmd
== ELS_CMD_PLOGI
) ||
2644 (cmd
== ELS_CMD_PRLI
)) {
2647 } else if (cmd
== ELS_CMD_FDISC
) {
2648 /* FDISC retry policy */
2650 if (cmdiocb
->retry
>= 32)
2656 case LSRJT_LOGICAL_ERR
:
2657 /* There are some cases where switches return this
2658 * error when they are not ready and should be returning
2659 * Logical Busy. We should delay every time.
2661 if (cmd
== ELS_CMD_FDISC
&&
2662 stat
.un
.b
.lsRjtRsnCodeExp
== LSEXP_PORT_LOGIN_REQ
) {
2668 case LSRJT_PROTOCOL_ERR
:
2669 if ((phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
2670 (cmd
== ELS_CMD_FDISC
) &&
2671 ((stat
.un
.b
.lsRjtRsnCodeExp
== LSEXP_INVALID_PNAME
) ||
2672 (stat
.un
.b
.lsRjtRsnCodeExp
== LSEXP_INVALID_NPORT_ID
))
2674 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
2675 "0122 FDISC Failed (x%x). "
2676 "Fabric Detected Bad WWN\n",
2677 stat
.un
.lsRjtError
);
2678 lpfc_vport_set_state(vport
,
2679 FC_VPORT_FABRIC_REJ_WWN
);
2685 case IOSTAT_INTERMED_RSP
:
2693 if (did
== FDMI_DID
)
2696 if ((cmd
== ELS_CMD_FLOGI
) &&
2697 (phba
->fc_topology
!= TOPOLOGY_LOOP
) &&
2698 !lpfc_error_lost_link(irsp
)) {
2699 /* FLOGI retry policy */
2702 if (cmdiocb
->retry
>= 32)
2706 if ((++cmdiocb
->retry
) >= maxretry
) {
2707 phba
->fc_stat
.elsRetryExceeded
++;
2711 if ((vport
->load_flag
& FC_UNLOADING
) != 0)
2716 /* Retry ELS command <elsCmd> to remote NPORT <did> */
2717 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
2718 "0107 Retry ELS command x%x to remote "
2719 "NPORT x%x Data: x%x x%x\n",
2720 cmd
, did
, cmdiocb
->retry
, delay
);
2722 if (((cmd
== ELS_CMD_PLOGI
) || (cmd
== ELS_CMD_ADISC
)) &&
2723 ((irsp
->ulpStatus
!= IOSTAT_LOCAL_REJECT
) ||
2724 ((irsp
->un
.ulpWord
[4] & 0xff) != IOERR_NO_RESOURCES
))) {
2725 /* Don't reset timer for no resources */
2727 /* If discovery / RSCN timer is running, reset it */
2728 if (timer_pending(&vport
->fc_disctmo
) ||
2729 (vport
->fc_flag
& FC_RSCN_MODE
))
2730 lpfc_set_disctmo(vport
);
2733 phba
->fc_stat
.elsXmitRetry
++;
2734 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
) && delay
) {
2735 phba
->fc_stat
.elsDelayRetry
++;
2736 ndlp
->nlp_retry
= cmdiocb
->retry
;
2738 /* delay is specified in milliseconds */
2739 mod_timer(&ndlp
->nlp_delayfunc
,
2740 jiffies
+ msecs_to_jiffies(delay
));
2741 spin_lock_irq(shost
->host_lock
);
2742 ndlp
->nlp_flag
|= NLP_DELAY_TMO
;
2743 spin_unlock_irq(shost
->host_lock
);
2745 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
2746 if (cmd
== ELS_CMD_PRLI
)
2747 lpfc_nlp_set_state(vport
, ndlp
,
2748 NLP_STE_REG_LOGIN_ISSUE
);
2750 lpfc_nlp_set_state(vport
, ndlp
,
2752 ndlp
->nlp_last_elscmd
= cmd
;
2758 lpfc_issue_els_flogi(vport
, ndlp
, cmdiocb
->retry
);
2761 lpfc_issue_els_fdisc(vport
, ndlp
, cmdiocb
->retry
);
2764 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
)) {
2765 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
2766 lpfc_nlp_set_state(vport
, ndlp
,
2767 NLP_STE_PLOGI_ISSUE
);
2769 lpfc_issue_els_plogi(vport
, did
, cmdiocb
->retry
);
2772 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
2773 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_ADISC_ISSUE
);
2774 lpfc_issue_els_adisc(vport
, ndlp
, cmdiocb
->retry
);
2777 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
2778 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PRLI_ISSUE
);
2779 lpfc_issue_els_prli(vport
, ndlp
, cmdiocb
->retry
);
2782 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
2783 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
2784 lpfc_issue_els_logo(vport
, ndlp
, cmdiocb
->retry
);
2788 /* No retry ELS command <elsCmd> to remote NPORT <did> */
2790 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
2791 "0137 No retry ELS command x%x to remote "
2792 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
2793 cmd
, did
, irsp
->ulpStatus
,
2794 irsp
->un
.ulpWord
[4]);
2797 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
2798 "0108 No retry ELS command x%x to remote "
2799 "NPORT x%x Retried:%d Error:x%x/%x\n",
2800 cmd
, did
, cmdiocb
->retry
, irsp
->ulpStatus
,
2801 irsp
->un
.ulpWord
[4]);
2807 * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
2808 * @phba: pointer to lpfc hba data structure.
2809 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
2811 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
2812 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
2813 * checks to see whether there is a lpfc DMA buffer associated with the
2814 * response of the command IOCB. If so, it will be released before releasing
2815 * the lpfc DMA buffer associated with the IOCB itself.
2818 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
2821 lpfc_els_free_data(struct lpfc_hba
*phba
, struct lpfc_dmabuf
*buf_ptr1
)
2823 struct lpfc_dmabuf
*buf_ptr
;
2825 /* Free the response before processing the command. */
2826 if (!list_empty(&buf_ptr1
->list
)) {
2827 list_remove_head(&buf_ptr1
->list
, buf_ptr
,
2830 lpfc_mbuf_free(phba
, buf_ptr
->virt
, buf_ptr
->phys
);
2833 lpfc_mbuf_free(phba
, buf_ptr1
->virt
, buf_ptr1
->phys
);
2839 * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
2840 * @phba: pointer to lpfc hba data structure.
2841 * @buf_ptr: pointer to the lpfc dma buffer data structure.
2843 * This routine releases the lpfc Direct Memory Access (DMA) buffer
2844 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
2848 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
2851 lpfc_els_free_bpl(struct lpfc_hba
*phba
, struct lpfc_dmabuf
*buf_ptr
)
2853 lpfc_mbuf_free(phba
, buf_ptr
->virt
, buf_ptr
->phys
);
2859 * lpfc_els_free_iocb - Free a command iocb and its associated resources
2860 * @phba: pointer to lpfc hba data structure.
2861 * @elsiocb: pointer to lpfc els command iocb data structure.
2863 * This routine frees a command IOCB and its associated resources. The
2864 * command IOCB data structure contains the reference to various associated
2865 * resources, these fields must be set to NULL if the associated reference
2867 * context1 - reference to ndlp
2868 * context2 - reference to cmd
2869 * context2->next - reference to rsp
2870 * context3 - reference to bpl
2872 * It first properly decrements the reference count held on ndlp for the
2873 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
2874 * set, it invokes the lpfc_els_free_data() routine to release the Direct
2875 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
2876 * adds the DMA buffer the @phba data structure for the delayed release.
2877 * If reference to the Buffer Pointer List (BPL) is present, the
2878 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
2879 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
2880 * invoked to release the IOCB data structure back to @phba IOCBQ list.
2883 * 0 - Success (currently, always return 0)
2886 lpfc_els_free_iocb(struct lpfc_hba
*phba
, struct lpfc_iocbq
*elsiocb
)
2888 struct lpfc_dmabuf
*buf_ptr
, *buf_ptr1
;
2889 struct lpfc_nodelist
*ndlp
;
2891 ndlp
= (struct lpfc_nodelist
*)elsiocb
->context1
;
2893 if (ndlp
->nlp_flag
& NLP_DEFER_RM
) {
2896 /* If the ndlp is not being used by another discovery
2899 if (!lpfc_nlp_not_used(ndlp
)) {
2900 /* If ndlp is being used by another discovery
2901 * thread, just clear NLP_DEFER_RM
2903 ndlp
->nlp_flag
&= ~NLP_DEFER_RM
;
2908 elsiocb
->context1
= NULL
;
2910 /* context2 = cmd, context2->next = rsp, context3 = bpl */
2911 if (elsiocb
->context2
) {
2912 if (elsiocb
->iocb_flag
& LPFC_DELAY_MEM_FREE
) {
2913 /* Firmware could still be in progress of DMAing
2914 * payload, so don't free data buffer till after
2917 elsiocb
->iocb_flag
&= ~LPFC_DELAY_MEM_FREE
;
2918 buf_ptr
= elsiocb
->context2
;
2919 elsiocb
->context2
= NULL
;
2922 spin_lock_irq(&phba
->hbalock
);
2923 if (!list_empty(&buf_ptr
->list
)) {
2924 list_remove_head(&buf_ptr
->list
,
2925 buf_ptr1
, struct lpfc_dmabuf
,
2927 INIT_LIST_HEAD(&buf_ptr1
->list
);
2928 list_add_tail(&buf_ptr1
->list
,
2932 INIT_LIST_HEAD(&buf_ptr
->list
);
2933 list_add_tail(&buf_ptr
->list
, &phba
->elsbuf
);
2935 spin_unlock_irq(&phba
->hbalock
);
2938 buf_ptr1
= (struct lpfc_dmabuf
*) elsiocb
->context2
;
2939 lpfc_els_free_data(phba
, buf_ptr1
);
2943 if (elsiocb
->context3
) {
2944 buf_ptr
= (struct lpfc_dmabuf
*) elsiocb
->context3
;
2945 lpfc_els_free_bpl(phba
, buf_ptr
);
2947 lpfc_sli_release_iocbq(phba
, elsiocb
);
2952 * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
2953 * @phba: pointer to lpfc hba data structure.
2954 * @cmdiocb: pointer to lpfc command iocb data structure.
2955 * @rspiocb: pointer to lpfc response iocb data structure.
2957 * This routine is the completion callback function to the Logout (LOGO)
2958 * Accept (ACC) Response ELS command. This routine is invoked to indicate
2959 * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
2960 * release the ndlp if it has the last reference remaining (reference count
2961 * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
2962 * field to NULL to inform the following lpfc_els_free_iocb() routine no
2963 * ndlp reference count needs to be decremented. Otherwise, the ndlp
2964 * reference use-count shall be decremented by the lpfc_els_free_iocb()
2965 * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
2966 * IOCB data structure.
2969 lpfc_cmpl_els_logo_acc(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
2970 struct lpfc_iocbq
*rspiocb
)
2972 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) cmdiocb
->context1
;
2973 struct lpfc_vport
*vport
= cmdiocb
->vport
;
2976 irsp
= &rspiocb
->iocb
;
2977 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
2978 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
2979 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4], ndlp
->nlp_DID
);
2980 /* ACC to LOGO completes to NPort <nlp_DID> */
2981 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
2982 "0109 ACC to LOGO completes to NPort x%x "
2983 "Data: x%x x%x x%x\n",
2984 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
2987 if (ndlp
->nlp_state
== NLP_STE_NPR_NODE
) {
2988 /* NPort Recovery mode or node is just allocated */
2989 if (!lpfc_nlp_not_used(ndlp
)) {
2990 /* If the ndlp is being used by another discovery
2991 * thread, just unregister the RPI.
2993 lpfc_unreg_rpi(vport
, ndlp
);
2995 /* Indicate the node has already released, should
2996 * not reference to it from within lpfc_els_free_iocb.
2998 cmdiocb
->context1
= NULL
;
3001 lpfc_els_free_iocb(phba
, cmdiocb
);
3006 * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
3007 * @phba: pointer to lpfc hba data structure.
3008 * @pmb: pointer to the driver internal queue element for mailbox command.
3010 * This routine is the completion callback function for unregister default
3011 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
3012 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
3013 * decrements the ndlp reference count held for this completion callback
3014 * function. After that, it invokes the lpfc_nlp_not_used() to check
3015 * whether there is only one reference left on the ndlp. If so, it will
3016 * perform one more decrement and trigger the release of the ndlp.
3019 lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
3021 struct lpfc_dmabuf
*mp
= (struct lpfc_dmabuf
*) (pmb
->context1
);
3022 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) pmb
->context2
;
3025 * This routine is used to register and unregister in previous SLI
3028 if ((pmb
->u
.mb
.mbxCommand
== MBX_UNREG_LOGIN
) &&
3029 (phba
->sli_rev
== LPFC_SLI_REV4
))
3030 lpfc_sli4_free_rpi(phba
, pmb
->u
.mb
.un
.varUnregLogin
.rpi
);
3032 pmb
->context1
= NULL
;
3033 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
3035 mempool_free(pmb
, phba
->mbox_mem_pool
);
3036 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
)) {
3038 /* This is the end of the default RPI cleanup logic for this
3039 * ndlp. If no other discovery threads are using this ndlp.
3040 * we should free all resources associated with it.
3042 lpfc_nlp_not_used(ndlp
);
3049 * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
3050 * @phba: pointer to lpfc hba data structure.
3051 * @cmdiocb: pointer to lpfc command iocb data structure.
3052 * @rspiocb: pointer to lpfc response iocb data structure.
3054 * This routine is the completion callback function for ELS Response IOCB
3055 * command. In normal case, this callback function just properly sets the
3056 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
3057 * field in the command IOCB is not NULL, the referred mailbox command will
3058 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
3059 * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
3060 * link down event occurred during the discovery, the lpfc_nlp_not_used()
3061 * routine shall be invoked trying to release the ndlp if no other threads
3062 * are currently referring it.
3065 lpfc_cmpl_els_rsp(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
3066 struct lpfc_iocbq
*rspiocb
)
3068 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) cmdiocb
->context1
;
3069 struct lpfc_vport
*vport
= ndlp
? ndlp
->vport
: NULL
;
3070 struct Scsi_Host
*shost
= vport
? lpfc_shost_from_vport(vport
) : NULL
;
3073 LPFC_MBOXQ_t
*mbox
= NULL
;
3074 struct lpfc_dmabuf
*mp
= NULL
;
3075 uint32_t ls_rjt
= 0;
3077 irsp
= &rspiocb
->iocb
;
3079 if (cmdiocb
->context_un
.mbox
)
3080 mbox
= cmdiocb
->context_un
.mbox
;
3082 /* First determine if this is a LS_RJT cmpl. Note, this callback
3083 * function can have cmdiocb->contest1 (ndlp) field set to NULL.
3085 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) cmdiocb
->context2
)->virt
);
3086 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
) &&
3087 (*((uint32_t *) (pcmd
)) == ELS_CMD_LS_RJT
)) {
3088 /* A LS_RJT associated with Default RPI cleanup has its own
3089 * seperate code path.
3091 if (!(ndlp
->nlp_flag
& NLP_RM_DFLT_RPI
))
3095 /* Check to see if link went down during discovery */
3096 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
) || lpfc_els_chk_latt(vport
)) {
3098 mp
= (struct lpfc_dmabuf
*) mbox
->context1
;
3100 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
3103 mempool_free(mbox
, phba
->mbox_mem_pool
);
3105 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
) &&
3106 (ndlp
->nlp_flag
& NLP_RM_DFLT_RPI
))
3107 if (lpfc_nlp_not_used(ndlp
)) {
3109 /* Indicate the node has already released,
3110 * should not reference to it from within
3111 * the routine lpfc_els_free_iocb.
3113 cmdiocb
->context1
= NULL
;
3118 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
3119 "ELS rsp cmpl: status:x%x/x%x did:x%x",
3120 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
3121 cmdiocb
->iocb
.un
.elsreq64
.remoteID
);
3122 /* ELS response tag <ulpIoTag> completes */
3123 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
3124 "0110 ELS response tag x%x completes "
3125 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
3126 cmdiocb
->iocb
.ulpIoTag
, rspiocb
->iocb
.ulpStatus
,
3127 rspiocb
->iocb
.un
.ulpWord
[4], rspiocb
->iocb
.ulpTimeout
,
3128 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
3131 if ((rspiocb
->iocb
.ulpStatus
== 0)
3132 && (ndlp
->nlp_flag
& NLP_ACC_REGLOGIN
)) {
3133 lpfc_unreg_rpi(vport
, ndlp
);
3134 /* Increment reference count to ndlp to hold the
3135 * reference to ndlp for the callback function.
3137 mbox
->context2
= lpfc_nlp_get(ndlp
);
3138 mbox
->vport
= vport
;
3139 if (ndlp
->nlp_flag
& NLP_RM_DFLT_RPI
) {
3140 mbox
->mbox_flag
|= LPFC_MBX_IMED_UNREG
;
3141 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_dflt_rpi
;
3144 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_reg_login
;
3145 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
3146 lpfc_nlp_set_state(vport
, ndlp
,
3147 NLP_STE_REG_LOGIN_ISSUE
);
3149 if (lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
)
3150 != MBX_NOT_FINISHED
)
3153 /* Decrement the ndlp reference count we
3154 * set for this failed mailbox command.
3158 /* ELS rsp: Cannot issue reg_login for <NPortid> */
3159 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
3160 "0138 ELS rsp: Cannot issue reg_login for x%x "
3161 "Data: x%x x%x x%x\n",
3162 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
3165 if (lpfc_nlp_not_used(ndlp
)) {
3167 /* Indicate node has already been released,
3168 * should not reference to it from within
3169 * the routine lpfc_els_free_iocb.
3171 cmdiocb
->context1
= NULL
;
3174 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
3175 if (!lpfc_error_lost_link(irsp
) &&
3176 ndlp
->nlp_flag
& NLP_ACC_REGLOGIN
) {
3177 if (lpfc_nlp_not_used(ndlp
)) {
3179 /* Indicate node has already been
3180 * released, should not reference
3181 * to it from within the routine
3182 * lpfc_els_free_iocb.
3184 cmdiocb
->context1
= NULL
;
3188 mp
= (struct lpfc_dmabuf
*) mbox
->context1
;
3190 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
3193 mempool_free(mbox
, phba
->mbox_mem_pool
);
3196 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
)) {
3197 spin_lock_irq(shost
->host_lock
);
3198 ndlp
->nlp_flag
&= ~(NLP_ACC_REGLOGIN
| NLP_RM_DFLT_RPI
);
3199 spin_unlock_irq(shost
->host_lock
);
3201 /* If the node is not being used by another discovery thread,
3202 * and we are sending a reject, we are done with it.
3203 * Release driver reference count here and free associated
3207 if (lpfc_nlp_not_used(ndlp
))
3208 /* Indicate node has already been released,
3209 * should not reference to it from within
3210 * the routine lpfc_els_free_iocb.
3212 cmdiocb
->context1
= NULL
;
3215 lpfc_els_free_iocb(phba
, cmdiocb
);
3220 * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
3221 * @vport: pointer to a host virtual N_Port data structure.
3222 * @flag: the els command code to be accepted.
3223 * @oldiocb: pointer to the original lpfc command iocb data structure.
3224 * @ndlp: pointer to a node-list data structure.
3225 * @mbox: pointer to the driver internal queue element for mailbox command.
3227 * This routine prepares and issues an Accept (ACC) response IOCB
3228 * command. It uses the @flag to properly set up the IOCB field for the
3229 * specific ACC response command to be issued and invokes the
3230 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
3231 * @mbox pointer is passed in, it will be put into the context_un.mbox
3232 * field of the IOCB for the completion callback function to issue the
3233 * mailbox command to the HBA later when callback is invoked.
3235 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3236 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3237 * will be stored into the context1 field of the IOCB for the completion
3238 * callback function to the corresponding response ELS IOCB command.
3241 * 0 - Successfully issued acc response
3242 * 1 - Failed to issue acc response
3245 lpfc_els_rsp_acc(struct lpfc_vport
*vport
, uint32_t flag
,
3246 struct lpfc_iocbq
*oldiocb
, struct lpfc_nodelist
*ndlp
,
3249 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
3250 struct lpfc_hba
*phba
= vport
->phba
;
3253 struct lpfc_iocbq
*elsiocb
;
3254 struct lpfc_sli
*psli
;
3258 ELS_PKT
*els_pkt_ptr
;
3261 oldcmd
= &oldiocb
->iocb
;
3265 cmdsize
= sizeof(uint32_t);
3266 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
,
3267 ndlp
, ndlp
->nlp_DID
, ELS_CMD_ACC
);
3269 spin_lock_irq(shost
->host_lock
);
3270 ndlp
->nlp_flag
&= ~NLP_LOGO_ACC
;
3271 spin_unlock_irq(shost
->host_lock
);
3275 icmd
= &elsiocb
->iocb
;
3276 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri */
3277 pcmd
= (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
3278 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
3279 pcmd
+= sizeof(uint32_t);
3281 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
3282 "Issue ACC: did:x%x flg:x%x",
3283 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
3286 cmdsize
= (sizeof(struct serv_parm
) + sizeof(uint32_t));
3287 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
,
3288 ndlp
, ndlp
->nlp_DID
, ELS_CMD_ACC
);
3292 icmd
= &elsiocb
->iocb
;
3293 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri */
3294 pcmd
= (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
3297 elsiocb
->context_un
.mbox
= mbox
;
3299 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
3300 pcmd
+= sizeof(uint32_t);
3301 memcpy(pcmd
, &vport
->fc_sparam
, sizeof(struct serv_parm
));
3303 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
3304 "Issue ACC PLOGI: did:x%x flg:x%x",
3305 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
3308 cmdsize
= sizeof(uint32_t) + sizeof(PRLO
);
3309 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
,
3310 ndlp
, ndlp
->nlp_DID
, ELS_CMD_PRLO
);
3314 icmd
= &elsiocb
->iocb
;
3315 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri */
3316 pcmd
= (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
3318 memcpy(pcmd
, ((struct lpfc_dmabuf
*) oldiocb
->context2
)->virt
,
3319 sizeof(uint32_t) + sizeof(PRLO
));
3320 *((uint32_t *) (pcmd
)) = ELS_CMD_PRLO_ACC
;
3321 els_pkt_ptr
= (ELS_PKT
*) pcmd
;
3322 els_pkt_ptr
->un
.prlo
.acceptRspCode
= PRLO_REQ_EXECUTED
;
3324 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
3325 "Issue ACC PRLO: did:x%x flg:x%x",
3326 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
3331 /* Xmit ELS ACC response tag <ulpIoTag> */
3332 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
3333 "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
3334 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n",
3335 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
,
3336 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
3338 if (ndlp
->nlp_flag
& NLP_LOGO_ACC
) {
3339 spin_lock_irq(shost
->host_lock
);
3340 ndlp
->nlp_flag
&= ~NLP_LOGO_ACC
;
3341 spin_unlock_irq(shost
->host_lock
);
3342 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_logo_acc
;
3344 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
3347 phba
->fc_stat
.elsXmitACC
++;
3348 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
3349 if (rc
== IOCB_ERROR
) {
3350 lpfc_els_free_iocb(phba
, elsiocb
);
3357 * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command
3358 * @vport: pointer to a virtual N_Port data structure.
3360 * @oldiocb: pointer to the original lpfc command iocb data structure.
3361 * @ndlp: pointer to a node-list data structure.
3362 * @mbox: pointer to the driver internal queue element for mailbox command.
3364 * This routine prepares and issue an Reject (RJT) response IOCB
3365 * command. If a @mbox pointer is passed in, it will be put into the
3366 * context_un.mbox field of the IOCB for the completion callback function
3367 * to issue to the HBA later.
3369 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3370 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3371 * will be stored into the context1 field of the IOCB for the completion
3372 * callback function to the reject response ELS IOCB command.
3375 * 0 - Successfully issued reject response
3376 * 1 - Failed to issue reject response
3379 lpfc_els_rsp_reject(struct lpfc_vport
*vport
, uint32_t rejectError
,
3380 struct lpfc_iocbq
*oldiocb
, struct lpfc_nodelist
*ndlp
,
3383 struct lpfc_hba
*phba
= vport
->phba
;
3386 struct lpfc_iocbq
*elsiocb
;
3387 struct lpfc_sli
*psli
;
3393 cmdsize
= 2 * sizeof(uint32_t);
3394 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
, ndlp
,
3395 ndlp
->nlp_DID
, ELS_CMD_LS_RJT
);
3399 icmd
= &elsiocb
->iocb
;
3400 oldcmd
= &oldiocb
->iocb
;
3401 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri */
3402 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
3404 *((uint32_t *) (pcmd
)) = ELS_CMD_LS_RJT
;
3405 pcmd
+= sizeof(uint32_t);
3406 *((uint32_t *) (pcmd
)) = rejectError
;
3409 elsiocb
->context_un
.mbox
= mbox
;
3411 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
3412 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
3413 "0129 Xmit ELS RJT x%x response tag x%x "
3414 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
3416 rejectError
, elsiocb
->iotag
,
3417 elsiocb
->iocb
.ulpContext
, ndlp
->nlp_DID
,
3418 ndlp
->nlp_flag
, ndlp
->nlp_state
, ndlp
->nlp_rpi
);
3419 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
3420 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
3421 ndlp
->nlp_DID
, ndlp
->nlp_flag
, rejectError
);
3423 phba
->fc_stat
.elsXmitLSRJT
++;
3424 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
3425 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
3427 if (rc
== IOCB_ERROR
) {
3428 lpfc_els_free_iocb(phba
, elsiocb
);
3435 * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
3436 * @vport: pointer to a virtual N_Port data structure.
3437 * @oldiocb: pointer to the original lpfc command iocb data structure.
3438 * @ndlp: pointer to a node-list data structure.
3440 * This routine prepares and issues an Accept (ACC) response to Address
3441 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
3442 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3444 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3445 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3446 * will be stored into the context1 field of the IOCB for the completion
3447 * callback function to the ADISC Accept response ELS IOCB command.
3450 * 0 - Successfully issued acc adisc response
3451 * 1 - Failed to issue adisc acc response
3454 lpfc_els_rsp_adisc_acc(struct lpfc_vport
*vport
, struct lpfc_iocbq
*oldiocb
,
3455 struct lpfc_nodelist
*ndlp
)
3457 struct lpfc_hba
*phba
= vport
->phba
;
3459 IOCB_t
*icmd
, *oldcmd
;
3460 struct lpfc_iocbq
*elsiocb
;
3465 cmdsize
= sizeof(uint32_t) + sizeof(ADISC
);
3466 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
, ndlp
,
3467 ndlp
->nlp_DID
, ELS_CMD_ACC
);
3471 icmd
= &elsiocb
->iocb
;
3472 oldcmd
= &oldiocb
->iocb
;
3473 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri */
3475 /* Xmit ADISC ACC response tag <ulpIoTag> */
3476 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
3477 "0130 Xmit ADISC ACC response iotag x%x xri: "
3478 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
3479 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
,
3480 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
3482 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
3484 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
3485 pcmd
+= sizeof(uint32_t);
3487 ap
= (ADISC
*) (pcmd
);
3488 ap
->hardAL_PA
= phba
->fc_pref_ALPA
;
3489 memcpy(&ap
->portName
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
3490 memcpy(&ap
->nodeName
, &vport
->fc_nodename
, sizeof(struct lpfc_name
));
3491 ap
->DID
= be32_to_cpu(vport
->fc_myDID
);
3493 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
3494 "Issue ACC ADISC: did:x%x flg:x%x",
3495 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
3497 phba
->fc_stat
.elsXmitACC
++;
3498 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
3499 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
3500 if (rc
== IOCB_ERROR
) {
3501 lpfc_els_free_iocb(phba
, elsiocb
);
3508 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
3509 * @vport: pointer to a virtual N_Port data structure.
3510 * @oldiocb: pointer to the original lpfc command iocb data structure.
3511 * @ndlp: pointer to a node-list data structure.
3513 * This routine prepares and issues an Accept (ACC) response to Process
3514 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
3515 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3517 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3518 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3519 * will be stored into the context1 field of the IOCB for the completion
3520 * callback function to the PRLI Accept response ELS IOCB command.
3523 * 0 - Successfully issued acc prli response
3524 * 1 - Failed to issue acc prli response
3527 lpfc_els_rsp_prli_acc(struct lpfc_vport
*vport
, struct lpfc_iocbq
*oldiocb
,
3528 struct lpfc_nodelist
*ndlp
)
3530 struct lpfc_hba
*phba
= vport
->phba
;
3535 struct lpfc_iocbq
*elsiocb
;
3536 struct lpfc_sli
*psli
;
3543 cmdsize
= sizeof(uint32_t) + sizeof(PRLI
);
3544 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
, ndlp
,
3545 ndlp
->nlp_DID
, (ELS_CMD_ACC
| (ELS_CMD_PRLI
& ~ELS_RSP_MASK
)));
3549 icmd
= &elsiocb
->iocb
;
3550 oldcmd
= &oldiocb
->iocb
;
3551 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri */
3552 /* Xmit PRLI ACC response tag <ulpIoTag> */
3553 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
3554 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
3555 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
3556 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
,
3557 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
3559 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
3561 *((uint32_t *) (pcmd
)) = (ELS_CMD_ACC
| (ELS_CMD_PRLI
& ~ELS_RSP_MASK
));
3562 pcmd
+= sizeof(uint32_t);
3564 /* For PRLI, remainder of payload is PRLI parameter page */
3565 memset(pcmd
, 0, sizeof(PRLI
));
3567 npr
= (PRLI
*) pcmd
;
3570 * If the remote port is a target and our firmware version is 3.20 or
3571 * later, set the following bits for FC-TAPE support.
3573 if ((ndlp
->nlp_type
& NLP_FCP_TARGET
) &&
3574 (vpd
->rev
.feaLevelHigh
>= 0x02)) {
3575 npr
->ConfmComplAllowed
= 1;
3577 npr
->TaskRetryIdReq
= 1;
3580 npr
->acceptRspCode
= PRLI_REQ_EXECUTED
;
3581 npr
->estabImagePair
= 1;
3582 npr
->readXferRdyDis
= 1;
3583 npr
->ConfmComplAllowed
= 1;
3585 npr
->prliType
= PRLI_FCP_TYPE
;
3586 npr
->initiatorFunc
= 1;
3588 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
3589 "Issue ACC PRLI: did:x%x flg:x%x",
3590 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
3592 phba
->fc_stat
.elsXmitACC
++;
3593 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
3595 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
3596 if (rc
== IOCB_ERROR
) {
3597 lpfc_els_free_iocb(phba
, elsiocb
);
3604 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
3605 * @vport: pointer to a virtual N_Port data structure.
3606 * @format: rnid command format.
3607 * @oldiocb: pointer to the original lpfc command iocb data structure.
3608 * @ndlp: pointer to a node-list data structure.
3610 * This routine issues a Request Node Identification Data (RNID) Accept
3611 * (ACC) response. It constructs the RNID ACC response command according to
3612 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
3613 * issue the response. Note that this command does not need to hold the ndlp
3614 * reference count for the callback. So, the ndlp reference count taken by
3615 * the lpfc_prep_els_iocb() routine is put back and the context1 field of
3616 * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
3617 * there is no ndlp reference available.
3619 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3620 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3621 * will be stored into the context1 field of the IOCB for the completion
3622 * callback function. However, for the RNID Accept Response ELS command,
3623 * this is undone later by this routine after the IOCB is allocated.
3626 * 0 - Successfully issued acc rnid response
3627 * 1 - Failed to issue acc rnid response
3630 lpfc_els_rsp_rnid_acc(struct lpfc_vport
*vport
, uint8_t format
,
3631 struct lpfc_iocbq
*oldiocb
, struct lpfc_nodelist
*ndlp
)
3633 struct lpfc_hba
*phba
= vport
->phba
;
3635 IOCB_t
*icmd
, *oldcmd
;
3636 struct lpfc_iocbq
*elsiocb
;
3637 struct lpfc_sli
*psli
;
3643 cmdsize
= sizeof(uint32_t) + sizeof(uint32_t)
3644 + (2 * sizeof(struct lpfc_name
));
3646 cmdsize
+= sizeof(RNID_TOP_DISC
);
3648 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
, ndlp
,
3649 ndlp
->nlp_DID
, ELS_CMD_ACC
);
3653 icmd
= &elsiocb
->iocb
;
3654 oldcmd
= &oldiocb
->iocb
;
3655 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri */
3656 /* Xmit RNID ACC response tag <ulpIoTag> */
3657 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
3658 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
3659 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
);
3660 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
3661 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
3662 pcmd
+= sizeof(uint32_t);
3664 memset(pcmd
, 0, sizeof(RNID
));
3665 rn
= (RNID
*) (pcmd
);
3666 rn
->Format
= format
;
3667 rn
->CommonLen
= (2 * sizeof(struct lpfc_name
));
3668 memcpy(&rn
->portName
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
3669 memcpy(&rn
->nodeName
, &vport
->fc_nodename
, sizeof(struct lpfc_name
));
3672 rn
->SpecificLen
= 0;
3674 case RNID_TOPOLOGY_DISC
:
3675 rn
->SpecificLen
= sizeof(RNID_TOP_DISC
);
3676 memcpy(&rn
->un
.topologyDisc
.portName
,
3677 &vport
->fc_portname
, sizeof(struct lpfc_name
));
3678 rn
->un
.topologyDisc
.unitType
= RNID_HBA
;
3679 rn
->un
.topologyDisc
.physPort
= 0;
3680 rn
->un
.topologyDisc
.attachedNodes
= 0;
3684 rn
->SpecificLen
= 0;
3688 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
3689 "Issue ACC RNID: did:x%x flg:x%x",
3690 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
3692 phba
->fc_stat
.elsXmitACC
++;
3693 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
3695 elsiocb
->context1
= NULL
; /* Don't need ndlp for cmpl,
3696 * it could be freed */
3698 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
3699 if (rc
== IOCB_ERROR
) {
3700 lpfc_els_free_iocb(phba
, elsiocb
);
3707 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
3708 * @vport: pointer to a host virtual N_Port data structure.
3710 * This routine issues Address Discover (ADISC) ELS commands to those
3711 * N_Ports which are in node port recovery state and ADISC has not been issued
3712 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
3713 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
3714 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
3715 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
3716 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
3717 * IOCBs quit for later pick up. On the other hand, after walking through
3718 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
3719 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
3720 * no more ADISC need to be sent.
3723 * The number of N_Ports with adisc issued.
3726 lpfc_els_disc_adisc(struct lpfc_vport
*vport
)
3728 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
3729 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
3732 /* go thru NPR nodes and issue any remaining ELS ADISCs */
3733 list_for_each_entry_safe(ndlp
, next_ndlp
, &vport
->fc_nodes
, nlp_listp
) {
3734 if (!NLP_CHK_NODE_ACT(ndlp
))
3736 if (ndlp
->nlp_state
== NLP_STE_NPR_NODE
&&
3737 (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
) != 0 &&
3738 (ndlp
->nlp_flag
& NLP_NPR_ADISC
) != 0) {
3739 spin_lock_irq(shost
->host_lock
);
3740 ndlp
->nlp_flag
&= ~NLP_NPR_ADISC
;
3741 spin_unlock_irq(shost
->host_lock
);
3742 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
3743 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_ADISC_ISSUE
);
3744 lpfc_issue_els_adisc(vport
, ndlp
, 0);
3746 vport
->num_disc_nodes
++;
3747 if (vport
->num_disc_nodes
>=
3748 vport
->cfg_discovery_threads
) {
3749 spin_lock_irq(shost
->host_lock
);
3750 vport
->fc_flag
|= FC_NLP_MORE
;
3751 spin_unlock_irq(shost
->host_lock
);
3756 if (sentadisc
== 0) {
3757 spin_lock_irq(shost
->host_lock
);
3758 vport
->fc_flag
&= ~FC_NLP_MORE
;
3759 spin_unlock_irq(shost
->host_lock
);
3765 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
3766 * @vport: pointer to a host virtual N_Port data structure.
3768 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
3769 * which are in node port recovery state, with a @vport. Each time an ELS
3770 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
3771 * the per @vport number of discover count (num_disc_nodes) shall be
3772 * incremented. If the num_disc_nodes reaches a pre-configured threshold
3773 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
3774 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
3775 * later pick up. On the other hand, after walking through all the ndlps with
3776 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
3777 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
3778 * PLOGI need to be sent.
3781 * The number of N_Ports with plogi issued.
3784 lpfc_els_disc_plogi(struct lpfc_vport
*vport
)
3786 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
3787 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
3790 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
3791 list_for_each_entry_safe(ndlp
, next_ndlp
, &vport
->fc_nodes
, nlp_listp
) {
3792 if (!NLP_CHK_NODE_ACT(ndlp
))
3794 if (ndlp
->nlp_state
== NLP_STE_NPR_NODE
&&
3795 (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
) != 0 &&
3796 (ndlp
->nlp_flag
& NLP_DELAY_TMO
) == 0 &&
3797 (ndlp
->nlp_flag
& NLP_NPR_ADISC
) == 0) {
3798 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
3799 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
3800 lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, 0);
3802 vport
->num_disc_nodes
++;
3803 if (vport
->num_disc_nodes
>=
3804 vport
->cfg_discovery_threads
) {
3805 spin_lock_irq(shost
->host_lock
);
3806 vport
->fc_flag
|= FC_NLP_MORE
;
3807 spin_unlock_irq(shost
->host_lock
);
3813 lpfc_set_disctmo(vport
);
3816 spin_lock_irq(shost
->host_lock
);
3817 vport
->fc_flag
&= ~FC_NLP_MORE
;
3818 spin_unlock_irq(shost
->host_lock
);
3824 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
3825 * @vport: pointer to a host virtual N_Port data structure.
3827 * This routine cleans up any Registration State Change Notification
3828 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
3829 * @vport together with the host_lock is used to prevent multiple thread
3830 * trying to access the RSCN array on a same @vport at the same time.
3833 lpfc_els_flush_rscn(struct lpfc_vport
*vport
)
3835 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
3836 struct lpfc_hba
*phba
= vport
->phba
;
3839 spin_lock_irq(shost
->host_lock
);
3840 if (vport
->fc_rscn_flush
) {
3841 /* Another thread is walking fc_rscn_id_list on this vport */
3842 spin_unlock_irq(shost
->host_lock
);
3845 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
3846 vport
->fc_rscn_flush
= 1;
3847 spin_unlock_irq(shost
->host_lock
);
3849 for (i
= 0; i
< vport
->fc_rscn_id_cnt
; i
++) {
3850 lpfc_in_buf_free(phba
, vport
->fc_rscn_id_list
[i
]);
3851 vport
->fc_rscn_id_list
[i
] = NULL
;
3853 spin_lock_irq(shost
->host_lock
);
3854 vport
->fc_rscn_id_cnt
= 0;
3855 vport
->fc_flag
&= ~(FC_RSCN_MODE
| FC_RSCN_DISCOVERY
);
3856 spin_unlock_irq(shost
->host_lock
);
3857 lpfc_can_disctmo(vport
);
3858 /* Indicate we are done walking this fc_rscn_id_list */
3859 vport
->fc_rscn_flush
= 0;
3863 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
3864 * @vport: pointer to a host virtual N_Port data structure.
3865 * @did: remote destination port identifier.
3867 * This routine checks whether there is any pending Registration State
3868 * Configuration Notification (RSCN) to a @did on @vport.
3871 * None zero - The @did matched with a pending rscn
3872 * 0 - not able to match @did with a pending rscn
3875 lpfc_rscn_payload_check(struct lpfc_vport
*vport
, uint32_t did
)
3880 uint32_t payload_len
, i
;
3881 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
3883 ns_did
.un
.word
= did
;
3885 /* Never match fabric nodes for RSCNs */
3886 if ((did
& Fabric_DID_MASK
) == Fabric_DID_MASK
)
3889 /* If we are doing a FULL RSCN rediscovery, match everything */
3890 if (vport
->fc_flag
& FC_RSCN_DISCOVERY
)
3893 spin_lock_irq(shost
->host_lock
);
3894 if (vport
->fc_rscn_flush
) {
3895 /* Another thread is walking fc_rscn_id_list on this vport */
3896 spin_unlock_irq(shost
->host_lock
);
3899 /* Indicate we are walking fc_rscn_id_list on this vport */
3900 vport
->fc_rscn_flush
= 1;
3901 spin_unlock_irq(shost
->host_lock
);
3902 for (i
= 0; i
< vport
->fc_rscn_id_cnt
; i
++) {
3903 lp
= vport
->fc_rscn_id_list
[i
]->virt
;
3904 payload_len
= be32_to_cpu(*lp
++ & ~ELS_CMD_MASK
);
3905 payload_len
-= sizeof(uint32_t); /* take off word 0 */
3906 while (payload_len
) {
3907 rscn_did
.un
.word
= be32_to_cpu(*lp
++);
3908 payload_len
-= sizeof(uint32_t);
3909 switch (rscn_did
.un
.b
.resv
& RSCN_ADDRESS_FORMAT_MASK
) {
3910 case RSCN_ADDRESS_FORMAT_PORT
:
3911 if ((ns_did
.un
.b
.domain
== rscn_did
.un
.b
.domain
)
3912 && (ns_did
.un
.b
.area
== rscn_did
.un
.b
.area
)
3913 && (ns_did
.un
.b
.id
== rscn_did
.un
.b
.id
))
3914 goto return_did_out
;
3916 case RSCN_ADDRESS_FORMAT_AREA
:
3917 if ((ns_did
.un
.b
.domain
== rscn_did
.un
.b
.domain
)
3918 && (ns_did
.un
.b
.area
== rscn_did
.un
.b
.area
))
3919 goto return_did_out
;
3921 case RSCN_ADDRESS_FORMAT_DOMAIN
:
3922 if (ns_did
.un
.b
.domain
== rscn_did
.un
.b
.domain
)
3923 goto return_did_out
;
3925 case RSCN_ADDRESS_FORMAT_FABRIC
:
3926 goto return_did_out
;
3930 /* Indicate we are done with walking fc_rscn_id_list on this vport */
3931 vport
->fc_rscn_flush
= 0;
3934 /* Indicate we are done with walking fc_rscn_id_list on this vport */
3935 vport
->fc_rscn_flush
= 0;
3940 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
3941 * @vport: pointer to a host virtual N_Port data structure.
3943 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
3944 * state machine for a @vport's nodes that are with pending RSCN (Registration
3945 * State Change Notification).
3948 * 0 - Successful (currently alway return 0)
3951 lpfc_rscn_recovery_check(struct lpfc_vport
*vport
)
3953 struct lpfc_nodelist
*ndlp
= NULL
;
3955 /* Move all affected nodes by pending RSCNs to NPR state. */
3956 list_for_each_entry(ndlp
, &vport
->fc_nodes
, nlp_listp
) {
3957 if (!NLP_CHK_NODE_ACT(ndlp
) ||
3958 (ndlp
->nlp_state
== NLP_STE_UNUSED_NODE
) ||
3959 !lpfc_rscn_payload_check(vport
, ndlp
->nlp_DID
))
3961 lpfc_disc_state_machine(vport
, ndlp
, NULL
,
3962 NLP_EVT_DEVICE_RECOVERY
);
3963 lpfc_cancel_retry_delay_tmo(vport
, ndlp
);
3969 * lpfc_send_rscn_event - Send an RSCN event to management application
3970 * @vport: pointer to a host virtual N_Port data structure.
3971 * @cmdiocb: pointer to lpfc command iocb data structure.
3973 * lpfc_send_rscn_event sends an RSCN netlink event to management
3977 lpfc_send_rscn_event(struct lpfc_vport
*vport
,
3978 struct lpfc_iocbq
*cmdiocb
)
3980 struct lpfc_dmabuf
*pcmd
;
3981 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
3982 uint32_t *payload_ptr
;
3983 uint32_t payload_len
;
3984 struct lpfc_rscn_event_header
*rscn_event_data
;
3986 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
3987 payload_ptr
= (uint32_t *) pcmd
->virt
;
3988 payload_len
= be32_to_cpu(*payload_ptr
& ~ELS_CMD_MASK
);
3990 rscn_event_data
= kmalloc(sizeof(struct lpfc_rscn_event_header
) +
3991 payload_len
, GFP_KERNEL
);
3992 if (!rscn_event_data
) {
3993 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
3994 "0147 Failed to allocate memory for RSCN event\n");
3997 rscn_event_data
->event_type
= FC_REG_RSCN_EVENT
;
3998 rscn_event_data
->payload_length
= payload_len
;
3999 memcpy(rscn_event_data
->rscn_payload
, payload_ptr
,
4002 fc_host_post_vendor_event(shost
,
4003 fc_get_event_number(),
4004 sizeof(struct lpfc_els_event_header
) + payload_len
,
4005 (char *)rscn_event_data
,
4008 kfree(rscn_event_data
);
4012 * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
4013 * @vport: pointer to a host virtual N_Port data structure.
4014 * @cmdiocb: pointer to lpfc command iocb data structure.
4015 * @ndlp: pointer to a node-list data structure.
4017 * This routine processes an unsolicited RSCN (Registration State Change
4018 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
4019 * to invoke fc_host_post_event() routine to the FC transport layer. If the
4020 * discover state machine is about to begin discovery, it just accepts the
4021 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
4022 * contains N_Port IDs for other vports on this HBA, it just accepts the
4023 * RSCN and ignore processing it. If the state machine is in the recovery
4024 * state, the fc_rscn_id_list of this @vport is walked and the
4025 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
4026 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
4027 * routine is invoked to handle the RSCN event.
4030 * 0 - Just sent the acc response
4031 * 1 - Sent the acc response and waited for name server completion
4034 lpfc_els_rcv_rscn(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
4035 struct lpfc_nodelist
*ndlp
)
4037 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4038 struct lpfc_hba
*phba
= vport
->phba
;
4039 struct lpfc_dmabuf
*pcmd
;
4040 uint32_t *lp
, *datap
;
4042 uint32_t payload_len
, length
, nportid
, *cmd
;
4044 int rscn_id
= 0, hba_id
= 0;
4047 icmd
= &cmdiocb
->iocb
;
4048 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
4049 lp
= (uint32_t *) pcmd
->virt
;
4051 payload_len
= be32_to_cpu(*lp
++ & ~ELS_CMD_MASK
);
4052 payload_len
-= sizeof(uint32_t); /* take off word 0 */
4054 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
4055 "0214 RSCN received Data: x%x x%x x%x x%x\n",
4056 vport
->fc_flag
, payload_len
, *lp
,
4057 vport
->fc_rscn_id_cnt
);
4059 /* Send an RSCN event to the management application */
4060 lpfc_send_rscn_event(vport
, cmdiocb
);
4062 for (i
= 0; i
< payload_len
/sizeof(uint32_t); i
++)
4063 fc_host_post_event(shost
, fc_get_event_number(),
4064 FCH_EVT_RSCN
, lp
[i
]);
4066 /* If we are about to begin discovery, just ACC the RSCN.
4067 * Discovery processing will satisfy it.
4069 if (vport
->port_state
<= LPFC_NS_QRY
) {
4070 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
4071 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
4072 ndlp
->nlp_DID
, vport
->port_state
, ndlp
->nlp_flag
);
4074 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
4078 /* If this RSCN just contains NPortIDs for other vports on this HBA,
4079 * just ACC and ignore it.
4081 if ((phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
4082 !(vport
->cfg_peer_port_login
)) {
4087 nportid
= ((be32_to_cpu(nportid
)) & Mask_DID
);
4088 i
-= sizeof(uint32_t);
4090 if (lpfc_find_vport_by_did(phba
, nportid
))
4093 if (rscn_id
== hba_id
) {
4094 /* ALL NPortIDs in RSCN are on HBA */
4095 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
4097 "Data: x%x x%x x%x x%x\n",
4098 vport
->fc_flag
, payload_len
,
4099 *lp
, vport
->fc_rscn_id_cnt
);
4100 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
4101 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
4102 ndlp
->nlp_DID
, vport
->port_state
,
4105 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
,
4111 spin_lock_irq(shost
->host_lock
);
4112 if (vport
->fc_rscn_flush
) {
4113 /* Another thread is walking fc_rscn_id_list on this vport */
4114 spin_unlock_irq(shost
->host_lock
);
4115 vport
->fc_flag
|= FC_RSCN_DISCOVERY
;
4117 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
4120 /* Indicate we are walking fc_rscn_id_list on this vport */
4121 vport
->fc_rscn_flush
= 1;
4122 spin_unlock_irq(shost
->host_lock
);
4123 /* Get the array count after sucessfully have the token */
4124 rscn_cnt
= vport
->fc_rscn_id_cnt
;
4125 /* If we are already processing an RSCN, save the received
4126 * RSCN payload buffer, cmdiocb->context2 to process later.
4128 if (vport
->fc_flag
& (FC_RSCN_MODE
| FC_NDISC_ACTIVE
)) {
4129 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
4130 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
4131 ndlp
->nlp_DID
, vport
->port_state
, ndlp
->nlp_flag
);
4133 spin_lock_irq(shost
->host_lock
);
4134 vport
->fc_flag
|= FC_RSCN_DEFERRED
;
4135 if ((rscn_cnt
< FC_MAX_HOLD_RSCN
) &&
4136 !(vport
->fc_flag
& FC_RSCN_DISCOVERY
)) {
4137 vport
->fc_flag
|= FC_RSCN_MODE
;
4138 spin_unlock_irq(shost
->host_lock
);
4140 cmd
= vport
->fc_rscn_id_list
[rscn_cnt
-1]->virt
;
4141 length
= be32_to_cpu(*cmd
& ~ELS_CMD_MASK
);
4144 (payload_len
+ length
<= LPFC_BPL_SIZE
)) {
4145 *cmd
&= ELS_CMD_MASK
;
4146 *cmd
|= cpu_to_be32(payload_len
+ length
);
4147 memcpy(((uint8_t *)cmd
) + length
, lp
,
4150 vport
->fc_rscn_id_list
[rscn_cnt
] = pcmd
;
4151 vport
->fc_rscn_id_cnt
++;
4152 /* If we zero, cmdiocb->context2, the calling
4153 * routine will not try to free it.
4155 cmdiocb
->context2
= NULL
;
4158 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
4159 "0235 Deferred RSCN "
4160 "Data: x%x x%x x%x\n",
4161 vport
->fc_rscn_id_cnt
, vport
->fc_flag
,
4164 vport
->fc_flag
|= FC_RSCN_DISCOVERY
;
4165 spin_unlock_irq(shost
->host_lock
);
4166 /* ReDiscovery RSCN */
4167 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
4168 "0234 ReDiscovery RSCN "
4169 "Data: x%x x%x x%x\n",
4170 vport
->fc_rscn_id_cnt
, vport
->fc_flag
,
4173 /* Indicate we are done walking fc_rscn_id_list on this vport */
4174 vport
->fc_rscn_flush
= 0;
4176 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
4177 /* send RECOVERY event for ALL nodes that match RSCN payload */
4178 lpfc_rscn_recovery_check(vport
);
4179 spin_lock_irq(shost
->host_lock
);
4180 vport
->fc_flag
&= ~FC_RSCN_DEFERRED
;
4181 spin_unlock_irq(shost
->host_lock
);
4184 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
4185 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
4186 ndlp
->nlp_DID
, vport
->port_state
, ndlp
->nlp_flag
);
4188 spin_lock_irq(shost
->host_lock
);
4189 vport
->fc_flag
|= FC_RSCN_MODE
;
4190 spin_unlock_irq(shost
->host_lock
);
4191 vport
->fc_rscn_id_list
[vport
->fc_rscn_id_cnt
++] = pcmd
;
4192 /* Indicate we are done walking fc_rscn_id_list on this vport */
4193 vport
->fc_rscn_flush
= 0;
4195 * If we zero, cmdiocb->context2, the calling routine will
4196 * not try to free it.
4198 cmdiocb
->context2
= NULL
;
4199 lpfc_set_disctmo(vport
);
4201 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
4202 /* send RECOVERY event for ALL nodes that match RSCN payload */
4203 lpfc_rscn_recovery_check(vport
);
4204 return lpfc_els_handle_rscn(vport
);
4208 * lpfc_els_handle_rscn - Handle rscn for a vport
4209 * @vport: pointer to a host virtual N_Port data structure.
4211 * This routine handles the Registration State Configuration Notification
4212 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
4213 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
4214 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
4215 * NameServer shall be issued. If CT command to the NameServer fails to be
4216 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
4217 * RSCN activities with the @vport.
4220 * 0 - Cleaned up rscn on the @vport
4221 * 1 - Wait for plogi to name server before proceed
4224 lpfc_els_handle_rscn(struct lpfc_vport
*vport
)
4226 struct lpfc_nodelist
*ndlp
;
4227 struct lpfc_hba
*phba
= vport
->phba
;
4229 /* Ignore RSCN if the port is being torn down. */
4230 if (vport
->load_flag
& FC_UNLOADING
) {
4231 lpfc_els_flush_rscn(vport
);
4235 /* Start timer for RSCN processing */
4236 lpfc_set_disctmo(vport
);
4238 /* RSCN processed */
4239 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
4240 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
4241 vport
->fc_flag
, 0, vport
->fc_rscn_id_cnt
,
4244 /* To process RSCN, first compare RSCN data with NameServer */
4245 vport
->fc_ns_retry
= 0;
4246 vport
->num_disc_nodes
= 0;
4248 ndlp
= lpfc_findnode_did(vport
, NameServer_DID
);
4249 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
)
4250 && ndlp
->nlp_state
== NLP_STE_UNMAPPED_NODE
) {
4251 /* Good ndlp, issue CT Request to NameServer */
4252 if (lpfc_ns_cmd(vport
, SLI_CTNS_GID_FT
, 0, 0) == 0)
4253 /* Wait for NameServer query cmpl before we can
4257 /* If login to NameServer does not exist, issue one */
4258 /* Good status, issue PLOGI to NameServer */
4259 ndlp
= lpfc_findnode_did(vport
, NameServer_DID
);
4260 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
))
4261 /* Wait for NameServer login cmpl before we can
4266 ndlp
= lpfc_enable_node(vport
, ndlp
,
4267 NLP_STE_PLOGI_ISSUE
);
4269 lpfc_els_flush_rscn(vport
);
4272 ndlp
->nlp_prev_state
= NLP_STE_UNUSED_NODE
;
4274 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
4276 lpfc_els_flush_rscn(vport
);
4279 lpfc_nlp_init(vport
, ndlp
, NameServer_DID
);
4280 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
4281 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
4283 ndlp
->nlp_type
|= NLP_FABRIC
;
4284 lpfc_issue_els_plogi(vport
, NameServer_DID
, 0);
4285 /* Wait for NameServer login cmpl before we can
4291 lpfc_els_flush_rscn(vport
);
4296 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
4297 * @vport: pointer to a host virtual N_Port data structure.
4298 * @cmdiocb: pointer to lpfc command iocb data structure.
4299 * @ndlp: pointer to a node-list data structure.
4301 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
4302 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
4303 * point topology. As an unsolicited FLOGI should not be received in a loop
4304 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
4305 * lpfc_check_sparm() routine is invoked to check the parameters in the
4306 * unsolicited FLOGI. If parameters validation failed, the routine
4307 * lpfc_els_rsp_reject() shall be called with reject reason code set to
4308 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
4309 * FLOGI shall be compared with the Port WWN of the @vport to determine who
4310 * will initiate PLOGI. The higher lexicographical value party shall has
4311 * higher priority (as the winning port) and will initiate PLOGI and
4312 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
4313 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
4314 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
4317 * 0 - Successfully processed the unsolicited flogi
4318 * 1 - Failed to process the unsolicited flogi
4321 lpfc_els_rcv_flogi(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
4322 struct lpfc_nodelist
*ndlp
)
4324 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4325 struct lpfc_hba
*phba
= vport
->phba
;
4326 struct lpfc_dmabuf
*pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
4327 uint32_t *lp
= (uint32_t *) pcmd
->virt
;
4328 IOCB_t
*icmd
= &cmdiocb
->iocb
;
4329 struct serv_parm
*sp
;
4336 sp
= (struct serv_parm
*) lp
;
4338 /* FLOGI received */
4340 lpfc_set_disctmo(vport
);
4342 if (phba
->fc_topology
== TOPOLOGY_LOOP
) {
4343 /* We should never receive a FLOGI in loop mode, ignore it */
4344 did
= icmd
->un
.elsreq64
.remoteID
;
4346 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
4348 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
4349 "0113 An FLOGI ELS command x%x was "
4350 "received from DID x%x in Loop Mode\n",
4357 if ((lpfc_check_sparm(vport
, ndlp
, sp
, CLASS3
))) {
4358 /* For a FLOGI we accept, then if our portname is greater
4359 * then the remote portname we initiate Nport login.
4362 rc
= memcmp(&vport
->fc_portname
, &sp
->portName
,
4363 sizeof(struct lpfc_name
));
4366 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4370 lpfc_linkdown(phba
);
4371 lpfc_init_link(phba
, mbox
,
4373 phba
->cfg_link_speed
);
4374 mbox
->u
.mb
.un
.varInitLnk
.lipsr_AL_PA
= 0;
4375 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
4376 mbox
->vport
= vport
;
4377 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
4378 lpfc_set_loopback_flag(phba
);
4379 if (rc
== MBX_NOT_FINISHED
) {
4380 mempool_free(mbox
, phba
->mbox_mem_pool
);
4383 } else if (rc
> 0) { /* greater than */
4384 spin_lock_irq(shost
->host_lock
);
4385 vport
->fc_flag
|= FC_PT2PT_PLOGI
;
4386 spin_unlock_irq(shost
->host_lock
);
4388 spin_lock_irq(shost
->host_lock
);
4389 vport
->fc_flag
|= FC_PT2PT
;
4390 vport
->fc_flag
&= ~(FC_FABRIC
| FC_PUBLIC_LOOP
);
4391 spin_unlock_irq(shost
->host_lock
);
4393 /* Reject this request because invalid parameters */
4394 stat
.un
.b
.lsRjtRsvd0
= 0;
4395 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
4396 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_SPARM_OPTIONS
;
4397 stat
.un
.b
.vendorUnique
= 0;
4398 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
,
4404 lpfc_els_rsp_acc(vport
, ELS_CMD_PLOGI
, cmdiocb
, ndlp
, NULL
);
4410 * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
4411 * @vport: pointer to a host virtual N_Port data structure.
4412 * @cmdiocb: pointer to lpfc command iocb data structure.
4413 * @ndlp: pointer to a node-list data structure.
4415 * This routine processes Request Node Identification Data (RNID) IOCB
4416 * received as an ELS unsolicited event. Only when the RNID specified format
4417 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
4418 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
4419 * Accept (ACC) the RNID ELS command. All the other RNID formats are
4420 * rejected by invoking the lpfc_els_rsp_reject() routine.
4423 * 0 - Successfully processed rnid iocb (currently always return 0)
4426 lpfc_els_rcv_rnid(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
4427 struct lpfc_nodelist
*ndlp
)
4429 struct lpfc_dmabuf
*pcmd
;
4436 icmd
= &cmdiocb
->iocb
;
4437 did
= icmd
->un
.elsreq64
.remoteID
;
4438 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
4439 lp
= (uint32_t *) pcmd
->virt
;
4446 switch (rn
->Format
) {
4448 case RNID_TOPOLOGY_DISC
:
4450 lpfc_els_rsp_rnid_acc(vport
, rn
->Format
, cmdiocb
, ndlp
);
4453 /* Reject this request because format not supported */
4454 stat
.un
.b
.lsRjtRsvd0
= 0;
4455 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
4456 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_CANT_GIVE_DATA
;
4457 stat
.un
.b
.vendorUnique
= 0;
4458 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
,
4465 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
4466 * @vport: pointer to a host virtual N_Port data structure.
4467 * @cmdiocb: pointer to lpfc command iocb data structure.
4468 * @ndlp: pointer to a node-list data structure.
4470 * This routine processes a Link Incident Report Registration(LIRR) IOCB
4471 * received as an ELS unsolicited event. Currently, this function just invokes
4472 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
4475 * 0 - Successfully processed lirr iocb (currently always return 0)
4478 lpfc_els_rcv_lirr(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
4479 struct lpfc_nodelist
*ndlp
)
4483 /* For now, unconditionally reject this command */
4484 stat
.un
.b
.lsRjtRsvd0
= 0;
4485 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
4486 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_CANT_GIVE_DATA
;
4487 stat
.un
.b
.vendorUnique
= 0;
4488 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
4493 * lpfc_els_rsp_rps_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
4494 * @phba: pointer to lpfc hba data structure.
4495 * @pmb: pointer to the driver internal queue element for mailbox command.
4497 * This routine is the completion callback function for the MBX_READ_LNK_STAT
4498 * mailbox command. This callback function is to actually send the Accept
4499 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
4500 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
4501 * mailbox command, constructs the RPS response with the link statistics
4502 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
4503 * response to the RPS.
4505 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4506 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4507 * will be stored into the context1 field of the IOCB for the completion
4508 * callback function to the RPS Accept Response ELS IOCB command.
4512 lpfc_els_rsp_rps_acc(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
4518 struct lpfc_iocbq
*elsiocb
;
4519 struct lpfc_nodelist
*ndlp
;
4520 uint16_t xri
, status
;
4525 ndlp
= (struct lpfc_nodelist
*) pmb
->context2
;
4526 xri
= (uint16_t) ((unsigned long)(pmb
->context1
));
4527 pmb
->context1
= NULL
;
4528 pmb
->context2
= NULL
;
4530 if (mb
->mbxStatus
) {
4531 mempool_free(pmb
, phba
->mbox_mem_pool
);
4535 cmdsize
= sizeof(RPS_RSP
) + sizeof(uint32_t);
4536 mempool_free(pmb
, phba
->mbox_mem_pool
);
4537 elsiocb
= lpfc_prep_els_iocb(phba
->pport
, 0, cmdsize
,
4538 lpfc_max_els_tries
, ndlp
,
4539 ndlp
->nlp_DID
, ELS_CMD_ACC
);
4541 /* Decrement the ndlp reference count from previous mbox command */
4547 icmd
= &elsiocb
->iocb
;
4548 icmd
->ulpContext
= xri
;
4550 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
4551 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
4552 pcmd
+= sizeof(uint32_t); /* Skip past command */
4553 rps_rsp
= (RPS_RSP
*)pcmd
;
4555 if (phba
->fc_topology
!= TOPOLOGY_LOOP
)
4559 if (phba
->pport
->fc_flag
& FC_FABRIC
)
4563 rps_rsp
->portStatus
= cpu_to_be16(status
);
4564 rps_rsp
->linkFailureCnt
= cpu_to_be32(mb
->un
.varRdLnk
.linkFailureCnt
);
4565 rps_rsp
->lossSyncCnt
= cpu_to_be32(mb
->un
.varRdLnk
.lossSyncCnt
);
4566 rps_rsp
->lossSignalCnt
= cpu_to_be32(mb
->un
.varRdLnk
.lossSignalCnt
);
4567 rps_rsp
->primSeqErrCnt
= cpu_to_be32(mb
->un
.varRdLnk
.primSeqErrCnt
);
4568 rps_rsp
->invalidXmitWord
= cpu_to_be32(mb
->un
.varRdLnk
.invalidXmitWord
);
4569 rps_rsp
->crcCnt
= cpu_to_be32(mb
->un
.varRdLnk
.crcCnt
);
4570 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
4571 lpfc_printf_vlog(ndlp
->vport
, KERN_INFO
, LOG_ELS
,
4572 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
4573 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
4574 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
,
4575 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
4577 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
4578 phba
->fc_stat
.elsXmitACC
++;
4579 if (lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0) == IOCB_ERROR
)
4580 lpfc_els_free_iocb(phba
, elsiocb
);
4585 * lpfc_els_rcv_rps - Process an unsolicited rps iocb
4586 * @vport: pointer to a host virtual N_Port data structure.
4587 * @cmdiocb: pointer to lpfc command iocb data structure.
4588 * @ndlp: pointer to a node-list data structure.
4590 * This routine processes Read Port Status (RPS) IOCB received as an
4591 * ELS unsolicited event. It first checks the remote port state. If the
4592 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
4593 * state, it invokes the lpfc_els_rsp_reject() routine to send the reject
4594 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
4595 * for reading the HBA link statistics. It is for the callback function,
4596 * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command
4597 * to actually sending out RPS Accept (ACC) response.
4600 * 0 - Successfully processed rps iocb (currently always return 0)
4603 lpfc_els_rcv_rps(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
4604 struct lpfc_nodelist
*ndlp
)
4606 struct lpfc_hba
*phba
= vport
->phba
;
4610 struct lpfc_dmabuf
*pcmd
;
4614 if ((ndlp
->nlp_state
!= NLP_STE_UNMAPPED_NODE
) &&
4615 (ndlp
->nlp_state
!= NLP_STE_MAPPED_NODE
))
4616 /* reject the unsolicited RPS request and done with it */
4619 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
4620 lp
= (uint32_t *) pcmd
->virt
;
4621 flag
= (be32_to_cpu(*lp
++) & 0xf);
4625 ((flag
== 1) && (be32_to_cpu(rps
->un
.portNum
) == 0)) ||
4626 ((flag
== 2) && (memcmp(&rps
->un
.portName
, &vport
->fc_portname
,
4627 sizeof(struct lpfc_name
)) == 0))) {
4629 printk("Fix me....\n");
4631 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_ATOMIC
);
4633 lpfc_read_lnk_stat(phba
, mbox
);
4635 (void *)((unsigned long) cmdiocb
->iocb
.ulpContext
);
4636 mbox
->context2
= lpfc_nlp_get(ndlp
);
4637 mbox
->vport
= vport
;
4638 mbox
->mbox_cmpl
= lpfc_els_rsp_rps_acc
;
4639 if (lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
)
4640 != MBX_NOT_FINISHED
)
4641 /* Mbox completion will send ELS Response */
4643 /* Decrement reference count used for the failed mbox
4647 mempool_free(mbox
, phba
->mbox_mem_pool
);
4652 /* issue rejection response */
4653 stat
.un
.b
.lsRjtRsvd0
= 0;
4654 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
4655 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_CANT_GIVE_DATA
;
4656 stat
.un
.b
.vendorUnique
= 0;
4657 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
4662 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
4663 * @vport: pointer to a host virtual N_Port data structure.
4664 * @cmdsize: size of the ELS command.
4665 * @oldiocb: pointer to the original lpfc command iocb data structure.
4666 * @ndlp: pointer to a node-list data structure.
4668 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
4669 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
4671 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4672 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4673 * will be stored into the context1 field of the IOCB for the completion
4674 * callback function to the RPL Accept Response ELS command.
4677 * 0 - Successfully issued ACC RPL ELS command
4678 * 1 - Failed to issue ACC RPL ELS command
4681 lpfc_els_rsp_rpl_acc(struct lpfc_vport
*vport
, uint16_t cmdsize
,
4682 struct lpfc_iocbq
*oldiocb
, struct lpfc_nodelist
*ndlp
)
4684 struct lpfc_hba
*phba
= vport
->phba
;
4685 IOCB_t
*icmd
, *oldcmd
;
4687 struct lpfc_iocbq
*elsiocb
;
4690 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
, ndlp
,
4691 ndlp
->nlp_DID
, ELS_CMD_ACC
);
4696 icmd
= &elsiocb
->iocb
;
4697 oldcmd
= &oldiocb
->iocb
;
4698 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri */
4700 pcmd
= (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
4701 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
4702 pcmd
+= sizeof(uint16_t);
4703 *((uint16_t *)(pcmd
)) = be16_to_cpu(cmdsize
);
4704 pcmd
+= sizeof(uint16_t);
4706 /* Setup the RPL ACC payload */
4707 rpl_rsp
.listLen
= be32_to_cpu(1);
4709 rpl_rsp
.port_num_blk
.portNum
= 0;
4710 rpl_rsp
.port_num_blk
.portID
= be32_to_cpu(vport
->fc_myDID
);
4711 memcpy(&rpl_rsp
.port_num_blk
.portName
, &vport
->fc_portname
,
4712 sizeof(struct lpfc_name
));
4713 memcpy(pcmd
, &rpl_rsp
, cmdsize
- sizeof(uint32_t));
4714 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
4715 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
4716 "0120 Xmit ELS RPL ACC response tag x%x "
4717 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
4719 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
,
4720 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
4722 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
4723 phba
->fc_stat
.elsXmitACC
++;
4724 if (lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0) ==
4726 lpfc_els_free_iocb(phba
, elsiocb
);
4733 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
4734 * @vport: pointer to a host virtual N_Port data structure.
4735 * @cmdiocb: pointer to lpfc command iocb data structure.
4736 * @ndlp: pointer to a node-list data structure.
4738 * This routine processes Read Port List (RPL) IOCB received as an ELS
4739 * unsolicited event. It first checks the remote port state. If the remote
4740 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
4741 * invokes the lpfc_els_rsp_reject() routine to send reject response.
4742 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
4743 * to accept the RPL.
4746 * 0 - Successfully processed rpl iocb (currently always return 0)
4749 lpfc_els_rcv_rpl(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
4750 struct lpfc_nodelist
*ndlp
)
4752 struct lpfc_dmabuf
*pcmd
;
4759 if ((ndlp
->nlp_state
!= NLP_STE_UNMAPPED_NODE
) &&
4760 (ndlp
->nlp_state
!= NLP_STE_MAPPED_NODE
)) {
4761 /* issue rejection response */
4762 stat
.un
.b
.lsRjtRsvd0
= 0;
4763 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
4764 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_CANT_GIVE_DATA
;
4765 stat
.un
.b
.vendorUnique
= 0;
4766 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
,
4768 /* rejected the unsolicited RPL request and done with it */
4772 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
4773 lp
= (uint32_t *) pcmd
->virt
;
4774 rpl
= (RPL
*) (lp
+ 1);
4776 maxsize
= be32_to_cpu(rpl
->maxsize
);
4778 /* We support only one port */
4779 if ((rpl
->index
== 0) &&
4781 ((maxsize
* sizeof(uint32_t)) >= sizeof(RPL_RSP
)))) {
4782 cmdsize
= sizeof(uint32_t) + sizeof(RPL_RSP
);
4784 cmdsize
= sizeof(uint32_t) + maxsize
* sizeof(uint32_t);
4786 lpfc_els_rsp_rpl_acc(vport
, cmdsize
, cmdiocb
, ndlp
);
4792 * lpfc_els_rcv_farp - Process an unsolicited farp request els command
4793 * @vport: pointer to a virtual N_Port data structure.
4794 * @cmdiocb: pointer to lpfc command iocb data structure.
4795 * @ndlp: pointer to a node-list data structure.
4797 * This routine processes Fibre Channel Address Resolution Protocol
4798 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
4799 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
4800 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
4801 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
4802 * remote PortName is compared against the FC PortName stored in the @vport
4803 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
4804 * compared against the FC NodeName stored in the @vport data structure.
4805 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
4806 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
4807 * invoked to send out FARP Response to the remote node. Before sending the
4808 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
4809 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
4810 * routine is invoked to log into the remote port first.
4813 * 0 - Either the FARP Match Mode not supported or successfully processed
4816 lpfc_els_rcv_farp(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
4817 struct lpfc_nodelist
*ndlp
)
4819 struct lpfc_dmabuf
*pcmd
;
4823 uint32_t cmd
, cnt
, did
;
4825 icmd
= &cmdiocb
->iocb
;
4826 did
= icmd
->un
.elsreq64
.remoteID
;
4827 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
4828 lp
= (uint32_t *) pcmd
->virt
;
4832 /* FARP-REQ received from DID <did> */
4833 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
4834 "0601 FARP-REQ received from DID x%x\n", did
);
4835 /* We will only support match on WWPN or WWNN */
4836 if (fp
->Mflags
& ~(FARP_MATCH_NODE
| FARP_MATCH_PORT
)) {
4841 /* If this FARP command is searching for my portname */
4842 if (fp
->Mflags
& FARP_MATCH_PORT
) {
4843 if (memcmp(&fp
->RportName
, &vport
->fc_portname
,
4844 sizeof(struct lpfc_name
)) == 0)
4848 /* If this FARP command is searching for my nodename */
4849 if (fp
->Mflags
& FARP_MATCH_NODE
) {
4850 if (memcmp(&fp
->RnodeName
, &vport
->fc_nodename
,
4851 sizeof(struct lpfc_name
)) == 0)
4856 if ((ndlp
->nlp_state
== NLP_STE_UNMAPPED_NODE
) ||
4857 (ndlp
->nlp_state
== NLP_STE_MAPPED_NODE
)) {
4858 /* Log back into the node before sending the FARP. */
4859 if (fp
->Rflags
& FARP_REQUEST_PLOGI
) {
4860 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
4861 lpfc_nlp_set_state(vport
, ndlp
,
4862 NLP_STE_PLOGI_ISSUE
);
4863 lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, 0);
4866 /* Send a FARP response to that node */
4867 if (fp
->Rflags
& FARP_REQUEST_FARPR
)
4868 lpfc_issue_els_farpr(vport
, did
, 0);
4875 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
4876 * @vport: pointer to a host virtual N_Port data structure.
4877 * @cmdiocb: pointer to lpfc command iocb data structure.
4878 * @ndlp: pointer to a node-list data structure.
4880 * This routine processes Fibre Channel Address Resolution Protocol
4881 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
4882 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
4883 * the FARP response request.
4886 * 0 - Successfully processed FARPR IOCB (currently always return 0)
4889 lpfc_els_rcv_farpr(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
4890 struct lpfc_nodelist
*ndlp
)
4892 struct lpfc_dmabuf
*pcmd
;
4897 icmd
= &cmdiocb
->iocb
;
4898 did
= icmd
->un
.elsreq64
.remoteID
;
4899 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
4900 lp
= (uint32_t *) pcmd
->virt
;
4903 /* FARP-RSP received from DID <did> */
4904 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
4905 "0600 FARP-RSP received from DID x%x\n", did
);
4906 /* ACCEPT the Farp resp request */
4907 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
4913 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
4914 * @vport: pointer to a host virtual N_Port data structure.
4915 * @cmdiocb: pointer to lpfc command iocb data structure.
4916 * @fan_ndlp: pointer to a node-list data structure.
4918 * This routine processes a Fabric Address Notification (FAN) IOCB
4919 * command received as an ELS unsolicited event. The FAN ELS command will
4920 * only be processed on a physical port (i.e., the @vport represents the
4921 * physical port). The fabric NodeName and PortName from the FAN IOCB are
4922 * compared against those in the phba data structure. If any of those is
4923 * different, the lpfc_initial_flogi() routine is invoked to initialize
4924 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
4925 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
4926 * is invoked to register login to the fabric.
4929 * 0 - Successfully processed fan iocb (currently always return 0).
4932 lpfc_els_rcv_fan(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
4933 struct lpfc_nodelist
*fan_ndlp
)
4935 struct lpfc_hba
*phba
= vport
->phba
;
4939 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
, "0265 FAN received\n");
4940 lp
= (uint32_t *)((struct lpfc_dmabuf
*)cmdiocb
->context2
)->virt
;
4942 /* FAN received; Fan does not have a reply sequence */
4943 if ((vport
== phba
->pport
) &&
4944 (vport
->port_state
== LPFC_LOCAL_CFG_LINK
)) {
4945 if ((memcmp(&phba
->fc_fabparam
.nodeName
, &fp
->FnodeName
,
4946 sizeof(struct lpfc_name
))) ||
4947 (memcmp(&phba
->fc_fabparam
.portName
, &fp
->FportName
,
4948 sizeof(struct lpfc_name
)))) {
4949 /* This port has switched fabrics. FLOGI is required */
4950 lpfc_initial_flogi(vport
);
4952 /* FAN verified - skip FLOGI */
4953 vport
->fc_myDID
= vport
->fc_prevDID
;
4954 if (phba
->sli_rev
< LPFC_SLI_REV4
)
4955 lpfc_issue_fabric_reglogin(vport
);
4957 lpfc_issue_reg_vfi(vport
);
4964 * lpfc_els_timeout - Handler funciton to the els timer
4965 * @ptr: holder for the timer function associated data.
4967 * This routine is invoked by the ELS timer after timeout. It posts the ELS
4968 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
4969 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
4970 * up the worker thread. It is for the worker thread to invoke the routine
4971 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
4974 lpfc_els_timeout(unsigned long ptr
)
4976 struct lpfc_vport
*vport
= (struct lpfc_vport
*) ptr
;
4977 struct lpfc_hba
*phba
= vport
->phba
;
4978 uint32_t tmo_posted
;
4979 unsigned long iflag
;
4981 spin_lock_irqsave(&vport
->work_port_lock
, iflag
);
4982 tmo_posted
= vport
->work_port_events
& WORKER_ELS_TMO
;
4984 vport
->work_port_events
|= WORKER_ELS_TMO
;
4985 spin_unlock_irqrestore(&vport
->work_port_lock
, iflag
);
4988 lpfc_worker_wake_up(phba
);
4993 * lpfc_els_timeout_handler - Process an els timeout event
4994 * @vport: pointer to a virtual N_Port data structure.
4996 * This routine is the actual handler function that processes an ELS timeout
4997 * event. It walks the ELS ring to get and abort all the IOCBs (except the
4998 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
4999 * invoking the lpfc_sli_issue_abort_iotag() routine.
5002 lpfc_els_timeout_handler(struct lpfc_vport
*vport
)
5004 struct lpfc_hba
*phba
= vport
->phba
;
5005 struct lpfc_sli_ring
*pring
;
5006 struct lpfc_iocbq
*tmp_iocb
, *piocb
;
5008 struct lpfc_dmabuf
*pcmd
;
5009 uint32_t els_command
= 0;
5011 uint32_t remote_ID
= 0xffffffff;
5013 spin_lock_irq(&phba
->hbalock
);
5014 timeout
= (uint32_t)(phba
->fc_ratov
<< 1);
5016 pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
5018 list_for_each_entry_safe(piocb
, tmp_iocb
, &pring
->txcmplq
, list
) {
5021 if ((piocb
->iocb_flag
& LPFC_IO_LIBDFC
) != 0 ||
5022 piocb
->iocb
.ulpCommand
== CMD_ABORT_XRI_CN
||
5023 piocb
->iocb
.ulpCommand
== CMD_CLOSE_XRI_CN
)
5026 if (piocb
->vport
!= vport
)
5029 pcmd
= (struct lpfc_dmabuf
*) piocb
->context2
;
5031 els_command
= *(uint32_t *) (pcmd
->virt
);
5033 if (els_command
== ELS_CMD_FARP
||
5034 els_command
== ELS_CMD_FARPR
||
5035 els_command
== ELS_CMD_FDISC
)
5038 if (piocb
->drvrTimeout
> 0) {
5039 if (piocb
->drvrTimeout
>= timeout
)
5040 piocb
->drvrTimeout
-= timeout
;
5042 piocb
->drvrTimeout
= 0;
5046 remote_ID
= 0xffffffff;
5047 if (cmd
->ulpCommand
!= CMD_GEN_REQUEST64_CR
)
5048 remote_ID
= cmd
->un
.elsreq64
.remoteID
;
5050 struct lpfc_nodelist
*ndlp
;
5051 ndlp
= __lpfc_findnode_rpi(vport
, cmd
->ulpContext
);
5052 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
))
5053 remote_ID
= ndlp
->nlp_DID
;
5055 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
5056 "0127 ELS timeout Data: x%x x%x x%x "
5057 "x%x\n", els_command
,
5058 remote_ID
, cmd
->ulpCommand
, cmd
->ulpIoTag
);
5059 lpfc_sli_issue_abort_iotag(phba
, pring
, piocb
);
5061 spin_unlock_irq(&phba
->hbalock
);
5063 if (phba
->sli
.ring
[LPFC_ELS_RING
].txcmplq_cnt
)
5064 mod_timer(&vport
->els_tmofunc
, jiffies
+ HZ
* timeout
);
5068 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
5069 * @vport: pointer to a host virtual N_Port data structure.
5071 * This routine is used to clean up all the outstanding ELS commands on a
5072 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
5073 * routine. After that, it walks the ELS transmit queue to remove all the
5074 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
5075 * the IOCBs with a non-NULL completion callback function, the callback
5076 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
5077 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
5078 * callback function, the IOCB will simply be released. Finally, it walks
5079 * the ELS transmit completion queue to issue an abort IOCB to any transmit
5080 * completion queue IOCB that is associated with the @vport and is not
5081 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
5082 * part of the discovery state machine) out to HBA by invoking the
5083 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
5084 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
5085 * the IOCBs are aborted when this function returns.
5088 lpfc_els_flush_cmd(struct lpfc_vport
*vport
)
5090 LIST_HEAD(completions
);
5091 struct lpfc_hba
*phba
= vport
->phba
;
5092 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
5093 struct lpfc_iocbq
*tmp_iocb
, *piocb
;
5096 lpfc_fabric_abort_vport(vport
);
5098 spin_lock_irq(&phba
->hbalock
);
5099 list_for_each_entry_safe(piocb
, tmp_iocb
, &pring
->txq
, list
) {
5102 if (piocb
->iocb_flag
& LPFC_IO_LIBDFC
) {
5106 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
5107 if (cmd
->ulpCommand
== CMD_QUE_RING_BUF_CN
||
5108 cmd
->ulpCommand
== CMD_QUE_RING_BUF64_CN
||
5109 cmd
->ulpCommand
== CMD_CLOSE_XRI_CN
||
5110 cmd
->ulpCommand
== CMD_ABORT_XRI_CN
)
5113 if (piocb
->vport
!= vport
)
5116 list_move_tail(&piocb
->list
, &completions
);
5120 list_for_each_entry_safe(piocb
, tmp_iocb
, &pring
->txcmplq
, list
) {
5121 if (piocb
->iocb_flag
& LPFC_IO_LIBDFC
) {
5125 if (piocb
->vport
!= vport
)
5128 lpfc_sli_issue_abort_iotag(phba
, pring
, piocb
);
5130 spin_unlock_irq(&phba
->hbalock
);
5132 /* Cancell all the IOCBs from the completions list */
5133 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
5140 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
5141 * @phba: pointer to lpfc hba data structure.
5143 * This routine is used to clean up all the outstanding ELS commands on a
5144 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
5145 * routine. After that, it walks the ELS transmit queue to remove all the
5146 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
5147 * the IOCBs with the completion callback function associated, the callback
5148 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
5149 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
5150 * callback function associated, the IOCB will simply be released. Finally,
5151 * it walks the ELS transmit completion queue to issue an abort IOCB to any
5152 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
5153 * management plane IOCBs that are not part of the discovery state machine)
5154 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
5157 lpfc_els_flush_all_cmd(struct lpfc_hba
*phba
)
5159 LIST_HEAD(completions
);
5160 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
5161 struct lpfc_iocbq
*tmp_iocb
, *piocb
;
5164 lpfc_fabric_abort_hba(phba
);
5165 spin_lock_irq(&phba
->hbalock
);
5166 list_for_each_entry_safe(piocb
, tmp_iocb
, &pring
->txq
, list
) {
5168 if (piocb
->iocb_flag
& LPFC_IO_LIBDFC
)
5170 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
5171 if (cmd
->ulpCommand
== CMD_QUE_RING_BUF_CN
||
5172 cmd
->ulpCommand
== CMD_QUE_RING_BUF64_CN
||
5173 cmd
->ulpCommand
== CMD_CLOSE_XRI_CN
||
5174 cmd
->ulpCommand
== CMD_ABORT_XRI_CN
)
5176 list_move_tail(&piocb
->list
, &completions
);
5179 list_for_each_entry_safe(piocb
, tmp_iocb
, &pring
->txcmplq
, list
) {
5180 if (piocb
->iocb_flag
& LPFC_IO_LIBDFC
)
5182 lpfc_sli_issue_abort_iotag(phba
, pring
, piocb
);
5184 spin_unlock_irq(&phba
->hbalock
);
5186 /* Cancel all the IOCBs from the completions list */
5187 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
5194 * lpfc_send_els_failure_event - Posts an ELS command failure event
5195 * @phba: Pointer to hba context object.
5196 * @cmdiocbp: Pointer to command iocb which reported error.
5197 * @rspiocbp: Pointer to response iocb which reported error.
5199 * This function sends an event when there is an ELS command
5203 lpfc_send_els_failure_event(struct lpfc_hba
*phba
,
5204 struct lpfc_iocbq
*cmdiocbp
,
5205 struct lpfc_iocbq
*rspiocbp
)
5207 struct lpfc_vport
*vport
= cmdiocbp
->vport
;
5208 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
5209 struct lpfc_lsrjt_event lsrjt_event
;
5210 struct lpfc_fabric_event_header fabric_event
;
5212 struct lpfc_nodelist
*ndlp
;
5215 ndlp
= cmdiocbp
->context1
;
5216 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
))
5219 if (rspiocbp
->iocb
.ulpStatus
== IOSTAT_LS_RJT
) {
5220 lsrjt_event
.header
.event_type
= FC_REG_ELS_EVENT
;
5221 lsrjt_event
.header
.subcategory
= LPFC_EVENT_LSRJT_RCV
;
5222 memcpy(lsrjt_event
.header
.wwpn
, &ndlp
->nlp_portname
,
5223 sizeof(struct lpfc_name
));
5224 memcpy(lsrjt_event
.header
.wwnn
, &ndlp
->nlp_nodename
,
5225 sizeof(struct lpfc_name
));
5226 pcmd
= (uint32_t *) (((struct lpfc_dmabuf
*)
5227 cmdiocbp
->context2
)->virt
);
5228 lsrjt_event
.command
= *pcmd
;
5229 stat
.un
.lsRjtError
= be32_to_cpu(rspiocbp
->iocb
.un
.ulpWord
[4]);
5230 lsrjt_event
.reason_code
= stat
.un
.b
.lsRjtRsnCode
;
5231 lsrjt_event
.explanation
= stat
.un
.b
.lsRjtRsnCodeExp
;
5232 fc_host_post_vendor_event(shost
,
5233 fc_get_event_number(),
5234 sizeof(lsrjt_event
),
5235 (char *)&lsrjt_event
,
5239 if ((rspiocbp
->iocb
.ulpStatus
== IOSTAT_NPORT_BSY
) ||
5240 (rspiocbp
->iocb
.ulpStatus
== IOSTAT_FABRIC_BSY
)) {
5241 fabric_event
.event_type
= FC_REG_FABRIC_EVENT
;
5242 if (rspiocbp
->iocb
.ulpStatus
== IOSTAT_NPORT_BSY
)
5243 fabric_event
.subcategory
= LPFC_EVENT_PORT_BUSY
;
5245 fabric_event
.subcategory
= LPFC_EVENT_FABRIC_BUSY
;
5246 memcpy(fabric_event
.wwpn
, &ndlp
->nlp_portname
,
5247 sizeof(struct lpfc_name
));
5248 memcpy(fabric_event
.wwnn
, &ndlp
->nlp_nodename
,
5249 sizeof(struct lpfc_name
));
5250 fc_host_post_vendor_event(shost
,
5251 fc_get_event_number(),
5252 sizeof(fabric_event
),
5253 (char *)&fabric_event
,
5261 * lpfc_send_els_event - Posts unsolicited els event
5262 * @vport: Pointer to vport object.
5263 * @ndlp: Pointer FC node object.
5264 * @cmd: ELS command code.
5266 * This function posts an event when there is an incoming
5267 * unsolicited ELS command.
5270 lpfc_send_els_event(struct lpfc_vport
*vport
,
5271 struct lpfc_nodelist
*ndlp
,
5274 struct lpfc_els_event_header
*els_data
= NULL
;
5275 struct lpfc_logo_event
*logo_data
= NULL
;
5276 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
5278 if (*payload
== ELS_CMD_LOGO
) {
5279 logo_data
= kmalloc(sizeof(struct lpfc_logo_event
), GFP_KERNEL
);
5281 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
5282 "0148 Failed to allocate memory "
5283 "for LOGO event\n");
5286 els_data
= &logo_data
->header
;
5288 els_data
= kmalloc(sizeof(struct lpfc_els_event_header
),
5291 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
5292 "0149 Failed to allocate memory "
5297 els_data
->event_type
= FC_REG_ELS_EVENT
;
5300 els_data
->subcategory
= LPFC_EVENT_PLOGI_RCV
;
5303 els_data
->subcategory
= LPFC_EVENT_PRLO_RCV
;
5306 els_data
->subcategory
= LPFC_EVENT_ADISC_RCV
;
5309 els_data
->subcategory
= LPFC_EVENT_LOGO_RCV
;
5310 /* Copy the WWPN in the LOGO payload */
5311 memcpy(logo_data
->logo_wwpn
, &payload
[2],
5312 sizeof(struct lpfc_name
));
5318 memcpy(els_data
->wwpn
, &ndlp
->nlp_portname
, sizeof(struct lpfc_name
));
5319 memcpy(els_data
->wwnn
, &ndlp
->nlp_nodename
, sizeof(struct lpfc_name
));
5320 if (*payload
== ELS_CMD_LOGO
) {
5321 fc_host_post_vendor_event(shost
,
5322 fc_get_event_number(),
5323 sizeof(struct lpfc_logo_event
),
5328 fc_host_post_vendor_event(shost
,
5329 fc_get_event_number(),
5330 sizeof(struct lpfc_els_event_header
),
5341 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
5342 * @phba: pointer to lpfc hba data structure.
5343 * @pring: pointer to a SLI ring.
5344 * @vport: pointer to a host virtual N_Port data structure.
5345 * @elsiocb: pointer to lpfc els command iocb data structure.
5347 * This routine is used for processing the IOCB associated with a unsolicited
5348 * event. It first determines whether there is an existing ndlp that matches
5349 * the DID from the unsolicited IOCB. If not, it will create a new one with
5350 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
5351 * IOCB is then used to invoke the proper routine and to set up proper state
5352 * of the discovery state machine.
5355 lpfc_els_unsol_buffer(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
5356 struct lpfc_vport
*vport
, struct lpfc_iocbq
*elsiocb
)
5358 struct Scsi_Host
*shost
;
5359 struct lpfc_nodelist
*ndlp
;
5362 uint32_t cmd
, did
, newnode
, rjt_err
= 0;
5363 IOCB_t
*icmd
= &elsiocb
->iocb
;
5365 if (!vport
|| !(elsiocb
->context2
))
5369 payload
= ((struct lpfc_dmabuf
*)elsiocb
->context2
)->virt
;
5371 if ((phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) == 0)
5372 lpfc_post_buffer(phba
, pring
, 1);
5374 did
= icmd
->un
.rcvels
.remoteID
;
5375 if (icmd
->ulpStatus
) {
5376 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
5377 "RCV Unsol ELS: status:x%x/x%x did:x%x",
5378 icmd
->ulpStatus
, icmd
->un
.ulpWord
[4], did
);
5382 /* Check to see if link went down during discovery */
5383 if (lpfc_els_chk_latt(vport
))
5386 /* Ignore traffic recevied during vport shutdown. */
5387 if (vport
->load_flag
& FC_UNLOADING
)
5390 ndlp
= lpfc_findnode_did(vport
, did
);
5392 /* Cannot find existing Fabric ndlp, so allocate a new one */
5393 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
5397 lpfc_nlp_init(vport
, ndlp
, did
);
5398 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
5400 if ((did
& Fabric_DID_MASK
) == Fabric_DID_MASK
)
5401 ndlp
->nlp_type
|= NLP_FABRIC
;
5402 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
5403 ndlp
= lpfc_enable_node(vport
, ndlp
,
5404 NLP_STE_UNUSED_NODE
);
5407 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
5409 if ((did
& Fabric_DID_MASK
) == Fabric_DID_MASK
)
5410 ndlp
->nlp_type
|= NLP_FABRIC
;
5411 } else if (ndlp
->nlp_state
== NLP_STE_UNUSED_NODE
) {
5412 /* This is similar to the new node path */
5413 ndlp
= lpfc_nlp_get(ndlp
);
5416 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
5420 phba
->fc_stat
.elsRcvFrame
++;
5422 elsiocb
->context1
= lpfc_nlp_get(ndlp
);
5423 elsiocb
->vport
= vport
;
5425 if ((cmd
& ELS_CMD_MASK
) == ELS_CMD_RSCN
) {
5426 cmd
&= ELS_CMD_MASK
;
5428 /* ELS command <elsCmd> received from NPORT <did> */
5429 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
5430 "0112 ELS command x%x received from NPORT x%x "
5431 "Data: x%x\n", cmd
, did
, vport
->port_state
);
5434 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
5435 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
5436 did
, vport
->port_state
, ndlp
->nlp_flag
);
5438 phba
->fc_stat
.elsRcvPLOGI
++;
5439 ndlp
= lpfc_plogi_confirm_nport(phba
, payload
, ndlp
);
5441 lpfc_send_els_event(vport
, ndlp
, payload
);
5442 if (vport
->port_state
< LPFC_DISC_AUTH
) {
5443 if (!(phba
->pport
->fc_flag
& FC_PT2PT
) ||
5444 (phba
->pport
->fc_flag
& FC_PT2PT_PLOGI
)) {
5445 rjt_err
= LSRJT_UNABLE_TPC
;
5448 /* We get here, and drop thru, if we are PT2PT with
5449 * another NPort and the other side has initiated
5450 * the PLOGI before responding to our FLOGI.
5454 shost
= lpfc_shost_from_vport(vport
);
5455 spin_lock_irq(shost
->host_lock
);
5456 ndlp
->nlp_flag
&= ~NLP_TARGET_REMOVE
;
5457 spin_unlock_irq(shost
->host_lock
);
5459 lpfc_disc_state_machine(vport
, ndlp
, elsiocb
,
5464 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
5465 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
5466 did
, vport
->port_state
, ndlp
->nlp_flag
);
5468 phba
->fc_stat
.elsRcvFLOGI
++;
5469 lpfc_els_rcv_flogi(vport
, elsiocb
, ndlp
);
5474 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
5475 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
5476 did
, vport
->port_state
, ndlp
->nlp_flag
);
5478 phba
->fc_stat
.elsRcvLOGO
++;
5479 lpfc_send_els_event(vport
, ndlp
, payload
);
5480 if (vport
->port_state
< LPFC_DISC_AUTH
) {
5481 rjt_err
= LSRJT_UNABLE_TPC
;
5484 lpfc_disc_state_machine(vport
, ndlp
, elsiocb
, NLP_EVT_RCV_LOGO
);
5487 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
5488 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
5489 did
, vport
->port_state
, ndlp
->nlp_flag
);
5491 phba
->fc_stat
.elsRcvPRLO
++;
5492 lpfc_send_els_event(vport
, ndlp
, payload
);
5493 if (vport
->port_state
< LPFC_DISC_AUTH
) {
5494 rjt_err
= LSRJT_UNABLE_TPC
;
5497 lpfc_disc_state_machine(vport
, ndlp
, elsiocb
, NLP_EVT_RCV_PRLO
);
5500 phba
->fc_stat
.elsRcvRSCN
++;
5501 lpfc_els_rcv_rscn(vport
, elsiocb
, ndlp
);
5506 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
5507 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
5508 did
, vport
->port_state
, ndlp
->nlp_flag
);
5510 lpfc_send_els_event(vport
, ndlp
, payload
);
5511 phba
->fc_stat
.elsRcvADISC
++;
5512 if (vport
->port_state
< LPFC_DISC_AUTH
) {
5513 rjt_err
= LSRJT_UNABLE_TPC
;
5516 lpfc_disc_state_machine(vport
, ndlp
, elsiocb
,
5520 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
5521 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
5522 did
, vport
->port_state
, ndlp
->nlp_flag
);
5524 phba
->fc_stat
.elsRcvPDISC
++;
5525 if (vport
->port_state
< LPFC_DISC_AUTH
) {
5526 rjt_err
= LSRJT_UNABLE_TPC
;
5529 lpfc_disc_state_machine(vport
, ndlp
, elsiocb
,
5533 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
5534 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
5535 did
, vport
->port_state
, ndlp
->nlp_flag
);
5537 phba
->fc_stat
.elsRcvFARPR
++;
5538 lpfc_els_rcv_farpr(vport
, elsiocb
, ndlp
);
5541 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
5542 "RCV FARP: did:x%x/ste:x%x flg:x%x",
5543 did
, vport
->port_state
, ndlp
->nlp_flag
);
5545 phba
->fc_stat
.elsRcvFARP
++;
5546 lpfc_els_rcv_farp(vport
, elsiocb
, ndlp
);
5549 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
5550 "RCV FAN: did:x%x/ste:x%x flg:x%x",
5551 did
, vport
->port_state
, ndlp
->nlp_flag
);
5553 phba
->fc_stat
.elsRcvFAN
++;
5554 lpfc_els_rcv_fan(vport
, elsiocb
, ndlp
);
5557 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
5558 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
5559 did
, vport
->port_state
, ndlp
->nlp_flag
);
5561 phba
->fc_stat
.elsRcvPRLI
++;
5562 if (vport
->port_state
< LPFC_DISC_AUTH
) {
5563 rjt_err
= LSRJT_UNABLE_TPC
;
5566 lpfc_disc_state_machine(vport
, ndlp
, elsiocb
, NLP_EVT_RCV_PRLI
);
5569 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
5570 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
5571 did
, vport
->port_state
, ndlp
->nlp_flag
);
5573 phba
->fc_stat
.elsRcvLIRR
++;
5574 lpfc_els_rcv_lirr(vport
, elsiocb
, ndlp
);
5579 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
5580 "RCV RPS: did:x%x/ste:x%x flg:x%x",
5581 did
, vport
->port_state
, ndlp
->nlp_flag
);
5583 phba
->fc_stat
.elsRcvRPS
++;
5584 lpfc_els_rcv_rps(vport
, elsiocb
, ndlp
);
5589 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
5590 "RCV RPL: did:x%x/ste:x%x flg:x%x",
5591 did
, vport
->port_state
, ndlp
->nlp_flag
);
5593 phba
->fc_stat
.elsRcvRPL
++;
5594 lpfc_els_rcv_rpl(vport
, elsiocb
, ndlp
);
5599 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
5600 "RCV RNID: did:x%x/ste:x%x flg:x%x",
5601 did
, vport
->port_state
, ndlp
->nlp_flag
);
5603 phba
->fc_stat
.elsRcvRNID
++;
5604 lpfc_els_rcv_rnid(vport
, elsiocb
, ndlp
);
5609 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
5610 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
5611 cmd
, did
, vport
->port_state
);
5613 /* Unsupported ELS command, reject */
5614 rjt_err
= LSRJT_INVALID_CMD
;
5616 /* Unknown ELS command <elsCmd> received from NPORT <did> */
5617 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
5618 "0115 Unknown ELS command x%x "
5619 "received from NPORT x%x\n", cmd
, did
);
5625 /* check if need to LS_RJT received ELS cmd */
5627 memset(&stat
, 0, sizeof(stat
));
5628 stat
.un
.b
.lsRjtRsnCode
= rjt_err
;
5629 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_NOTHING_MORE
;
5630 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, elsiocb
, ndlp
,
5634 lpfc_nlp_put(elsiocb
->context1
);
5635 elsiocb
->context1
= NULL
;
5639 if (vport
&& !(vport
->load_flag
& FC_UNLOADING
))
5640 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
5641 "0111 Dropping received ELS cmd "
5642 "Data: x%x x%x x%x\n",
5643 icmd
->ulpStatus
, icmd
->un
.ulpWord
[4], icmd
->ulpTimeout
);
5644 phba
->fc_stat
.elsRcvDrop
++;
5648 * lpfc_find_vport_by_vpid - Find a vport on a HBA through vport identifier
5649 * @phba: pointer to lpfc hba data structure.
5650 * @vpi: host virtual N_Port identifier.
5652 * This routine finds a vport on a HBA (referred by @phba) through a
5653 * @vpi. The function walks the HBA's vport list and returns the address
5654 * of the vport with the matching @vpi.
5657 * NULL - No vport with the matching @vpi found
5658 * Otherwise - Address to the vport with the matching @vpi.
5660 static struct lpfc_vport
*
5661 lpfc_find_vport_by_vpid(struct lpfc_hba
*phba
, uint16_t vpi
)
5663 struct lpfc_vport
*vport
;
5664 unsigned long flags
;
5666 spin_lock_irqsave(&phba
->hbalock
, flags
);
5667 list_for_each_entry(vport
, &phba
->port_list
, listentry
) {
5668 if (vport
->vpi
== vpi
) {
5669 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
5673 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
5678 * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
5679 * @phba: pointer to lpfc hba data structure.
5680 * @pring: pointer to a SLI ring.
5681 * @elsiocb: pointer to lpfc els iocb data structure.
5683 * This routine is used to process an unsolicited event received from a SLI
5684 * (Service Level Interface) ring. The actual processing of the data buffer
5685 * associated with the unsolicited event is done by invoking the routine
5686 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
5687 * SLI ring on which the unsolicited event was received.
5690 lpfc_els_unsol_event(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
5691 struct lpfc_iocbq
*elsiocb
)
5693 struct lpfc_vport
*vport
= phba
->pport
;
5694 IOCB_t
*icmd
= &elsiocb
->iocb
;
5696 struct lpfc_dmabuf
*bdeBuf1
= elsiocb
->context2
;
5697 struct lpfc_dmabuf
*bdeBuf2
= elsiocb
->context3
;
5699 elsiocb
->context1
= NULL
;
5700 elsiocb
->context2
= NULL
;
5701 elsiocb
->context3
= NULL
;
5703 if (icmd
->ulpStatus
== IOSTAT_NEED_BUFFER
) {
5704 lpfc_sli_hbqbuf_add_hbqs(phba
, LPFC_ELS_HBQ
);
5705 } else if (icmd
->ulpStatus
== IOSTAT_LOCAL_REJECT
&&
5706 (icmd
->un
.ulpWord
[4] & 0xff) == IOERR_RCV_BUFFER_WAITING
) {
5707 phba
->fc_stat
.NoRcvBuf
++;
5708 /* Not enough posted buffers; Try posting more buffers */
5709 if (!(phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
))
5710 lpfc_post_buffer(phba
, pring
, 0);
5714 if ((phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
5715 (icmd
->ulpCommand
== CMD_IOCB_RCV_ELS64_CX
||
5716 icmd
->ulpCommand
== CMD_IOCB_RCV_SEQ64_CX
)) {
5717 if (icmd
->unsli3
.rcvsli3
.vpi
== 0xffff)
5718 vport
= phba
->pport
;
5720 vport
= lpfc_find_vport_by_vpid(phba
,
5721 icmd
->unsli3
.rcvsli3
.vpi
- phba
->vpi_base
);
5723 /* If there are no BDEs associated
5724 * with this IOCB, there is nothing to do.
5726 if (icmd
->ulpBdeCount
== 0)
5729 /* type of ELS cmd is first 32bit word
5732 if (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) {
5733 elsiocb
->context2
= bdeBuf1
;
5735 paddr
= getPaddr(icmd
->un
.cont64
[0].addrHigh
,
5736 icmd
->un
.cont64
[0].addrLow
);
5737 elsiocb
->context2
= lpfc_sli_ringpostbuf_get(phba
, pring
,
5741 lpfc_els_unsol_buffer(phba
, pring
, vport
, elsiocb
);
5743 * The different unsolicited event handlers would tell us
5744 * if they are done with "mp" by setting context2 to NULL.
5746 if (elsiocb
->context2
) {
5747 lpfc_in_buf_free(phba
, (struct lpfc_dmabuf
*)elsiocb
->context2
);
5748 elsiocb
->context2
= NULL
;
5751 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
5752 if ((phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) &&
5753 icmd
->ulpBdeCount
== 2) {
5754 elsiocb
->context2
= bdeBuf2
;
5755 lpfc_els_unsol_buffer(phba
, pring
, vport
, elsiocb
);
5756 /* free mp if we are done with it */
5757 if (elsiocb
->context2
) {
5758 lpfc_in_buf_free(phba
, elsiocb
->context2
);
5759 elsiocb
->context2
= NULL
;
5765 * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
5766 * @phba: pointer to lpfc hba data structure.
5767 * @vport: pointer to a virtual N_Port data structure.
5769 * This routine issues a Port Login (PLOGI) to the Name Server with
5770 * State Change Request (SCR) for a @vport. This routine will create an
5771 * ndlp for the Name Server associated to the @vport if such node does
5772 * not already exist. The PLOGI to Name Server is issued by invoking the
5773 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
5774 * (FDMI) is configured to the @vport, a FDMI node will be created and
5775 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
5778 lpfc_do_scr_ns_plogi(struct lpfc_hba
*phba
, struct lpfc_vport
*vport
)
5780 struct lpfc_nodelist
*ndlp
, *ndlp_fdmi
;
5782 ndlp
= lpfc_findnode_did(vport
, NameServer_DID
);
5784 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
5786 if (phba
->fc_topology
== TOPOLOGY_LOOP
) {
5787 lpfc_disc_start(vport
);
5790 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
5791 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
5792 "0251 NameServer login: no memory\n");
5795 lpfc_nlp_init(vport
, ndlp
, NameServer_DID
);
5796 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
5797 ndlp
= lpfc_enable_node(vport
, ndlp
, NLP_STE_UNUSED_NODE
);
5799 if (phba
->fc_topology
== TOPOLOGY_LOOP
) {
5800 lpfc_disc_start(vport
);
5803 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
5804 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
5805 "0348 NameServer login: node freed\n");
5809 ndlp
->nlp_type
|= NLP_FABRIC
;
5811 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
5813 if (lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, 0)) {
5814 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
5815 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
5816 "0252 Cannot issue NameServer login\n");
5820 if (vport
->cfg_fdmi_on
) {
5821 ndlp_fdmi
= mempool_alloc(phba
->nlp_mem_pool
,
5824 lpfc_nlp_init(vport
, ndlp_fdmi
, FDMI_DID
);
5825 ndlp_fdmi
->nlp_type
|= NLP_FABRIC
;
5826 lpfc_nlp_set_state(vport
, ndlp_fdmi
,
5827 NLP_STE_PLOGI_ISSUE
);
5828 lpfc_issue_els_plogi(vport
, ndlp_fdmi
->nlp_DID
,
5836 * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
5837 * @phba: pointer to lpfc hba data structure.
5838 * @pmb: pointer to the driver internal queue element for mailbox command.
5840 * This routine is the completion callback function to register new vport
5841 * mailbox command. If the new vport mailbox command completes successfully,
5842 * the fabric registration login shall be performed on physical port (the
5843 * new vport created is actually a physical port, with VPI 0) or the port
5844 * login to Name Server for State Change Request (SCR) will be performed
5845 * on virtual port (real virtual port, with VPI greater than 0).
5848 lpfc_cmpl_reg_new_vport(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
5850 struct lpfc_vport
*vport
= pmb
->vport
;
5851 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
5852 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) pmb
->context2
;
5853 MAILBOX_t
*mb
= &pmb
->u
.mb
;
5855 spin_lock_irq(shost
->host_lock
);
5856 vport
->fc_flag
&= ~FC_VPORT_NEEDS_REG_VPI
;
5857 spin_unlock_irq(shost
->host_lock
);
5859 if (mb
->mbxStatus
) {
5860 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
5861 "0915 Register VPI failed: 0x%x\n",
5864 switch (mb
->mbxStatus
) {
5865 case 0x11: /* unsupported feature */
5866 case 0x9603: /* max_vpi exceeded */
5867 case 0x9602: /* Link event since CLEAR_LA */
5868 /* giving up on vport registration */
5869 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
5870 spin_lock_irq(shost
->host_lock
);
5871 vport
->fc_flag
&= ~(FC_FABRIC
| FC_PUBLIC_LOOP
);
5872 spin_unlock_irq(shost
->host_lock
);
5873 lpfc_can_disctmo(vport
);
5876 /* Try to recover from this error */
5877 lpfc_mbx_unreg_vpi(vport
);
5878 spin_lock_irq(shost
->host_lock
);
5879 vport
->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
5880 spin_unlock_irq(shost
->host_lock
);
5881 if (vport
->port_type
== LPFC_PHYSICAL_PORT
)
5882 lpfc_initial_flogi(vport
);
5884 lpfc_initial_fdisc(vport
);
5889 if (vport
== phba
->pport
)
5890 if (phba
->sli_rev
< LPFC_SLI_REV4
)
5891 lpfc_issue_fabric_reglogin(vport
);
5893 lpfc_issue_reg_vfi(vport
);
5895 lpfc_do_scr_ns_plogi(phba
, vport
);
5898 /* Now, we decrement the ndlp reference count held for this
5903 mempool_free(pmb
, phba
->mbox_mem_pool
);
5908 * lpfc_register_new_vport - Register a new vport with a HBA
5909 * @phba: pointer to lpfc hba data structure.
5910 * @vport: pointer to a host virtual N_Port data structure.
5911 * @ndlp: pointer to a node-list data structure.
5913 * This routine registers the @vport as a new virtual port with a HBA.
5914 * It is done through a registering vpi mailbox command.
5917 lpfc_register_new_vport(struct lpfc_hba
*phba
, struct lpfc_vport
*vport
,
5918 struct lpfc_nodelist
*ndlp
)
5920 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
5923 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
5925 lpfc_reg_vpi(vport
, mbox
);
5926 mbox
->vport
= vport
;
5927 mbox
->context2
= lpfc_nlp_get(ndlp
);
5928 mbox
->mbox_cmpl
= lpfc_cmpl_reg_new_vport
;
5929 if (lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
)
5930 == MBX_NOT_FINISHED
) {
5931 /* mailbox command not success, decrement ndlp
5932 * reference count for this command
5935 mempool_free(mbox
, phba
->mbox_mem_pool
);
5937 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
5938 "0253 Register VPI: Can't send mbox\n");
5942 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
5943 "0254 Register VPI: no memory\n");
5949 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
5950 spin_lock_irq(shost
->host_lock
);
5951 vport
->fc_flag
&= ~FC_VPORT_NEEDS_REG_VPI
;
5952 spin_unlock_irq(shost
->host_lock
);
5957 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
5958 * @phba: pointer to lpfc hba data structure.
5959 * @cmdiocb: pointer to lpfc command iocb data structure.
5960 * @rspiocb: pointer to lpfc response iocb data structure.
5962 * This routine is the completion callback function to a Fabric Discover
5963 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
5964 * single threaded, each FDISC completion callback function will reset
5965 * the discovery timer for all vports such that the timers will not get
5966 * unnecessary timeout. The function checks the FDISC IOCB status. If error
5967 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
5968 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
5969 * assigned to the vport has been changed with the completion of the FDISC
5970 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
5971 * are unregistered from the HBA, and then the lpfc_register_new_vport()
5972 * routine is invoked to register new vport with the HBA. Otherwise, the
5973 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
5974 * Server for State Change Request (SCR).
5977 lpfc_cmpl_els_fdisc(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
5978 struct lpfc_iocbq
*rspiocb
)
5980 struct lpfc_vport
*vport
= cmdiocb
->vport
;
5981 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
5982 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) cmdiocb
->context1
;
5983 struct lpfc_nodelist
*np
;
5984 struct lpfc_nodelist
*next_np
;
5985 IOCB_t
*irsp
= &rspiocb
->iocb
;
5986 struct lpfc_iocbq
*piocb
;
5988 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
5989 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
5990 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
5992 /* Since all FDISCs are being single threaded, we
5993 * must reset the discovery timer for ALL vports
5994 * waiting to send FDISC when one completes.
5996 list_for_each_entry(piocb
, &phba
->fabric_iocb_list
, list
) {
5997 lpfc_set_disctmo(piocb
->vport
);
6000 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
6001 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
6002 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4], vport
->fc_prevDID
);
6004 if (irsp
->ulpStatus
) {
6005 /* Check for retry */
6006 if (lpfc_els_retry(phba
, cmdiocb
, rspiocb
))
6009 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
6010 "0126 FDISC failed. (%d/%d)\n",
6011 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4]);
6014 if (vport
->fc_vport
->vport_state
== FC_VPORT_INITIALIZING
)
6015 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
6017 /* giving up on FDISC. Cancel discovery timer */
6018 lpfc_can_disctmo(vport
);
6019 spin_lock_irq(shost
->host_lock
);
6020 vport
->fc_flag
|= FC_FABRIC
;
6021 if (vport
->phba
->fc_topology
== TOPOLOGY_LOOP
)
6022 vport
->fc_flag
|= FC_PUBLIC_LOOP
;
6023 spin_unlock_irq(shost
->host_lock
);
6025 vport
->fc_myDID
= irsp
->un
.ulpWord
[4] & Mask_DID
;
6026 lpfc_vport_set_state(vport
, FC_VPORT_ACTIVE
);
6027 if ((vport
->fc_prevDID
!= vport
->fc_myDID
) &&
6028 !(vport
->fc_flag
& FC_VPORT_NEEDS_REG_VPI
)) {
6029 /* If our NportID changed, we need to ensure all
6030 * remaining NPORTs get unreg_login'ed so we can
6033 list_for_each_entry_safe(np
, next_np
,
6034 &vport
->fc_nodes
, nlp_listp
) {
6035 if (!NLP_CHK_NODE_ACT(ndlp
) ||
6036 (np
->nlp_state
!= NLP_STE_NPR_NODE
) ||
6037 !(np
->nlp_flag
& NLP_NPR_ADISC
))
6039 spin_lock_irq(shost
->host_lock
);
6040 np
->nlp_flag
&= ~NLP_NPR_ADISC
;
6041 spin_unlock_irq(shost
->host_lock
);
6042 lpfc_unreg_rpi(vport
, np
);
6044 lpfc_mbx_unreg_vpi(vport
);
6045 spin_lock_irq(shost
->host_lock
);
6046 vport
->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
6047 spin_unlock_irq(shost
->host_lock
);
6050 if (vport
->fc_flag
& FC_VPORT_NEEDS_REG_VPI
)
6051 lpfc_register_new_vport(phba
, vport
, ndlp
);
6053 lpfc_do_scr_ns_plogi(phba
, vport
);
6056 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
6057 /* Cancel discovery timer */
6058 lpfc_can_disctmo(vport
);
6061 lpfc_els_free_iocb(phba
, cmdiocb
);
6065 * lpfc_issue_els_fdisc - Issue a fdisc iocb command
6066 * @vport: pointer to a virtual N_Port data structure.
6067 * @ndlp: pointer to a node-list data structure.
6068 * @retry: number of retries to the command IOCB.
6070 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
6071 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
6072 * routine to issue the IOCB, which makes sure only one outstanding fabric
6073 * IOCB will be sent off HBA at any given time.
6075 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6076 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6077 * will be stored into the context1 field of the IOCB for the completion
6078 * callback function to the FDISC ELS command.
6081 * 0 - Successfully issued fdisc iocb command
6082 * 1 - Failed to issue fdisc iocb command
6085 lpfc_issue_els_fdisc(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
6088 struct lpfc_hba
*phba
= vport
->phba
;
6090 struct lpfc_iocbq
*elsiocb
;
6091 struct serv_parm
*sp
;
6094 int did
= ndlp
->nlp_DID
;
6097 cmdsize
= (sizeof(uint32_t) + sizeof(struct serv_parm
));
6098 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
, did
,
6101 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
6102 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
6103 "0255 Issue FDISC: no IOCB\n");
6107 icmd
= &elsiocb
->iocb
;
6108 icmd
->un
.elsreq64
.myID
= 0;
6109 icmd
->un
.elsreq64
.fl
= 1;
6111 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
6112 /* FDISC needs to be 1 for WQE VPI */
6113 elsiocb
->iocb
.ulpCt_h
= (SLI4_CT_VPI
>> 1) & 1;
6114 elsiocb
->iocb
.ulpCt_l
= SLI4_CT_VPI
& 1 ;
6115 /* Set the ulpContext to the vpi */
6116 elsiocb
->iocb
.ulpContext
= vport
->vpi
+ phba
->vpi_base
;
6118 /* For FDISC, Let FDISC rsp set the NPortID for this VPI */
6123 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
6124 *((uint32_t *) (pcmd
)) = ELS_CMD_FDISC
;
6125 pcmd
+= sizeof(uint32_t); /* CSP Word 1 */
6126 memcpy(pcmd
, &vport
->phba
->pport
->fc_sparam
, sizeof(struct serv_parm
));
6127 sp
= (struct serv_parm
*) pcmd
;
6128 /* Setup CSPs accordingly for Fabric */
6129 sp
->cmn
.e_d_tov
= 0;
6130 sp
->cmn
.w2
.r_a_tov
= 0;
6131 sp
->cls1
.classValid
= 0;
6132 sp
->cls2
.seqDelivery
= 1;
6133 sp
->cls3
.seqDelivery
= 1;
6135 pcmd
+= sizeof(uint32_t); /* CSP Word 2 */
6136 pcmd
+= sizeof(uint32_t); /* CSP Word 3 */
6137 pcmd
+= sizeof(uint32_t); /* CSP Word 4 */
6138 pcmd
+= sizeof(uint32_t); /* Port Name */
6139 memcpy(pcmd
, &vport
->fc_portname
, 8);
6140 pcmd
+= sizeof(uint32_t); /* Node Name */
6141 pcmd
+= sizeof(uint32_t); /* Node Name */
6142 memcpy(pcmd
, &vport
->fc_nodename
, 8);
6144 lpfc_set_disctmo(vport
);
6146 phba
->fc_stat
.elsXmitFDISC
++;
6147 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_fdisc
;
6149 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
6150 "Issue FDISC: did:x%x",
6153 rc
= lpfc_issue_fabric_iocb(phba
, elsiocb
);
6154 if (rc
== IOCB_ERROR
) {
6155 lpfc_els_free_iocb(phba
, elsiocb
);
6156 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
6157 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
6158 "0256 Issue FDISC: Cannot send IOCB\n");
6161 lpfc_vport_set_state(vport
, FC_VPORT_INITIALIZING
);
6162 vport
->port_state
= LPFC_FDISC
;
6167 * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
6168 * @phba: pointer to lpfc hba data structure.
6169 * @cmdiocb: pointer to lpfc command iocb data structure.
6170 * @rspiocb: pointer to lpfc response iocb data structure.
6172 * This routine is the completion callback function to the issuing of a LOGO
6173 * ELS command off a vport. It frees the command IOCB and then decrement the
6174 * reference count held on ndlp for this completion function, indicating that
6175 * the reference to the ndlp is no long needed. Note that the
6176 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
6177 * callback function and an additional explicit ndlp reference decrementation
6178 * will trigger the actual release of the ndlp.
6181 lpfc_cmpl_els_npiv_logo(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
6182 struct lpfc_iocbq
*rspiocb
)
6184 struct lpfc_vport
*vport
= cmdiocb
->vport
;
6186 struct lpfc_nodelist
*ndlp
;
6187 ndlp
= (struct lpfc_nodelist
*)cmdiocb
->context1
;
6189 irsp
= &rspiocb
->iocb
;
6190 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
6191 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
6192 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4], irsp
->un
.rcvels
.remoteID
);
6194 lpfc_els_free_iocb(phba
, cmdiocb
);
6195 vport
->unreg_vpi_cmpl
= VPORT_ERROR
;
6197 /* Trigger the release of the ndlp after logo */
6202 * lpfc_issue_els_npiv_logo - Issue a logo off a vport
6203 * @vport: pointer to a virtual N_Port data structure.
6204 * @ndlp: pointer to a node-list data structure.
6206 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
6208 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6209 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6210 * will be stored into the context1 field of the IOCB for the completion
6211 * callback function to the LOGO ELS command.
6214 * 0 - Successfully issued logo off the @vport
6215 * 1 - Failed to issue logo off the @vport
6218 lpfc_issue_els_npiv_logo(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
6220 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
6221 struct lpfc_hba
*phba
= vport
->phba
;
6223 struct lpfc_iocbq
*elsiocb
;
6227 cmdsize
= 2 * sizeof(uint32_t) + sizeof(struct lpfc_name
);
6228 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, 0, ndlp
, ndlp
->nlp_DID
,
6233 icmd
= &elsiocb
->iocb
;
6234 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
6235 *((uint32_t *) (pcmd
)) = ELS_CMD_LOGO
;
6236 pcmd
+= sizeof(uint32_t);
6238 /* Fill in LOGO payload */
6239 *((uint32_t *) (pcmd
)) = be32_to_cpu(vport
->fc_myDID
);
6240 pcmd
+= sizeof(uint32_t);
6241 memcpy(pcmd
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
6243 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
6244 "Issue LOGO npiv did:x%x flg:x%x",
6245 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
6247 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_npiv_logo
;
6248 spin_lock_irq(shost
->host_lock
);
6249 ndlp
->nlp_flag
|= NLP_LOGO_SND
;
6250 spin_unlock_irq(shost
->host_lock
);
6251 if (lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0) ==
6253 spin_lock_irq(shost
->host_lock
);
6254 ndlp
->nlp_flag
&= ~NLP_LOGO_SND
;
6255 spin_unlock_irq(shost
->host_lock
);
6256 lpfc_els_free_iocb(phba
, elsiocb
);
6263 * lpfc_fabric_block_timeout - Handler function to the fabric block timer
6264 * @ptr: holder for the timer function associated data.
6266 * This routine is invoked by the fabric iocb block timer after
6267 * timeout. It posts the fabric iocb block timeout event by setting the
6268 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
6269 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
6270 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
6271 * posted event WORKER_FABRIC_BLOCK_TMO.
6274 lpfc_fabric_block_timeout(unsigned long ptr
)
6276 struct lpfc_hba
*phba
= (struct lpfc_hba
*) ptr
;
6277 unsigned long iflags
;
6278 uint32_t tmo_posted
;
6280 spin_lock_irqsave(&phba
->pport
->work_port_lock
, iflags
);
6281 tmo_posted
= phba
->pport
->work_port_events
& WORKER_FABRIC_BLOCK_TMO
;
6283 phba
->pport
->work_port_events
|= WORKER_FABRIC_BLOCK_TMO
;
6284 spin_unlock_irqrestore(&phba
->pport
->work_port_lock
, iflags
);
6287 lpfc_worker_wake_up(phba
);
6292 * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
6293 * @phba: pointer to lpfc hba data structure.
6295 * This routine issues one fabric iocb from the driver internal list to
6296 * the HBA. It first checks whether it's ready to issue one fabric iocb to
6297 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
6298 * remove one pending fabric iocb from the driver internal list and invokes
6299 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
6302 lpfc_resume_fabric_iocbs(struct lpfc_hba
*phba
)
6304 struct lpfc_iocbq
*iocb
;
6305 unsigned long iflags
;
6311 spin_lock_irqsave(&phba
->hbalock
, iflags
);
6312 /* Post any pending iocb to the SLI layer */
6313 if (atomic_read(&phba
->fabric_iocb_count
) == 0) {
6314 list_remove_head(&phba
->fabric_iocb_list
, iocb
, typeof(*iocb
),
6317 /* Increment fabric iocb count to hold the position */
6318 atomic_inc(&phba
->fabric_iocb_count
);
6320 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
6322 iocb
->fabric_iocb_cmpl
= iocb
->iocb_cmpl
;
6323 iocb
->iocb_cmpl
= lpfc_cmpl_fabric_iocb
;
6324 iocb
->iocb_flag
|= LPFC_IO_FABRIC
;
6326 lpfc_debugfs_disc_trc(iocb
->vport
, LPFC_DISC_TRC_ELS_CMD
,
6327 "Fabric sched1: ste:x%x",
6328 iocb
->vport
->port_state
, 0, 0);
6330 ret
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, iocb
, 0);
6332 if (ret
== IOCB_ERROR
) {
6333 iocb
->iocb_cmpl
= iocb
->fabric_iocb_cmpl
;
6334 iocb
->fabric_iocb_cmpl
= NULL
;
6335 iocb
->iocb_flag
&= ~LPFC_IO_FABRIC
;
6337 cmd
->ulpStatus
= IOSTAT_LOCAL_REJECT
;
6338 cmd
->un
.ulpWord
[4] = IOERR_SLI_ABORTED
;
6339 iocb
->iocb_cmpl(phba
, iocb
, iocb
);
6341 atomic_dec(&phba
->fabric_iocb_count
);
6350 * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
6351 * @phba: pointer to lpfc hba data structure.
6353 * This routine unblocks the issuing fabric iocb command. The function
6354 * will clear the fabric iocb block bit and then invoke the routine
6355 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
6356 * from the driver internal fabric iocb list.
6359 lpfc_unblock_fabric_iocbs(struct lpfc_hba
*phba
)
6361 clear_bit(FABRIC_COMANDS_BLOCKED
, &phba
->bit_flags
);
6363 lpfc_resume_fabric_iocbs(phba
);
6368 * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
6369 * @phba: pointer to lpfc hba data structure.
6371 * This routine blocks the issuing fabric iocb for a specified amount of
6372 * time (currently 100 ms). This is done by set the fabric iocb block bit
6373 * and set up a timeout timer for 100ms. When the block bit is set, no more
6374 * fabric iocb will be issued out of the HBA.
6377 lpfc_block_fabric_iocbs(struct lpfc_hba
*phba
)
6381 blocked
= test_and_set_bit(FABRIC_COMANDS_BLOCKED
, &phba
->bit_flags
);
6382 /* Start a timer to unblock fabric iocbs after 100ms */
6384 mod_timer(&phba
->fabric_block_timer
, jiffies
+ HZ
/10 );
6390 * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
6391 * @phba: pointer to lpfc hba data structure.
6392 * @cmdiocb: pointer to lpfc command iocb data structure.
6393 * @rspiocb: pointer to lpfc response iocb data structure.
6395 * This routine is the callback function that is put to the fabric iocb's
6396 * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
6397 * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
6398 * function first restores and invokes the original iocb's callback function
6399 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
6400 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
6403 lpfc_cmpl_fabric_iocb(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
6404 struct lpfc_iocbq
*rspiocb
)
6408 if ((cmdiocb
->iocb_flag
& LPFC_IO_FABRIC
) != LPFC_IO_FABRIC
)
6411 switch (rspiocb
->iocb
.ulpStatus
) {
6412 case IOSTAT_NPORT_RJT
:
6413 case IOSTAT_FABRIC_RJT
:
6414 if (rspiocb
->iocb
.un
.ulpWord
[4] & RJT_UNAVAIL_TEMP
) {
6415 lpfc_block_fabric_iocbs(phba
);
6419 case IOSTAT_NPORT_BSY
:
6420 case IOSTAT_FABRIC_BSY
:
6421 lpfc_block_fabric_iocbs(phba
);
6425 stat
.un
.lsRjtError
=
6426 be32_to_cpu(rspiocb
->iocb
.un
.ulpWord
[4]);
6427 if ((stat
.un
.b
.lsRjtRsnCode
== LSRJT_UNABLE_TPC
) ||
6428 (stat
.un
.b
.lsRjtRsnCode
== LSRJT_LOGICAL_BSY
))
6429 lpfc_block_fabric_iocbs(phba
);
6433 if (atomic_read(&phba
->fabric_iocb_count
) == 0)
6436 cmdiocb
->iocb_cmpl
= cmdiocb
->fabric_iocb_cmpl
;
6437 cmdiocb
->fabric_iocb_cmpl
= NULL
;
6438 cmdiocb
->iocb_flag
&= ~LPFC_IO_FABRIC
;
6439 cmdiocb
->iocb_cmpl(phba
, cmdiocb
, rspiocb
);
6441 atomic_dec(&phba
->fabric_iocb_count
);
6442 if (!test_bit(FABRIC_COMANDS_BLOCKED
, &phba
->bit_flags
)) {
6443 /* Post any pending iocbs to HBA */
6444 lpfc_resume_fabric_iocbs(phba
);
6449 * lpfc_issue_fabric_iocb - Issue a fabric iocb command
6450 * @phba: pointer to lpfc hba data structure.
6451 * @iocb: pointer to lpfc command iocb data structure.
6453 * This routine is used as the top-level API for issuing a fabric iocb command
6454 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
6455 * function makes sure that only one fabric bound iocb will be outstanding at
6456 * any given time. As such, this function will first check to see whether there
6457 * is already an outstanding fabric iocb on the wire. If so, it will put the
6458 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
6459 * issued later. Otherwise, it will issue the iocb on the wire and update the
6460 * fabric iocb count it indicate that there is one fabric iocb on the wire.
6462 * Note, this implementation has a potential sending out fabric IOCBs out of
6463 * order. The problem is caused by the construction of the "ready" boolen does
6464 * not include the condition that the internal fabric IOCB list is empty. As
6465 * such, it is possible a fabric IOCB issued by this routine might be "jump"
6466 * ahead of the fabric IOCBs in the internal list.
6469 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
6470 * IOCB_ERROR - failed to issue fabric iocb
6473 lpfc_issue_fabric_iocb(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocb
)
6475 unsigned long iflags
;
6479 if (atomic_read(&phba
->fabric_iocb_count
) > 1)
6482 spin_lock_irqsave(&phba
->hbalock
, iflags
);
6483 ready
= atomic_read(&phba
->fabric_iocb_count
) == 0 &&
6484 !test_bit(FABRIC_COMANDS_BLOCKED
, &phba
->bit_flags
);
6487 /* Increment fabric iocb count to hold the position */
6488 atomic_inc(&phba
->fabric_iocb_count
);
6489 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
6491 iocb
->fabric_iocb_cmpl
= iocb
->iocb_cmpl
;
6492 iocb
->iocb_cmpl
= lpfc_cmpl_fabric_iocb
;
6493 iocb
->iocb_flag
|= LPFC_IO_FABRIC
;
6495 lpfc_debugfs_disc_trc(iocb
->vport
, LPFC_DISC_TRC_ELS_CMD
,
6496 "Fabric sched2: ste:x%x",
6497 iocb
->vport
->port_state
, 0, 0);
6499 ret
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, iocb
, 0);
6501 if (ret
== IOCB_ERROR
) {
6502 iocb
->iocb_cmpl
= iocb
->fabric_iocb_cmpl
;
6503 iocb
->fabric_iocb_cmpl
= NULL
;
6504 iocb
->iocb_flag
&= ~LPFC_IO_FABRIC
;
6505 atomic_dec(&phba
->fabric_iocb_count
);
6508 spin_lock_irqsave(&phba
->hbalock
, iflags
);
6509 list_add_tail(&iocb
->list
, &phba
->fabric_iocb_list
);
6510 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
6517 * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
6518 * @vport: pointer to a virtual N_Port data structure.
6520 * This routine aborts all the IOCBs associated with a @vport from the
6521 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
6522 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
6523 * list, removes each IOCB associated with the @vport off the list, set the
6524 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
6525 * associated with the IOCB.
6527 static void lpfc_fabric_abort_vport(struct lpfc_vport
*vport
)
6529 LIST_HEAD(completions
);
6530 struct lpfc_hba
*phba
= vport
->phba
;
6531 struct lpfc_iocbq
*tmp_iocb
, *piocb
;
6533 spin_lock_irq(&phba
->hbalock
);
6534 list_for_each_entry_safe(piocb
, tmp_iocb
, &phba
->fabric_iocb_list
,
6537 if (piocb
->vport
!= vport
)
6540 list_move_tail(&piocb
->list
, &completions
);
6542 spin_unlock_irq(&phba
->hbalock
);
6544 /* Cancel all the IOCBs from the completions list */
6545 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
6550 * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
6551 * @ndlp: pointer to a node-list data structure.
6553 * This routine aborts all the IOCBs associated with an @ndlp from the
6554 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
6555 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
6556 * list, removes each IOCB associated with the @ndlp off the list, set the
6557 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
6558 * associated with the IOCB.
6560 void lpfc_fabric_abort_nport(struct lpfc_nodelist
*ndlp
)
6562 LIST_HEAD(completions
);
6563 struct lpfc_hba
*phba
= ndlp
->phba
;
6564 struct lpfc_iocbq
*tmp_iocb
, *piocb
;
6565 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
6567 spin_lock_irq(&phba
->hbalock
);
6568 list_for_each_entry_safe(piocb
, tmp_iocb
, &phba
->fabric_iocb_list
,
6570 if ((lpfc_check_sli_ndlp(phba
, pring
, piocb
, ndlp
))) {
6572 list_move_tail(&piocb
->list
, &completions
);
6575 spin_unlock_irq(&phba
->hbalock
);
6577 /* Cancel all the IOCBs from the completions list */
6578 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
6583 * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
6584 * @phba: pointer to lpfc hba data structure.
6586 * This routine aborts all the IOCBs currently on the driver internal
6587 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
6588 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
6589 * list, removes IOCBs off the list, set the status feild to
6590 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
6593 void lpfc_fabric_abort_hba(struct lpfc_hba
*phba
)
6595 LIST_HEAD(completions
);
6597 spin_lock_irq(&phba
->hbalock
);
6598 list_splice_init(&phba
->fabric_iocb_list
, &completions
);
6599 spin_unlock_irq(&phba
->hbalock
);
6601 /* Cancel all the IOCBs from the completions list */
6602 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
6607 * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
6608 * @phba: pointer to lpfc hba data structure.
6609 * @axri: pointer to the els xri abort wcqe structure.
6611 * This routine is invoked by the worker thread to process a SLI4 slow-path
6615 lpfc_sli4_els_xri_aborted(struct lpfc_hba
*phba
,
6616 struct sli4_wcqe_xri_aborted
*axri
)
6618 uint16_t xri
= bf_get(lpfc_wcqe_xa_xri
, axri
);
6619 struct lpfc_sglq
*sglq_entry
= NULL
, *sglq_next
= NULL
;
6620 unsigned long iflag
= 0;
6622 spin_lock_irqsave(&phba
->sli4_hba
.abts_sgl_list_lock
, iflag
);
6623 list_for_each_entry_safe(sglq_entry
, sglq_next
,
6624 &phba
->sli4_hba
.lpfc_abts_els_sgl_list
, list
) {
6625 if (sglq_entry
->sli4_xritag
== xri
) {
6626 list_del(&sglq_entry
->list
);
6627 spin_unlock_irqrestore(
6628 &phba
->sli4_hba
.abts_sgl_list_lock
,
6630 spin_lock_irqsave(&phba
->hbalock
, iflag
);
6632 list_add_tail(&sglq_entry
->list
,
6633 &phba
->sli4_hba
.lpfc_sgl_list
);
6634 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
6638 spin_unlock_irqrestore(&phba
->sli4_hba
.abts_sgl_list_lock
, iflag
);