1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2009 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. *
7 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
9 * This program is free software; you can redistribute it and/or *
10 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
20 *******************************************************************/
21 /* See Fibre Channel protocol T11 FC-LS for details */
22 #include <linux/blkdev.h>
23 #include <linux/pci.h>
24 #include <linux/slab.h>
25 #include <linux/interrupt.h>
27 #include <scsi/scsi.h>
28 #include <scsi/scsi_device.h>
29 #include <scsi/scsi_host.h>
30 #include <scsi/scsi_transport_fc.h>
35 #include "lpfc_sli4.h"
37 #include "lpfc_disc.h"
38 #include "lpfc_scsi.h"
40 #include "lpfc_logmsg.h"
41 #include "lpfc_crtn.h"
42 #include "lpfc_vport.h"
43 #include "lpfc_debugfs.h"
45 static int lpfc_els_retry(struct lpfc_hba
*, struct lpfc_iocbq
*,
47 static void lpfc_cmpl_fabric_iocb(struct lpfc_hba
*, struct lpfc_iocbq
*,
49 static void lpfc_fabric_abort_vport(struct lpfc_vport
*vport
);
50 static int lpfc_issue_els_fdisc(struct lpfc_vport
*vport
,
51 struct lpfc_nodelist
*ndlp
, uint8_t retry
);
52 static int lpfc_issue_fabric_iocb(struct lpfc_hba
*phba
,
53 struct lpfc_iocbq
*iocb
);
55 static int lpfc_max_els_tries
= 3;
58 * lpfc_els_chk_latt - Check host link attention event for a vport
59 * @vport: pointer to a host virtual N_Port data structure.
61 * This routine checks whether there is an outstanding host link
62 * attention event during the discovery process with the @vport. It is done
63 * by reading the HBA's Host Attention (HA) register. If there is any host
64 * link attention events during this @vport's discovery process, the @vport
65 * shall be marked as FC_ABORT_DISCOVERY, a host link attention clear shall
66 * be issued if the link state is not already in host link cleared state,
67 * and a return code shall indicate whether the host link attention event
70 * Note that, if either the host link is in state LPFC_LINK_DOWN or @vport
71 * state in LPFC_VPORT_READY, the request for checking host link attention
72 * event will be ignored and a return code shall indicate no host link
73 * attention event had happened.
76 * 0 - no host link attention event happened
77 * 1 - host link attention event happened
80 lpfc_els_chk_latt(struct lpfc_vport
*vport
)
82 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
83 struct lpfc_hba
*phba
= vport
->phba
;
86 if (vport
->port_state
>= LPFC_VPORT_READY
||
87 phba
->link_state
== LPFC_LINK_DOWN
||
88 phba
->sli_rev
> LPFC_SLI_REV3
)
91 /* Read the HBA Host Attention Register */
92 ha_copy
= readl(phba
->HAregaddr
);
94 if (!(ha_copy
& HA_LATT
))
97 /* Pending Link Event during Discovery */
98 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
99 "0237 Pending Link Event during "
100 "Discovery: State x%x\n",
101 phba
->pport
->port_state
);
103 /* CLEAR_LA should re-enable link attention events and
104 * we should then imediately take a LATT event. The
105 * LATT processing should call lpfc_linkdown() which
106 * will cleanup any left over in-progress discovery
109 spin_lock_irq(shost
->host_lock
);
110 vport
->fc_flag
|= FC_ABORT_DISCOVERY
;
111 spin_unlock_irq(shost
->host_lock
);
113 if (phba
->link_state
!= LPFC_CLEAR_LA
)
114 lpfc_issue_clear_la(phba
, vport
);
120 * lpfc_prep_els_iocb - Allocate and prepare a lpfc iocb data structure
121 * @vport: pointer to a host virtual N_Port data structure.
122 * @expectRsp: flag indicating whether response is expected.
123 * @cmdSize: size of the ELS command.
124 * @retry: number of retries to the command IOCB when it fails.
125 * @ndlp: pointer to a node-list data structure.
126 * @did: destination identifier.
127 * @elscmd: the ELS command code.
129 * This routine is used for allocating a lpfc-IOCB data structure from
130 * the driver lpfc-IOCB free-list and prepare the IOCB with the parameters
131 * passed into the routine for discovery state machine to issue an Extended
132 * Link Service (ELS) commands. It is a generic lpfc-IOCB allocation
133 * and preparation routine that is used by all the discovery state machine
134 * routines and the ELS command-specific fields will be later set up by
135 * the individual discovery machine routines after calling this routine
136 * allocating and preparing a generic IOCB data structure. It fills in the
137 * Buffer Descriptor Entries (BDEs), allocates buffers for both command
138 * payload and response payload (if expected). The reference count on the
139 * ndlp is incremented by 1 and the reference to the ndlp is put into
140 * context1 of the IOCB data structure for this IOCB to hold the ndlp
141 * reference for the command's callback function to access later.
144 * Pointer to the newly allocated/prepared els iocb data structure
145 * NULL - when els iocb data structure allocation/preparation failed
148 lpfc_prep_els_iocb(struct lpfc_vport
*vport
, uint8_t expectRsp
,
149 uint16_t cmdSize
, uint8_t retry
,
150 struct lpfc_nodelist
*ndlp
, uint32_t did
,
153 struct lpfc_hba
*phba
= vport
->phba
;
154 struct lpfc_iocbq
*elsiocb
;
155 struct lpfc_dmabuf
*pcmd
, *prsp
, *pbuflist
;
156 struct ulp_bde64
*bpl
;
160 if (!lpfc_is_link_up(phba
))
163 /* Allocate buffer for command iocb */
164 elsiocb
= lpfc_sli_get_iocbq(phba
);
170 * If this command is for fabric controller and HBA running
171 * in FIP mode send FLOGI, FDISC and LOGO as FIP frames.
173 if ((did
== Fabric_DID
) &&
174 (phba
->hba_flag
& HBA_FIP_SUPPORT
) &&
175 ((elscmd
== ELS_CMD_FLOGI
) ||
176 (elscmd
== ELS_CMD_FDISC
) ||
177 (elscmd
== ELS_CMD_LOGO
)))
180 elsiocb
->iocb_flag
|= ((ELS_ID_FLOGI
<< LPFC_FIP_ELS_ID_SHIFT
)
181 & LPFC_FIP_ELS_ID_MASK
);
184 elsiocb
->iocb_flag
|= ((ELS_ID_FDISC
<< LPFC_FIP_ELS_ID_SHIFT
)
185 & LPFC_FIP_ELS_ID_MASK
);
188 elsiocb
->iocb_flag
|= ((ELS_ID_LOGO
<< LPFC_FIP_ELS_ID_SHIFT
)
189 & LPFC_FIP_ELS_ID_MASK
);
193 elsiocb
->iocb_flag
&= ~LPFC_FIP_ELS_ID_MASK
;
195 icmd
= &elsiocb
->iocb
;
197 /* fill in BDEs for command */
198 /* Allocate buffer for command payload */
199 pcmd
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
201 pcmd
->virt
= lpfc_mbuf_alloc(phba
, MEM_PRI
, &pcmd
->phys
);
202 if (!pcmd
|| !pcmd
->virt
)
203 goto els_iocb_free_pcmb_exit
;
205 INIT_LIST_HEAD(&pcmd
->list
);
207 /* Allocate buffer for response payload */
209 prsp
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
211 prsp
->virt
= lpfc_mbuf_alloc(phba
, MEM_PRI
,
213 if (!prsp
|| !prsp
->virt
)
214 goto els_iocb_free_prsp_exit
;
215 INIT_LIST_HEAD(&prsp
->list
);
219 /* Allocate buffer for Buffer ptr list */
220 pbuflist
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
222 pbuflist
->virt
= lpfc_mbuf_alloc(phba
, MEM_PRI
,
224 if (!pbuflist
|| !pbuflist
->virt
)
225 goto els_iocb_free_pbuf_exit
;
227 INIT_LIST_HEAD(&pbuflist
->list
);
229 icmd
->un
.elsreq64
.bdl
.addrHigh
= putPaddrHigh(pbuflist
->phys
);
230 icmd
->un
.elsreq64
.bdl
.addrLow
= putPaddrLow(pbuflist
->phys
);
231 icmd
->un
.elsreq64
.bdl
.bdeFlags
= BUFF_TYPE_BLP_64
;
232 icmd
->un
.elsreq64
.remoteID
= did
; /* DID */
234 icmd
->un
.elsreq64
.bdl
.bdeSize
= (2 * sizeof(struct ulp_bde64
));
235 icmd
->ulpCommand
= CMD_ELS_REQUEST64_CR
;
236 icmd
->ulpTimeout
= phba
->fc_ratov
* 2;
238 icmd
->un
.elsreq64
.bdl
.bdeSize
= sizeof(struct ulp_bde64
);
239 icmd
->ulpCommand
= CMD_XMIT_ELS_RSP64_CX
;
241 icmd
->ulpBdeCount
= 1;
243 icmd
->ulpClass
= CLASS3
;
245 if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) {
246 icmd
->un
.elsreq64
.myID
= vport
->fc_myDID
;
248 /* For ELS_REQUEST64_CR, use the VPI by default */
249 icmd
->ulpContext
= vport
->vpi
+ phba
->vpi_base
;
251 /* The CT field must be 0=INVALID_RPI for the ECHO cmd */
252 if (elscmd
== ELS_CMD_ECHO
)
253 icmd
->ulpCt_l
= 0; /* context = invalid RPI */
255 icmd
->ulpCt_l
= 1; /* context = VPI */
258 bpl
= (struct ulp_bde64
*) pbuflist
->virt
;
259 bpl
->addrLow
= le32_to_cpu(putPaddrLow(pcmd
->phys
));
260 bpl
->addrHigh
= le32_to_cpu(putPaddrHigh(pcmd
->phys
));
261 bpl
->tus
.f
.bdeSize
= cmdSize
;
262 bpl
->tus
.f
.bdeFlags
= 0;
263 bpl
->tus
.w
= le32_to_cpu(bpl
->tus
.w
);
267 bpl
->addrLow
= le32_to_cpu(putPaddrLow(prsp
->phys
));
268 bpl
->addrHigh
= le32_to_cpu(putPaddrHigh(prsp
->phys
));
269 bpl
->tus
.f
.bdeSize
= FCELSSIZE
;
270 bpl
->tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64
;
271 bpl
->tus
.w
= le32_to_cpu(bpl
->tus
.w
);
274 /* prevent preparing iocb with NULL ndlp reference */
275 elsiocb
->context1
= lpfc_nlp_get(ndlp
);
276 if (!elsiocb
->context1
)
277 goto els_iocb_free_pbuf_exit
;
278 elsiocb
->context2
= pcmd
;
279 elsiocb
->context3
= pbuflist
;
280 elsiocb
->retry
= retry
;
281 elsiocb
->vport
= vport
;
282 elsiocb
->drvrTimeout
= (phba
->fc_ratov
<< 1) + LPFC_DRVR_TIMEOUT
;
285 list_add(&prsp
->list
, &pcmd
->list
);
288 /* Xmit ELS command <elsCmd> to remote NPORT <did> */
289 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
290 "0116 Xmit ELS command x%x to remote "
291 "NPORT x%x I/O tag: x%x, port state: x%x\n",
292 elscmd
, did
, elsiocb
->iotag
,
295 /* Xmit ELS response <elsCmd> to remote NPORT <did> */
296 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
297 "0117 Xmit ELS response x%x to remote "
298 "NPORT x%x I/O tag: x%x, size: x%x\n",
299 elscmd
, ndlp
->nlp_DID
, elsiocb
->iotag
,
304 els_iocb_free_pbuf_exit
:
306 lpfc_mbuf_free(phba
, prsp
->virt
, prsp
->phys
);
309 els_iocb_free_prsp_exit
:
310 lpfc_mbuf_free(phba
, pcmd
->virt
, pcmd
->phys
);
313 els_iocb_free_pcmb_exit
:
315 lpfc_sli_release_iocbq(phba
, elsiocb
);
320 * lpfc_issue_fabric_reglogin - Issue fabric registration login for a vport
321 * @vport: pointer to a host virtual N_Port data structure.
323 * This routine issues a fabric registration login for a @vport. An
324 * active ndlp node with Fabric_DID must already exist for this @vport.
325 * The routine invokes two mailbox commands to carry out fabric registration
326 * login through the HBA firmware: the first mailbox command requests the
327 * HBA to perform link configuration for the @vport; and the second mailbox
328 * command requests the HBA to perform the actual fabric registration login
332 * 0 - successfully issued fabric registration login for @vport
333 * -ENXIO -- failed to issue fabric registration login for @vport
336 lpfc_issue_fabric_reglogin(struct lpfc_vport
*vport
)
338 struct lpfc_hba
*phba
= vport
->phba
;
340 struct lpfc_dmabuf
*mp
;
341 struct lpfc_nodelist
*ndlp
;
342 struct serv_parm
*sp
;
346 sp
= &phba
->fc_fabparam
;
347 ndlp
= lpfc_findnode_did(vport
, Fabric_DID
);
348 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
)) {
353 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
359 vport
->port_state
= LPFC_FABRIC_CFG_LINK
;
360 lpfc_config_link(phba
, mbox
);
361 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
364 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
365 if (rc
== MBX_NOT_FINISHED
) {
370 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
375 rc
= lpfc_reg_rpi(phba
, vport
->vpi
, Fabric_DID
, (uint8_t *)sp
, mbox
, 0);
381 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_fabric_reg_login
;
383 /* increment the reference count on ndlp to hold reference
384 * for the callback routine.
386 mbox
->context2
= lpfc_nlp_get(ndlp
);
388 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
389 if (rc
== MBX_NOT_FINISHED
) {
391 goto fail_issue_reg_login
;
396 fail_issue_reg_login
:
397 /* decrement the reference count on ndlp just incremented
398 * for the failed mbox command.
401 mp
= (struct lpfc_dmabuf
*) mbox
->context1
;
402 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
405 mempool_free(mbox
, phba
->mbox_mem_pool
);
408 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
409 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
410 "0249 Cannot issue Register Fabric login: Err %d\n", err
);
415 * lpfc_issue_reg_vfi - Register VFI for this vport's fabric login
416 * @vport: pointer to a host virtual N_Port data structure.
418 * This routine issues a REG_VFI mailbox for the vfi, vpi, fcfi triplet for
419 * the @vport. This mailbox command is necessary for FCoE only.
422 * 0 - successfully issued REG_VFI for @vport
423 * A failure code otherwise.
426 lpfc_issue_reg_vfi(struct lpfc_vport
*vport
)
428 struct lpfc_hba
*phba
= vport
->phba
;
430 struct lpfc_nodelist
*ndlp
;
431 struct serv_parm
*sp
;
432 struct lpfc_dmabuf
*dmabuf
;
435 sp
= &phba
->fc_fabparam
;
436 ndlp
= lpfc_findnode_did(vport
, Fabric_DID
);
437 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
)) {
442 dmabuf
= kzalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
447 dmabuf
->virt
= lpfc_mbuf_alloc(phba
, MEM_PRI
, &dmabuf
->phys
);
450 goto fail_free_dmabuf
;
452 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
455 goto fail_free_coherent
;
457 vport
->port_state
= LPFC_FABRIC_CFG_LINK
;
458 memcpy(dmabuf
->virt
, &phba
->fc_fabparam
, sizeof(vport
->fc_sparam
));
459 lpfc_reg_vfi(mboxq
, vport
, dmabuf
->phys
);
460 mboxq
->mbox_cmpl
= lpfc_mbx_cmpl_reg_vfi
;
461 mboxq
->vport
= vport
;
462 mboxq
->context1
= dmabuf
;
463 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
464 if (rc
== MBX_NOT_FINISHED
) {
471 mempool_free(mboxq
, phba
->mbox_mem_pool
);
473 lpfc_mbuf_free(phba
, dmabuf
->virt
, dmabuf
->phys
);
477 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
478 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
479 "0289 Issue Register VFI failed: Err %d\n", rc
);
484 * lpfc_cmpl_els_flogi_fabric - Completion function for flogi to a fabric port
485 * @vport: pointer to a host virtual N_Port data structure.
486 * @ndlp: pointer to a node-list data structure.
487 * @sp: pointer to service parameter data structure.
488 * @irsp: pointer to the IOCB within the lpfc response IOCB.
490 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
491 * function to handle the completion of a Fabric Login (FLOGI) into a fabric
492 * port in a fabric topology. It properly sets up the parameters to the @ndlp
493 * from the IOCB response. It also check the newly assigned N_Port ID to the
494 * @vport against the previously assigned N_Port ID. If it is different from
495 * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine
496 * is invoked on all the remaining nodes with the @vport to unregister the
497 * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin()
498 * is invoked to register login to the fabric.
501 * 0 - Success (currently, always return 0)
504 lpfc_cmpl_els_flogi_fabric(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
505 struct serv_parm
*sp
, IOCB_t
*irsp
)
507 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
508 struct lpfc_hba
*phba
= vport
->phba
;
509 struct lpfc_nodelist
*np
;
510 struct lpfc_nodelist
*next_np
;
512 spin_lock_irq(shost
->host_lock
);
513 vport
->fc_flag
|= FC_FABRIC
;
514 spin_unlock_irq(shost
->host_lock
);
516 phba
->fc_edtov
= be32_to_cpu(sp
->cmn
.e_d_tov
);
517 if (sp
->cmn
.edtovResolution
) /* E_D_TOV ticks are in nanoseconds */
518 phba
->fc_edtov
= (phba
->fc_edtov
+ 999999) / 1000000;
520 phba
->fc_ratov
= (be32_to_cpu(sp
->cmn
.w2
.r_a_tov
) + 999) / 1000;
522 if (phba
->fc_topology
== TOPOLOGY_LOOP
) {
523 spin_lock_irq(shost
->host_lock
);
524 vport
->fc_flag
|= FC_PUBLIC_LOOP
;
525 spin_unlock_irq(shost
->host_lock
);
528 * If we are a N-port connected to a Fabric, fixup sparam's so
529 * logins to devices on remote loops work.
531 vport
->fc_sparam
.cmn
.altBbCredit
= 1;
534 vport
->fc_myDID
= irsp
->un
.ulpWord
[4] & Mask_DID
;
535 memcpy(&ndlp
->nlp_portname
, &sp
->portName
, sizeof(struct lpfc_name
));
536 memcpy(&ndlp
->nlp_nodename
, &sp
->nodeName
, sizeof(struct lpfc_name
));
537 ndlp
->nlp_class_sup
= 0;
538 if (sp
->cls1
.classValid
)
539 ndlp
->nlp_class_sup
|= FC_COS_CLASS1
;
540 if (sp
->cls2
.classValid
)
541 ndlp
->nlp_class_sup
|= FC_COS_CLASS2
;
542 if (sp
->cls3
.classValid
)
543 ndlp
->nlp_class_sup
|= FC_COS_CLASS3
;
544 if (sp
->cls4
.classValid
)
545 ndlp
->nlp_class_sup
|= FC_COS_CLASS4
;
546 ndlp
->nlp_maxframe
= ((sp
->cmn
.bbRcvSizeMsb
& 0x0F) << 8) |
547 sp
->cmn
.bbRcvSizeLsb
;
548 memcpy(&phba
->fc_fabparam
, sp
, sizeof(struct serv_parm
));
550 if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) {
551 if (sp
->cmn
.response_multiple_NPort
) {
552 lpfc_printf_vlog(vport
, KERN_WARNING
,
554 "1816 FLOGI NPIV supported, "
555 "response data 0x%x\n",
556 sp
->cmn
.response_multiple_NPort
);
557 phba
->link_flag
|= LS_NPIV_FAB_SUPPORTED
;
559 /* Because we asked f/w for NPIV it still expects us
560 to call reg_vnpid atleast for the physcial host */
561 lpfc_printf_vlog(vport
, KERN_WARNING
,
563 "1817 Fabric does not support NPIV "
564 "- configuring single port mode.\n");
565 phba
->link_flag
&= ~LS_NPIV_FAB_SUPPORTED
;
569 if ((vport
->fc_prevDID
!= vport
->fc_myDID
) &&
570 !(vport
->fc_flag
& FC_VPORT_NEEDS_REG_VPI
)) {
572 /* If our NportID changed, we need to ensure all
573 * remaining NPORTs get unreg_login'ed.
575 list_for_each_entry_safe(np
, next_np
,
576 &vport
->fc_nodes
, nlp_listp
) {
577 if (!NLP_CHK_NODE_ACT(np
))
579 if ((np
->nlp_state
!= NLP_STE_NPR_NODE
) ||
580 !(np
->nlp_flag
& NLP_NPR_ADISC
))
582 spin_lock_irq(shost
->host_lock
);
583 np
->nlp_flag
&= ~NLP_NPR_ADISC
;
584 spin_unlock_irq(shost
->host_lock
);
585 lpfc_unreg_rpi(vport
, np
);
587 lpfc_cleanup_pending_mbox(vport
);
588 if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) {
589 lpfc_mbx_unreg_vpi(vport
);
590 spin_lock_irq(shost
->host_lock
);
591 vport
->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
592 spin_unlock_irq(shost
->host_lock
);
595 * If VPI is unreged, driver need to do INIT_VPI
596 * before re-registering
598 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
599 spin_lock_irq(shost
->host_lock
);
600 vport
->fc_flag
|= FC_VPORT_NEEDS_INIT_VPI
;
601 spin_unlock_irq(shost
->host_lock
);
605 if (phba
->sli_rev
< LPFC_SLI_REV4
) {
606 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_REG_LOGIN_ISSUE
);
607 if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
&&
608 vport
->fc_flag
& FC_VPORT_NEEDS_REG_VPI
)
609 lpfc_register_new_vport(phba
, vport
, ndlp
);
611 lpfc_issue_fabric_reglogin(vport
);
613 ndlp
->nlp_type
|= NLP_FABRIC
;
614 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
615 if ((!(vport
->fc_flag
& FC_VPORT_NEEDS_REG_VPI
)) &&
616 (vport
->vpi_state
& LPFC_VPI_REGISTERED
)) {
617 lpfc_start_fdiscs(phba
);
618 lpfc_do_scr_ns_plogi(phba
, vport
);
619 } else if (vport
->fc_flag
& FC_VFI_REGISTERED
)
620 lpfc_issue_init_vpi(vport
);
622 lpfc_issue_reg_vfi(vport
);
627 * lpfc_cmpl_els_flogi_nport - Completion function for flogi to an N_Port
628 * @vport: pointer to a host virtual N_Port data structure.
629 * @ndlp: pointer to a node-list data structure.
630 * @sp: pointer to service parameter data structure.
632 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
633 * function to handle the completion of a Fabric Login (FLOGI) into an N_Port
634 * in a point-to-point topology. First, the @vport's N_Port Name is compared
635 * with the received N_Port Name: if the @vport's N_Port Name is greater than
636 * the received N_Port Name lexicographically, this node shall assign local
637 * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and
638 * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise,
639 * this node shall just wait for the remote node to issue PLOGI and assign
647 lpfc_cmpl_els_flogi_nport(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
648 struct serv_parm
*sp
)
650 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
651 struct lpfc_hba
*phba
= vport
->phba
;
655 spin_lock_irq(shost
->host_lock
);
656 vport
->fc_flag
&= ~(FC_FABRIC
| FC_PUBLIC_LOOP
);
657 spin_unlock_irq(shost
->host_lock
);
659 phba
->fc_edtov
= FF_DEF_EDTOV
;
660 phba
->fc_ratov
= FF_DEF_RATOV
;
661 rc
= memcmp(&vport
->fc_portname
, &sp
->portName
,
662 sizeof(vport
->fc_portname
));
664 /* This side will initiate the PLOGI */
665 spin_lock_irq(shost
->host_lock
);
666 vport
->fc_flag
|= FC_PT2PT_PLOGI
;
667 spin_unlock_irq(shost
->host_lock
);
670 * N_Port ID cannot be 0, set our to LocalID the other
671 * side will be RemoteID.
676 vport
->fc_myDID
= PT2PT_LocalID
;
678 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
682 lpfc_config_link(phba
, mbox
);
684 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
686 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
687 if (rc
== MBX_NOT_FINISHED
) {
688 mempool_free(mbox
, phba
->mbox_mem_pool
);
691 /* Decrement ndlp reference count indicating that ndlp can be
692 * safely released when other references to it are done.
696 ndlp
= lpfc_findnode_did(vport
, PT2PT_RemoteID
);
699 * Cannot find existing Fabric ndlp, so allocate a
702 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
705 lpfc_nlp_init(vport
, ndlp
, PT2PT_RemoteID
);
706 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
707 ndlp
= lpfc_enable_node(vport
, ndlp
,
708 NLP_STE_UNUSED_NODE
);
713 memcpy(&ndlp
->nlp_portname
, &sp
->portName
,
714 sizeof(struct lpfc_name
));
715 memcpy(&ndlp
->nlp_nodename
, &sp
->nodeName
,
716 sizeof(struct lpfc_name
));
717 /* Set state will put ndlp onto node list if not already done */
718 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
719 spin_lock_irq(shost
->host_lock
);
720 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
721 spin_unlock_irq(shost
->host_lock
);
723 /* This side will wait for the PLOGI, decrement ndlp reference
724 * count indicating that ndlp can be released when other
725 * references to it are done.
729 /* If we are pt2pt with another NPort, force NPIV off! */
730 phba
->sli3_options
&= ~LPFC_SLI3_NPIV_ENABLED
;
732 spin_lock_irq(shost
->host_lock
);
733 vport
->fc_flag
|= FC_PT2PT
;
734 spin_unlock_irq(shost
->host_lock
);
736 /* Start discovery - this should just do CLEAR_LA */
737 lpfc_disc_start(vport
);
744 * lpfc_cmpl_els_flogi - Completion callback function for flogi
745 * @phba: pointer to lpfc hba data structure.
746 * @cmdiocb: pointer to lpfc command iocb data structure.
747 * @rspiocb: pointer to lpfc response iocb data structure.
749 * This routine is the top-level completion callback function for issuing
750 * a Fabric Login (FLOGI) command. If the response IOCB reported error,
751 * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If
752 * retry has been made (either immediately or delayed with lpfc_els_retry()
753 * returning 1), the command IOCB will be released and function returned.
754 * If the retry attempt has been given up (possibly reach the maximum
755 * number of retries), one additional decrement of ndlp reference shall be
756 * invoked before going out after releasing the command IOCB. This will
757 * actually release the remote node (Note, lpfc_els_free_iocb() will also
758 * invoke one decrement of ndlp reference count). If no error reported in
759 * the IOCB status, the command Port ID field is used to determine whether
760 * this is a point-to-point topology or a fabric topology: if the Port ID
761 * field is assigned, it is a fabric topology; otherwise, it is a
762 * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or
763 * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the
764 * specific topology completion conditions.
767 lpfc_cmpl_els_flogi(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
768 struct lpfc_iocbq
*rspiocb
)
770 struct lpfc_vport
*vport
= cmdiocb
->vport
;
771 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
772 IOCB_t
*irsp
= &rspiocb
->iocb
;
773 struct lpfc_nodelist
*ndlp
= cmdiocb
->context1
;
774 struct lpfc_dmabuf
*pcmd
= cmdiocb
->context2
, *prsp
;
775 struct serv_parm
*sp
;
779 /* Check to see if link went down during discovery */
780 if (lpfc_els_chk_latt(vport
)) {
781 /* One additional decrement on node reference count to
782 * trigger the release of the node
788 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
789 "FLOGI cmpl: status:x%x/x%x state:x%x",
790 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
793 if (irsp
->ulpStatus
) {
795 * In case of FIP mode, perform round robin FCF failover
796 * due to new FCF discovery
798 if ((phba
->hba_flag
& HBA_FIP_SUPPORT
) &&
799 (phba
->fcf
.fcf_flag
& FCF_DISCOVERY
)) {
800 lpfc_printf_log(phba
, KERN_WARNING
, LOG_FIP
| LOG_ELS
,
801 "2611 FLOGI failed on registered "
802 "FCF record fcf_index:%d, trying "
803 "to perform round robin failover\n",
804 phba
->fcf
.current_rec
.fcf_indx
);
805 fcf_index
= lpfc_sli4_fcf_rr_next_index_get(phba
);
806 if (fcf_index
== LPFC_FCOE_FCF_NEXT_NONE
) {
808 * Exhausted the eligible FCF record list,
809 * fail through to retry FLOGI on current
812 lpfc_printf_log(phba
, KERN_WARNING
,
814 "2760 FLOGI exhausted FCF "
815 "round robin failover list, "
816 "retry FLOGI on the current "
817 "registered FCF index:%d\n",
818 phba
->fcf
.current_rec
.fcf_indx
);
819 spin_lock_irq(&phba
->hbalock
);
820 phba
->fcf
.fcf_flag
&= ~FCF_DISCOVERY
;
821 spin_unlock_irq(&phba
->hbalock
);
823 rc
= lpfc_sli4_fcf_rr_read_fcf_rec(phba
,
826 lpfc_printf_log(phba
, KERN_WARNING
,
829 "robin FCF failover "
833 phba
->fcf
.current_rec
.fcf_indx
);
834 spin_lock_irq(&phba
->hbalock
);
835 phba
->fcf
.fcf_flag
&= ~FCF_DISCOVERY
;
836 spin_unlock_irq(&phba
->hbalock
);
842 /* Check for retry */
843 if (lpfc_els_retry(phba
, cmdiocb
, rspiocb
))
846 /* FLOGI failed, so there is no fabric */
847 spin_lock_irq(shost
->host_lock
);
848 vport
->fc_flag
&= ~(FC_FABRIC
| FC_PUBLIC_LOOP
);
849 spin_unlock_irq(shost
->host_lock
);
851 /* If private loop, then allow max outstanding els to be
852 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
853 * alpa map would take too long otherwise.
855 if (phba
->alpa_map
[0] == 0) {
856 vport
->cfg_discovery_threads
= LPFC_MAX_DISC_THREADS
;
860 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
861 "0100 FLOGI failure Status:x%x/x%x TMO:x%x\n",
862 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
866 spin_lock_irq(shost
->host_lock
);
867 vport
->fc_flag
&= ~FC_VPORT_CVL_RCVD
;
868 vport
->fc_flag
&= ~FC_VPORT_LOGO_RCVD
;
869 spin_unlock_irq(shost
->host_lock
);
872 * The FLogI succeeded. Sync the data for the CPU before
875 prsp
= list_get_first(&pcmd
->list
, struct lpfc_dmabuf
, list
);
877 sp
= prsp
->virt
+ sizeof(uint32_t);
879 /* FLOGI completes successfully */
880 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
881 "0101 FLOGI completes successfully "
882 "Data: x%x x%x x%x x%x\n",
883 irsp
->un
.ulpWord
[4], sp
->cmn
.e_d_tov
,
884 sp
->cmn
.w2
.r_a_tov
, sp
->cmn
.edtovResolution
);
886 if (vport
->port_state
== LPFC_FLOGI
) {
888 * If Common Service Parameters indicate Nport
889 * we are point to point, if Fport we are Fabric.
892 rc
= lpfc_cmpl_els_flogi_fabric(vport
, ndlp
, sp
, irsp
);
894 rc
= lpfc_cmpl_els_flogi_nport(vport
, ndlp
, sp
);
897 /* Mark the FCF discovery process done */
898 if (phba
->hba_flag
& HBA_FIP_SUPPORT
)
899 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_FIP
|
901 "2769 FLOGI successful on FCF "
902 "record: current_fcf_index:"
903 "x%x, terminate FCF round "
904 "robin failover process\n",
905 phba
->fcf
.current_rec
.fcf_indx
);
906 spin_lock_irq(&phba
->hbalock
);
907 phba
->fcf
.fcf_flag
&= ~FCF_DISCOVERY
;
908 spin_unlock_irq(&phba
->hbalock
);
916 if (!lpfc_error_lost_link(irsp
)) {
917 /* FLOGI failed, so just use loop map to make discovery list */
918 lpfc_disc_list_loopmap(vport
);
920 /* Start discovery */
921 lpfc_disc_start(vport
);
922 } else if (((irsp
->ulpStatus
!= IOSTAT_LOCAL_REJECT
) ||
923 ((irsp
->un
.ulpWord
[4] != IOERR_SLI_ABORTED
) &&
924 (irsp
->un
.ulpWord
[4] != IOERR_SLI_DOWN
))) &&
925 (phba
->link_state
!= LPFC_CLEAR_LA
)) {
926 /* If FLOGI failed enable link interrupt. */
927 lpfc_issue_clear_la(phba
, vport
);
930 lpfc_els_free_iocb(phba
, cmdiocb
);
934 * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport
935 * @vport: pointer to a host virtual N_Port data structure.
936 * @ndlp: pointer to a node-list data structure.
937 * @retry: number of retries to the command IOCB.
939 * This routine issues a Fabric Login (FLOGI) Request ELS command
940 * for a @vport. The initiator service parameters are put into the payload
941 * of the FLOGI Request IOCB and the top-level callback function pointer
942 * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
943 * function field. The lpfc_issue_fabric_iocb routine is invoked to send
944 * out FLOGI ELS command with one outstanding fabric IOCB at a time.
946 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
947 * will be incremented by 1 for holding the ndlp and the reference to ndlp
948 * will be stored into the context1 field of the IOCB for the completion
949 * callback function to the FLOGI ELS command.
952 * 0 - successfully issued flogi iocb for @vport
953 * 1 - failed to issue flogi iocb for @vport
956 lpfc_issue_els_flogi(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
959 struct lpfc_hba
*phba
= vport
->phba
;
960 struct serv_parm
*sp
;
962 struct lpfc_iocbq
*elsiocb
;
963 struct lpfc_sli_ring
*pring
;
969 pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
971 cmdsize
= (sizeof(uint32_t) + sizeof(struct serv_parm
));
972 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
,
973 ndlp
->nlp_DID
, ELS_CMD_FLOGI
);
978 icmd
= &elsiocb
->iocb
;
979 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
981 /* For FLOGI request, remainder of payload is service parameters */
982 *((uint32_t *) (pcmd
)) = ELS_CMD_FLOGI
;
983 pcmd
+= sizeof(uint32_t);
984 memcpy(pcmd
, &vport
->fc_sparam
, sizeof(struct serv_parm
));
985 sp
= (struct serv_parm
*) pcmd
;
987 /* Setup CSPs accordingly for Fabric */
989 sp
->cmn
.w2
.r_a_tov
= 0;
990 sp
->cls1
.classValid
= 0;
991 sp
->cls2
.seqDelivery
= 1;
992 sp
->cls3
.seqDelivery
= 1;
993 if (sp
->cmn
.fcphLow
< FC_PH3
)
994 sp
->cmn
.fcphLow
= FC_PH3
;
995 if (sp
->cmn
.fcphHigh
< FC_PH3
)
996 sp
->cmn
.fcphHigh
= FC_PH3
;
998 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
999 elsiocb
->iocb
.ulpCt_h
= ((SLI4_CT_FCFI
>> 1) & 1);
1000 elsiocb
->iocb
.ulpCt_l
= (SLI4_CT_FCFI
& 1);
1001 /* FLOGI needs to be 3 for WQE FCFI */
1002 /* Set the fcfi to the fcfi we registered with */
1003 elsiocb
->iocb
.ulpContext
= phba
->fcf
.fcfi
;
1004 } else if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) {
1005 sp
->cmn
.request_multiple_Nport
= 1;
1006 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
1011 if (phba
->fc_topology
!= TOPOLOGY_LOOP
) {
1012 icmd
->un
.elsreq64
.myID
= 0;
1013 icmd
->un
.elsreq64
.fl
= 1;
1016 tmo
= phba
->fc_ratov
;
1017 phba
->fc_ratov
= LPFC_DISC_FLOGI_TMO
;
1018 lpfc_set_disctmo(vport
);
1019 phba
->fc_ratov
= tmo
;
1021 phba
->fc_stat
.elsXmitFLOGI
++;
1022 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_flogi
;
1024 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
1025 "Issue FLOGI: opt:x%x",
1026 phba
->sli3_options
, 0, 0);
1028 rc
= lpfc_issue_fabric_iocb(phba
, elsiocb
);
1029 if (rc
== IOCB_ERROR
) {
1030 lpfc_els_free_iocb(phba
, elsiocb
);
1037 * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs
1038 * @phba: pointer to lpfc hba data structure.
1040 * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
1041 * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
1042 * list and issues an abort IOCB commond on each outstanding IOCB that
1043 * contains a active Fabric_DID ndlp. Note that this function is to issue
1044 * the abort IOCB command on all the outstanding IOCBs, thus when this
1045 * function returns, it does not guarantee all the IOCBs are actually aborted.
1048 * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0)
1051 lpfc_els_abort_flogi(struct lpfc_hba
*phba
)
1053 struct lpfc_sli_ring
*pring
;
1054 struct lpfc_iocbq
*iocb
, *next_iocb
;
1055 struct lpfc_nodelist
*ndlp
;
1058 /* Abort outstanding I/O on NPort <nlp_DID> */
1059 lpfc_printf_log(phba
, KERN_INFO
, LOG_DISCOVERY
,
1060 "0201 Abort outstanding I/O on NPort x%x\n",
1063 pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
1066 * Check the txcmplq for an iocb that matches the nport the driver is
1069 spin_lock_irq(&phba
->hbalock
);
1070 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txcmplq
, list
) {
1072 if (icmd
->ulpCommand
== CMD_ELS_REQUEST64_CR
&&
1073 icmd
->un
.elsreq64
.bdl
.ulpIoTag32
) {
1074 ndlp
= (struct lpfc_nodelist
*)(iocb
->context1
);
1075 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
) &&
1076 (ndlp
->nlp_DID
== Fabric_DID
))
1077 lpfc_sli_issue_abort_iotag(phba
, pring
, iocb
);
1080 spin_unlock_irq(&phba
->hbalock
);
1086 * lpfc_initial_flogi - Issue an initial fabric login for a vport
1087 * @vport: pointer to a host virtual N_Port data structure.
1089 * This routine issues an initial Fabric Login (FLOGI) for the @vport
1090 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1091 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1092 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1093 * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
1094 * is then invoked with the @vport and the ndlp to perform the FLOGI for the
1098 * 0 - failed to issue initial flogi for @vport
1099 * 1 - successfully issued initial flogi for @vport
1102 lpfc_initial_flogi(struct lpfc_vport
*vport
)
1104 struct lpfc_hba
*phba
= vport
->phba
;
1105 struct lpfc_nodelist
*ndlp
;
1107 vport
->port_state
= LPFC_FLOGI
;
1108 lpfc_set_disctmo(vport
);
1110 /* First look for the Fabric ndlp */
1111 ndlp
= lpfc_findnode_did(vport
, Fabric_DID
);
1113 /* Cannot find existing Fabric ndlp, so allocate a new one */
1114 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
1117 lpfc_nlp_init(vport
, ndlp
, Fabric_DID
);
1118 /* Set the node type */
1119 ndlp
->nlp_type
|= NLP_FABRIC
;
1120 /* Put ndlp onto node list */
1121 lpfc_enqueue_node(vport
, ndlp
);
1122 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
1123 /* re-setup ndlp without removing from node list */
1124 ndlp
= lpfc_enable_node(vport
, ndlp
, NLP_STE_UNUSED_NODE
);
1129 if (lpfc_issue_els_flogi(vport
, ndlp
, 0))
1130 /* This decrement of reference count to node shall kick off
1131 * the release of the node.
1139 * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport
1140 * @vport: pointer to a host virtual N_Port data structure.
1142 * This routine issues an initial Fabric Discover (FDISC) for the @vport
1143 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1144 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1145 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1146 * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
1147 * is then invoked with the @vport and the ndlp to perform the FDISC for the
1151 * 0 - failed to issue initial fdisc for @vport
1152 * 1 - successfully issued initial fdisc for @vport
1155 lpfc_initial_fdisc(struct lpfc_vport
*vport
)
1157 struct lpfc_hba
*phba
= vport
->phba
;
1158 struct lpfc_nodelist
*ndlp
;
1160 /* First look for the Fabric ndlp */
1161 ndlp
= lpfc_findnode_did(vport
, Fabric_DID
);
1163 /* Cannot find existing Fabric ndlp, so allocate a new one */
1164 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
1167 lpfc_nlp_init(vport
, ndlp
, Fabric_DID
);
1168 /* Put ndlp onto node list */
1169 lpfc_enqueue_node(vport
, ndlp
);
1170 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
1171 /* re-setup ndlp without removing from node list */
1172 ndlp
= lpfc_enable_node(vport
, ndlp
, NLP_STE_UNUSED_NODE
);
1177 if (lpfc_issue_els_fdisc(vport
, ndlp
, 0)) {
1178 /* decrement node reference count to trigger the release of
1188 * lpfc_more_plogi - Check and issue remaining plogis for a vport
1189 * @vport: pointer to a host virtual N_Port data structure.
1191 * This routine checks whether there are more remaining Port Logins
1192 * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
1193 * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
1194 * to issue ELS PLOGIs up to the configured discover threads with the
1195 * @vport (@vport->cfg_discovery_threads). The function also decrement
1196 * the @vport's num_disc_node by 1 if it is not already 0.
1199 lpfc_more_plogi(struct lpfc_vport
*vport
)
1203 if (vport
->num_disc_nodes
)
1204 vport
->num_disc_nodes
--;
1206 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
1207 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
1208 "0232 Continue discovery with %d PLOGIs to go "
1209 "Data: x%x x%x x%x\n",
1210 vport
->num_disc_nodes
, vport
->fc_plogi_cnt
,
1211 vport
->fc_flag
, vport
->port_state
);
1212 /* Check to see if there are more PLOGIs to be sent */
1213 if (vport
->fc_flag
& FC_NLP_MORE
)
1214 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
1215 sentplogi
= lpfc_els_disc_plogi(vport
);
1221 * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp
1222 * @phba: pointer to lpfc hba data structure.
1223 * @prsp: pointer to response IOCB payload.
1224 * @ndlp: pointer to a node-list data structure.
1226 * This routine checks and indicates whether the WWPN of an N_Port, retrieved
1227 * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
1228 * The following cases are considered N_Port confirmed:
1229 * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
1230 * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
1231 * it does not have WWPN assigned either. If the WWPN is confirmed, the
1232 * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
1233 * 1) if there is a node on vport list other than the @ndlp with the same
1234 * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
1235 * on that node to release the RPI associated with the node; 2) if there is
1236 * no node found on vport list with the same WWPN of the N_Port PLOGI logged
1237 * into, a new node shall be allocated (or activated). In either case, the
1238 * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
1239 * be released and the new_ndlp shall be put on to the vport node list and
1240 * its pointer returned as the confirmed node.
1242 * Note that before the @ndlp got "released", the keepDID from not-matching
1243 * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
1244 * of the @ndlp. This is because the release of @ndlp is actually to put it
1245 * into an inactive state on the vport node list and the vport node list
1246 * management algorithm does not allow two node with a same DID.
1249 * pointer to the PLOGI N_Port @ndlp
1251 static struct lpfc_nodelist
*
1252 lpfc_plogi_confirm_nport(struct lpfc_hba
*phba
, uint32_t *prsp
,
1253 struct lpfc_nodelist
*ndlp
)
1255 struct lpfc_vport
*vport
= ndlp
->vport
;
1256 struct lpfc_nodelist
*new_ndlp
;
1257 struct lpfc_rport_data
*rdata
;
1258 struct fc_rport
*rport
;
1259 struct serv_parm
*sp
;
1260 uint8_t name
[sizeof(struct lpfc_name
)];
1261 uint32_t rc
, keepDID
= 0;
1263 /* Fabric nodes can have the same WWPN so we don't bother searching
1264 * by WWPN. Just return the ndlp that was given to us.
1266 if (ndlp
->nlp_type
& NLP_FABRIC
)
1269 sp
= (struct serv_parm
*) ((uint8_t *) prsp
+ sizeof(uint32_t));
1270 memset(name
, 0, sizeof(struct lpfc_name
));
1272 /* Now we find out if the NPort we are logging into, matches the WWPN
1273 * we have for that ndlp. If not, we have some work to do.
1275 new_ndlp
= lpfc_findnode_wwpn(vport
, &sp
->portName
);
1277 if (new_ndlp
== ndlp
&& NLP_CHK_NODE_ACT(new_ndlp
))
1281 rc
= memcmp(&ndlp
->nlp_portname
, name
,
1282 sizeof(struct lpfc_name
));
1285 new_ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_ATOMIC
);
1288 lpfc_nlp_init(vport
, new_ndlp
, ndlp
->nlp_DID
);
1289 } else if (!NLP_CHK_NODE_ACT(new_ndlp
)) {
1290 rc
= memcmp(&ndlp
->nlp_portname
, name
,
1291 sizeof(struct lpfc_name
));
1294 new_ndlp
= lpfc_enable_node(vport
, new_ndlp
,
1295 NLP_STE_UNUSED_NODE
);
1298 keepDID
= new_ndlp
->nlp_DID
;
1300 keepDID
= new_ndlp
->nlp_DID
;
1302 lpfc_unreg_rpi(vport
, new_ndlp
);
1303 new_ndlp
->nlp_DID
= ndlp
->nlp_DID
;
1304 new_ndlp
->nlp_prev_state
= ndlp
->nlp_prev_state
;
1306 if (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
)
1307 new_ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
1308 ndlp
->nlp_flag
&= ~NLP_NPR_2B_DISC
;
1310 /* Set state will put new_ndlp on to node list if not already done */
1311 lpfc_nlp_set_state(vport
, new_ndlp
, ndlp
->nlp_state
);
1313 /* Move this back to NPR state */
1314 if (memcmp(&ndlp
->nlp_portname
, name
, sizeof(struct lpfc_name
)) == 0) {
1315 /* The new_ndlp is replacing ndlp totally, so we need
1316 * to put ndlp on UNUSED list and try to free it.
1319 /* Fix up the rport accordingly */
1320 rport
= ndlp
->rport
;
1322 rdata
= rport
->dd_data
;
1323 if (rdata
->pnode
== ndlp
) {
1326 rdata
->pnode
= lpfc_nlp_get(new_ndlp
);
1327 new_ndlp
->rport
= rport
;
1329 new_ndlp
->nlp_type
= ndlp
->nlp_type
;
1331 /* We shall actually free the ndlp with both nlp_DID and
1332 * nlp_portname fields equals 0 to avoid any ndlp on the
1333 * nodelist never to be used.
1335 if (ndlp
->nlp_DID
== 0) {
1336 spin_lock_irq(&phba
->ndlp_lock
);
1337 NLP_SET_FREE_REQ(ndlp
);
1338 spin_unlock_irq(&phba
->ndlp_lock
);
1341 /* Two ndlps cannot have the same did on the nodelist */
1342 ndlp
->nlp_DID
= keepDID
;
1343 lpfc_drop_node(vport
, ndlp
);
1346 lpfc_unreg_rpi(vport
, ndlp
);
1347 /* Two ndlps cannot have the same did */
1348 ndlp
->nlp_DID
= keepDID
;
1349 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
1355 * lpfc_end_rscn - Check and handle more rscn for a vport
1356 * @vport: pointer to a host virtual N_Port data structure.
1358 * This routine checks whether more Registration State Change
1359 * Notifications (RSCNs) came in while the discovery state machine was in
1360 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1361 * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1362 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1363 * handling the RSCNs.
1366 lpfc_end_rscn(struct lpfc_vport
*vport
)
1368 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1370 if (vport
->fc_flag
& FC_RSCN_MODE
) {
1372 * Check to see if more RSCNs came in while we were
1373 * processing this one.
1375 if (vport
->fc_rscn_id_cnt
||
1376 (vport
->fc_flag
& FC_RSCN_DISCOVERY
) != 0)
1377 lpfc_els_handle_rscn(vport
);
1379 spin_lock_irq(shost
->host_lock
);
1380 vport
->fc_flag
&= ~FC_RSCN_MODE
;
1381 spin_unlock_irq(shost
->host_lock
);
1387 * lpfc_cmpl_els_plogi - Completion callback function for plogi
1388 * @phba: pointer to lpfc hba data structure.
1389 * @cmdiocb: pointer to lpfc command iocb data structure.
1390 * @rspiocb: pointer to lpfc response iocb data structure.
1392 * This routine is the completion callback function for issuing the Port
1393 * Login (PLOGI) command. For PLOGI completion, there must be an active
1394 * ndlp on the vport node list that matches the remote node ID from the
1395 * PLOGI reponse IOCB. If such ndlp does not exist, the PLOGI is simply
1396 * ignored and command IOCB released. The PLOGI response IOCB status is
1397 * checked for error conditons. If there is error status reported, PLOGI
1398 * retry shall be attempted by invoking the lpfc_els_retry() routine.
1399 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1400 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1401 * (DSM) is set for this PLOGI completion. Finally, it checks whether
1402 * there are additional N_Port nodes with the vport that need to perform
1403 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
1407 lpfc_cmpl_els_plogi(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
1408 struct lpfc_iocbq
*rspiocb
)
1410 struct lpfc_vport
*vport
= cmdiocb
->vport
;
1411 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1413 struct lpfc_nodelist
*ndlp
;
1414 struct lpfc_dmabuf
*prsp
;
1415 int disc
, rc
, did
, type
;
1417 /* we pass cmdiocb to state machine which needs rspiocb as well */
1418 cmdiocb
->context_un
.rsp_iocb
= rspiocb
;
1420 irsp
= &rspiocb
->iocb
;
1421 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
1422 "PLOGI cmpl: status:x%x/x%x did:x%x",
1423 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1424 irsp
->un
.elsreq64
.remoteID
);
1426 ndlp
= lpfc_findnode_did(vport
, irsp
->un
.elsreq64
.remoteID
);
1427 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
)) {
1428 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
1429 "0136 PLOGI completes to NPort x%x "
1430 "with no ndlp. Data: x%x x%x x%x\n",
1431 irsp
->un
.elsreq64
.remoteID
,
1432 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1437 /* Since ndlp can be freed in the disc state machine, note if this node
1438 * is being used during discovery.
1440 spin_lock_irq(shost
->host_lock
);
1441 disc
= (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
);
1442 ndlp
->nlp_flag
&= ~NLP_NPR_2B_DISC
;
1443 spin_unlock_irq(shost
->host_lock
);
1446 /* PLOGI completes to NPort <nlp_DID> */
1447 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
1448 "0102 PLOGI completes to NPort x%x "
1449 "Data: x%x x%x x%x x%x x%x\n",
1450 ndlp
->nlp_DID
, irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1451 irsp
->ulpTimeout
, disc
, vport
->num_disc_nodes
);
1452 /* Check to see if link went down during discovery */
1453 if (lpfc_els_chk_latt(vport
)) {
1454 spin_lock_irq(shost
->host_lock
);
1455 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
1456 spin_unlock_irq(shost
->host_lock
);
1460 /* ndlp could be freed in DSM, save these values now */
1461 type
= ndlp
->nlp_type
;
1462 did
= ndlp
->nlp_DID
;
1464 if (irsp
->ulpStatus
) {
1465 /* Check for retry */
1466 if (lpfc_els_retry(phba
, cmdiocb
, rspiocb
)) {
1467 /* ELS command is being retried */
1469 spin_lock_irq(shost
->host_lock
);
1470 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
1471 spin_unlock_irq(shost
->host_lock
);
1476 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
1477 "2753 PLOGI failure DID:%06X Status:x%x/x%x\n",
1478 ndlp
->nlp_DID
, irsp
->ulpStatus
,
1479 irsp
->un
.ulpWord
[4]);
1480 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1481 if (lpfc_error_lost_link(irsp
))
1482 rc
= NLP_STE_FREED_NODE
;
1484 rc
= lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
1485 NLP_EVT_CMPL_PLOGI
);
1487 /* Good status, call state machine */
1488 prsp
= list_entry(((struct lpfc_dmabuf
*)
1489 cmdiocb
->context2
)->list
.next
,
1490 struct lpfc_dmabuf
, list
);
1491 ndlp
= lpfc_plogi_confirm_nport(phba
, prsp
->virt
, ndlp
);
1492 rc
= lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
1493 NLP_EVT_CMPL_PLOGI
);
1496 if (disc
&& vport
->num_disc_nodes
) {
1497 /* Check to see if there are more PLOGIs to be sent */
1498 lpfc_more_plogi(vport
);
1500 if (vport
->num_disc_nodes
== 0) {
1501 spin_lock_irq(shost
->host_lock
);
1502 vport
->fc_flag
&= ~FC_NDISC_ACTIVE
;
1503 spin_unlock_irq(shost
->host_lock
);
1505 lpfc_can_disctmo(vport
);
1506 lpfc_end_rscn(vport
);
1511 lpfc_els_free_iocb(phba
, cmdiocb
);
1516 * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
1517 * @vport: pointer to a host virtual N_Port data structure.
1518 * @did: destination port identifier.
1519 * @retry: number of retries to the command IOCB.
1521 * This routine issues a Port Login (PLOGI) command to a remote N_Port
1522 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
1523 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
1524 * This routine constructs the proper feilds of the PLOGI IOCB and invokes
1525 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
1527 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1528 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1529 * will be stored into the context1 field of the IOCB for the completion
1530 * callback function to the PLOGI ELS command.
1533 * 0 - Successfully issued a plogi for @vport
1534 * 1 - failed to issue a plogi for @vport
1537 lpfc_issue_els_plogi(struct lpfc_vport
*vport
, uint32_t did
, uint8_t retry
)
1539 struct lpfc_hba
*phba
= vport
->phba
;
1540 struct serv_parm
*sp
;
1542 struct lpfc_nodelist
*ndlp
;
1543 struct lpfc_iocbq
*elsiocb
;
1544 struct lpfc_sli
*psli
;
1551 ndlp
= lpfc_findnode_did(vport
, did
);
1552 if (ndlp
&& !NLP_CHK_NODE_ACT(ndlp
))
1555 /* If ndlp is not NULL, we will bump the reference count on it */
1556 cmdsize
= (sizeof(uint32_t) + sizeof(struct serv_parm
));
1557 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
, did
,
1562 icmd
= &elsiocb
->iocb
;
1563 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
1565 /* For PLOGI request, remainder of payload is service parameters */
1566 *((uint32_t *) (pcmd
)) = ELS_CMD_PLOGI
;
1567 pcmd
+= sizeof(uint32_t);
1568 memcpy(pcmd
, &vport
->fc_sparam
, sizeof(struct serv_parm
));
1569 sp
= (struct serv_parm
*) pcmd
;
1571 if (sp
->cmn
.fcphLow
< FC_PH_4_3
)
1572 sp
->cmn
.fcphLow
= FC_PH_4_3
;
1574 if (sp
->cmn
.fcphHigh
< FC_PH3
)
1575 sp
->cmn
.fcphHigh
= FC_PH3
;
1577 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
1578 "Issue PLOGI: did:x%x",
1581 phba
->fc_stat
.elsXmitPLOGI
++;
1582 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_plogi
;
1583 ret
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
1585 if (ret
== IOCB_ERROR
) {
1586 lpfc_els_free_iocb(phba
, elsiocb
);
1593 * lpfc_cmpl_els_prli - Completion callback function for prli
1594 * @phba: pointer to lpfc hba data structure.
1595 * @cmdiocb: pointer to lpfc command iocb data structure.
1596 * @rspiocb: pointer to lpfc response iocb data structure.
1598 * This routine is the completion callback function for a Process Login
1599 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
1600 * status. If there is error status reported, PRLI retry shall be attempted
1601 * by invoking the lpfc_els_retry() routine. Otherwise, the state
1602 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
1603 * ndlp to mark the PRLI completion.
1606 lpfc_cmpl_els_prli(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
1607 struct lpfc_iocbq
*rspiocb
)
1609 struct lpfc_vport
*vport
= cmdiocb
->vport
;
1610 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1612 struct lpfc_sli
*psli
;
1613 struct lpfc_nodelist
*ndlp
;
1616 /* we pass cmdiocb to state machine which needs rspiocb as well */
1617 cmdiocb
->context_un
.rsp_iocb
= rspiocb
;
1619 irsp
= &(rspiocb
->iocb
);
1620 ndlp
= (struct lpfc_nodelist
*) cmdiocb
->context1
;
1621 spin_lock_irq(shost
->host_lock
);
1622 ndlp
->nlp_flag
&= ~NLP_PRLI_SND
;
1623 spin_unlock_irq(shost
->host_lock
);
1625 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
1626 "PRLI cmpl: status:x%x/x%x did:x%x",
1627 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1629 /* PRLI completes to NPort <nlp_DID> */
1630 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
1631 "0103 PRLI completes to NPort x%x "
1632 "Data: x%x x%x x%x x%x\n",
1633 ndlp
->nlp_DID
, irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1634 irsp
->ulpTimeout
, vport
->num_disc_nodes
);
1636 vport
->fc_prli_sent
--;
1637 /* Check to see if link went down during discovery */
1638 if (lpfc_els_chk_latt(vport
))
1641 if (irsp
->ulpStatus
) {
1642 /* Check for retry */
1643 if (lpfc_els_retry(phba
, cmdiocb
, rspiocb
)) {
1644 /* ELS command is being retried */
1648 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
1649 "2754 PRLI failure DID:%06X Status:x%x/x%x\n",
1650 ndlp
->nlp_DID
, irsp
->ulpStatus
,
1651 irsp
->un
.ulpWord
[4]);
1652 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1653 if (lpfc_error_lost_link(irsp
))
1656 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
1659 /* Good status, call state machine */
1660 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
1663 lpfc_els_free_iocb(phba
, cmdiocb
);
1668 * lpfc_issue_els_prli - Issue a prli iocb command for a vport
1669 * @vport: pointer to a host virtual N_Port data structure.
1670 * @ndlp: pointer to a node-list data structure.
1671 * @retry: number of retries to the command IOCB.
1673 * This routine issues a Process Login (PRLI) ELS command for the
1674 * @vport. The PRLI service parameters are set up in the payload of the
1675 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
1676 * is put to the IOCB completion callback func field before invoking the
1677 * routine lpfc_sli_issue_iocb() to send out PRLI command.
1679 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1680 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1681 * will be stored into the context1 field of the IOCB for the completion
1682 * callback function to the PRLI ELS command.
1685 * 0 - successfully issued prli iocb command for @vport
1686 * 1 - failed to issue prli iocb command for @vport
1689 lpfc_issue_els_prli(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1692 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1693 struct lpfc_hba
*phba
= vport
->phba
;
1696 struct lpfc_iocbq
*elsiocb
;
1700 cmdsize
= (sizeof(uint32_t) + sizeof(PRLI
));
1701 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
,
1702 ndlp
->nlp_DID
, ELS_CMD_PRLI
);
1706 icmd
= &elsiocb
->iocb
;
1707 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
1709 /* For PRLI request, remainder of payload is service parameters */
1710 memset(pcmd
, 0, (sizeof(PRLI
) + sizeof(uint32_t)));
1711 *((uint32_t *) (pcmd
)) = ELS_CMD_PRLI
;
1712 pcmd
+= sizeof(uint32_t);
1714 /* For PRLI, remainder of payload is PRLI parameter page */
1715 npr
= (PRLI
*) pcmd
;
1717 * If our firmware version is 3.20 or later,
1718 * set the following bits for FC-TAPE support.
1720 if (phba
->vpd
.rev
.feaLevelHigh
>= 0x02) {
1721 npr
->ConfmComplAllowed
= 1;
1723 npr
->TaskRetryIdReq
= 1;
1725 npr
->estabImagePair
= 1;
1726 npr
->readXferRdyDis
= 1;
1728 /* For FCP support */
1729 npr
->prliType
= PRLI_FCP_TYPE
;
1730 npr
->initiatorFunc
= 1;
1732 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
1733 "Issue PRLI: did:x%x",
1734 ndlp
->nlp_DID
, 0, 0);
1736 phba
->fc_stat
.elsXmitPRLI
++;
1737 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_prli
;
1738 spin_lock_irq(shost
->host_lock
);
1739 ndlp
->nlp_flag
|= NLP_PRLI_SND
;
1740 spin_unlock_irq(shost
->host_lock
);
1741 if (lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0) ==
1743 spin_lock_irq(shost
->host_lock
);
1744 ndlp
->nlp_flag
&= ~NLP_PRLI_SND
;
1745 spin_unlock_irq(shost
->host_lock
);
1746 lpfc_els_free_iocb(phba
, elsiocb
);
1749 vport
->fc_prli_sent
++;
1754 * lpfc_rscn_disc - Perform rscn discovery for a vport
1755 * @vport: pointer to a host virtual N_Port data structure.
1757 * This routine performs Registration State Change Notification (RSCN)
1758 * discovery for a @vport. If the @vport's node port recovery count is not
1759 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
1760 * the nodes that need recovery. If none of the PLOGI were needed through
1761 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
1762 * invoked to check and handle possible more RSCN came in during the period
1763 * of processing the current ones.
1766 lpfc_rscn_disc(struct lpfc_vport
*vport
)
1768 lpfc_can_disctmo(vport
);
1770 /* RSCN discovery */
1771 /* go thru NPR nodes and issue ELS PLOGIs */
1772 if (vport
->fc_npr_cnt
)
1773 if (lpfc_els_disc_plogi(vport
))
1776 lpfc_end_rscn(vport
);
1780 * lpfc_adisc_done - Complete the adisc phase of discovery
1781 * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
1783 * This function is called when the final ADISC is completed during discovery.
1784 * This function handles clearing link attention or issuing reg_vpi depending
1785 * on whether npiv is enabled. This function also kicks off the PLOGI phase of
1787 * This function is called with no locks held.
1790 lpfc_adisc_done(struct lpfc_vport
*vport
)
1792 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1793 struct lpfc_hba
*phba
= vport
->phba
;
1796 * For NPIV, cmpl_reg_vpi will set port_state to READY,
1797 * and continue discovery.
1799 if ((phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
1800 !(vport
->fc_flag
& FC_RSCN_MODE
) &&
1801 (phba
->sli_rev
< LPFC_SLI_REV4
)) {
1802 lpfc_issue_reg_vpi(phba
, vport
);
1806 * For SLI2, we need to set port_state to READY
1807 * and continue discovery.
1809 if (vport
->port_state
< LPFC_VPORT_READY
) {
1810 /* If we get here, there is nothing to ADISC */
1811 if (vport
->port_type
== LPFC_PHYSICAL_PORT
)
1812 lpfc_issue_clear_la(phba
, vport
);
1813 if (!(vport
->fc_flag
& FC_ABORT_DISCOVERY
)) {
1814 vport
->num_disc_nodes
= 0;
1815 /* go thru NPR list, issue ELS PLOGIs */
1816 if (vport
->fc_npr_cnt
)
1817 lpfc_els_disc_plogi(vport
);
1818 if (!vport
->num_disc_nodes
) {
1819 spin_lock_irq(shost
->host_lock
);
1820 vport
->fc_flag
&= ~FC_NDISC_ACTIVE
;
1821 spin_unlock_irq(shost
->host_lock
);
1822 lpfc_can_disctmo(vport
);
1823 lpfc_end_rscn(vport
);
1826 vport
->port_state
= LPFC_VPORT_READY
;
1828 lpfc_rscn_disc(vport
);
1832 * lpfc_more_adisc - Issue more adisc as needed
1833 * @vport: pointer to a host virtual N_Port data structure.
1835 * This routine determines whether there are more ndlps on a @vport
1836 * node list need to have Address Discover (ADISC) issued. If so, it will
1837 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
1838 * remaining nodes which need to have ADISC sent.
1841 lpfc_more_adisc(struct lpfc_vport
*vport
)
1845 if (vport
->num_disc_nodes
)
1846 vport
->num_disc_nodes
--;
1847 /* Continue discovery with <num_disc_nodes> ADISCs to go */
1848 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
1849 "0210 Continue discovery with %d ADISCs to go "
1850 "Data: x%x x%x x%x\n",
1851 vport
->num_disc_nodes
, vport
->fc_adisc_cnt
,
1852 vport
->fc_flag
, vport
->port_state
);
1853 /* Check to see if there are more ADISCs to be sent */
1854 if (vport
->fc_flag
& FC_NLP_MORE
) {
1855 lpfc_set_disctmo(vport
);
1856 /* go thru NPR nodes and issue any remaining ELS ADISCs */
1857 sentadisc
= lpfc_els_disc_adisc(vport
);
1859 if (!vport
->num_disc_nodes
)
1860 lpfc_adisc_done(vport
);
1865 * lpfc_cmpl_els_adisc - Completion callback function for adisc
1866 * @phba: pointer to lpfc hba data structure.
1867 * @cmdiocb: pointer to lpfc command iocb data structure.
1868 * @rspiocb: pointer to lpfc response iocb data structure.
1870 * This routine is the completion function for issuing the Address Discover
1871 * (ADISC) command. It first checks to see whether link went down during
1872 * the discovery process. If so, the node will be marked as node port
1873 * recovery for issuing discover IOCB by the link attention handler and
1874 * exit. Otherwise, the response status is checked. If error was reported
1875 * in the response status, the ADISC command shall be retried by invoking
1876 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
1877 * the response status, the state machine is invoked to set transition
1878 * with respect to NLP_EVT_CMPL_ADISC event.
1881 lpfc_cmpl_els_adisc(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
1882 struct lpfc_iocbq
*rspiocb
)
1884 struct lpfc_vport
*vport
= cmdiocb
->vport
;
1885 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1887 struct lpfc_nodelist
*ndlp
;
1890 /* we pass cmdiocb to state machine which needs rspiocb as well */
1891 cmdiocb
->context_un
.rsp_iocb
= rspiocb
;
1893 irsp
= &(rspiocb
->iocb
);
1894 ndlp
= (struct lpfc_nodelist
*) cmdiocb
->context1
;
1896 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
1897 "ADISC cmpl: status:x%x/x%x did:x%x",
1898 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1901 /* Since ndlp can be freed in the disc state machine, note if this node
1902 * is being used during discovery.
1904 spin_lock_irq(shost
->host_lock
);
1905 disc
= (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
);
1906 ndlp
->nlp_flag
&= ~(NLP_ADISC_SND
| NLP_NPR_2B_DISC
);
1907 spin_unlock_irq(shost
->host_lock
);
1908 /* ADISC completes to NPort <nlp_DID> */
1909 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
1910 "0104 ADISC completes to NPort x%x "
1911 "Data: x%x x%x x%x x%x x%x\n",
1912 ndlp
->nlp_DID
, irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1913 irsp
->ulpTimeout
, disc
, vport
->num_disc_nodes
);
1914 /* Check to see if link went down during discovery */
1915 if (lpfc_els_chk_latt(vport
)) {
1916 spin_lock_irq(shost
->host_lock
);
1917 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
1918 spin_unlock_irq(shost
->host_lock
);
1922 if (irsp
->ulpStatus
) {
1923 /* Check for retry */
1924 if (lpfc_els_retry(phba
, cmdiocb
, rspiocb
)) {
1925 /* ELS command is being retried */
1927 spin_lock_irq(shost
->host_lock
);
1928 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
1929 spin_unlock_irq(shost
->host_lock
);
1930 lpfc_set_disctmo(vport
);
1935 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
1936 "2755 ADISC failure DID:%06X Status:x%x/x%x\n",
1937 ndlp
->nlp_DID
, irsp
->ulpStatus
,
1938 irsp
->un
.ulpWord
[4]);
1939 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1940 if (!lpfc_error_lost_link(irsp
))
1941 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
1942 NLP_EVT_CMPL_ADISC
);
1944 /* Good status, call state machine */
1945 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
1946 NLP_EVT_CMPL_ADISC
);
1948 /* Check to see if there are more ADISCs to be sent */
1949 if (disc
&& vport
->num_disc_nodes
)
1950 lpfc_more_adisc(vport
);
1952 lpfc_els_free_iocb(phba
, cmdiocb
);
1957 * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
1958 * @vport: pointer to a virtual N_Port data structure.
1959 * @ndlp: pointer to a node-list data structure.
1960 * @retry: number of retries to the command IOCB.
1962 * This routine issues an Address Discover (ADISC) for an @ndlp on a
1963 * @vport. It prepares the payload of the ADISC ELS command, updates the
1964 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
1965 * to issue the ADISC ELS command.
1967 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1968 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1969 * will be stored into the context1 field of the IOCB for the completion
1970 * callback function to the ADISC ELS command.
1973 * 0 - successfully issued adisc
1974 * 1 - failed to issue adisc
1977 lpfc_issue_els_adisc(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1980 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1981 struct lpfc_hba
*phba
= vport
->phba
;
1984 struct lpfc_iocbq
*elsiocb
;
1988 cmdsize
= (sizeof(uint32_t) + sizeof(ADISC
));
1989 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
,
1990 ndlp
->nlp_DID
, ELS_CMD_ADISC
);
1994 icmd
= &elsiocb
->iocb
;
1995 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
1997 /* For ADISC request, remainder of payload is service parameters */
1998 *((uint32_t *) (pcmd
)) = ELS_CMD_ADISC
;
1999 pcmd
+= sizeof(uint32_t);
2001 /* Fill in ADISC payload */
2002 ap
= (ADISC
*) pcmd
;
2003 ap
->hardAL_PA
= phba
->fc_pref_ALPA
;
2004 memcpy(&ap
->portName
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
2005 memcpy(&ap
->nodeName
, &vport
->fc_nodename
, sizeof(struct lpfc_name
));
2006 ap
->DID
= be32_to_cpu(vport
->fc_myDID
);
2008 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
2009 "Issue ADISC: did:x%x",
2010 ndlp
->nlp_DID
, 0, 0);
2012 phba
->fc_stat
.elsXmitADISC
++;
2013 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_adisc
;
2014 spin_lock_irq(shost
->host_lock
);
2015 ndlp
->nlp_flag
|= NLP_ADISC_SND
;
2016 spin_unlock_irq(shost
->host_lock
);
2017 if (lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0) ==
2019 spin_lock_irq(shost
->host_lock
);
2020 ndlp
->nlp_flag
&= ~NLP_ADISC_SND
;
2021 spin_unlock_irq(shost
->host_lock
);
2022 lpfc_els_free_iocb(phba
, elsiocb
);
2029 * lpfc_cmpl_els_logo - Completion callback function for logo
2030 * @phba: pointer to lpfc hba data structure.
2031 * @cmdiocb: pointer to lpfc command iocb data structure.
2032 * @rspiocb: pointer to lpfc response iocb data structure.
2034 * This routine is the completion function for issuing the ELS Logout (LOGO)
2035 * command. If no error status was reported from the LOGO response, the
2036 * state machine of the associated ndlp shall be invoked for transition with
2037 * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
2038 * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
2041 lpfc_cmpl_els_logo(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
2042 struct lpfc_iocbq
*rspiocb
)
2044 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) cmdiocb
->context1
;
2045 struct lpfc_vport
*vport
= ndlp
->vport
;
2046 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2048 struct lpfc_sli
*psli
;
2051 /* we pass cmdiocb to state machine which needs rspiocb as well */
2052 cmdiocb
->context_un
.rsp_iocb
= rspiocb
;
2054 irsp
= &(rspiocb
->iocb
);
2055 spin_lock_irq(shost
->host_lock
);
2056 ndlp
->nlp_flag
&= ~NLP_LOGO_SND
;
2057 spin_unlock_irq(shost
->host_lock
);
2059 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
2060 "LOGO cmpl: status:x%x/x%x did:x%x",
2061 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
2063 /* LOGO completes to NPort <nlp_DID> */
2064 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
2065 "0105 LOGO completes to NPort x%x "
2066 "Data: x%x x%x x%x x%x\n",
2067 ndlp
->nlp_DID
, irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
2068 irsp
->ulpTimeout
, vport
->num_disc_nodes
);
2069 /* Check to see if link went down during discovery */
2070 if (lpfc_els_chk_latt(vport
))
2073 if (ndlp
->nlp_flag
& NLP_TARGET_REMOVE
) {
2074 /* NLP_EVT_DEVICE_RM should unregister the RPI
2075 * which should abort all outstanding IOs.
2077 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
2082 if (irsp
->ulpStatus
) {
2083 /* Check for retry */
2084 if (lpfc_els_retry(phba
, cmdiocb
, rspiocb
))
2085 /* ELS command is being retried */
2088 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
2089 "2756 LOGO failure DID:%06X Status:x%x/x%x\n",
2090 ndlp
->nlp_DID
, irsp
->ulpStatus
,
2091 irsp
->un
.ulpWord
[4]);
2092 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2093 if (lpfc_error_lost_link(irsp
))
2096 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
2099 /* Good status, call state machine.
2100 * This will unregister the rpi if needed.
2102 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
2105 lpfc_els_free_iocb(phba
, cmdiocb
);
2110 * lpfc_issue_els_logo - Issue a logo to an node on a vport
2111 * @vport: pointer to a virtual N_Port data structure.
2112 * @ndlp: pointer to a node-list data structure.
2113 * @retry: number of retries to the command IOCB.
2115 * This routine constructs and issues an ELS Logout (LOGO) iocb command
2116 * to a remote node, referred by an @ndlp on a @vport. It constructs the
2117 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
2118 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
2120 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2121 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2122 * will be stored into the context1 field of the IOCB for the completion
2123 * callback function to the LOGO ELS command.
2126 * 0 - successfully issued logo
2127 * 1 - failed to issue logo
2130 lpfc_issue_els_logo(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2133 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2134 struct lpfc_hba
*phba
= vport
->phba
;
2136 struct lpfc_iocbq
*elsiocb
;
2141 spin_lock_irq(shost
->host_lock
);
2142 if (ndlp
->nlp_flag
& NLP_LOGO_SND
) {
2143 spin_unlock_irq(shost
->host_lock
);
2146 spin_unlock_irq(shost
->host_lock
);
2148 cmdsize
= (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name
);
2149 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
,
2150 ndlp
->nlp_DID
, ELS_CMD_LOGO
);
2154 icmd
= &elsiocb
->iocb
;
2155 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
2156 *((uint32_t *) (pcmd
)) = ELS_CMD_LOGO
;
2157 pcmd
+= sizeof(uint32_t);
2159 /* Fill in LOGO payload */
2160 *((uint32_t *) (pcmd
)) = be32_to_cpu(vport
->fc_myDID
);
2161 pcmd
+= sizeof(uint32_t);
2162 memcpy(pcmd
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
2164 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
2165 "Issue LOGO: did:x%x",
2166 ndlp
->nlp_DID
, 0, 0);
2168 phba
->fc_stat
.elsXmitLOGO
++;
2169 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_logo
;
2170 spin_lock_irq(shost
->host_lock
);
2171 ndlp
->nlp_flag
|= NLP_LOGO_SND
;
2172 spin_unlock_irq(shost
->host_lock
);
2173 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
2175 if (rc
== IOCB_ERROR
) {
2176 spin_lock_irq(shost
->host_lock
);
2177 ndlp
->nlp_flag
&= ~NLP_LOGO_SND
;
2178 spin_unlock_irq(shost
->host_lock
);
2179 lpfc_els_free_iocb(phba
, elsiocb
);
2186 * lpfc_cmpl_els_cmd - Completion callback function for generic els command
2187 * @phba: pointer to lpfc hba data structure.
2188 * @cmdiocb: pointer to lpfc command iocb data structure.
2189 * @rspiocb: pointer to lpfc response iocb data structure.
2191 * This routine is a generic completion callback function for ELS commands.
2192 * Specifically, it is the callback function which does not need to perform
2193 * any command specific operations. It is currently used by the ELS command
2194 * issuing routines for the ELS State Change Request (SCR),
2195 * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution
2196 * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than
2197 * certain debug loggings, this callback function simply invokes the
2198 * lpfc_els_chk_latt() routine to check whether link went down during the
2199 * discovery process.
2202 lpfc_cmpl_els_cmd(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
2203 struct lpfc_iocbq
*rspiocb
)
2205 struct lpfc_vport
*vport
= cmdiocb
->vport
;
2208 irsp
= &rspiocb
->iocb
;
2210 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
2211 "ELS cmd cmpl: status:x%x/x%x did:x%x",
2212 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
2213 irsp
->un
.elsreq64
.remoteID
);
2214 /* ELS cmd tag <ulpIoTag> completes */
2215 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
2216 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
2217 irsp
->ulpIoTag
, irsp
->ulpStatus
,
2218 irsp
->un
.ulpWord
[4], irsp
->ulpTimeout
);
2219 /* Check to see if link went down during discovery */
2220 lpfc_els_chk_latt(vport
);
2221 lpfc_els_free_iocb(phba
, cmdiocb
);
2226 * lpfc_issue_els_scr - Issue a scr to an node on a vport
2227 * @vport: pointer to a host virtual N_Port data structure.
2228 * @nportid: N_Port identifier to the remote node.
2229 * @retry: number of retries to the command IOCB.
2231 * This routine issues a State Change Request (SCR) to a fabric node
2232 * on a @vport. The remote node @nportid is passed into the function. It
2233 * first search the @vport node list to find the matching ndlp. If no such
2234 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
2235 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
2236 * routine is invoked to send the SCR IOCB.
2238 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2239 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2240 * will be stored into the context1 field of the IOCB for the completion
2241 * callback function to the SCR ELS command.
2244 * 0 - Successfully issued scr command
2245 * 1 - Failed to issue scr command
2248 lpfc_issue_els_scr(struct lpfc_vport
*vport
, uint32_t nportid
, uint8_t retry
)
2250 struct lpfc_hba
*phba
= vport
->phba
;
2252 struct lpfc_iocbq
*elsiocb
;
2253 struct lpfc_sli
*psli
;
2256 struct lpfc_nodelist
*ndlp
;
2259 cmdsize
= (sizeof(uint32_t) + sizeof(SCR
));
2261 ndlp
= lpfc_findnode_did(vport
, nportid
);
2263 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
2266 lpfc_nlp_init(vport
, ndlp
, nportid
);
2267 lpfc_enqueue_node(vport
, ndlp
);
2268 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
2269 ndlp
= lpfc_enable_node(vport
, ndlp
, NLP_STE_UNUSED_NODE
);
2274 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
,
2275 ndlp
->nlp_DID
, ELS_CMD_SCR
);
2278 /* This will trigger the release of the node just
2285 icmd
= &elsiocb
->iocb
;
2286 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
2288 *((uint32_t *) (pcmd
)) = ELS_CMD_SCR
;
2289 pcmd
+= sizeof(uint32_t);
2291 /* For SCR, remainder of payload is SCR parameter page */
2292 memset(pcmd
, 0, sizeof(SCR
));
2293 ((SCR
*) pcmd
)->Function
= SCR_FUNC_FULL
;
2295 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
2296 "Issue SCR: did:x%x",
2297 ndlp
->nlp_DID
, 0, 0);
2299 phba
->fc_stat
.elsXmitSCR
++;
2300 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_cmd
;
2301 if (lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0) ==
2303 /* The additional lpfc_nlp_put will cause the following
2304 * lpfc_els_free_iocb routine to trigger the rlease of
2308 lpfc_els_free_iocb(phba
, elsiocb
);
2311 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2312 * trigger the release of node.
2319 * lpfc_issue_els_farpr - Issue a farp to an node on a vport
2320 * @vport: pointer to a host virtual N_Port data structure.
2321 * @nportid: N_Port identifier to the remote node.
2322 * @retry: number of retries to the command IOCB.
2324 * This routine issues a Fibre Channel Address Resolution Response
2325 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
2326 * is passed into the function. It first search the @vport node list to find
2327 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
2328 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
2329 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
2331 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2332 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2333 * will be stored into the context1 field of the IOCB for the completion
2334 * callback function to the PARPR ELS command.
2337 * 0 - Successfully issued farpr command
2338 * 1 - Failed to issue farpr command
2341 lpfc_issue_els_farpr(struct lpfc_vport
*vport
, uint32_t nportid
, uint8_t retry
)
2343 struct lpfc_hba
*phba
= vport
->phba
;
2345 struct lpfc_iocbq
*elsiocb
;
2346 struct lpfc_sli
*psli
;
2351 struct lpfc_nodelist
*ondlp
;
2352 struct lpfc_nodelist
*ndlp
;
2355 cmdsize
= (sizeof(uint32_t) + sizeof(FARP
));
2357 ndlp
= lpfc_findnode_did(vport
, nportid
);
2359 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
2362 lpfc_nlp_init(vport
, ndlp
, nportid
);
2363 lpfc_enqueue_node(vport
, ndlp
);
2364 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
2365 ndlp
= lpfc_enable_node(vport
, ndlp
, NLP_STE_UNUSED_NODE
);
2370 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
,
2371 ndlp
->nlp_DID
, ELS_CMD_RNID
);
2373 /* This will trigger the release of the node just
2380 icmd
= &elsiocb
->iocb
;
2381 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
2383 *((uint32_t *) (pcmd
)) = ELS_CMD_FARPR
;
2384 pcmd
+= sizeof(uint32_t);
2386 /* Fill in FARPR payload */
2387 fp
= (FARP
*) (pcmd
);
2388 memset(fp
, 0, sizeof(FARP
));
2389 lp
= (uint32_t *) pcmd
;
2390 *lp
++ = be32_to_cpu(nportid
);
2391 *lp
++ = be32_to_cpu(vport
->fc_myDID
);
2393 fp
->Mflags
= (FARP_MATCH_PORT
| FARP_MATCH_NODE
);
2395 memcpy(&fp
->RportName
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
2396 memcpy(&fp
->RnodeName
, &vport
->fc_nodename
, sizeof(struct lpfc_name
));
2397 ondlp
= lpfc_findnode_did(vport
, nportid
);
2398 if (ondlp
&& NLP_CHK_NODE_ACT(ondlp
)) {
2399 memcpy(&fp
->OportName
, &ondlp
->nlp_portname
,
2400 sizeof(struct lpfc_name
));
2401 memcpy(&fp
->OnodeName
, &ondlp
->nlp_nodename
,
2402 sizeof(struct lpfc_name
));
2405 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
2406 "Issue FARPR: did:x%x",
2407 ndlp
->nlp_DID
, 0, 0);
2409 phba
->fc_stat
.elsXmitFARPR
++;
2410 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_cmd
;
2411 if (lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0) ==
2413 /* The additional lpfc_nlp_put will cause the following
2414 * lpfc_els_free_iocb routine to trigger the release of
2418 lpfc_els_free_iocb(phba
, elsiocb
);
2421 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2422 * trigger the release of the node.
2429 * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
2430 * @vport: pointer to a host virtual N_Port data structure.
2431 * @nlp: pointer to a node-list data structure.
2433 * This routine cancels the timer with a delayed IOCB-command retry for
2434 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
2435 * removes the ELS retry event if it presents. In addition, if the
2436 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
2437 * commands are sent for the @vport's nodes that require issuing discovery
2441 lpfc_cancel_retry_delay_tmo(struct lpfc_vport
*vport
, struct lpfc_nodelist
*nlp
)
2443 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2444 struct lpfc_work_evt
*evtp
;
2446 if (!(nlp
->nlp_flag
& NLP_DELAY_TMO
))
2448 spin_lock_irq(shost
->host_lock
);
2449 nlp
->nlp_flag
&= ~NLP_DELAY_TMO
;
2450 spin_unlock_irq(shost
->host_lock
);
2451 del_timer_sync(&nlp
->nlp_delayfunc
);
2452 nlp
->nlp_last_elscmd
= 0;
2453 if (!list_empty(&nlp
->els_retry_evt
.evt_listp
)) {
2454 list_del_init(&nlp
->els_retry_evt
.evt_listp
);
2455 /* Decrement nlp reference count held for the delayed retry */
2456 evtp
= &nlp
->els_retry_evt
;
2457 lpfc_nlp_put((struct lpfc_nodelist
*)evtp
->evt_arg1
);
2459 if (nlp
->nlp_flag
& NLP_NPR_2B_DISC
) {
2460 spin_lock_irq(shost
->host_lock
);
2461 nlp
->nlp_flag
&= ~NLP_NPR_2B_DISC
;
2462 spin_unlock_irq(shost
->host_lock
);
2463 if (vport
->num_disc_nodes
) {
2464 if (vport
->port_state
< LPFC_VPORT_READY
) {
2465 /* Check if there are more ADISCs to be sent */
2466 lpfc_more_adisc(vport
);
2468 /* Check if there are more PLOGIs to be sent */
2469 lpfc_more_plogi(vport
);
2470 if (vport
->num_disc_nodes
== 0) {
2471 spin_lock_irq(shost
->host_lock
);
2472 vport
->fc_flag
&= ~FC_NDISC_ACTIVE
;
2473 spin_unlock_irq(shost
->host_lock
);
2474 lpfc_can_disctmo(vport
);
2475 lpfc_end_rscn(vport
);
2484 * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
2485 * @ptr: holder for the pointer to the timer function associated data (ndlp).
2487 * This routine is invoked by the ndlp delayed-function timer to check
2488 * whether there is any pending ELS retry event(s) with the node. If not, it
2489 * simply returns. Otherwise, if there is at least one ELS delayed event, it
2490 * adds the delayed events to the HBA work list and invokes the
2491 * lpfc_worker_wake_up() routine to wake up worker thread to process the
2492 * event. Note that lpfc_nlp_get() is called before posting the event to
2493 * the work list to hold reference count of ndlp so that it guarantees the
2494 * reference to ndlp will still be available when the worker thread gets
2495 * to the event associated with the ndlp.
2498 lpfc_els_retry_delay(unsigned long ptr
)
2500 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) ptr
;
2501 struct lpfc_vport
*vport
= ndlp
->vport
;
2502 struct lpfc_hba
*phba
= vport
->phba
;
2503 unsigned long flags
;
2504 struct lpfc_work_evt
*evtp
= &ndlp
->els_retry_evt
;
2506 spin_lock_irqsave(&phba
->hbalock
, flags
);
2507 if (!list_empty(&evtp
->evt_listp
)) {
2508 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
2512 /* We need to hold the node by incrementing the reference
2513 * count until the queued work is done
2515 evtp
->evt_arg1
= lpfc_nlp_get(ndlp
);
2516 if (evtp
->evt_arg1
) {
2517 evtp
->evt
= LPFC_EVT_ELS_RETRY
;
2518 list_add_tail(&evtp
->evt_listp
, &phba
->work_list
);
2519 lpfc_worker_wake_up(phba
);
2521 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
2526 * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
2527 * @ndlp: pointer to a node-list data structure.
2529 * This routine is the worker-thread handler for processing the @ndlp delayed
2530 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
2531 * the last ELS command from the associated ndlp and invokes the proper ELS
2532 * function according to the delayed ELS command to retry the command.
2535 lpfc_els_retry_delay_handler(struct lpfc_nodelist
*ndlp
)
2537 struct lpfc_vport
*vport
= ndlp
->vport
;
2538 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2539 uint32_t cmd
, did
, retry
;
2541 spin_lock_irq(shost
->host_lock
);
2542 did
= ndlp
->nlp_DID
;
2543 cmd
= ndlp
->nlp_last_elscmd
;
2544 ndlp
->nlp_last_elscmd
= 0;
2546 if (!(ndlp
->nlp_flag
& NLP_DELAY_TMO
)) {
2547 spin_unlock_irq(shost
->host_lock
);
2551 ndlp
->nlp_flag
&= ~NLP_DELAY_TMO
;
2552 spin_unlock_irq(shost
->host_lock
);
2554 * If a discovery event readded nlp_delayfunc after timer
2555 * firing and before processing the timer, cancel the
2558 del_timer_sync(&ndlp
->nlp_delayfunc
);
2559 retry
= ndlp
->nlp_retry
;
2560 ndlp
->nlp_retry
= 0;
2564 lpfc_issue_els_flogi(vport
, ndlp
, retry
);
2567 if (!lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, retry
)) {
2568 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
2569 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
2573 if (!lpfc_issue_els_adisc(vport
, ndlp
, retry
)) {
2574 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
2575 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_ADISC_ISSUE
);
2579 if (!lpfc_issue_els_prli(vport
, ndlp
, retry
)) {
2580 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
2581 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PRLI_ISSUE
);
2585 if (!lpfc_issue_els_logo(vport
, ndlp
, retry
)) {
2586 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
2587 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
2591 lpfc_issue_els_fdisc(vport
, ndlp
, retry
);
2598 * lpfc_els_retry - Make retry decision on an els command iocb
2599 * @phba: pointer to lpfc hba data structure.
2600 * @cmdiocb: pointer to lpfc command iocb data structure.
2601 * @rspiocb: pointer to lpfc response iocb data structure.
2603 * This routine makes a retry decision on an ELS command IOCB, which has
2604 * failed. The following ELS IOCBs use this function for retrying the command
2605 * when previously issued command responsed with error status: FLOGI, PLOGI,
2606 * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
2607 * returned error status, it makes the decision whether a retry shall be
2608 * issued for the command, and whether a retry shall be made immediately or
2609 * delayed. In the former case, the corresponding ELS command issuing-function
2610 * is called to retry the command. In the later case, the ELS command shall
2611 * be posted to the ndlp delayed event and delayed function timer set to the
2612 * ndlp for the delayed command issusing.
2615 * 0 - No retry of els command is made
2616 * 1 - Immediate or delayed retry of els command is made
2619 lpfc_els_retry(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
2620 struct lpfc_iocbq
*rspiocb
)
2622 struct lpfc_vport
*vport
= cmdiocb
->vport
;
2623 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2624 IOCB_t
*irsp
= &rspiocb
->iocb
;
2625 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) cmdiocb
->context1
;
2626 struct lpfc_dmabuf
*pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
2629 int retry
= 0, maxretry
= lpfc_max_els_tries
, delay
= 0;
2635 /* Note: context2 may be 0 for internal driver abort
2636 * of delays ELS command.
2639 if (pcmd
&& pcmd
->virt
) {
2640 elscmd
= (uint32_t *) (pcmd
->virt
);
2644 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
))
2645 did
= ndlp
->nlp_DID
;
2647 /* We should only hit this case for retrying PLOGI */
2648 did
= irsp
->un
.elsreq64
.remoteID
;
2649 ndlp
= lpfc_findnode_did(vport
, did
);
2650 if ((!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
))
2651 && (cmd
!= ELS_CMD_PLOGI
))
2655 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
2656 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
2657 *(((uint32_t *) irsp
) + 7), irsp
->un
.ulpWord
[4], ndlp
->nlp_DID
);
2659 switch (irsp
->ulpStatus
) {
2660 case IOSTAT_FCP_RSP_ERROR
:
2661 case IOSTAT_REMOTE_STOP
:
2664 case IOSTAT_LOCAL_REJECT
:
2665 switch ((irsp
->un
.ulpWord
[4] & 0xff)) {
2666 case IOERR_LOOP_OPEN_FAILURE
:
2667 if (cmd
== ELS_CMD_FLOGI
) {
2668 if (PCI_DEVICE_ID_HORNET
==
2669 phba
->pcidev
->device
) {
2670 phba
->fc_topology
= TOPOLOGY_LOOP
;
2671 phba
->pport
->fc_myDID
= 0;
2672 phba
->alpa_map
[0] = 0;
2673 phba
->alpa_map
[1] = 0;
2676 if (cmd
== ELS_CMD_PLOGI
&& cmdiocb
->retry
== 0)
2681 case IOERR_ILLEGAL_COMMAND
:
2682 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
2683 "0124 Retry illegal cmd x%x "
2684 "retry:x%x delay:x%x\n",
2685 cmd
, cmdiocb
->retry
, delay
);
2687 /* All command's retry policy */
2689 if (cmdiocb
->retry
> 2)
2693 case IOERR_NO_RESOURCES
:
2694 logerr
= 1; /* HBA out of resources */
2696 if (cmdiocb
->retry
> 100)
2701 case IOERR_ILLEGAL_FRAME
:
2706 case IOERR_SEQUENCE_TIMEOUT
:
2707 case IOERR_INVALID_RPI
:
2713 case IOSTAT_NPORT_RJT
:
2714 case IOSTAT_FABRIC_RJT
:
2715 if (irsp
->un
.ulpWord
[4] & RJT_UNAVAIL_TEMP
) {
2721 case IOSTAT_NPORT_BSY
:
2722 case IOSTAT_FABRIC_BSY
:
2723 logerr
= 1; /* Fabric / Remote NPort out of resources */
2728 stat
.un
.lsRjtError
= be32_to_cpu(irsp
->un
.ulpWord
[4]);
2729 /* Added for Vendor specifc support
2730 * Just keep retrying for these Rsn / Exp codes
2732 switch (stat
.un
.b
.lsRjtRsnCode
) {
2733 case LSRJT_UNABLE_TPC
:
2734 if (stat
.un
.b
.lsRjtRsnCodeExp
==
2735 LSEXP_CMD_IN_PROGRESS
) {
2736 if (cmd
== ELS_CMD_PLOGI
) {
2743 if (cmd
== ELS_CMD_PLOGI
) {
2745 maxretry
= lpfc_max_els_tries
+ 1;
2749 if ((phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
2750 (cmd
== ELS_CMD_FDISC
) &&
2751 (stat
.un
.b
.lsRjtRsnCodeExp
== LSEXP_OUT_OF_RESOURCE
)){
2752 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
2753 "0125 FDISC Failed (x%x). "
2754 "Fabric out of resources\n",
2755 stat
.un
.lsRjtError
);
2756 lpfc_vport_set_state(vport
,
2757 FC_VPORT_NO_FABRIC_RSCS
);
2761 case LSRJT_LOGICAL_BSY
:
2762 if ((cmd
== ELS_CMD_PLOGI
) ||
2763 (cmd
== ELS_CMD_PRLI
)) {
2766 } else if (cmd
== ELS_CMD_FDISC
) {
2767 /* FDISC retry policy */
2769 if (cmdiocb
->retry
>= 32)
2775 case LSRJT_LOGICAL_ERR
:
2776 /* There are some cases where switches return this
2777 * error when they are not ready and should be returning
2778 * Logical Busy. We should delay every time.
2780 if (cmd
== ELS_CMD_FDISC
&&
2781 stat
.un
.b
.lsRjtRsnCodeExp
== LSEXP_PORT_LOGIN_REQ
) {
2787 case LSRJT_PROTOCOL_ERR
:
2788 if ((phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
2789 (cmd
== ELS_CMD_FDISC
) &&
2790 ((stat
.un
.b
.lsRjtRsnCodeExp
== LSEXP_INVALID_PNAME
) ||
2791 (stat
.un
.b
.lsRjtRsnCodeExp
== LSEXP_INVALID_NPORT_ID
))
2793 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
2794 "0122 FDISC Failed (x%x). "
2795 "Fabric Detected Bad WWN\n",
2796 stat
.un
.lsRjtError
);
2797 lpfc_vport_set_state(vport
,
2798 FC_VPORT_FABRIC_REJ_WWN
);
2804 case IOSTAT_INTERMED_RSP
:
2812 if (did
== FDMI_DID
)
2815 if (((cmd
== ELS_CMD_FLOGI
) || (cmd
== ELS_CMD_FDISC
)) &&
2816 (phba
->fc_topology
!= TOPOLOGY_LOOP
) &&
2817 !lpfc_error_lost_link(irsp
)) {
2818 /* FLOGI retry policy */
2822 if (cmdiocb
->retry
>= 100)
2824 else if (cmdiocb
->retry
>= 32)
2829 if (maxretry
&& (cmdiocb
->retry
>= maxretry
)) {
2830 phba
->fc_stat
.elsRetryExceeded
++;
2834 if ((vport
->load_flag
& FC_UNLOADING
) != 0)
2839 /* Retry ELS command <elsCmd> to remote NPORT <did> */
2840 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
2841 "0107 Retry ELS command x%x to remote "
2842 "NPORT x%x Data: x%x x%x\n",
2843 cmd
, did
, cmdiocb
->retry
, delay
);
2845 if (((cmd
== ELS_CMD_PLOGI
) || (cmd
== ELS_CMD_ADISC
)) &&
2846 ((irsp
->ulpStatus
!= IOSTAT_LOCAL_REJECT
) ||
2847 ((irsp
->un
.ulpWord
[4] & 0xff) != IOERR_NO_RESOURCES
))) {
2848 /* Don't reset timer for no resources */
2850 /* If discovery / RSCN timer is running, reset it */
2851 if (timer_pending(&vport
->fc_disctmo
) ||
2852 (vport
->fc_flag
& FC_RSCN_MODE
))
2853 lpfc_set_disctmo(vport
);
2856 phba
->fc_stat
.elsXmitRetry
++;
2857 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
) && delay
) {
2858 phba
->fc_stat
.elsDelayRetry
++;
2859 ndlp
->nlp_retry
= cmdiocb
->retry
;
2861 /* delay is specified in milliseconds */
2862 mod_timer(&ndlp
->nlp_delayfunc
,
2863 jiffies
+ msecs_to_jiffies(delay
));
2864 spin_lock_irq(shost
->host_lock
);
2865 ndlp
->nlp_flag
|= NLP_DELAY_TMO
;
2866 spin_unlock_irq(shost
->host_lock
);
2868 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
2869 if (cmd
== ELS_CMD_PRLI
)
2870 lpfc_nlp_set_state(vport
, ndlp
,
2871 NLP_STE_REG_LOGIN_ISSUE
);
2873 lpfc_nlp_set_state(vport
, ndlp
,
2875 ndlp
->nlp_last_elscmd
= cmd
;
2881 lpfc_issue_els_flogi(vport
, ndlp
, cmdiocb
->retry
);
2884 lpfc_issue_els_fdisc(vport
, ndlp
, cmdiocb
->retry
);
2887 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
)) {
2888 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
2889 lpfc_nlp_set_state(vport
, ndlp
,
2890 NLP_STE_PLOGI_ISSUE
);
2892 lpfc_issue_els_plogi(vport
, did
, cmdiocb
->retry
);
2895 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
2896 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_ADISC_ISSUE
);
2897 lpfc_issue_els_adisc(vport
, ndlp
, cmdiocb
->retry
);
2900 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
2901 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PRLI_ISSUE
);
2902 lpfc_issue_els_prli(vport
, ndlp
, cmdiocb
->retry
);
2905 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
2906 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
2907 lpfc_issue_els_logo(vport
, ndlp
, cmdiocb
->retry
);
2911 /* No retry ELS command <elsCmd> to remote NPORT <did> */
2913 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
2914 "0137 No retry ELS command x%x to remote "
2915 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
2916 cmd
, did
, irsp
->ulpStatus
,
2917 irsp
->un
.ulpWord
[4]);
2920 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
2921 "0108 No retry ELS command x%x to remote "
2922 "NPORT x%x Retried:%d Error:x%x/%x\n",
2923 cmd
, did
, cmdiocb
->retry
, irsp
->ulpStatus
,
2924 irsp
->un
.ulpWord
[4]);
2930 * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
2931 * @phba: pointer to lpfc hba data structure.
2932 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
2934 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
2935 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
2936 * checks to see whether there is a lpfc DMA buffer associated with the
2937 * response of the command IOCB. If so, it will be released before releasing
2938 * the lpfc DMA buffer associated with the IOCB itself.
2941 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
2944 lpfc_els_free_data(struct lpfc_hba
*phba
, struct lpfc_dmabuf
*buf_ptr1
)
2946 struct lpfc_dmabuf
*buf_ptr
;
2948 /* Free the response before processing the command. */
2949 if (!list_empty(&buf_ptr1
->list
)) {
2950 list_remove_head(&buf_ptr1
->list
, buf_ptr
,
2953 lpfc_mbuf_free(phba
, buf_ptr
->virt
, buf_ptr
->phys
);
2956 lpfc_mbuf_free(phba
, buf_ptr1
->virt
, buf_ptr1
->phys
);
2962 * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
2963 * @phba: pointer to lpfc hba data structure.
2964 * @buf_ptr: pointer to the lpfc dma buffer data structure.
2966 * This routine releases the lpfc Direct Memory Access (DMA) buffer
2967 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
2971 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
2974 lpfc_els_free_bpl(struct lpfc_hba
*phba
, struct lpfc_dmabuf
*buf_ptr
)
2976 lpfc_mbuf_free(phba
, buf_ptr
->virt
, buf_ptr
->phys
);
2982 * lpfc_els_free_iocb - Free a command iocb and its associated resources
2983 * @phba: pointer to lpfc hba data structure.
2984 * @elsiocb: pointer to lpfc els command iocb data structure.
2986 * This routine frees a command IOCB and its associated resources. The
2987 * command IOCB data structure contains the reference to various associated
2988 * resources, these fields must be set to NULL if the associated reference
2990 * context1 - reference to ndlp
2991 * context2 - reference to cmd
2992 * context2->next - reference to rsp
2993 * context3 - reference to bpl
2995 * It first properly decrements the reference count held on ndlp for the
2996 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
2997 * set, it invokes the lpfc_els_free_data() routine to release the Direct
2998 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
2999 * adds the DMA buffer the @phba data structure for the delayed release.
3000 * If reference to the Buffer Pointer List (BPL) is present, the
3001 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
3002 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
3003 * invoked to release the IOCB data structure back to @phba IOCBQ list.
3006 * 0 - Success (currently, always return 0)
3009 lpfc_els_free_iocb(struct lpfc_hba
*phba
, struct lpfc_iocbq
*elsiocb
)
3011 struct lpfc_dmabuf
*buf_ptr
, *buf_ptr1
;
3012 struct lpfc_nodelist
*ndlp
;
3014 ndlp
= (struct lpfc_nodelist
*)elsiocb
->context1
;
3016 if (ndlp
->nlp_flag
& NLP_DEFER_RM
) {
3019 /* If the ndlp is not being used by another discovery
3022 if (!lpfc_nlp_not_used(ndlp
)) {
3023 /* If ndlp is being used by another discovery
3024 * thread, just clear NLP_DEFER_RM
3026 ndlp
->nlp_flag
&= ~NLP_DEFER_RM
;
3031 elsiocb
->context1
= NULL
;
3033 /* context2 = cmd, context2->next = rsp, context3 = bpl */
3034 if (elsiocb
->context2
) {
3035 if (elsiocb
->iocb_flag
& LPFC_DELAY_MEM_FREE
) {
3036 /* Firmware could still be in progress of DMAing
3037 * payload, so don't free data buffer till after
3040 elsiocb
->iocb_flag
&= ~LPFC_DELAY_MEM_FREE
;
3041 buf_ptr
= elsiocb
->context2
;
3042 elsiocb
->context2
= NULL
;
3045 spin_lock_irq(&phba
->hbalock
);
3046 if (!list_empty(&buf_ptr
->list
)) {
3047 list_remove_head(&buf_ptr
->list
,
3048 buf_ptr1
, struct lpfc_dmabuf
,
3050 INIT_LIST_HEAD(&buf_ptr1
->list
);
3051 list_add_tail(&buf_ptr1
->list
,
3055 INIT_LIST_HEAD(&buf_ptr
->list
);
3056 list_add_tail(&buf_ptr
->list
, &phba
->elsbuf
);
3058 spin_unlock_irq(&phba
->hbalock
);
3061 buf_ptr1
= (struct lpfc_dmabuf
*) elsiocb
->context2
;
3062 lpfc_els_free_data(phba
, buf_ptr1
);
3066 if (elsiocb
->context3
) {
3067 buf_ptr
= (struct lpfc_dmabuf
*) elsiocb
->context3
;
3068 lpfc_els_free_bpl(phba
, buf_ptr
);
3070 lpfc_sli_release_iocbq(phba
, elsiocb
);
3075 * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
3076 * @phba: pointer to lpfc hba data structure.
3077 * @cmdiocb: pointer to lpfc command iocb data structure.
3078 * @rspiocb: pointer to lpfc response iocb data structure.
3080 * This routine is the completion callback function to the Logout (LOGO)
3081 * Accept (ACC) Response ELS command. This routine is invoked to indicate
3082 * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
3083 * release the ndlp if it has the last reference remaining (reference count
3084 * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
3085 * field to NULL to inform the following lpfc_els_free_iocb() routine no
3086 * ndlp reference count needs to be decremented. Otherwise, the ndlp
3087 * reference use-count shall be decremented by the lpfc_els_free_iocb()
3088 * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
3089 * IOCB data structure.
3092 lpfc_cmpl_els_logo_acc(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
3093 struct lpfc_iocbq
*rspiocb
)
3095 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) cmdiocb
->context1
;
3096 struct lpfc_vport
*vport
= cmdiocb
->vport
;
3099 irsp
= &rspiocb
->iocb
;
3100 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
3101 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
3102 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4], ndlp
->nlp_DID
);
3103 /* ACC to LOGO completes to NPort <nlp_DID> */
3104 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
3105 "0109 ACC to LOGO completes to NPort x%x "
3106 "Data: x%x x%x x%x\n",
3107 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
3110 if (ndlp
->nlp_state
== NLP_STE_NPR_NODE
) {
3111 /* NPort Recovery mode or node is just allocated */
3112 if (!lpfc_nlp_not_used(ndlp
)) {
3113 /* If the ndlp is being used by another discovery
3114 * thread, just unregister the RPI.
3116 lpfc_unreg_rpi(vport
, ndlp
);
3118 /* Indicate the node has already released, should
3119 * not reference to it from within lpfc_els_free_iocb.
3121 cmdiocb
->context1
= NULL
;
3124 lpfc_els_free_iocb(phba
, cmdiocb
);
3129 * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
3130 * @phba: pointer to lpfc hba data structure.
3131 * @pmb: pointer to the driver internal queue element for mailbox command.
3133 * This routine is the completion callback function for unregister default
3134 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
3135 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
3136 * decrements the ndlp reference count held for this completion callback
3137 * function. After that, it invokes the lpfc_nlp_not_used() to check
3138 * whether there is only one reference left on the ndlp. If so, it will
3139 * perform one more decrement and trigger the release of the ndlp.
3142 lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
3144 struct lpfc_dmabuf
*mp
= (struct lpfc_dmabuf
*) (pmb
->context1
);
3145 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) pmb
->context2
;
3148 * This routine is used to register and unregister in previous SLI
3151 if ((pmb
->u
.mb
.mbxCommand
== MBX_UNREG_LOGIN
) &&
3152 (phba
->sli_rev
== LPFC_SLI_REV4
))
3153 lpfc_sli4_free_rpi(phba
, pmb
->u
.mb
.un
.varUnregLogin
.rpi
);
3155 pmb
->context1
= NULL
;
3156 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
3158 mempool_free(pmb
, phba
->mbox_mem_pool
);
3159 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
)) {
3161 /* This is the end of the default RPI cleanup logic for this
3162 * ndlp. If no other discovery threads are using this ndlp.
3163 * we should free all resources associated with it.
3165 lpfc_nlp_not_used(ndlp
);
3172 * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
3173 * @phba: pointer to lpfc hba data structure.
3174 * @cmdiocb: pointer to lpfc command iocb data structure.
3175 * @rspiocb: pointer to lpfc response iocb data structure.
3177 * This routine is the completion callback function for ELS Response IOCB
3178 * command. In normal case, this callback function just properly sets the
3179 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
3180 * field in the command IOCB is not NULL, the referred mailbox command will
3181 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
3182 * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
3183 * link down event occurred during the discovery, the lpfc_nlp_not_used()
3184 * routine shall be invoked trying to release the ndlp if no other threads
3185 * are currently referring it.
3188 lpfc_cmpl_els_rsp(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
3189 struct lpfc_iocbq
*rspiocb
)
3191 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) cmdiocb
->context1
;
3192 struct lpfc_vport
*vport
= ndlp
? ndlp
->vport
: NULL
;
3193 struct Scsi_Host
*shost
= vport
? lpfc_shost_from_vport(vport
) : NULL
;
3196 LPFC_MBOXQ_t
*mbox
= NULL
;
3197 struct lpfc_dmabuf
*mp
= NULL
;
3198 uint32_t ls_rjt
= 0;
3200 irsp
= &rspiocb
->iocb
;
3202 if (cmdiocb
->context_un
.mbox
)
3203 mbox
= cmdiocb
->context_un
.mbox
;
3205 /* First determine if this is a LS_RJT cmpl. Note, this callback
3206 * function can have cmdiocb->contest1 (ndlp) field set to NULL.
3208 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) cmdiocb
->context2
)->virt
);
3209 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
) &&
3210 (*((uint32_t *) (pcmd
)) == ELS_CMD_LS_RJT
)) {
3211 /* A LS_RJT associated with Default RPI cleanup has its own
3212 * separate code path.
3214 if (!(ndlp
->nlp_flag
& NLP_RM_DFLT_RPI
))
3218 /* Check to see if link went down during discovery */
3219 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
) || lpfc_els_chk_latt(vport
)) {
3221 mp
= (struct lpfc_dmabuf
*) mbox
->context1
;
3223 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
3226 mempool_free(mbox
, phba
->mbox_mem_pool
);
3228 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
) &&
3229 (ndlp
->nlp_flag
& NLP_RM_DFLT_RPI
))
3230 if (lpfc_nlp_not_used(ndlp
)) {
3232 /* Indicate the node has already released,
3233 * should not reference to it from within
3234 * the routine lpfc_els_free_iocb.
3236 cmdiocb
->context1
= NULL
;
3241 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
3242 "ELS rsp cmpl: status:x%x/x%x did:x%x",
3243 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
3244 cmdiocb
->iocb
.un
.elsreq64
.remoteID
);
3245 /* ELS response tag <ulpIoTag> completes */
3246 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
3247 "0110 ELS response tag x%x completes "
3248 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
3249 cmdiocb
->iocb
.ulpIoTag
, rspiocb
->iocb
.ulpStatus
,
3250 rspiocb
->iocb
.un
.ulpWord
[4], rspiocb
->iocb
.ulpTimeout
,
3251 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
3254 if ((rspiocb
->iocb
.ulpStatus
== 0)
3255 && (ndlp
->nlp_flag
& NLP_ACC_REGLOGIN
)) {
3256 lpfc_unreg_rpi(vport
, ndlp
);
3257 /* Increment reference count to ndlp to hold the
3258 * reference to ndlp for the callback function.
3260 mbox
->context2
= lpfc_nlp_get(ndlp
);
3261 mbox
->vport
= vport
;
3262 if (ndlp
->nlp_flag
& NLP_RM_DFLT_RPI
) {
3263 mbox
->mbox_flag
|= LPFC_MBX_IMED_UNREG
;
3264 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_dflt_rpi
;
3267 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_reg_login
;
3268 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
3269 lpfc_nlp_set_state(vport
, ndlp
,
3270 NLP_STE_REG_LOGIN_ISSUE
);
3272 if (lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
)
3273 != MBX_NOT_FINISHED
)
3276 /* Decrement the ndlp reference count we
3277 * set for this failed mailbox command.
3281 /* ELS rsp: Cannot issue reg_login for <NPortid> */
3282 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
3283 "0138 ELS rsp: Cannot issue reg_login for x%x "
3284 "Data: x%x x%x x%x\n",
3285 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
3288 if (lpfc_nlp_not_used(ndlp
)) {
3290 /* Indicate node has already been released,
3291 * should not reference to it from within
3292 * the routine lpfc_els_free_iocb.
3294 cmdiocb
->context1
= NULL
;
3297 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
3298 if (!lpfc_error_lost_link(irsp
) &&
3299 ndlp
->nlp_flag
& NLP_ACC_REGLOGIN
) {
3300 if (lpfc_nlp_not_used(ndlp
)) {
3302 /* Indicate node has already been
3303 * released, should not reference
3304 * to it from within the routine
3305 * lpfc_els_free_iocb.
3307 cmdiocb
->context1
= NULL
;
3311 mp
= (struct lpfc_dmabuf
*) mbox
->context1
;
3313 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
3316 mempool_free(mbox
, phba
->mbox_mem_pool
);
3319 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
)) {
3320 spin_lock_irq(shost
->host_lock
);
3321 ndlp
->nlp_flag
&= ~(NLP_ACC_REGLOGIN
| NLP_RM_DFLT_RPI
);
3322 spin_unlock_irq(shost
->host_lock
);
3324 /* If the node is not being used by another discovery thread,
3325 * and we are sending a reject, we are done with it.
3326 * Release driver reference count here and free associated
3330 if (lpfc_nlp_not_used(ndlp
))
3331 /* Indicate node has already been released,
3332 * should not reference to it from within
3333 * the routine lpfc_els_free_iocb.
3335 cmdiocb
->context1
= NULL
;
3338 lpfc_els_free_iocb(phba
, cmdiocb
);
3343 * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
3344 * @vport: pointer to a host virtual N_Port data structure.
3345 * @flag: the els command code to be accepted.
3346 * @oldiocb: pointer to the original lpfc command iocb data structure.
3347 * @ndlp: pointer to a node-list data structure.
3348 * @mbox: pointer to the driver internal queue element for mailbox command.
3350 * This routine prepares and issues an Accept (ACC) response IOCB
3351 * command. It uses the @flag to properly set up the IOCB field for the
3352 * specific ACC response command to be issued and invokes the
3353 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
3354 * @mbox pointer is passed in, it will be put into the context_un.mbox
3355 * field of the IOCB for the completion callback function to issue the
3356 * mailbox command to the HBA later when callback is invoked.
3358 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3359 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3360 * will be stored into the context1 field of the IOCB for the completion
3361 * callback function to the corresponding response ELS IOCB command.
3364 * 0 - Successfully issued acc response
3365 * 1 - Failed to issue acc response
3368 lpfc_els_rsp_acc(struct lpfc_vport
*vport
, uint32_t flag
,
3369 struct lpfc_iocbq
*oldiocb
, struct lpfc_nodelist
*ndlp
,
3372 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
3373 struct lpfc_hba
*phba
= vport
->phba
;
3376 struct lpfc_iocbq
*elsiocb
;
3377 struct lpfc_sli
*psli
;
3381 ELS_PKT
*els_pkt_ptr
;
3384 oldcmd
= &oldiocb
->iocb
;
3388 cmdsize
= sizeof(uint32_t);
3389 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
,
3390 ndlp
, ndlp
->nlp_DID
, ELS_CMD_ACC
);
3392 spin_lock_irq(shost
->host_lock
);
3393 ndlp
->nlp_flag
&= ~NLP_LOGO_ACC
;
3394 spin_unlock_irq(shost
->host_lock
);
3398 icmd
= &elsiocb
->iocb
;
3399 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri */
3400 pcmd
= (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
3401 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
3402 pcmd
+= sizeof(uint32_t);
3404 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
3405 "Issue ACC: did:x%x flg:x%x",
3406 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
3409 cmdsize
= (sizeof(struct serv_parm
) + sizeof(uint32_t));
3410 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
,
3411 ndlp
, ndlp
->nlp_DID
, ELS_CMD_ACC
);
3415 icmd
= &elsiocb
->iocb
;
3416 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri */
3417 pcmd
= (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
3420 elsiocb
->context_un
.mbox
= mbox
;
3422 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
3423 pcmd
+= sizeof(uint32_t);
3424 memcpy(pcmd
, &vport
->fc_sparam
, sizeof(struct serv_parm
));
3426 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
3427 "Issue ACC PLOGI: did:x%x flg:x%x",
3428 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
3431 cmdsize
= sizeof(uint32_t) + sizeof(PRLO
);
3432 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
,
3433 ndlp
, ndlp
->nlp_DID
, ELS_CMD_PRLO
);
3437 icmd
= &elsiocb
->iocb
;
3438 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri */
3439 pcmd
= (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
3441 memcpy(pcmd
, ((struct lpfc_dmabuf
*) oldiocb
->context2
)->virt
,
3442 sizeof(uint32_t) + sizeof(PRLO
));
3443 *((uint32_t *) (pcmd
)) = ELS_CMD_PRLO_ACC
;
3444 els_pkt_ptr
= (ELS_PKT
*) pcmd
;
3445 els_pkt_ptr
->un
.prlo
.acceptRspCode
= PRLO_REQ_EXECUTED
;
3447 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
3448 "Issue ACC PRLO: did:x%x flg:x%x",
3449 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
3454 /* Xmit ELS ACC response tag <ulpIoTag> */
3455 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
3456 "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
3457 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n",
3458 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
,
3459 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
3461 if (ndlp
->nlp_flag
& NLP_LOGO_ACC
) {
3462 spin_lock_irq(shost
->host_lock
);
3463 ndlp
->nlp_flag
&= ~NLP_LOGO_ACC
;
3464 spin_unlock_irq(shost
->host_lock
);
3465 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_logo_acc
;
3467 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
3470 phba
->fc_stat
.elsXmitACC
++;
3471 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
3472 if (rc
== IOCB_ERROR
) {
3473 lpfc_els_free_iocb(phba
, elsiocb
);
3480 * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command
3481 * @vport: pointer to a virtual N_Port data structure.
3483 * @oldiocb: pointer to the original lpfc command iocb data structure.
3484 * @ndlp: pointer to a node-list data structure.
3485 * @mbox: pointer to the driver internal queue element for mailbox command.
3487 * This routine prepares and issue an Reject (RJT) response IOCB
3488 * command. If a @mbox pointer is passed in, it will be put into the
3489 * context_un.mbox field of the IOCB for the completion callback function
3490 * to issue to the HBA later.
3492 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3493 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3494 * will be stored into the context1 field of the IOCB for the completion
3495 * callback function to the reject response ELS IOCB command.
3498 * 0 - Successfully issued reject response
3499 * 1 - Failed to issue reject response
3502 lpfc_els_rsp_reject(struct lpfc_vport
*vport
, uint32_t rejectError
,
3503 struct lpfc_iocbq
*oldiocb
, struct lpfc_nodelist
*ndlp
,
3506 struct lpfc_hba
*phba
= vport
->phba
;
3509 struct lpfc_iocbq
*elsiocb
;
3510 struct lpfc_sli
*psli
;
3516 cmdsize
= 2 * sizeof(uint32_t);
3517 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
, ndlp
,
3518 ndlp
->nlp_DID
, ELS_CMD_LS_RJT
);
3522 icmd
= &elsiocb
->iocb
;
3523 oldcmd
= &oldiocb
->iocb
;
3524 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri */
3525 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
3527 *((uint32_t *) (pcmd
)) = ELS_CMD_LS_RJT
;
3528 pcmd
+= sizeof(uint32_t);
3529 *((uint32_t *) (pcmd
)) = rejectError
;
3532 elsiocb
->context_un
.mbox
= mbox
;
3534 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
3535 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
3536 "0129 Xmit ELS RJT x%x response tag x%x "
3537 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
3539 rejectError
, elsiocb
->iotag
,
3540 elsiocb
->iocb
.ulpContext
, ndlp
->nlp_DID
,
3541 ndlp
->nlp_flag
, ndlp
->nlp_state
, ndlp
->nlp_rpi
);
3542 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
3543 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
3544 ndlp
->nlp_DID
, ndlp
->nlp_flag
, rejectError
);
3546 phba
->fc_stat
.elsXmitLSRJT
++;
3547 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
3548 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
3550 if (rc
== IOCB_ERROR
) {
3551 lpfc_els_free_iocb(phba
, elsiocb
);
3558 * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
3559 * @vport: pointer to a virtual N_Port data structure.
3560 * @oldiocb: pointer to the original lpfc command iocb data structure.
3561 * @ndlp: pointer to a node-list data structure.
3563 * This routine prepares and issues an Accept (ACC) response to Address
3564 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
3565 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3567 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3568 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3569 * will be stored into the context1 field of the IOCB for the completion
3570 * callback function to the ADISC Accept response ELS IOCB command.
3573 * 0 - Successfully issued acc adisc response
3574 * 1 - Failed to issue adisc acc response
3577 lpfc_els_rsp_adisc_acc(struct lpfc_vport
*vport
, struct lpfc_iocbq
*oldiocb
,
3578 struct lpfc_nodelist
*ndlp
)
3580 struct lpfc_hba
*phba
= vport
->phba
;
3582 IOCB_t
*icmd
, *oldcmd
;
3583 struct lpfc_iocbq
*elsiocb
;
3588 cmdsize
= sizeof(uint32_t) + sizeof(ADISC
);
3589 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
, ndlp
,
3590 ndlp
->nlp_DID
, ELS_CMD_ACC
);
3594 icmd
= &elsiocb
->iocb
;
3595 oldcmd
= &oldiocb
->iocb
;
3596 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri */
3598 /* Xmit ADISC ACC response tag <ulpIoTag> */
3599 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
3600 "0130 Xmit ADISC ACC response iotag x%x xri: "
3601 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
3602 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
,
3603 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
3605 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
3607 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
3608 pcmd
+= sizeof(uint32_t);
3610 ap
= (ADISC
*) (pcmd
);
3611 ap
->hardAL_PA
= phba
->fc_pref_ALPA
;
3612 memcpy(&ap
->portName
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
3613 memcpy(&ap
->nodeName
, &vport
->fc_nodename
, sizeof(struct lpfc_name
));
3614 ap
->DID
= be32_to_cpu(vport
->fc_myDID
);
3616 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
3617 "Issue ACC ADISC: did:x%x flg:x%x",
3618 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
3620 phba
->fc_stat
.elsXmitACC
++;
3621 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
3622 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
3623 if (rc
== IOCB_ERROR
) {
3624 lpfc_els_free_iocb(phba
, elsiocb
);
3631 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
3632 * @vport: pointer to a virtual N_Port data structure.
3633 * @oldiocb: pointer to the original lpfc command iocb data structure.
3634 * @ndlp: pointer to a node-list data structure.
3636 * This routine prepares and issues an Accept (ACC) response to Process
3637 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
3638 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3640 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3641 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3642 * will be stored into the context1 field of the IOCB for the completion
3643 * callback function to the PRLI Accept response ELS IOCB command.
3646 * 0 - Successfully issued acc prli response
3647 * 1 - Failed to issue acc prli response
3650 lpfc_els_rsp_prli_acc(struct lpfc_vport
*vport
, struct lpfc_iocbq
*oldiocb
,
3651 struct lpfc_nodelist
*ndlp
)
3653 struct lpfc_hba
*phba
= vport
->phba
;
3658 struct lpfc_iocbq
*elsiocb
;
3659 struct lpfc_sli
*psli
;
3666 cmdsize
= sizeof(uint32_t) + sizeof(PRLI
);
3667 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
, ndlp
,
3668 ndlp
->nlp_DID
, (ELS_CMD_ACC
| (ELS_CMD_PRLI
& ~ELS_RSP_MASK
)));
3672 icmd
= &elsiocb
->iocb
;
3673 oldcmd
= &oldiocb
->iocb
;
3674 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri */
3675 /* Xmit PRLI ACC response tag <ulpIoTag> */
3676 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
3677 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
3678 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
3679 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
,
3680 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
3682 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
3684 *((uint32_t *) (pcmd
)) = (ELS_CMD_ACC
| (ELS_CMD_PRLI
& ~ELS_RSP_MASK
));
3685 pcmd
+= sizeof(uint32_t);
3687 /* For PRLI, remainder of payload is PRLI parameter page */
3688 memset(pcmd
, 0, sizeof(PRLI
));
3690 npr
= (PRLI
*) pcmd
;
3693 * If the remote port is a target and our firmware version is 3.20 or
3694 * later, set the following bits for FC-TAPE support.
3696 if ((ndlp
->nlp_type
& NLP_FCP_TARGET
) &&
3697 (vpd
->rev
.feaLevelHigh
>= 0x02)) {
3698 npr
->ConfmComplAllowed
= 1;
3700 npr
->TaskRetryIdReq
= 1;
3703 npr
->acceptRspCode
= PRLI_REQ_EXECUTED
;
3704 npr
->estabImagePair
= 1;
3705 npr
->readXferRdyDis
= 1;
3706 npr
->ConfmComplAllowed
= 1;
3708 npr
->prliType
= PRLI_FCP_TYPE
;
3709 npr
->initiatorFunc
= 1;
3711 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
3712 "Issue ACC PRLI: did:x%x flg:x%x",
3713 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
3715 phba
->fc_stat
.elsXmitACC
++;
3716 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
3718 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
3719 if (rc
== IOCB_ERROR
) {
3720 lpfc_els_free_iocb(phba
, elsiocb
);
3727 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
3728 * @vport: pointer to a virtual N_Port data structure.
3729 * @format: rnid command format.
3730 * @oldiocb: pointer to the original lpfc command iocb data structure.
3731 * @ndlp: pointer to a node-list data structure.
3733 * This routine issues a Request Node Identification Data (RNID) Accept
3734 * (ACC) response. It constructs the RNID ACC response command according to
3735 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
3736 * issue the response. Note that this command does not need to hold the ndlp
3737 * reference count for the callback. So, the ndlp reference count taken by
3738 * the lpfc_prep_els_iocb() routine is put back and the context1 field of
3739 * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
3740 * there is no ndlp reference available.
3742 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3743 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3744 * will be stored into the context1 field of the IOCB for the completion
3745 * callback function. However, for the RNID Accept Response ELS command,
3746 * this is undone later by this routine after the IOCB is allocated.
3749 * 0 - Successfully issued acc rnid response
3750 * 1 - Failed to issue acc rnid response
3753 lpfc_els_rsp_rnid_acc(struct lpfc_vport
*vport
, uint8_t format
,
3754 struct lpfc_iocbq
*oldiocb
, struct lpfc_nodelist
*ndlp
)
3756 struct lpfc_hba
*phba
= vport
->phba
;
3758 IOCB_t
*icmd
, *oldcmd
;
3759 struct lpfc_iocbq
*elsiocb
;
3760 struct lpfc_sli
*psli
;
3766 cmdsize
= sizeof(uint32_t) + sizeof(uint32_t)
3767 + (2 * sizeof(struct lpfc_name
));
3769 cmdsize
+= sizeof(RNID_TOP_DISC
);
3771 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
, ndlp
,
3772 ndlp
->nlp_DID
, ELS_CMD_ACC
);
3776 icmd
= &elsiocb
->iocb
;
3777 oldcmd
= &oldiocb
->iocb
;
3778 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri */
3779 /* Xmit RNID ACC response tag <ulpIoTag> */
3780 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
3781 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
3782 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
);
3783 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
3784 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
3785 pcmd
+= sizeof(uint32_t);
3787 memset(pcmd
, 0, sizeof(RNID
));
3788 rn
= (RNID
*) (pcmd
);
3789 rn
->Format
= format
;
3790 rn
->CommonLen
= (2 * sizeof(struct lpfc_name
));
3791 memcpy(&rn
->portName
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
3792 memcpy(&rn
->nodeName
, &vport
->fc_nodename
, sizeof(struct lpfc_name
));
3795 rn
->SpecificLen
= 0;
3797 case RNID_TOPOLOGY_DISC
:
3798 rn
->SpecificLen
= sizeof(RNID_TOP_DISC
);
3799 memcpy(&rn
->un
.topologyDisc
.portName
,
3800 &vport
->fc_portname
, sizeof(struct lpfc_name
));
3801 rn
->un
.topologyDisc
.unitType
= RNID_HBA
;
3802 rn
->un
.topologyDisc
.physPort
= 0;
3803 rn
->un
.topologyDisc
.attachedNodes
= 0;
3807 rn
->SpecificLen
= 0;
3811 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
3812 "Issue ACC RNID: did:x%x flg:x%x",
3813 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
3815 phba
->fc_stat
.elsXmitACC
++;
3816 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
3818 elsiocb
->context1
= NULL
; /* Don't need ndlp for cmpl,
3819 * it could be freed */
3821 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
3822 if (rc
== IOCB_ERROR
) {
3823 lpfc_els_free_iocb(phba
, elsiocb
);
3830 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
3831 * @vport: pointer to a host virtual N_Port data structure.
3833 * This routine issues Address Discover (ADISC) ELS commands to those
3834 * N_Ports which are in node port recovery state and ADISC has not been issued
3835 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
3836 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
3837 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
3838 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
3839 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
3840 * IOCBs quit for later pick up. On the other hand, after walking through
3841 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
3842 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
3843 * no more ADISC need to be sent.
3846 * The number of N_Ports with adisc issued.
3849 lpfc_els_disc_adisc(struct lpfc_vport
*vport
)
3851 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
3852 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
3855 /* go thru NPR nodes and issue any remaining ELS ADISCs */
3856 list_for_each_entry_safe(ndlp
, next_ndlp
, &vport
->fc_nodes
, nlp_listp
) {
3857 if (!NLP_CHK_NODE_ACT(ndlp
))
3859 if (ndlp
->nlp_state
== NLP_STE_NPR_NODE
&&
3860 (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
) != 0 &&
3861 (ndlp
->nlp_flag
& NLP_NPR_ADISC
) != 0) {
3862 spin_lock_irq(shost
->host_lock
);
3863 ndlp
->nlp_flag
&= ~NLP_NPR_ADISC
;
3864 spin_unlock_irq(shost
->host_lock
);
3865 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
3866 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_ADISC_ISSUE
);
3867 lpfc_issue_els_adisc(vport
, ndlp
, 0);
3869 vport
->num_disc_nodes
++;
3870 if (vport
->num_disc_nodes
>=
3871 vport
->cfg_discovery_threads
) {
3872 spin_lock_irq(shost
->host_lock
);
3873 vport
->fc_flag
|= FC_NLP_MORE
;
3874 spin_unlock_irq(shost
->host_lock
);
3879 if (sentadisc
== 0) {
3880 spin_lock_irq(shost
->host_lock
);
3881 vport
->fc_flag
&= ~FC_NLP_MORE
;
3882 spin_unlock_irq(shost
->host_lock
);
3888 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
3889 * @vport: pointer to a host virtual N_Port data structure.
3891 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
3892 * which are in node port recovery state, with a @vport. Each time an ELS
3893 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
3894 * the per @vport number of discover count (num_disc_nodes) shall be
3895 * incremented. If the num_disc_nodes reaches a pre-configured threshold
3896 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
3897 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
3898 * later pick up. On the other hand, after walking through all the ndlps with
3899 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
3900 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
3901 * PLOGI need to be sent.
3904 * The number of N_Ports with plogi issued.
3907 lpfc_els_disc_plogi(struct lpfc_vport
*vport
)
3909 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
3910 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
3913 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
3914 list_for_each_entry_safe(ndlp
, next_ndlp
, &vport
->fc_nodes
, nlp_listp
) {
3915 if (!NLP_CHK_NODE_ACT(ndlp
))
3917 if (ndlp
->nlp_state
== NLP_STE_NPR_NODE
&&
3918 (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
) != 0 &&
3919 (ndlp
->nlp_flag
& NLP_DELAY_TMO
) == 0 &&
3920 (ndlp
->nlp_flag
& NLP_NPR_ADISC
) == 0) {
3921 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
3922 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
3923 lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, 0);
3925 vport
->num_disc_nodes
++;
3926 if (vport
->num_disc_nodes
>=
3927 vport
->cfg_discovery_threads
) {
3928 spin_lock_irq(shost
->host_lock
);
3929 vport
->fc_flag
|= FC_NLP_MORE
;
3930 spin_unlock_irq(shost
->host_lock
);
3936 lpfc_set_disctmo(vport
);
3939 spin_lock_irq(shost
->host_lock
);
3940 vport
->fc_flag
&= ~FC_NLP_MORE
;
3941 spin_unlock_irq(shost
->host_lock
);
3947 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
3948 * @vport: pointer to a host virtual N_Port data structure.
3950 * This routine cleans up any Registration State Change Notification
3951 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
3952 * @vport together with the host_lock is used to prevent multiple thread
3953 * trying to access the RSCN array on a same @vport at the same time.
3956 lpfc_els_flush_rscn(struct lpfc_vport
*vport
)
3958 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
3959 struct lpfc_hba
*phba
= vport
->phba
;
3962 spin_lock_irq(shost
->host_lock
);
3963 if (vport
->fc_rscn_flush
) {
3964 /* Another thread is walking fc_rscn_id_list on this vport */
3965 spin_unlock_irq(shost
->host_lock
);
3968 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
3969 vport
->fc_rscn_flush
= 1;
3970 spin_unlock_irq(shost
->host_lock
);
3972 for (i
= 0; i
< vport
->fc_rscn_id_cnt
; i
++) {
3973 lpfc_in_buf_free(phba
, vport
->fc_rscn_id_list
[i
]);
3974 vport
->fc_rscn_id_list
[i
] = NULL
;
3976 spin_lock_irq(shost
->host_lock
);
3977 vport
->fc_rscn_id_cnt
= 0;
3978 vport
->fc_flag
&= ~(FC_RSCN_MODE
| FC_RSCN_DISCOVERY
);
3979 spin_unlock_irq(shost
->host_lock
);
3980 lpfc_can_disctmo(vport
);
3981 /* Indicate we are done walking this fc_rscn_id_list */
3982 vport
->fc_rscn_flush
= 0;
3986 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
3987 * @vport: pointer to a host virtual N_Port data structure.
3988 * @did: remote destination port identifier.
3990 * This routine checks whether there is any pending Registration State
3991 * Configuration Notification (RSCN) to a @did on @vport.
3994 * None zero - The @did matched with a pending rscn
3995 * 0 - not able to match @did with a pending rscn
3998 lpfc_rscn_payload_check(struct lpfc_vport
*vport
, uint32_t did
)
4003 uint32_t payload_len
, i
;
4004 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4006 ns_did
.un
.word
= did
;
4008 /* Never match fabric nodes for RSCNs */
4009 if ((did
& Fabric_DID_MASK
) == Fabric_DID_MASK
)
4012 /* If we are doing a FULL RSCN rediscovery, match everything */
4013 if (vport
->fc_flag
& FC_RSCN_DISCOVERY
)
4016 spin_lock_irq(shost
->host_lock
);
4017 if (vport
->fc_rscn_flush
) {
4018 /* Another thread is walking fc_rscn_id_list on this vport */
4019 spin_unlock_irq(shost
->host_lock
);
4022 /* Indicate we are walking fc_rscn_id_list on this vport */
4023 vport
->fc_rscn_flush
= 1;
4024 spin_unlock_irq(shost
->host_lock
);
4025 for (i
= 0; i
< vport
->fc_rscn_id_cnt
; i
++) {
4026 lp
= vport
->fc_rscn_id_list
[i
]->virt
;
4027 payload_len
= be32_to_cpu(*lp
++ & ~ELS_CMD_MASK
);
4028 payload_len
-= sizeof(uint32_t); /* take off word 0 */
4029 while (payload_len
) {
4030 rscn_did
.un
.word
= be32_to_cpu(*lp
++);
4031 payload_len
-= sizeof(uint32_t);
4032 switch (rscn_did
.un
.b
.resv
& RSCN_ADDRESS_FORMAT_MASK
) {
4033 case RSCN_ADDRESS_FORMAT_PORT
:
4034 if ((ns_did
.un
.b
.domain
== rscn_did
.un
.b
.domain
)
4035 && (ns_did
.un
.b
.area
== rscn_did
.un
.b
.area
)
4036 && (ns_did
.un
.b
.id
== rscn_did
.un
.b
.id
))
4037 goto return_did_out
;
4039 case RSCN_ADDRESS_FORMAT_AREA
:
4040 if ((ns_did
.un
.b
.domain
== rscn_did
.un
.b
.domain
)
4041 && (ns_did
.un
.b
.area
== rscn_did
.un
.b
.area
))
4042 goto return_did_out
;
4044 case RSCN_ADDRESS_FORMAT_DOMAIN
:
4045 if (ns_did
.un
.b
.domain
== rscn_did
.un
.b
.domain
)
4046 goto return_did_out
;
4048 case RSCN_ADDRESS_FORMAT_FABRIC
:
4049 goto return_did_out
;
4053 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4054 vport
->fc_rscn_flush
= 0;
4057 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4058 vport
->fc_rscn_flush
= 0;
4063 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
4064 * @vport: pointer to a host virtual N_Port data structure.
4066 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
4067 * state machine for a @vport's nodes that are with pending RSCN (Registration
4068 * State Change Notification).
4071 * 0 - Successful (currently alway return 0)
4074 lpfc_rscn_recovery_check(struct lpfc_vport
*vport
)
4076 struct lpfc_nodelist
*ndlp
= NULL
;
4078 /* Move all affected nodes by pending RSCNs to NPR state. */
4079 list_for_each_entry(ndlp
, &vport
->fc_nodes
, nlp_listp
) {
4080 if (!NLP_CHK_NODE_ACT(ndlp
) ||
4081 (ndlp
->nlp_state
== NLP_STE_UNUSED_NODE
) ||
4082 !lpfc_rscn_payload_check(vport
, ndlp
->nlp_DID
))
4084 lpfc_disc_state_machine(vport
, ndlp
, NULL
,
4085 NLP_EVT_DEVICE_RECOVERY
);
4086 lpfc_cancel_retry_delay_tmo(vport
, ndlp
);
4092 * lpfc_send_rscn_event - Send an RSCN event to management application
4093 * @vport: pointer to a host virtual N_Port data structure.
4094 * @cmdiocb: pointer to lpfc command iocb data structure.
4096 * lpfc_send_rscn_event sends an RSCN netlink event to management
4100 lpfc_send_rscn_event(struct lpfc_vport
*vport
,
4101 struct lpfc_iocbq
*cmdiocb
)
4103 struct lpfc_dmabuf
*pcmd
;
4104 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4105 uint32_t *payload_ptr
;
4106 uint32_t payload_len
;
4107 struct lpfc_rscn_event_header
*rscn_event_data
;
4109 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
4110 payload_ptr
= (uint32_t *) pcmd
->virt
;
4111 payload_len
= be32_to_cpu(*payload_ptr
& ~ELS_CMD_MASK
);
4113 rscn_event_data
= kmalloc(sizeof(struct lpfc_rscn_event_header
) +
4114 payload_len
, GFP_KERNEL
);
4115 if (!rscn_event_data
) {
4116 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
4117 "0147 Failed to allocate memory for RSCN event\n");
4120 rscn_event_data
->event_type
= FC_REG_RSCN_EVENT
;
4121 rscn_event_data
->payload_length
= payload_len
;
4122 memcpy(rscn_event_data
->rscn_payload
, payload_ptr
,
4125 fc_host_post_vendor_event(shost
,
4126 fc_get_event_number(),
4127 sizeof(struct lpfc_els_event_header
) + payload_len
,
4128 (char *)rscn_event_data
,
4131 kfree(rscn_event_data
);
4135 * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
4136 * @vport: pointer to a host virtual N_Port data structure.
4137 * @cmdiocb: pointer to lpfc command iocb data structure.
4138 * @ndlp: pointer to a node-list data structure.
4140 * This routine processes an unsolicited RSCN (Registration State Change
4141 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
4142 * to invoke fc_host_post_event() routine to the FC transport layer. If the
4143 * discover state machine is about to begin discovery, it just accepts the
4144 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
4145 * contains N_Port IDs for other vports on this HBA, it just accepts the
4146 * RSCN and ignore processing it. If the state machine is in the recovery
4147 * state, the fc_rscn_id_list of this @vport is walked and the
4148 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
4149 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
4150 * routine is invoked to handle the RSCN event.
4153 * 0 - Just sent the acc response
4154 * 1 - Sent the acc response and waited for name server completion
4157 lpfc_els_rcv_rscn(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
4158 struct lpfc_nodelist
*ndlp
)
4160 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4161 struct lpfc_hba
*phba
= vport
->phba
;
4162 struct lpfc_dmabuf
*pcmd
;
4163 uint32_t *lp
, *datap
;
4165 uint32_t payload_len
, length
, nportid
, *cmd
;
4167 int rscn_id
= 0, hba_id
= 0;
4170 icmd
= &cmdiocb
->iocb
;
4171 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
4172 lp
= (uint32_t *) pcmd
->virt
;
4174 payload_len
= be32_to_cpu(*lp
++ & ~ELS_CMD_MASK
);
4175 payload_len
-= sizeof(uint32_t); /* take off word 0 */
4177 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
4178 "0214 RSCN received Data: x%x x%x x%x x%x\n",
4179 vport
->fc_flag
, payload_len
, *lp
,
4180 vport
->fc_rscn_id_cnt
);
4182 /* Send an RSCN event to the management application */
4183 lpfc_send_rscn_event(vport
, cmdiocb
);
4185 for (i
= 0; i
< payload_len
/sizeof(uint32_t); i
++)
4186 fc_host_post_event(shost
, fc_get_event_number(),
4187 FCH_EVT_RSCN
, lp
[i
]);
4189 /* If we are about to begin discovery, just ACC the RSCN.
4190 * Discovery processing will satisfy it.
4192 if (vport
->port_state
<= LPFC_NS_QRY
) {
4193 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
4194 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
4195 ndlp
->nlp_DID
, vport
->port_state
, ndlp
->nlp_flag
);
4197 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
4201 /* If this RSCN just contains NPortIDs for other vports on this HBA,
4202 * just ACC and ignore it.
4204 if ((phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
4205 !(vport
->cfg_peer_port_login
)) {
4210 nportid
= ((be32_to_cpu(nportid
)) & Mask_DID
);
4211 i
-= sizeof(uint32_t);
4213 if (lpfc_find_vport_by_did(phba
, nportid
))
4216 if (rscn_id
== hba_id
) {
4217 /* ALL NPortIDs in RSCN are on HBA */
4218 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
4220 "Data: x%x x%x x%x x%x\n",
4221 vport
->fc_flag
, payload_len
,
4222 *lp
, vport
->fc_rscn_id_cnt
);
4223 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
4224 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
4225 ndlp
->nlp_DID
, vport
->port_state
,
4228 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
,
4234 spin_lock_irq(shost
->host_lock
);
4235 if (vport
->fc_rscn_flush
) {
4236 /* Another thread is walking fc_rscn_id_list on this vport */
4237 vport
->fc_flag
|= FC_RSCN_DISCOVERY
;
4238 spin_unlock_irq(shost
->host_lock
);
4240 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
4243 /* Indicate we are walking fc_rscn_id_list on this vport */
4244 vport
->fc_rscn_flush
= 1;
4245 spin_unlock_irq(shost
->host_lock
);
4246 /* Get the array count after successfully have the token */
4247 rscn_cnt
= vport
->fc_rscn_id_cnt
;
4248 /* If we are already processing an RSCN, save the received
4249 * RSCN payload buffer, cmdiocb->context2 to process later.
4251 if (vport
->fc_flag
& (FC_RSCN_MODE
| FC_NDISC_ACTIVE
)) {
4252 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
4253 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
4254 ndlp
->nlp_DID
, vport
->port_state
, ndlp
->nlp_flag
);
4256 spin_lock_irq(shost
->host_lock
);
4257 vport
->fc_flag
|= FC_RSCN_DEFERRED
;
4258 if ((rscn_cnt
< FC_MAX_HOLD_RSCN
) &&
4259 !(vport
->fc_flag
& FC_RSCN_DISCOVERY
)) {
4260 vport
->fc_flag
|= FC_RSCN_MODE
;
4261 spin_unlock_irq(shost
->host_lock
);
4263 cmd
= vport
->fc_rscn_id_list
[rscn_cnt
-1]->virt
;
4264 length
= be32_to_cpu(*cmd
& ~ELS_CMD_MASK
);
4267 (payload_len
+ length
<= LPFC_BPL_SIZE
)) {
4268 *cmd
&= ELS_CMD_MASK
;
4269 *cmd
|= cpu_to_be32(payload_len
+ length
);
4270 memcpy(((uint8_t *)cmd
) + length
, lp
,
4273 vport
->fc_rscn_id_list
[rscn_cnt
] = pcmd
;
4274 vport
->fc_rscn_id_cnt
++;
4275 /* If we zero, cmdiocb->context2, the calling
4276 * routine will not try to free it.
4278 cmdiocb
->context2
= NULL
;
4281 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
4282 "0235 Deferred RSCN "
4283 "Data: x%x x%x x%x\n",
4284 vport
->fc_rscn_id_cnt
, vport
->fc_flag
,
4287 vport
->fc_flag
|= FC_RSCN_DISCOVERY
;
4288 spin_unlock_irq(shost
->host_lock
);
4289 /* ReDiscovery RSCN */
4290 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
4291 "0234 ReDiscovery RSCN "
4292 "Data: x%x x%x x%x\n",
4293 vport
->fc_rscn_id_cnt
, vport
->fc_flag
,
4296 /* Indicate we are done walking fc_rscn_id_list on this vport */
4297 vport
->fc_rscn_flush
= 0;
4299 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
4300 /* send RECOVERY event for ALL nodes that match RSCN payload */
4301 lpfc_rscn_recovery_check(vport
);
4302 spin_lock_irq(shost
->host_lock
);
4303 vport
->fc_flag
&= ~FC_RSCN_DEFERRED
;
4304 spin_unlock_irq(shost
->host_lock
);
4307 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
4308 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
4309 ndlp
->nlp_DID
, vport
->port_state
, ndlp
->nlp_flag
);
4311 spin_lock_irq(shost
->host_lock
);
4312 vport
->fc_flag
|= FC_RSCN_MODE
;
4313 spin_unlock_irq(shost
->host_lock
);
4314 vport
->fc_rscn_id_list
[vport
->fc_rscn_id_cnt
++] = pcmd
;
4315 /* Indicate we are done walking fc_rscn_id_list on this vport */
4316 vport
->fc_rscn_flush
= 0;
4318 * If we zero, cmdiocb->context2, the calling routine will
4319 * not try to free it.
4321 cmdiocb
->context2
= NULL
;
4322 lpfc_set_disctmo(vport
);
4324 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
4325 /* send RECOVERY event for ALL nodes that match RSCN payload */
4326 lpfc_rscn_recovery_check(vport
);
4327 return lpfc_els_handle_rscn(vport
);
4331 * lpfc_els_handle_rscn - Handle rscn for a vport
4332 * @vport: pointer to a host virtual N_Port data structure.
4334 * This routine handles the Registration State Configuration Notification
4335 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
4336 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
4337 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
4338 * NameServer shall be issued. If CT command to the NameServer fails to be
4339 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
4340 * RSCN activities with the @vport.
4343 * 0 - Cleaned up rscn on the @vport
4344 * 1 - Wait for plogi to name server before proceed
4347 lpfc_els_handle_rscn(struct lpfc_vport
*vport
)
4349 struct lpfc_nodelist
*ndlp
;
4350 struct lpfc_hba
*phba
= vport
->phba
;
4352 /* Ignore RSCN if the port is being torn down. */
4353 if (vport
->load_flag
& FC_UNLOADING
) {
4354 lpfc_els_flush_rscn(vport
);
4358 /* Start timer for RSCN processing */
4359 lpfc_set_disctmo(vport
);
4361 /* RSCN processed */
4362 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
4363 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
4364 vport
->fc_flag
, 0, vport
->fc_rscn_id_cnt
,
4367 /* To process RSCN, first compare RSCN data with NameServer */
4368 vport
->fc_ns_retry
= 0;
4369 vport
->num_disc_nodes
= 0;
4371 ndlp
= lpfc_findnode_did(vport
, NameServer_DID
);
4372 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
)
4373 && ndlp
->nlp_state
== NLP_STE_UNMAPPED_NODE
) {
4374 /* Good ndlp, issue CT Request to NameServer */
4375 if (lpfc_ns_cmd(vport
, SLI_CTNS_GID_FT
, 0, 0) == 0)
4376 /* Wait for NameServer query cmpl before we can
4380 /* If login to NameServer does not exist, issue one */
4381 /* Good status, issue PLOGI to NameServer */
4382 ndlp
= lpfc_findnode_did(vport
, NameServer_DID
);
4383 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
))
4384 /* Wait for NameServer login cmpl before we can
4389 ndlp
= lpfc_enable_node(vport
, ndlp
,
4390 NLP_STE_PLOGI_ISSUE
);
4392 lpfc_els_flush_rscn(vport
);
4395 ndlp
->nlp_prev_state
= NLP_STE_UNUSED_NODE
;
4397 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
4399 lpfc_els_flush_rscn(vport
);
4402 lpfc_nlp_init(vport
, ndlp
, NameServer_DID
);
4403 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
4404 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
4406 ndlp
->nlp_type
|= NLP_FABRIC
;
4407 lpfc_issue_els_plogi(vport
, NameServer_DID
, 0);
4408 /* Wait for NameServer login cmpl before we can
4414 lpfc_els_flush_rscn(vport
);
4419 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
4420 * @vport: pointer to a host virtual N_Port data structure.
4421 * @cmdiocb: pointer to lpfc command iocb data structure.
4422 * @ndlp: pointer to a node-list data structure.
4424 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
4425 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
4426 * point topology. As an unsolicited FLOGI should not be received in a loop
4427 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
4428 * lpfc_check_sparm() routine is invoked to check the parameters in the
4429 * unsolicited FLOGI. If parameters validation failed, the routine
4430 * lpfc_els_rsp_reject() shall be called with reject reason code set to
4431 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
4432 * FLOGI shall be compared with the Port WWN of the @vport to determine who
4433 * will initiate PLOGI. The higher lexicographical value party shall has
4434 * higher priority (as the winning port) and will initiate PLOGI and
4435 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
4436 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
4437 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
4440 * 0 - Successfully processed the unsolicited flogi
4441 * 1 - Failed to process the unsolicited flogi
4444 lpfc_els_rcv_flogi(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
4445 struct lpfc_nodelist
*ndlp
)
4447 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4448 struct lpfc_hba
*phba
= vport
->phba
;
4449 struct lpfc_dmabuf
*pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
4450 uint32_t *lp
= (uint32_t *) pcmd
->virt
;
4451 IOCB_t
*icmd
= &cmdiocb
->iocb
;
4452 struct serv_parm
*sp
;
4459 sp
= (struct serv_parm
*) lp
;
4461 /* FLOGI received */
4463 lpfc_set_disctmo(vport
);
4465 if (phba
->fc_topology
== TOPOLOGY_LOOP
) {
4466 /* We should never receive a FLOGI in loop mode, ignore it */
4467 did
= icmd
->un
.elsreq64
.remoteID
;
4469 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
4471 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
4472 "0113 An FLOGI ELS command x%x was "
4473 "received from DID x%x in Loop Mode\n",
4480 if ((lpfc_check_sparm(vport
, ndlp
, sp
, CLASS3
, 1))) {
4481 /* For a FLOGI we accept, then if our portname is greater
4482 * then the remote portname we initiate Nport login.
4485 rc
= memcmp(&vport
->fc_portname
, &sp
->portName
,
4486 sizeof(struct lpfc_name
));
4489 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4493 lpfc_linkdown(phba
);
4494 lpfc_init_link(phba
, mbox
,
4496 phba
->cfg_link_speed
);
4497 mbox
->u
.mb
.un
.varInitLnk
.lipsr_AL_PA
= 0;
4498 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
4499 mbox
->vport
= vport
;
4500 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
4501 lpfc_set_loopback_flag(phba
);
4502 if (rc
== MBX_NOT_FINISHED
) {
4503 mempool_free(mbox
, phba
->mbox_mem_pool
);
4506 } else if (rc
> 0) { /* greater than */
4507 spin_lock_irq(shost
->host_lock
);
4508 vport
->fc_flag
|= FC_PT2PT_PLOGI
;
4509 spin_unlock_irq(shost
->host_lock
);
4511 spin_lock_irq(shost
->host_lock
);
4512 vport
->fc_flag
|= FC_PT2PT
;
4513 vport
->fc_flag
&= ~(FC_FABRIC
| FC_PUBLIC_LOOP
);
4514 spin_unlock_irq(shost
->host_lock
);
4516 /* Reject this request because invalid parameters */
4517 stat
.un
.b
.lsRjtRsvd0
= 0;
4518 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
4519 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_SPARM_OPTIONS
;
4520 stat
.un
.b
.vendorUnique
= 0;
4521 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
,
4527 lpfc_els_rsp_acc(vport
, ELS_CMD_PLOGI
, cmdiocb
, ndlp
, NULL
);
4533 * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
4534 * @vport: pointer to a host virtual N_Port data structure.
4535 * @cmdiocb: pointer to lpfc command iocb data structure.
4536 * @ndlp: pointer to a node-list data structure.
4538 * This routine processes Request Node Identification Data (RNID) IOCB
4539 * received as an ELS unsolicited event. Only when the RNID specified format
4540 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
4541 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
4542 * Accept (ACC) the RNID ELS command. All the other RNID formats are
4543 * rejected by invoking the lpfc_els_rsp_reject() routine.
4546 * 0 - Successfully processed rnid iocb (currently always return 0)
4549 lpfc_els_rcv_rnid(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
4550 struct lpfc_nodelist
*ndlp
)
4552 struct lpfc_dmabuf
*pcmd
;
4559 icmd
= &cmdiocb
->iocb
;
4560 did
= icmd
->un
.elsreq64
.remoteID
;
4561 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
4562 lp
= (uint32_t *) pcmd
->virt
;
4569 switch (rn
->Format
) {
4571 case RNID_TOPOLOGY_DISC
:
4573 lpfc_els_rsp_rnid_acc(vport
, rn
->Format
, cmdiocb
, ndlp
);
4576 /* Reject this request because format not supported */
4577 stat
.un
.b
.lsRjtRsvd0
= 0;
4578 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
4579 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_CANT_GIVE_DATA
;
4580 stat
.un
.b
.vendorUnique
= 0;
4581 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
,
4588 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
4589 * @vport: pointer to a host virtual N_Port data structure.
4590 * @cmdiocb: pointer to lpfc command iocb data structure.
4591 * @ndlp: pointer to a node-list data structure.
4593 * This routine processes a Link Incident Report Registration(LIRR) IOCB
4594 * received as an ELS unsolicited event. Currently, this function just invokes
4595 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
4598 * 0 - Successfully processed lirr iocb (currently always return 0)
4601 lpfc_els_rcv_lirr(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
4602 struct lpfc_nodelist
*ndlp
)
4606 /* For now, unconditionally reject this command */
4607 stat
.un
.b
.lsRjtRsvd0
= 0;
4608 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
4609 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_CANT_GIVE_DATA
;
4610 stat
.un
.b
.vendorUnique
= 0;
4611 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
4616 * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb
4617 * @vport: pointer to a host virtual N_Port data structure.
4618 * @cmdiocb: pointer to lpfc command iocb data structure.
4619 * @ndlp: pointer to a node-list data structure.
4621 * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB
4622 * received as an ELS unsolicited event. A request to RRQ shall only
4623 * be accepted if the Originator Nx_Port N_Port_ID or the Responder
4624 * Nx_Port N_Port_ID of the target Exchange is the same as the
4625 * N_Port_ID of the Nx_Port that makes the request. If the RRQ is
4626 * not accepted, an LS_RJT with reason code "Unable to perform
4627 * command request" and reason code explanation "Invalid Originator
4628 * S_ID" shall be returned. For now, we just unconditionally accept
4629 * RRQ from the target.
4632 lpfc_els_rcv_rrq(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
4633 struct lpfc_nodelist
*ndlp
)
4635 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
4639 * lpfc_els_rsp_rps_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
4640 * @phba: pointer to lpfc hba data structure.
4641 * @pmb: pointer to the driver internal queue element for mailbox command.
4643 * This routine is the completion callback function for the MBX_READ_LNK_STAT
4644 * mailbox command. This callback function is to actually send the Accept
4645 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
4646 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
4647 * mailbox command, constructs the RPS response with the link statistics
4648 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
4649 * response to the RPS.
4651 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4652 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4653 * will be stored into the context1 field of the IOCB for the completion
4654 * callback function to the RPS Accept Response ELS IOCB command.
4658 lpfc_els_rsp_rps_acc(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
4664 struct lpfc_iocbq
*elsiocb
;
4665 struct lpfc_nodelist
*ndlp
;
4666 uint16_t xri
, status
;
4671 ndlp
= (struct lpfc_nodelist
*) pmb
->context2
;
4672 xri
= (uint16_t) ((unsigned long)(pmb
->context1
));
4673 pmb
->context1
= NULL
;
4674 pmb
->context2
= NULL
;
4676 if (mb
->mbxStatus
) {
4677 mempool_free(pmb
, phba
->mbox_mem_pool
);
4681 cmdsize
= sizeof(RPS_RSP
) + sizeof(uint32_t);
4682 mempool_free(pmb
, phba
->mbox_mem_pool
);
4683 elsiocb
= lpfc_prep_els_iocb(phba
->pport
, 0, cmdsize
,
4684 lpfc_max_els_tries
, ndlp
,
4685 ndlp
->nlp_DID
, ELS_CMD_ACC
);
4687 /* Decrement the ndlp reference count from previous mbox command */
4693 icmd
= &elsiocb
->iocb
;
4694 icmd
->ulpContext
= xri
;
4696 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
4697 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
4698 pcmd
+= sizeof(uint32_t); /* Skip past command */
4699 rps_rsp
= (RPS_RSP
*)pcmd
;
4701 if (phba
->fc_topology
!= TOPOLOGY_LOOP
)
4705 if (phba
->pport
->fc_flag
& FC_FABRIC
)
4709 rps_rsp
->portStatus
= cpu_to_be16(status
);
4710 rps_rsp
->linkFailureCnt
= cpu_to_be32(mb
->un
.varRdLnk
.linkFailureCnt
);
4711 rps_rsp
->lossSyncCnt
= cpu_to_be32(mb
->un
.varRdLnk
.lossSyncCnt
);
4712 rps_rsp
->lossSignalCnt
= cpu_to_be32(mb
->un
.varRdLnk
.lossSignalCnt
);
4713 rps_rsp
->primSeqErrCnt
= cpu_to_be32(mb
->un
.varRdLnk
.primSeqErrCnt
);
4714 rps_rsp
->invalidXmitWord
= cpu_to_be32(mb
->un
.varRdLnk
.invalidXmitWord
);
4715 rps_rsp
->crcCnt
= cpu_to_be32(mb
->un
.varRdLnk
.crcCnt
);
4716 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
4717 lpfc_printf_vlog(ndlp
->vport
, KERN_INFO
, LOG_ELS
,
4718 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
4719 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
4720 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
,
4721 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
4723 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
4724 phba
->fc_stat
.elsXmitACC
++;
4725 if (lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0) == IOCB_ERROR
)
4726 lpfc_els_free_iocb(phba
, elsiocb
);
4731 * lpfc_els_rcv_rps - Process an unsolicited rps iocb
4732 * @vport: pointer to a host virtual N_Port data structure.
4733 * @cmdiocb: pointer to lpfc command iocb data structure.
4734 * @ndlp: pointer to a node-list data structure.
4736 * This routine processes Read Port Status (RPS) IOCB received as an
4737 * ELS unsolicited event. It first checks the remote port state. If the
4738 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
4739 * state, it invokes the lpfc_els_rsp_reject() routine to send the reject
4740 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
4741 * for reading the HBA link statistics. It is for the callback function,
4742 * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command
4743 * to actually sending out RPS Accept (ACC) response.
4746 * 0 - Successfully processed rps iocb (currently always return 0)
4749 lpfc_els_rcv_rps(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
4750 struct lpfc_nodelist
*ndlp
)
4752 struct lpfc_hba
*phba
= vport
->phba
;
4756 struct lpfc_dmabuf
*pcmd
;
4760 if ((ndlp
->nlp_state
!= NLP_STE_UNMAPPED_NODE
) &&
4761 (ndlp
->nlp_state
!= NLP_STE_MAPPED_NODE
))
4762 /* reject the unsolicited RPS request and done with it */
4765 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
4766 lp
= (uint32_t *) pcmd
->virt
;
4767 flag
= (be32_to_cpu(*lp
++) & 0xf);
4771 ((flag
== 1) && (be32_to_cpu(rps
->un
.portNum
) == 0)) ||
4772 ((flag
== 2) && (memcmp(&rps
->un
.portName
, &vport
->fc_portname
,
4773 sizeof(struct lpfc_name
)) == 0))) {
4775 printk("Fix me....\n");
4777 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_ATOMIC
);
4779 lpfc_read_lnk_stat(phba
, mbox
);
4781 (void *)((unsigned long) cmdiocb
->iocb
.ulpContext
);
4782 mbox
->context2
= lpfc_nlp_get(ndlp
);
4783 mbox
->vport
= vport
;
4784 mbox
->mbox_cmpl
= lpfc_els_rsp_rps_acc
;
4785 if (lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
)
4786 != MBX_NOT_FINISHED
)
4787 /* Mbox completion will send ELS Response */
4789 /* Decrement reference count used for the failed mbox
4793 mempool_free(mbox
, phba
->mbox_mem_pool
);
4798 /* issue rejection response */
4799 stat
.un
.b
.lsRjtRsvd0
= 0;
4800 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
4801 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_CANT_GIVE_DATA
;
4802 stat
.un
.b
.vendorUnique
= 0;
4803 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
4808 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
4809 * @vport: pointer to a host virtual N_Port data structure.
4810 * @cmdsize: size of the ELS command.
4811 * @oldiocb: pointer to the original lpfc command iocb data structure.
4812 * @ndlp: pointer to a node-list data structure.
4814 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
4815 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
4817 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4818 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4819 * will be stored into the context1 field of the IOCB for the completion
4820 * callback function to the RPL Accept Response ELS command.
4823 * 0 - Successfully issued ACC RPL ELS command
4824 * 1 - Failed to issue ACC RPL ELS command
4827 lpfc_els_rsp_rpl_acc(struct lpfc_vport
*vport
, uint16_t cmdsize
,
4828 struct lpfc_iocbq
*oldiocb
, struct lpfc_nodelist
*ndlp
)
4830 struct lpfc_hba
*phba
= vport
->phba
;
4831 IOCB_t
*icmd
, *oldcmd
;
4833 struct lpfc_iocbq
*elsiocb
;
4836 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
, ndlp
,
4837 ndlp
->nlp_DID
, ELS_CMD_ACC
);
4842 icmd
= &elsiocb
->iocb
;
4843 oldcmd
= &oldiocb
->iocb
;
4844 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri */
4846 pcmd
= (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
4847 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
4848 pcmd
+= sizeof(uint16_t);
4849 *((uint16_t *)(pcmd
)) = be16_to_cpu(cmdsize
);
4850 pcmd
+= sizeof(uint16_t);
4852 /* Setup the RPL ACC payload */
4853 rpl_rsp
.listLen
= be32_to_cpu(1);
4855 rpl_rsp
.port_num_blk
.portNum
= 0;
4856 rpl_rsp
.port_num_blk
.portID
= be32_to_cpu(vport
->fc_myDID
);
4857 memcpy(&rpl_rsp
.port_num_blk
.portName
, &vport
->fc_portname
,
4858 sizeof(struct lpfc_name
));
4859 memcpy(pcmd
, &rpl_rsp
, cmdsize
- sizeof(uint32_t));
4860 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
4861 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
4862 "0120 Xmit ELS RPL ACC response tag x%x "
4863 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
4865 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
,
4866 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
4868 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
4869 phba
->fc_stat
.elsXmitACC
++;
4870 if (lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0) ==
4872 lpfc_els_free_iocb(phba
, elsiocb
);
4879 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
4880 * @vport: pointer to a host virtual N_Port data structure.
4881 * @cmdiocb: pointer to lpfc command iocb data structure.
4882 * @ndlp: pointer to a node-list data structure.
4884 * This routine processes Read Port List (RPL) IOCB received as an ELS
4885 * unsolicited event. It first checks the remote port state. If the remote
4886 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
4887 * invokes the lpfc_els_rsp_reject() routine to send reject response.
4888 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
4889 * to accept the RPL.
4892 * 0 - Successfully processed rpl iocb (currently always return 0)
4895 lpfc_els_rcv_rpl(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
4896 struct lpfc_nodelist
*ndlp
)
4898 struct lpfc_dmabuf
*pcmd
;
4905 if ((ndlp
->nlp_state
!= NLP_STE_UNMAPPED_NODE
) &&
4906 (ndlp
->nlp_state
!= NLP_STE_MAPPED_NODE
)) {
4907 /* issue rejection response */
4908 stat
.un
.b
.lsRjtRsvd0
= 0;
4909 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
4910 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_CANT_GIVE_DATA
;
4911 stat
.un
.b
.vendorUnique
= 0;
4912 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
,
4914 /* rejected the unsolicited RPL request and done with it */
4918 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
4919 lp
= (uint32_t *) pcmd
->virt
;
4920 rpl
= (RPL
*) (lp
+ 1);
4922 maxsize
= be32_to_cpu(rpl
->maxsize
);
4924 /* We support only one port */
4925 if ((rpl
->index
== 0) &&
4927 ((maxsize
* sizeof(uint32_t)) >= sizeof(RPL_RSP
)))) {
4928 cmdsize
= sizeof(uint32_t) + sizeof(RPL_RSP
);
4930 cmdsize
= sizeof(uint32_t) + maxsize
* sizeof(uint32_t);
4932 lpfc_els_rsp_rpl_acc(vport
, cmdsize
, cmdiocb
, ndlp
);
4938 * lpfc_els_rcv_farp - Process an unsolicited farp request els command
4939 * @vport: pointer to a virtual N_Port data structure.
4940 * @cmdiocb: pointer to lpfc command iocb data structure.
4941 * @ndlp: pointer to a node-list data structure.
4943 * This routine processes Fibre Channel Address Resolution Protocol
4944 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
4945 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
4946 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
4947 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
4948 * remote PortName is compared against the FC PortName stored in the @vport
4949 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
4950 * compared against the FC NodeName stored in the @vport data structure.
4951 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
4952 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
4953 * invoked to send out FARP Response to the remote node. Before sending the
4954 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
4955 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
4956 * routine is invoked to log into the remote port first.
4959 * 0 - Either the FARP Match Mode not supported or successfully processed
4962 lpfc_els_rcv_farp(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
4963 struct lpfc_nodelist
*ndlp
)
4965 struct lpfc_dmabuf
*pcmd
;
4969 uint32_t cmd
, cnt
, did
;
4971 icmd
= &cmdiocb
->iocb
;
4972 did
= icmd
->un
.elsreq64
.remoteID
;
4973 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
4974 lp
= (uint32_t *) pcmd
->virt
;
4978 /* FARP-REQ received from DID <did> */
4979 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
4980 "0601 FARP-REQ received from DID x%x\n", did
);
4981 /* We will only support match on WWPN or WWNN */
4982 if (fp
->Mflags
& ~(FARP_MATCH_NODE
| FARP_MATCH_PORT
)) {
4987 /* If this FARP command is searching for my portname */
4988 if (fp
->Mflags
& FARP_MATCH_PORT
) {
4989 if (memcmp(&fp
->RportName
, &vport
->fc_portname
,
4990 sizeof(struct lpfc_name
)) == 0)
4994 /* If this FARP command is searching for my nodename */
4995 if (fp
->Mflags
& FARP_MATCH_NODE
) {
4996 if (memcmp(&fp
->RnodeName
, &vport
->fc_nodename
,
4997 sizeof(struct lpfc_name
)) == 0)
5002 if ((ndlp
->nlp_state
== NLP_STE_UNMAPPED_NODE
) ||
5003 (ndlp
->nlp_state
== NLP_STE_MAPPED_NODE
)) {
5004 /* Log back into the node before sending the FARP. */
5005 if (fp
->Rflags
& FARP_REQUEST_PLOGI
) {
5006 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
5007 lpfc_nlp_set_state(vport
, ndlp
,
5008 NLP_STE_PLOGI_ISSUE
);
5009 lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, 0);
5012 /* Send a FARP response to that node */
5013 if (fp
->Rflags
& FARP_REQUEST_FARPR
)
5014 lpfc_issue_els_farpr(vport
, did
, 0);
5021 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
5022 * @vport: pointer to a host virtual N_Port data structure.
5023 * @cmdiocb: pointer to lpfc command iocb data structure.
5024 * @ndlp: pointer to a node-list data structure.
5026 * This routine processes Fibre Channel Address Resolution Protocol
5027 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
5028 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
5029 * the FARP response request.
5032 * 0 - Successfully processed FARPR IOCB (currently always return 0)
5035 lpfc_els_rcv_farpr(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
5036 struct lpfc_nodelist
*ndlp
)
5038 struct lpfc_dmabuf
*pcmd
;
5043 icmd
= &cmdiocb
->iocb
;
5044 did
= icmd
->un
.elsreq64
.remoteID
;
5045 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
5046 lp
= (uint32_t *) pcmd
->virt
;
5049 /* FARP-RSP received from DID <did> */
5050 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
5051 "0600 FARP-RSP received from DID x%x\n", did
);
5052 /* ACCEPT the Farp resp request */
5053 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
5059 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
5060 * @vport: pointer to a host virtual N_Port data structure.
5061 * @cmdiocb: pointer to lpfc command iocb data structure.
5062 * @fan_ndlp: pointer to a node-list data structure.
5064 * This routine processes a Fabric Address Notification (FAN) IOCB
5065 * command received as an ELS unsolicited event. The FAN ELS command will
5066 * only be processed on a physical port (i.e., the @vport represents the
5067 * physical port). The fabric NodeName and PortName from the FAN IOCB are
5068 * compared against those in the phba data structure. If any of those is
5069 * different, the lpfc_initial_flogi() routine is invoked to initialize
5070 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
5071 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
5072 * is invoked to register login to the fabric.
5075 * 0 - Successfully processed fan iocb (currently always return 0).
5078 lpfc_els_rcv_fan(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
5079 struct lpfc_nodelist
*fan_ndlp
)
5081 struct lpfc_hba
*phba
= vport
->phba
;
5085 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
, "0265 FAN received\n");
5086 lp
= (uint32_t *)((struct lpfc_dmabuf
*)cmdiocb
->context2
)->virt
;
5088 /* FAN received; Fan does not have a reply sequence */
5089 if ((vport
== phba
->pport
) &&
5090 (vport
->port_state
== LPFC_LOCAL_CFG_LINK
)) {
5091 if ((memcmp(&phba
->fc_fabparam
.nodeName
, &fp
->FnodeName
,
5092 sizeof(struct lpfc_name
))) ||
5093 (memcmp(&phba
->fc_fabparam
.portName
, &fp
->FportName
,
5094 sizeof(struct lpfc_name
)))) {
5095 /* This port has switched fabrics. FLOGI is required */
5096 lpfc_initial_flogi(vport
);
5098 /* FAN verified - skip FLOGI */
5099 vport
->fc_myDID
= vport
->fc_prevDID
;
5100 if (phba
->sli_rev
< LPFC_SLI_REV4
)
5101 lpfc_issue_fabric_reglogin(vport
);
5103 lpfc_issue_reg_vfi(vport
);
5110 * lpfc_els_timeout - Handler funciton to the els timer
5111 * @ptr: holder for the timer function associated data.
5113 * This routine is invoked by the ELS timer after timeout. It posts the ELS
5114 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
5115 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
5116 * up the worker thread. It is for the worker thread to invoke the routine
5117 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
5120 lpfc_els_timeout(unsigned long ptr
)
5122 struct lpfc_vport
*vport
= (struct lpfc_vport
*) ptr
;
5123 struct lpfc_hba
*phba
= vport
->phba
;
5124 uint32_t tmo_posted
;
5125 unsigned long iflag
;
5127 spin_lock_irqsave(&vport
->work_port_lock
, iflag
);
5128 tmo_posted
= vport
->work_port_events
& WORKER_ELS_TMO
;
5130 vport
->work_port_events
|= WORKER_ELS_TMO
;
5131 spin_unlock_irqrestore(&vport
->work_port_lock
, iflag
);
5134 lpfc_worker_wake_up(phba
);
5139 * lpfc_els_timeout_handler - Process an els timeout event
5140 * @vport: pointer to a virtual N_Port data structure.
5142 * This routine is the actual handler function that processes an ELS timeout
5143 * event. It walks the ELS ring to get and abort all the IOCBs (except the
5144 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
5145 * invoking the lpfc_sli_issue_abort_iotag() routine.
5148 lpfc_els_timeout_handler(struct lpfc_vport
*vport
)
5150 struct lpfc_hba
*phba
= vport
->phba
;
5151 struct lpfc_sli_ring
*pring
;
5152 struct lpfc_iocbq
*tmp_iocb
, *piocb
;
5154 struct lpfc_dmabuf
*pcmd
;
5155 uint32_t els_command
= 0;
5157 uint32_t remote_ID
= 0xffffffff;
5159 spin_lock_irq(&phba
->hbalock
);
5160 timeout
= (uint32_t)(phba
->fc_ratov
<< 1);
5162 pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
5164 list_for_each_entry_safe(piocb
, tmp_iocb
, &pring
->txcmplq
, list
) {
5167 if ((piocb
->iocb_flag
& LPFC_IO_LIBDFC
) != 0 ||
5168 piocb
->iocb
.ulpCommand
== CMD_ABORT_XRI_CN
||
5169 piocb
->iocb
.ulpCommand
== CMD_CLOSE_XRI_CN
)
5172 if (piocb
->vport
!= vport
)
5175 pcmd
= (struct lpfc_dmabuf
*) piocb
->context2
;
5177 els_command
= *(uint32_t *) (pcmd
->virt
);
5179 if (els_command
== ELS_CMD_FARP
||
5180 els_command
== ELS_CMD_FARPR
||
5181 els_command
== ELS_CMD_FDISC
)
5184 if (piocb
->drvrTimeout
> 0) {
5185 if (piocb
->drvrTimeout
>= timeout
)
5186 piocb
->drvrTimeout
-= timeout
;
5188 piocb
->drvrTimeout
= 0;
5192 remote_ID
= 0xffffffff;
5193 if (cmd
->ulpCommand
!= CMD_GEN_REQUEST64_CR
)
5194 remote_ID
= cmd
->un
.elsreq64
.remoteID
;
5196 struct lpfc_nodelist
*ndlp
;
5197 ndlp
= __lpfc_findnode_rpi(vport
, cmd
->ulpContext
);
5198 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
))
5199 remote_ID
= ndlp
->nlp_DID
;
5201 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
5202 "0127 ELS timeout Data: x%x x%x x%x "
5203 "x%x\n", els_command
,
5204 remote_ID
, cmd
->ulpCommand
, cmd
->ulpIoTag
);
5205 lpfc_sli_issue_abort_iotag(phba
, pring
, piocb
);
5207 spin_unlock_irq(&phba
->hbalock
);
5209 if (phba
->sli
.ring
[LPFC_ELS_RING
].txcmplq_cnt
)
5210 mod_timer(&vport
->els_tmofunc
, jiffies
+ HZ
* timeout
);
5214 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
5215 * @vport: pointer to a host virtual N_Port data structure.
5217 * This routine is used to clean up all the outstanding ELS commands on a
5218 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
5219 * routine. After that, it walks the ELS transmit queue to remove all the
5220 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
5221 * the IOCBs with a non-NULL completion callback function, the callback
5222 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
5223 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
5224 * callback function, the IOCB will simply be released. Finally, it walks
5225 * the ELS transmit completion queue to issue an abort IOCB to any transmit
5226 * completion queue IOCB that is associated with the @vport and is not
5227 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
5228 * part of the discovery state machine) out to HBA by invoking the
5229 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
5230 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
5231 * the IOCBs are aborted when this function returns.
5234 lpfc_els_flush_cmd(struct lpfc_vport
*vport
)
5236 LIST_HEAD(completions
);
5237 struct lpfc_hba
*phba
= vport
->phba
;
5238 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
5239 struct lpfc_iocbq
*tmp_iocb
, *piocb
;
5242 lpfc_fabric_abort_vport(vport
);
5244 spin_lock_irq(&phba
->hbalock
);
5245 list_for_each_entry_safe(piocb
, tmp_iocb
, &pring
->txq
, list
) {
5248 if (piocb
->iocb_flag
& LPFC_IO_LIBDFC
) {
5252 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
5253 if (cmd
->ulpCommand
== CMD_QUE_RING_BUF_CN
||
5254 cmd
->ulpCommand
== CMD_QUE_RING_BUF64_CN
||
5255 cmd
->ulpCommand
== CMD_CLOSE_XRI_CN
||
5256 cmd
->ulpCommand
== CMD_ABORT_XRI_CN
)
5259 if (piocb
->vport
!= vport
)
5262 list_move_tail(&piocb
->list
, &completions
);
5266 list_for_each_entry_safe(piocb
, tmp_iocb
, &pring
->txcmplq
, list
) {
5267 if (piocb
->iocb_flag
& LPFC_IO_LIBDFC
) {
5271 if (piocb
->vport
!= vport
)
5274 lpfc_sli_issue_abort_iotag(phba
, pring
, piocb
);
5276 spin_unlock_irq(&phba
->hbalock
);
5278 /* Cancell all the IOCBs from the completions list */
5279 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
5286 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
5287 * @phba: pointer to lpfc hba data structure.
5289 * This routine is used to clean up all the outstanding ELS commands on a
5290 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
5291 * routine. After that, it walks the ELS transmit queue to remove all the
5292 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
5293 * the IOCBs with the completion callback function associated, the callback
5294 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
5295 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
5296 * callback function associated, the IOCB will simply be released. Finally,
5297 * it walks the ELS transmit completion queue to issue an abort IOCB to any
5298 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
5299 * management plane IOCBs that are not part of the discovery state machine)
5300 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
5303 lpfc_els_flush_all_cmd(struct lpfc_hba
*phba
)
5305 LIST_HEAD(completions
);
5306 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
5307 struct lpfc_iocbq
*tmp_iocb
, *piocb
;
5310 lpfc_fabric_abort_hba(phba
);
5311 spin_lock_irq(&phba
->hbalock
);
5312 list_for_each_entry_safe(piocb
, tmp_iocb
, &pring
->txq
, list
) {
5314 if (piocb
->iocb_flag
& LPFC_IO_LIBDFC
)
5316 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
5317 if (cmd
->ulpCommand
== CMD_QUE_RING_BUF_CN
||
5318 cmd
->ulpCommand
== CMD_QUE_RING_BUF64_CN
||
5319 cmd
->ulpCommand
== CMD_CLOSE_XRI_CN
||
5320 cmd
->ulpCommand
== CMD_ABORT_XRI_CN
)
5322 list_move_tail(&piocb
->list
, &completions
);
5325 list_for_each_entry_safe(piocb
, tmp_iocb
, &pring
->txcmplq
, list
) {
5326 if (piocb
->iocb_flag
& LPFC_IO_LIBDFC
)
5328 lpfc_sli_issue_abort_iotag(phba
, pring
, piocb
);
5330 spin_unlock_irq(&phba
->hbalock
);
5332 /* Cancel all the IOCBs from the completions list */
5333 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
5340 * lpfc_send_els_failure_event - Posts an ELS command failure event
5341 * @phba: Pointer to hba context object.
5342 * @cmdiocbp: Pointer to command iocb which reported error.
5343 * @rspiocbp: Pointer to response iocb which reported error.
5345 * This function sends an event when there is an ELS command
5349 lpfc_send_els_failure_event(struct lpfc_hba
*phba
,
5350 struct lpfc_iocbq
*cmdiocbp
,
5351 struct lpfc_iocbq
*rspiocbp
)
5353 struct lpfc_vport
*vport
= cmdiocbp
->vport
;
5354 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
5355 struct lpfc_lsrjt_event lsrjt_event
;
5356 struct lpfc_fabric_event_header fabric_event
;
5358 struct lpfc_nodelist
*ndlp
;
5361 ndlp
= cmdiocbp
->context1
;
5362 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
))
5365 if (rspiocbp
->iocb
.ulpStatus
== IOSTAT_LS_RJT
) {
5366 lsrjt_event
.header
.event_type
= FC_REG_ELS_EVENT
;
5367 lsrjt_event
.header
.subcategory
= LPFC_EVENT_LSRJT_RCV
;
5368 memcpy(lsrjt_event
.header
.wwpn
, &ndlp
->nlp_portname
,
5369 sizeof(struct lpfc_name
));
5370 memcpy(lsrjt_event
.header
.wwnn
, &ndlp
->nlp_nodename
,
5371 sizeof(struct lpfc_name
));
5372 pcmd
= (uint32_t *) (((struct lpfc_dmabuf
*)
5373 cmdiocbp
->context2
)->virt
);
5374 lsrjt_event
.command
= (pcmd
!= NULL
) ? *pcmd
: 0;
5375 stat
.un
.lsRjtError
= be32_to_cpu(rspiocbp
->iocb
.un
.ulpWord
[4]);
5376 lsrjt_event
.reason_code
= stat
.un
.b
.lsRjtRsnCode
;
5377 lsrjt_event
.explanation
= stat
.un
.b
.lsRjtRsnCodeExp
;
5378 fc_host_post_vendor_event(shost
,
5379 fc_get_event_number(),
5380 sizeof(lsrjt_event
),
5381 (char *)&lsrjt_event
,
5385 if ((rspiocbp
->iocb
.ulpStatus
== IOSTAT_NPORT_BSY
) ||
5386 (rspiocbp
->iocb
.ulpStatus
== IOSTAT_FABRIC_BSY
)) {
5387 fabric_event
.event_type
= FC_REG_FABRIC_EVENT
;
5388 if (rspiocbp
->iocb
.ulpStatus
== IOSTAT_NPORT_BSY
)
5389 fabric_event
.subcategory
= LPFC_EVENT_PORT_BUSY
;
5391 fabric_event
.subcategory
= LPFC_EVENT_FABRIC_BUSY
;
5392 memcpy(fabric_event
.wwpn
, &ndlp
->nlp_portname
,
5393 sizeof(struct lpfc_name
));
5394 memcpy(fabric_event
.wwnn
, &ndlp
->nlp_nodename
,
5395 sizeof(struct lpfc_name
));
5396 fc_host_post_vendor_event(shost
,
5397 fc_get_event_number(),
5398 sizeof(fabric_event
),
5399 (char *)&fabric_event
,
5407 * lpfc_send_els_event - Posts unsolicited els event
5408 * @vport: Pointer to vport object.
5409 * @ndlp: Pointer FC node object.
5410 * @cmd: ELS command code.
5412 * This function posts an event when there is an incoming
5413 * unsolicited ELS command.
5416 lpfc_send_els_event(struct lpfc_vport
*vport
,
5417 struct lpfc_nodelist
*ndlp
,
5420 struct lpfc_els_event_header
*els_data
= NULL
;
5421 struct lpfc_logo_event
*logo_data
= NULL
;
5422 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
5424 if (*payload
== ELS_CMD_LOGO
) {
5425 logo_data
= kmalloc(sizeof(struct lpfc_logo_event
), GFP_KERNEL
);
5427 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
5428 "0148 Failed to allocate memory "
5429 "for LOGO event\n");
5432 els_data
= &logo_data
->header
;
5434 els_data
= kmalloc(sizeof(struct lpfc_els_event_header
),
5437 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
5438 "0149 Failed to allocate memory "
5443 els_data
->event_type
= FC_REG_ELS_EVENT
;
5446 els_data
->subcategory
= LPFC_EVENT_PLOGI_RCV
;
5449 els_data
->subcategory
= LPFC_EVENT_PRLO_RCV
;
5452 els_data
->subcategory
= LPFC_EVENT_ADISC_RCV
;
5455 els_data
->subcategory
= LPFC_EVENT_LOGO_RCV
;
5456 /* Copy the WWPN in the LOGO payload */
5457 memcpy(logo_data
->logo_wwpn
, &payload
[2],
5458 sizeof(struct lpfc_name
));
5464 memcpy(els_data
->wwpn
, &ndlp
->nlp_portname
, sizeof(struct lpfc_name
));
5465 memcpy(els_data
->wwnn
, &ndlp
->nlp_nodename
, sizeof(struct lpfc_name
));
5466 if (*payload
== ELS_CMD_LOGO
) {
5467 fc_host_post_vendor_event(shost
,
5468 fc_get_event_number(),
5469 sizeof(struct lpfc_logo_event
),
5474 fc_host_post_vendor_event(shost
,
5475 fc_get_event_number(),
5476 sizeof(struct lpfc_els_event_header
),
5487 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
5488 * @phba: pointer to lpfc hba data structure.
5489 * @pring: pointer to a SLI ring.
5490 * @vport: pointer to a host virtual N_Port data structure.
5491 * @elsiocb: pointer to lpfc els command iocb data structure.
5493 * This routine is used for processing the IOCB associated with a unsolicited
5494 * event. It first determines whether there is an existing ndlp that matches
5495 * the DID from the unsolicited IOCB. If not, it will create a new one with
5496 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
5497 * IOCB is then used to invoke the proper routine and to set up proper state
5498 * of the discovery state machine.
5501 lpfc_els_unsol_buffer(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
5502 struct lpfc_vport
*vport
, struct lpfc_iocbq
*elsiocb
)
5504 struct Scsi_Host
*shost
;
5505 struct lpfc_nodelist
*ndlp
;
5508 uint32_t cmd
, did
, newnode
, rjt_err
= 0;
5509 IOCB_t
*icmd
= &elsiocb
->iocb
;
5511 if (!vport
|| !(elsiocb
->context2
))
5515 payload
= ((struct lpfc_dmabuf
*)elsiocb
->context2
)->virt
;
5517 if ((phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) == 0)
5518 lpfc_post_buffer(phba
, pring
, 1);
5520 did
= icmd
->un
.rcvels
.remoteID
;
5521 if (icmd
->ulpStatus
) {
5522 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
5523 "RCV Unsol ELS: status:x%x/x%x did:x%x",
5524 icmd
->ulpStatus
, icmd
->un
.ulpWord
[4], did
);
5528 /* Check to see if link went down during discovery */
5529 if (lpfc_els_chk_latt(vport
))
5532 /* Ignore traffic received during vport shutdown. */
5533 if (vport
->load_flag
& FC_UNLOADING
)
5536 ndlp
= lpfc_findnode_did(vport
, did
);
5538 /* Cannot find existing Fabric ndlp, so allocate a new one */
5539 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
5543 lpfc_nlp_init(vport
, ndlp
, did
);
5544 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
5546 if ((did
& Fabric_DID_MASK
) == Fabric_DID_MASK
)
5547 ndlp
->nlp_type
|= NLP_FABRIC
;
5548 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
5549 ndlp
= lpfc_enable_node(vport
, ndlp
,
5550 NLP_STE_UNUSED_NODE
);
5553 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
5555 if ((did
& Fabric_DID_MASK
) == Fabric_DID_MASK
)
5556 ndlp
->nlp_type
|= NLP_FABRIC
;
5557 } else if (ndlp
->nlp_state
== NLP_STE_UNUSED_NODE
) {
5558 /* This is similar to the new node path */
5559 ndlp
= lpfc_nlp_get(ndlp
);
5562 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
5566 phba
->fc_stat
.elsRcvFrame
++;
5568 elsiocb
->context1
= lpfc_nlp_get(ndlp
);
5569 elsiocb
->vport
= vport
;
5571 if ((cmd
& ELS_CMD_MASK
) == ELS_CMD_RSCN
) {
5572 cmd
&= ELS_CMD_MASK
;
5574 /* ELS command <elsCmd> received from NPORT <did> */
5575 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
5576 "0112 ELS command x%x received from NPORT x%x "
5577 "Data: x%x\n", cmd
, did
, vport
->port_state
);
5580 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
5581 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
5582 did
, vport
->port_state
, ndlp
->nlp_flag
);
5584 phba
->fc_stat
.elsRcvPLOGI
++;
5585 ndlp
= lpfc_plogi_confirm_nport(phba
, payload
, ndlp
);
5587 lpfc_send_els_event(vport
, ndlp
, payload
);
5588 if (vport
->port_state
< LPFC_DISC_AUTH
) {
5589 if (!(phba
->pport
->fc_flag
& FC_PT2PT
) ||
5590 (phba
->pport
->fc_flag
& FC_PT2PT_PLOGI
)) {
5591 rjt_err
= LSRJT_UNABLE_TPC
;
5594 /* We get here, and drop thru, if we are PT2PT with
5595 * another NPort and the other side has initiated
5596 * the PLOGI before responding to our FLOGI.
5600 shost
= lpfc_shost_from_vport(vport
);
5601 spin_lock_irq(shost
->host_lock
);
5602 ndlp
->nlp_flag
&= ~NLP_TARGET_REMOVE
;
5603 spin_unlock_irq(shost
->host_lock
);
5605 lpfc_disc_state_machine(vport
, ndlp
, elsiocb
,
5610 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
5611 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
5612 did
, vport
->port_state
, ndlp
->nlp_flag
);
5614 phba
->fc_stat
.elsRcvFLOGI
++;
5615 lpfc_els_rcv_flogi(vport
, elsiocb
, ndlp
);
5620 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
5621 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
5622 did
, vport
->port_state
, ndlp
->nlp_flag
);
5624 phba
->fc_stat
.elsRcvLOGO
++;
5625 lpfc_send_els_event(vport
, ndlp
, payload
);
5626 if (vport
->port_state
< LPFC_DISC_AUTH
) {
5627 rjt_err
= LSRJT_UNABLE_TPC
;
5630 lpfc_disc_state_machine(vport
, ndlp
, elsiocb
, NLP_EVT_RCV_LOGO
);
5633 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
5634 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
5635 did
, vport
->port_state
, ndlp
->nlp_flag
);
5637 phba
->fc_stat
.elsRcvPRLO
++;
5638 lpfc_send_els_event(vport
, ndlp
, payload
);
5639 if (vport
->port_state
< LPFC_DISC_AUTH
) {
5640 rjt_err
= LSRJT_UNABLE_TPC
;
5643 lpfc_disc_state_machine(vport
, ndlp
, elsiocb
, NLP_EVT_RCV_PRLO
);
5646 phba
->fc_stat
.elsRcvRSCN
++;
5647 lpfc_els_rcv_rscn(vport
, elsiocb
, ndlp
);
5652 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
5653 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
5654 did
, vport
->port_state
, ndlp
->nlp_flag
);
5656 lpfc_send_els_event(vport
, ndlp
, payload
);
5657 phba
->fc_stat
.elsRcvADISC
++;
5658 if (vport
->port_state
< LPFC_DISC_AUTH
) {
5659 rjt_err
= LSRJT_UNABLE_TPC
;
5662 lpfc_disc_state_machine(vport
, ndlp
, elsiocb
,
5666 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
5667 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
5668 did
, vport
->port_state
, ndlp
->nlp_flag
);
5670 phba
->fc_stat
.elsRcvPDISC
++;
5671 if (vport
->port_state
< LPFC_DISC_AUTH
) {
5672 rjt_err
= LSRJT_UNABLE_TPC
;
5675 lpfc_disc_state_machine(vport
, ndlp
, elsiocb
,
5679 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
5680 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
5681 did
, vport
->port_state
, ndlp
->nlp_flag
);
5683 phba
->fc_stat
.elsRcvFARPR
++;
5684 lpfc_els_rcv_farpr(vport
, elsiocb
, ndlp
);
5687 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
5688 "RCV FARP: did:x%x/ste:x%x flg:x%x",
5689 did
, vport
->port_state
, ndlp
->nlp_flag
);
5691 phba
->fc_stat
.elsRcvFARP
++;
5692 lpfc_els_rcv_farp(vport
, elsiocb
, ndlp
);
5695 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
5696 "RCV FAN: did:x%x/ste:x%x flg:x%x",
5697 did
, vport
->port_state
, ndlp
->nlp_flag
);
5699 phba
->fc_stat
.elsRcvFAN
++;
5700 lpfc_els_rcv_fan(vport
, elsiocb
, ndlp
);
5703 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
5704 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
5705 did
, vport
->port_state
, ndlp
->nlp_flag
);
5707 phba
->fc_stat
.elsRcvPRLI
++;
5708 if (vport
->port_state
< LPFC_DISC_AUTH
) {
5709 rjt_err
= LSRJT_UNABLE_TPC
;
5712 lpfc_disc_state_machine(vport
, ndlp
, elsiocb
, NLP_EVT_RCV_PRLI
);
5715 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
5716 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
5717 did
, vport
->port_state
, ndlp
->nlp_flag
);
5719 phba
->fc_stat
.elsRcvLIRR
++;
5720 lpfc_els_rcv_lirr(vport
, elsiocb
, ndlp
);
5725 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
5726 "RCV RPS: did:x%x/ste:x%x flg:x%x",
5727 did
, vport
->port_state
, ndlp
->nlp_flag
);
5729 phba
->fc_stat
.elsRcvRPS
++;
5730 lpfc_els_rcv_rps(vport
, elsiocb
, ndlp
);
5735 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
5736 "RCV RPL: did:x%x/ste:x%x flg:x%x",
5737 did
, vport
->port_state
, ndlp
->nlp_flag
);
5739 phba
->fc_stat
.elsRcvRPL
++;
5740 lpfc_els_rcv_rpl(vport
, elsiocb
, ndlp
);
5745 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
5746 "RCV RNID: did:x%x/ste:x%x flg:x%x",
5747 did
, vport
->port_state
, ndlp
->nlp_flag
);
5749 phba
->fc_stat
.elsRcvRNID
++;
5750 lpfc_els_rcv_rnid(vport
, elsiocb
, ndlp
);
5755 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
5756 "RCV RRQ: did:x%x/ste:x%x flg:x%x",
5757 did
, vport
->port_state
, ndlp
->nlp_flag
);
5759 phba
->fc_stat
.elsRcvRRQ
++;
5760 lpfc_els_rcv_rrq(vport
, elsiocb
, ndlp
);
5765 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
5766 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
5767 cmd
, did
, vport
->port_state
);
5769 /* Unsupported ELS command, reject */
5770 rjt_err
= LSRJT_INVALID_CMD
;
5772 /* Unknown ELS command <elsCmd> received from NPORT <did> */
5773 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
5774 "0115 Unknown ELS command x%x "
5775 "received from NPORT x%x\n", cmd
, did
);
5781 /* check if need to LS_RJT received ELS cmd */
5783 memset(&stat
, 0, sizeof(stat
));
5784 stat
.un
.b
.lsRjtRsnCode
= rjt_err
;
5785 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_NOTHING_MORE
;
5786 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, elsiocb
, ndlp
,
5790 lpfc_nlp_put(elsiocb
->context1
);
5791 elsiocb
->context1
= NULL
;
5795 if (vport
&& !(vport
->load_flag
& FC_UNLOADING
))
5796 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
5797 "0111 Dropping received ELS cmd "
5798 "Data: x%x x%x x%x\n",
5799 icmd
->ulpStatus
, icmd
->un
.ulpWord
[4], icmd
->ulpTimeout
);
5800 phba
->fc_stat
.elsRcvDrop
++;
5804 * lpfc_find_vport_by_vpid - Find a vport on a HBA through vport identifier
5805 * @phba: pointer to lpfc hba data structure.
5806 * @vpi: host virtual N_Port identifier.
5808 * This routine finds a vport on a HBA (referred by @phba) through a
5809 * @vpi. The function walks the HBA's vport list and returns the address
5810 * of the vport with the matching @vpi.
5813 * NULL - No vport with the matching @vpi found
5814 * Otherwise - Address to the vport with the matching @vpi.
5817 lpfc_find_vport_by_vpid(struct lpfc_hba
*phba
, uint16_t vpi
)
5819 struct lpfc_vport
*vport
;
5820 unsigned long flags
;
5822 spin_lock_irqsave(&phba
->hbalock
, flags
);
5823 list_for_each_entry(vport
, &phba
->port_list
, listentry
) {
5824 if (vport
->vpi
== vpi
) {
5825 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
5829 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
5834 * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
5835 * @phba: pointer to lpfc hba data structure.
5836 * @pring: pointer to a SLI ring.
5837 * @elsiocb: pointer to lpfc els iocb data structure.
5839 * This routine is used to process an unsolicited event received from a SLI
5840 * (Service Level Interface) ring. The actual processing of the data buffer
5841 * associated with the unsolicited event is done by invoking the routine
5842 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
5843 * SLI ring on which the unsolicited event was received.
5846 lpfc_els_unsol_event(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
5847 struct lpfc_iocbq
*elsiocb
)
5849 struct lpfc_vport
*vport
= phba
->pport
;
5850 IOCB_t
*icmd
= &elsiocb
->iocb
;
5852 struct lpfc_dmabuf
*bdeBuf1
= elsiocb
->context2
;
5853 struct lpfc_dmabuf
*bdeBuf2
= elsiocb
->context3
;
5855 elsiocb
->context1
= NULL
;
5856 elsiocb
->context2
= NULL
;
5857 elsiocb
->context3
= NULL
;
5859 if (icmd
->ulpStatus
== IOSTAT_NEED_BUFFER
) {
5860 lpfc_sli_hbqbuf_add_hbqs(phba
, LPFC_ELS_HBQ
);
5861 } else if (icmd
->ulpStatus
== IOSTAT_LOCAL_REJECT
&&
5862 (icmd
->un
.ulpWord
[4] & 0xff) == IOERR_RCV_BUFFER_WAITING
) {
5863 phba
->fc_stat
.NoRcvBuf
++;
5864 /* Not enough posted buffers; Try posting more buffers */
5865 if (!(phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
))
5866 lpfc_post_buffer(phba
, pring
, 0);
5870 if ((phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
5871 (icmd
->ulpCommand
== CMD_IOCB_RCV_ELS64_CX
||
5872 icmd
->ulpCommand
== CMD_IOCB_RCV_SEQ64_CX
)) {
5873 if (icmd
->unsli3
.rcvsli3
.vpi
== 0xffff)
5874 vport
= phba
->pport
;
5876 vport
= lpfc_find_vport_by_vpid(phba
,
5877 icmd
->unsli3
.rcvsli3
.vpi
- phba
->vpi_base
);
5879 /* If there are no BDEs associated
5880 * with this IOCB, there is nothing to do.
5882 if (icmd
->ulpBdeCount
== 0)
5885 /* type of ELS cmd is first 32bit word
5888 if (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) {
5889 elsiocb
->context2
= bdeBuf1
;
5891 paddr
= getPaddr(icmd
->un
.cont64
[0].addrHigh
,
5892 icmd
->un
.cont64
[0].addrLow
);
5893 elsiocb
->context2
= lpfc_sli_ringpostbuf_get(phba
, pring
,
5897 lpfc_els_unsol_buffer(phba
, pring
, vport
, elsiocb
);
5899 * The different unsolicited event handlers would tell us
5900 * if they are done with "mp" by setting context2 to NULL.
5902 if (elsiocb
->context2
) {
5903 lpfc_in_buf_free(phba
, (struct lpfc_dmabuf
*)elsiocb
->context2
);
5904 elsiocb
->context2
= NULL
;
5907 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
5908 if ((phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) &&
5909 icmd
->ulpBdeCount
== 2) {
5910 elsiocb
->context2
= bdeBuf2
;
5911 lpfc_els_unsol_buffer(phba
, pring
, vport
, elsiocb
);
5912 /* free mp if we are done with it */
5913 if (elsiocb
->context2
) {
5914 lpfc_in_buf_free(phba
, elsiocb
->context2
);
5915 elsiocb
->context2
= NULL
;
5921 * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
5922 * @phba: pointer to lpfc hba data structure.
5923 * @vport: pointer to a virtual N_Port data structure.
5925 * This routine issues a Port Login (PLOGI) to the Name Server with
5926 * State Change Request (SCR) for a @vport. This routine will create an
5927 * ndlp for the Name Server associated to the @vport if such node does
5928 * not already exist. The PLOGI to Name Server is issued by invoking the
5929 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
5930 * (FDMI) is configured to the @vport, a FDMI node will be created and
5931 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
5934 lpfc_do_scr_ns_plogi(struct lpfc_hba
*phba
, struct lpfc_vport
*vport
)
5936 struct lpfc_nodelist
*ndlp
, *ndlp_fdmi
;
5938 ndlp
= lpfc_findnode_did(vport
, NameServer_DID
);
5940 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
5942 if (phba
->fc_topology
== TOPOLOGY_LOOP
) {
5943 lpfc_disc_start(vport
);
5946 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
5947 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
5948 "0251 NameServer login: no memory\n");
5951 lpfc_nlp_init(vport
, ndlp
, NameServer_DID
);
5952 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
5953 ndlp
= lpfc_enable_node(vport
, ndlp
, NLP_STE_UNUSED_NODE
);
5955 if (phba
->fc_topology
== TOPOLOGY_LOOP
) {
5956 lpfc_disc_start(vport
);
5959 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
5960 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
5961 "0348 NameServer login: node freed\n");
5965 ndlp
->nlp_type
|= NLP_FABRIC
;
5967 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
5969 if (lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, 0)) {
5970 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
5971 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
5972 "0252 Cannot issue NameServer login\n");
5976 if (vport
->cfg_fdmi_on
) {
5977 ndlp_fdmi
= mempool_alloc(phba
->nlp_mem_pool
,
5980 lpfc_nlp_init(vport
, ndlp_fdmi
, FDMI_DID
);
5981 ndlp_fdmi
->nlp_type
|= NLP_FABRIC
;
5982 lpfc_nlp_set_state(vport
, ndlp_fdmi
,
5983 NLP_STE_PLOGI_ISSUE
);
5984 lpfc_issue_els_plogi(vport
, ndlp_fdmi
->nlp_DID
,
5992 * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
5993 * @phba: pointer to lpfc hba data structure.
5994 * @pmb: pointer to the driver internal queue element for mailbox command.
5996 * This routine is the completion callback function to register new vport
5997 * mailbox command. If the new vport mailbox command completes successfully,
5998 * the fabric registration login shall be performed on physical port (the
5999 * new vport created is actually a physical port, with VPI 0) or the port
6000 * login to Name Server for State Change Request (SCR) will be performed
6001 * on virtual port (real virtual port, with VPI greater than 0).
6004 lpfc_cmpl_reg_new_vport(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
6006 struct lpfc_vport
*vport
= pmb
->vport
;
6007 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
6008 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) pmb
->context2
;
6009 MAILBOX_t
*mb
= &pmb
->u
.mb
;
6012 spin_lock_irq(shost
->host_lock
);
6013 vport
->fc_flag
&= ~FC_VPORT_NEEDS_REG_VPI
;
6014 spin_unlock_irq(shost
->host_lock
);
6016 if (mb
->mbxStatus
) {
6017 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
6018 "0915 Register VPI failed: 0x%x\n",
6021 switch (mb
->mbxStatus
) {
6022 case 0x11: /* unsupported feature */
6023 case 0x9603: /* max_vpi exceeded */
6024 case 0x9602: /* Link event since CLEAR_LA */
6025 /* giving up on vport registration */
6026 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
6027 spin_lock_irq(shost
->host_lock
);
6028 vport
->fc_flag
&= ~(FC_FABRIC
| FC_PUBLIC_LOOP
);
6029 spin_unlock_irq(shost
->host_lock
);
6030 lpfc_can_disctmo(vport
);
6032 /* If reg_vpi fail with invalid VPI status, re-init VPI */
6034 spin_lock_irq(shost
->host_lock
);
6035 vport
->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
6036 spin_unlock_irq(shost
->host_lock
);
6037 lpfc_init_vpi(phba
, pmb
, vport
->vpi
);
6039 pmb
->mbox_cmpl
= lpfc_init_vpi_cmpl
;
6040 rc
= lpfc_sli_issue_mbox(phba
, pmb
,
6042 if (rc
== MBX_NOT_FINISHED
) {
6043 lpfc_printf_vlog(vport
,
6045 "2732 Failed to issue INIT_VPI"
6046 " mailbox command\n");
6053 /* Try to recover from this error */
6054 lpfc_mbx_unreg_vpi(vport
);
6055 spin_lock_irq(shost
->host_lock
);
6056 vport
->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
6057 spin_unlock_irq(shost
->host_lock
);
6058 if (vport
->port_type
== LPFC_PHYSICAL_PORT
6059 && !(vport
->fc_flag
& FC_LOGO_RCVD_DID_CHNG
))
6060 lpfc_initial_flogi(vport
);
6062 lpfc_initial_fdisc(vport
);
6066 spin_lock_irq(shost
->host_lock
);
6067 vport
->vpi_state
|= LPFC_VPI_REGISTERED
;
6068 spin_unlock_irq(shost
->host_lock
);
6069 if (vport
== phba
->pport
) {
6070 if (phba
->sli_rev
< LPFC_SLI_REV4
)
6071 lpfc_issue_fabric_reglogin(vport
);
6074 * If the physical port is instantiated using
6075 * FDISC, do not start vport discovery.
6077 if (vport
->port_state
!= LPFC_FDISC
)
6078 lpfc_start_fdiscs(phba
);
6079 lpfc_do_scr_ns_plogi(phba
, vport
);
6082 lpfc_do_scr_ns_plogi(phba
, vport
);
6085 /* Now, we decrement the ndlp reference count held for this
6090 mempool_free(pmb
, phba
->mbox_mem_pool
);
6095 * lpfc_register_new_vport - Register a new vport with a HBA
6096 * @phba: pointer to lpfc hba data structure.
6097 * @vport: pointer to a host virtual N_Port data structure.
6098 * @ndlp: pointer to a node-list data structure.
6100 * This routine registers the @vport as a new virtual port with a HBA.
6101 * It is done through a registering vpi mailbox command.
6104 lpfc_register_new_vport(struct lpfc_hba
*phba
, struct lpfc_vport
*vport
,
6105 struct lpfc_nodelist
*ndlp
)
6107 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
6110 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
6112 lpfc_reg_vpi(vport
, mbox
);
6113 mbox
->vport
= vport
;
6114 mbox
->context2
= lpfc_nlp_get(ndlp
);
6115 mbox
->mbox_cmpl
= lpfc_cmpl_reg_new_vport
;
6116 if (lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
)
6117 == MBX_NOT_FINISHED
) {
6118 /* mailbox command not success, decrement ndlp
6119 * reference count for this command
6122 mempool_free(mbox
, phba
->mbox_mem_pool
);
6124 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
6125 "0253 Register VPI: Can't send mbox\n");
6129 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
6130 "0254 Register VPI: no memory\n");
6136 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
6137 spin_lock_irq(shost
->host_lock
);
6138 vport
->fc_flag
&= ~FC_VPORT_NEEDS_REG_VPI
;
6139 spin_unlock_irq(shost
->host_lock
);
6144 * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer
6145 * @phba: pointer to lpfc hba data structure.
6147 * This routine cancels the retry delay timers to all the vports.
6150 lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba
*phba
)
6152 struct lpfc_vport
**vports
;
6153 struct lpfc_nodelist
*ndlp
;
6154 uint32_t link_state
;
6157 /* Treat this failure as linkdown for all vports */
6158 link_state
= phba
->link_state
;
6159 lpfc_linkdown(phba
);
6160 phba
->link_state
= link_state
;
6162 vports
= lpfc_create_vport_work_array(phba
);
6165 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
6166 ndlp
= lpfc_findnode_did(vports
[i
], Fabric_DID
);
6168 lpfc_cancel_retry_delay_tmo(vports
[i
], ndlp
);
6169 lpfc_els_flush_cmd(vports
[i
]);
6171 lpfc_destroy_vport_work_array(phba
, vports
);
6176 * lpfc_retry_pport_discovery - Start timer to retry FLOGI.
6177 * @phba: pointer to lpfc hba data structure.
6179 * This routine abort all pending discovery commands and
6180 * start a timer to retry FLOGI for the physical port
6184 lpfc_retry_pport_discovery(struct lpfc_hba
*phba
)
6186 struct lpfc_nodelist
*ndlp
;
6187 struct Scsi_Host
*shost
;
6189 /* Cancel the all vports retry delay retry timers */
6190 lpfc_cancel_all_vport_retry_delay_timer(phba
);
6192 /* If fabric require FLOGI, then re-instantiate physical login */
6193 ndlp
= lpfc_findnode_did(phba
->pport
, Fabric_DID
);
6197 shost
= lpfc_shost_from_vport(phba
->pport
);
6198 mod_timer(&ndlp
->nlp_delayfunc
, jiffies
+ HZ
);
6199 spin_lock_irq(shost
->host_lock
);
6200 ndlp
->nlp_flag
|= NLP_DELAY_TMO
;
6201 spin_unlock_irq(shost
->host_lock
);
6202 ndlp
->nlp_last_elscmd
= ELS_CMD_FLOGI
;
6203 phba
->pport
->port_state
= LPFC_FLOGI
;
6208 * lpfc_fabric_login_reqd - Check if FLOGI required.
6209 * @phba: pointer to lpfc hba data structure.
6210 * @cmdiocb: pointer to FDISC command iocb.
6211 * @rspiocb: pointer to FDISC response iocb.
6213 * This routine checks if a FLOGI is reguired for FDISC
6217 lpfc_fabric_login_reqd(struct lpfc_hba
*phba
,
6218 struct lpfc_iocbq
*cmdiocb
,
6219 struct lpfc_iocbq
*rspiocb
)
6222 if ((rspiocb
->iocb
.ulpStatus
!= IOSTAT_FABRIC_RJT
) ||
6223 (rspiocb
->iocb
.un
.ulpWord
[4] != RJT_LOGIN_REQUIRED
))
6230 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
6231 * @phba: pointer to lpfc hba data structure.
6232 * @cmdiocb: pointer to lpfc command iocb data structure.
6233 * @rspiocb: pointer to lpfc response iocb data structure.
6235 * This routine is the completion callback function to a Fabric Discover
6236 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
6237 * single threaded, each FDISC completion callback function will reset
6238 * the discovery timer for all vports such that the timers will not get
6239 * unnecessary timeout. The function checks the FDISC IOCB status. If error
6240 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
6241 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
6242 * assigned to the vport has been changed with the completion of the FDISC
6243 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
6244 * are unregistered from the HBA, and then the lpfc_register_new_vport()
6245 * routine is invoked to register new vport with the HBA. Otherwise, the
6246 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
6247 * Server for State Change Request (SCR).
6250 lpfc_cmpl_els_fdisc(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
6251 struct lpfc_iocbq
*rspiocb
)
6253 struct lpfc_vport
*vport
= cmdiocb
->vport
;
6254 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
6255 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) cmdiocb
->context1
;
6256 struct lpfc_nodelist
*np
;
6257 struct lpfc_nodelist
*next_np
;
6258 IOCB_t
*irsp
= &rspiocb
->iocb
;
6259 struct lpfc_iocbq
*piocb
;
6261 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
6262 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
6263 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
6265 /* Since all FDISCs are being single threaded, we
6266 * must reset the discovery timer for ALL vports
6267 * waiting to send FDISC when one completes.
6269 list_for_each_entry(piocb
, &phba
->fabric_iocb_list
, list
) {
6270 lpfc_set_disctmo(piocb
->vport
);
6273 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
6274 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
6275 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4], vport
->fc_prevDID
);
6277 if (irsp
->ulpStatus
) {
6279 if (lpfc_fabric_login_reqd(phba
, cmdiocb
, rspiocb
)) {
6280 lpfc_retry_pport_discovery(phba
);
6284 /* Check for retry */
6285 if (lpfc_els_retry(phba
, cmdiocb
, rspiocb
))
6288 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
6289 "0126 FDISC failed. (%d/%d)\n",
6290 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4]);
6293 spin_lock_irq(shost
->host_lock
);
6294 vport
->fc_flag
&= ~FC_VPORT_CVL_RCVD
;
6295 vport
->fc_flag
&= ~FC_VPORT_LOGO_RCVD
;
6296 vport
->fc_flag
|= FC_FABRIC
;
6297 if (vport
->phba
->fc_topology
== TOPOLOGY_LOOP
)
6298 vport
->fc_flag
|= FC_PUBLIC_LOOP
;
6299 spin_unlock_irq(shost
->host_lock
);
6301 vport
->fc_myDID
= irsp
->un
.ulpWord
[4] & Mask_DID
;
6302 lpfc_vport_set_state(vport
, FC_VPORT_ACTIVE
);
6303 if ((vport
->fc_prevDID
!= vport
->fc_myDID
) &&
6304 !(vport
->fc_flag
& FC_VPORT_NEEDS_REG_VPI
)) {
6305 /* If our NportID changed, we need to ensure all
6306 * remaining NPORTs get unreg_login'ed so we can
6309 list_for_each_entry_safe(np
, next_np
,
6310 &vport
->fc_nodes
, nlp_listp
) {
6311 if (!NLP_CHK_NODE_ACT(ndlp
) ||
6312 (np
->nlp_state
!= NLP_STE_NPR_NODE
) ||
6313 !(np
->nlp_flag
& NLP_NPR_ADISC
))
6315 spin_lock_irq(shost
->host_lock
);
6316 np
->nlp_flag
&= ~NLP_NPR_ADISC
;
6317 spin_unlock_irq(shost
->host_lock
);
6318 lpfc_unreg_rpi(vport
, np
);
6320 lpfc_cleanup_pending_mbox(vport
);
6321 lpfc_mbx_unreg_vpi(vport
);
6322 spin_lock_irq(shost
->host_lock
);
6323 vport
->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
6324 if (phba
->sli_rev
== LPFC_SLI_REV4
)
6325 vport
->fc_flag
|= FC_VPORT_NEEDS_INIT_VPI
;
6327 vport
->fc_flag
|= FC_LOGO_RCVD_DID_CHNG
;
6328 spin_unlock_irq(shost
->host_lock
);
6331 if (vport
->fc_flag
& FC_VPORT_NEEDS_INIT_VPI
)
6332 lpfc_issue_init_vpi(vport
);
6333 else if (vport
->fc_flag
& FC_VPORT_NEEDS_REG_VPI
)
6334 lpfc_register_new_vport(phba
, vport
, ndlp
);
6336 lpfc_do_scr_ns_plogi(phba
, vport
);
6339 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
6340 /* Cancel discovery timer */
6341 lpfc_can_disctmo(vport
);
6344 lpfc_els_free_iocb(phba
, cmdiocb
);
6348 * lpfc_issue_els_fdisc - Issue a fdisc iocb command
6349 * @vport: pointer to a virtual N_Port data structure.
6350 * @ndlp: pointer to a node-list data structure.
6351 * @retry: number of retries to the command IOCB.
6353 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
6354 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
6355 * routine to issue the IOCB, which makes sure only one outstanding fabric
6356 * IOCB will be sent off HBA at any given time.
6358 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6359 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6360 * will be stored into the context1 field of the IOCB for the completion
6361 * callback function to the FDISC ELS command.
6364 * 0 - Successfully issued fdisc iocb command
6365 * 1 - Failed to issue fdisc iocb command
6368 lpfc_issue_els_fdisc(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
6371 struct lpfc_hba
*phba
= vport
->phba
;
6373 struct lpfc_iocbq
*elsiocb
;
6374 struct serv_parm
*sp
;
6377 int did
= ndlp
->nlp_DID
;
6380 vport
->port_state
= LPFC_FDISC
;
6381 cmdsize
= (sizeof(uint32_t) + sizeof(struct serv_parm
));
6382 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
, did
,
6385 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
6386 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
6387 "0255 Issue FDISC: no IOCB\n");
6391 icmd
= &elsiocb
->iocb
;
6392 icmd
->un
.elsreq64
.myID
= 0;
6393 icmd
->un
.elsreq64
.fl
= 1;
6395 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
6396 /* FDISC needs to be 1 for WQE VPI */
6397 elsiocb
->iocb
.ulpCt_h
= (SLI4_CT_VPI
>> 1) & 1;
6398 elsiocb
->iocb
.ulpCt_l
= SLI4_CT_VPI
& 1 ;
6399 /* Set the ulpContext to the vpi */
6400 elsiocb
->iocb
.ulpContext
= vport
->vpi
+ phba
->vpi_base
;
6402 /* For FDISC, Let FDISC rsp set the NPortID for this VPI */
6407 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
6408 *((uint32_t *) (pcmd
)) = ELS_CMD_FDISC
;
6409 pcmd
+= sizeof(uint32_t); /* CSP Word 1 */
6410 memcpy(pcmd
, &vport
->phba
->pport
->fc_sparam
, sizeof(struct serv_parm
));
6411 sp
= (struct serv_parm
*) pcmd
;
6412 /* Setup CSPs accordingly for Fabric */
6413 sp
->cmn
.e_d_tov
= 0;
6414 sp
->cmn
.w2
.r_a_tov
= 0;
6415 sp
->cls1
.classValid
= 0;
6416 sp
->cls2
.seqDelivery
= 1;
6417 sp
->cls3
.seqDelivery
= 1;
6419 pcmd
+= sizeof(uint32_t); /* CSP Word 2 */
6420 pcmd
+= sizeof(uint32_t); /* CSP Word 3 */
6421 pcmd
+= sizeof(uint32_t); /* CSP Word 4 */
6422 pcmd
+= sizeof(uint32_t); /* Port Name */
6423 memcpy(pcmd
, &vport
->fc_portname
, 8);
6424 pcmd
+= sizeof(uint32_t); /* Node Name */
6425 pcmd
+= sizeof(uint32_t); /* Node Name */
6426 memcpy(pcmd
, &vport
->fc_nodename
, 8);
6428 lpfc_set_disctmo(vport
);
6430 phba
->fc_stat
.elsXmitFDISC
++;
6431 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_fdisc
;
6433 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
6434 "Issue FDISC: did:x%x",
6437 rc
= lpfc_issue_fabric_iocb(phba
, elsiocb
);
6438 if (rc
== IOCB_ERROR
) {
6439 lpfc_els_free_iocb(phba
, elsiocb
);
6440 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
6441 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
6442 "0256 Issue FDISC: Cannot send IOCB\n");
6445 lpfc_vport_set_state(vport
, FC_VPORT_INITIALIZING
);
6450 * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
6451 * @phba: pointer to lpfc hba data structure.
6452 * @cmdiocb: pointer to lpfc command iocb data structure.
6453 * @rspiocb: pointer to lpfc response iocb data structure.
6455 * This routine is the completion callback function to the issuing of a LOGO
6456 * ELS command off a vport. It frees the command IOCB and then decrement the
6457 * reference count held on ndlp for this completion function, indicating that
6458 * the reference to the ndlp is no long needed. Note that the
6459 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
6460 * callback function and an additional explicit ndlp reference decrementation
6461 * will trigger the actual release of the ndlp.
6464 lpfc_cmpl_els_npiv_logo(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
6465 struct lpfc_iocbq
*rspiocb
)
6467 struct lpfc_vport
*vport
= cmdiocb
->vport
;
6469 struct lpfc_nodelist
*ndlp
;
6470 ndlp
= (struct lpfc_nodelist
*)cmdiocb
->context1
;
6472 irsp
= &rspiocb
->iocb
;
6473 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
6474 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
6475 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4], irsp
->un
.rcvels
.remoteID
);
6477 lpfc_els_free_iocb(phba
, cmdiocb
);
6478 vport
->unreg_vpi_cmpl
= VPORT_ERROR
;
6480 /* Trigger the release of the ndlp after logo */
6485 * lpfc_issue_els_npiv_logo - Issue a logo off a vport
6486 * @vport: pointer to a virtual N_Port data structure.
6487 * @ndlp: pointer to a node-list data structure.
6489 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
6491 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6492 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6493 * will be stored into the context1 field of the IOCB for the completion
6494 * callback function to the LOGO ELS command.
6497 * 0 - Successfully issued logo off the @vport
6498 * 1 - Failed to issue logo off the @vport
6501 lpfc_issue_els_npiv_logo(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
6503 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
6504 struct lpfc_hba
*phba
= vport
->phba
;
6506 struct lpfc_iocbq
*elsiocb
;
6510 cmdsize
= 2 * sizeof(uint32_t) + sizeof(struct lpfc_name
);
6511 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, 0, ndlp
, ndlp
->nlp_DID
,
6516 icmd
= &elsiocb
->iocb
;
6517 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
6518 *((uint32_t *) (pcmd
)) = ELS_CMD_LOGO
;
6519 pcmd
+= sizeof(uint32_t);
6521 /* Fill in LOGO payload */
6522 *((uint32_t *) (pcmd
)) = be32_to_cpu(vport
->fc_myDID
);
6523 pcmd
+= sizeof(uint32_t);
6524 memcpy(pcmd
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
6526 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
6527 "Issue LOGO npiv did:x%x flg:x%x",
6528 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
6530 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_npiv_logo
;
6531 spin_lock_irq(shost
->host_lock
);
6532 ndlp
->nlp_flag
|= NLP_LOGO_SND
;
6533 spin_unlock_irq(shost
->host_lock
);
6534 if (lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0) ==
6536 spin_lock_irq(shost
->host_lock
);
6537 ndlp
->nlp_flag
&= ~NLP_LOGO_SND
;
6538 spin_unlock_irq(shost
->host_lock
);
6539 lpfc_els_free_iocb(phba
, elsiocb
);
6546 * lpfc_fabric_block_timeout - Handler function to the fabric block timer
6547 * @ptr: holder for the timer function associated data.
6549 * This routine is invoked by the fabric iocb block timer after
6550 * timeout. It posts the fabric iocb block timeout event by setting the
6551 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
6552 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
6553 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
6554 * posted event WORKER_FABRIC_BLOCK_TMO.
6557 lpfc_fabric_block_timeout(unsigned long ptr
)
6559 struct lpfc_hba
*phba
= (struct lpfc_hba
*) ptr
;
6560 unsigned long iflags
;
6561 uint32_t tmo_posted
;
6563 spin_lock_irqsave(&phba
->pport
->work_port_lock
, iflags
);
6564 tmo_posted
= phba
->pport
->work_port_events
& WORKER_FABRIC_BLOCK_TMO
;
6566 phba
->pport
->work_port_events
|= WORKER_FABRIC_BLOCK_TMO
;
6567 spin_unlock_irqrestore(&phba
->pport
->work_port_lock
, iflags
);
6570 lpfc_worker_wake_up(phba
);
6575 * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
6576 * @phba: pointer to lpfc hba data structure.
6578 * This routine issues one fabric iocb from the driver internal list to
6579 * the HBA. It first checks whether it's ready to issue one fabric iocb to
6580 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
6581 * remove one pending fabric iocb from the driver internal list and invokes
6582 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
6585 lpfc_resume_fabric_iocbs(struct lpfc_hba
*phba
)
6587 struct lpfc_iocbq
*iocb
;
6588 unsigned long iflags
;
6594 spin_lock_irqsave(&phba
->hbalock
, iflags
);
6595 /* Post any pending iocb to the SLI layer */
6596 if (atomic_read(&phba
->fabric_iocb_count
) == 0) {
6597 list_remove_head(&phba
->fabric_iocb_list
, iocb
, typeof(*iocb
),
6600 /* Increment fabric iocb count to hold the position */
6601 atomic_inc(&phba
->fabric_iocb_count
);
6603 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
6605 iocb
->fabric_iocb_cmpl
= iocb
->iocb_cmpl
;
6606 iocb
->iocb_cmpl
= lpfc_cmpl_fabric_iocb
;
6607 iocb
->iocb_flag
|= LPFC_IO_FABRIC
;
6609 lpfc_debugfs_disc_trc(iocb
->vport
, LPFC_DISC_TRC_ELS_CMD
,
6610 "Fabric sched1: ste:x%x",
6611 iocb
->vport
->port_state
, 0, 0);
6613 ret
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, iocb
, 0);
6615 if (ret
== IOCB_ERROR
) {
6616 iocb
->iocb_cmpl
= iocb
->fabric_iocb_cmpl
;
6617 iocb
->fabric_iocb_cmpl
= NULL
;
6618 iocb
->iocb_flag
&= ~LPFC_IO_FABRIC
;
6620 cmd
->ulpStatus
= IOSTAT_LOCAL_REJECT
;
6621 cmd
->un
.ulpWord
[4] = IOERR_SLI_ABORTED
;
6622 iocb
->iocb_cmpl(phba
, iocb
, iocb
);
6624 atomic_dec(&phba
->fabric_iocb_count
);
6633 * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
6634 * @phba: pointer to lpfc hba data structure.
6636 * This routine unblocks the issuing fabric iocb command. The function
6637 * will clear the fabric iocb block bit and then invoke the routine
6638 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
6639 * from the driver internal fabric iocb list.
6642 lpfc_unblock_fabric_iocbs(struct lpfc_hba
*phba
)
6644 clear_bit(FABRIC_COMANDS_BLOCKED
, &phba
->bit_flags
);
6646 lpfc_resume_fabric_iocbs(phba
);
6651 * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
6652 * @phba: pointer to lpfc hba data structure.
6654 * This routine blocks the issuing fabric iocb for a specified amount of
6655 * time (currently 100 ms). This is done by set the fabric iocb block bit
6656 * and set up a timeout timer for 100ms. When the block bit is set, no more
6657 * fabric iocb will be issued out of the HBA.
6660 lpfc_block_fabric_iocbs(struct lpfc_hba
*phba
)
6664 blocked
= test_and_set_bit(FABRIC_COMANDS_BLOCKED
, &phba
->bit_flags
);
6665 /* Start a timer to unblock fabric iocbs after 100ms */
6667 mod_timer(&phba
->fabric_block_timer
, jiffies
+ HZ
/10 );
6673 * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
6674 * @phba: pointer to lpfc hba data structure.
6675 * @cmdiocb: pointer to lpfc command iocb data structure.
6676 * @rspiocb: pointer to lpfc response iocb data structure.
6678 * This routine is the callback function that is put to the fabric iocb's
6679 * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
6680 * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
6681 * function first restores and invokes the original iocb's callback function
6682 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
6683 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
6686 lpfc_cmpl_fabric_iocb(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
6687 struct lpfc_iocbq
*rspiocb
)
6691 if ((cmdiocb
->iocb_flag
& LPFC_IO_FABRIC
) != LPFC_IO_FABRIC
)
6694 switch (rspiocb
->iocb
.ulpStatus
) {
6695 case IOSTAT_NPORT_RJT
:
6696 case IOSTAT_FABRIC_RJT
:
6697 if (rspiocb
->iocb
.un
.ulpWord
[4] & RJT_UNAVAIL_TEMP
) {
6698 lpfc_block_fabric_iocbs(phba
);
6702 case IOSTAT_NPORT_BSY
:
6703 case IOSTAT_FABRIC_BSY
:
6704 lpfc_block_fabric_iocbs(phba
);
6708 stat
.un
.lsRjtError
=
6709 be32_to_cpu(rspiocb
->iocb
.un
.ulpWord
[4]);
6710 if ((stat
.un
.b
.lsRjtRsnCode
== LSRJT_UNABLE_TPC
) ||
6711 (stat
.un
.b
.lsRjtRsnCode
== LSRJT_LOGICAL_BSY
))
6712 lpfc_block_fabric_iocbs(phba
);
6716 if (atomic_read(&phba
->fabric_iocb_count
) == 0)
6719 cmdiocb
->iocb_cmpl
= cmdiocb
->fabric_iocb_cmpl
;
6720 cmdiocb
->fabric_iocb_cmpl
= NULL
;
6721 cmdiocb
->iocb_flag
&= ~LPFC_IO_FABRIC
;
6722 cmdiocb
->iocb_cmpl(phba
, cmdiocb
, rspiocb
);
6724 atomic_dec(&phba
->fabric_iocb_count
);
6725 if (!test_bit(FABRIC_COMANDS_BLOCKED
, &phba
->bit_flags
)) {
6726 /* Post any pending iocbs to HBA */
6727 lpfc_resume_fabric_iocbs(phba
);
6732 * lpfc_issue_fabric_iocb - Issue a fabric iocb command
6733 * @phba: pointer to lpfc hba data structure.
6734 * @iocb: pointer to lpfc command iocb data structure.
6736 * This routine is used as the top-level API for issuing a fabric iocb command
6737 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
6738 * function makes sure that only one fabric bound iocb will be outstanding at
6739 * any given time. As such, this function will first check to see whether there
6740 * is already an outstanding fabric iocb on the wire. If so, it will put the
6741 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
6742 * issued later. Otherwise, it will issue the iocb on the wire and update the
6743 * fabric iocb count it indicate that there is one fabric iocb on the wire.
6745 * Note, this implementation has a potential sending out fabric IOCBs out of
6746 * order. The problem is caused by the construction of the "ready" boolen does
6747 * not include the condition that the internal fabric IOCB list is empty. As
6748 * such, it is possible a fabric IOCB issued by this routine might be "jump"
6749 * ahead of the fabric IOCBs in the internal list.
6752 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
6753 * IOCB_ERROR - failed to issue fabric iocb
6756 lpfc_issue_fabric_iocb(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocb
)
6758 unsigned long iflags
;
6762 if (atomic_read(&phba
->fabric_iocb_count
) > 1)
6765 spin_lock_irqsave(&phba
->hbalock
, iflags
);
6766 ready
= atomic_read(&phba
->fabric_iocb_count
) == 0 &&
6767 !test_bit(FABRIC_COMANDS_BLOCKED
, &phba
->bit_flags
);
6770 /* Increment fabric iocb count to hold the position */
6771 atomic_inc(&phba
->fabric_iocb_count
);
6772 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
6774 iocb
->fabric_iocb_cmpl
= iocb
->iocb_cmpl
;
6775 iocb
->iocb_cmpl
= lpfc_cmpl_fabric_iocb
;
6776 iocb
->iocb_flag
|= LPFC_IO_FABRIC
;
6778 lpfc_debugfs_disc_trc(iocb
->vport
, LPFC_DISC_TRC_ELS_CMD
,
6779 "Fabric sched2: ste:x%x",
6780 iocb
->vport
->port_state
, 0, 0);
6782 ret
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, iocb
, 0);
6784 if (ret
== IOCB_ERROR
) {
6785 iocb
->iocb_cmpl
= iocb
->fabric_iocb_cmpl
;
6786 iocb
->fabric_iocb_cmpl
= NULL
;
6787 iocb
->iocb_flag
&= ~LPFC_IO_FABRIC
;
6788 atomic_dec(&phba
->fabric_iocb_count
);
6791 spin_lock_irqsave(&phba
->hbalock
, iflags
);
6792 list_add_tail(&iocb
->list
, &phba
->fabric_iocb_list
);
6793 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
6800 * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
6801 * @vport: pointer to a virtual N_Port data structure.
6803 * This routine aborts all the IOCBs associated with a @vport from the
6804 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
6805 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
6806 * list, removes each IOCB associated with the @vport off the list, set the
6807 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
6808 * associated with the IOCB.
6810 static void lpfc_fabric_abort_vport(struct lpfc_vport
*vport
)
6812 LIST_HEAD(completions
);
6813 struct lpfc_hba
*phba
= vport
->phba
;
6814 struct lpfc_iocbq
*tmp_iocb
, *piocb
;
6816 spin_lock_irq(&phba
->hbalock
);
6817 list_for_each_entry_safe(piocb
, tmp_iocb
, &phba
->fabric_iocb_list
,
6820 if (piocb
->vport
!= vport
)
6823 list_move_tail(&piocb
->list
, &completions
);
6825 spin_unlock_irq(&phba
->hbalock
);
6827 /* Cancel all the IOCBs from the completions list */
6828 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
6833 * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
6834 * @ndlp: pointer to a node-list data structure.
6836 * This routine aborts all the IOCBs associated with an @ndlp from the
6837 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
6838 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
6839 * list, removes each IOCB associated with the @ndlp off the list, set the
6840 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
6841 * associated with the IOCB.
6843 void lpfc_fabric_abort_nport(struct lpfc_nodelist
*ndlp
)
6845 LIST_HEAD(completions
);
6846 struct lpfc_hba
*phba
= ndlp
->phba
;
6847 struct lpfc_iocbq
*tmp_iocb
, *piocb
;
6848 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
6850 spin_lock_irq(&phba
->hbalock
);
6851 list_for_each_entry_safe(piocb
, tmp_iocb
, &phba
->fabric_iocb_list
,
6853 if ((lpfc_check_sli_ndlp(phba
, pring
, piocb
, ndlp
))) {
6855 list_move_tail(&piocb
->list
, &completions
);
6858 spin_unlock_irq(&phba
->hbalock
);
6860 /* Cancel all the IOCBs from the completions list */
6861 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
6866 * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
6867 * @phba: pointer to lpfc hba data structure.
6869 * This routine aborts all the IOCBs currently on the driver internal
6870 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
6871 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
6872 * list, removes IOCBs off the list, set the status feild to
6873 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
6876 void lpfc_fabric_abort_hba(struct lpfc_hba
*phba
)
6878 LIST_HEAD(completions
);
6880 spin_lock_irq(&phba
->hbalock
);
6881 list_splice_init(&phba
->fabric_iocb_list
, &completions
);
6882 spin_unlock_irq(&phba
->hbalock
);
6884 /* Cancel all the IOCBs from the completions list */
6885 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
6890 * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
6891 * @phba: pointer to lpfc hba data structure.
6892 * @axri: pointer to the els xri abort wcqe structure.
6894 * This routine is invoked by the worker thread to process a SLI4 slow-path
6898 lpfc_sli4_els_xri_aborted(struct lpfc_hba
*phba
,
6899 struct sli4_wcqe_xri_aborted
*axri
)
6901 uint16_t xri
= bf_get(lpfc_wcqe_xa_xri
, axri
);
6902 struct lpfc_sglq
*sglq_entry
= NULL
, *sglq_next
= NULL
;
6903 unsigned long iflag
= 0;
6905 spin_lock_irqsave(&phba
->hbalock
, iflag
);
6906 spin_lock(&phba
->sli4_hba
.abts_sgl_list_lock
);
6907 list_for_each_entry_safe(sglq_entry
, sglq_next
,
6908 &phba
->sli4_hba
.lpfc_abts_els_sgl_list
, list
) {
6909 if (sglq_entry
->sli4_xritag
== xri
) {
6910 list_del(&sglq_entry
->list
);
6911 list_add_tail(&sglq_entry
->list
,
6912 &phba
->sli4_hba
.lpfc_sgl_list
);
6913 sglq_entry
->state
= SGL_FREED
;
6914 spin_unlock(&phba
->sli4_hba
.abts_sgl_list_lock
);
6915 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
6919 spin_unlock(&phba
->sli4_hba
.abts_sgl_list_lock
);
6920 sglq_entry
= __lpfc_get_active_sglq(phba
, xri
);
6921 if (!sglq_entry
|| (sglq_entry
->sli4_xritag
!= xri
)) {
6922 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
6925 sglq_entry
->state
= SGL_XRI_ABORTED
;
6926 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);