1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2009 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. *
7 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
9 * This program is free software; you can redistribute it and/or *
10 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
20 *******************************************************************/
21 /* See Fibre Channel protocol T11 FC-LS for details */
22 #include <linux/blkdev.h>
23 #include <linux/pci.h>
24 #include <linux/slab.h>
25 #include <linux/interrupt.h>
27 #include <scsi/scsi.h>
28 #include <scsi/scsi_device.h>
29 #include <scsi/scsi_host.h>
30 #include <scsi/scsi_transport_fc.h>
35 #include "lpfc_sli4.h"
37 #include "lpfc_disc.h"
38 #include "lpfc_scsi.h"
40 #include "lpfc_logmsg.h"
41 #include "lpfc_crtn.h"
42 #include "lpfc_vport.h"
43 #include "lpfc_debugfs.h"
45 static int lpfc_els_retry(struct lpfc_hba
*, struct lpfc_iocbq
*,
47 static void lpfc_cmpl_fabric_iocb(struct lpfc_hba
*, struct lpfc_iocbq
*,
49 static void lpfc_fabric_abort_vport(struct lpfc_vport
*vport
);
50 static int lpfc_issue_els_fdisc(struct lpfc_vport
*vport
,
51 struct lpfc_nodelist
*ndlp
, uint8_t retry
);
52 static int lpfc_issue_fabric_iocb(struct lpfc_hba
*phba
,
53 struct lpfc_iocbq
*iocb
);
55 static int lpfc_max_els_tries
= 3;
58 * lpfc_els_chk_latt - Check host link attention event for a vport
59 * @vport: pointer to a host virtual N_Port data structure.
61 * This routine checks whether there is an outstanding host link
62 * attention event during the discovery process with the @vport. It is done
63 * by reading the HBA's Host Attention (HA) register. If there is any host
64 * link attention events during this @vport's discovery process, the @vport
65 * shall be marked as FC_ABORT_DISCOVERY, a host link attention clear shall
66 * be issued if the link state is not already in host link cleared state,
67 * and a return code shall indicate whether the host link attention event
70 * Note that, if either the host link is in state LPFC_LINK_DOWN or @vport
71 * state in LPFC_VPORT_READY, the request for checking host link attention
72 * event will be ignored and a return code shall indicate no host link
73 * attention event had happened.
76 * 0 - no host link attention event happened
77 * 1 - host link attention event happened
80 lpfc_els_chk_latt(struct lpfc_vport
*vport
)
82 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
83 struct lpfc_hba
*phba
= vport
->phba
;
86 if (vport
->port_state
>= LPFC_VPORT_READY
||
87 phba
->link_state
== LPFC_LINK_DOWN
||
88 phba
->sli_rev
> LPFC_SLI_REV3
)
91 /* Read the HBA Host Attention Register */
92 ha_copy
= readl(phba
->HAregaddr
);
94 if (!(ha_copy
& HA_LATT
))
97 /* Pending Link Event during Discovery */
98 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
99 "0237 Pending Link Event during "
100 "Discovery: State x%x\n",
101 phba
->pport
->port_state
);
103 /* CLEAR_LA should re-enable link attention events and
104 * we should then imediately take a LATT event. The
105 * LATT processing should call lpfc_linkdown() which
106 * will cleanup any left over in-progress discovery
109 spin_lock_irq(shost
->host_lock
);
110 vport
->fc_flag
|= FC_ABORT_DISCOVERY
;
111 spin_unlock_irq(shost
->host_lock
);
113 if (phba
->link_state
!= LPFC_CLEAR_LA
)
114 lpfc_issue_clear_la(phba
, vport
);
120 * lpfc_prep_els_iocb - Allocate and prepare a lpfc iocb data structure
121 * @vport: pointer to a host virtual N_Port data structure.
122 * @expectRsp: flag indicating whether response is expected.
123 * @cmdSize: size of the ELS command.
124 * @retry: number of retries to the command IOCB when it fails.
125 * @ndlp: pointer to a node-list data structure.
126 * @did: destination identifier.
127 * @elscmd: the ELS command code.
129 * This routine is used for allocating a lpfc-IOCB data structure from
130 * the driver lpfc-IOCB free-list and prepare the IOCB with the parameters
131 * passed into the routine for discovery state machine to issue an Extended
132 * Link Service (ELS) commands. It is a generic lpfc-IOCB allocation
133 * and preparation routine that is used by all the discovery state machine
134 * routines and the ELS command-specific fields will be later set up by
135 * the individual discovery machine routines after calling this routine
136 * allocating and preparing a generic IOCB data structure. It fills in the
137 * Buffer Descriptor Entries (BDEs), allocates buffers for both command
138 * payload and response payload (if expected). The reference count on the
139 * ndlp is incremented by 1 and the reference to the ndlp is put into
140 * context1 of the IOCB data structure for this IOCB to hold the ndlp
141 * reference for the command's callback function to access later.
144 * Pointer to the newly allocated/prepared els iocb data structure
145 * NULL - when els iocb data structure allocation/preparation failed
148 lpfc_prep_els_iocb(struct lpfc_vport
*vport
, uint8_t expectRsp
,
149 uint16_t cmdSize
, uint8_t retry
,
150 struct lpfc_nodelist
*ndlp
, uint32_t did
,
153 struct lpfc_hba
*phba
= vport
->phba
;
154 struct lpfc_iocbq
*elsiocb
;
155 struct lpfc_dmabuf
*pcmd
, *prsp
, *pbuflist
;
156 struct ulp_bde64
*bpl
;
160 if (!lpfc_is_link_up(phba
))
163 /* Allocate buffer for command iocb */
164 elsiocb
= lpfc_sli_get_iocbq(phba
);
170 * If this command is for fabric controller and HBA running
171 * in FIP mode send FLOGI, FDISC and LOGO as FIP frames.
173 if ((did
== Fabric_DID
) &&
174 (phba
->hba_flag
& HBA_FIP_SUPPORT
) &&
175 ((elscmd
== ELS_CMD_FLOGI
) ||
176 (elscmd
== ELS_CMD_FDISC
) ||
177 (elscmd
== ELS_CMD_LOGO
)))
180 elsiocb
->iocb_flag
|=
181 ((LPFC_ELS_ID_FLOGI
<< LPFC_FIP_ELS_ID_SHIFT
)
182 & LPFC_FIP_ELS_ID_MASK
);
185 elsiocb
->iocb_flag
|=
186 ((LPFC_ELS_ID_FDISC
<< LPFC_FIP_ELS_ID_SHIFT
)
187 & LPFC_FIP_ELS_ID_MASK
);
190 elsiocb
->iocb_flag
|=
191 ((LPFC_ELS_ID_LOGO
<< LPFC_FIP_ELS_ID_SHIFT
)
192 & LPFC_FIP_ELS_ID_MASK
);
196 elsiocb
->iocb_flag
&= ~LPFC_FIP_ELS_ID_MASK
;
198 icmd
= &elsiocb
->iocb
;
200 /* fill in BDEs for command */
201 /* Allocate buffer for command payload */
202 pcmd
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
204 pcmd
->virt
= lpfc_mbuf_alloc(phba
, MEM_PRI
, &pcmd
->phys
);
205 if (!pcmd
|| !pcmd
->virt
)
206 goto els_iocb_free_pcmb_exit
;
208 INIT_LIST_HEAD(&pcmd
->list
);
210 /* Allocate buffer for response payload */
212 prsp
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
214 prsp
->virt
= lpfc_mbuf_alloc(phba
, MEM_PRI
,
216 if (!prsp
|| !prsp
->virt
)
217 goto els_iocb_free_prsp_exit
;
218 INIT_LIST_HEAD(&prsp
->list
);
222 /* Allocate buffer for Buffer ptr list */
223 pbuflist
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
225 pbuflist
->virt
= lpfc_mbuf_alloc(phba
, MEM_PRI
,
227 if (!pbuflist
|| !pbuflist
->virt
)
228 goto els_iocb_free_pbuf_exit
;
230 INIT_LIST_HEAD(&pbuflist
->list
);
232 icmd
->un
.elsreq64
.bdl
.addrHigh
= putPaddrHigh(pbuflist
->phys
);
233 icmd
->un
.elsreq64
.bdl
.addrLow
= putPaddrLow(pbuflist
->phys
);
234 icmd
->un
.elsreq64
.bdl
.bdeFlags
= BUFF_TYPE_BLP_64
;
235 icmd
->un
.elsreq64
.remoteID
= did
; /* DID */
237 icmd
->un
.elsreq64
.bdl
.bdeSize
= (2 * sizeof(struct ulp_bde64
));
238 icmd
->ulpCommand
= CMD_ELS_REQUEST64_CR
;
239 icmd
->ulpTimeout
= phba
->fc_ratov
* 2;
241 icmd
->un
.elsreq64
.bdl
.bdeSize
= sizeof(struct ulp_bde64
);
242 icmd
->ulpCommand
= CMD_XMIT_ELS_RSP64_CX
;
244 icmd
->ulpBdeCount
= 1;
246 icmd
->ulpClass
= CLASS3
;
248 if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) {
249 icmd
->un
.elsreq64
.myID
= vport
->fc_myDID
;
251 /* For ELS_REQUEST64_CR, use the VPI by default */
252 icmd
->ulpContext
= vport
->vpi
+ phba
->vpi_base
;
254 /* The CT field must be 0=INVALID_RPI for the ECHO cmd */
255 if (elscmd
== ELS_CMD_ECHO
)
256 icmd
->ulpCt_l
= 0; /* context = invalid RPI */
258 icmd
->ulpCt_l
= 1; /* context = VPI */
261 bpl
= (struct ulp_bde64
*) pbuflist
->virt
;
262 bpl
->addrLow
= le32_to_cpu(putPaddrLow(pcmd
->phys
));
263 bpl
->addrHigh
= le32_to_cpu(putPaddrHigh(pcmd
->phys
));
264 bpl
->tus
.f
.bdeSize
= cmdSize
;
265 bpl
->tus
.f
.bdeFlags
= 0;
266 bpl
->tus
.w
= le32_to_cpu(bpl
->tus
.w
);
270 bpl
->addrLow
= le32_to_cpu(putPaddrLow(prsp
->phys
));
271 bpl
->addrHigh
= le32_to_cpu(putPaddrHigh(prsp
->phys
));
272 bpl
->tus
.f
.bdeSize
= FCELSSIZE
;
273 bpl
->tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64
;
274 bpl
->tus
.w
= le32_to_cpu(bpl
->tus
.w
);
277 /* prevent preparing iocb with NULL ndlp reference */
278 elsiocb
->context1
= lpfc_nlp_get(ndlp
);
279 if (!elsiocb
->context1
)
280 goto els_iocb_free_pbuf_exit
;
281 elsiocb
->context2
= pcmd
;
282 elsiocb
->context3
= pbuflist
;
283 elsiocb
->retry
= retry
;
284 elsiocb
->vport
= vport
;
285 elsiocb
->drvrTimeout
= (phba
->fc_ratov
<< 1) + LPFC_DRVR_TIMEOUT
;
288 list_add(&prsp
->list
, &pcmd
->list
);
291 /* Xmit ELS command <elsCmd> to remote NPORT <did> */
292 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
293 "0116 Xmit ELS command x%x to remote "
294 "NPORT x%x I/O tag: x%x, port state: x%x\n",
295 elscmd
, did
, elsiocb
->iotag
,
298 /* Xmit ELS response <elsCmd> to remote NPORT <did> */
299 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
300 "0117 Xmit ELS response x%x to remote "
301 "NPORT x%x I/O tag: x%x, size: x%x\n",
302 elscmd
, ndlp
->nlp_DID
, elsiocb
->iotag
,
307 els_iocb_free_pbuf_exit
:
309 lpfc_mbuf_free(phba
, prsp
->virt
, prsp
->phys
);
312 els_iocb_free_prsp_exit
:
313 lpfc_mbuf_free(phba
, pcmd
->virt
, pcmd
->phys
);
316 els_iocb_free_pcmb_exit
:
318 lpfc_sli_release_iocbq(phba
, elsiocb
);
323 * lpfc_issue_fabric_reglogin - Issue fabric registration login for a vport
324 * @vport: pointer to a host virtual N_Port data structure.
326 * This routine issues a fabric registration login for a @vport. An
327 * active ndlp node with Fabric_DID must already exist for this @vport.
328 * The routine invokes two mailbox commands to carry out fabric registration
329 * login through the HBA firmware: the first mailbox command requests the
330 * HBA to perform link configuration for the @vport; and the second mailbox
331 * command requests the HBA to perform the actual fabric registration login
335 * 0 - successfully issued fabric registration login for @vport
336 * -ENXIO -- failed to issue fabric registration login for @vport
339 lpfc_issue_fabric_reglogin(struct lpfc_vport
*vport
)
341 struct lpfc_hba
*phba
= vport
->phba
;
343 struct lpfc_dmabuf
*mp
;
344 struct lpfc_nodelist
*ndlp
;
345 struct serv_parm
*sp
;
349 sp
= &phba
->fc_fabparam
;
350 ndlp
= lpfc_findnode_did(vport
, Fabric_DID
);
351 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
)) {
356 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
362 vport
->port_state
= LPFC_FABRIC_CFG_LINK
;
363 lpfc_config_link(phba
, mbox
);
364 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
367 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
368 if (rc
== MBX_NOT_FINISHED
) {
373 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
378 rc
= lpfc_reg_rpi(phba
, vport
->vpi
, Fabric_DID
, (uint8_t *)sp
, mbox
, 0);
384 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_fabric_reg_login
;
386 /* increment the reference count on ndlp to hold reference
387 * for the callback routine.
389 mbox
->context2
= lpfc_nlp_get(ndlp
);
391 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
392 if (rc
== MBX_NOT_FINISHED
) {
394 goto fail_issue_reg_login
;
399 fail_issue_reg_login
:
400 /* decrement the reference count on ndlp just incremented
401 * for the failed mbox command.
404 mp
= (struct lpfc_dmabuf
*) mbox
->context1
;
405 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
408 mempool_free(mbox
, phba
->mbox_mem_pool
);
411 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
412 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
413 "0249 Cannot issue Register Fabric login: Err %d\n", err
);
418 * lpfc_issue_reg_vfi - Register VFI for this vport's fabric login
419 * @vport: pointer to a host virtual N_Port data structure.
421 * This routine issues a REG_VFI mailbox for the vfi, vpi, fcfi triplet for
422 * the @vport. This mailbox command is necessary for FCoE only.
425 * 0 - successfully issued REG_VFI for @vport
426 * A failure code otherwise.
429 lpfc_issue_reg_vfi(struct lpfc_vport
*vport
)
431 struct lpfc_hba
*phba
= vport
->phba
;
433 struct lpfc_nodelist
*ndlp
;
434 struct serv_parm
*sp
;
435 struct lpfc_dmabuf
*dmabuf
;
438 sp
= &phba
->fc_fabparam
;
439 ndlp
= lpfc_findnode_did(vport
, Fabric_DID
);
440 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
)) {
445 dmabuf
= kzalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
450 dmabuf
->virt
= lpfc_mbuf_alloc(phba
, MEM_PRI
, &dmabuf
->phys
);
453 goto fail_free_dmabuf
;
455 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
458 goto fail_free_coherent
;
460 vport
->port_state
= LPFC_FABRIC_CFG_LINK
;
461 memcpy(dmabuf
->virt
, &phba
->fc_fabparam
, sizeof(vport
->fc_sparam
));
462 lpfc_reg_vfi(mboxq
, vport
, dmabuf
->phys
);
463 mboxq
->mbox_cmpl
= lpfc_mbx_cmpl_reg_vfi
;
464 mboxq
->vport
= vport
;
465 mboxq
->context1
= dmabuf
;
466 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
467 if (rc
== MBX_NOT_FINISHED
) {
474 mempool_free(mboxq
, phba
->mbox_mem_pool
);
476 lpfc_mbuf_free(phba
, dmabuf
->virt
, dmabuf
->phys
);
480 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
481 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
482 "0289 Issue Register VFI failed: Err %d\n", rc
);
487 * lpfc_cmpl_els_flogi_fabric - Completion function for flogi to a fabric port
488 * @vport: pointer to a host virtual N_Port data structure.
489 * @ndlp: pointer to a node-list data structure.
490 * @sp: pointer to service parameter data structure.
491 * @irsp: pointer to the IOCB within the lpfc response IOCB.
493 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
494 * function to handle the completion of a Fabric Login (FLOGI) into a fabric
495 * port in a fabric topology. It properly sets up the parameters to the @ndlp
496 * from the IOCB response. It also check the newly assigned N_Port ID to the
497 * @vport against the previously assigned N_Port ID. If it is different from
498 * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine
499 * is invoked on all the remaining nodes with the @vport to unregister the
500 * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin()
501 * is invoked to register login to the fabric.
504 * 0 - Success (currently, always return 0)
507 lpfc_cmpl_els_flogi_fabric(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
508 struct serv_parm
*sp
, IOCB_t
*irsp
)
510 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
511 struct lpfc_hba
*phba
= vport
->phba
;
512 struct lpfc_nodelist
*np
;
513 struct lpfc_nodelist
*next_np
;
515 spin_lock_irq(shost
->host_lock
);
516 vport
->fc_flag
|= FC_FABRIC
;
517 spin_unlock_irq(shost
->host_lock
);
519 phba
->fc_edtov
= be32_to_cpu(sp
->cmn
.e_d_tov
);
520 if (sp
->cmn
.edtovResolution
) /* E_D_TOV ticks are in nanoseconds */
521 phba
->fc_edtov
= (phba
->fc_edtov
+ 999999) / 1000000;
523 phba
->fc_edtovResol
= sp
->cmn
.edtovResolution
;
524 phba
->fc_ratov
= (be32_to_cpu(sp
->cmn
.w2
.r_a_tov
) + 999) / 1000;
526 if (phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
) {
527 spin_lock_irq(shost
->host_lock
);
528 vport
->fc_flag
|= FC_PUBLIC_LOOP
;
529 spin_unlock_irq(shost
->host_lock
);
532 vport
->fc_myDID
= irsp
->un
.ulpWord
[4] & Mask_DID
;
533 memcpy(&ndlp
->nlp_portname
, &sp
->portName
, sizeof(struct lpfc_name
));
534 memcpy(&ndlp
->nlp_nodename
, &sp
->nodeName
, sizeof(struct lpfc_name
));
535 ndlp
->nlp_class_sup
= 0;
536 if (sp
->cls1
.classValid
)
537 ndlp
->nlp_class_sup
|= FC_COS_CLASS1
;
538 if (sp
->cls2
.classValid
)
539 ndlp
->nlp_class_sup
|= FC_COS_CLASS2
;
540 if (sp
->cls3
.classValid
)
541 ndlp
->nlp_class_sup
|= FC_COS_CLASS3
;
542 if (sp
->cls4
.classValid
)
543 ndlp
->nlp_class_sup
|= FC_COS_CLASS4
;
544 ndlp
->nlp_maxframe
= ((sp
->cmn
.bbRcvSizeMsb
& 0x0F) << 8) |
545 sp
->cmn
.bbRcvSizeLsb
;
546 memcpy(&phba
->fc_fabparam
, sp
, sizeof(struct serv_parm
));
548 if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) {
549 if (sp
->cmn
.response_multiple_NPort
) {
550 lpfc_printf_vlog(vport
, KERN_WARNING
,
552 "1816 FLOGI NPIV supported, "
553 "response data 0x%x\n",
554 sp
->cmn
.response_multiple_NPort
);
555 phba
->link_flag
|= LS_NPIV_FAB_SUPPORTED
;
557 /* Because we asked f/w for NPIV it still expects us
558 to call reg_vnpid atleast for the physcial host */
559 lpfc_printf_vlog(vport
, KERN_WARNING
,
561 "1817 Fabric does not support NPIV "
562 "- configuring single port mode.\n");
563 phba
->link_flag
&= ~LS_NPIV_FAB_SUPPORTED
;
567 if ((vport
->fc_prevDID
!= vport
->fc_myDID
) &&
568 !(vport
->fc_flag
& FC_VPORT_NEEDS_REG_VPI
)) {
570 /* If our NportID changed, we need to ensure all
571 * remaining NPORTs get unreg_login'ed.
573 list_for_each_entry_safe(np
, next_np
,
574 &vport
->fc_nodes
, nlp_listp
) {
575 if (!NLP_CHK_NODE_ACT(np
))
577 if ((np
->nlp_state
!= NLP_STE_NPR_NODE
) ||
578 !(np
->nlp_flag
& NLP_NPR_ADISC
))
580 spin_lock_irq(shost
->host_lock
);
581 np
->nlp_flag
&= ~NLP_NPR_ADISC
;
582 spin_unlock_irq(shost
->host_lock
);
583 lpfc_unreg_rpi(vport
, np
);
585 lpfc_cleanup_pending_mbox(vport
);
587 if (phba
->sli_rev
== LPFC_SLI_REV4
)
588 lpfc_sli4_unreg_all_rpis(vport
);
590 if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) {
591 lpfc_mbx_unreg_vpi(vport
);
592 spin_lock_irq(shost
->host_lock
);
593 vport
->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
594 spin_unlock_irq(shost
->host_lock
);
597 * If VPI is unreged, driver need to do INIT_VPI
598 * before re-registering
600 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
601 spin_lock_irq(shost
->host_lock
);
602 vport
->fc_flag
|= FC_VPORT_NEEDS_INIT_VPI
;
603 spin_unlock_irq(shost
->host_lock
);
605 } else if ((phba
->sli_rev
== LPFC_SLI_REV4
) &&
606 !(vport
->fc_flag
& FC_VPORT_NEEDS_REG_VPI
)) {
608 * Driver needs to re-reg VPI in order for f/w
609 * to update the MAC address.
611 lpfc_register_new_vport(phba
, vport
, ndlp
);
615 if (phba
->sli_rev
< LPFC_SLI_REV4
) {
616 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_REG_LOGIN_ISSUE
);
617 if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
&&
618 vport
->fc_flag
& FC_VPORT_NEEDS_REG_VPI
)
619 lpfc_register_new_vport(phba
, vport
, ndlp
);
621 lpfc_issue_fabric_reglogin(vport
);
623 ndlp
->nlp_type
|= NLP_FABRIC
;
624 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
625 if ((!(vport
->fc_flag
& FC_VPORT_NEEDS_REG_VPI
)) &&
626 (vport
->vpi_state
& LPFC_VPI_REGISTERED
)) {
627 lpfc_start_fdiscs(phba
);
628 lpfc_do_scr_ns_plogi(phba
, vport
);
629 } else if (vport
->fc_flag
& FC_VFI_REGISTERED
)
630 lpfc_issue_init_vpi(vport
);
632 lpfc_issue_reg_vfi(vport
);
637 * lpfc_cmpl_els_flogi_nport - Completion function for flogi to an N_Port
638 * @vport: pointer to a host virtual N_Port data structure.
639 * @ndlp: pointer to a node-list data structure.
640 * @sp: pointer to service parameter data structure.
642 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
643 * function to handle the completion of a Fabric Login (FLOGI) into an N_Port
644 * in a point-to-point topology. First, the @vport's N_Port Name is compared
645 * with the received N_Port Name: if the @vport's N_Port Name is greater than
646 * the received N_Port Name lexicographically, this node shall assign local
647 * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and
648 * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise,
649 * this node shall just wait for the remote node to issue PLOGI and assign
657 lpfc_cmpl_els_flogi_nport(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
658 struct serv_parm
*sp
)
660 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
661 struct lpfc_hba
*phba
= vport
->phba
;
665 spin_lock_irq(shost
->host_lock
);
666 vport
->fc_flag
&= ~(FC_FABRIC
| FC_PUBLIC_LOOP
);
667 spin_unlock_irq(shost
->host_lock
);
669 phba
->fc_edtov
= FF_DEF_EDTOV
;
670 phba
->fc_ratov
= FF_DEF_RATOV
;
671 rc
= memcmp(&vport
->fc_portname
, &sp
->portName
,
672 sizeof(vport
->fc_portname
));
674 /* This side will initiate the PLOGI */
675 spin_lock_irq(shost
->host_lock
);
676 vport
->fc_flag
|= FC_PT2PT_PLOGI
;
677 spin_unlock_irq(shost
->host_lock
);
680 * N_Port ID cannot be 0, set our to LocalID the other
681 * side will be RemoteID.
686 vport
->fc_myDID
= PT2PT_LocalID
;
688 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
692 lpfc_config_link(phba
, mbox
);
694 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
696 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
697 if (rc
== MBX_NOT_FINISHED
) {
698 mempool_free(mbox
, phba
->mbox_mem_pool
);
701 /* Decrement ndlp reference count indicating that ndlp can be
702 * safely released when other references to it are done.
706 ndlp
= lpfc_findnode_did(vport
, PT2PT_RemoteID
);
709 * Cannot find existing Fabric ndlp, so allocate a
712 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
715 lpfc_nlp_init(vport
, ndlp
, PT2PT_RemoteID
);
716 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
717 ndlp
= lpfc_enable_node(vport
, ndlp
,
718 NLP_STE_UNUSED_NODE
);
723 memcpy(&ndlp
->nlp_portname
, &sp
->portName
,
724 sizeof(struct lpfc_name
));
725 memcpy(&ndlp
->nlp_nodename
, &sp
->nodeName
,
726 sizeof(struct lpfc_name
));
727 /* Set state will put ndlp onto node list if not already done */
728 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
729 spin_lock_irq(shost
->host_lock
);
730 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
731 spin_unlock_irq(shost
->host_lock
);
733 /* This side will wait for the PLOGI, decrement ndlp reference
734 * count indicating that ndlp can be released when other
735 * references to it are done.
739 /* If we are pt2pt with another NPort, force NPIV off! */
740 phba
->sli3_options
&= ~LPFC_SLI3_NPIV_ENABLED
;
742 spin_lock_irq(shost
->host_lock
);
743 vport
->fc_flag
|= FC_PT2PT
;
744 spin_unlock_irq(shost
->host_lock
);
746 /* Start discovery - this should just do CLEAR_LA */
747 lpfc_disc_start(vport
);
754 * lpfc_cmpl_els_flogi - Completion callback function for flogi
755 * @phba: pointer to lpfc hba data structure.
756 * @cmdiocb: pointer to lpfc command iocb data structure.
757 * @rspiocb: pointer to lpfc response iocb data structure.
759 * This routine is the top-level completion callback function for issuing
760 * a Fabric Login (FLOGI) command. If the response IOCB reported error,
761 * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If
762 * retry has been made (either immediately or delayed with lpfc_els_retry()
763 * returning 1), the command IOCB will be released and function returned.
764 * If the retry attempt has been given up (possibly reach the maximum
765 * number of retries), one additional decrement of ndlp reference shall be
766 * invoked before going out after releasing the command IOCB. This will
767 * actually release the remote node (Note, lpfc_els_free_iocb() will also
768 * invoke one decrement of ndlp reference count). If no error reported in
769 * the IOCB status, the command Port ID field is used to determine whether
770 * this is a point-to-point topology or a fabric topology: if the Port ID
771 * field is assigned, it is a fabric topology; otherwise, it is a
772 * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or
773 * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the
774 * specific topology completion conditions.
777 lpfc_cmpl_els_flogi(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
778 struct lpfc_iocbq
*rspiocb
)
780 struct lpfc_vport
*vport
= cmdiocb
->vport
;
781 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
782 IOCB_t
*irsp
= &rspiocb
->iocb
;
783 struct lpfc_nodelist
*ndlp
= cmdiocb
->context1
;
784 struct lpfc_dmabuf
*pcmd
= cmdiocb
->context2
, *prsp
;
785 struct serv_parm
*sp
;
789 /* Check to see if link went down during discovery */
790 if (lpfc_els_chk_latt(vport
)) {
791 /* One additional decrement on node reference count to
792 * trigger the release of the node
798 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
799 "FLOGI cmpl: status:x%x/x%x state:x%x",
800 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
803 if (irsp
->ulpStatus
) {
805 * In case of FIP mode, perform roundrobin FCF failover
806 * due to new FCF discovery
808 if ((phba
->hba_flag
& HBA_FIP_SUPPORT
) &&
809 (phba
->fcf
.fcf_flag
& FCF_DISCOVERY
) &&
810 (irsp
->ulpStatus
!= IOSTAT_LOCAL_REJECT
) &&
811 (irsp
->un
.ulpWord
[4] != IOERR_SLI_ABORTED
)) {
812 lpfc_printf_log(phba
, KERN_WARNING
, LOG_FIP
| LOG_ELS
,
813 "2611 FLOGI failed on FCF (x%x), "
814 "status:x%x/x%x, tmo:x%x, perform "
815 "roundrobin FCF failover\n",
816 phba
->fcf
.current_rec
.fcf_indx
,
817 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
819 fcf_index
= lpfc_sli4_fcf_rr_next_index_get(phba
);
820 rc
= lpfc_sli4_fcf_rr_next_proc(vport
, fcf_index
);
826 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
827 "2858 FLOGI failure Status:x%x/x%x TMO:x%x\n",
828 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
831 /* Check for retry */
832 if (lpfc_els_retry(phba
, cmdiocb
, rspiocb
))
836 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
837 "0100 FLOGI failure Status:x%x/x%x TMO:x%x\n",
838 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
841 /* FLOGI failed, so there is no fabric */
842 spin_lock_irq(shost
->host_lock
);
843 vport
->fc_flag
&= ~(FC_FABRIC
| FC_PUBLIC_LOOP
);
844 spin_unlock_irq(shost
->host_lock
);
846 /* If private loop, then allow max outstanding els to be
847 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
848 * alpa map would take too long otherwise.
850 if (phba
->alpa_map
[0] == 0) {
851 vport
->cfg_discovery_threads
= LPFC_MAX_DISC_THREADS
;
852 if ((phba
->sli_rev
== LPFC_SLI_REV4
) &&
853 (!(vport
->fc_flag
& FC_VFI_REGISTERED
) ||
854 (vport
->fc_prevDID
!= vport
->fc_myDID
))) {
855 if (vport
->fc_flag
& FC_VFI_REGISTERED
)
856 lpfc_sli4_unreg_all_rpis(vport
);
857 lpfc_issue_reg_vfi(vport
);
864 spin_lock_irq(shost
->host_lock
);
865 vport
->fc_flag
&= ~FC_VPORT_CVL_RCVD
;
866 vport
->fc_flag
&= ~FC_VPORT_LOGO_RCVD
;
867 spin_unlock_irq(shost
->host_lock
);
870 * The FLogI succeeded. Sync the data for the CPU before
873 prsp
= list_get_first(&pcmd
->list
, struct lpfc_dmabuf
, list
);
875 sp
= prsp
->virt
+ sizeof(uint32_t);
877 /* FLOGI completes successfully */
878 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
879 "0101 FLOGI completes successfully "
880 "Data: x%x x%x x%x x%x\n",
881 irsp
->un
.ulpWord
[4], sp
->cmn
.e_d_tov
,
882 sp
->cmn
.w2
.r_a_tov
, sp
->cmn
.edtovResolution
);
884 if (vport
->port_state
== LPFC_FLOGI
) {
886 * If Common Service Parameters indicate Nport
887 * we are point to point, if Fport we are Fabric.
890 rc
= lpfc_cmpl_els_flogi_fabric(vport
, ndlp
, sp
, irsp
);
891 else if (!(phba
->hba_flag
& HBA_FCOE_MODE
))
892 rc
= lpfc_cmpl_els_flogi_nport(vport
, ndlp
, sp
);
894 lpfc_printf_vlog(vport
, KERN_ERR
,
896 "2831 FLOGI response with cleared Fabric "
897 "bit fcf_index 0x%x "
898 "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x "
900 "%02x%02x%02x%02x%02x%02x%02x%02x\n",
901 phba
->fcf
.current_rec
.fcf_indx
,
902 phba
->fcf
.current_rec
.switch_name
[0],
903 phba
->fcf
.current_rec
.switch_name
[1],
904 phba
->fcf
.current_rec
.switch_name
[2],
905 phba
->fcf
.current_rec
.switch_name
[3],
906 phba
->fcf
.current_rec
.switch_name
[4],
907 phba
->fcf
.current_rec
.switch_name
[5],
908 phba
->fcf
.current_rec
.switch_name
[6],
909 phba
->fcf
.current_rec
.switch_name
[7],
910 phba
->fcf
.current_rec
.fabric_name
[0],
911 phba
->fcf
.current_rec
.fabric_name
[1],
912 phba
->fcf
.current_rec
.fabric_name
[2],
913 phba
->fcf
.current_rec
.fabric_name
[3],
914 phba
->fcf
.current_rec
.fabric_name
[4],
915 phba
->fcf
.current_rec
.fabric_name
[5],
916 phba
->fcf
.current_rec
.fabric_name
[6],
917 phba
->fcf
.current_rec
.fabric_name
[7]);
919 spin_lock_irq(&phba
->hbalock
);
920 phba
->fcf
.fcf_flag
&= ~FCF_DISCOVERY
;
921 phba
->hba_flag
&= ~(FCF_RR_INPROG
| HBA_DEVLOSS_TMO
);
922 spin_unlock_irq(&phba
->hbalock
);
926 /* Mark the FCF discovery process done */
927 if (phba
->hba_flag
& HBA_FIP_SUPPORT
)
928 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_FIP
|
930 "2769 FLOGI to FCF (x%x) "
931 "completed successfully\n",
932 phba
->fcf
.current_rec
.fcf_indx
);
933 spin_lock_irq(&phba
->hbalock
);
934 phba
->fcf
.fcf_flag
&= ~FCF_DISCOVERY
;
935 phba
->hba_flag
&= ~(FCF_RR_INPROG
| HBA_DEVLOSS_TMO
);
936 spin_unlock_irq(&phba
->hbalock
);
944 if (!lpfc_error_lost_link(irsp
)) {
945 /* FLOGI failed, so just use loop map to make discovery list */
946 lpfc_disc_list_loopmap(vport
);
948 /* Start discovery */
949 lpfc_disc_start(vport
);
950 } else if (((irsp
->ulpStatus
!= IOSTAT_LOCAL_REJECT
) ||
951 ((irsp
->un
.ulpWord
[4] != IOERR_SLI_ABORTED
) &&
952 (irsp
->un
.ulpWord
[4] != IOERR_SLI_DOWN
))) &&
953 (phba
->link_state
!= LPFC_CLEAR_LA
)) {
954 /* If FLOGI failed enable link interrupt. */
955 lpfc_issue_clear_la(phba
, vport
);
958 lpfc_els_free_iocb(phba
, cmdiocb
);
962 * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport
963 * @vport: pointer to a host virtual N_Port data structure.
964 * @ndlp: pointer to a node-list data structure.
965 * @retry: number of retries to the command IOCB.
967 * This routine issues a Fabric Login (FLOGI) Request ELS command
968 * for a @vport. The initiator service parameters are put into the payload
969 * of the FLOGI Request IOCB and the top-level callback function pointer
970 * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
971 * function field. The lpfc_issue_fabric_iocb routine is invoked to send
972 * out FLOGI ELS command with one outstanding fabric IOCB at a time.
974 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
975 * will be incremented by 1 for holding the ndlp and the reference to ndlp
976 * will be stored into the context1 field of the IOCB for the completion
977 * callback function to the FLOGI ELS command.
980 * 0 - successfully issued flogi iocb for @vport
981 * 1 - failed to issue flogi iocb for @vport
984 lpfc_issue_els_flogi(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
987 struct lpfc_hba
*phba
= vport
->phba
;
988 struct serv_parm
*sp
;
990 struct lpfc_iocbq
*elsiocb
;
991 struct lpfc_sli_ring
*pring
;
997 pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
999 cmdsize
= (sizeof(uint32_t) + sizeof(struct serv_parm
));
1000 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
,
1001 ndlp
->nlp_DID
, ELS_CMD_FLOGI
);
1006 icmd
= &elsiocb
->iocb
;
1007 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
1009 /* For FLOGI request, remainder of payload is service parameters */
1010 *((uint32_t *) (pcmd
)) = ELS_CMD_FLOGI
;
1011 pcmd
+= sizeof(uint32_t);
1012 memcpy(pcmd
, &vport
->fc_sparam
, sizeof(struct serv_parm
));
1013 sp
= (struct serv_parm
*) pcmd
;
1015 /* Setup CSPs accordingly for Fabric */
1016 sp
->cmn
.e_d_tov
= 0;
1017 sp
->cmn
.w2
.r_a_tov
= 0;
1018 sp
->cls1
.classValid
= 0;
1019 sp
->cls2
.seqDelivery
= 1;
1020 sp
->cls3
.seqDelivery
= 1;
1021 if (sp
->cmn
.fcphLow
< FC_PH3
)
1022 sp
->cmn
.fcphLow
= FC_PH3
;
1023 if (sp
->cmn
.fcphHigh
< FC_PH3
)
1024 sp
->cmn
.fcphHigh
= FC_PH3
;
1026 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
1027 elsiocb
->iocb
.ulpCt_h
= ((SLI4_CT_FCFI
>> 1) & 1);
1028 elsiocb
->iocb
.ulpCt_l
= (SLI4_CT_FCFI
& 1);
1029 /* FLOGI needs to be 3 for WQE FCFI */
1030 /* Set the fcfi to the fcfi we registered with */
1031 elsiocb
->iocb
.ulpContext
= phba
->fcf
.fcfi
;
1032 } else if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) {
1033 sp
->cmn
.request_multiple_Nport
= 1;
1034 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
1039 if (phba
->fc_topology
!= LPFC_TOPOLOGY_LOOP
) {
1040 icmd
->un
.elsreq64
.myID
= 0;
1041 icmd
->un
.elsreq64
.fl
= 1;
1044 tmo
= phba
->fc_ratov
;
1045 phba
->fc_ratov
= LPFC_DISC_FLOGI_TMO
;
1046 lpfc_set_disctmo(vport
);
1047 phba
->fc_ratov
= tmo
;
1049 phba
->fc_stat
.elsXmitFLOGI
++;
1050 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_flogi
;
1052 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
1053 "Issue FLOGI: opt:x%x",
1054 phba
->sli3_options
, 0, 0);
1056 rc
= lpfc_issue_fabric_iocb(phba
, elsiocb
);
1057 if (rc
== IOCB_ERROR
) {
1058 lpfc_els_free_iocb(phba
, elsiocb
);
1065 * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs
1066 * @phba: pointer to lpfc hba data structure.
1068 * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
1069 * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
1070 * list and issues an abort IOCB commond on each outstanding IOCB that
1071 * contains a active Fabric_DID ndlp. Note that this function is to issue
1072 * the abort IOCB command on all the outstanding IOCBs, thus when this
1073 * function returns, it does not guarantee all the IOCBs are actually aborted.
1076 * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0)
1079 lpfc_els_abort_flogi(struct lpfc_hba
*phba
)
1081 struct lpfc_sli_ring
*pring
;
1082 struct lpfc_iocbq
*iocb
, *next_iocb
;
1083 struct lpfc_nodelist
*ndlp
;
1086 /* Abort outstanding I/O on NPort <nlp_DID> */
1087 lpfc_printf_log(phba
, KERN_INFO
, LOG_DISCOVERY
,
1088 "0201 Abort outstanding I/O on NPort x%x\n",
1091 pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
1094 * Check the txcmplq for an iocb that matches the nport the driver is
1097 spin_lock_irq(&phba
->hbalock
);
1098 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txcmplq
, list
) {
1100 if (icmd
->ulpCommand
== CMD_ELS_REQUEST64_CR
&&
1101 icmd
->un
.elsreq64
.bdl
.ulpIoTag32
) {
1102 ndlp
= (struct lpfc_nodelist
*)(iocb
->context1
);
1103 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
) &&
1104 (ndlp
->nlp_DID
== Fabric_DID
))
1105 lpfc_sli_issue_abort_iotag(phba
, pring
, iocb
);
1108 spin_unlock_irq(&phba
->hbalock
);
1114 * lpfc_initial_flogi - Issue an initial fabric login for a vport
1115 * @vport: pointer to a host virtual N_Port data structure.
1117 * This routine issues an initial Fabric Login (FLOGI) for the @vport
1118 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1119 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1120 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1121 * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
1122 * is then invoked with the @vport and the ndlp to perform the FLOGI for the
1126 * 0 - failed to issue initial flogi for @vport
1127 * 1 - successfully issued initial flogi for @vport
1130 lpfc_initial_flogi(struct lpfc_vport
*vport
)
1132 struct lpfc_hba
*phba
= vport
->phba
;
1133 struct lpfc_nodelist
*ndlp
;
1135 vport
->port_state
= LPFC_FLOGI
;
1136 lpfc_set_disctmo(vport
);
1138 /* First look for the Fabric ndlp */
1139 ndlp
= lpfc_findnode_did(vport
, Fabric_DID
);
1141 /* Cannot find existing Fabric ndlp, so allocate a new one */
1142 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
1145 lpfc_nlp_init(vport
, ndlp
, Fabric_DID
);
1146 /* Set the node type */
1147 ndlp
->nlp_type
|= NLP_FABRIC
;
1148 /* Put ndlp onto node list */
1149 lpfc_enqueue_node(vport
, ndlp
);
1150 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
1151 /* re-setup ndlp without removing from node list */
1152 ndlp
= lpfc_enable_node(vport
, ndlp
, NLP_STE_UNUSED_NODE
);
1157 if (lpfc_issue_els_flogi(vport
, ndlp
, 0)) {
1158 /* This decrement of reference count to node shall kick off
1159 * the release of the node.
1168 * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport
1169 * @vport: pointer to a host virtual N_Port data structure.
1171 * This routine issues an initial Fabric Discover (FDISC) for the @vport
1172 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1173 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1174 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1175 * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
1176 * is then invoked with the @vport and the ndlp to perform the FDISC for the
1180 * 0 - failed to issue initial fdisc for @vport
1181 * 1 - successfully issued initial fdisc for @vport
1184 lpfc_initial_fdisc(struct lpfc_vport
*vport
)
1186 struct lpfc_hba
*phba
= vport
->phba
;
1187 struct lpfc_nodelist
*ndlp
;
1189 /* First look for the Fabric ndlp */
1190 ndlp
= lpfc_findnode_did(vport
, Fabric_DID
);
1192 /* Cannot find existing Fabric ndlp, so allocate a new one */
1193 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
1196 lpfc_nlp_init(vport
, ndlp
, Fabric_DID
);
1197 /* Put ndlp onto node list */
1198 lpfc_enqueue_node(vport
, ndlp
);
1199 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
1200 /* re-setup ndlp without removing from node list */
1201 ndlp
= lpfc_enable_node(vport
, ndlp
, NLP_STE_UNUSED_NODE
);
1206 if (lpfc_issue_els_fdisc(vport
, ndlp
, 0)) {
1207 /* decrement node reference count to trigger the release of
1217 * lpfc_more_plogi - Check and issue remaining plogis for a vport
1218 * @vport: pointer to a host virtual N_Port data structure.
1220 * This routine checks whether there are more remaining Port Logins
1221 * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
1222 * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
1223 * to issue ELS PLOGIs up to the configured discover threads with the
1224 * @vport (@vport->cfg_discovery_threads). The function also decrement
1225 * the @vport's num_disc_node by 1 if it is not already 0.
1228 lpfc_more_plogi(struct lpfc_vport
*vport
)
1232 if (vport
->num_disc_nodes
)
1233 vport
->num_disc_nodes
--;
1235 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
1236 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
1237 "0232 Continue discovery with %d PLOGIs to go "
1238 "Data: x%x x%x x%x\n",
1239 vport
->num_disc_nodes
, vport
->fc_plogi_cnt
,
1240 vport
->fc_flag
, vport
->port_state
);
1241 /* Check to see if there are more PLOGIs to be sent */
1242 if (vport
->fc_flag
& FC_NLP_MORE
)
1243 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
1244 sentplogi
= lpfc_els_disc_plogi(vport
);
1250 * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp
1251 * @phba: pointer to lpfc hba data structure.
1252 * @prsp: pointer to response IOCB payload.
1253 * @ndlp: pointer to a node-list data structure.
1255 * This routine checks and indicates whether the WWPN of an N_Port, retrieved
1256 * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
1257 * The following cases are considered N_Port confirmed:
1258 * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
1259 * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
1260 * it does not have WWPN assigned either. If the WWPN is confirmed, the
1261 * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
1262 * 1) if there is a node on vport list other than the @ndlp with the same
1263 * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
1264 * on that node to release the RPI associated with the node; 2) if there is
1265 * no node found on vport list with the same WWPN of the N_Port PLOGI logged
1266 * into, a new node shall be allocated (or activated). In either case, the
1267 * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
1268 * be released and the new_ndlp shall be put on to the vport node list and
1269 * its pointer returned as the confirmed node.
1271 * Note that before the @ndlp got "released", the keepDID from not-matching
1272 * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
1273 * of the @ndlp. This is because the release of @ndlp is actually to put it
1274 * into an inactive state on the vport node list and the vport node list
1275 * management algorithm does not allow two node with a same DID.
1278 * pointer to the PLOGI N_Port @ndlp
1280 static struct lpfc_nodelist
*
1281 lpfc_plogi_confirm_nport(struct lpfc_hba
*phba
, uint32_t *prsp
,
1282 struct lpfc_nodelist
*ndlp
)
1284 struct lpfc_vport
*vport
= ndlp
->vport
;
1285 struct lpfc_nodelist
*new_ndlp
;
1286 struct lpfc_rport_data
*rdata
;
1287 struct fc_rport
*rport
;
1288 struct serv_parm
*sp
;
1289 uint8_t name
[sizeof(struct lpfc_name
)];
1290 uint32_t rc
, keepDID
= 0;
1293 struct lpfc_node_rrqs rrq
;
1295 /* Fabric nodes can have the same WWPN so we don't bother searching
1296 * by WWPN. Just return the ndlp that was given to us.
1298 if (ndlp
->nlp_type
& NLP_FABRIC
)
1301 sp
= (struct serv_parm
*) ((uint8_t *) prsp
+ sizeof(uint32_t));
1302 memset(name
, 0, sizeof(struct lpfc_name
));
1304 /* Now we find out if the NPort we are logging into, matches the WWPN
1305 * we have for that ndlp. If not, we have some work to do.
1307 new_ndlp
= lpfc_findnode_wwpn(vport
, &sp
->portName
);
1309 if (new_ndlp
== ndlp
&& NLP_CHK_NODE_ACT(new_ndlp
))
1311 memset(&rrq
.xri_bitmap
, 0, sizeof(new_ndlp
->active_rrqs
.xri_bitmap
));
1314 rc
= memcmp(&ndlp
->nlp_portname
, name
,
1315 sizeof(struct lpfc_name
));
1318 new_ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_ATOMIC
);
1321 lpfc_nlp_init(vport
, new_ndlp
, ndlp
->nlp_DID
);
1322 } else if (!NLP_CHK_NODE_ACT(new_ndlp
)) {
1323 rc
= memcmp(&ndlp
->nlp_portname
, name
,
1324 sizeof(struct lpfc_name
));
1327 new_ndlp
= lpfc_enable_node(vport
, new_ndlp
,
1328 NLP_STE_UNUSED_NODE
);
1331 keepDID
= new_ndlp
->nlp_DID
;
1332 if (phba
->sli_rev
== LPFC_SLI_REV4
)
1333 memcpy(&rrq
.xri_bitmap
,
1334 &new_ndlp
->active_rrqs
.xri_bitmap
,
1335 sizeof(new_ndlp
->active_rrqs
.xri_bitmap
));
1337 keepDID
= new_ndlp
->nlp_DID
;
1338 if (phba
->sli_rev
== LPFC_SLI_REV4
)
1339 memcpy(&rrq
.xri_bitmap
,
1340 &new_ndlp
->active_rrqs
.xri_bitmap
,
1341 sizeof(new_ndlp
->active_rrqs
.xri_bitmap
));
1344 lpfc_unreg_rpi(vport
, new_ndlp
);
1345 new_ndlp
->nlp_DID
= ndlp
->nlp_DID
;
1346 new_ndlp
->nlp_prev_state
= ndlp
->nlp_prev_state
;
1347 if (phba
->sli_rev
== LPFC_SLI_REV4
)
1348 memcpy(new_ndlp
->active_rrqs
.xri_bitmap
,
1349 &ndlp
->active_rrqs
.xri_bitmap
,
1350 sizeof(ndlp
->active_rrqs
.xri_bitmap
));
1352 if (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
)
1353 new_ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
1354 ndlp
->nlp_flag
&= ~NLP_NPR_2B_DISC
;
1356 /* Set state will put new_ndlp on to node list if not already done */
1357 lpfc_nlp_set_state(vport
, new_ndlp
, ndlp
->nlp_state
);
1359 /* Move this back to NPR state */
1360 if (memcmp(&ndlp
->nlp_portname
, name
, sizeof(struct lpfc_name
)) == 0) {
1361 /* The new_ndlp is replacing ndlp totally, so we need
1362 * to put ndlp on UNUSED list and try to free it.
1365 /* Fix up the rport accordingly */
1366 rport
= ndlp
->rport
;
1368 rdata
= rport
->dd_data
;
1369 if (rdata
->pnode
== ndlp
) {
1372 rdata
->pnode
= lpfc_nlp_get(new_ndlp
);
1373 new_ndlp
->rport
= rport
;
1375 new_ndlp
->nlp_type
= ndlp
->nlp_type
;
1377 /* We shall actually free the ndlp with both nlp_DID and
1378 * nlp_portname fields equals 0 to avoid any ndlp on the
1379 * nodelist never to be used.
1381 if (ndlp
->nlp_DID
== 0) {
1382 spin_lock_irq(&phba
->ndlp_lock
);
1383 NLP_SET_FREE_REQ(ndlp
);
1384 spin_unlock_irq(&phba
->ndlp_lock
);
1387 /* Two ndlps cannot have the same did on the nodelist */
1388 ndlp
->nlp_DID
= keepDID
;
1389 if (phba
->sli_rev
== LPFC_SLI_REV4
)
1390 memcpy(&ndlp
->active_rrqs
.xri_bitmap
,
1392 sizeof(ndlp
->active_rrqs
.xri_bitmap
));
1393 lpfc_drop_node(vport
, ndlp
);
1396 lpfc_unreg_rpi(vport
, ndlp
);
1397 /* Two ndlps cannot have the same did */
1398 ndlp
->nlp_DID
= keepDID
;
1399 if (phba
->sli_rev
== LPFC_SLI_REV4
)
1400 memcpy(&ndlp
->active_rrqs
.xri_bitmap
,
1402 sizeof(ndlp
->active_rrqs
.xri_bitmap
));
1403 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
1404 /* Since we are swapping the ndlp passed in with the new one
1405 * and the did has already been swapped, copy over the
1408 memcpy(&new_ndlp
->nlp_portname
, &ndlp
->nlp_portname
,
1409 sizeof(struct lpfc_name
));
1410 memcpy(&new_ndlp
->nlp_nodename
, &ndlp
->nlp_nodename
,
1411 sizeof(struct lpfc_name
));
1412 new_ndlp
->nlp_state
= ndlp
->nlp_state
;
1413 /* Fix up the rport accordingly */
1414 rport
= ndlp
->rport
;
1416 rdata
= rport
->dd_data
;
1417 put_node
= rdata
->pnode
!= NULL
;
1418 put_rport
= ndlp
->rport
!= NULL
;
1419 rdata
->pnode
= NULL
;
1424 put_device(&rport
->dev
);
1431 * lpfc_end_rscn - Check and handle more rscn for a vport
1432 * @vport: pointer to a host virtual N_Port data structure.
1434 * This routine checks whether more Registration State Change
1435 * Notifications (RSCNs) came in while the discovery state machine was in
1436 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1437 * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1438 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1439 * handling the RSCNs.
1442 lpfc_end_rscn(struct lpfc_vport
*vport
)
1444 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1446 if (vport
->fc_flag
& FC_RSCN_MODE
) {
1448 * Check to see if more RSCNs came in while we were
1449 * processing this one.
1451 if (vport
->fc_rscn_id_cnt
||
1452 (vport
->fc_flag
& FC_RSCN_DISCOVERY
) != 0)
1453 lpfc_els_handle_rscn(vport
);
1455 spin_lock_irq(shost
->host_lock
);
1456 vport
->fc_flag
&= ~FC_RSCN_MODE
;
1457 spin_unlock_irq(shost
->host_lock
);
1463 * lpfc_cmpl_els_rrq - Completion handled for els RRQs.
1464 * @phba: pointer to lpfc hba data structure.
1465 * @cmdiocb: pointer to lpfc command iocb data structure.
1466 * @rspiocb: pointer to lpfc response iocb data structure.
1468 * This routine will call the clear rrq function to free the rrq and
1469 * clear the xri's bit in the ndlp's xri_bitmap. If the ndlp does not
1470 * exist then the clear_rrq is still called because the rrq needs to
1475 lpfc_cmpl_els_rrq(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
1476 struct lpfc_iocbq
*rspiocb
)
1478 struct lpfc_vport
*vport
= cmdiocb
->vport
;
1480 struct lpfc_nodelist
*ndlp
;
1481 struct lpfc_node_rrq
*rrq
;
1483 /* we pass cmdiocb to state machine which needs rspiocb as well */
1484 rrq
= cmdiocb
->context_un
.rrq
;
1485 cmdiocb
->context_un
.rsp_iocb
= rspiocb
;
1487 irsp
= &rspiocb
->iocb
;
1488 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
1489 "RRQ cmpl: status:x%x/x%x did:x%x",
1490 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1491 irsp
->un
.elsreq64
.remoteID
);
1493 ndlp
= lpfc_findnode_did(vport
, irsp
->un
.elsreq64
.remoteID
);
1494 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
) || ndlp
!= rrq
->ndlp
) {
1495 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
1496 "2882 RRQ completes to NPort x%x "
1497 "with no ndlp. Data: x%x x%x x%x\n",
1498 irsp
->un
.elsreq64
.remoteID
,
1499 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1504 /* rrq completes to NPort <nlp_DID> */
1505 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
1506 "2880 RRQ completes to NPort x%x "
1507 "Data: x%x x%x x%x x%x x%x\n",
1508 ndlp
->nlp_DID
, irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1509 irsp
->ulpTimeout
, rrq
->xritag
, rrq
->rxid
);
1511 if (irsp
->ulpStatus
) {
1512 /* Check for retry */
1513 /* RRQ failed Don't print the vport to vport rjts */
1514 if (irsp
->ulpStatus
!= IOSTAT_LS_RJT
||
1515 (((irsp
->un
.ulpWord
[4]) >> 16 != LSRJT_INVALID_CMD
) &&
1516 ((irsp
->un
.ulpWord
[4]) >> 16 != LSRJT_UNABLE_TPC
)) ||
1517 (phba
)->pport
->cfg_log_verbose
& LOG_ELS
)
1518 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
1519 "2881 RRQ failure DID:%06X Status:x%x/x%x\n",
1520 ndlp
->nlp_DID
, irsp
->ulpStatus
,
1521 irsp
->un
.ulpWord
[4]);
1525 lpfc_clr_rrq_active(phba
, rrq
->xritag
, rrq
);
1526 lpfc_els_free_iocb(phba
, cmdiocb
);
1530 * lpfc_cmpl_els_plogi - Completion callback function for plogi
1531 * @phba: pointer to lpfc hba data structure.
1532 * @cmdiocb: pointer to lpfc command iocb data structure.
1533 * @rspiocb: pointer to lpfc response iocb data structure.
1535 * This routine is the completion callback function for issuing the Port
1536 * Login (PLOGI) command. For PLOGI completion, there must be an active
1537 * ndlp on the vport node list that matches the remote node ID from the
1538 * PLOGI reponse IOCB. If such ndlp does not exist, the PLOGI is simply
1539 * ignored and command IOCB released. The PLOGI response IOCB status is
1540 * checked for error conditons. If there is error status reported, PLOGI
1541 * retry shall be attempted by invoking the lpfc_els_retry() routine.
1542 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1543 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1544 * (DSM) is set for this PLOGI completion. Finally, it checks whether
1545 * there are additional N_Port nodes with the vport that need to perform
1546 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
1550 lpfc_cmpl_els_plogi(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
1551 struct lpfc_iocbq
*rspiocb
)
1553 struct lpfc_vport
*vport
= cmdiocb
->vport
;
1554 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1556 struct lpfc_nodelist
*ndlp
;
1557 struct lpfc_dmabuf
*prsp
;
1558 int disc
, rc
, did
, type
;
1560 /* we pass cmdiocb to state machine which needs rspiocb as well */
1561 cmdiocb
->context_un
.rsp_iocb
= rspiocb
;
1563 irsp
= &rspiocb
->iocb
;
1564 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
1565 "PLOGI cmpl: status:x%x/x%x did:x%x",
1566 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1567 irsp
->un
.elsreq64
.remoteID
);
1569 ndlp
= lpfc_findnode_did(vport
, irsp
->un
.elsreq64
.remoteID
);
1570 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
)) {
1571 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
1572 "0136 PLOGI completes to NPort x%x "
1573 "with no ndlp. Data: x%x x%x x%x\n",
1574 irsp
->un
.elsreq64
.remoteID
,
1575 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1580 /* Since ndlp can be freed in the disc state machine, note if this node
1581 * is being used during discovery.
1583 spin_lock_irq(shost
->host_lock
);
1584 disc
= (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
);
1585 ndlp
->nlp_flag
&= ~NLP_NPR_2B_DISC
;
1586 spin_unlock_irq(shost
->host_lock
);
1589 /* PLOGI completes to NPort <nlp_DID> */
1590 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
1591 "0102 PLOGI completes to NPort x%x "
1592 "Data: x%x x%x x%x x%x x%x\n",
1593 ndlp
->nlp_DID
, irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1594 irsp
->ulpTimeout
, disc
, vport
->num_disc_nodes
);
1595 /* Check to see if link went down during discovery */
1596 if (lpfc_els_chk_latt(vport
)) {
1597 spin_lock_irq(shost
->host_lock
);
1598 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
1599 spin_unlock_irq(shost
->host_lock
);
1603 /* ndlp could be freed in DSM, save these values now */
1604 type
= ndlp
->nlp_type
;
1605 did
= ndlp
->nlp_DID
;
1607 if (irsp
->ulpStatus
) {
1608 /* Check for retry */
1609 if (lpfc_els_retry(phba
, cmdiocb
, rspiocb
)) {
1610 /* ELS command is being retried */
1612 spin_lock_irq(shost
->host_lock
);
1613 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
1614 spin_unlock_irq(shost
->host_lock
);
1618 /* PLOGI failed Don't print the vport to vport rjts */
1619 if (irsp
->ulpStatus
!= IOSTAT_LS_RJT
||
1620 (((irsp
->un
.ulpWord
[4]) >> 16 != LSRJT_INVALID_CMD
) &&
1621 ((irsp
->un
.ulpWord
[4]) >> 16 != LSRJT_UNABLE_TPC
)) ||
1622 (phba
)->pport
->cfg_log_verbose
& LOG_ELS
)
1623 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
1624 "2753 PLOGI failure DID:%06X Status:x%x/x%x\n",
1625 ndlp
->nlp_DID
, irsp
->ulpStatus
,
1626 irsp
->un
.ulpWord
[4]);
1627 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1628 if (lpfc_error_lost_link(irsp
))
1629 rc
= NLP_STE_FREED_NODE
;
1631 rc
= lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
1632 NLP_EVT_CMPL_PLOGI
);
1634 /* Good status, call state machine */
1635 prsp
= list_entry(((struct lpfc_dmabuf
*)
1636 cmdiocb
->context2
)->list
.next
,
1637 struct lpfc_dmabuf
, list
);
1638 ndlp
= lpfc_plogi_confirm_nport(phba
, prsp
->virt
, ndlp
);
1639 rc
= lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
1640 NLP_EVT_CMPL_PLOGI
);
1643 if (disc
&& vport
->num_disc_nodes
) {
1644 /* Check to see if there are more PLOGIs to be sent */
1645 lpfc_more_plogi(vport
);
1647 if (vport
->num_disc_nodes
== 0) {
1648 spin_lock_irq(shost
->host_lock
);
1649 vport
->fc_flag
&= ~FC_NDISC_ACTIVE
;
1650 spin_unlock_irq(shost
->host_lock
);
1652 lpfc_can_disctmo(vport
);
1653 lpfc_end_rscn(vport
);
1658 lpfc_els_free_iocb(phba
, cmdiocb
);
1663 * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
1664 * @vport: pointer to a host virtual N_Port data structure.
1665 * @did: destination port identifier.
1666 * @retry: number of retries to the command IOCB.
1668 * This routine issues a Port Login (PLOGI) command to a remote N_Port
1669 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
1670 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
1671 * This routine constructs the proper feilds of the PLOGI IOCB and invokes
1672 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
1674 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1675 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1676 * will be stored into the context1 field of the IOCB for the completion
1677 * callback function to the PLOGI ELS command.
1680 * 0 - Successfully issued a plogi for @vport
1681 * 1 - failed to issue a plogi for @vport
1684 lpfc_issue_els_plogi(struct lpfc_vport
*vport
, uint32_t did
, uint8_t retry
)
1686 struct lpfc_hba
*phba
= vport
->phba
;
1687 struct serv_parm
*sp
;
1689 struct lpfc_nodelist
*ndlp
;
1690 struct lpfc_iocbq
*elsiocb
;
1691 struct lpfc_sli
*psli
;
1698 ndlp
= lpfc_findnode_did(vport
, did
);
1699 if (ndlp
&& !NLP_CHK_NODE_ACT(ndlp
))
1702 /* If ndlp is not NULL, we will bump the reference count on it */
1703 cmdsize
= (sizeof(uint32_t) + sizeof(struct serv_parm
));
1704 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
, did
,
1709 icmd
= &elsiocb
->iocb
;
1710 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
1712 /* For PLOGI request, remainder of payload is service parameters */
1713 *((uint32_t *) (pcmd
)) = ELS_CMD_PLOGI
;
1714 pcmd
+= sizeof(uint32_t);
1715 memcpy(pcmd
, &vport
->fc_sparam
, sizeof(struct serv_parm
));
1716 sp
= (struct serv_parm
*) pcmd
;
1719 * If we are a N-port connected to a Fabric, fix-up paramm's so logins
1720 * to device on remote loops work.
1722 if ((vport
->fc_flag
& FC_FABRIC
) && !(vport
->fc_flag
& FC_PUBLIC_LOOP
))
1723 sp
->cmn
.altBbCredit
= 1;
1725 if (sp
->cmn
.fcphLow
< FC_PH_4_3
)
1726 sp
->cmn
.fcphLow
= FC_PH_4_3
;
1728 if (sp
->cmn
.fcphHigh
< FC_PH3
)
1729 sp
->cmn
.fcphHigh
= FC_PH3
;
1731 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
1732 "Issue PLOGI: did:x%x",
1735 phba
->fc_stat
.elsXmitPLOGI
++;
1736 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_plogi
;
1737 ret
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
1739 if (ret
== IOCB_ERROR
) {
1740 lpfc_els_free_iocb(phba
, elsiocb
);
1747 * lpfc_cmpl_els_prli - Completion callback function for prli
1748 * @phba: pointer to lpfc hba data structure.
1749 * @cmdiocb: pointer to lpfc command iocb data structure.
1750 * @rspiocb: pointer to lpfc response iocb data structure.
1752 * This routine is the completion callback function for a Process Login
1753 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
1754 * status. If there is error status reported, PRLI retry shall be attempted
1755 * by invoking the lpfc_els_retry() routine. Otherwise, the state
1756 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
1757 * ndlp to mark the PRLI completion.
1760 lpfc_cmpl_els_prli(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
1761 struct lpfc_iocbq
*rspiocb
)
1763 struct lpfc_vport
*vport
= cmdiocb
->vport
;
1764 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1766 struct lpfc_sli
*psli
;
1767 struct lpfc_nodelist
*ndlp
;
1770 /* we pass cmdiocb to state machine which needs rspiocb as well */
1771 cmdiocb
->context_un
.rsp_iocb
= rspiocb
;
1773 irsp
= &(rspiocb
->iocb
);
1774 ndlp
= (struct lpfc_nodelist
*) cmdiocb
->context1
;
1775 spin_lock_irq(shost
->host_lock
);
1776 ndlp
->nlp_flag
&= ~NLP_PRLI_SND
;
1777 spin_unlock_irq(shost
->host_lock
);
1779 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
1780 "PRLI cmpl: status:x%x/x%x did:x%x",
1781 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1783 /* PRLI completes to NPort <nlp_DID> */
1784 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
1785 "0103 PRLI completes to NPort x%x "
1786 "Data: x%x x%x x%x x%x\n",
1787 ndlp
->nlp_DID
, irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1788 irsp
->ulpTimeout
, vport
->num_disc_nodes
);
1790 vport
->fc_prli_sent
--;
1791 /* Check to see if link went down during discovery */
1792 if (lpfc_els_chk_latt(vport
))
1795 if (irsp
->ulpStatus
) {
1796 /* Check for retry */
1797 if (lpfc_els_retry(phba
, cmdiocb
, rspiocb
)) {
1798 /* ELS command is being retried */
1802 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
1803 "2754 PRLI failure DID:%06X Status:x%x/x%x\n",
1804 ndlp
->nlp_DID
, irsp
->ulpStatus
,
1805 irsp
->un
.ulpWord
[4]);
1806 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1807 if (lpfc_error_lost_link(irsp
))
1810 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
1813 /* Good status, call state machine */
1814 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
1817 lpfc_els_free_iocb(phba
, cmdiocb
);
1822 * lpfc_issue_els_prli - Issue a prli iocb command for a vport
1823 * @vport: pointer to a host virtual N_Port data structure.
1824 * @ndlp: pointer to a node-list data structure.
1825 * @retry: number of retries to the command IOCB.
1827 * This routine issues a Process Login (PRLI) ELS command for the
1828 * @vport. The PRLI service parameters are set up in the payload of the
1829 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
1830 * is put to the IOCB completion callback func field before invoking the
1831 * routine lpfc_sli_issue_iocb() to send out PRLI command.
1833 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1834 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1835 * will be stored into the context1 field of the IOCB for the completion
1836 * callback function to the PRLI ELS command.
1839 * 0 - successfully issued prli iocb command for @vport
1840 * 1 - failed to issue prli iocb command for @vport
1843 lpfc_issue_els_prli(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1846 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1847 struct lpfc_hba
*phba
= vport
->phba
;
1850 struct lpfc_iocbq
*elsiocb
;
1854 cmdsize
= (sizeof(uint32_t) + sizeof(PRLI
));
1855 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
,
1856 ndlp
->nlp_DID
, ELS_CMD_PRLI
);
1860 icmd
= &elsiocb
->iocb
;
1861 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
1863 /* For PRLI request, remainder of payload is service parameters */
1864 memset(pcmd
, 0, (sizeof(PRLI
) + sizeof(uint32_t)));
1865 *((uint32_t *) (pcmd
)) = ELS_CMD_PRLI
;
1866 pcmd
+= sizeof(uint32_t);
1868 /* For PRLI, remainder of payload is PRLI parameter page */
1869 npr
= (PRLI
*) pcmd
;
1871 * If our firmware version is 3.20 or later,
1872 * set the following bits for FC-TAPE support.
1874 if (phba
->vpd
.rev
.feaLevelHigh
>= 0x02) {
1875 npr
->ConfmComplAllowed
= 1;
1877 npr
->TaskRetryIdReq
= 1;
1879 npr
->estabImagePair
= 1;
1880 npr
->readXferRdyDis
= 1;
1882 /* For FCP support */
1883 npr
->prliType
= PRLI_FCP_TYPE
;
1884 npr
->initiatorFunc
= 1;
1886 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
1887 "Issue PRLI: did:x%x",
1888 ndlp
->nlp_DID
, 0, 0);
1890 phba
->fc_stat
.elsXmitPRLI
++;
1891 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_prli
;
1892 spin_lock_irq(shost
->host_lock
);
1893 ndlp
->nlp_flag
|= NLP_PRLI_SND
;
1894 spin_unlock_irq(shost
->host_lock
);
1895 if (lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0) ==
1897 spin_lock_irq(shost
->host_lock
);
1898 ndlp
->nlp_flag
&= ~NLP_PRLI_SND
;
1899 spin_unlock_irq(shost
->host_lock
);
1900 lpfc_els_free_iocb(phba
, elsiocb
);
1903 vport
->fc_prli_sent
++;
1908 * lpfc_rscn_disc - Perform rscn discovery for a vport
1909 * @vport: pointer to a host virtual N_Port data structure.
1911 * This routine performs Registration State Change Notification (RSCN)
1912 * discovery for a @vport. If the @vport's node port recovery count is not
1913 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
1914 * the nodes that need recovery. If none of the PLOGI were needed through
1915 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
1916 * invoked to check and handle possible more RSCN came in during the period
1917 * of processing the current ones.
1920 lpfc_rscn_disc(struct lpfc_vport
*vport
)
1922 lpfc_can_disctmo(vport
);
1924 /* RSCN discovery */
1925 /* go thru NPR nodes and issue ELS PLOGIs */
1926 if (vport
->fc_npr_cnt
)
1927 if (lpfc_els_disc_plogi(vport
))
1930 lpfc_end_rscn(vport
);
1934 * lpfc_adisc_done - Complete the adisc phase of discovery
1935 * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
1937 * This function is called when the final ADISC is completed during discovery.
1938 * This function handles clearing link attention or issuing reg_vpi depending
1939 * on whether npiv is enabled. This function also kicks off the PLOGI phase of
1941 * This function is called with no locks held.
1944 lpfc_adisc_done(struct lpfc_vport
*vport
)
1946 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1947 struct lpfc_hba
*phba
= vport
->phba
;
1950 * For NPIV, cmpl_reg_vpi will set port_state to READY,
1951 * and continue discovery.
1953 if ((phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
1954 !(vport
->fc_flag
& FC_RSCN_MODE
) &&
1955 (phba
->sli_rev
< LPFC_SLI_REV4
)) {
1956 lpfc_issue_reg_vpi(phba
, vport
);
1960 * For SLI2, we need to set port_state to READY
1961 * and continue discovery.
1963 if (vport
->port_state
< LPFC_VPORT_READY
) {
1964 /* If we get here, there is nothing to ADISC */
1965 if (vport
->port_type
== LPFC_PHYSICAL_PORT
)
1966 lpfc_issue_clear_la(phba
, vport
);
1967 if (!(vport
->fc_flag
& FC_ABORT_DISCOVERY
)) {
1968 vport
->num_disc_nodes
= 0;
1969 /* go thru NPR list, issue ELS PLOGIs */
1970 if (vport
->fc_npr_cnt
)
1971 lpfc_els_disc_plogi(vport
);
1972 if (!vport
->num_disc_nodes
) {
1973 spin_lock_irq(shost
->host_lock
);
1974 vport
->fc_flag
&= ~FC_NDISC_ACTIVE
;
1975 spin_unlock_irq(shost
->host_lock
);
1976 lpfc_can_disctmo(vport
);
1977 lpfc_end_rscn(vport
);
1980 vport
->port_state
= LPFC_VPORT_READY
;
1982 lpfc_rscn_disc(vport
);
1986 * lpfc_more_adisc - Issue more adisc as needed
1987 * @vport: pointer to a host virtual N_Port data structure.
1989 * This routine determines whether there are more ndlps on a @vport
1990 * node list need to have Address Discover (ADISC) issued. If so, it will
1991 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
1992 * remaining nodes which need to have ADISC sent.
1995 lpfc_more_adisc(struct lpfc_vport
*vport
)
1999 if (vport
->num_disc_nodes
)
2000 vport
->num_disc_nodes
--;
2001 /* Continue discovery with <num_disc_nodes> ADISCs to go */
2002 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
2003 "0210 Continue discovery with %d ADISCs to go "
2004 "Data: x%x x%x x%x\n",
2005 vport
->num_disc_nodes
, vport
->fc_adisc_cnt
,
2006 vport
->fc_flag
, vport
->port_state
);
2007 /* Check to see if there are more ADISCs to be sent */
2008 if (vport
->fc_flag
& FC_NLP_MORE
) {
2009 lpfc_set_disctmo(vport
);
2010 /* go thru NPR nodes and issue any remaining ELS ADISCs */
2011 sentadisc
= lpfc_els_disc_adisc(vport
);
2013 if (!vport
->num_disc_nodes
)
2014 lpfc_adisc_done(vport
);
2019 * lpfc_cmpl_els_adisc - Completion callback function for adisc
2020 * @phba: pointer to lpfc hba data structure.
2021 * @cmdiocb: pointer to lpfc command iocb data structure.
2022 * @rspiocb: pointer to lpfc response iocb data structure.
2024 * This routine is the completion function for issuing the Address Discover
2025 * (ADISC) command. It first checks to see whether link went down during
2026 * the discovery process. If so, the node will be marked as node port
2027 * recovery for issuing discover IOCB by the link attention handler and
2028 * exit. Otherwise, the response status is checked. If error was reported
2029 * in the response status, the ADISC command shall be retried by invoking
2030 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
2031 * the response status, the state machine is invoked to set transition
2032 * with respect to NLP_EVT_CMPL_ADISC event.
2035 lpfc_cmpl_els_adisc(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
2036 struct lpfc_iocbq
*rspiocb
)
2038 struct lpfc_vport
*vport
= cmdiocb
->vport
;
2039 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2041 struct lpfc_nodelist
*ndlp
;
2044 /* we pass cmdiocb to state machine which needs rspiocb as well */
2045 cmdiocb
->context_un
.rsp_iocb
= rspiocb
;
2047 irsp
= &(rspiocb
->iocb
);
2048 ndlp
= (struct lpfc_nodelist
*) cmdiocb
->context1
;
2050 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
2051 "ADISC cmpl: status:x%x/x%x did:x%x",
2052 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
2055 /* Since ndlp can be freed in the disc state machine, note if this node
2056 * is being used during discovery.
2058 spin_lock_irq(shost
->host_lock
);
2059 disc
= (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
);
2060 ndlp
->nlp_flag
&= ~(NLP_ADISC_SND
| NLP_NPR_2B_DISC
);
2061 spin_unlock_irq(shost
->host_lock
);
2062 /* ADISC completes to NPort <nlp_DID> */
2063 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
2064 "0104 ADISC completes to NPort x%x "
2065 "Data: x%x x%x x%x x%x x%x\n",
2066 ndlp
->nlp_DID
, irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
2067 irsp
->ulpTimeout
, disc
, vport
->num_disc_nodes
);
2068 /* Check to see if link went down during discovery */
2069 if (lpfc_els_chk_latt(vport
)) {
2070 spin_lock_irq(shost
->host_lock
);
2071 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
2072 spin_unlock_irq(shost
->host_lock
);
2076 if (irsp
->ulpStatus
) {
2077 /* Check for retry */
2078 if (lpfc_els_retry(phba
, cmdiocb
, rspiocb
)) {
2079 /* ELS command is being retried */
2081 spin_lock_irq(shost
->host_lock
);
2082 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
2083 spin_unlock_irq(shost
->host_lock
);
2084 lpfc_set_disctmo(vport
);
2089 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
2090 "2755 ADISC failure DID:%06X Status:x%x/x%x\n",
2091 ndlp
->nlp_DID
, irsp
->ulpStatus
,
2092 irsp
->un
.ulpWord
[4]);
2093 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2094 if (!lpfc_error_lost_link(irsp
))
2095 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
2096 NLP_EVT_CMPL_ADISC
);
2098 /* Good status, call state machine */
2099 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
2100 NLP_EVT_CMPL_ADISC
);
2102 /* Check to see if there are more ADISCs to be sent */
2103 if (disc
&& vport
->num_disc_nodes
)
2104 lpfc_more_adisc(vport
);
2106 lpfc_els_free_iocb(phba
, cmdiocb
);
2111 * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
2112 * @vport: pointer to a virtual N_Port data structure.
2113 * @ndlp: pointer to a node-list data structure.
2114 * @retry: number of retries to the command IOCB.
2116 * This routine issues an Address Discover (ADISC) for an @ndlp on a
2117 * @vport. It prepares the payload of the ADISC ELS command, updates the
2118 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
2119 * to issue the ADISC ELS command.
2121 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2122 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2123 * will be stored into the context1 field of the IOCB for the completion
2124 * callback function to the ADISC ELS command.
2127 * 0 - successfully issued adisc
2128 * 1 - failed to issue adisc
2131 lpfc_issue_els_adisc(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2134 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2135 struct lpfc_hba
*phba
= vport
->phba
;
2138 struct lpfc_iocbq
*elsiocb
;
2142 cmdsize
= (sizeof(uint32_t) + sizeof(ADISC
));
2143 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
,
2144 ndlp
->nlp_DID
, ELS_CMD_ADISC
);
2148 icmd
= &elsiocb
->iocb
;
2149 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
2151 /* For ADISC request, remainder of payload is service parameters */
2152 *((uint32_t *) (pcmd
)) = ELS_CMD_ADISC
;
2153 pcmd
+= sizeof(uint32_t);
2155 /* Fill in ADISC payload */
2156 ap
= (ADISC
*) pcmd
;
2157 ap
->hardAL_PA
= phba
->fc_pref_ALPA
;
2158 memcpy(&ap
->portName
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
2159 memcpy(&ap
->nodeName
, &vport
->fc_nodename
, sizeof(struct lpfc_name
));
2160 ap
->DID
= be32_to_cpu(vport
->fc_myDID
);
2162 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
2163 "Issue ADISC: did:x%x",
2164 ndlp
->nlp_DID
, 0, 0);
2166 phba
->fc_stat
.elsXmitADISC
++;
2167 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_adisc
;
2168 spin_lock_irq(shost
->host_lock
);
2169 ndlp
->nlp_flag
|= NLP_ADISC_SND
;
2170 spin_unlock_irq(shost
->host_lock
);
2171 if (lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0) ==
2173 spin_lock_irq(shost
->host_lock
);
2174 ndlp
->nlp_flag
&= ~NLP_ADISC_SND
;
2175 spin_unlock_irq(shost
->host_lock
);
2176 lpfc_els_free_iocb(phba
, elsiocb
);
2183 * lpfc_cmpl_els_logo - Completion callback function for logo
2184 * @phba: pointer to lpfc hba data structure.
2185 * @cmdiocb: pointer to lpfc command iocb data structure.
2186 * @rspiocb: pointer to lpfc response iocb data structure.
2188 * This routine is the completion function for issuing the ELS Logout (LOGO)
2189 * command. If no error status was reported from the LOGO response, the
2190 * state machine of the associated ndlp shall be invoked for transition with
2191 * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
2192 * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
2195 lpfc_cmpl_els_logo(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
2196 struct lpfc_iocbq
*rspiocb
)
2198 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) cmdiocb
->context1
;
2199 struct lpfc_vport
*vport
= ndlp
->vport
;
2200 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2202 struct lpfc_sli
*psli
;
2205 /* we pass cmdiocb to state machine which needs rspiocb as well */
2206 cmdiocb
->context_un
.rsp_iocb
= rspiocb
;
2208 irsp
= &(rspiocb
->iocb
);
2209 spin_lock_irq(shost
->host_lock
);
2210 ndlp
->nlp_flag
&= ~NLP_LOGO_SND
;
2211 spin_unlock_irq(shost
->host_lock
);
2213 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
2214 "LOGO cmpl: status:x%x/x%x did:x%x",
2215 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
2217 /* LOGO completes to NPort <nlp_DID> */
2218 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
2219 "0105 LOGO completes to NPort x%x "
2220 "Data: x%x x%x x%x x%x\n",
2221 ndlp
->nlp_DID
, irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
2222 irsp
->ulpTimeout
, vport
->num_disc_nodes
);
2223 /* Check to see if link went down during discovery */
2224 if (lpfc_els_chk_latt(vport
))
2227 if (ndlp
->nlp_flag
& NLP_TARGET_REMOVE
) {
2228 /* NLP_EVT_DEVICE_RM should unregister the RPI
2229 * which should abort all outstanding IOs.
2231 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
2236 if (irsp
->ulpStatus
) {
2237 /* Check for retry */
2238 if (lpfc_els_retry(phba
, cmdiocb
, rspiocb
))
2239 /* ELS command is being retried */
2242 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
2243 "2756 LOGO failure DID:%06X Status:x%x/x%x\n",
2244 ndlp
->nlp_DID
, irsp
->ulpStatus
,
2245 irsp
->un
.ulpWord
[4]);
2246 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2247 if (lpfc_error_lost_link(irsp
))
2250 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
2253 /* Good status, call state machine.
2254 * This will unregister the rpi if needed.
2256 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
2259 lpfc_els_free_iocb(phba
, cmdiocb
);
2264 * lpfc_issue_els_logo - Issue a logo to an node on a vport
2265 * @vport: pointer to a virtual N_Port data structure.
2266 * @ndlp: pointer to a node-list data structure.
2267 * @retry: number of retries to the command IOCB.
2269 * This routine constructs and issues an ELS Logout (LOGO) iocb command
2270 * to a remote node, referred by an @ndlp on a @vport. It constructs the
2271 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
2272 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
2274 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2275 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2276 * will be stored into the context1 field of the IOCB for the completion
2277 * callback function to the LOGO ELS command.
2280 * 0 - successfully issued logo
2281 * 1 - failed to issue logo
2284 lpfc_issue_els_logo(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2287 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2288 struct lpfc_hba
*phba
= vport
->phba
;
2290 struct lpfc_iocbq
*elsiocb
;
2295 spin_lock_irq(shost
->host_lock
);
2296 if (ndlp
->nlp_flag
& NLP_LOGO_SND
) {
2297 spin_unlock_irq(shost
->host_lock
);
2300 spin_unlock_irq(shost
->host_lock
);
2302 cmdsize
= (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name
);
2303 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
,
2304 ndlp
->nlp_DID
, ELS_CMD_LOGO
);
2308 icmd
= &elsiocb
->iocb
;
2309 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
2310 *((uint32_t *) (pcmd
)) = ELS_CMD_LOGO
;
2311 pcmd
+= sizeof(uint32_t);
2313 /* Fill in LOGO payload */
2314 *((uint32_t *) (pcmd
)) = be32_to_cpu(vport
->fc_myDID
);
2315 pcmd
+= sizeof(uint32_t);
2316 memcpy(pcmd
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
2318 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
2319 "Issue LOGO: did:x%x",
2320 ndlp
->nlp_DID
, 0, 0);
2322 phba
->fc_stat
.elsXmitLOGO
++;
2323 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_logo
;
2324 spin_lock_irq(shost
->host_lock
);
2325 ndlp
->nlp_flag
|= NLP_LOGO_SND
;
2326 spin_unlock_irq(shost
->host_lock
);
2327 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
2329 if (rc
== IOCB_ERROR
) {
2330 spin_lock_irq(shost
->host_lock
);
2331 ndlp
->nlp_flag
&= ~NLP_LOGO_SND
;
2332 spin_unlock_irq(shost
->host_lock
);
2333 lpfc_els_free_iocb(phba
, elsiocb
);
2340 * lpfc_cmpl_els_cmd - Completion callback function for generic els command
2341 * @phba: pointer to lpfc hba data structure.
2342 * @cmdiocb: pointer to lpfc command iocb data structure.
2343 * @rspiocb: pointer to lpfc response iocb data structure.
2345 * This routine is a generic completion callback function for ELS commands.
2346 * Specifically, it is the callback function which does not need to perform
2347 * any command specific operations. It is currently used by the ELS command
2348 * issuing routines for the ELS State Change Request (SCR),
2349 * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution
2350 * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than
2351 * certain debug loggings, this callback function simply invokes the
2352 * lpfc_els_chk_latt() routine to check whether link went down during the
2353 * discovery process.
2356 lpfc_cmpl_els_cmd(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
2357 struct lpfc_iocbq
*rspiocb
)
2359 struct lpfc_vport
*vport
= cmdiocb
->vport
;
2362 irsp
= &rspiocb
->iocb
;
2364 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
2365 "ELS cmd cmpl: status:x%x/x%x did:x%x",
2366 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
2367 irsp
->un
.elsreq64
.remoteID
);
2368 /* ELS cmd tag <ulpIoTag> completes */
2369 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
2370 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
2371 irsp
->ulpIoTag
, irsp
->ulpStatus
,
2372 irsp
->un
.ulpWord
[4], irsp
->ulpTimeout
);
2373 /* Check to see if link went down during discovery */
2374 lpfc_els_chk_latt(vport
);
2375 lpfc_els_free_iocb(phba
, cmdiocb
);
2380 * lpfc_issue_els_scr - Issue a scr to an node on a vport
2381 * @vport: pointer to a host virtual N_Port data structure.
2382 * @nportid: N_Port identifier to the remote node.
2383 * @retry: number of retries to the command IOCB.
2385 * This routine issues a State Change Request (SCR) to a fabric node
2386 * on a @vport. The remote node @nportid is passed into the function. It
2387 * first search the @vport node list to find the matching ndlp. If no such
2388 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
2389 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
2390 * routine is invoked to send the SCR IOCB.
2392 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2393 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2394 * will be stored into the context1 field of the IOCB for the completion
2395 * callback function to the SCR ELS command.
2398 * 0 - Successfully issued scr command
2399 * 1 - Failed to issue scr command
2402 lpfc_issue_els_scr(struct lpfc_vport
*vport
, uint32_t nportid
, uint8_t retry
)
2404 struct lpfc_hba
*phba
= vport
->phba
;
2406 struct lpfc_iocbq
*elsiocb
;
2407 struct lpfc_sli
*psli
;
2410 struct lpfc_nodelist
*ndlp
;
2413 cmdsize
= (sizeof(uint32_t) + sizeof(SCR
));
2415 ndlp
= lpfc_findnode_did(vport
, nportid
);
2417 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
2420 lpfc_nlp_init(vport
, ndlp
, nportid
);
2421 lpfc_enqueue_node(vport
, ndlp
);
2422 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
2423 ndlp
= lpfc_enable_node(vport
, ndlp
, NLP_STE_UNUSED_NODE
);
2428 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
,
2429 ndlp
->nlp_DID
, ELS_CMD_SCR
);
2432 /* This will trigger the release of the node just
2439 icmd
= &elsiocb
->iocb
;
2440 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
2442 *((uint32_t *) (pcmd
)) = ELS_CMD_SCR
;
2443 pcmd
+= sizeof(uint32_t);
2445 /* For SCR, remainder of payload is SCR parameter page */
2446 memset(pcmd
, 0, sizeof(SCR
));
2447 ((SCR
*) pcmd
)->Function
= SCR_FUNC_FULL
;
2449 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
2450 "Issue SCR: did:x%x",
2451 ndlp
->nlp_DID
, 0, 0);
2453 phba
->fc_stat
.elsXmitSCR
++;
2454 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_cmd
;
2455 if (lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0) ==
2457 /* The additional lpfc_nlp_put will cause the following
2458 * lpfc_els_free_iocb routine to trigger the rlease of
2462 lpfc_els_free_iocb(phba
, elsiocb
);
2465 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2466 * trigger the release of node.
2473 * lpfc_issue_els_farpr - Issue a farp to an node on a vport
2474 * @vport: pointer to a host virtual N_Port data structure.
2475 * @nportid: N_Port identifier to the remote node.
2476 * @retry: number of retries to the command IOCB.
2478 * This routine issues a Fibre Channel Address Resolution Response
2479 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
2480 * is passed into the function. It first search the @vport node list to find
2481 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
2482 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
2483 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
2485 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2486 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2487 * will be stored into the context1 field of the IOCB for the completion
2488 * callback function to the PARPR ELS command.
2491 * 0 - Successfully issued farpr command
2492 * 1 - Failed to issue farpr command
2495 lpfc_issue_els_farpr(struct lpfc_vport
*vport
, uint32_t nportid
, uint8_t retry
)
2497 struct lpfc_hba
*phba
= vport
->phba
;
2499 struct lpfc_iocbq
*elsiocb
;
2500 struct lpfc_sli
*psli
;
2505 struct lpfc_nodelist
*ondlp
;
2506 struct lpfc_nodelist
*ndlp
;
2509 cmdsize
= (sizeof(uint32_t) + sizeof(FARP
));
2511 ndlp
= lpfc_findnode_did(vport
, nportid
);
2513 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
2516 lpfc_nlp_init(vport
, ndlp
, nportid
);
2517 lpfc_enqueue_node(vport
, ndlp
);
2518 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
2519 ndlp
= lpfc_enable_node(vport
, ndlp
, NLP_STE_UNUSED_NODE
);
2524 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
,
2525 ndlp
->nlp_DID
, ELS_CMD_RNID
);
2527 /* This will trigger the release of the node just
2534 icmd
= &elsiocb
->iocb
;
2535 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
2537 *((uint32_t *) (pcmd
)) = ELS_CMD_FARPR
;
2538 pcmd
+= sizeof(uint32_t);
2540 /* Fill in FARPR payload */
2541 fp
= (FARP
*) (pcmd
);
2542 memset(fp
, 0, sizeof(FARP
));
2543 lp
= (uint32_t *) pcmd
;
2544 *lp
++ = be32_to_cpu(nportid
);
2545 *lp
++ = be32_to_cpu(vport
->fc_myDID
);
2547 fp
->Mflags
= (FARP_MATCH_PORT
| FARP_MATCH_NODE
);
2549 memcpy(&fp
->RportName
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
2550 memcpy(&fp
->RnodeName
, &vport
->fc_nodename
, sizeof(struct lpfc_name
));
2551 ondlp
= lpfc_findnode_did(vport
, nportid
);
2552 if (ondlp
&& NLP_CHK_NODE_ACT(ondlp
)) {
2553 memcpy(&fp
->OportName
, &ondlp
->nlp_portname
,
2554 sizeof(struct lpfc_name
));
2555 memcpy(&fp
->OnodeName
, &ondlp
->nlp_nodename
,
2556 sizeof(struct lpfc_name
));
2559 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
2560 "Issue FARPR: did:x%x",
2561 ndlp
->nlp_DID
, 0, 0);
2563 phba
->fc_stat
.elsXmitFARPR
++;
2564 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_cmd
;
2565 if (lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0) ==
2567 /* The additional lpfc_nlp_put will cause the following
2568 * lpfc_els_free_iocb routine to trigger the release of
2572 lpfc_els_free_iocb(phba
, elsiocb
);
2575 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2576 * trigger the release of the node.
2583 * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
2584 * @vport: pointer to a host virtual N_Port data structure.
2585 * @nlp: pointer to a node-list data structure.
2587 * This routine cancels the timer with a delayed IOCB-command retry for
2588 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
2589 * removes the ELS retry event if it presents. In addition, if the
2590 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
2591 * commands are sent for the @vport's nodes that require issuing discovery
2595 lpfc_cancel_retry_delay_tmo(struct lpfc_vport
*vport
, struct lpfc_nodelist
*nlp
)
2597 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2598 struct lpfc_work_evt
*evtp
;
2600 if (!(nlp
->nlp_flag
& NLP_DELAY_TMO
))
2602 spin_lock_irq(shost
->host_lock
);
2603 nlp
->nlp_flag
&= ~NLP_DELAY_TMO
;
2604 spin_unlock_irq(shost
->host_lock
);
2605 del_timer_sync(&nlp
->nlp_delayfunc
);
2606 nlp
->nlp_last_elscmd
= 0;
2607 if (!list_empty(&nlp
->els_retry_evt
.evt_listp
)) {
2608 list_del_init(&nlp
->els_retry_evt
.evt_listp
);
2609 /* Decrement nlp reference count held for the delayed retry */
2610 evtp
= &nlp
->els_retry_evt
;
2611 lpfc_nlp_put((struct lpfc_nodelist
*)evtp
->evt_arg1
);
2613 if (nlp
->nlp_flag
& NLP_NPR_2B_DISC
) {
2614 spin_lock_irq(shost
->host_lock
);
2615 nlp
->nlp_flag
&= ~NLP_NPR_2B_DISC
;
2616 spin_unlock_irq(shost
->host_lock
);
2617 if (vport
->num_disc_nodes
) {
2618 if (vport
->port_state
< LPFC_VPORT_READY
) {
2619 /* Check if there are more ADISCs to be sent */
2620 lpfc_more_adisc(vport
);
2622 /* Check if there are more PLOGIs to be sent */
2623 lpfc_more_plogi(vport
);
2624 if (vport
->num_disc_nodes
== 0) {
2625 spin_lock_irq(shost
->host_lock
);
2626 vport
->fc_flag
&= ~FC_NDISC_ACTIVE
;
2627 spin_unlock_irq(shost
->host_lock
);
2628 lpfc_can_disctmo(vport
);
2629 lpfc_end_rscn(vport
);
2638 * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
2639 * @ptr: holder for the pointer to the timer function associated data (ndlp).
2641 * This routine is invoked by the ndlp delayed-function timer to check
2642 * whether there is any pending ELS retry event(s) with the node. If not, it
2643 * simply returns. Otherwise, if there is at least one ELS delayed event, it
2644 * adds the delayed events to the HBA work list and invokes the
2645 * lpfc_worker_wake_up() routine to wake up worker thread to process the
2646 * event. Note that lpfc_nlp_get() is called before posting the event to
2647 * the work list to hold reference count of ndlp so that it guarantees the
2648 * reference to ndlp will still be available when the worker thread gets
2649 * to the event associated with the ndlp.
2652 lpfc_els_retry_delay(unsigned long ptr
)
2654 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) ptr
;
2655 struct lpfc_vport
*vport
= ndlp
->vport
;
2656 struct lpfc_hba
*phba
= vport
->phba
;
2657 unsigned long flags
;
2658 struct lpfc_work_evt
*evtp
= &ndlp
->els_retry_evt
;
2660 spin_lock_irqsave(&phba
->hbalock
, flags
);
2661 if (!list_empty(&evtp
->evt_listp
)) {
2662 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
2666 /* We need to hold the node by incrementing the reference
2667 * count until the queued work is done
2669 evtp
->evt_arg1
= lpfc_nlp_get(ndlp
);
2670 if (evtp
->evt_arg1
) {
2671 evtp
->evt
= LPFC_EVT_ELS_RETRY
;
2672 list_add_tail(&evtp
->evt_listp
, &phba
->work_list
);
2673 lpfc_worker_wake_up(phba
);
2675 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
2680 * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
2681 * @ndlp: pointer to a node-list data structure.
2683 * This routine is the worker-thread handler for processing the @ndlp delayed
2684 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
2685 * the last ELS command from the associated ndlp and invokes the proper ELS
2686 * function according to the delayed ELS command to retry the command.
2689 lpfc_els_retry_delay_handler(struct lpfc_nodelist
*ndlp
)
2691 struct lpfc_vport
*vport
= ndlp
->vport
;
2692 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2693 uint32_t cmd
, did
, retry
;
2695 spin_lock_irq(shost
->host_lock
);
2696 did
= ndlp
->nlp_DID
;
2697 cmd
= ndlp
->nlp_last_elscmd
;
2698 ndlp
->nlp_last_elscmd
= 0;
2700 if (!(ndlp
->nlp_flag
& NLP_DELAY_TMO
)) {
2701 spin_unlock_irq(shost
->host_lock
);
2705 ndlp
->nlp_flag
&= ~NLP_DELAY_TMO
;
2706 spin_unlock_irq(shost
->host_lock
);
2708 * If a discovery event readded nlp_delayfunc after timer
2709 * firing and before processing the timer, cancel the
2712 del_timer_sync(&ndlp
->nlp_delayfunc
);
2713 retry
= ndlp
->nlp_retry
;
2714 ndlp
->nlp_retry
= 0;
2718 lpfc_issue_els_flogi(vport
, ndlp
, retry
);
2721 if (!lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, retry
)) {
2722 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
2723 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
2727 if (!lpfc_issue_els_adisc(vport
, ndlp
, retry
)) {
2728 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
2729 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_ADISC_ISSUE
);
2733 if (!lpfc_issue_els_prli(vport
, ndlp
, retry
)) {
2734 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
2735 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PRLI_ISSUE
);
2739 if (!lpfc_issue_els_logo(vport
, ndlp
, retry
)) {
2740 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
2741 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
2745 lpfc_issue_els_fdisc(vport
, ndlp
, retry
);
2752 * lpfc_els_retry - Make retry decision on an els command iocb
2753 * @phba: pointer to lpfc hba data structure.
2754 * @cmdiocb: pointer to lpfc command iocb data structure.
2755 * @rspiocb: pointer to lpfc response iocb data structure.
2757 * This routine makes a retry decision on an ELS command IOCB, which has
2758 * failed. The following ELS IOCBs use this function for retrying the command
2759 * when previously issued command responsed with error status: FLOGI, PLOGI,
2760 * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
2761 * returned error status, it makes the decision whether a retry shall be
2762 * issued for the command, and whether a retry shall be made immediately or
2763 * delayed. In the former case, the corresponding ELS command issuing-function
2764 * is called to retry the command. In the later case, the ELS command shall
2765 * be posted to the ndlp delayed event and delayed function timer set to the
2766 * ndlp for the delayed command issusing.
2769 * 0 - No retry of els command is made
2770 * 1 - Immediate or delayed retry of els command is made
2773 lpfc_els_retry(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
2774 struct lpfc_iocbq
*rspiocb
)
2776 struct lpfc_vport
*vport
= cmdiocb
->vport
;
2777 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2778 IOCB_t
*irsp
= &rspiocb
->iocb
;
2779 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) cmdiocb
->context1
;
2780 struct lpfc_dmabuf
*pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
2783 int retry
= 0, maxretry
= lpfc_max_els_tries
, delay
= 0;
2789 /* Note: context2 may be 0 for internal driver abort
2790 * of delays ELS command.
2793 if (pcmd
&& pcmd
->virt
) {
2794 elscmd
= (uint32_t *) (pcmd
->virt
);
2798 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
))
2799 did
= ndlp
->nlp_DID
;
2801 /* We should only hit this case for retrying PLOGI */
2802 did
= irsp
->un
.elsreq64
.remoteID
;
2803 ndlp
= lpfc_findnode_did(vport
, did
);
2804 if ((!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
))
2805 && (cmd
!= ELS_CMD_PLOGI
))
2809 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
2810 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
2811 *(((uint32_t *) irsp
) + 7), irsp
->un
.ulpWord
[4], ndlp
->nlp_DID
);
2813 switch (irsp
->ulpStatus
) {
2814 case IOSTAT_FCP_RSP_ERROR
:
2815 case IOSTAT_REMOTE_STOP
:
2818 case IOSTAT_LOCAL_REJECT
:
2819 switch ((irsp
->un
.ulpWord
[4] & 0xff)) {
2820 case IOERR_LOOP_OPEN_FAILURE
:
2821 if (cmd
== ELS_CMD_FLOGI
) {
2822 if (PCI_DEVICE_ID_HORNET
==
2823 phba
->pcidev
->device
) {
2824 phba
->fc_topology
= LPFC_TOPOLOGY_LOOP
;
2825 phba
->pport
->fc_myDID
= 0;
2826 phba
->alpa_map
[0] = 0;
2827 phba
->alpa_map
[1] = 0;
2830 if (cmd
== ELS_CMD_PLOGI
&& cmdiocb
->retry
== 0)
2835 case IOERR_ILLEGAL_COMMAND
:
2836 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
2837 "0124 Retry illegal cmd x%x "
2838 "retry:x%x delay:x%x\n",
2839 cmd
, cmdiocb
->retry
, delay
);
2841 /* All command's retry policy */
2843 if (cmdiocb
->retry
> 2)
2847 case IOERR_NO_RESOURCES
:
2848 logerr
= 1; /* HBA out of resources */
2850 if (cmdiocb
->retry
> 100)
2855 case IOERR_ILLEGAL_FRAME
:
2860 case IOERR_SEQUENCE_TIMEOUT
:
2861 case IOERR_INVALID_RPI
:
2867 case IOSTAT_NPORT_RJT
:
2868 case IOSTAT_FABRIC_RJT
:
2869 if (irsp
->un
.ulpWord
[4] & RJT_UNAVAIL_TEMP
) {
2875 case IOSTAT_NPORT_BSY
:
2876 case IOSTAT_FABRIC_BSY
:
2877 logerr
= 1; /* Fabric / Remote NPort out of resources */
2882 stat
.un
.lsRjtError
= be32_to_cpu(irsp
->un
.ulpWord
[4]);
2883 /* Added for Vendor specifc support
2884 * Just keep retrying for these Rsn / Exp codes
2886 switch (stat
.un
.b
.lsRjtRsnCode
) {
2887 case LSRJT_UNABLE_TPC
:
2888 if (stat
.un
.b
.lsRjtRsnCodeExp
==
2889 LSEXP_CMD_IN_PROGRESS
) {
2890 if (cmd
== ELS_CMD_PLOGI
) {
2897 if (stat
.un
.b
.lsRjtRsnCodeExp
==
2898 LSEXP_CANT_GIVE_DATA
) {
2899 if (cmd
== ELS_CMD_PLOGI
) {
2906 if (cmd
== ELS_CMD_PLOGI
) {
2908 maxretry
= lpfc_max_els_tries
+ 1;
2912 if ((phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
2913 (cmd
== ELS_CMD_FDISC
) &&
2914 (stat
.un
.b
.lsRjtRsnCodeExp
== LSEXP_OUT_OF_RESOURCE
)){
2915 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
2916 "0125 FDISC Failed (x%x). "
2917 "Fabric out of resources\n",
2918 stat
.un
.lsRjtError
);
2919 lpfc_vport_set_state(vport
,
2920 FC_VPORT_NO_FABRIC_RSCS
);
2924 case LSRJT_LOGICAL_BSY
:
2925 if ((cmd
== ELS_CMD_PLOGI
) ||
2926 (cmd
== ELS_CMD_PRLI
)) {
2929 } else if (cmd
== ELS_CMD_FDISC
) {
2930 /* FDISC retry policy */
2932 if (cmdiocb
->retry
>= 32)
2938 case LSRJT_LOGICAL_ERR
:
2939 /* There are some cases where switches return this
2940 * error when they are not ready and should be returning
2941 * Logical Busy. We should delay every time.
2943 if (cmd
== ELS_CMD_FDISC
&&
2944 stat
.un
.b
.lsRjtRsnCodeExp
== LSEXP_PORT_LOGIN_REQ
) {
2950 case LSRJT_PROTOCOL_ERR
:
2951 if ((phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
2952 (cmd
== ELS_CMD_FDISC
) &&
2953 ((stat
.un
.b
.lsRjtRsnCodeExp
== LSEXP_INVALID_PNAME
) ||
2954 (stat
.un
.b
.lsRjtRsnCodeExp
== LSEXP_INVALID_NPORT_ID
))
2956 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
2957 "0122 FDISC Failed (x%x). "
2958 "Fabric Detected Bad WWN\n",
2959 stat
.un
.lsRjtError
);
2960 lpfc_vport_set_state(vport
,
2961 FC_VPORT_FABRIC_REJ_WWN
);
2967 case IOSTAT_INTERMED_RSP
:
2975 if (did
== FDMI_DID
)
2978 if (((cmd
== ELS_CMD_FLOGI
) || (cmd
== ELS_CMD_FDISC
)) &&
2979 (phba
->fc_topology
!= LPFC_TOPOLOGY_LOOP
) &&
2980 !lpfc_error_lost_link(irsp
)) {
2981 /* FLOGI retry policy */
2985 if (cmdiocb
->retry
>= 100)
2987 else if (cmdiocb
->retry
>= 32)
2992 if (maxretry
&& (cmdiocb
->retry
>= maxretry
)) {
2993 phba
->fc_stat
.elsRetryExceeded
++;
2997 if ((vport
->load_flag
& FC_UNLOADING
) != 0)
3001 if ((cmd
== ELS_CMD_PLOGI
) || (cmd
== ELS_CMD_FDISC
)) {
3002 /* Stop retrying PLOGI and FDISC if in FCF discovery */
3003 if (phba
->fcf
.fcf_flag
& FCF_DISCOVERY
) {
3004 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
3005 "2849 Stop retry ELS command "
3006 "x%x to remote NPORT x%x, "
3007 "Data: x%x x%x\n", cmd
, did
,
3008 cmdiocb
->retry
, delay
);
3013 /* Retry ELS command <elsCmd> to remote NPORT <did> */
3014 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
3015 "0107 Retry ELS command x%x to remote "
3016 "NPORT x%x Data: x%x x%x\n",
3017 cmd
, did
, cmdiocb
->retry
, delay
);
3019 if (((cmd
== ELS_CMD_PLOGI
) || (cmd
== ELS_CMD_ADISC
)) &&
3020 ((irsp
->ulpStatus
!= IOSTAT_LOCAL_REJECT
) ||
3021 ((irsp
->un
.ulpWord
[4] & 0xff) != IOERR_NO_RESOURCES
))) {
3022 /* Don't reset timer for no resources */
3024 /* If discovery / RSCN timer is running, reset it */
3025 if (timer_pending(&vport
->fc_disctmo
) ||
3026 (vport
->fc_flag
& FC_RSCN_MODE
))
3027 lpfc_set_disctmo(vport
);
3030 phba
->fc_stat
.elsXmitRetry
++;
3031 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
) && delay
) {
3032 phba
->fc_stat
.elsDelayRetry
++;
3033 ndlp
->nlp_retry
= cmdiocb
->retry
;
3035 /* delay is specified in milliseconds */
3036 mod_timer(&ndlp
->nlp_delayfunc
,
3037 jiffies
+ msecs_to_jiffies(delay
));
3038 spin_lock_irq(shost
->host_lock
);
3039 ndlp
->nlp_flag
|= NLP_DELAY_TMO
;
3040 spin_unlock_irq(shost
->host_lock
);
3042 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
3043 if (cmd
== ELS_CMD_PRLI
)
3044 lpfc_nlp_set_state(vport
, ndlp
,
3045 NLP_STE_REG_LOGIN_ISSUE
);
3047 lpfc_nlp_set_state(vport
, ndlp
,
3049 ndlp
->nlp_last_elscmd
= cmd
;
3055 lpfc_issue_els_flogi(vport
, ndlp
, cmdiocb
->retry
);
3058 lpfc_issue_els_fdisc(vport
, ndlp
, cmdiocb
->retry
);
3061 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
)) {
3062 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
3063 lpfc_nlp_set_state(vport
, ndlp
,
3064 NLP_STE_PLOGI_ISSUE
);
3066 lpfc_issue_els_plogi(vport
, did
, cmdiocb
->retry
);
3069 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
3070 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_ADISC_ISSUE
);
3071 lpfc_issue_els_adisc(vport
, ndlp
, cmdiocb
->retry
);
3074 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
3075 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PRLI_ISSUE
);
3076 lpfc_issue_els_prli(vport
, ndlp
, cmdiocb
->retry
);
3079 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
3080 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
3081 lpfc_issue_els_logo(vport
, ndlp
, cmdiocb
->retry
);
3085 /* No retry ELS command <elsCmd> to remote NPORT <did> */
3087 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
3088 "0137 No retry ELS command x%x to remote "
3089 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
3090 cmd
, did
, irsp
->ulpStatus
,
3091 irsp
->un
.ulpWord
[4]);
3094 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
3095 "0108 No retry ELS command x%x to remote "
3096 "NPORT x%x Retried:%d Error:x%x/%x\n",
3097 cmd
, did
, cmdiocb
->retry
, irsp
->ulpStatus
,
3098 irsp
->un
.ulpWord
[4]);
3104 * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
3105 * @phba: pointer to lpfc hba data structure.
3106 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
3108 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
3109 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
3110 * checks to see whether there is a lpfc DMA buffer associated with the
3111 * response of the command IOCB. If so, it will be released before releasing
3112 * the lpfc DMA buffer associated with the IOCB itself.
3115 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3118 lpfc_els_free_data(struct lpfc_hba
*phba
, struct lpfc_dmabuf
*buf_ptr1
)
3120 struct lpfc_dmabuf
*buf_ptr
;
3122 /* Free the response before processing the command. */
3123 if (!list_empty(&buf_ptr1
->list
)) {
3124 list_remove_head(&buf_ptr1
->list
, buf_ptr
,
3127 lpfc_mbuf_free(phba
, buf_ptr
->virt
, buf_ptr
->phys
);
3130 lpfc_mbuf_free(phba
, buf_ptr1
->virt
, buf_ptr1
->phys
);
3136 * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
3137 * @phba: pointer to lpfc hba data structure.
3138 * @buf_ptr: pointer to the lpfc dma buffer data structure.
3140 * This routine releases the lpfc Direct Memory Access (DMA) buffer
3141 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
3145 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3148 lpfc_els_free_bpl(struct lpfc_hba
*phba
, struct lpfc_dmabuf
*buf_ptr
)
3150 lpfc_mbuf_free(phba
, buf_ptr
->virt
, buf_ptr
->phys
);
3156 * lpfc_els_free_iocb - Free a command iocb and its associated resources
3157 * @phba: pointer to lpfc hba data structure.
3158 * @elsiocb: pointer to lpfc els command iocb data structure.
3160 * This routine frees a command IOCB and its associated resources. The
3161 * command IOCB data structure contains the reference to various associated
3162 * resources, these fields must be set to NULL if the associated reference
3164 * context1 - reference to ndlp
3165 * context2 - reference to cmd
3166 * context2->next - reference to rsp
3167 * context3 - reference to bpl
3169 * It first properly decrements the reference count held on ndlp for the
3170 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
3171 * set, it invokes the lpfc_els_free_data() routine to release the Direct
3172 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
3173 * adds the DMA buffer the @phba data structure for the delayed release.
3174 * If reference to the Buffer Pointer List (BPL) is present, the
3175 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
3176 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
3177 * invoked to release the IOCB data structure back to @phba IOCBQ list.
3180 * 0 - Success (currently, always return 0)
3183 lpfc_els_free_iocb(struct lpfc_hba
*phba
, struct lpfc_iocbq
*elsiocb
)
3185 struct lpfc_dmabuf
*buf_ptr
, *buf_ptr1
;
3186 struct lpfc_nodelist
*ndlp
;
3188 ndlp
= (struct lpfc_nodelist
*)elsiocb
->context1
;
3190 if (ndlp
->nlp_flag
& NLP_DEFER_RM
) {
3193 /* If the ndlp is not being used by another discovery
3196 if (!lpfc_nlp_not_used(ndlp
)) {
3197 /* If ndlp is being used by another discovery
3198 * thread, just clear NLP_DEFER_RM
3200 ndlp
->nlp_flag
&= ~NLP_DEFER_RM
;
3205 elsiocb
->context1
= NULL
;
3207 /* context2 = cmd, context2->next = rsp, context3 = bpl */
3208 if (elsiocb
->context2
) {
3209 if (elsiocb
->iocb_flag
& LPFC_DELAY_MEM_FREE
) {
3210 /* Firmware could still be in progress of DMAing
3211 * payload, so don't free data buffer till after
3214 elsiocb
->iocb_flag
&= ~LPFC_DELAY_MEM_FREE
;
3215 buf_ptr
= elsiocb
->context2
;
3216 elsiocb
->context2
= NULL
;
3219 spin_lock_irq(&phba
->hbalock
);
3220 if (!list_empty(&buf_ptr
->list
)) {
3221 list_remove_head(&buf_ptr
->list
,
3222 buf_ptr1
, struct lpfc_dmabuf
,
3224 INIT_LIST_HEAD(&buf_ptr1
->list
);
3225 list_add_tail(&buf_ptr1
->list
,
3229 INIT_LIST_HEAD(&buf_ptr
->list
);
3230 list_add_tail(&buf_ptr
->list
, &phba
->elsbuf
);
3232 spin_unlock_irq(&phba
->hbalock
);
3235 buf_ptr1
= (struct lpfc_dmabuf
*) elsiocb
->context2
;
3236 lpfc_els_free_data(phba
, buf_ptr1
);
3240 if (elsiocb
->context3
) {
3241 buf_ptr
= (struct lpfc_dmabuf
*) elsiocb
->context3
;
3242 lpfc_els_free_bpl(phba
, buf_ptr
);
3244 lpfc_sli_release_iocbq(phba
, elsiocb
);
3249 * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
3250 * @phba: pointer to lpfc hba data structure.
3251 * @cmdiocb: pointer to lpfc command iocb data structure.
3252 * @rspiocb: pointer to lpfc response iocb data structure.
3254 * This routine is the completion callback function to the Logout (LOGO)
3255 * Accept (ACC) Response ELS command. This routine is invoked to indicate
3256 * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
3257 * release the ndlp if it has the last reference remaining (reference count
3258 * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
3259 * field to NULL to inform the following lpfc_els_free_iocb() routine no
3260 * ndlp reference count needs to be decremented. Otherwise, the ndlp
3261 * reference use-count shall be decremented by the lpfc_els_free_iocb()
3262 * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
3263 * IOCB data structure.
3266 lpfc_cmpl_els_logo_acc(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
3267 struct lpfc_iocbq
*rspiocb
)
3269 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) cmdiocb
->context1
;
3270 struct lpfc_vport
*vport
= cmdiocb
->vport
;
3273 irsp
= &rspiocb
->iocb
;
3274 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
3275 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
3276 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4], ndlp
->nlp_DID
);
3277 /* ACC to LOGO completes to NPort <nlp_DID> */
3278 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
3279 "0109 ACC to LOGO completes to NPort x%x "
3280 "Data: x%x x%x x%x\n",
3281 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
3284 if (ndlp
->nlp_state
== NLP_STE_NPR_NODE
) {
3285 /* NPort Recovery mode or node is just allocated */
3286 if (!lpfc_nlp_not_used(ndlp
)) {
3287 /* If the ndlp is being used by another discovery
3288 * thread, just unregister the RPI.
3290 lpfc_unreg_rpi(vport
, ndlp
);
3292 /* Indicate the node has already released, should
3293 * not reference to it from within lpfc_els_free_iocb.
3295 cmdiocb
->context1
= NULL
;
3298 lpfc_els_free_iocb(phba
, cmdiocb
);
3303 * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
3304 * @phba: pointer to lpfc hba data structure.
3305 * @pmb: pointer to the driver internal queue element for mailbox command.
3307 * This routine is the completion callback function for unregister default
3308 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
3309 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
3310 * decrements the ndlp reference count held for this completion callback
3311 * function. After that, it invokes the lpfc_nlp_not_used() to check
3312 * whether there is only one reference left on the ndlp. If so, it will
3313 * perform one more decrement and trigger the release of the ndlp.
3316 lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
3318 struct lpfc_dmabuf
*mp
= (struct lpfc_dmabuf
*) (pmb
->context1
);
3319 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) pmb
->context2
;
3322 * This routine is used to register and unregister in previous SLI
3325 if ((pmb
->u
.mb
.mbxCommand
== MBX_UNREG_LOGIN
) &&
3326 (phba
->sli_rev
== LPFC_SLI_REV4
))
3327 lpfc_sli4_free_rpi(phba
, pmb
->u
.mb
.un
.varUnregLogin
.rpi
);
3329 pmb
->context1
= NULL
;
3330 pmb
->context2
= NULL
;
3332 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
3334 mempool_free(pmb
, phba
->mbox_mem_pool
);
3335 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
)) {
3337 /* This is the end of the default RPI cleanup logic for this
3338 * ndlp. If no other discovery threads are using this ndlp.
3339 * we should free all resources associated with it.
3341 lpfc_nlp_not_used(ndlp
);
3348 * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
3349 * @phba: pointer to lpfc hba data structure.
3350 * @cmdiocb: pointer to lpfc command iocb data structure.
3351 * @rspiocb: pointer to lpfc response iocb data structure.
3353 * This routine is the completion callback function for ELS Response IOCB
3354 * command. In normal case, this callback function just properly sets the
3355 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
3356 * field in the command IOCB is not NULL, the referred mailbox command will
3357 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
3358 * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
3359 * link down event occurred during the discovery, the lpfc_nlp_not_used()
3360 * routine shall be invoked trying to release the ndlp if no other threads
3361 * are currently referring it.
3364 lpfc_cmpl_els_rsp(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
3365 struct lpfc_iocbq
*rspiocb
)
3367 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) cmdiocb
->context1
;
3368 struct lpfc_vport
*vport
= ndlp
? ndlp
->vport
: NULL
;
3369 struct Scsi_Host
*shost
= vport
? lpfc_shost_from_vport(vport
) : NULL
;
3372 LPFC_MBOXQ_t
*mbox
= NULL
;
3373 struct lpfc_dmabuf
*mp
= NULL
;
3374 uint32_t ls_rjt
= 0;
3376 irsp
= &rspiocb
->iocb
;
3378 if (cmdiocb
->context_un
.mbox
)
3379 mbox
= cmdiocb
->context_un
.mbox
;
3381 /* First determine if this is a LS_RJT cmpl. Note, this callback
3382 * function can have cmdiocb->contest1 (ndlp) field set to NULL.
3384 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) cmdiocb
->context2
)->virt
);
3385 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
) &&
3386 (*((uint32_t *) (pcmd
)) == ELS_CMD_LS_RJT
)) {
3387 /* A LS_RJT associated with Default RPI cleanup has its own
3388 * separate code path.
3390 if (!(ndlp
->nlp_flag
& NLP_RM_DFLT_RPI
))
3394 /* Check to see if link went down during discovery */
3395 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
) || lpfc_els_chk_latt(vport
)) {
3397 mp
= (struct lpfc_dmabuf
*) mbox
->context1
;
3399 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
3402 mempool_free(mbox
, phba
->mbox_mem_pool
);
3404 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
) &&
3405 (ndlp
->nlp_flag
& NLP_RM_DFLT_RPI
))
3406 if (lpfc_nlp_not_used(ndlp
)) {
3408 /* Indicate the node has already released,
3409 * should not reference to it from within
3410 * the routine lpfc_els_free_iocb.
3412 cmdiocb
->context1
= NULL
;
3417 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
3418 "ELS rsp cmpl: status:x%x/x%x did:x%x",
3419 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
3420 cmdiocb
->iocb
.un
.elsreq64
.remoteID
);
3421 /* ELS response tag <ulpIoTag> completes */
3422 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
3423 "0110 ELS response tag x%x completes "
3424 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
3425 cmdiocb
->iocb
.ulpIoTag
, rspiocb
->iocb
.ulpStatus
,
3426 rspiocb
->iocb
.un
.ulpWord
[4], rspiocb
->iocb
.ulpTimeout
,
3427 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
3430 if ((rspiocb
->iocb
.ulpStatus
== 0)
3431 && (ndlp
->nlp_flag
& NLP_ACC_REGLOGIN
)) {
3432 lpfc_unreg_rpi(vport
, ndlp
);
3433 /* Increment reference count to ndlp to hold the
3434 * reference to ndlp for the callback function.
3436 mbox
->context2
= lpfc_nlp_get(ndlp
);
3437 mbox
->vport
= vport
;
3438 if (ndlp
->nlp_flag
& NLP_RM_DFLT_RPI
) {
3439 mbox
->mbox_flag
|= LPFC_MBX_IMED_UNREG
;
3440 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_dflt_rpi
;
3443 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_reg_login
;
3444 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
3445 lpfc_nlp_set_state(vport
, ndlp
,
3446 NLP_STE_REG_LOGIN_ISSUE
);
3448 if (lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
)
3449 != MBX_NOT_FINISHED
)
3452 /* Decrement the ndlp reference count we
3453 * set for this failed mailbox command.
3457 /* ELS rsp: Cannot issue reg_login for <NPortid> */
3458 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
3459 "0138 ELS rsp: Cannot issue reg_login for x%x "
3460 "Data: x%x x%x x%x\n",
3461 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
3464 if (lpfc_nlp_not_used(ndlp
)) {
3466 /* Indicate node has already been released,
3467 * should not reference to it from within
3468 * the routine lpfc_els_free_iocb.
3470 cmdiocb
->context1
= NULL
;
3473 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
3474 if (!lpfc_error_lost_link(irsp
) &&
3475 ndlp
->nlp_flag
& NLP_ACC_REGLOGIN
) {
3476 if (lpfc_nlp_not_used(ndlp
)) {
3478 /* Indicate node has already been
3479 * released, should not reference
3480 * to it from within the routine
3481 * lpfc_els_free_iocb.
3483 cmdiocb
->context1
= NULL
;
3487 mp
= (struct lpfc_dmabuf
*) mbox
->context1
;
3489 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
3492 mempool_free(mbox
, phba
->mbox_mem_pool
);
3495 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
)) {
3496 spin_lock_irq(shost
->host_lock
);
3497 ndlp
->nlp_flag
&= ~(NLP_ACC_REGLOGIN
| NLP_RM_DFLT_RPI
);
3498 spin_unlock_irq(shost
->host_lock
);
3500 /* If the node is not being used by another discovery thread,
3501 * and we are sending a reject, we are done with it.
3502 * Release driver reference count here and free associated
3506 if (lpfc_nlp_not_used(ndlp
))
3507 /* Indicate node has already been released,
3508 * should not reference to it from within
3509 * the routine lpfc_els_free_iocb.
3511 cmdiocb
->context1
= NULL
;
3514 lpfc_els_free_iocb(phba
, cmdiocb
);
3519 * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
3520 * @vport: pointer to a host virtual N_Port data structure.
3521 * @flag: the els command code to be accepted.
3522 * @oldiocb: pointer to the original lpfc command iocb data structure.
3523 * @ndlp: pointer to a node-list data structure.
3524 * @mbox: pointer to the driver internal queue element for mailbox command.
3526 * This routine prepares and issues an Accept (ACC) response IOCB
3527 * command. It uses the @flag to properly set up the IOCB field for the
3528 * specific ACC response command to be issued and invokes the
3529 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
3530 * @mbox pointer is passed in, it will be put into the context_un.mbox
3531 * field of the IOCB for the completion callback function to issue the
3532 * mailbox command to the HBA later when callback is invoked.
3534 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3535 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3536 * will be stored into the context1 field of the IOCB for the completion
3537 * callback function to the corresponding response ELS IOCB command.
3540 * 0 - Successfully issued acc response
3541 * 1 - Failed to issue acc response
3544 lpfc_els_rsp_acc(struct lpfc_vport
*vport
, uint32_t flag
,
3545 struct lpfc_iocbq
*oldiocb
, struct lpfc_nodelist
*ndlp
,
3548 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
3549 struct lpfc_hba
*phba
= vport
->phba
;
3552 struct lpfc_iocbq
*elsiocb
;
3553 struct lpfc_sli
*psli
;
3557 ELS_PKT
*els_pkt_ptr
;
3560 oldcmd
= &oldiocb
->iocb
;
3564 cmdsize
= sizeof(uint32_t);
3565 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
,
3566 ndlp
, ndlp
->nlp_DID
, ELS_CMD_ACC
);
3568 spin_lock_irq(shost
->host_lock
);
3569 ndlp
->nlp_flag
&= ~NLP_LOGO_ACC
;
3570 spin_unlock_irq(shost
->host_lock
);
3574 icmd
= &elsiocb
->iocb
;
3575 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri */
3576 pcmd
= (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
3577 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
3578 pcmd
+= sizeof(uint32_t);
3580 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
3581 "Issue ACC: did:x%x flg:x%x",
3582 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
3585 cmdsize
= (sizeof(struct serv_parm
) + sizeof(uint32_t));
3586 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
,
3587 ndlp
, ndlp
->nlp_DID
, ELS_CMD_ACC
);
3591 icmd
= &elsiocb
->iocb
;
3592 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri */
3593 pcmd
= (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
3596 elsiocb
->context_un
.mbox
= mbox
;
3598 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
3599 pcmd
+= sizeof(uint32_t);
3600 memcpy(pcmd
, &vport
->fc_sparam
, sizeof(struct serv_parm
));
3602 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
3603 "Issue ACC PLOGI: did:x%x flg:x%x",
3604 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
3607 cmdsize
= sizeof(uint32_t) + sizeof(PRLO
);
3608 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
,
3609 ndlp
, ndlp
->nlp_DID
, ELS_CMD_PRLO
);
3613 icmd
= &elsiocb
->iocb
;
3614 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri */
3615 pcmd
= (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
3617 memcpy(pcmd
, ((struct lpfc_dmabuf
*) oldiocb
->context2
)->virt
,
3618 sizeof(uint32_t) + sizeof(PRLO
));
3619 *((uint32_t *) (pcmd
)) = ELS_CMD_PRLO_ACC
;
3620 els_pkt_ptr
= (ELS_PKT
*) pcmd
;
3621 els_pkt_ptr
->un
.prlo
.acceptRspCode
= PRLO_REQ_EXECUTED
;
3623 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
3624 "Issue ACC PRLO: did:x%x flg:x%x",
3625 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
3630 /* Xmit ELS ACC response tag <ulpIoTag> */
3631 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
3632 "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
3633 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n",
3634 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
,
3635 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
3637 if (ndlp
->nlp_flag
& NLP_LOGO_ACC
) {
3638 spin_lock_irq(shost
->host_lock
);
3639 ndlp
->nlp_flag
&= ~NLP_LOGO_ACC
;
3640 spin_unlock_irq(shost
->host_lock
);
3641 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_logo_acc
;
3643 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
3646 phba
->fc_stat
.elsXmitACC
++;
3647 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
3648 if (rc
== IOCB_ERROR
) {
3649 lpfc_els_free_iocb(phba
, elsiocb
);
3656 * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command
3657 * @vport: pointer to a virtual N_Port data structure.
3659 * @oldiocb: pointer to the original lpfc command iocb data structure.
3660 * @ndlp: pointer to a node-list data structure.
3661 * @mbox: pointer to the driver internal queue element for mailbox command.
3663 * This routine prepares and issue an Reject (RJT) response IOCB
3664 * command. If a @mbox pointer is passed in, it will be put into the
3665 * context_un.mbox field of the IOCB for the completion callback function
3666 * to issue to the HBA later.
3668 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3669 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3670 * will be stored into the context1 field of the IOCB for the completion
3671 * callback function to the reject response ELS IOCB command.
3674 * 0 - Successfully issued reject response
3675 * 1 - Failed to issue reject response
3678 lpfc_els_rsp_reject(struct lpfc_vport
*vport
, uint32_t rejectError
,
3679 struct lpfc_iocbq
*oldiocb
, struct lpfc_nodelist
*ndlp
,
3682 struct lpfc_hba
*phba
= vport
->phba
;
3685 struct lpfc_iocbq
*elsiocb
;
3686 struct lpfc_sli
*psli
;
3692 cmdsize
= 2 * sizeof(uint32_t);
3693 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
, ndlp
,
3694 ndlp
->nlp_DID
, ELS_CMD_LS_RJT
);
3698 icmd
= &elsiocb
->iocb
;
3699 oldcmd
= &oldiocb
->iocb
;
3700 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri */
3701 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
3703 *((uint32_t *) (pcmd
)) = ELS_CMD_LS_RJT
;
3704 pcmd
+= sizeof(uint32_t);
3705 *((uint32_t *) (pcmd
)) = rejectError
;
3708 elsiocb
->context_un
.mbox
= mbox
;
3710 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
3711 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
3712 "0129 Xmit ELS RJT x%x response tag x%x "
3713 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
3715 rejectError
, elsiocb
->iotag
,
3716 elsiocb
->iocb
.ulpContext
, ndlp
->nlp_DID
,
3717 ndlp
->nlp_flag
, ndlp
->nlp_state
, ndlp
->nlp_rpi
);
3718 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
3719 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
3720 ndlp
->nlp_DID
, ndlp
->nlp_flag
, rejectError
);
3722 phba
->fc_stat
.elsXmitLSRJT
++;
3723 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
3724 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
3726 if (rc
== IOCB_ERROR
) {
3727 lpfc_els_free_iocb(phba
, elsiocb
);
3734 * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
3735 * @vport: pointer to a virtual N_Port data structure.
3736 * @oldiocb: pointer to the original lpfc command iocb data structure.
3737 * @ndlp: pointer to a node-list data structure.
3739 * This routine prepares and issues an Accept (ACC) response to Address
3740 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
3741 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3743 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3744 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3745 * will be stored into the context1 field of the IOCB for the completion
3746 * callback function to the ADISC Accept response ELS IOCB command.
3749 * 0 - Successfully issued acc adisc response
3750 * 1 - Failed to issue adisc acc response
3753 lpfc_els_rsp_adisc_acc(struct lpfc_vport
*vport
, struct lpfc_iocbq
*oldiocb
,
3754 struct lpfc_nodelist
*ndlp
)
3756 struct lpfc_hba
*phba
= vport
->phba
;
3758 IOCB_t
*icmd
, *oldcmd
;
3759 struct lpfc_iocbq
*elsiocb
;
3764 cmdsize
= sizeof(uint32_t) + sizeof(ADISC
);
3765 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
, ndlp
,
3766 ndlp
->nlp_DID
, ELS_CMD_ACC
);
3770 icmd
= &elsiocb
->iocb
;
3771 oldcmd
= &oldiocb
->iocb
;
3772 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri */
3774 /* Xmit ADISC ACC response tag <ulpIoTag> */
3775 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
3776 "0130 Xmit ADISC ACC response iotag x%x xri: "
3777 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
3778 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
,
3779 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
3781 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
3783 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
3784 pcmd
+= sizeof(uint32_t);
3786 ap
= (ADISC
*) (pcmd
);
3787 ap
->hardAL_PA
= phba
->fc_pref_ALPA
;
3788 memcpy(&ap
->portName
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
3789 memcpy(&ap
->nodeName
, &vport
->fc_nodename
, sizeof(struct lpfc_name
));
3790 ap
->DID
= be32_to_cpu(vport
->fc_myDID
);
3792 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
3793 "Issue ACC ADISC: did:x%x flg:x%x",
3794 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
3796 phba
->fc_stat
.elsXmitACC
++;
3797 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
3798 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
3799 if (rc
== IOCB_ERROR
) {
3800 lpfc_els_free_iocb(phba
, elsiocb
);
3807 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
3808 * @vport: pointer to a virtual N_Port data structure.
3809 * @oldiocb: pointer to the original lpfc command iocb data structure.
3810 * @ndlp: pointer to a node-list data structure.
3812 * This routine prepares and issues an Accept (ACC) response to Process
3813 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
3814 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3816 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3817 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3818 * will be stored into the context1 field of the IOCB for the completion
3819 * callback function to the PRLI Accept response ELS IOCB command.
3822 * 0 - Successfully issued acc prli response
3823 * 1 - Failed to issue acc prli response
3826 lpfc_els_rsp_prli_acc(struct lpfc_vport
*vport
, struct lpfc_iocbq
*oldiocb
,
3827 struct lpfc_nodelist
*ndlp
)
3829 struct lpfc_hba
*phba
= vport
->phba
;
3834 struct lpfc_iocbq
*elsiocb
;
3835 struct lpfc_sli
*psli
;
3842 cmdsize
= sizeof(uint32_t) + sizeof(PRLI
);
3843 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
, ndlp
,
3844 ndlp
->nlp_DID
, (ELS_CMD_ACC
| (ELS_CMD_PRLI
& ~ELS_RSP_MASK
)));
3848 icmd
= &elsiocb
->iocb
;
3849 oldcmd
= &oldiocb
->iocb
;
3850 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri */
3851 /* Xmit PRLI ACC response tag <ulpIoTag> */
3852 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
3853 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
3854 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
3855 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
,
3856 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
3858 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
3860 *((uint32_t *) (pcmd
)) = (ELS_CMD_ACC
| (ELS_CMD_PRLI
& ~ELS_RSP_MASK
));
3861 pcmd
+= sizeof(uint32_t);
3863 /* For PRLI, remainder of payload is PRLI parameter page */
3864 memset(pcmd
, 0, sizeof(PRLI
));
3866 npr
= (PRLI
*) pcmd
;
3869 * If the remote port is a target and our firmware version is 3.20 or
3870 * later, set the following bits for FC-TAPE support.
3872 if ((ndlp
->nlp_type
& NLP_FCP_TARGET
) &&
3873 (vpd
->rev
.feaLevelHigh
>= 0x02)) {
3874 npr
->ConfmComplAllowed
= 1;
3876 npr
->TaskRetryIdReq
= 1;
3879 npr
->acceptRspCode
= PRLI_REQ_EXECUTED
;
3880 npr
->estabImagePair
= 1;
3881 npr
->readXferRdyDis
= 1;
3882 npr
->ConfmComplAllowed
= 1;
3884 npr
->prliType
= PRLI_FCP_TYPE
;
3885 npr
->initiatorFunc
= 1;
3887 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
3888 "Issue ACC PRLI: did:x%x flg:x%x",
3889 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
3891 phba
->fc_stat
.elsXmitACC
++;
3892 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
3894 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
3895 if (rc
== IOCB_ERROR
) {
3896 lpfc_els_free_iocb(phba
, elsiocb
);
3903 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
3904 * @vport: pointer to a virtual N_Port data structure.
3905 * @format: rnid command format.
3906 * @oldiocb: pointer to the original lpfc command iocb data structure.
3907 * @ndlp: pointer to a node-list data structure.
3909 * This routine issues a Request Node Identification Data (RNID) Accept
3910 * (ACC) response. It constructs the RNID ACC response command according to
3911 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
3912 * issue the response. Note that this command does not need to hold the ndlp
3913 * reference count for the callback. So, the ndlp reference count taken by
3914 * the lpfc_prep_els_iocb() routine is put back and the context1 field of
3915 * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
3916 * there is no ndlp reference available.
3918 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3919 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3920 * will be stored into the context1 field of the IOCB for the completion
3921 * callback function. However, for the RNID Accept Response ELS command,
3922 * this is undone later by this routine after the IOCB is allocated.
3925 * 0 - Successfully issued acc rnid response
3926 * 1 - Failed to issue acc rnid response
3929 lpfc_els_rsp_rnid_acc(struct lpfc_vport
*vport
, uint8_t format
,
3930 struct lpfc_iocbq
*oldiocb
, struct lpfc_nodelist
*ndlp
)
3932 struct lpfc_hba
*phba
= vport
->phba
;
3934 IOCB_t
*icmd
, *oldcmd
;
3935 struct lpfc_iocbq
*elsiocb
;
3936 struct lpfc_sli
*psli
;
3942 cmdsize
= sizeof(uint32_t) + sizeof(uint32_t)
3943 + (2 * sizeof(struct lpfc_name
));
3945 cmdsize
+= sizeof(RNID_TOP_DISC
);
3947 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
, ndlp
,
3948 ndlp
->nlp_DID
, ELS_CMD_ACC
);
3952 icmd
= &elsiocb
->iocb
;
3953 oldcmd
= &oldiocb
->iocb
;
3954 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri */
3955 /* Xmit RNID ACC response tag <ulpIoTag> */
3956 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
3957 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
3958 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
);
3959 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
3960 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
3961 pcmd
+= sizeof(uint32_t);
3963 memset(pcmd
, 0, sizeof(RNID
));
3964 rn
= (RNID
*) (pcmd
);
3965 rn
->Format
= format
;
3966 rn
->CommonLen
= (2 * sizeof(struct lpfc_name
));
3967 memcpy(&rn
->portName
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
3968 memcpy(&rn
->nodeName
, &vport
->fc_nodename
, sizeof(struct lpfc_name
));
3971 rn
->SpecificLen
= 0;
3973 case RNID_TOPOLOGY_DISC
:
3974 rn
->SpecificLen
= sizeof(RNID_TOP_DISC
);
3975 memcpy(&rn
->un
.topologyDisc
.portName
,
3976 &vport
->fc_portname
, sizeof(struct lpfc_name
));
3977 rn
->un
.topologyDisc
.unitType
= RNID_HBA
;
3978 rn
->un
.topologyDisc
.physPort
= 0;
3979 rn
->un
.topologyDisc
.attachedNodes
= 0;
3983 rn
->SpecificLen
= 0;
3987 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
3988 "Issue ACC RNID: did:x%x flg:x%x",
3989 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
3991 phba
->fc_stat
.elsXmitACC
++;
3992 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
3994 elsiocb
->context1
= NULL
; /* Don't need ndlp for cmpl,
3995 * it could be freed */
3997 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
3998 if (rc
== IOCB_ERROR
) {
3999 lpfc_els_free_iocb(phba
, elsiocb
);
4006 * lpfc_els_clear_rrq - Clear the rq that this rrq describes.
4007 * @vport: pointer to a virtual N_Port data structure.
4008 * @iocb: pointer to the lpfc command iocb data structure.
4009 * @ndlp: pointer to a node-list data structure.
4014 lpfc_els_clear_rrq(struct lpfc_vport
*vport
,
4015 struct lpfc_iocbq
*iocb
, struct lpfc_nodelist
*ndlp
)
4017 struct lpfc_hba
*phba
= vport
->phba
;
4021 struct lpfc_node_rrq
*prrq
;
4024 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) iocb
->context2
)->virt
);
4025 pcmd
+= sizeof(uint32_t);
4026 rrq
= (struct RRQ
*)pcmd
;
4027 rxid
= bf_get(rrq_oxid
, rrq
);
4029 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
4030 "2883 Clear RRQ for SID:x%x OXID:x%x RXID:x%x"
4032 bf_get(rrq_did
, rrq
),
4033 bf_get(rrq_oxid
, rrq
),
4035 iocb
->iotag
, iocb
->iocb
.ulpContext
);
4037 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
4038 "Clear RRQ: did:x%x flg:x%x exchg:x%.08x",
4039 ndlp
->nlp_DID
, ndlp
->nlp_flag
, rrq
->rrq_exchg
);
4040 prrq
= lpfc_get_active_rrq(vport
, rxid
, ndlp
->nlp_DID
);
4042 lpfc_clr_rrq_active(phba
, rxid
, prrq
);
4047 * lpfc_els_rsp_echo_acc - Issue echo acc response
4048 * @vport: pointer to a virtual N_Port data structure.
4049 * @data: pointer to echo data to return in the accept.
4050 * @oldiocb: pointer to the original lpfc command iocb data structure.
4051 * @ndlp: pointer to a node-list data structure.
4054 * 0 - Successfully issued acc echo response
4055 * 1 - Failed to issue acc echo response
4058 lpfc_els_rsp_echo_acc(struct lpfc_vport
*vport
, uint8_t *data
,
4059 struct lpfc_iocbq
*oldiocb
, struct lpfc_nodelist
*ndlp
)
4061 struct lpfc_hba
*phba
= vport
->phba
;
4062 struct lpfc_iocbq
*elsiocb
;
4063 struct lpfc_sli
*psli
;
4069 cmdsize
= oldiocb
->iocb
.unsli3
.rcvsli3
.acc_len
;
4071 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
, ndlp
,
4072 ndlp
->nlp_DID
, ELS_CMD_ACC
);
4076 elsiocb
->iocb
.ulpContext
= oldiocb
->iocb
.ulpContext
; /* Xri */
4077 /* Xmit ECHO ACC response tag <ulpIoTag> */
4078 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
4079 "2876 Xmit ECHO ACC response tag x%x xri x%x\n",
4080 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
);
4081 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
4082 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
4083 pcmd
+= sizeof(uint32_t);
4084 memcpy(pcmd
, data
, cmdsize
- sizeof(uint32_t));
4086 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
4087 "Issue ACC ECHO: did:x%x flg:x%x",
4088 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
4090 phba
->fc_stat
.elsXmitACC
++;
4091 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
4093 elsiocb
->context1
= NULL
; /* Don't need ndlp for cmpl,
4094 * it could be freed */
4096 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
4097 if (rc
== IOCB_ERROR
) {
4098 lpfc_els_free_iocb(phba
, elsiocb
);
4105 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
4106 * @vport: pointer to a host virtual N_Port data structure.
4108 * This routine issues Address Discover (ADISC) ELS commands to those
4109 * N_Ports which are in node port recovery state and ADISC has not been issued
4110 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
4111 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
4112 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
4113 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
4114 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
4115 * IOCBs quit for later pick up. On the other hand, after walking through
4116 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
4117 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
4118 * no more ADISC need to be sent.
4121 * The number of N_Ports with adisc issued.
4124 lpfc_els_disc_adisc(struct lpfc_vport
*vport
)
4126 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4127 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
4130 /* go thru NPR nodes and issue any remaining ELS ADISCs */
4131 list_for_each_entry_safe(ndlp
, next_ndlp
, &vport
->fc_nodes
, nlp_listp
) {
4132 if (!NLP_CHK_NODE_ACT(ndlp
))
4134 if (ndlp
->nlp_state
== NLP_STE_NPR_NODE
&&
4135 (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
) != 0 &&
4136 (ndlp
->nlp_flag
& NLP_NPR_ADISC
) != 0) {
4137 spin_lock_irq(shost
->host_lock
);
4138 ndlp
->nlp_flag
&= ~NLP_NPR_ADISC
;
4139 spin_unlock_irq(shost
->host_lock
);
4140 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
4141 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_ADISC_ISSUE
);
4142 lpfc_issue_els_adisc(vport
, ndlp
, 0);
4144 vport
->num_disc_nodes
++;
4145 if (vport
->num_disc_nodes
>=
4146 vport
->cfg_discovery_threads
) {
4147 spin_lock_irq(shost
->host_lock
);
4148 vport
->fc_flag
|= FC_NLP_MORE
;
4149 spin_unlock_irq(shost
->host_lock
);
4154 if (sentadisc
== 0) {
4155 spin_lock_irq(shost
->host_lock
);
4156 vport
->fc_flag
&= ~FC_NLP_MORE
;
4157 spin_unlock_irq(shost
->host_lock
);
4163 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
4164 * @vport: pointer to a host virtual N_Port data structure.
4166 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
4167 * which are in node port recovery state, with a @vport. Each time an ELS
4168 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
4169 * the per @vport number of discover count (num_disc_nodes) shall be
4170 * incremented. If the num_disc_nodes reaches a pre-configured threshold
4171 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
4172 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
4173 * later pick up. On the other hand, after walking through all the ndlps with
4174 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
4175 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
4176 * PLOGI need to be sent.
4179 * The number of N_Ports with plogi issued.
4182 lpfc_els_disc_plogi(struct lpfc_vport
*vport
)
4184 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4185 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
4188 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
4189 list_for_each_entry_safe(ndlp
, next_ndlp
, &vport
->fc_nodes
, nlp_listp
) {
4190 if (!NLP_CHK_NODE_ACT(ndlp
))
4192 if (ndlp
->nlp_state
== NLP_STE_NPR_NODE
&&
4193 (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
) != 0 &&
4194 (ndlp
->nlp_flag
& NLP_DELAY_TMO
) == 0 &&
4195 (ndlp
->nlp_flag
& NLP_NPR_ADISC
) == 0) {
4196 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
4197 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
4198 lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, 0);
4200 vport
->num_disc_nodes
++;
4201 if (vport
->num_disc_nodes
>=
4202 vport
->cfg_discovery_threads
) {
4203 spin_lock_irq(shost
->host_lock
);
4204 vport
->fc_flag
|= FC_NLP_MORE
;
4205 spin_unlock_irq(shost
->host_lock
);
4211 lpfc_set_disctmo(vport
);
4214 spin_lock_irq(shost
->host_lock
);
4215 vport
->fc_flag
&= ~FC_NLP_MORE
;
4216 spin_unlock_irq(shost
->host_lock
);
4222 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
4223 * @vport: pointer to a host virtual N_Port data structure.
4225 * This routine cleans up any Registration State Change Notification
4226 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
4227 * @vport together with the host_lock is used to prevent multiple thread
4228 * trying to access the RSCN array on a same @vport at the same time.
4231 lpfc_els_flush_rscn(struct lpfc_vport
*vport
)
4233 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4234 struct lpfc_hba
*phba
= vport
->phba
;
4237 spin_lock_irq(shost
->host_lock
);
4238 if (vport
->fc_rscn_flush
) {
4239 /* Another thread is walking fc_rscn_id_list on this vport */
4240 spin_unlock_irq(shost
->host_lock
);
4243 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
4244 vport
->fc_rscn_flush
= 1;
4245 spin_unlock_irq(shost
->host_lock
);
4247 for (i
= 0; i
< vport
->fc_rscn_id_cnt
; i
++) {
4248 lpfc_in_buf_free(phba
, vport
->fc_rscn_id_list
[i
]);
4249 vport
->fc_rscn_id_list
[i
] = NULL
;
4251 spin_lock_irq(shost
->host_lock
);
4252 vport
->fc_rscn_id_cnt
= 0;
4253 vport
->fc_flag
&= ~(FC_RSCN_MODE
| FC_RSCN_DISCOVERY
);
4254 spin_unlock_irq(shost
->host_lock
);
4255 lpfc_can_disctmo(vport
);
4256 /* Indicate we are done walking this fc_rscn_id_list */
4257 vport
->fc_rscn_flush
= 0;
4261 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
4262 * @vport: pointer to a host virtual N_Port data structure.
4263 * @did: remote destination port identifier.
4265 * This routine checks whether there is any pending Registration State
4266 * Configuration Notification (RSCN) to a @did on @vport.
4269 * None zero - The @did matched with a pending rscn
4270 * 0 - not able to match @did with a pending rscn
4273 lpfc_rscn_payload_check(struct lpfc_vport
*vport
, uint32_t did
)
4278 uint32_t payload_len
, i
;
4279 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4281 ns_did
.un
.word
= did
;
4283 /* Never match fabric nodes for RSCNs */
4284 if ((did
& Fabric_DID_MASK
) == Fabric_DID_MASK
)
4287 /* If we are doing a FULL RSCN rediscovery, match everything */
4288 if (vport
->fc_flag
& FC_RSCN_DISCOVERY
)
4291 spin_lock_irq(shost
->host_lock
);
4292 if (vport
->fc_rscn_flush
) {
4293 /* Another thread is walking fc_rscn_id_list on this vport */
4294 spin_unlock_irq(shost
->host_lock
);
4297 /* Indicate we are walking fc_rscn_id_list on this vport */
4298 vport
->fc_rscn_flush
= 1;
4299 spin_unlock_irq(shost
->host_lock
);
4300 for (i
= 0; i
< vport
->fc_rscn_id_cnt
; i
++) {
4301 lp
= vport
->fc_rscn_id_list
[i
]->virt
;
4302 payload_len
= be32_to_cpu(*lp
++ & ~ELS_CMD_MASK
);
4303 payload_len
-= sizeof(uint32_t); /* take off word 0 */
4304 while (payload_len
) {
4305 rscn_did
.un
.word
= be32_to_cpu(*lp
++);
4306 payload_len
-= sizeof(uint32_t);
4307 switch (rscn_did
.un
.b
.resv
& RSCN_ADDRESS_FORMAT_MASK
) {
4308 case RSCN_ADDRESS_FORMAT_PORT
:
4309 if ((ns_did
.un
.b
.domain
== rscn_did
.un
.b
.domain
)
4310 && (ns_did
.un
.b
.area
== rscn_did
.un
.b
.area
)
4311 && (ns_did
.un
.b
.id
== rscn_did
.un
.b
.id
))
4312 goto return_did_out
;
4314 case RSCN_ADDRESS_FORMAT_AREA
:
4315 if ((ns_did
.un
.b
.domain
== rscn_did
.un
.b
.domain
)
4316 && (ns_did
.un
.b
.area
== rscn_did
.un
.b
.area
))
4317 goto return_did_out
;
4319 case RSCN_ADDRESS_FORMAT_DOMAIN
:
4320 if (ns_did
.un
.b
.domain
== rscn_did
.un
.b
.domain
)
4321 goto return_did_out
;
4323 case RSCN_ADDRESS_FORMAT_FABRIC
:
4324 goto return_did_out
;
4328 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4329 vport
->fc_rscn_flush
= 0;
4332 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4333 vport
->fc_rscn_flush
= 0;
4338 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
4339 * @vport: pointer to a host virtual N_Port data structure.
4341 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
4342 * state machine for a @vport's nodes that are with pending RSCN (Registration
4343 * State Change Notification).
4346 * 0 - Successful (currently alway return 0)
4349 lpfc_rscn_recovery_check(struct lpfc_vport
*vport
)
4351 struct lpfc_nodelist
*ndlp
= NULL
;
4353 /* Move all affected nodes by pending RSCNs to NPR state. */
4354 list_for_each_entry(ndlp
, &vport
->fc_nodes
, nlp_listp
) {
4355 if (!NLP_CHK_NODE_ACT(ndlp
) ||
4356 (ndlp
->nlp_state
== NLP_STE_UNUSED_NODE
) ||
4357 !lpfc_rscn_payload_check(vport
, ndlp
->nlp_DID
))
4359 lpfc_disc_state_machine(vport
, ndlp
, NULL
,
4360 NLP_EVT_DEVICE_RECOVERY
);
4361 lpfc_cancel_retry_delay_tmo(vport
, ndlp
);
4367 * lpfc_send_rscn_event - Send an RSCN event to management application
4368 * @vport: pointer to a host virtual N_Port data structure.
4369 * @cmdiocb: pointer to lpfc command iocb data structure.
4371 * lpfc_send_rscn_event sends an RSCN netlink event to management
4375 lpfc_send_rscn_event(struct lpfc_vport
*vport
,
4376 struct lpfc_iocbq
*cmdiocb
)
4378 struct lpfc_dmabuf
*pcmd
;
4379 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4380 uint32_t *payload_ptr
;
4381 uint32_t payload_len
;
4382 struct lpfc_rscn_event_header
*rscn_event_data
;
4384 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
4385 payload_ptr
= (uint32_t *) pcmd
->virt
;
4386 payload_len
= be32_to_cpu(*payload_ptr
& ~ELS_CMD_MASK
);
4388 rscn_event_data
= kmalloc(sizeof(struct lpfc_rscn_event_header
) +
4389 payload_len
, GFP_KERNEL
);
4390 if (!rscn_event_data
) {
4391 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
4392 "0147 Failed to allocate memory for RSCN event\n");
4395 rscn_event_data
->event_type
= FC_REG_RSCN_EVENT
;
4396 rscn_event_data
->payload_length
= payload_len
;
4397 memcpy(rscn_event_data
->rscn_payload
, payload_ptr
,
4400 fc_host_post_vendor_event(shost
,
4401 fc_get_event_number(),
4402 sizeof(struct lpfc_els_event_header
) + payload_len
,
4403 (char *)rscn_event_data
,
4406 kfree(rscn_event_data
);
4410 * lpfc_els_rcv_rscn - Process an unsolicited rscn 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 an unsolicited RSCN (Registration State Change
4416 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
4417 * to invoke fc_host_post_event() routine to the FC transport layer. If the
4418 * discover state machine is about to begin discovery, it just accepts the
4419 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
4420 * contains N_Port IDs for other vports on this HBA, it just accepts the
4421 * RSCN and ignore processing it. If the state machine is in the recovery
4422 * state, the fc_rscn_id_list of this @vport is walked and the
4423 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
4424 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
4425 * routine is invoked to handle the RSCN event.
4428 * 0 - Just sent the acc response
4429 * 1 - Sent the acc response and waited for name server completion
4432 lpfc_els_rcv_rscn(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
4433 struct lpfc_nodelist
*ndlp
)
4435 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4436 struct lpfc_hba
*phba
= vport
->phba
;
4437 struct lpfc_dmabuf
*pcmd
;
4438 uint32_t *lp
, *datap
;
4440 uint32_t payload_len
, length
, nportid
, *cmd
;
4442 int rscn_id
= 0, hba_id
= 0;
4445 icmd
= &cmdiocb
->iocb
;
4446 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
4447 lp
= (uint32_t *) pcmd
->virt
;
4449 payload_len
= be32_to_cpu(*lp
++ & ~ELS_CMD_MASK
);
4450 payload_len
-= sizeof(uint32_t); /* take off word 0 */
4452 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
4453 "0214 RSCN received Data: x%x x%x x%x x%x\n",
4454 vport
->fc_flag
, payload_len
, *lp
,
4455 vport
->fc_rscn_id_cnt
);
4457 /* Send an RSCN event to the management application */
4458 lpfc_send_rscn_event(vport
, cmdiocb
);
4460 for (i
= 0; i
< payload_len
/sizeof(uint32_t); i
++)
4461 fc_host_post_event(shost
, fc_get_event_number(),
4462 FCH_EVT_RSCN
, lp
[i
]);
4464 /* If we are about to begin discovery, just ACC the RSCN.
4465 * Discovery processing will satisfy it.
4467 if (vport
->port_state
<= LPFC_NS_QRY
) {
4468 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
4469 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
4470 ndlp
->nlp_DID
, vport
->port_state
, ndlp
->nlp_flag
);
4472 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
4476 /* If this RSCN just contains NPortIDs for other vports on this HBA,
4477 * just ACC and ignore it.
4479 if ((phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
4480 !(vport
->cfg_peer_port_login
)) {
4485 nportid
= ((be32_to_cpu(nportid
)) & Mask_DID
);
4486 i
-= sizeof(uint32_t);
4488 if (lpfc_find_vport_by_did(phba
, nportid
))
4491 if (rscn_id
== hba_id
) {
4492 /* ALL NPortIDs in RSCN are on HBA */
4493 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
4495 "Data: x%x x%x x%x x%x\n",
4496 vport
->fc_flag
, payload_len
,
4497 *lp
, vport
->fc_rscn_id_cnt
);
4498 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
4499 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
4500 ndlp
->nlp_DID
, vport
->port_state
,
4503 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
,
4509 spin_lock_irq(shost
->host_lock
);
4510 if (vport
->fc_rscn_flush
) {
4511 /* Another thread is walking fc_rscn_id_list on this vport */
4512 vport
->fc_flag
|= FC_RSCN_DISCOVERY
;
4513 spin_unlock_irq(shost
->host_lock
);
4515 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
4518 /* Indicate we are walking fc_rscn_id_list on this vport */
4519 vport
->fc_rscn_flush
= 1;
4520 spin_unlock_irq(shost
->host_lock
);
4521 /* Get the array count after successfully have the token */
4522 rscn_cnt
= vport
->fc_rscn_id_cnt
;
4523 /* If we are already processing an RSCN, save the received
4524 * RSCN payload buffer, cmdiocb->context2 to process later.
4526 if (vport
->fc_flag
& (FC_RSCN_MODE
| FC_NDISC_ACTIVE
)) {
4527 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
4528 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
4529 ndlp
->nlp_DID
, vport
->port_state
, ndlp
->nlp_flag
);
4531 spin_lock_irq(shost
->host_lock
);
4532 vport
->fc_flag
|= FC_RSCN_DEFERRED
;
4533 if ((rscn_cnt
< FC_MAX_HOLD_RSCN
) &&
4534 !(vport
->fc_flag
& FC_RSCN_DISCOVERY
)) {
4535 vport
->fc_flag
|= FC_RSCN_MODE
;
4536 spin_unlock_irq(shost
->host_lock
);
4538 cmd
= vport
->fc_rscn_id_list
[rscn_cnt
-1]->virt
;
4539 length
= be32_to_cpu(*cmd
& ~ELS_CMD_MASK
);
4542 (payload_len
+ length
<= LPFC_BPL_SIZE
)) {
4543 *cmd
&= ELS_CMD_MASK
;
4544 *cmd
|= cpu_to_be32(payload_len
+ length
);
4545 memcpy(((uint8_t *)cmd
) + length
, lp
,
4548 vport
->fc_rscn_id_list
[rscn_cnt
] = pcmd
;
4549 vport
->fc_rscn_id_cnt
++;
4550 /* If we zero, cmdiocb->context2, the calling
4551 * routine will not try to free it.
4553 cmdiocb
->context2
= NULL
;
4556 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
4557 "0235 Deferred RSCN "
4558 "Data: x%x x%x x%x\n",
4559 vport
->fc_rscn_id_cnt
, vport
->fc_flag
,
4562 vport
->fc_flag
|= FC_RSCN_DISCOVERY
;
4563 spin_unlock_irq(shost
->host_lock
);
4564 /* ReDiscovery RSCN */
4565 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
4566 "0234 ReDiscovery RSCN "
4567 "Data: x%x x%x x%x\n",
4568 vport
->fc_rscn_id_cnt
, vport
->fc_flag
,
4571 /* Indicate we are done walking fc_rscn_id_list on this vport */
4572 vport
->fc_rscn_flush
= 0;
4574 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
4575 /* send RECOVERY event for ALL nodes that match RSCN payload */
4576 lpfc_rscn_recovery_check(vport
);
4577 spin_lock_irq(shost
->host_lock
);
4578 vport
->fc_flag
&= ~FC_RSCN_DEFERRED
;
4579 spin_unlock_irq(shost
->host_lock
);
4582 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
4583 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
4584 ndlp
->nlp_DID
, vport
->port_state
, ndlp
->nlp_flag
);
4586 spin_lock_irq(shost
->host_lock
);
4587 vport
->fc_flag
|= FC_RSCN_MODE
;
4588 spin_unlock_irq(shost
->host_lock
);
4589 vport
->fc_rscn_id_list
[vport
->fc_rscn_id_cnt
++] = pcmd
;
4590 /* Indicate we are done walking fc_rscn_id_list on this vport */
4591 vport
->fc_rscn_flush
= 0;
4593 * If we zero, cmdiocb->context2, the calling routine will
4594 * not try to free it.
4596 cmdiocb
->context2
= NULL
;
4597 lpfc_set_disctmo(vport
);
4599 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
4600 /* send RECOVERY event for ALL nodes that match RSCN payload */
4601 lpfc_rscn_recovery_check(vport
);
4602 return lpfc_els_handle_rscn(vport
);
4606 * lpfc_els_handle_rscn - Handle rscn for a vport
4607 * @vport: pointer to a host virtual N_Port data structure.
4609 * This routine handles the Registration State Configuration Notification
4610 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
4611 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
4612 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
4613 * NameServer shall be issued. If CT command to the NameServer fails to be
4614 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
4615 * RSCN activities with the @vport.
4618 * 0 - Cleaned up rscn on the @vport
4619 * 1 - Wait for plogi to name server before proceed
4622 lpfc_els_handle_rscn(struct lpfc_vport
*vport
)
4624 struct lpfc_nodelist
*ndlp
;
4625 struct lpfc_hba
*phba
= vport
->phba
;
4627 /* Ignore RSCN if the port is being torn down. */
4628 if (vport
->load_flag
& FC_UNLOADING
) {
4629 lpfc_els_flush_rscn(vport
);
4633 /* Start timer for RSCN processing */
4634 lpfc_set_disctmo(vport
);
4636 /* RSCN processed */
4637 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
4638 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
4639 vport
->fc_flag
, 0, vport
->fc_rscn_id_cnt
,
4642 /* To process RSCN, first compare RSCN data with NameServer */
4643 vport
->fc_ns_retry
= 0;
4644 vport
->num_disc_nodes
= 0;
4646 ndlp
= lpfc_findnode_did(vport
, NameServer_DID
);
4647 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
)
4648 && ndlp
->nlp_state
== NLP_STE_UNMAPPED_NODE
) {
4649 /* Good ndlp, issue CT Request to NameServer */
4650 if (lpfc_ns_cmd(vport
, SLI_CTNS_GID_FT
, 0, 0) == 0)
4651 /* Wait for NameServer query cmpl before we can
4655 /* If login to NameServer does not exist, issue one */
4656 /* Good status, issue PLOGI to NameServer */
4657 ndlp
= lpfc_findnode_did(vport
, NameServer_DID
);
4658 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
))
4659 /* Wait for NameServer login cmpl before we can
4664 ndlp
= lpfc_enable_node(vport
, ndlp
,
4665 NLP_STE_PLOGI_ISSUE
);
4667 lpfc_els_flush_rscn(vport
);
4670 ndlp
->nlp_prev_state
= NLP_STE_UNUSED_NODE
;
4672 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
4674 lpfc_els_flush_rscn(vport
);
4677 lpfc_nlp_init(vport
, ndlp
, NameServer_DID
);
4678 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
4679 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
4681 ndlp
->nlp_type
|= NLP_FABRIC
;
4682 lpfc_issue_els_plogi(vport
, NameServer_DID
, 0);
4683 /* Wait for NameServer login cmpl before we can
4689 lpfc_els_flush_rscn(vport
);
4694 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
4695 * @vport: pointer to a host virtual N_Port data structure.
4696 * @cmdiocb: pointer to lpfc command iocb data structure.
4697 * @ndlp: pointer to a node-list data structure.
4699 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
4700 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
4701 * point topology. As an unsolicited FLOGI should not be received in a loop
4702 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
4703 * lpfc_check_sparm() routine is invoked to check the parameters in the
4704 * unsolicited FLOGI. If parameters validation failed, the routine
4705 * lpfc_els_rsp_reject() shall be called with reject reason code set to
4706 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
4707 * FLOGI shall be compared with the Port WWN of the @vport to determine who
4708 * will initiate PLOGI. The higher lexicographical value party shall has
4709 * higher priority (as the winning port) and will initiate PLOGI and
4710 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
4711 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
4712 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
4715 * 0 - Successfully processed the unsolicited flogi
4716 * 1 - Failed to process the unsolicited flogi
4719 lpfc_els_rcv_flogi(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
4720 struct lpfc_nodelist
*ndlp
)
4722 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4723 struct lpfc_hba
*phba
= vport
->phba
;
4724 struct lpfc_dmabuf
*pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
4725 uint32_t *lp
= (uint32_t *) pcmd
->virt
;
4726 IOCB_t
*icmd
= &cmdiocb
->iocb
;
4727 struct serv_parm
*sp
;
4734 sp
= (struct serv_parm
*) lp
;
4736 /* FLOGI received */
4738 lpfc_set_disctmo(vport
);
4740 if (phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
) {
4741 /* We should never receive a FLOGI in loop mode, ignore it */
4742 did
= icmd
->un
.elsreq64
.remoteID
;
4744 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
4746 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
4747 "0113 An FLOGI ELS command x%x was "
4748 "received from DID x%x in Loop Mode\n",
4755 if ((lpfc_check_sparm(vport
, ndlp
, sp
, CLASS3
, 1))) {
4756 /* For a FLOGI we accept, then if our portname is greater
4757 * then the remote portname we initiate Nport login.
4760 rc
= memcmp(&vport
->fc_portname
, &sp
->portName
,
4761 sizeof(struct lpfc_name
));
4764 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4768 lpfc_linkdown(phba
);
4769 lpfc_init_link(phba
, mbox
,
4771 phba
->cfg_link_speed
);
4772 mbox
->u
.mb
.un
.varInitLnk
.lipsr_AL_PA
= 0;
4773 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
4774 mbox
->vport
= vport
;
4775 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
4776 lpfc_set_loopback_flag(phba
);
4777 if (rc
== MBX_NOT_FINISHED
) {
4778 mempool_free(mbox
, phba
->mbox_mem_pool
);
4781 } else if (rc
> 0) { /* greater than */
4782 spin_lock_irq(shost
->host_lock
);
4783 vport
->fc_flag
|= FC_PT2PT_PLOGI
;
4784 spin_unlock_irq(shost
->host_lock
);
4786 spin_lock_irq(shost
->host_lock
);
4787 vport
->fc_flag
|= FC_PT2PT
;
4788 vport
->fc_flag
&= ~(FC_FABRIC
| FC_PUBLIC_LOOP
);
4789 spin_unlock_irq(shost
->host_lock
);
4791 /* Reject this request because invalid parameters */
4792 stat
.un
.b
.lsRjtRsvd0
= 0;
4793 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
4794 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_SPARM_OPTIONS
;
4795 stat
.un
.b
.vendorUnique
= 0;
4796 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
,
4802 lpfc_els_rsp_acc(vport
, ELS_CMD_PLOGI
, cmdiocb
, ndlp
, NULL
);
4808 * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
4809 * @vport: pointer to a host virtual N_Port data structure.
4810 * @cmdiocb: pointer to lpfc command iocb data structure.
4811 * @ndlp: pointer to a node-list data structure.
4813 * This routine processes Request Node Identification Data (RNID) IOCB
4814 * received as an ELS unsolicited event. Only when the RNID specified format
4815 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
4816 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
4817 * Accept (ACC) the RNID ELS command. All the other RNID formats are
4818 * rejected by invoking the lpfc_els_rsp_reject() routine.
4821 * 0 - Successfully processed rnid iocb (currently always return 0)
4824 lpfc_els_rcv_rnid(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
4825 struct lpfc_nodelist
*ndlp
)
4827 struct lpfc_dmabuf
*pcmd
;
4834 icmd
= &cmdiocb
->iocb
;
4835 did
= icmd
->un
.elsreq64
.remoteID
;
4836 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
4837 lp
= (uint32_t *) pcmd
->virt
;
4844 switch (rn
->Format
) {
4846 case RNID_TOPOLOGY_DISC
:
4848 lpfc_els_rsp_rnid_acc(vport
, rn
->Format
, cmdiocb
, ndlp
);
4851 /* Reject this request because format not supported */
4852 stat
.un
.b
.lsRjtRsvd0
= 0;
4853 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
4854 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_CANT_GIVE_DATA
;
4855 stat
.un
.b
.vendorUnique
= 0;
4856 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
,
4863 * lpfc_els_rcv_echo - Process an unsolicited echo iocb
4864 * @vport: pointer to a host virtual N_Port data structure.
4865 * @cmdiocb: pointer to lpfc command iocb data structure.
4866 * @ndlp: pointer to a node-list data structure.
4869 * 0 - Successfully processed echo iocb (currently always return 0)
4872 lpfc_els_rcv_echo(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
4873 struct lpfc_nodelist
*ndlp
)
4877 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) cmdiocb
->context2
)->virt
);
4879 /* skip over first word of echo command to find echo data */
4880 pcmd
+= sizeof(uint32_t);
4882 lpfc_els_rsp_echo_acc(vport
, pcmd
, cmdiocb
, ndlp
);
4887 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
4888 * @vport: pointer to a host virtual N_Port data structure.
4889 * @cmdiocb: pointer to lpfc command iocb data structure.
4890 * @ndlp: pointer to a node-list data structure.
4892 * This routine processes a Link Incident Report Registration(LIRR) IOCB
4893 * received as an ELS unsolicited event. Currently, this function just invokes
4894 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
4897 * 0 - Successfully processed lirr iocb (currently always return 0)
4900 lpfc_els_rcv_lirr(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
4901 struct lpfc_nodelist
*ndlp
)
4905 /* For now, unconditionally reject this command */
4906 stat
.un
.b
.lsRjtRsvd0
= 0;
4907 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
4908 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_CANT_GIVE_DATA
;
4909 stat
.un
.b
.vendorUnique
= 0;
4910 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
4915 * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb
4916 * @vport: pointer to a host virtual N_Port data structure.
4917 * @cmdiocb: pointer to lpfc command iocb data structure.
4918 * @ndlp: pointer to a node-list data structure.
4920 * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB
4921 * received as an ELS unsolicited event. A request to RRQ shall only
4922 * be accepted if the Originator Nx_Port N_Port_ID or the Responder
4923 * Nx_Port N_Port_ID of the target Exchange is the same as the
4924 * N_Port_ID of the Nx_Port that makes the request. If the RRQ is
4925 * not accepted, an LS_RJT with reason code "Unable to perform
4926 * command request" and reason code explanation "Invalid Originator
4927 * S_ID" shall be returned. For now, we just unconditionally accept
4928 * RRQ from the target.
4931 lpfc_els_rcv_rrq(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
4932 struct lpfc_nodelist
*ndlp
)
4934 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
4935 if (vport
->phba
->sli_rev
== LPFC_SLI_REV4
)
4936 lpfc_els_clear_rrq(vport
, cmdiocb
, ndlp
);
4940 * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
4941 * @phba: pointer to lpfc hba data structure.
4942 * @pmb: pointer to the driver internal queue element for mailbox command.
4944 * This routine is the completion callback function for the MBX_READ_LNK_STAT
4945 * mailbox command. This callback function is to actually send the Accept
4946 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
4947 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
4948 * mailbox command, constructs the RPS response with the link statistics
4949 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
4950 * response to the RPS.
4952 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4953 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4954 * will be stored into the context1 field of the IOCB for the completion
4955 * callback function to the RPS Accept Response ELS IOCB command.
4959 lpfc_els_rsp_rls_acc(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
4963 struct RLS_RSP
*rls_rsp
;
4965 struct lpfc_iocbq
*elsiocb
;
4966 struct lpfc_nodelist
*ndlp
;
4972 ndlp
= (struct lpfc_nodelist
*) pmb
->context2
;
4973 xri
= (uint16_t) ((unsigned long)(pmb
->context1
));
4974 pmb
->context1
= NULL
;
4975 pmb
->context2
= NULL
;
4977 if (mb
->mbxStatus
) {
4978 mempool_free(pmb
, phba
->mbox_mem_pool
);
4982 cmdsize
= sizeof(struct RLS_RSP
) + sizeof(uint32_t);
4983 mempool_free(pmb
, phba
->mbox_mem_pool
);
4984 elsiocb
= lpfc_prep_els_iocb(phba
->pport
, 0, cmdsize
,
4985 lpfc_max_els_tries
, ndlp
,
4986 ndlp
->nlp_DID
, ELS_CMD_ACC
);
4988 /* Decrement the ndlp reference count from previous mbox command */
4994 icmd
= &elsiocb
->iocb
;
4995 icmd
->ulpContext
= xri
;
4997 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
4998 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
4999 pcmd
+= sizeof(uint32_t); /* Skip past command */
5000 rls_rsp
= (struct RLS_RSP
*)pcmd
;
5002 rls_rsp
->linkFailureCnt
= cpu_to_be32(mb
->un
.varRdLnk
.linkFailureCnt
);
5003 rls_rsp
->lossSyncCnt
= cpu_to_be32(mb
->un
.varRdLnk
.lossSyncCnt
);
5004 rls_rsp
->lossSignalCnt
= cpu_to_be32(mb
->un
.varRdLnk
.lossSignalCnt
);
5005 rls_rsp
->primSeqErrCnt
= cpu_to_be32(mb
->un
.varRdLnk
.primSeqErrCnt
);
5006 rls_rsp
->invalidXmitWord
= cpu_to_be32(mb
->un
.varRdLnk
.invalidXmitWord
);
5007 rls_rsp
->crcCnt
= cpu_to_be32(mb
->un
.varRdLnk
.crcCnt
);
5009 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
5010 lpfc_printf_vlog(ndlp
->vport
, KERN_INFO
, LOG_ELS
,
5011 "2874 Xmit ELS RLS ACC response tag x%x xri x%x, "
5012 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
5013 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
,
5014 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
5016 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
5017 phba
->fc_stat
.elsXmitACC
++;
5018 if (lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0) == IOCB_ERROR
)
5019 lpfc_els_free_iocb(phba
, elsiocb
);
5023 * lpfc_els_rsp_rps_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
5024 * @phba: pointer to lpfc hba data structure.
5025 * @pmb: pointer to the driver internal queue element for mailbox command.
5027 * This routine is the completion callback function for the MBX_READ_LNK_STAT
5028 * mailbox command. This callback function is to actually send the Accept
5029 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
5030 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
5031 * mailbox command, constructs the RPS response with the link statistics
5032 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
5033 * response to the RPS.
5035 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5036 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5037 * will be stored into the context1 field of the IOCB for the completion
5038 * callback function to the RPS Accept Response ELS IOCB command.
5042 lpfc_els_rsp_rps_acc(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
5048 struct lpfc_iocbq
*elsiocb
;
5049 struct lpfc_nodelist
*ndlp
;
5050 uint16_t xri
, status
;
5055 ndlp
= (struct lpfc_nodelist
*) pmb
->context2
;
5056 xri
= (uint16_t) ((unsigned long)(pmb
->context1
));
5057 pmb
->context1
= NULL
;
5058 pmb
->context2
= NULL
;
5060 if (mb
->mbxStatus
) {
5061 mempool_free(pmb
, phba
->mbox_mem_pool
);
5065 cmdsize
= sizeof(RPS_RSP
) + sizeof(uint32_t);
5066 mempool_free(pmb
, phba
->mbox_mem_pool
);
5067 elsiocb
= lpfc_prep_els_iocb(phba
->pport
, 0, cmdsize
,
5068 lpfc_max_els_tries
, ndlp
,
5069 ndlp
->nlp_DID
, ELS_CMD_ACC
);
5071 /* Decrement the ndlp reference count from previous mbox command */
5077 icmd
= &elsiocb
->iocb
;
5078 icmd
->ulpContext
= xri
;
5080 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
5081 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
5082 pcmd
+= sizeof(uint32_t); /* Skip past command */
5083 rps_rsp
= (RPS_RSP
*)pcmd
;
5085 if (phba
->fc_topology
!= LPFC_TOPOLOGY_LOOP
)
5089 if (phba
->pport
->fc_flag
& FC_FABRIC
)
5093 rps_rsp
->portStatus
= cpu_to_be16(status
);
5094 rps_rsp
->linkFailureCnt
= cpu_to_be32(mb
->un
.varRdLnk
.linkFailureCnt
);
5095 rps_rsp
->lossSyncCnt
= cpu_to_be32(mb
->un
.varRdLnk
.lossSyncCnt
);
5096 rps_rsp
->lossSignalCnt
= cpu_to_be32(mb
->un
.varRdLnk
.lossSignalCnt
);
5097 rps_rsp
->primSeqErrCnt
= cpu_to_be32(mb
->un
.varRdLnk
.primSeqErrCnt
);
5098 rps_rsp
->invalidXmitWord
= cpu_to_be32(mb
->un
.varRdLnk
.invalidXmitWord
);
5099 rps_rsp
->crcCnt
= cpu_to_be32(mb
->un
.varRdLnk
.crcCnt
);
5100 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
5101 lpfc_printf_vlog(ndlp
->vport
, KERN_INFO
, LOG_ELS
,
5102 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
5103 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
5104 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
,
5105 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
5107 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
5108 phba
->fc_stat
.elsXmitACC
++;
5109 if (lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0) == IOCB_ERROR
)
5110 lpfc_els_free_iocb(phba
, elsiocb
);
5115 * lpfc_els_rcv_rls - Process an unsolicited rls iocb
5116 * @vport: pointer to a host virtual N_Port data structure.
5117 * @cmdiocb: pointer to lpfc command iocb data structure.
5118 * @ndlp: pointer to a node-list data structure.
5120 * This routine processes Read Port Status (RPL) IOCB received as an
5121 * ELS unsolicited event. It first checks the remote port state. If the
5122 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5123 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
5124 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
5125 * for reading the HBA link statistics. It is for the callback function,
5126 * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command
5127 * to actually sending out RPL Accept (ACC) response.
5130 * 0 - Successfully processed rls iocb (currently always return 0)
5133 lpfc_els_rcv_rls(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
5134 struct lpfc_nodelist
*ndlp
)
5136 struct lpfc_hba
*phba
= vport
->phba
;
5138 struct lpfc_dmabuf
*pcmd
;
5141 if ((ndlp
->nlp_state
!= NLP_STE_UNMAPPED_NODE
) &&
5142 (ndlp
->nlp_state
!= NLP_STE_MAPPED_NODE
))
5143 /* reject the unsolicited RPS request and done with it */
5146 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
5148 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_ATOMIC
);
5150 lpfc_read_lnk_stat(phba
, mbox
);
5152 (void *)((unsigned long) cmdiocb
->iocb
.ulpContext
);
5153 mbox
->context2
= lpfc_nlp_get(ndlp
);
5154 mbox
->vport
= vport
;
5155 mbox
->mbox_cmpl
= lpfc_els_rsp_rls_acc
;
5156 if (lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
)
5157 != MBX_NOT_FINISHED
)
5158 /* Mbox completion will send ELS Response */
5160 /* Decrement reference count used for the failed mbox
5164 mempool_free(mbox
, phba
->mbox_mem_pool
);
5167 /* issue rejection response */
5168 stat
.un
.b
.lsRjtRsvd0
= 0;
5169 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
5170 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_CANT_GIVE_DATA
;
5171 stat
.un
.b
.vendorUnique
= 0;
5172 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
5177 * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb
5178 * @vport: pointer to a host virtual N_Port data structure.
5179 * @cmdiocb: pointer to lpfc command iocb data structure.
5180 * @ndlp: pointer to a node-list data structure.
5182 * This routine processes Read Timout Value (RTV) IOCB received as an
5183 * ELS unsolicited event. It first checks the remote port state. If the
5184 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5185 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
5186 * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout
5187 * Value (RTV) unsolicited IOCB event.
5189 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5190 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5191 * will be stored into the context1 field of the IOCB for the completion
5192 * callback function to the RPS Accept Response ELS IOCB command.
5195 * 0 - Successfully processed rtv iocb (currently always return 0)
5198 lpfc_els_rcv_rtv(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
5199 struct lpfc_nodelist
*ndlp
)
5201 struct lpfc_hba
*phba
= vport
->phba
;
5203 struct RTV_RSP
*rtv_rsp
;
5205 struct lpfc_iocbq
*elsiocb
;
5209 if ((ndlp
->nlp_state
!= NLP_STE_UNMAPPED_NODE
) &&
5210 (ndlp
->nlp_state
!= NLP_STE_MAPPED_NODE
))
5211 /* reject the unsolicited RPS request and done with it */
5214 cmdsize
= sizeof(struct RTV_RSP
) + sizeof(uint32_t);
5215 elsiocb
= lpfc_prep_els_iocb(phba
->pport
, 0, cmdsize
,
5216 lpfc_max_els_tries
, ndlp
,
5217 ndlp
->nlp_DID
, ELS_CMD_ACC
);
5222 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
5223 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
5224 pcmd
+= sizeof(uint32_t); /* Skip past command */
5226 /* use the command's xri in the response */
5227 elsiocb
->iocb
.ulpContext
= cmdiocb
->iocb
.ulpContext
;
5229 rtv_rsp
= (struct RTV_RSP
*)pcmd
;
5231 /* populate RTV payload */
5232 rtv_rsp
->ratov
= cpu_to_be32(phba
->fc_ratov
* 1000); /* report msecs */
5233 rtv_rsp
->edtov
= cpu_to_be32(phba
->fc_edtov
);
5234 bf_set(qtov_edtovres
, rtv_rsp
, phba
->fc_edtovResol
? 1 : 0);
5235 bf_set(qtov_rttov
, rtv_rsp
, 0); /* Field is for FC ONLY */
5236 rtv_rsp
->qtov
= cpu_to_be32(rtv_rsp
->qtov
);
5238 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
5239 lpfc_printf_vlog(ndlp
->vport
, KERN_INFO
, LOG_ELS
,
5240 "2875 Xmit ELS RTV ACC response tag x%x xri x%x, "
5241 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, "
5242 "Data: x%x x%x x%x\n",
5243 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
,
5244 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
5246 rtv_rsp
->ratov
, rtv_rsp
->edtov
, rtv_rsp
->qtov
);
5247 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
5248 phba
->fc_stat
.elsXmitACC
++;
5249 if (lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0) == IOCB_ERROR
)
5250 lpfc_els_free_iocb(phba
, elsiocb
);
5254 /* issue rejection response */
5255 stat
.un
.b
.lsRjtRsvd0
= 0;
5256 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
5257 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_CANT_GIVE_DATA
;
5258 stat
.un
.b
.vendorUnique
= 0;
5259 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
5263 /* lpfc_els_rcv_rps - Process an unsolicited rps iocb
5264 * @vport: pointer to a host virtual N_Port data structure.
5265 * @cmdiocb: pointer to lpfc command iocb data structure.
5266 * @ndlp: pointer to a node-list data structure.
5268 * This routine processes Read Port Status (RPS) IOCB received as an
5269 * ELS unsolicited event. It first checks the remote port state. If the
5270 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5271 * state, it invokes the lpfc_els_rsp_reject() routine to send the reject
5272 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
5273 * for reading the HBA link statistics. It is for the callback function,
5274 * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command
5275 * to actually sending out RPS Accept (ACC) response.
5278 * 0 - Successfully processed rps iocb (currently always return 0)
5281 lpfc_els_rcv_rps(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
5282 struct lpfc_nodelist
*ndlp
)
5284 struct lpfc_hba
*phba
= vport
->phba
;
5288 struct lpfc_dmabuf
*pcmd
;
5292 if ((ndlp
->nlp_state
!= NLP_STE_UNMAPPED_NODE
) &&
5293 (ndlp
->nlp_state
!= NLP_STE_MAPPED_NODE
))
5294 /* reject the unsolicited RPS request and done with it */
5297 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
5298 lp
= (uint32_t *) pcmd
->virt
;
5299 flag
= (be32_to_cpu(*lp
++) & 0xf);
5303 ((flag
== 1) && (be32_to_cpu(rps
->un
.portNum
) == 0)) ||
5304 ((flag
== 2) && (memcmp(&rps
->un
.portName
, &vport
->fc_portname
,
5305 sizeof(struct lpfc_name
)) == 0))) {
5307 printk("Fix me....\n");
5309 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_ATOMIC
);
5311 lpfc_read_lnk_stat(phba
, mbox
);
5313 (void *)((unsigned long) cmdiocb
->iocb
.ulpContext
);
5314 mbox
->context2
= lpfc_nlp_get(ndlp
);
5315 mbox
->vport
= vport
;
5316 mbox
->mbox_cmpl
= lpfc_els_rsp_rps_acc
;
5317 if (lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
)
5318 != MBX_NOT_FINISHED
)
5319 /* Mbox completion will send ELS Response */
5321 /* Decrement reference count used for the failed mbox
5325 mempool_free(mbox
, phba
->mbox_mem_pool
);
5330 /* issue rejection response */
5331 stat
.un
.b
.lsRjtRsvd0
= 0;
5332 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
5333 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_CANT_GIVE_DATA
;
5334 stat
.un
.b
.vendorUnique
= 0;
5335 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
5339 /* lpfc_issue_els_rrq - Process an unsolicited rps iocb
5340 * @vport: pointer to a host virtual N_Port data structure.
5341 * @ndlp: pointer to a node-list data structure.
5342 * @did: DID of the target.
5343 * @rrq: Pointer to the rrq struct.
5345 * Build a ELS RRQ command and send it to the target. If the issue_iocb is
5346 * Successful the the completion handler will clear the RRQ.
5349 * 0 - Successfully sent rrq els iocb.
5350 * 1 - Failed to send rrq els iocb.
5353 lpfc_issue_els_rrq(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
5354 uint32_t did
, struct lpfc_node_rrq
*rrq
)
5356 struct lpfc_hba
*phba
= vport
->phba
;
5357 struct RRQ
*els_rrq
;
5359 struct lpfc_iocbq
*elsiocb
;
5365 if (ndlp
!= rrq
->ndlp
)
5367 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
))
5370 /* If ndlp is not NULL, we will bump the reference count on it */
5371 cmdsize
= (sizeof(uint32_t) + sizeof(struct RRQ
));
5372 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, 0, ndlp
, did
,
5377 icmd
= &elsiocb
->iocb
;
5378 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
5380 /* For RRQ request, remainder of payload is Exchange IDs */
5381 *((uint32_t *) (pcmd
)) = ELS_CMD_RRQ
;
5382 pcmd
+= sizeof(uint32_t);
5383 els_rrq
= (struct RRQ
*) pcmd
;
5385 bf_set(rrq_oxid
, els_rrq
, rrq
->xritag
);
5386 bf_set(rrq_rxid
, els_rrq
, rrq
->rxid
);
5387 bf_set(rrq_did
, els_rrq
, vport
->fc_myDID
);
5388 els_rrq
->rrq
= cpu_to_be32(els_rrq
->rrq
);
5389 els_rrq
->rrq_exchg
= cpu_to_be32(els_rrq
->rrq_exchg
);
5392 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
5393 "Issue RRQ: did:x%x",
5394 did
, rrq
->xritag
, rrq
->rxid
);
5395 elsiocb
->context_un
.rrq
= rrq
;
5396 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rrq
;
5397 ret
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
5399 if (ret
== IOCB_ERROR
) {
5400 lpfc_els_free_iocb(phba
, elsiocb
);
5407 * lpfc_send_rrq - Sends ELS RRQ if needed.
5408 * @phba: pointer to lpfc hba data structure.
5409 * @rrq: pointer to the active rrq.
5411 * This routine will call the lpfc_issue_els_rrq if the rrq is
5412 * still active for the xri. If this function returns a failure then
5413 * the caller needs to clean up the RRQ by calling lpfc_clr_active_rrq.
5415 * Returns 0 Success.
5419 lpfc_send_rrq(struct lpfc_hba
*phba
, struct lpfc_node_rrq
*rrq
)
5421 struct lpfc_nodelist
*ndlp
= lpfc_findnode_did(rrq
->vport
,
5423 if (lpfc_test_rrq_active(phba
, ndlp
, rrq
->xritag
))
5424 return lpfc_issue_els_rrq(rrq
->vport
, ndlp
,
5431 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
5432 * @vport: pointer to a host virtual N_Port data structure.
5433 * @cmdsize: size of the ELS command.
5434 * @oldiocb: pointer to the original lpfc command iocb data structure.
5435 * @ndlp: pointer to a node-list data structure.
5437 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
5438 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
5440 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5441 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5442 * will be stored into the context1 field of the IOCB for the completion
5443 * callback function to the RPL Accept Response ELS command.
5446 * 0 - Successfully issued ACC RPL ELS command
5447 * 1 - Failed to issue ACC RPL ELS command
5450 lpfc_els_rsp_rpl_acc(struct lpfc_vport
*vport
, uint16_t cmdsize
,
5451 struct lpfc_iocbq
*oldiocb
, struct lpfc_nodelist
*ndlp
)
5453 struct lpfc_hba
*phba
= vport
->phba
;
5454 IOCB_t
*icmd
, *oldcmd
;
5456 struct lpfc_iocbq
*elsiocb
;
5459 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
, ndlp
,
5460 ndlp
->nlp_DID
, ELS_CMD_ACC
);
5465 icmd
= &elsiocb
->iocb
;
5466 oldcmd
= &oldiocb
->iocb
;
5467 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri */
5469 pcmd
= (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
5470 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
5471 pcmd
+= sizeof(uint16_t);
5472 *((uint16_t *)(pcmd
)) = be16_to_cpu(cmdsize
);
5473 pcmd
+= sizeof(uint16_t);
5475 /* Setup the RPL ACC payload */
5476 rpl_rsp
.listLen
= be32_to_cpu(1);
5478 rpl_rsp
.port_num_blk
.portNum
= 0;
5479 rpl_rsp
.port_num_blk
.portID
= be32_to_cpu(vport
->fc_myDID
);
5480 memcpy(&rpl_rsp
.port_num_blk
.portName
, &vport
->fc_portname
,
5481 sizeof(struct lpfc_name
));
5482 memcpy(pcmd
, &rpl_rsp
, cmdsize
- sizeof(uint32_t));
5483 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
5484 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
5485 "0120 Xmit ELS RPL ACC response tag x%x "
5486 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
5488 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
,
5489 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
5491 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
5492 phba
->fc_stat
.elsXmitACC
++;
5493 if (lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0) ==
5495 lpfc_els_free_iocb(phba
, elsiocb
);
5502 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
5503 * @vport: pointer to a host virtual N_Port data structure.
5504 * @cmdiocb: pointer to lpfc command iocb data structure.
5505 * @ndlp: pointer to a node-list data structure.
5507 * This routine processes Read Port List (RPL) IOCB received as an ELS
5508 * unsolicited event. It first checks the remote port state. If the remote
5509 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
5510 * invokes the lpfc_els_rsp_reject() routine to send reject response.
5511 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
5512 * to accept the RPL.
5515 * 0 - Successfully processed rpl iocb (currently always return 0)
5518 lpfc_els_rcv_rpl(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
5519 struct lpfc_nodelist
*ndlp
)
5521 struct lpfc_dmabuf
*pcmd
;
5528 if ((ndlp
->nlp_state
!= NLP_STE_UNMAPPED_NODE
) &&
5529 (ndlp
->nlp_state
!= NLP_STE_MAPPED_NODE
)) {
5530 /* issue rejection response */
5531 stat
.un
.b
.lsRjtRsvd0
= 0;
5532 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
5533 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_CANT_GIVE_DATA
;
5534 stat
.un
.b
.vendorUnique
= 0;
5535 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
,
5537 /* rejected the unsolicited RPL request and done with it */
5541 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
5542 lp
= (uint32_t *) pcmd
->virt
;
5543 rpl
= (RPL
*) (lp
+ 1);
5544 maxsize
= be32_to_cpu(rpl
->maxsize
);
5546 /* We support only one port */
5547 if ((rpl
->index
== 0) &&
5549 ((maxsize
* sizeof(uint32_t)) >= sizeof(RPL_RSP
)))) {
5550 cmdsize
= sizeof(uint32_t) + sizeof(RPL_RSP
);
5552 cmdsize
= sizeof(uint32_t) + maxsize
* sizeof(uint32_t);
5554 lpfc_els_rsp_rpl_acc(vport
, cmdsize
, cmdiocb
, ndlp
);
5560 * lpfc_els_rcv_farp - Process an unsolicited farp request els command
5561 * @vport: pointer to a virtual N_Port data structure.
5562 * @cmdiocb: pointer to lpfc command iocb data structure.
5563 * @ndlp: pointer to a node-list data structure.
5565 * This routine processes Fibre Channel Address Resolution Protocol
5566 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
5567 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
5568 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
5569 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
5570 * remote PortName is compared against the FC PortName stored in the @vport
5571 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
5572 * compared against the FC NodeName stored in the @vport data structure.
5573 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
5574 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
5575 * invoked to send out FARP Response to the remote node. Before sending the
5576 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
5577 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
5578 * routine is invoked to log into the remote port first.
5581 * 0 - Either the FARP Match Mode not supported or successfully processed
5584 lpfc_els_rcv_farp(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
5585 struct lpfc_nodelist
*ndlp
)
5587 struct lpfc_dmabuf
*pcmd
;
5591 uint32_t cmd
, cnt
, did
;
5593 icmd
= &cmdiocb
->iocb
;
5594 did
= icmd
->un
.elsreq64
.remoteID
;
5595 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
5596 lp
= (uint32_t *) pcmd
->virt
;
5600 /* FARP-REQ received from DID <did> */
5601 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
5602 "0601 FARP-REQ received from DID x%x\n", did
);
5603 /* We will only support match on WWPN or WWNN */
5604 if (fp
->Mflags
& ~(FARP_MATCH_NODE
| FARP_MATCH_PORT
)) {
5609 /* If this FARP command is searching for my portname */
5610 if (fp
->Mflags
& FARP_MATCH_PORT
) {
5611 if (memcmp(&fp
->RportName
, &vport
->fc_portname
,
5612 sizeof(struct lpfc_name
)) == 0)
5616 /* If this FARP command is searching for my nodename */
5617 if (fp
->Mflags
& FARP_MATCH_NODE
) {
5618 if (memcmp(&fp
->RnodeName
, &vport
->fc_nodename
,
5619 sizeof(struct lpfc_name
)) == 0)
5624 if ((ndlp
->nlp_state
== NLP_STE_UNMAPPED_NODE
) ||
5625 (ndlp
->nlp_state
== NLP_STE_MAPPED_NODE
)) {
5626 /* Log back into the node before sending the FARP. */
5627 if (fp
->Rflags
& FARP_REQUEST_PLOGI
) {
5628 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
5629 lpfc_nlp_set_state(vport
, ndlp
,
5630 NLP_STE_PLOGI_ISSUE
);
5631 lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, 0);
5634 /* Send a FARP response to that node */
5635 if (fp
->Rflags
& FARP_REQUEST_FARPR
)
5636 lpfc_issue_els_farpr(vport
, did
, 0);
5643 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
5644 * @vport: pointer to a host virtual N_Port data structure.
5645 * @cmdiocb: pointer to lpfc command iocb data structure.
5646 * @ndlp: pointer to a node-list data structure.
5648 * This routine processes Fibre Channel Address Resolution Protocol
5649 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
5650 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
5651 * the FARP response request.
5654 * 0 - Successfully processed FARPR IOCB (currently always return 0)
5657 lpfc_els_rcv_farpr(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
5658 struct lpfc_nodelist
*ndlp
)
5660 struct lpfc_dmabuf
*pcmd
;
5665 icmd
= &cmdiocb
->iocb
;
5666 did
= icmd
->un
.elsreq64
.remoteID
;
5667 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
5668 lp
= (uint32_t *) pcmd
->virt
;
5671 /* FARP-RSP received from DID <did> */
5672 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
5673 "0600 FARP-RSP received from DID x%x\n", did
);
5674 /* ACCEPT the Farp resp request */
5675 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
5681 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
5682 * @vport: pointer to a host virtual N_Port data structure.
5683 * @cmdiocb: pointer to lpfc command iocb data structure.
5684 * @fan_ndlp: pointer to a node-list data structure.
5686 * This routine processes a Fabric Address Notification (FAN) IOCB
5687 * command received as an ELS unsolicited event. The FAN ELS command will
5688 * only be processed on a physical port (i.e., the @vport represents the
5689 * physical port). The fabric NodeName and PortName from the FAN IOCB are
5690 * compared against those in the phba data structure. If any of those is
5691 * different, the lpfc_initial_flogi() routine is invoked to initialize
5692 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
5693 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
5694 * is invoked to register login to the fabric.
5697 * 0 - Successfully processed fan iocb (currently always return 0).
5700 lpfc_els_rcv_fan(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
5701 struct lpfc_nodelist
*fan_ndlp
)
5703 struct lpfc_hba
*phba
= vport
->phba
;
5707 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
, "0265 FAN received\n");
5708 lp
= (uint32_t *)((struct lpfc_dmabuf
*)cmdiocb
->context2
)->virt
;
5710 /* FAN received; Fan does not have a reply sequence */
5711 if ((vport
== phba
->pport
) &&
5712 (vport
->port_state
== LPFC_LOCAL_CFG_LINK
)) {
5713 if ((memcmp(&phba
->fc_fabparam
.nodeName
, &fp
->FnodeName
,
5714 sizeof(struct lpfc_name
))) ||
5715 (memcmp(&phba
->fc_fabparam
.portName
, &fp
->FportName
,
5716 sizeof(struct lpfc_name
)))) {
5717 /* This port has switched fabrics. FLOGI is required */
5718 lpfc_issue_init_vfi(vport
);
5720 /* FAN verified - skip FLOGI */
5721 vport
->fc_myDID
= vport
->fc_prevDID
;
5722 if (phba
->sli_rev
< LPFC_SLI_REV4
)
5723 lpfc_issue_fabric_reglogin(vport
);
5725 lpfc_issue_reg_vfi(vport
);
5732 * lpfc_els_timeout - Handler funciton to the els timer
5733 * @ptr: holder for the timer function associated data.
5735 * This routine is invoked by the ELS timer after timeout. It posts the ELS
5736 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
5737 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
5738 * up the worker thread. It is for the worker thread to invoke the routine
5739 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
5742 lpfc_els_timeout(unsigned long ptr
)
5744 struct lpfc_vport
*vport
= (struct lpfc_vport
*) ptr
;
5745 struct lpfc_hba
*phba
= vport
->phba
;
5746 uint32_t tmo_posted
;
5747 unsigned long iflag
;
5749 spin_lock_irqsave(&vport
->work_port_lock
, iflag
);
5750 tmo_posted
= vport
->work_port_events
& WORKER_ELS_TMO
;
5752 vport
->work_port_events
|= WORKER_ELS_TMO
;
5753 spin_unlock_irqrestore(&vport
->work_port_lock
, iflag
);
5756 lpfc_worker_wake_up(phba
);
5762 * lpfc_els_timeout_handler - Process an els timeout event
5763 * @vport: pointer to a virtual N_Port data structure.
5765 * This routine is the actual handler function that processes an ELS timeout
5766 * event. It walks the ELS ring to get and abort all the IOCBs (except the
5767 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
5768 * invoking the lpfc_sli_issue_abort_iotag() routine.
5771 lpfc_els_timeout_handler(struct lpfc_vport
*vport
)
5773 struct lpfc_hba
*phba
= vport
->phba
;
5774 struct lpfc_sli_ring
*pring
;
5775 struct lpfc_iocbq
*tmp_iocb
, *piocb
;
5777 struct lpfc_dmabuf
*pcmd
;
5778 uint32_t els_command
= 0;
5780 uint32_t remote_ID
= 0xffffffff;
5781 LIST_HEAD(txcmplq_completions
);
5782 LIST_HEAD(abort_list
);
5785 timeout
= (uint32_t)(phba
->fc_ratov
<< 1);
5787 pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
5789 spin_lock_irq(&phba
->hbalock
);
5790 list_splice_init(&pring
->txcmplq
, &txcmplq_completions
);
5791 spin_unlock_irq(&phba
->hbalock
);
5793 list_for_each_entry_safe(piocb
, tmp_iocb
, &txcmplq_completions
, list
) {
5796 if ((piocb
->iocb_flag
& LPFC_IO_LIBDFC
) != 0 ||
5797 piocb
->iocb
.ulpCommand
== CMD_ABORT_XRI_CN
||
5798 piocb
->iocb
.ulpCommand
== CMD_CLOSE_XRI_CN
)
5801 if (piocb
->vport
!= vport
)
5804 pcmd
= (struct lpfc_dmabuf
*) piocb
->context2
;
5806 els_command
= *(uint32_t *) (pcmd
->virt
);
5808 if (els_command
== ELS_CMD_FARP
||
5809 els_command
== ELS_CMD_FARPR
||
5810 els_command
== ELS_CMD_FDISC
)
5813 if (piocb
->drvrTimeout
> 0) {
5814 if (piocb
->drvrTimeout
>= timeout
)
5815 piocb
->drvrTimeout
-= timeout
;
5817 piocb
->drvrTimeout
= 0;
5821 remote_ID
= 0xffffffff;
5822 if (cmd
->ulpCommand
!= CMD_GEN_REQUEST64_CR
)
5823 remote_ID
= cmd
->un
.elsreq64
.remoteID
;
5825 struct lpfc_nodelist
*ndlp
;
5826 ndlp
= __lpfc_findnode_rpi(vport
, cmd
->ulpContext
);
5827 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
))
5828 remote_ID
= ndlp
->nlp_DID
;
5830 list_add_tail(&piocb
->dlist
, &abort_list
);
5832 spin_lock_irq(&phba
->hbalock
);
5833 list_splice(&txcmplq_completions
, &pring
->txcmplq
);
5834 spin_unlock_irq(&phba
->hbalock
);
5836 list_for_each_entry_safe(piocb
, tmp_iocb
, &abort_list
, dlist
) {
5837 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
5838 "0127 ELS timeout Data: x%x x%x x%x "
5839 "x%x\n", els_command
,
5840 remote_ID
, cmd
->ulpCommand
, cmd
->ulpIoTag
);
5841 spin_lock_irq(&phba
->hbalock
);
5842 list_del_init(&piocb
->dlist
);
5843 lpfc_sli_issue_abort_iotag(phba
, pring
, piocb
);
5844 spin_unlock_irq(&phba
->hbalock
);
5847 if (phba
->sli
.ring
[LPFC_ELS_RING
].txcmplq_cnt
)
5848 mod_timer(&vport
->els_tmofunc
, jiffies
+ HZ
* timeout
);
5852 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
5853 * @vport: pointer to a host virtual N_Port data structure.
5855 * This routine is used to clean up all the outstanding ELS commands on a
5856 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
5857 * routine. After that, it walks the ELS transmit queue to remove all the
5858 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
5859 * the IOCBs with a non-NULL completion callback function, the callback
5860 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
5861 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
5862 * callback function, the IOCB will simply be released. Finally, it walks
5863 * the ELS transmit completion queue to issue an abort IOCB to any transmit
5864 * completion queue IOCB that is associated with the @vport and is not
5865 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
5866 * part of the discovery state machine) out to HBA by invoking the
5867 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
5868 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
5869 * the IOCBs are aborted when this function returns.
5872 lpfc_els_flush_cmd(struct lpfc_vport
*vport
)
5874 LIST_HEAD(completions
);
5875 struct lpfc_hba
*phba
= vport
->phba
;
5876 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
5877 struct lpfc_iocbq
*tmp_iocb
, *piocb
;
5880 lpfc_fabric_abort_vport(vport
);
5882 spin_lock_irq(&phba
->hbalock
);
5883 list_for_each_entry_safe(piocb
, tmp_iocb
, &pring
->txq
, list
) {
5886 if (piocb
->iocb_flag
& LPFC_IO_LIBDFC
) {
5890 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
5891 if (cmd
->ulpCommand
== CMD_QUE_RING_BUF_CN
||
5892 cmd
->ulpCommand
== CMD_QUE_RING_BUF64_CN
||
5893 cmd
->ulpCommand
== CMD_CLOSE_XRI_CN
||
5894 cmd
->ulpCommand
== CMD_ABORT_XRI_CN
)
5897 if (piocb
->vport
!= vport
)
5900 list_move_tail(&piocb
->list
, &completions
);
5904 list_for_each_entry_safe(piocb
, tmp_iocb
, &pring
->txcmplq
, list
) {
5905 if (piocb
->iocb_flag
& LPFC_IO_LIBDFC
) {
5909 if (piocb
->vport
!= vport
)
5912 lpfc_sli_issue_abort_iotag(phba
, pring
, piocb
);
5914 spin_unlock_irq(&phba
->hbalock
);
5916 /* Cancell all the IOCBs from the completions list */
5917 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
5924 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
5925 * @phba: pointer to lpfc hba data structure.
5927 * This routine is used to clean up all the outstanding ELS commands on a
5928 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
5929 * routine. After that, it walks the ELS transmit queue to remove all the
5930 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
5931 * the IOCBs with the completion callback function associated, the callback
5932 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
5933 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
5934 * callback function associated, the IOCB will simply be released. Finally,
5935 * it walks the ELS transmit completion queue to issue an abort IOCB to any
5936 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
5937 * management plane IOCBs that are not part of the discovery state machine)
5938 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
5941 lpfc_els_flush_all_cmd(struct lpfc_hba
*phba
)
5943 LIST_HEAD(completions
);
5944 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
5945 struct lpfc_iocbq
*tmp_iocb
, *piocb
;
5948 lpfc_fabric_abort_hba(phba
);
5949 spin_lock_irq(&phba
->hbalock
);
5950 list_for_each_entry_safe(piocb
, tmp_iocb
, &pring
->txq
, list
) {
5952 if (piocb
->iocb_flag
& LPFC_IO_LIBDFC
)
5954 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
5955 if (cmd
->ulpCommand
== CMD_QUE_RING_BUF_CN
||
5956 cmd
->ulpCommand
== CMD_QUE_RING_BUF64_CN
||
5957 cmd
->ulpCommand
== CMD_CLOSE_XRI_CN
||
5958 cmd
->ulpCommand
== CMD_ABORT_XRI_CN
)
5960 list_move_tail(&piocb
->list
, &completions
);
5963 list_for_each_entry_safe(piocb
, tmp_iocb
, &pring
->txcmplq
, list
) {
5964 if (piocb
->iocb_flag
& LPFC_IO_LIBDFC
)
5966 lpfc_sli_issue_abort_iotag(phba
, pring
, piocb
);
5968 spin_unlock_irq(&phba
->hbalock
);
5970 /* Cancel all the IOCBs from the completions list */
5971 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
5978 * lpfc_send_els_failure_event - Posts an ELS command failure event
5979 * @phba: Pointer to hba context object.
5980 * @cmdiocbp: Pointer to command iocb which reported error.
5981 * @rspiocbp: Pointer to response iocb which reported error.
5983 * This function sends an event when there is an ELS command
5987 lpfc_send_els_failure_event(struct lpfc_hba
*phba
,
5988 struct lpfc_iocbq
*cmdiocbp
,
5989 struct lpfc_iocbq
*rspiocbp
)
5991 struct lpfc_vport
*vport
= cmdiocbp
->vport
;
5992 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
5993 struct lpfc_lsrjt_event lsrjt_event
;
5994 struct lpfc_fabric_event_header fabric_event
;
5996 struct lpfc_nodelist
*ndlp
;
5999 ndlp
= cmdiocbp
->context1
;
6000 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
))
6003 if (rspiocbp
->iocb
.ulpStatus
== IOSTAT_LS_RJT
) {
6004 lsrjt_event
.header
.event_type
= FC_REG_ELS_EVENT
;
6005 lsrjt_event
.header
.subcategory
= LPFC_EVENT_LSRJT_RCV
;
6006 memcpy(lsrjt_event
.header
.wwpn
, &ndlp
->nlp_portname
,
6007 sizeof(struct lpfc_name
));
6008 memcpy(lsrjt_event
.header
.wwnn
, &ndlp
->nlp_nodename
,
6009 sizeof(struct lpfc_name
));
6010 pcmd
= (uint32_t *) (((struct lpfc_dmabuf
*)
6011 cmdiocbp
->context2
)->virt
);
6012 lsrjt_event
.command
= (pcmd
!= NULL
) ? *pcmd
: 0;
6013 stat
.un
.lsRjtError
= be32_to_cpu(rspiocbp
->iocb
.un
.ulpWord
[4]);
6014 lsrjt_event
.reason_code
= stat
.un
.b
.lsRjtRsnCode
;
6015 lsrjt_event
.explanation
= stat
.un
.b
.lsRjtRsnCodeExp
;
6016 fc_host_post_vendor_event(shost
,
6017 fc_get_event_number(),
6018 sizeof(lsrjt_event
),
6019 (char *)&lsrjt_event
,
6023 if ((rspiocbp
->iocb
.ulpStatus
== IOSTAT_NPORT_BSY
) ||
6024 (rspiocbp
->iocb
.ulpStatus
== IOSTAT_FABRIC_BSY
)) {
6025 fabric_event
.event_type
= FC_REG_FABRIC_EVENT
;
6026 if (rspiocbp
->iocb
.ulpStatus
== IOSTAT_NPORT_BSY
)
6027 fabric_event
.subcategory
= LPFC_EVENT_PORT_BUSY
;
6029 fabric_event
.subcategory
= LPFC_EVENT_FABRIC_BUSY
;
6030 memcpy(fabric_event
.wwpn
, &ndlp
->nlp_portname
,
6031 sizeof(struct lpfc_name
));
6032 memcpy(fabric_event
.wwnn
, &ndlp
->nlp_nodename
,
6033 sizeof(struct lpfc_name
));
6034 fc_host_post_vendor_event(shost
,
6035 fc_get_event_number(),
6036 sizeof(fabric_event
),
6037 (char *)&fabric_event
,
6045 * lpfc_send_els_event - Posts unsolicited els event
6046 * @vport: Pointer to vport object.
6047 * @ndlp: Pointer FC node object.
6048 * @cmd: ELS command code.
6050 * This function posts an event when there is an incoming
6051 * unsolicited ELS command.
6054 lpfc_send_els_event(struct lpfc_vport
*vport
,
6055 struct lpfc_nodelist
*ndlp
,
6058 struct lpfc_els_event_header
*els_data
= NULL
;
6059 struct lpfc_logo_event
*logo_data
= NULL
;
6060 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
6062 if (*payload
== ELS_CMD_LOGO
) {
6063 logo_data
= kmalloc(sizeof(struct lpfc_logo_event
), GFP_KERNEL
);
6065 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
6066 "0148 Failed to allocate memory "
6067 "for LOGO event\n");
6070 els_data
= &logo_data
->header
;
6072 els_data
= kmalloc(sizeof(struct lpfc_els_event_header
),
6075 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
6076 "0149 Failed to allocate memory "
6081 els_data
->event_type
= FC_REG_ELS_EVENT
;
6084 els_data
->subcategory
= LPFC_EVENT_PLOGI_RCV
;
6087 els_data
->subcategory
= LPFC_EVENT_PRLO_RCV
;
6090 els_data
->subcategory
= LPFC_EVENT_ADISC_RCV
;
6093 els_data
->subcategory
= LPFC_EVENT_LOGO_RCV
;
6094 /* Copy the WWPN in the LOGO payload */
6095 memcpy(logo_data
->logo_wwpn
, &payload
[2],
6096 sizeof(struct lpfc_name
));
6102 memcpy(els_data
->wwpn
, &ndlp
->nlp_portname
, sizeof(struct lpfc_name
));
6103 memcpy(els_data
->wwnn
, &ndlp
->nlp_nodename
, sizeof(struct lpfc_name
));
6104 if (*payload
== ELS_CMD_LOGO
) {
6105 fc_host_post_vendor_event(shost
,
6106 fc_get_event_number(),
6107 sizeof(struct lpfc_logo_event
),
6112 fc_host_post_vendor_event(shost
,
6113 fc_get_event_number(),
6114 sizeof(struct lpfc_els_event_header
),
6125 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
6126 * @phba: pointer to lpfc hba data structure.
6127 * @pring: pointer to a SLI ring.
6128 * @vport: pointer to a host virtual N_Port data structure.
6129 * @elsiocb: pointer to lpfc els command iocb data structure.
6131 * This routine is used for processing the IOCB associated with a unsolicited
6132 * event. It first determines whether there is an existing ndlp that matches
6133 * the DID from the unsolicited IOCB. If not, it will create a new one with
6134 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
6135 * IOCB is then used to invoke the proper routine and to set up proper state
6136 * of the discovery state machine.
6139 lpfc_els_unsol_buffer(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
6140 struct lpfc_vport
*vport
, struct lpfc_iocbq
*elsiocb
)
6142 struct Scsi_Host
*shost
;
6143 struct lpfc_nodelist
*ndlp
;
6146 uint32_t cmd
, did
, newnode
, rjt_err
= 0;
6147 IOCB_t
*icmd
= &elsiocb
->iocb
;
6149 if (!vport
|| !(elsiocb
->context2
))
6153 payload
= ((struct lpfc_dmabuf
*)elsiocb
->context2
)->virt
;
6155 if ((phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) == 0)
6156 lpfc_post_buffer(phba
, pring
, 1);
6158 did
= icmd
->un
.rcvels
.remoteID
;
6159 if (icmd
->ulpStatus
) {
6160 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
6161 "RCV Unsol ELS: status:x%x/x%x did:x%x",
6162 icmd
->ulpStatus
, icmd
->un
.ulpWord
[4], did
);
6166 /* Check to see if link went down during discovery */
6167 if (lpfc_els_chk_latt(vport
))
6170 /* Ignore traffic received during vport shutdown. */
6171 if (vport
->load_flag
& FC_UNLOADING
)
6174 ndlp
= lpfc_findnode_did(vport
, did
);
6176 /* Cannot find existing Fabric ndlp, so allocate a new one */
6177 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
6181 lpfc_nlp_init(vport
, ndlp
, did
);
6182 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
6184 if ((did
& Fabric_DID_MASK
) == Fabric_DID_MASK
)
6185 ndlp
->nlp_type
|= NLP_FABRIC
;
6186 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
6187 ndlp
= lpfc_enable_node(vport
, ndlp
,
6188 NLP_STE_UNUSED_NODE
);
6191 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
6193 if ((did
& Fabric_DID_MASK
) == Fabric_DID_MASK
)
6194 ndlp
->nlp_type
|= NLP_FABRIC
;
6195 } else if (ndlp
->nlp_state
== NLP_STE_UNUSED_NODE
) {
6196 /* This is similar to the new node path */
6197 ndlp
= lpfc_nlp_get(ndlp
);
6200 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
6204 phba
->fc_stat
.elsRcvFrame
++;
6206 elsiocb
->context1
= lpfc_nlp_get(ndlp
);
6207 elsiocb
->vport
= vport
;
6209 if ((cmd
& ELS_CMD_MASK
) == ELS_CMD_RSCN
) {
6210 cmd
&= ELS_CMD_MASK
;
6212 /* ELS command <elsCmd> received from NPORT <did> */
6213 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
6214 "0112 ELS command x%x received from NPORT x%x "
6215 "Data: x%x\n", cmd
, did
, vport
->port_state
);
6218 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
6219 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
6220 did
, vport
->port_state
, ndlp
->nlp_flag
);
6222 phba
->fc_stat
.elsRcvPLOGI
++;
6223 ndlp
= lpfc_plogi_confirm_nport(phba
, payload
, ndlp
);
6225 lpfc_send_els_event(vport
, ndlp
, payload
);
6226 if (vport
->port_state
< LPFC_DISC_AUTH
) {
6227 if (!(phba
->pport
->fc_flag
& FC_PT2PT
) ||
6228 (phba
->pport
->fc_flag
& FC_PT2PT_PLOGI
)) {
6229 rjt_err
= LSRJT_UNABLE_TPC
;
6232 /* We get here, and drop thru, if we are PT2PT with
6233 * another NPort and the other side has initiated
6234 * the PLOGI before responding to our FLOGI.
6238 shost
= lpfc_shost_from_vport(vport
);
6239 spin_lock_irq(shost
->host_lock
);
6240 ndlp
->nlp_flag
&= ~NLP_TARGET_REMOVE
;
6241 spin_unlock_irq(shost
->host_lock
);
6243 lpfc_disc_state_machine(vport
, ndlp
, elsiocb
,
6248 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
6249 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
6250 did
, vport
->port_state
, ndlp
->nlp_flag
);
6252 phba
->fc_stat
.elsRcvFLOGI
++;
6253 lpfc_els_rcv_flogi(vport
, elsiocb
, ndlp
);
6258 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
6259 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
6260 did
, vport
->port_state
, ndlp
->nlp_flag
);
6262 phba
->fc_stat
.elsRcvLOGO
++;
6263 lpfc_send_els_event(vport
, ndlp
, payload
);
6264 if (vport
->port_state
< LPFC_DISC_AUTH
) {
6265 rjt_err
= LSRJT_UNABLE_TPC
;
6268 lpfc_disc_state_machine(vport
, ndlp
, elsiocb
, NLP_EVT_RCV_LOGO
);
6271 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
6272 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
6273 did
, vport
->port_state
, ndlp
->nlp_flag
);
6275 phba
->fc_stat
.elsRcvPRLO
++;
6276 lpfc_send_els_event(vport
, ndlp
, payload
);
6277 if (vport
->port_state
< LPFC_DISC_AUTH
) {
6278 rjt_err
= LSRJT_UNABLE_TPC
;
6281 lpfc_disc_state_machine(vport
, ndlp
, elsiocb
, NLP_EVT_RCV_PRLO
);
6284 phba
->fc_stat
.elsRcvRSCN
++;
6285 lpfc_els_rcv_rscn(vport
, elsiocb
, ndlp
);
6290 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
6291 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
6292 did
, vport
->port_state
, ndlp
->nlp_flag
);
6294 lpfc_send_els_event(vport
, ndlp
, payload
);
6295 phba
->fc_stat
.elsRcvADISC
++;
6296 if (vport
->port_state
< LPFC_DISC_AUTH
) {
6297 rjt_err
= LSRJT_UNABLE_TPC
;
6300 lpfc_disc_state_machine(vport
, ndlp
, elsiocb
,
6304 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
6305 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
6306 did
, vport
->port_state
, ndlp
->nlp_flag
);
6308 phba
->fc_stat
.elsRcvPDISC
++;
6309 if (vport
->port_state
< LPFC_DISC_AUTH
) {
6310 rjt_err
= LSRJT_UNABLE_TPC
;
6313 lpfc_disc_state_machine(vport
, ndlp
, elsiocb
,
6317 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
6318 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
6319 did
, vport
->port_state
, ndlp
->nlp_flag
);
6321 phba
->fc_stat
.elsRcvFARPR
++;
6322 lpfc_els_rcv_farpr(vport
, elsiocb
, ndlp
);
6325 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
6326 "RCV FARP: did:x%x/ste:x%x flg:x%x",
6327 did
, vport
->port_state
, ndlp
->nlp_flag
);
6329 phba
->fc_stat
.elsRcvFARP
++;
6330 lpfc_els_rcv_farp(vport
, elsiocb
, ndlp
);
6333 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
6334 "RCV FAN: did:x%x/ste:x%x flg:x%x",
6335 did
, vport
->port_state
, ndlp
->nlp_flag
);
6337 phba
->fc_stat
.elsRcvFAN
++;
6338 lpfc_els_rcv_fan(vport
, elsiocb
, ndlp
);
6341 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
6342 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
6343 did
, vport
->port_state
, ndlp
->nlp_flag
);
6345 phba
->fc_stat
.elsRcvPRLI
++;
6346 if (vport
->port_state
< LPFC_DISC_AUTH
) {
6347 rjt_err
= LSRJT_UNABLE_TPC
;
6350 lpfc_disc_state_machine(vport
, ndlp
, elsiocb
, NLP_EVT_RCV_PRLI
);
6353 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
6354 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
6355 did
, vport
->port_state
, ndlp
->nlp_flag
);
6357 phba
->fc_stat
.elsRcvLIRR
++;
6358 lpfc_els_rcv_lirr(vport
, elsiocb
, ndlp
);
6363 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
6364 "RCV RLS: did:x%x/ste:x%x flg:x%x",
6365 did
, vport
->port_state
, ndlp
->nlp_flag
);
6367 phba
->fc_stat
.elsRcvRLS
++;
6368 lpfc_els_rcv_rls(vport
, elsiocb
, ndlp
);
6373 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
6374 "RCV RPS: did:x%x/ste:x%x flg:x%x",
6375 did
, vport
->port_state
, ndlp
->nlp_flag
);
6377 phba
->fc_stat
.elsRcvRPS
++;
6378 lpfc_els_rcv_rps(vport
, elsiocb
, ndlp
);
6383 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
6384 "RCV RPL: did:x%x/ste:x%x flg:x%x",
6385 did
, vport
->port_state
, ndlp
->nlp_flag
);
6387 phba
->fc_stat
.elsRcvRPL
++;
6388 lpfc_els_rcv_rpl(vport
, elsiocb
, ndlp
);
6393 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
6394 "RCV RNID: did:x%x/ste:x%x flg:x%x",
6395 did
, vport
->port_state
, ndlp
->nlp_flag
);
6397 phba
->fc_stat
.elsRcvRNID
++;
6398 lpfc_els_rcv_rnid(vport
, elsiocb
, ndlp
);
6403 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
6404 "RCV RTV: did:x%x/ste:x%x flg:x%x",
6405 did
, vport
->port_state
, ndlp
->nlp_flag
);
6406 phba
->fc_stat
.elsRcvRTV
++;
6407 lpfc_els_rcv_rtv(vport
, elsiocb
, ndlp
);
6412 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
6413 "RCV RRQ: did:x%x/ste:x%x flg:x%x",
6414 did
, vport
->port_state
, ndlp
->nlp_flag
);
6416 phba
->fc_stat
.elsRcvRRQ
++;
6417 lpfc_els_rcv_rrq(vport
, elsiocb
, ndlp
);
6422 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
6423 "RCV ECHO: did:x%x/ste:x%x flg:x%x",
6424 did
, vport
->port_state
, ndlp
->nlp_flag
);
6426 phba
->fc_stat
.elsRcvECHO
++;
6427 lpfc_els_rcv_echo(vport
, elsiocb
, ndlp
);
6432 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
6433 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
6434 cmd
, did
, vport
->port_state
);
6436 /* Unsupported ELS command, reject */
6437 rjt_err
= LSRJT_CMD_UNSUPPORTED
;
6439 /* Unknown ELS command <elsCmd> received from NPORT <did> */
6440 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
6441 "0115 Unknown ELS command x%x "
6442 "received from NPORT x%x\n", cmd
, did
);
6448 /* check if need to LS_RJT received ELS cmd */
6450 memset(&stat
, 0, sizeof(stat
));
6451 stat
.un
.b
.lsRjtRsnCode
= rjt_err
;
6452 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_NOTHING_MORE
;
6453 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, elsiocb
, ndlp
,
6457 lpfc_nlp_put(elsiocb
->context1
);
6458 elsiocb
->context1
= NULL
;
6462 if (vport
&& !(vport
->load_flag
& FC_UNLOADING
))
6463 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
6464 "0111 Dropping received ELS cmd "
6465 "Data: x%x x%x x%x\n",
6466 icmd
->ulpStatus
, icmd
->un
.ulpWord
[4], icmd
->ulpTimeout
);
6467 phba
->fc_stat
.elsRcvDrop
++;
6471 * lpfc_find_vport_by_vpid - Find a vport on a HBA through vport identifier
6472 * @phba: pointer to lpfc hba data structure.
6473 * @vpi: host virtual N_Port identifier.
6475 * This routine finds a vport on a HBA (referred by @phba) through a
6476 * @vpi. The function walks the HBA's vport list and returns the address
6477 * of the vport with the matching @vpi.
6480 * NULL - No vport with the matching @vpi found
6481 * Otherwise - Address to the vport with the matching @vpi.
6484 lpfc_find_vport_by_vpid(struct lpfc_hba
*phba
, uint16_t vpi
)
6486 struct lpfc_vport
*vport
;
6487 unsigned long flags
;
6489 spin_lock_irqsave(&phba
->hbalock
, flags
);
6490 list_for_each_entry(vport
, &phba
->port_list
, listentry
) {
6491 if (vport
->vpi
== vpi
) {
6492 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
6496 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
6501 * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
6502 * @phba: pointer to lpfc hba data structure.
6503 * @pring: pointer to a SLI ring.
6504 * @elsiocb: pointer to lpfc els iocb data structure.
6506 * This routine is used to process an unsolicited event received from a SLI
6507 * (Service Level Interface) ring. The actual processing of the data buffer
6508 * associated with the unsolicited event is done by invoking the routine
6509 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
6510 * SLI ring on which the unsolicited event was received.
6513 lpfc_els_unsol_event(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
6514 struct lpfc_iocbq
*elsiocb
)
6516 struct lpfc_vport
*vport
= phba
->pport
;
6517 IOCB_t
*icmd
= &elsiocb
->iocb
;
6519 struct lpfc_dmabuf
*bdeBuf1
= elsiocb
->context2
;
6520 struct lpfc_dmabuf
*bdeBuf2
= elsiocb
->context3
;
6522 elsiocb
->context1
= NULL
;
6523 elsiocb
->context2
= NULL
;
6524 elsiocb
->context3
= NULL
;
6526 if (icmd
->ulpStatus
== IOSTAT_NEED_BUFFER
) {
6527 lpfc_sli_hbqbuf_add_hbqs(phba
, LPFC_ELS_HBQ
);
6528 } else if (icmd
->ulpStatus
== IOSTAT_LOCAL_REJECT
&&
6529 (icmd
->un
.ulpWord
[4] & 0xff) == IOERR_RCV_BUFFER_WAITING
) {
6530 phba
->fc_stat
.NoRcvBuf
++;
6531 /* Not enough posted buffers; Try posting more buffers */
6532 if (!(phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
))
6533 lpfc_post_buffer(phba
, pring
, 0);
6537 if ((phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
6538 (icmd
->ulpCommand
== CMD_IOCB_RCV_ELS64_CX
||
6539 icmd
->ulpCommand
== CMD_IOCB_RCV_SEQ64_CX
)) {
6540 if (icmd
->unsli3
.rcvsli3
.vpi
== 0xffff)
6541 vport
= phba
->pport
;
6543 vport
= lpfc_find_vport_by_vpid(phba
,
6544 icmd
->unsli3
.rcvsli3
.vpi
- phba
->vpi_base
);
6546 /* If there are no BDEs associated
6547 * with this IOCB, there is nothing to do.
6549 if (icmd
->ulpBdeCount
== 0)
6552 /* type of ELS cmd is first 32bit word
6555 if (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) {
6556 elsiocb
->context2
= bdeBuf1
;
6558 paddr
= getPaddr(icmd
->un
.cont64
[0].addrHigh
,
6559 icmd
->un
.cont64
[0].addrLow
);
6560 elsiocb
->context2
= lpfc_sli_ringpostbuf_get(phba
, pring
,
6564 lpfc_els_unsol_buffer(phba
, pring
, vport
, elsiocb
);
6566 * The different unsolicited event handlers would tell us
6567 * if they are done with "mp" by setting context2 to NULL.
6569 if (elsiocb
->context2
) {
6570 lpfc_in_buf_free(phba
, (struct lpfc_dmabuf
*)elsiocb
->context2
);
6571 elsiocb
->context2
= NULL
;
6574 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
6575 if ((phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) &&
6576 icmd
->ulpBdeCount
== 2) {
6577 elsiocb
->context2
= bdeBuf2
;
6578 lpfc_els_unsol_buffer(phba
, pring
, vport
, elsiocb
);
6579 /* free mp if we are done with it */
6580 if (elsiocb
->context2
) {
6581 lpfc_in_buf_free(phba
, elsiocb
->context2
);
6582 elsiocb
->context2
= NULL
;
6588 * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
6589 * @phba: pointer to lpfc hba data structure.
6590 * @vport: pointer to a virtual N_Port data structure.
6592 * This routine issues a Port Login (PLOGI) to the Name Server with
6593 * State Change Request (SCR) for a @vport. This routine will create an
6594 * ndlp for the Name Server associated to the @vport if such node does
6595 * not already exist. The PLOGI to Name Server is issued by invoking the
6596 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
6597 * (FDMI) is configured to the @vport, a FDMI node will be created and
6598 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
6601 lpfc_do_scr_ns_plogi(struct lpfc_hba
*phba
, struct lpfc_vport
*vport
)
6603 struct lpfc_nodelist
*ndlp
, *ndlp_fdmi
;
6605 ndlp
= lpfc_findnode_did(vport
, NameServer_DID
);
6607 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
6609 if (phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
) {
6610 lpfc_disc_start(vport
);
6613 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
6614 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
6615 "0251 NameServer login: no memory\n");
6618 lpfc_nlp_init(vport
, ndlp
, NameServer_DID
);
6619 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
6620 ndlp
= lpfc_enable_node(vport
, ndlp
, NLP_STE_UNUSED_NODE
);
6622 if (phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
) {
6623 lpfc_disc_start(vport
);
6626 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
6627 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
6628 "0348 NameServer login: node freed\n");
6632 ndlp
->nlp_type
|= NLP_FABRIC
;
6634 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
6636 if (lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, 0)) {
6637 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
6638 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
6639 "0252 Cannot issue NameServer login\n");
6643 if (vport
->cfg_fdmi_on
) {
6644 /* If this is the first time, allocate an ndlp and initialize
6645 * it. Otherwise, make sure the node is enabled and then do the
6648 ndlp_fdmi
= lpfc_findnode_did(vport
, FDMI_DID
);
6650 ndlp_fdmi
= mempool_alloc(phba
->nlp_mem_pool
,
6653 lpfc_nlp_init(vport
, ndlp_fdmi
, FDMI_DID
);
6654 ndlp_fdmi
->nlp_type
|= NLP_FABRIC
;
6658 if (!NLP_CHK_NODE_ACT(ndlp_fdmi
))
6659 ndlp_fdmi
= lpfc_enable_node(vport
,
6664 lpfc_nlp_set_state(vport
, ndlp_fdmi
,
6665 NLP_STE_PLOGI_ISSUE
);
6666 lpfc_issue_els_plogi(vport
, ndlp_fdmi
->nlp_DID
, 0);
6672 * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
6673 * @phba: pointer to lpfc hba data structure.
6674 * @pmb: pointer to the driver internal queue element for mailbox command.
6676 * This routine is the completion callback function to register new vport
6677 * mailbox command. If the new vport mailbox command completes successfully,
6678 * the fabric registration login shall be performed on physical port (the
6679 * new vport created is actually a physical port, with VPI 0) or the port
6680 * login to Name Server for State Change Request (SCR) will be performed
6681 * on virtual port (real virtual port, with VPI greater than 0).
6684 lpfc_cmpl_reg_new_vport(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
6686 struct lpfc_vport
*vport
= pmb
->vport
;
6687 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
6688 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) pmb
->context2
;
6689 MAILBOX_t
*mb
= &pmb
->u
.mb
;
6692 spin_lock_irq(shost
->host_lock
);
6693 vport
->fc_flag
&= ~FC_VPORT_NEEDS_REG_VPI
;
6694 spin_unlock_irq(shost
->host_lock
);
6696 if (mb
->mbxStatus
) {
6697 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
6698 "0915 Register VPI failed : Status: x%x"
6699 " upd bit: x%x \n", mb
->mbxStatus
,
6700 mb
->un
.varRegVpi
.upd
);
6701 if (phba
->sli_rev
== LPFC_SLI_REV4
&&
6702 mb
->un
.varRegVpi
.upd
)
6703 goto mbox_err_exit
;
6705 switch (mb
->mbxStatus
) {
6706 case 0x11: /* unsupported feature */
6707 case 0x9603: /* max_vpi exceeded */
6708 case 0x9602: /* Link event since CLEAR_LA */
6709 /* giving up on vport registration */
6710 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
6711 spin_lock_irq(shost
->host_lock
);
6712 vport
->fc_flag
&= ~(FC_FABRIC
| FC_PUBLIC_LOOP
);
6713 spin_unlock_irq(shost
->host_lock
);
6714 lpfc_can_disctmo(vport
);
6716 /* If reg_vpi fail with invalid VPI status, re-init VPI */
6718 spin_lock_irq(shost
->host_lock
);
6719 vport
->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
6720 spin_unlock_irq(shost
->host_lock
);
6721 lpfc_init_vpi(phba
, pmb
, vport
->vpi
);
6723 pmb
->mbox_cmpl
= lpfc_init_vpi_cmpl
;
6724 rc
= lpfc_sli_issue_mbox(phba
, pmb
,
6726 if (rc
== MBX_NOT_FINISHED
) {
6727 lpfc_printf_vlog(vport
,
6729 "2732 Failed to issue INIT_VPI"
6730 " mailbox command\n");
6737 /* Try to recover from this error */
6738 if (phba
->sli_rev
== LPFC_SLI_REV4
)
6739 lpfc_sli4_unreg_all_rpis(vport
);
6740 lpfc_mbx_unreg_vpi(vport
);
6741 spin_lock_irq(shost
->host_lock
);
6742 vport
->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
6743 spin_unlock_irq(shost
->host_lock
);
6744 if (vport
->port_type
== LPFC_PHYSICAL_PORT
6745 && !(vport
->fc_flag
& FC_LOGO_RCVD_DID_CHNG
))
6746 lpfc_issue_init_vfi(vport
);
6748 lpfc_initial_fdisc(vport
);
6752 spin_lock_irq(shost
->host_lock
);
6753 vport
->vpi_state
|= LPFC_VPI_REGISTERED
;
6754 spin_unlock_irq(shost
->host_lock
);
6755 if (vport
== phba
->pport
) {
6756 if (phba
->sli_rev
< LPFC_SLI_REV4
)
6757 lpfc_issue_fabric_reglogin(vport
);
6760 * If the physical port is instantiated using
6761 * FDISC, do not start vport discovery.
6763 if (vport
->port_state
!= LPFC_FDISC
)
6764 lpfc_start_fdiscs(phba
);
6765 lpfc_do_scr_ns_plogi(phba
, vport
);
6768 lpfc_do_scr_ns_plogi(phba
, vport
);
6771 /* Now, we decrement the ndlp reference count held for this
6776 mempool_free(pmb
, phba
->mbox_mem_pool
);
6781 * lpfc_register_new_vport - Register a new vport with a HBA
6782 * @phba: pointer to lpfc hba data structure.
6783 * @vport: pointer to a host virtual N_Port data structure.
6784 * @ndlp: pointer to a node-list data structure.
6786 * This routine registers the @vport as a new virtual port with a HBA.
6787 * It is done through a registering vpi mailbox command.
6790 lpfc_register_new_vport(struct lpfc_hba
*phba
, struct lpfc_vport
*vport
,
6791 struct lpfc_nodelist
*ndlp
)
6793 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
6796 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
6798 lpfc_reg_vpi(vport
, mbox
);
6799 mbox
->vport
= vport
;
6800 mbox
->context2
= lpfc_nlp_get(ndlp
);
6801 mbox
->mbox_cmpl
= lpfc_cmpl_reg_new_vport
;
6802 if (lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
)
6803 == MBX_NOT_FINISHED
) {
6804 /* mailbox command not success, decrement ndlp
6805 * reference count for this command
6808 mempool_free(mbox
, phba
->mbox_mem_pool
);
6810 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
6811 "0253 Register VPI: Can't send mbox\n");
6815 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
6816 "0254 Register VPI: no memory\n");
6822 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
6823 spin_lock_irq(shost
->host_lock
);
6824 vport
->fc_flag
&= ~FC_VPORT_NEEDS_REG_VPI
;
6825 spin_unlock_irq(shost
->host_lock
);
6830 * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer
6831 * @phba: pointer to lpfc hba data structure.
6833 * This routine cancels the retry delay timers to all the vports.
6836 lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba
*phba
)
6838 struct lpfc_vport
**vports
;
6839 struct lpfc_nodelist
*ndlp
;
6840 uint32_t link_state
;
6843 /* Treat this failure as linkdown for all vports */
6844 link_state
= phba
->link_state
;
6845 lpfc_linkdown(phba
);
6846 phba
->link_state
= link_state
;
6848 vports
= lpfc_create_vport_work_array(phba
);
6851 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
6852 ndlp
= lpfc_findnode_did(vports
[i
], Fabric_DID
);
6854 lpfc_cancel_retry_delay_tmo(vports
[i
], ndlp
);
6855 lpfc_els_flush_cmd(vports
[i
]);
6857 lpfc_destroy_vport_work_array(phba
, vports
);
6862 * lpfc_retry_pport_discovery - Start timer to retry FLOGI.
6863 * @phba: pointer to lpfc hba data structure.
6865 * This routine abort all pending discovery commands and
6866 * start a timer to retry FLOGI for the physical port
6870 lpfc_retry_pport_discovery(struct lpfc_hba
*phba
)
6872 struct lpfc_nodelist
*ndlp
;
6873 struct Scsi_Host
*shost
;
6875 /* Cancel the all vports retry delay retry timers */
6876 lpfc_cancel_all_vport_retry_delay_timer(phba
);
6878 /* If fabric require FLOGI, then re-instantiate physical login */
6879 ndlp
= lpfc_findnode_did(phba
->pport
, Fabric_DID
);
6883 shost
= lpfc_shost_from_vport(phba
->pport
);
6884 mod_timer(&ndlp
->nlp_delayfunc
, jiffies
+ HZ
);
6885 spin_lock_irq(shost
->host_lock
);
6886 ndlp
->nlp_flag
|= NLP_DELAY_TMO
;
6887 spin_unlock_irq(shost
->host_lock
);
6888 ndlp
->nlp_last_elscmd
= ELS_CMD_FLOGI
;
6889 phba
->pport
->port_state
= LPFC_FLOGI
;
6894 * lpfc_fabric_login_reqd - Check if FLOGI required.
6895 * @phba: pointer to lpfc hba data structure.
6896 * @cmdiocb: pointer to FDISC command iocb.
6897 * @rspiocb: pointer to FDISC response iocb.
6899 * This routine checks if a FLOGI is reguired for FDISC
6903 lpfc_fabric_login_reqd(struct lpfc_hba
*phba
,
6904 struct lpfc_iocbq
*cmdiocb
,
6905 struct lpfc_iocbq
*rspiocb
)
6908 if ((rspiocb
->iocb
.ulpStatus
!= IOSTAT_FABRIC_RJT
) ||
6909 (rspiocb
->iocb
.un
.ulpWord
[4] != RJT_LOGIN_REQUIRED
))
6916 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
6917 * @phba: pointer to lpfc hba data structure.
6918 * @cmdiocb: pointer to lpfc command iocb data structure.
6919 * @rspiocb: pointer to lpfc response iocb data structure.
6921 * This routine is the completion callback function to a Fabric Discover
6922 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
6923 * single threaded, each FDISC completion callback function will reset
6924 * the discovery timer for all vports such that the timers will not get
6925 * unnecessary timeout. The function checks the FDISC IOCB status. If error
6926 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
6927 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
6928 * assigned to the vport has been changed with the completion of the FDISC
6929 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
6930 * are unregistered from the HBA, and then the lpfc_register_new_vport()
6931 * routine is invoked to register new vport with the HBA. Otherwise, the
6932 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
6933 * Server for State Change Request (SCR).
6936 lpfc_cmpl_els_fdisc(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
6937 struct lpfc_iocbq
*rspiocb
)
6939 struct lpfc_vport
*vport
= cmdiocb
->vport
;
6940 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
6941 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) cmdiocb
->context1
;
6942 struct lpfc_nodelist
*np
;
6943 struct lpfc_nodelist
*next_np
;
6944 IOCB_t
*irsp
= &rspiocb
->iocb
;
6945 struct lpfc_iocbq
*piocb
;
6947 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
6948 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
6949 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
6951 /* Since all FDISCs are being single threaded, we
6952 * must reset the discovery timer for ALL vports
6953 * waiting to send FDISC when one completes.
6955 list_for_each_entry(piocb
, &phba
->fabric_iocb_list
, list
) {
6956 lpfc_set_disctmo(piocb
->vport
);
6959 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
6960 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
6961 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4], vport
->fc_prevDID
);
6963 if (irsp
->ulpStatus
) {
6965 if (lpfc_fabric_login_reqd(phba
, cmdiocb
, rspiocb
)) {
6966 lpfc_retry_pport_discovery(phba
);
6970 /* Check for retry */
6971 if (lpfc_els_retry(phba
, cmdiocb
, rspiocb
))
6974 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
6975 "0126 FDISC failed. (%d/%d)\n",
6976 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4]);
6979 spin_lock_irq(shost
->host_lock
);
6980 vport
->fc_flag
&= ~FC_VPORT_CVL_RCVD
;
6981 vport
->fc_flag
&= ~FC_VPORT_LOGO_RCVD
;
6982 vport
->fc_flag
|= FC_FABRIC
;
6983 if (vport
->phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
)
6984 vport
->fc_flag
|= FC_PUBLIC_LOOP
;
6985 spin_unlock_irq(shost
->host_lock
);
6987 vport
->fc_myDID
= irsp
->un
.ulpWord
[4] & Mask_DID
;
6988 lpfc_vport_set_state(vport
, FC_VPORT_ACTIVE
);
6989 if ((vport
->fc_prevDID
!= vport
->fc_myDID
) &&
6990 !(vport
->fc_flag
& FC_VPORT_NEEDS_REG_VPI
)) {
6991 /* If our NportID changed, we need to ensure all
6992 * remaining NPORTs get unreg_login'ed so we can
6995 list_for_each_entry_safe(np
, next_np
,
6996 &vport
->fc_nodes
, nlp_listp
) {
6997 if (!NLP_CHK_NODE_ACT(ndlp
) ||
6998 (np
->nlp_state
!= NLP_STE_NPR_NODE
) ||
6999 !(np
->nlp_flag
& NLP_NPR_ADISC
))
7001 spin_lock_irq(shost
->host_lock
);
7002 np
->nlp_flag
&= ~NLP_NPR_ADISC
;
7003 spin_unlock_irq(shost
->host_lock
);
7004 lpfc_unreg_rpi(vport
, np
);
7006 lpfc_cleanup_pending_mbox(vport
);
7008 if (phba
->sli_rev
== LPFC_SLI_REV4
)
7009 lpfc_sli4_unreg_all_rpis(vport
);
7011 lpfc_mbx_unreg_vpi(vport
);
7012 spin_lock_irq(shost
->host_lock
);
7013 vport
->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
7014 if (phba
->sli_rev
== LPFC_SLI_REV4
)
7015 vport
->fc_flag
|= FC_VPORT_NEEDS_INIT_VPI
;
7017 vport
->fc_flag
|= FC_LOGO_RCVD_DID_CHNG
;
7018 spin_unlock_irq(shost
->host_lock
);
7019 } else if ((phba
->sli_rev
== LPFC_SLI_REV4
) &&
7020 !(vport
->fc_flag
& FC_VPORT_NEEDS_REG_VPI
)) {
7022 * Driver needs to re-reg VPI in order for f/w
7023 * to update the MAC address.
7025 lpfc_register_new_vport(phba
, vport
, ndlp
);
7029 if (vport
->fc_flag
& FC_VPORT_NEEDS_INIT_VPI
)
7030 lpfc_issue_init_vpi(vport
);
7031 else if (vport
->fc_flag
& FC_VPORT_NEEDS_REG_VPI
)
7032 lpfc_register_new_vport(phba
, vport
, ndlp
);
7034 lpfc_do_scr_ns_plogi(phba
, vport
);
7037 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
7038 /* Cancel discovery timer */
7039 lpfc_can_disctmo(vport
);
7042 lpfc_els_free_iocb(phba
, cmdiocb
);
7046 * lpfc_issue_els_fdisc - Issue a fdisc iocb command
7047 * @vport: pointer to a virtual N_Port data structure.
7048 * @ndlp: pointer to a node-list data structure.
7049 * @retry: number of retries to the command IOCB.
7051 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
7052 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
7053 * routine to issue the IOCB, which makes sure only one outstanding fabric
7054 * IOCB will be sent off HBA at any given time.
7056 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7057 * will be incremented by 1 for holding the ndlp and the reference to ndlp
7058 * will be stored into the context1 field of the IOCB for the completion
7059 * callback function to the FDISC ELS command.
7062 * 0 - Successfully issued fdisc iocb command
7063 * 1 - Failed to issue fdisc iocb command
7066 lpfc_issue_els_fdisc(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
7069 struct lpfc_hba
*phba
= vport
->phba
;
7071 struct lpfc_iocbq
*elsiocb
;
7072 struct serv_parm
*sp
;
7075 int did
= ndlp
->nlp_DID
;
7078 vport
->port_state
= LPFC_FDISC
;
7079 cmdsize
= (sizeof(uint32_t) + sizeof(struct serv_parm
));
7080 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
, did
,
7083 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
7084 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
7085 "0255 Issue FDISC: no IOCB\n");
7089 icmd
= &elsiocb
->iocb
;
7090 icmd
->un
.elsreq64
.myID
= 0;
7091 icmd
->un
.elsreq64
.fl
= 1;
7093 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
7094 /* FDISC needs to be 1 for WQE VPI */
7095 elsiocb
->iocb
.ulpCt_h
= (SLI4_CT_VPI
>> 1) & 1;
7096 elsiocb
->iocb
.ulpCt_l
= SLI4_CT_VPI
& 1 ;
7097 /* Set the ulpContext to the vpi */
7098 elsiocb
->iocb
.ulpContext
= vport
->vpi
+ phba
->vpi_base
;
7100 /* For FDISC, Let FDISC rsp set the NPortID for this VPI */
7105 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
7106 *((uint32_t *) (pcmd
)) = ELS_CMD_FDISC
;
7107 pcmd
+= sizeof(uint32_t); /* CSP Word 1 */
7108 memcpy(pcmd
, &vport
->phba
->pport
->fc_sparam
, sizeof(struct serv_parm
));
7109 sp
= (struct serv_parm
*) pcmd
;
7110 /* Setup CSPs accordingly for Fabric */
7111 sp
->cmn
.e_d_tov
= 0;
7112 sp
->cmn
.w2
.r_a_tov
= 0;
7113 sp
->cls1
.classValid
= 0;
7114 sp
->cls2
.seqDelivery
= 1;
7115 sp
->cls3
.seqDelivery
= 1;
7117 pcmd
+= sizeof(uint32_t); /* CSP Word 2 */
7118 pcmd
+= sizeof(uint32_t); /* CSP Word 3 */
7119 pcmd
+= sizeof(uint32_t); /* CSP Word 4 */
7120 pcmd
+= sizeof(uint32_t); /* Port Name */
7121 memcpy(pcmd
, &vport
->fc_portname
, 8);
7122 pcmd
+= sizeof(uint32_t); /* Node Name */
7123 pcmd
+= sizeof(uint32_t); /* Node Name */
7124 memcpy(pcmd
, &vport
->fc_nodename
, 8);
7126 lpfc_set_disctmo(vport
);
7128 phba
->fc_stat
.elsXmitFDISC
++;
7129 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_fdisc
;
7131 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
7132 "Issue FDISC: did:x%x",
7135 rc
= lpfc_issue_fabric_iocb(phba
, elsiocb
);
7136 if (rc
== IOCB_ERROR
) {
7137 lpfc_els_free_iocb(phba
, elsiocb
);
7138 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
7139 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
7140 "0256 Issue FDISC: Cannot send IOCB\n");
7143 lpfc_vport_set_state(vport
, FC_VPORT_INITIALIZING
);
7148 * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
7149 * @phba: pointer to lpfc hba data structure.
7150 * @cmdiocb: pointer to lpfc command iocb data structure.
7151 * @rspiocb: pointer to lpfc response iocb data structure.
7153 * This routine is the completion callback function to the issuing of a LOGO
7154 * ELS command off a vport. It frees the command IOCB and then decrement the
7155 * reference count held on ndlp for this completion function, indicating that
7156 * the reference to the ndlp is no long needed. Note that the
7157 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
7158 * callback function and an additional explicit ndlp reference decrementation
7159 * will trigger the actual release of the ndlp.
7162 lpfc_cmpl_els_npiv_logo(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
7163 struct lpfc_iocbq
*rspiocb
)
7165 struct lpfc_vport
*vport
= cmdiocb
->vport
;
7167 struct lpfc_nodelist
*ndlp
;
7168 ndlp
= (struct lpfc_nodelist
*)cmdiocb
->context1
;
7170 irsp
= &rspiocb
->iocb
;
7171 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
7172 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
7173 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4], irsp
->un
.rcvels
.remoteID
);
7175 lpfc_els_free_iocb(phba
, cmdiocb
);
7176 vport
->unreg_vpi_cmpl
= VPORT_ERROR
;
7178 /* Trigger the release of the ndlp after logo */
7183 * lpfc_issue_els_npiv_logo - Issue a logo off a vport
7184 * @vport: pointer to a virtual N_Port data structure.
7185 * @ndlp: pointer to a node-list data structure.
7187 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
7189 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7190 * will be incremented by 1 for holding the ndlp and the reference to ndlp
7191 * will be stored into the context1 field of the IOCB for the completion
7192 * callback function to the LOGO ELS command.
7195 * 0 - Successfully issued logo off the @vport
7196 * 1 - Failed to issue logo off the @vport
7199 lpfc_issue_els_npiv_logo(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
7201 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
7202 struct lpfc_hba
*phba
= vport
->phba
;
7204 struct lpfc_iocbq
*elsiocb
;
7208 cmdsize
= 2 * sizeof(uint32_t) + sizeof(struct lpfc_name
);
7209 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, 0, ndlp
, ndlp
->nlp_DID
,
7214 icmd
= &elsiocb
->iocb
;
7215 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
7216 *((uint32_t *) (pcmd
)) = ELS_CMD_LOGO
;
7217 pcmd
+= sizeof(uint32_t);
7219 /* Fill in LOGO payload */
7220 *((uint32_t *) (pcmd
)) = be32_to_cpu(vport
->fc_myDID
);
7221 pcmd
+= sizeof(uint32_t);
7222 memcpy(pcmd
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
7224 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
7225 "Issue LOGO npiv did:x%x flg:x%x",
7226 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
7228 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_npiv_logo
;
7229 spin_lock_irq(shost
->host_lock
);
7230 ndlp
->nlp_flag
|= NLP_LOGO_SND
;
7231 spin_unlock_irq(shost
->host_lock
);
7232 if (lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0) ==
7234 spin_lock_irq(shost
->host_lock
);
7235 ndlp
->nlp_flag
&= ~NLP_LOGO_SND
;
7236 spin_unlock_irq(shost
->host_lock
);
7237 lpfc_els_free_iocb(phba
, elsiocb
);
7244 * lpfc_fabric_block_timeout - Handler function to the fabric block timer
7245 * @ptr: holder for the timer function associated data.
7247 * This routine is invoked by the fabric iocb block timer after
7248 * timeout. It posts the fabric iocb block timeout event by setting the
7249 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
7250 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
7251 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
7252 * posted event WORKER_FABRIC_BLOCK_TMO.
7255 lpfc_fabric_block_timeout(unsigned long ptr
)
7257 struct lpfc_hba
*phba
= (struct lpfc_hba
*) ptr
;
7258 unsigned long iflags
;
7259 uint32_t tmo_posted
;
7261 spin_lock_irqsave(&phba
->pport
->work_port_lock
, iflags
);
7262 tmo_posted
= phba
->pport
->work_port_events
& WORKER_FABRIC_BLOCK_TMO
;
7264 phba
->pport
->work_port_events
|= WORKER_FABRIC_BLOCK_TMO
;
7265 spin_unlock_irqrestore(&phba
->pport
->work_port_lock
, iflags
);
7268 lpfc_worker_wake_up(phba
);
7273 * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
7274 * @phba: pointer to lpfc hba data structure.
7276 * This routine issues one fabric iocb from the driver internal list to
7277 * the HBA. It first checks whether it's ready to issue one fabric iocb to
7278 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
7279 * remove one pending fabric iocb from the driver internal list and invokes
7280 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
7283 lpfc_resume_fabric_iocbs(struct lpfc_hba
*phba
)
7285 struct lpfc_iocbq
*iocb
;
7286 unsigned long iflags
;
7292 spin_lock_irqsave(&phba
->hbalock
, iflags
);
7293 /* Post any pending iocb to the SLI layer */
7294 if (atomic_read(&phba
->fabric_iocb_count
) == 0) {
7295 list_remove_head(&phba
->fabric_iocb_list
, iocb
, typeof(*iocb
),
7298 /* Increment fabric iocb count to hold the position */
7299 atomic_inc(&phba
->fabric_iocb_count
);
7301 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
7303 iocb
->fabric_iocb_cmpl
= iocb
->iocb_cmpl
;
7304 iocb
->iocb_cmpl
= lpfc_cmpl_fabric_iocb
;
7305 iocb
->iocb_flag
|= LPFC_IO_FABRIC
;
7307 lpfc_debugfs_disc_trc(iocb
->vport
, LPFC_DISC_TRC_ELS_CMD
,
7308 "Fabric sched1: ste:x%x",
7309 iocb
->vport
->port_state
, 0, 0);
7311 ret
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, iocb
, 0);
7313 if (ret
== IOCB_ERROR
) {
7314 iocb
->iocb_cmpl
= iocb
->fabric_iocb_cmpl
;
7315 iocb
->fabric_iocb_cmpl
= NULL
;
7316 iocb
->iocb_flag
&= ~LPFC_IO_FABRIC
;
7318 cmd
->ulpStatus
= IOSTAT_LOCAL_REJECT
;
7319 cmd
->un
.ulpWord
[4] = IOERR_SLI_ABORTED
;
7320 iocb
->iocb_cmpl(phba
, iocb
, iocb
);
7322 atomic_dec(&phba
->fabric_iocb_count
);
7331 * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
7332 * @phba: pointer to lpfc hba data structure.
7334 * This routine unblocks the issuing fabric iocb command. The function
7335 * will clear the fabric iocb block bit and then invoke the routine
7336 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
7337 * from the driver internal fabric iocb list.
7340 lpfc_unblock_fabric_iocbs(struct lpfc_hba
*phba
)
7342 clear_bit(FABRIC_COMANDS_BLOCKED
, &phba
->bit_flags
);
7344 lpfc_resume_fabric_iocbs(phba
);
7349 * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
7350 * @phba: pointer to lpfc hba data structure.
7352 * This routine blocks the issuing fabric iocb for a specified amount of
7353 * time (currently 100 ms). This is done by set the fabric iocb block bit
7354 * and set up a timeout timer for 100ms. When the block bit is set, no more
7355 * fabric iocb will be issued out of the HBA.
7358 lpfc_block_fabric_iocbs(struct lpfc_hba
*phba
)
7362 blocked
= test_and_set_bit(FABRIC_COMANDS_BLOCKED
, &phba
->bit_flags
);
7363 /* Start a timer to unblock fabric iocbs after 100ms */
7365 mod_timer(&phba
->fabric_block_timer
, jiffies
+ HZ
/10 );
7371 * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
7372 * @phba: pointer to lpfc hba data structure.
7373 * @cmdiocb: pointer to lpfc command iocb data structure.
7374 * @rspiocb: pointer to lpfc response iocb data structure.
7376 * This routine is the callback function that is put to the fabric iocb's
7377 * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
7378 * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
7379 * function first restores and invokes the original iocb's callback function
7380 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
7381 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
7384 lpfc_cmpl_fabric_iocb(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
7385 struct lpfc_iocbq
*rspiocb
)
7389 if ((cmdiocb
->iocb_flag
& LPFC_IO_FABRIC
) != LPFC_IO_FABRIC
)
7392 switch (rspiocb
->iocb
.ulpStatus
) {
7393 case IOSTAT_NPORT_RJT
:
7394 case IOSTAT_FABRIC_RJT
:
7395 if (rspiocb
->iocb
.un
.ulpWord
[4] & RJT_UNAVAIL_TEMP
) {
7396 lpfc_block_fabric_iocbs(phba
);
7400 case IOSTAT_NPORT_BSY
:
7401 case IOSTAT_FABRIC_BSY
:
7402 lpfc_block_fabric_iocbs(phba
);
7406 stat
.un
.lsRjtError
=
7407 be32_to_cpu(rspiocb
->iocb
.un
.ulpWord
[4]);
7408 if ((stat
.un
.b
.lsRjtRsnCode
== LSRJT_UNABLE_TPC
) ||
7409 (stat
.un
.b
.lsRjtRsnCode
== LSRJT_LOGICAL_BSY
))
7410 lpfc_block_fabric_iocbs(phba
);
7414 if (atomic_read(&phba
->fabric_iocb_count
) == 0)
7417 cmdiocb
->iocb_cmpl
= cmdiocb
->fabric_iocb_cmpl
;
7418 cmdiocb
->fabric_iocb_cmpl
= NULL
;
7419 cmdiocb
->iocb_flag
&= ~LPFC_IO_FABRIC
;
7420 cmdiocb
->iocb_cmpl(phba
, cmdiocb
, rspiocb
);
7422 atomic_dec(&phba
->fabric_iocb_count
);
7423 if (!test_bit(FABRIC_COMANDS_BLOCKED
, &phba
->bit_flags
)) {
7424 /* Post any pending iocbs to HBA */
7425 lpfc_resume_fabric_iocbs(phba
);
7430 * lpfc_issue_fabric_iocb - Issue a fabric iocb command
7431 * @phba: pointer to lpfc hba data structure.
7432 * @iocb: pointer to lpfc command iocb data structure.
7434 * This routine is used as the top-level API for issuing a fabric iocb command
7435 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
7436 * function makes sure that only one fabric bound iocb will be outstanding at
7437 * any given time. As such, this function will first check to see whether there
7438 * is already an outstanding fabric iocb on the wire. If so, it will put the
7439 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
7440 * issued later. Otherwise, it will issue the iocb on the wire and update the
7441 * fabric iocb count it indicate that there is one fabric iocb on the wire.
7443 * Note, this implementation has a potential sending out fabric IOCBs out of
7444 * order. The problem is caused by the construction of the "ready" boolen does
7445 * not include the condition that the internal fabric IOCB list is empty. As
7446 * such, it is possible a fabric IOCB issued by this routine might be "jump"
7447 * ahead of the fabric IOCBs in the internal list.
7450 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
7451 * IOCB_ERROR - failed to issue fabric iocb
7454 lpfc_issue_fabric_iocb(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocb
)
7456 unsigned long iflags
;
7460 if (atomic_read(&phba
->fabric_iocb_count
) > 1)
7463 spin_lock_irqsave(&phba
->hbalock
, iflags
);
7464 ready
= atomic_read(&phba
->fabric_iocb_count
) == 0 &&
7465 !test_bit(FABRIC_COMANDS_BLOCKED
, &phba
->bit_flags
);
7468 /* Increment fabric iocb count to hold the position */
7469 atomic_inc(&phba
->fabric_iocb_count
);
7470 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
7472 iocb
->fabric_iocb_cmpl
= iocb
->iocb_cmpl
;
7473 iocb
->iocb_cmpl
= lpfc_cmpl_fabric_iocb
;
7474 iocb
->iocb_flag
|= LPFC_IO_FABRIC
;
7476 lpfc_debugfs_disc_trc(iocb
->vport
, LPFC_DISC_TRC_ELS_CMD
,
7477 "Fabric sched2: ste:x%x",
7478 iocb
->vport
->port_state
, 0, 0);
7480 ret
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, iocb
, 0);
7482 if (ret
== IOCB_ERROR
) {
7483 iocb
->iocb_cmpl
= iocb
->fabric_iocb_cmpl
;
7484 iocb
->fabric_iocb_cmpl
= NULL
;
7485 iocb
->iocb_flag
&= ~LPFC_IO_FABRIC
;
7486 atomic_dec(&phba
->fabric_iocb_count
);
7489 spin_lock_irqsave(&phba
->hbalock
, iflags
);
7490 list_add_tail(&iocb
->list
, &phba
->fabric_iocb_list
);
7491 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
7498 * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
7499 * @vport: pointer to a virtual N_Port data structure.
7501 * This routine aborts all the IOCBs associated with a @vport from the
7502 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
7503 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
7504 * list, removes each IOCB associated with the @vport off the list, set the
7505 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
7506 * associated with the IOCB.
7508 static void lpfc_fabric_abort_vport(struct lpfc_vport
*vport
)
7510 LIST_HEAD(completions
);
7511 struct lpfc_hba
*phba
= vport
->phba
;
7512 struct lpfc_iocbq
*tmp_iocb
, *piocb
;
7514 spin_lock_irq(&phba
->hbalock
);
7515 list_for_each_entry_safe(piocb
, tmp_iocb
, &phba
->fabric_iocb_list
,
7518 if (piocb
->vport
!= vport
)
7521 list_move_tail(&piocb
->list
, &completions
);
7523 spin_unlock_irq(&phba
->hbalock
);
7525 /* Cancel all the IOCBs from the completions list */
7526 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
7531 * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
7532 * @ndlp: pointer to a node-list data structure.
7534 * This routine aborts all the IOCBs associated with an @ndlp from the
7535 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
7536 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
7537 * list, removes each IOCB associated with the @ndlp off the list, set the
7538 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
7539 * associated with the IOCB.
7541 void lpfc_fabric_abort_nport(struct lpfc_nodelist
*ndlp
)
7543 LIST_HEAD(completions
);
7544 struct lpfc_hba
*phba
= ndlp
->phba
;
7545 struct lpfc_iocbq
*tmp_iocb
, *piocb
;
7546 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
7548 spin_lock_irq(&phba
->hbalock
);
7549 list_for_each_entry_safe(piocb
, tmp_iocb
, &phba
->fabric_iocb_list
,
7551 if ((lpfc_check_sli_ndlp(phba
, pring
, piocb
, ndlp
))) {
7553 list_move_tail(&piocb
->list
, &completions
);
7556 spin_unlock_irq(&phba
->hbalock
);
7558 /* Cancel all the IOCBs from the completions list */
7559 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
7564 * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
7565 * @phba: pointer to lpfc hba data structure.
7567 * This routine aborts all the IOCBs currently on the driver internal
7568 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
7569 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
7570 * list, removes IOCBs off the list, set the status feild to
7571 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
7574 void lpfc_fabric_abort_hba(struct lpfc_hba
*phba
)
7576 LIST_HEAD(completions
);
7578 spin_lock_irq(&phba
->hbalock
);
7579 list_splice_init(&phba
->fabric_iocb_list
, &completions
);
7580 spin_unlock_irq(&phba
->hbalock
);
7582 /* Cancel all the IOCBs from the completions list */
7583 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
7588 * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
7589 * @phba: pointer to lpfc hba data structure.
7590 * @axri: pointer to the els xri abort wcqe structure.
7592 * This routine is invoked by the worker thread to process a SLI4 slow-path
7596 lpfc_sli4_els_xri_aborted(struct lpfc_hba
*phba
,
7597 struct sli4_wcqe_xri_aborted
*axri
)
7599 uint16_t xri
= bf_get(lpfc_wcqe_xa_xri
, axri
);
7600 uint16_t rxid
= bf_get(lpfc_wcqe_xa_remote_xid
, axri
);
7602 struct lpfc_sglq
*sglq_entry
= NULL
, *sglq_next
= NULL
;
7603 unsigned long iflag
= 0;
7604 struct lpfc_nodelist
*ndlp
;
7605 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
7607 spin_lock_irqsave(&phba
->hbalock
, iflag
);
7608 spin_lock(&phba
->sli4_hba
.abts_sgl_list_lock
);
7609 list_for_each_entry_safe(sglq_entry
, sglq_next
,
7610 &phba
->sli4_hba
.lpfc_abts_els_sgl_list
, list
) {
7611 if (sglq_entry
->sli4_xritag
== xri
) {
7612 list_del(&sglq_entry
->list
);
7613 ndlp
= sglq_entry
->ndlp
;
7614 sglq_entry
->ndlp
= NULL
;
7615 list_add_tail(&sglq_entry
->list
,
7616 &phba
->sli4_hba
.lpfc_sgl_list
);
7617 sglq_entry
->state
= SGL_FREED
;
7618 spin_unlock(&phba
->sli4_hba
.abts_sgl_list_lock
);
7619 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
7620 lpfc_set_rrq_active(phba
, ndlp
, xri
, rxid
, 1);
7622 /* Check if TXQ queue needs to be serviced */
7624 lpfc_worker_wake_up(phba
);
7628 spin_unlock(&phba
->sli4_hba
.abts_sgl_list_lock
);
7629 sglq_entry
= __lpfc_get_active_sglq(phba
, xri
);
7630 if (!sglq_entry
|| (sglq_entry
->sli4_xritag
!= xri
)) {
7631 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
7634 sglq_entry
->state
= SGL_XRI_ABORTED
;
7635 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);