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 if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) {
588 lpfc_mbx_unreg_vpi(vport
);
589 spin_lock_irq(shost
->host_lock
);
590 vport
->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
591 spin_unlock_irq(shost
->host_lock
);
594 * If VPI is unreged, driver need to do INIT_VPI
595 * before re-registering
597 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
598 spin_lock_irq(shost
->host_lock
);
599 vport
->fc_flag
|= FC_VPORT_NEEDS_INIT_VPI
;
600 spin_unlock_irq(shost
->host_lock
);
604 if (phba
->sli_rev
< LPFC_SLI_REV4
) {
605 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_REG_LOGIN_ISSUE
);
606 if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
&&
607 vport
->fc_flag
& FC_VPORT_NEEDS_REG_VPI
)
608 lpfc_register_new_vport(phba
, vport
, ndlp
);
610 lpfc_issue_fabric_reglogin(vport
);
612 ndlp
->nlp_type
|= NLP_FABRIC
;
613 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
614 if ((!(vport
->fc_flag
& FC_VPORT_NEEDS_REG_VPI
)) &&
615 (vport
->vpi_state
& LPFC_VPI_REGISTERED
)) {
616 lpfc_start_fdiscs(phba
);
617 lpfc_do_scr_ns_plogi(phba
, vport
);
618 } else if (vport
->fc_flag
& FC_VFI_REGISTERED
)
619 lpfc_issue_init_vpi(vport
);
621 lpfc_issue_reg_vfi(vport
);
626 * lpfc_cmpl_els_flogi_nport - Completion function for flogi to an N_Port
627 * @vport: pointer to a host virtual N_Port data structure.
628 * @ndlp: pointer to a node-list data structure.
629 * @sp: pointer to service parameter data structure.
631 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
632 * function to handle the completion of a Fabric Login (FLOGI) into an N_Port
633 * in a point-to-point topology. First, the @vport's N_Port Name is compared
634 * with the received N_Port Name: if the @vport's N_Port Name is greater than
635 * the received N_Port Name lexicographically, this node shall assign local
636 * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and
637 * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise,
638 * this node shall just wait for the remote node to issue PLOGI and assign
646 lpfc_cmpl_els_flogi_nport(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
647 struct serv_parm
*sp
)
649 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
650 struct lpfc_hba
*phba
= vport
->phba
;
654 spin_lock_irq(shost
->host_lock
);
655 vport
->fc_flag
&= ~(FC_FABRIC
| FC_PUBLIC_LOOP
);
656 spin_unlock_irq(shost
->host_lock
);
658 phba
->fc_edtov
= FF_DEF_EDTOV
;
659 phba
->fc_ratov
= FF_DEF_RATOV
;
660 rc
= memcmp(&vport
->fc_portname
, &sp
->portName
,
661 sizeof(vport
->fc_portname
));
663 /* This side will initiate the PLOGI */
664 spin_lock_irq(shost
->host_lock
);
665 vport
->fc_flag
|= FC_PT2PT_PLOGI
;
666 spin_unlock_irq(shost
->host_lock
);
669 * N_Port ID cannot be 0, set our to LocalID the other
670 * side will be RemoteID.
675 vport
->fc_myDID
= PT2PT_LocalID
;
677 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
681 lpfc_config_link(phba
, mbox
);
683 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
685 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
686 if (rc
== MBX_NOT_FINISHED
) {
687 mempool_free(mbox
, phba
->mbox_mem_pool
);
690 /* Decrement ndlp reference count indicating that ndlp can be
691 * safely released when other references to it are done.
695 ndlp
= lpfc_findnode_did(vport
, PT2PT_RemoteID
);
698 * Cannot find existing Fabric ndlp, so allocate a
701 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
704 lpfc_nlp_init(vport
, ndlp
, PT2PT_RemoteID
);
705 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
706 ndlp
= lpfc_enable_node(vport
, ndlp
,
707 NLP_STE_UNUSED_NODE
);
712 memcpy(&ndlp
->nlp_portname
, &sp
->portName
,
713 sizeof(struct lpfc_name
));
714 memcpy(&ndlp
->nlp_nodename
, &sp
->nodeName
,
715 sizeof(struct lpfc_name
));
716 /* Set state will put ndlp onto node list if not already done */
717 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
718 spin_lock_irq(shost
->host_lock
);
719 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
720 spin_unlock_irq(shost
->host_lock
);
722 /* This side will wait for the PLOGI, decrement ndlp reference
723 * count indicating that ndlp can be released when other
724 * references to it are done.
728 /* If we are pt2pt with another NPort, force NPIV off! */
729 phba
->sli3_options
&= ~LPFC_SLI3_NPIV_ENABLED
;
731 spin_lock_irq(shost
->host_lock
);
732 vport
->fc_flag
|= FC_PT2PT
;
733 spin_unlock_irq(shost
->host_lock
);
735 /* Start discovery - this should just do CLEAR_LA */
736 lpfc_disc_start(vport
);
743 * lpfc_cmpl_els_flogi - Completion callback function for flogi
744 * @phba: pointer to lpfc hba data structure.
745 * @cmdiocb: pointer to lpfc command iocb data structure.
746 * @rspiocb: pointer to lpfc response iocb data structure.
748 * This routine is the top-level completion callback function for issuing
749 * a Fabric Login (FLOGI) command. If the response IOCB reported error,
750 * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If
751 * retry has been made (either immediately or delayed with lpfc_els_retry()
752 * returning 1), the command IOCB will be released and function returned.
753 * If the retry attempt has been given up (possibly reach the maximum
754 * number of retries), one additional decrement of ndlp reference shall be
755 * invoked before going out after releasing the command IOCB. This will
756 * actually release the remote node (Note, lpfc_els_free_iocb() will also
757 * invoke one decrement of ndlp reference count). If no error reported in
758 * the IOCB status, the command Port ID field is used to determine whether
759 * this is a point-to-point topology or a fabric topology: if the Port ID
760 * field is assigned, it is a fabric topology; otherwise, it is a
761 * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or
762 * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the
763 * specific topology completion conditions.
766 lpfc_cmpl_els_flogi(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
767 struct lpfc_iocbq
*rspiocb
)
769 struct lpfc_vport
*vport
= cmdiocb
->vport
;
770 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
771 IOCB_t
*irsp
= &rspiocb
->iocb
;
772 struct lpfc_nodelist
*ndlp
= cmdiocb
->context1
;
773 struct lpfc_dmabuf
*pcmd
= cmdiocb
->context2
, *prsp
;
774 struct serv_parm
*sp
;
778 /* Check to see if link went down during discovery */
779 if (lpfc_els_chk_latt(vport
)) {
780 /* One additional decrement on node reference count to
781 * trigger the release of the node
787 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
788 "FLOGI cmpl: status:x%x/x%x state:x%x",
789 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
792 if (irsp
->ulpStatus
) {
794 * In case of FIP mode, perform round robin FCF failover
795 * due to new FCF discovery
797 if ((phba
->hba_flag
& HBA_FIP_SUPPORT
) &&
798 (phba
->fcf
.fcf_flag
& FCF_DISCOVERY
)) {
799 lpfc_printf_log(phba
, KERN_WARNING
, LOG_FIP
| LOG_ELS
,
800 "2611 FLOGI failed on registered "
801 "FCF record fcf_index:%d, trying "
802 "to perform round robin failover\n",
803 phba
->fcf
.current_rec
.fcf_indx
);
804 fcf_index
= lpfc_sli4_fcf_rr_next_index_get(phba
);
805 if (fcf_index
== LPFC_FCOE_FCF_NEXT_NONE
) {
807 * Exhausted the eligible FCF record list,
808 * fail through to retry FLOGI on current
811 lpfc_printf_log(phba
, KERN_WARNING
,
813 "2760 FLOGI exhausted FCF "
814 "round robin failover list, "
815 "retry FLOGI on the current "
816 "registered FCF index:%d\n",
817 phba
->fcf
.current_rec
.fcf_indx
);
818 spin_lock_irq(&phba
->hbalock
);
819 phba
->fcf
.fcf_flag
&= ~FCF_DISCOVERY
;
820 spin_unlock_irq(&phba
->hbalock
);
822 rc
= lpfc_sli4_fcf_rr_read_fcf_rec(phba
,
825 lpfc_printf_log(phba
, KERN_WARNING
,
828 "robin FCF failover "
832 phba
->fcf
.current_rec
.fcf_indx
);
833 spin_lock_irq(&phba
->hbalock
);
834 phba
->fcf
.fcf_flag
&= ~FCF_DISCOVERY
;
835 spin_unlock_irq(&phba
->hbalock
);
841 /* Check for retry */
842 if (lpfc_els_retry(phba
, cmdiocb
, rspiocb
))
845 /* FLOGI failed, so there is no fabric */
846 spin_lock_irq(shost
->host_lock
);
847 vport
->fc_flag
&= ~(FC_FABRIC
| FC_PUBLIC_LOOP
);
848 spin_unlock_irq(shost
->host_lock
);
850 /* If private loop, then allow max outstanding els to be
851 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
852 * alpa map would take too long otherwise.
854 if (phba
->alpa_map
[0] == 0) {
855 vport
->cfg_discovery_threads
= LPFC_MAX_DISC_THREADS
;
859 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
860 "0100 FLOGI failure Status:x%x/x%x TMO:x%x\n",
861 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
865 spin_lock_irq(shost
->host_lock
);
866 vport
->fc_flag
&= ~FC_VPORT_CVL_RCVD
;
867 spin_unlock_irq(shost
->host_lock
);
870 * The FLogI succeeded. Sync the data for the CPU before
873 prsp
= list_get_first(&pcmd
->list
, struct lpfc_dmabuf
, list
);
875 sp
= prsp
->virt
+ sizeof(uint32_t);
877 /* FLOGI completes successfully */
878 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
879 "0101 FLOGI completes successfully "
880 "Data: x%x x%x x%x x%x\n",
881 irsp
->un
.ulpWord
[4], sp
->cmn
.e_d_tov
,
882 sp
->cmn
.w2
.r_a_tov
, sp
->cmn
.edtovResolution
);
884 if (vport
->port_state
== LPFC_FLOGI
) {
886 * If Common Service Parameters indicate Nport
887 * we are point to point, if Fport we are Fabric.
890 rc
= lpfc_cmpl_els_flogi_fabric(vport
, ndlp
, sp
, irsp
);
892 rc
= lpfc_cmpl_els_flogi_nport(vport
, ndlp
, sp
);
895 /* Mark the FCF discovery process done */
896 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_FIP
| LOG_ELS
,
897 "2769 FLOGI successful on FCF record: "
898 "current_fcf_index:x%x, terminate FCF "
899 "round robin failover process\n",
900 phba
->fcf
.current_rec
.fcf_indx
);
901 spin_lock_irq(&phba
->hbalock
);
902 phba
->fcf
.fcf_flag
&= ~FCF_DISCOVERY
;
903 spin_unlock_irq(&phba
->hbalock
);
911 if (!lpfc_error_lost_link(irsp
)) {
912 /* FLOGI failed, so just use loop map to make discovery list */
913 lpfc_disc_list_loopmap(vport
);
915 /* Start discovery */
916 lpfc_disc_start(vport
);
917 } else if (((irsp
->ulpStatus
!= IOSTAT_LOCAL_REJECT
) ||
918 ((irsp
->un
.ulpWord
[4] != IOERR_SLI_ABORTED
) &&
919 (irsp
->un
.ulpWord
[4] != IOERR_SLI_DOWN
))) &&
920 (phba
->link_state
!= LPFC_CLEAR_LA
)) {
921 /* If FLOGI failed enable link interrupt. */
922 lpfc_issue_clear_la(phba
, vport
);
925 lpfc_els_free_iocb(phba
, cmdiocb
);
929 * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport
930 * @vport: pointer to a host virtual N_Port data structure.
931 * @ndlp: pointer to a node-list data structure.
932 * @retry: number of retries to the command IOCB.
934 * This routine issues a Fabric Login (FLOGI) Request ELS command
935 * for a @vport. The initiator service parameters are put into the payload
936 * of the FLOGI Request IOCB and the top-level callback function pointer
937 * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
938 * function field. The lpfc_issue_fabric_iocb routine is invoked to send
939 * out FLOGI ELS command with one outstanding fabric IOCB at a time.
941 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
942 * will be incremented by 1 for holding the ndlp and the reference to ndlp
943 * will be stored into the context1 field of the IOCB for the completion
944 * callback function to the FLOGI ELS command.
947 * 0 - successfully issued flogi iocb for @vport
948 * 1 - failed to issue flogi iocb for @vport
951 lpfc_issue_els_flogi(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
954 struct lpfc_hba
*phba
= vport
->phba
;
955 struct serv_parm
*sp
;
957 struct lpfc_iocbq
*elsiocb
;
958 struct lpfc_sli_ring
*pring
;
964 pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
966 cmdsize
= (sizeof(uint32_t) + sizeof(struct serv_parm
));
967 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
,
968 ndlp
->nlp_DID
, ELS_CMD_FLOGI
);
973 icmd
= &elsiocb
->iocb
;
974 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
976 /* For FLOGI request, remainder of payload is service parameters */
977 *((uint32_t *) (pcmd
)) = ELS_CMD_FLOGI
;
978 pcmd
+= sizeof(uint32_t);
979 memcpy(pcmd
, &vport
->fc_sparam
, sizeof(struct serv_parm
));
980 sp
= (struct serv_parm
*) pcmd
;
982 /* Setup CSPs accordingly for Fabric */
984 sp
->cmn
.w2
.r_a_tov
= 0;
985 sp
->cls1
.classValid
= 0;
986 sp
->cls2
.seqDelivery
= 1;
987 sp
->cls3
.seqDelivery
= 1;
988 if (sp
->cmn
.fcphLow
< FC_PH3
)
989 sp
->cmn
.fcphLow
= FC_PH3
;
990 if (sp
->cmn
.fcphHigh
< FC_PH3
)
991 sp
->cmn
.fcphHigh
= FC_PH3
;
993 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
994 elsiocb
->iocb
.ulpCt_h
= ((SLI4_CT_FCFI
>> 1) & 1);
995 elsiocb
->iocb
.ulpCt_l
= (SLI4_CT_FCFI
& 1);
996 /* FLOGI needs to be 3 for WQE FCFI */
997 /* Set the fcfi to the fcfi we registered with */
998 elsiocb
->iocb
.ulpContext
= phba
->fcf
.fcfi
;
999 } else if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) {
1000 sp
->cmn
.request_multiple_Nport
= 1;
1001 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
1006 if (phba
->fc_topology
!= TOPOLOGY_LOOP
) {
1007 icmd
->un
.elsreq64
.myID
= 0;
1008 icmd
->un
.elsreq64
.fl
= 1;
1011 tmo
= phba
->fc_ratov
;
1012 phba
->fc_ratov
= LPFC_DISC_FLOGI_TMO
;
1013 lpfc_set_disctmo(vport
);
1014 phba
->fc_ratov
= tmo
;
1016 phba
->fc_stat
.elsXmitFLOGI
++;
1017 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_flogi
;
1019 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
1020 "Issue FLOGI: opt:x%x",
1021 phba
->sli3_options
, 0, 0);
1023 rc
= lpfc_issue_fabric_iocb(phba
, elsiocb
);
1024 if (rc
== IOCB_ERROR
) {
1025 lpfc_els_free_iocb(phba
, elsiocb
);
1032 * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs
1033 * @phba: pointer to lpfc hba data structure.
1035 * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
1036 * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
1037 * list and issues an abort IOCB commond on each outstanding IOCB that
1038 * contains a active Fabric_DID ndlp. Note that this function is to issue
1039 * the abort IOCB command on all the outstanding IOCBs, thus when this
1040 * function returns, it does not guarantee all the IOCBs are actually aborted.
1043 * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0)
1046 lpfc_els_abort_flogi(struct lpfc_hba
*phba
)
1048 struct lpfc_sli_ring
*pring
;
1049 struct lpfc_iocbq
*iocb
, *next_iocb
;
1050 struct lpfc_nodelist
*ndlp
;
1053 /* Abort outstanding I/O on NPort <nlp_DID> */
1054 lpfc_printf_log(phba
, KERN_INFO
, LOG_DISCOVERY
,
1055 "0201 Abort outstanding I/O on NPort x%x\n",
1058 pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
1061 * Check the txcmplq for an iocb that matches the nport the driver is
1064 spin_lock_irq(&phba
->hbalock
);
1065 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txcmplq
, list
) {
1067 if (icmd
->ulpCommand
== CMD_ELS_REQUEST64_CR
&&
1068 icmd
->un
.elsreq64
.bdl
.ulpIoTag32
) {
1069 ndlp
= (struct lpfc_nodelist
*)(iocb
->context1
);
1070 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
) &&
1071 (ndlp
->nlp_DID
== Fabric_DID
))
1072 lpfc_sli_issue_abort_iotag(phba
, pring
, iocb
);
1075 spin_unlock_irq(&phba
->hbalock
);
1081 * lpfc_initial_flogi - Issue an initial fabric login for a vport
1082 * @vport: pointer to a host virtual N_Port data structure.
1084 * This routine issues an initial Fabric Login (FLOGI) for the @vport
1085 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1086 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1087 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1088 * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
1089 * is then invoked with the @vport and the ndlp to perform the FLOGI for the
1093 * 0 - failed to issue initial flogi for @vport
1094 * 1 - successfully issued initial flogi for @vport
1097 lpfc_initial_flogi(struct lpfc_vport
*vport
)
1099 struct lpfc_hba
*phba
= vport
->phba
;
1100 struct lpfc_nodelist
*ndlp
;
1102 vport
->port_state
= LPFC_FLOGI
;
1103 lpfc_set_disctmo(vport
);
1105 /* First look for the Fabric ndlp */
1106 ndlp
= lpfc_findnode_did(vport
, Fabric_DID
);
1108 /* Cannot find existing Fabric ndlp, so allocate a new one */
1109 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
1112 lpfc_nlp_init(vport
, ndlp
, Fabric_DID
);
1113 /* Set the node type */
1114 ndlp
->nlp_type
|= NLP_FABRIC
;
1115 /* Put ndlp onto node list */
1116 lpfc_enqueue_node(vport
, ndlp
);
1117 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
1118 /* re-setup ndlp without removing from node list */
1119 ndlp
= lpfc_enable_node(vport
, ndlp
, NLP_STE_UNUSED_NODE
);
1124 if (lpfc_issue_els_flogi(vport
, ndlp
, 0))
1125 /* This decrement of reference count to node shall kick off
1126 * the release of the node.
1134 * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport
1135 * @vport: pointer to a host virtual N_Port data structure.
1137 * This routine issues an initial Fabric Discover (FDISC) for the @vport
1138 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1139 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1140 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1141 * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
1142 * is then invoked with the @vport and the ndlp to perform the FDISC for the
1146 * 0 - failed to issue initial fdisc for @vport
1147 * 1 - successfully issued initial fdisc for @vport
1150 lpfc_initial_fdisc(struct lpfc_vport
*vport
)
1152 struct lpfc_hba
*phba
= vport
->phba
;
1153 struct lpfc_nodelist
*ndlp
;
1155 /* First look for the Fabric ndlp */
1156 ndlp
= lpfc_findnode_did(vport
, Fabric_DID
);
1158 /* Cannot find existing Fabric ndlp, so allocate a new one */
1159 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
1162 lpfc_nlp_init(vport
, ndlp
, Fabric_DID
);
1163 /* Put ndlp onto node list */
1164 lpfc_enqueue_node(vport
, ndlp
);
1165 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
1166 /* re-setup ndlp without removing from node list */
1167 ndlp
= lpfc_enable_node(vport
, ndlp
, NLP_STE_UNUSED_NODE
);
1172 if (lpfc_issue_els_fdisc(vport
, ndlp
, 0)) {
1173 /* decrement node reference count to trigger the release of
1183 * lpfc_more_plogi - Check and issue remaining plogis for a vport
1184 * @vport: pointer to a host virtual N_Port data structure.
1186 * This routine checks whether there are more remaining Port Logins
1187 * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
1188 * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
1189 * to issue ELS PLOGIs up to the configured discover threads with the
1190 * @vport (@vport->cfg_discovery_threads). The function also decrement
1191 * the @vport's num_disc_node by 1 if it is not already 0.
1194 lpfc_more_plogi(struct lpfc_vport
*vport
)
1198 if (vport
->num_disc_nodes
)
1199 vport
->num_disc_nodes
--;
1201 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
1202 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
1203 "0232 Continue discovery with %d PLOGIs to go "
1204 "Data: x%x x%x x%x\n",
1205 vport
->num_disc_nodes
, vport
->fc_plogi_cnt
,
1206 vport
->fc_flag
, vport
->port_state
);
1207 /* Check to see if there are more PLOGIs to be sent */
1208 if (vport
->fc_flag
& FC_NLP_MORE
)
1209 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
1210 sentplogi
= lpfc_els_disc_plogi(vport
);
1216 * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp
1217 * @phba: pointer to lpfc hba data structure.
1218 * @prsp: pointer to response IOCB payload.
1219 * @ndlp: pointer to a node-list data structure.
1221 * This routine checks and indicates whether the WWPN of an N_Port, retrieved
1222 * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
1223 * The following cases are considered N_Port confirmed:
1224 * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
1225 * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
1226 * it does not have WWPN assigned either. If the WWPN is confirmed, the
1227 * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
1228 * 1) if there is a node on vport list other than the @ndlp with the same
1229 * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
1230 * on that node to release the RPI associated with the node; 2) if there is
1231 * no node found on vport list with the same WWPN of the N_Port PLOGI logged
1232 * into, a new node shall be allocated (or activated). In either case, the
1233 * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
1234 * be released and the new_ndlp shall be put on to the vport node list and
1235 * its pointer returned as the confirmed node.
1237 * Note that before the @ndlp got "released", the keepDID from not-matching
1238 * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
1239 * of the @ndlp. This is because the release of @ndlp is actually to put it
1240 * into an inactive state on the vport node list and the vport node list
1241 * management algorithm does not allow two node with a same DID.
1244 * pointer to the PLOGI N_Port @ndlp
1246 static struct lpfc_nodelist
*
1247 lpfc_plogi_confirm_nport(struct lpfc_hba
*phba
, uint32_t *prsp
,
1248 struct lpfc_nodelist
*ndlp
)
1250 struct lpfc_vport
*vport
= ndlp
->vport
;
1251 struct lpfc_nodelist
*new_ndlp
;
1252 struct lpfc_rport_data
*rdata
;
1253 struct fc_rport
*rport
;
1254 struct serv_parm
*sp
;
1255 uint8_t name
[sizeof(struct lpfc_name
)];
1256 uint32_t rc
, keepDID
= 0;
1258 /* Fabric nodes can have the same WWPN so we don't bother searching
1259 * by WWPN. Just return the ndlp that was given to us.
1261 if (ndlp
->nlp_type
& NLP_FABRIC
)
1264 sp
= (struct serv_parm
*) ((uint8_t *) prsp
+ sizeof(uint32_t));
1265 memset(name
, 0, sizeof(struct lpfc_name
));
1267 /* Now we find out if the NPort we are logging into, matches the WWPN
1268 * we have for that ndlp. If not, we have some work to do.
1270 new_ndlp
= lpfc_findnode_wwpn(vport
, &sp
->portName
);
1272 if (new_ndlp
== ndlp
&& NLP_CHK_NODE_ACT(new_ndlp
))
1276 rc
= memcmp(&ndlp
->nlp_portname
, name
,
1277 sizeof(struct lpfc_name
));
1280 new_ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_ATOMIC
);
1283 lpfc_nlp_init(vport
, new_ndlp
, ndlp
->nlp_DID
);
1284 } else if (!NLP_CHK_NODE_ACT(new_ndlp
)) {
1285 rc
= memcmp(&ndlp
->nlp_portname
, name
,
1286 sizeof(struct lpfc_name
));
1289 new_ndlp
= lpfc_enable_node(vport
, new_ndlp
,
1290 NLP_STE_UNUSED_NODE
);
1293 keepDID
= new_ndlp
->nlp_DID
;
1295 keepDID
= new_ndlp
->nlp_DID
;
1297 lpfc_unreg_rpi(vport
, new_ndlp
);
1298 new_ndlp
->nlp_DID
= ndlp
->nlp_DID
;
1299 new_ndlp
->nlp_prev_state
= ndlp
->nlp_prev_state
;
1301 if (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
)
1302 new_ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
1303 ndlp
->nlp_flag
&= ~NLP_NPR_2B_DISC
;
1305 /* Set state will put new_ndlp on to node list if not already done */
1306 lpfc_nlp_set_state(vport
, new_ndlp
, ndlp
->nlp_state
);
1308 /* Move this back to NPR state */
1309 if (memcmp(&ndlp
->nlp_portname
, name
, sizeof(struct lpfc_name
)) == 0) {
1310 /* The new_ndlp is replacing ndlp totally, so we need
1311 * to put ndlp on UNUSED list and try to free it.
1314 /* Fix up the rport accordingly */
1315 rport
= ndlp
->rport
;
1317 rdata
= rport
->dd_data
;
1318 if (rdata
->pnode
== ndlp
) {
1321 rdata
->pnode
= lpfc_nlp_get(new_ndlp
);
1322 new_ndlp
->rport
= rport
;
1324 new_ndlp
->nlp_type
= ndlp
->nlp_type
;
1326 /* We shall actually free the ndlp with both nlp_DID and
1327 * nlp_portname fields equals 0 to avoid any ndlp on the
1328 * nodelist never to be used.
1330 if (ndlp
->nlp_DID
== 0) {
1331 spin_lock_irq(&phba
->ndlp_lock
);
1332 NLP_SET_FREE_REQ(ndlp
);
1333 spin_unlock_irq(&phba
->ndlp_lock
);
1336 /* Two ndlps cannot have the same did on the nodelist */
1337 ndlp
->nlp_DID
= keepDID
;
1338 lpfc_drop_node(vport
, ndlp
);
1341 lpfc_unreg_rpi(vport
, ndlp
);
1342 /* Two ndlps cannot have the same did */
1343 ndlp
->nlp_DID
= keepDID
;
1344 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
1350 * lpfc_end_rscn - Check and handle more rscn for a vport
1351 * @vport: pointer to a host virtual N_Port data structure.
1353 * This routine checks whether more Registration State Change
1354 * Notifications (RSCNs) came in while the discovery state machine was in
1355 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1356 * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1357 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1358 * handling the RSCNs.
1361 lpfc_end_rscn(struct lpfc_vport
*vport
)
1363 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1365 if (vport
->fc_flag
& FC_RSCN_MODE
) {
1367 * Check to see if more RSCNs came in while we were
1368 * processing this one.
1370 if (vport
->fc_rscn_id_cnt
||
1371 (vport
->fc_flag
& FC_RSCN_DISCOVERY
) != 0)
1372 lpfc_els_handle_rscn(vport
);
1374 spin_lock_irq(shost
->host_lock
);
1375 vport
->fc_flag
&= ~FC_RSCN_MODE
;
1376 spin_unlock_irq(shost
->host_lock
);
1382 * lpfc_cmpl_els_plogi - Completion callback function for plogi
1383 * @phba: pointer to lpfc hba data structure.
1384 * @cmdiocb: pointer to lpfc command iocb data structure.
1385 * @rspiocb: pointer to lpfc response iocb data structure.
1387 * This routine is the completion callback function for issuing the Port
1388 * Login (PLOGI) command. For PLOGI completion, there must be an active
1389 * ndlp on the vport node list that matches the remote node ID from the
1390 * PLOGI reponse IOCB. If such ndlp does not exist, the PLOGI is simply
1391 * ignored and command IOCB released. The PLOGI response IOCB status is
1392 * checked for error conditons. If there is error status reported, PLOGI
1393 * retry shall be attempted by invoking the lpfc_els_retry() routine.
1394 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1395 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1396 * (DSM) is set for this PLOGI completion. Finally, it checks whether
1397 * there are additional N_Port nodes with the vport that need to perform
1398 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
1402 lpfc_cmpl_els_plogi(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
1403 struct lpfc_iocbq
*rspiocb
)
1405 struct lpfc_vport
*vport
= cmdiocb
->vport
;
1406 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1408 struct lpfc_nodelist
*ndlp
;
1409 struct lpfc_dmabuf
*prsp
;
1410 int disc
, rc
, did
, type
;
1412 /* we pass cmdiocb to state machine which needs rspiocb as well */
1413 cmdiocb
->context_un
.rsp_iocb
= rspiocb
;
1415 irsp
= &rspiocb
->iocb
;
1416 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
1417 "PLOGI cmpl: status:x%x/x%x did:x%x",
1418 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1419 irsp
->un
.elsreq64
.remoteID
);
1421 ndlp
= lpfc_findnode_did(vport
, irsp
->un
.elsreq64
.remoteID
);
1422 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
)) {
1423 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
1424 "0136 PLOGI completes to NPort x%x "
1425 "with no ndlp. Data: x%x x%x x%x\n",
1426 irsp
->un
.elsreq64
.remoteID
,
1427 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1432 /* Since ndlp can be freed in the disc state machine, note if this node
1433 * is being used during discovery.
1435 spin_lock_irq(shost
->host_lock
);
1436 disc
= (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
);
1437 ndlp
->nlp_flag
&= ~NLP_NPR_2B_DISC
;
1438 spin_unlock_irq(shost
->host_lock
);
1441 /* PLOGI completes to NPort <nlp_DID> */
1442 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
1443 "0102 PLOGI completes to NPort x%x "
1444 "Data: x%x x%x x%x x%x x%x\n",
1445 ndlp
->nlp_DID
, irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1446 irsp
->ulpTimeout
, disc
, vport
->num_disc_nodes
);
1447 /* Check to see if link went down during discovery */
1448 if (lpfc_els_chk_latt(vport
)) {
1449 spin_lock_irq(shost
->host_lock
);
1450 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
1451 spin_unlock_irq(shost
->host_lock
);
1455 /* ndlp could be freed in DSM, save these values now */
1456 type
= ndlp
->nlp_type
;
1457 did
= ndlp
->nlp_DID
;
1459 if (irsp
->ulpStatus
) {
1460 /* Check for retry */
1461 if (lpfc_els_retry(phba
, cmdiocb
, rspiocb
)) {
1462 /* ELS command is being retried */
1464 spin_lock_irq(shost
->host_lock
);
1465 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
1466 spin_unlock_irq(shost
->host_lock
);
1471 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
1472 "2753 PLOGI failure DID:%06X Status:x%x/x%x\n",
1473 ndlp
->nlp_DID
, irsp
->ulpStatus
,
1474 irsp
->un
.ulpWord
[4]);
1475 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1476 if (lpfc_error_lost_link(irsp
))
1477 rc
= NLP_STE_FREED_NODE
;
1479 rc
= lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
1480 NLP_EVT_CMPL_PLOGI
);
1482 /* Good status, call state machine */
1483 prsp
= list_entry(((struct lpfc_dmabuf
*)
1484 cmdiocb
->context2
)->list
.next
,
1485 struct lpfc_dmabuf
, list
);
1486 ndlp
= lpfc_plogi_confirm_nport(phba
, prsp
->virt
, ndlp
);
1487 rc
= lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
1488 NLP_EVT_CMPL_PLOGI
);
1491 if (disc
&& vport
->num_disc_nodes
) {
1492 /* Check to see if there are more PLOGIs to be sent */
1493 lpfc_more_plogi(vport
);
1495 if (vport
->num_disc_nodes
== 0) {
1496 spin_lock_irq(shost
->host_lock
);
1497 vport
->fc_flag
&= ~FC_NDISC_ACTIVE
;
1498 spin_unlock_irq(shost
->host_lock
);
1500 lpfc_can_disctmo(vport
);
1501 lpfc_end_rscn(vport
);
1506 lpfc_els_free_iocb(phba
, cmdiocb
);
1511 * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
1512 * @vport: pointer to a host virtual N_Port data structure.
1513 * @did: destination port identifier.
1514 * @retry: number of retries to the command IOCB.
1516 * This routine issues a Port Login (PLOGI) command to a remote N_Port
1517 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
1518 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
1519 * This routine constructs the proper feilds of the PLOGI IOCB and invokes
1520 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
1522 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1523 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1524 * will be stored into the context1 field of the IOCB for the completion
1525 * callback function to the PLOGI ELS command.
1528 * 0 - Successfully issued a plogi for @vport
1529 * 1 - failed to issue a plogi for @vport
1532 lpfc_issue_els_plogi(struct lpfc_vport
*vport
, uint32_t did
, uint8_t retry
)
1534 struct lpfc_hba
*phba
= vport
->phba
;
1535 struct serv_parm
*sp
;
1537 struct lpfc_nodelist
*ndlp
;
1538 struct lpfc_iocbq
*elsiocb
;
1539 struct lpfc_sli
*psli
;
1546 ndlp
= lpfc_findnode_did(vport
, did
);
1547 if (ndlp
&& !NLP_CHK_NODE_ACT(ndlp
))
1550 /* If ndlp is not NULL, we will bump the reference count on it */
1551 cmdsize
= (sizeof(uint32_t) + sizeof(struct serv_parm
));
1552 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
, did
,
1557 icmd
= &elsiocb
->iocb
;
1558 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
1560 /* For PLOGI request, remainder of payload is service parameters */
1561 *((uint32_t *) (pcmd
)) = ELS_CMD_PLOGI
;
1562 pcmd
+= sizeof(uint32_t);
1563 memcpy(pcmd
, &vport
->fc_sparam
, sizeof(struct serv_parm
));
1564 sp
= (struct serv_parm
*) pcmd
;
1566 if (sp
->cmn
.fcphLow
< FC_PH_4_3
)
1567 sp
->cmn
.fcphLow
= FC_PH_4_3
;
1569 if (sp
->cmn
.fcphHigh
< FC_PH3
)
1570 sp
->cmn
.fcphHigh
= FC_PH3
;
1572 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
1573 "Issue PLOGI: did:x%x",
1576 phba
->fc_stat
.elsXmitPLOGI
++;
1577 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_plogi
;
1578 ret
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
1580 if (ret
== IOCB_ERROR
) {
1581 lpfc_els_free_iocb(phba
, elsiocb
);
1588 * lpfc_cmpl_els_prli - Completion callback function for prli
1589 * @phba: pointer to lpfc hba data structure.
1590 * @cmdiocb: pointer to lpfc command iocb data structure.
1591 * @rspiocb: pointer to lpfc response iocb data structure.
1593 * This routine is the completion callback function for a Process Login
1594 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
1595 * status. If there is error status reported, PRLI retry shall be attempted
1596 * by invoking the lpfc_els_retry() routine. Otherwise, the state
1597 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
1598 * ndlp to mark the PRLI completion.
1601 lpfc_cmpl_els_prli(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
1602 struct lpfc_iocbq
*rspiocb
)
1604 struct lpfc_vport
*vport
= cmdiocb
->vport
;
1605 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1607 struct lpfc_sli
*psli
;
1608 struct lpfc_nodelist
*ndlp
;
1611 /* we pass cmdiocb to state machine which needs rspiocb as well */
1612 cmdiocb
->context_un
.rsp_iocb
= rspiocb
;
1614 irsp
= &(rspiocb
->iocb
);
1615 ndlp
= (struct lpfc_nodelist
*) cmdiocb
->context1
;
1616 spin_lock_irq(shost
->host_lock
);
1617 ndlp
->nlp_flag
&= ~NLP_PRLI_SND
;
1618 spin_unlock_irq(shost
->host_lock
);
1620 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
1621 "PRLI cmpl: status:x%x/x%x did:x%x",
1622 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1624 /* PRLI completes to NPort <nlp_DID> */
1625 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
1626 "0103 PRLI completes to NPort x%x "
1627 "Data: x%x x%x x%x x%x\n",
1628 ndlp
->nlp_DID
, irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1629 irsp
->ulpTimeout
, vport
->num_disc_nodes
);
1631 vport
->fc_prli_sent
--;
1632 /* Check to see if link went down during discovery */
1633 if (lpfc_els_chk_latt(vport
))
1636 if (irsp
->ulpStatus
) {
1637 /* Check for retry */
1638 if (lpfc_els_retry(phba
, cmdiocb
, rspiocb
)) {
1639 /* ELS command is being retried */
1643 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
1644 "2754 PRLI failure DID:%06X Status:x%x/x%x\n",
1645 ndlp
->nlp_DID
, irsp
->ulpStatus
,
1646 irsp
->un
.ulpWord
[4]);
1647 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1648 if (lpfc_error_lost_link(irsp
))
1651 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
1654 /* Good status, call state machine */
1655 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
1658 lpfc_els_free_iocb(phba
, cmdiocb
);
1663 * lpfc_issue_els_prli - Issue a prli iocb command for a vport
1664 * @vport: pointer to a host virtual N_Port data structure.
1665 * @ndlp: pointer to a node-list data structure.
1666 * @retry: number of retries to the command IOCB.
1668 * This routine issues a Process Login (PRLI) ELS command for the
1669 * @vport. The PRLI service parameters are set up in the payload of the
1670 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
1671 * is put to the IOCB completion callback func field before invoking the
1672 * routine lpfc_sli_issue_iocb() to send out PRLI command.
1674 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1675 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1676 * will be stored into the context1 field of the IOCB for the completion
1677 * callback function to the PRLI ELS command.
1680 * 0 - successfully issued prli iocb command for @vport
1681 * 1 - failed to issue prli iocb command for @vport
1684 lpfc_issue_els_prli(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1687 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1688 struct lpfc_hba
*phba
= vport
->phba
;
1691 struct lpfc_iocbq
*elsiocb
;
1695 cmdsize
= (sizeof(uint32_t) + sizeof(PRLI
));
1696 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
,
1697 ndlp
->nlp_DID
, ELS_CMD_PRLI
);
1701 icmd
= &elsiocb
->iocb
;
1702 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
1704 /* For PRLI request, remainder of payload is service parameters */
1705 memset(pcmd
, 0, (sizeof(PRLI
) + sizeof(uint32_t)));
1706 *((uint32_t *) (pcmd
)) = ELS_CMD_PRLI
;
1707 pcmd
+= sizeof(uint32_t);
1709 /* For PRLI, remainder of payload is PRLI parameter page */
1710 npr
= (PRLI
*) pcmd
;
1712 * If our firmware version is 3.20 or later,
1713 * set the following bits for FC-TAPE support.
1715 if (phba
->vpd
.rev
.feaLevelHigh
>= 0x02) {
1716 npr
->ConfmComplAllowed
= 1;
1718 npr
->TaskRetryIdReq
= 1;
1720 npr
->estabImagePair
= 1;
1721 npr
->readXferRdyDis
= 1;
1723 /* For FCP support */
1724 npr
->prliType
= PRLI_FCP_TYPE
;
1725 npr
->initiatorFunc
= 1;
1727 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
1728 "Issue PRLI: did:x%x",
1729 ndlp
->nlp_DID
, 0, 0);
1731 phba
->fc_stat
.elsXmitPRLI
++;
1732 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_prli
;
1733 spin_lock_irq(shost
->host_lock
);
1734 ndlp
->nlp_flag
|= NLP_PRLI_SND
;
1735 spin_unlock_irq(shost
->host_lock
);
1736 if (lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0) ==
1738 spin_lock_irq(shost
->host_lock
);
1739 ndlp
->nlp_flag
&= ~NLP_PRLI_SND
;
1740 spin_unlock_irq(shost
->host_lock
);
1741 lpfc_els_free_iocb(phba
, elsiocb
);
1744 vport
->fc_prli_sent
++;
1749 * lpfc_rscn_disc - Perform rscn discovery for a vport
1750 * @vport: pointer to a host virtual N_Port data structure.
1752 * This routine performs Registration State Change Notification (RSCN)
1753 * discovery for a @vport. If the @vport's node port recovery count is not
1754 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
1755 * the nodes that need recovery. If none of the PLOGI were needed through
1756 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
1757 * invoked to check and handle possible more RSCN came in during the period
1758 * of processing the current ones.
1761 lpfc_rscn_disc(struct lpfc_vport
*vport
)
1763 lpfc_can_disctmo(vport
);
1765 /* RSCN discovery */
1766 /* go thru NPR nodes and issue ELS PLOGIs */
1767 if (vport
->fc_npr_cnt
)
1768 if (lpfc_els_disc_plogi(vport
))
1771 lpfc_end_rscn(vport
);
1775 * lpfc_adisc_done - Complete the adisc phase of discovery
1776 * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
1778 * This function is called when the final ADISC is completed during discovery.
1779 * This function handles clearing link attention or issuing reg_vpi depending
1780 * on whether npiv is enabled. This function also kicks off the PLOGI phase of
1782 * This function is called with no locks held.
1785 lpfc_adisc_done(struct lpfc_vport
*vport
)
1787 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1788 struct lpfc_hba
*phba
= vport
->phba
;
1791 * For NPIV, cmpl_reg_vpi will set port_state to READY,
1792 * and continue discovery.
1794 if ((phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
1795 !(vport
->fc_flag
& FC_RSCN_MODE
) &&
1796 (phba
->sli_rev
< LPFC_SLI_REV4
)) {
1797 lpfc_issue_reg_vpi(phba
, vport
);
1801 * For SLI2, we need to set port_state to READY
1802 * and continue discovery.
1804 if (vport
->port_state
< LPFC_VPORT_READY
) {
1805 /* If we get here, there is nothing to ADISC */
1806 if (vport
->port_type
== LPFC_PHYSICAL_PORT
)
1807 lpfc_issue_clear_la(phba
, vport
);
1808 if (!(vport
->fc_flag
& FC_ABORT_DISCOVERY
)) {
1809 vport
->num_disc_nodes
= 0;
1810 /* go thru NPR list, issue ELS PLOGIs */
1811 if (vport
->fc_npr_cnt
)
1812 lpfc_els_disc_plogi(vport
);
1813 if (!vport
->num_disc_nodes
) {
1814 spin_lock_irq(shost
->host_lock
);
1815 vport
->fc_flag
&= ~FC_NDISC_ACTIVE
;
1816 spin_unlock_irq(shost
->host_lock
);
1817 lpfc_can_disctmo(vport
);
1818 lpfc_end_rscn(vport
);
1821 vport
->port_state
= LPFC_VPORT_READY
;
1823 lpfc_rscn_disc(vport
);
1827 * lpfc_more_adisc - Issue more adisc as needed
1828 * @vport: pointer to a host virtual N_Port data structure.
1830 * This routine determines whether there are more ndlps on a @vport
1831 * node list need to have Address Discover (ADISC) issued. If so, it will
1832 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
1833 * remaining nodes which need to have ADISC sent.
1836 lpfc_more_adisc(struct lpfc_vport
*vport
)
1840 if (vport
->num_disc_nodes
)
1841 vport
->num_disc_nodes
--;
1842 /* Continue discovery with <num_disc_nodes> ADISCs to go */
1843 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
1844 "0210 Continue discovery with %d ADISCs to go "
1845 "Data: x%x x%x x%x\n",
1846 vport
->num_disc_nodes
, vport
->fc_adisc_cnt
,
1847 vport
->fc_flag
, vport
->port_state
);
1848 /* Check to see if there are more ADISCs to be sent */
1849 if (vport
->fc_flag
& FC_NLP_MORE
) {
1850 lpfc_set_disctmo(vport
);
1851 /* go thru NPR nodes and issue any remaining ELS ADISCs */
1852 sentadisc
= lpfc_els_disc_adisc(vport
);
1854 if (!vport
->num_disc_nodes
)
1855 lpfc_adisc_done(vport
);
1860 * lpfc_cmpl_els_adisc - Completion callback function for adisc
1861 * @phba: pointer to lpfc hba data structure.
1862 * @cmdiocb: pointer to lpfc command iocb data structure.
1863 * @rspiocb: pointer to lpfc response iocb data structure.
1865 * This routine is the completion function for issuing the Address Discover
1866 * (ADISC) command. It first checks to see whether link went down during
1867 * the discovery process. If so, the node will be marked as node port
1868 * recovery for issuing discover IOCB by the link attention handler and
1869 * exit. Otherwise, the response status is checked. If error was reported
1870 * in the response status, the ADISC command shall be retried by invoking
1871 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
1872 * the response status, the state machine is invoked to set transition
1873 * with respect to NLP_EVT_CMPL_ADISC event.
1876 lpfc_cmpl_els_adisc(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
1877 struct lpfc_iocbq
*rspiocb
)
1879 struct lpfc_vport
*vport
= cmdiocb
->vport
;
1880 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1882 struct lpfc_nodelist
*ndlp
;
1885 /* we pass cmdiocb to state machine which needs rspiocb as well */
1886 cmdiocb
->context_un
.rsp_iocb
= rspiocb
;
1888 irsp
= &(rspiocb
->iocb
);
1889 ndlp
= (struct lpfc_nodelist
*) cmdiocb
->context1
;
1891 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
1892 "ADISC cmpl: status:x%x/x%x did:x%x",
1893 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1896 /* Since ndlp can be freed in the disc state machine, note if this node
1897 * is being used during discovery.
1899 spin_lock_irq(shost
->host_lock
);
1900 disc
= (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
);
1901 ndlp
->nlp_flag
&= ~(NLP_ADISC_SND
| NLP_NPR_2B_DISC
);
1902 spin_unlock_irq(shost
->host_lock
);
1903 /* ADISC completes to NPort <nlp_DID> */
1904 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
1905 "0104 ADISC completes to NPort x%x "
1906 "Data: x%x x%x x%x x%x x%x\n",
1907 ndlp
->nlp_DID
, irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1908 irsp
->ulpTimeout
, disc
, vport
->num_disc_nodes
);
1909 /* Check to see if link went down during discovery */
1910 if (lpfc_els_chk_latt(vport
)) {
1911 spin_lock_irq(shost
->host_lock
);
1912 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
1913 spin_unlock_irq(shost
->host_lock
);
1917 if (irsp
->ulpStatus
) {
1918 /* Check for retry */
1919 if (lpfc_els_retry(phba
, cmdiocb
, rspiocb
)) {
1920 /* ELS command is being retried */
1922 spin_lock_irq(shost
->host_lock
);
1923 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
1924 spin_unlock_irq(shost
->host_lock
);
1925 lpfc_set_disctmo(vport
);
1930 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
1931 "2755 ADISC failure DID:%06X Status:x%x/x%x\n",
1932 ndlp
->nlp_DID
, irsp
->ulpStatus
,
1933 irsp
->un
.ulpWord
[4]);
1934 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1935 if (!lpfc_error_lost_link(irsp
))
1936 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
1937 NLP_EVT_CMPL_ADISC
);
1939 /* Good status, call state machine */
1940 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
1941 NLP_EVT_CMPL_ADISC
);
1943 /* Check to see if there are more ADISCs to be sent */
1944 if (disc
&& vport
->num_disc_nodes
)
1945 lpfc_more_adisc(vport
);
1947 lpfc_els_free_iocb(phba
, cmdiocb
);
1952 * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
1953 * @vport: pointer to a virtual N_Port data structure.
1954 * @ndlp: pointer to a node-list data structure.
1955 * @retry: number of retries to the command IOCB.
1957 * This routine issues an Address Discover (ADISC) for an @ndlp on a
1958 * @vport. It prepares the payload of the ADISC ELS command, updates the
1959 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
1960 * to issue the ADISC ELS command.
1962 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1963 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1964 * will be stored into the context1 field of the IOCB for the completion
1965 * callback function to the ADISC ELS command.
1968 * 0 - successfully issued adisc
1969 * 1 - failed to issue adisc
1972 lpfc_issue_els_adisc(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1975 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1976 struct lpfc_hba
*phba
= vport
->phba
;
1979 struct lpfc_iocbq
*elsiocb
;
1983 cmdsize
= (sizeof(uint32_t) + sizeof(ADISC
));
1984 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
,
1985 ndlp
->nlp_DID
, ELS_CMD_ADISC
);
1989 icmd
= &elsiocb
->iocb
;
1990 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
1992 /* For ADISC request, remainder of payload is service parameters */
1993 *((uint32_t *) (pcmd
)) = ELS_CMD_ADISC
;
1994 pcmd
+= sizeof(uint32_t);
1996 /* Fill in ADISC payload */
1997 ap
= (ADISC
*) pcmd
;
1998 ap
->hardAL_PA
= phba
->fc_pref_ALPA
;
1999 memcpy(&ap
->portName
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
2000 memcpy(&ap
->nodeName
, &vport
->fc_nodename
, sizeof(struct lpfc_name
));
2001 ap
->DID
= be32_to_cpu(vport
->fc_myDID
);
2003 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
2004 "Issue ADISC: did:x%x",
2005 ndlp
->nlp_DID
, 0, 0);
2007 phba
->fc_stat
.elsXmitADISC
++;
2008 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_adisc
;
2009 spin_lock_irq(shost
->host_lock
);
2010 ndlp
->nlp_flag
|= NLP_ADISC_SND
;
2011 spin_unlock_irq(shost
->host_lock
);
2012 if (lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0) ==
2014 spin_lock_irq(shost
->host_lock
);
2015 ndlp
->nlp_flag
&= ~NLP_ADISC_SND
;
2016 spin_unlock_irq(shost
->host_lock
);
2017 lpfc_els_free_iocb(phba
, elsiocb
);
2024 * lpfc_cmpl_els_logo - Completion callback function for logo
2025 * @phba: pointer to lpfc hba data structure.
2026 * @cmdiocb: pointer to lpfc command iocb data structure.
2027 * @rspiocb: pointer to lpfc response iocb data structure.
2029 * This routine is the completion function for issuing the ELS Logout (LOGO)
2030 * command. If no error status was reported from the LOGO response, the
2031 * state machine of the associated ndlp shall be invoked for transition with
2032 * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
2033 * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
2036 lpfc_cmpl_els_logo(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
2037 struct lpfc_iocbq
*rspiocb
)
2039 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) cmdiocb
->context1
;
2040 struct lpfc_vport
*vport
= ndlp
->vport
;
2041 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2043 struct lpfc_sli
*psli
;
2046 /* we pass cmdiocb to state machine which needs rspiocb as well */
2047 cmdiocb
->context_un
.rsp_iocb
= rspiocb
;
2049 irsp
= &(rspiocb
->iocb
);
2050 spin_lock_irq(shost
->host_lock
);
2051 ndlp
->nlp_flag
&= ~NLP_LOGO_SND
;
2052 spin_unlock_irq(shost
->host_lock
);
2054 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
2055 "LOGO cmpl: status:x%x/x%x did:x%x",
2056 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
2058 /* LOGO completes to NPort <nlp_DID> */
2059 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
2060 "0105 LOGO completes to NPort x%x "
2061 "Data: x%x x%x x%x x%x\n",
2062 ndlp
->nlp_DID
, irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
2063 irsp
->ulpTimeout
, vport
->num_disc_nodes
);
2064 /* Check to see if link went down during discovery */
2065 if (lpfc_els_chk_latt(vport
))
2068 if (ndlp
->nlp_flag
& NLP_TARGET_REMOVE
) {
2069 /* NLP_EVT_DEVICE_RM should unregister the RPI
2070 * which should abort all outstanding IOs.
2072 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
2077 if (irsp
->ulpStatus
) {
2078 /* Check for retry */
2079 if (lpfc_els_retry(phba
, cmdiocb
, rspiocb
))
2080 /* ELS command is being retried */
2083 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
2084 "2756 LOGO failure DID:%06X Status:x%x/x%x\n",
2085 ndlp
->nlp_DID
, irsp
->ulpStatus
,
2086 irsp
->un
.ulpWord
[4]);
2087 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2088 if (lpfc_error_lost_link(irsp
))
2091 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
2094 /* Good status, call state machine.
2095 * This will unregister the rpi if needed.
2097 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
2100 lpfc_els_free_iocb(phba
, cmdiocb
);
2105 * lpfc_issue_els_logo - Issue a logo to an node on a vport
2106 * @vport: pointer to a virtual N_Port data structure.
2107 * @ndlp: pointer to a node-list data structure.
2108 * @retry: number of retries to the command IOCB.
2110 * This routine constructs and issues an ELS Logout (LOGO) iocb command
2111 * to a remote node, referred by an @ndlp on a @vport. It constructs the
2112 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
2113 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
2115 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2116 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2117 * will be stored into the context1 field of the IOCB for the completion
2118 * callback function to the LOGO ELS command.
2121 * 0 - successfully issued logo
2122 * 1 - failed to issue logo
2125 lpfc_issue_els_logo(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2128 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2129 struct lpfc_hba
*phba
= vport
->phba
;
2131 struct lpfc_iocbq
*elsiocb
;
2136 spin_lock_irq(shost
->host_lock
);
2137 if (ndlp
->nlp_flag
& NLP_LOGO_SND
) {
2138 spin_unlock_irq(shost
->host_lock
);
2141 spin_unlock_irq(shost
->host_lock
);
2143 cmdsize
= (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name
);
2144 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
,
2145 ndlp
->nlp_DID
, ELS_CMD_LOGO
);
2149 icmd
= &elsiocb
->iocb
;
2150 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
2151 *((uint32_t *) (pcmd
)) = ELS_CMD_LOGO
;
2152 pcmd
+= sizeof(uint32_t);
2154 /* Fill in LOGO payload */
2155 *((uint32_t *) (pcmd
)) = be32_to_cpu(vport
->fc_myDID
);
2156 pcmd
+= sizeof(uint32_t);
2157 memcpy(pcmd
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
2159 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
2160 "Issue LOGO: did:x%x",
2161 ndlp
->nlp_DID
, 0, 0);
2163 phba
->fc_stat
.elsXmitLOGO
++;
2164 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_logo
;
2165 spin_lock_irq(shost
->host_lock
);
2166 ndlp
->nlp_flag
|= NLP_LOGO_SND
;
2167 spin_unlock_irq(shost
->host_lock
);
2168 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
2170 if (rc
== IOCB_ERROR
) {
2171 spin_lock_irq(shost
->host_lock
);
2172 ndlp
->nlp_flag
&= ~NLP_LOGO_SND
;
2173 spin_unlock_irq(shost
->host_lock
);
2174 lpfc_els_free_iocb(phba
, elsiocb
);
2181 * lpfc_cmpl_els_cmd - Completion callback function for generic els command
2182 * @phba: pointer to lpfc hba data structure.
2183 * @cmdiocb: pointer to lpfc command iocb data structure.
2184 * @rspiocb: pointer to lpfc response iocb data structure.
2186 * This routine is a generic completion callback function for ELS commands.
2187 * Specifically, it is the callback function which does not need to perform
2188 * any command specific operations. It is currently used by the ELS command
2189 * issuing routines for the ELS State Change Request (SCR),
2190 * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution
2191 * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than
2192 * certain debug loggings, this callback function simply invokes the
2193 * lpfc_els_chk_latt() routine to check whether link went down during the
2194 * discovery process.
2197 lpfc_cmpl_els_cmd(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
2198 struct lpfc_iocbq
*rspiocb
)
2200 struct lpfc_vport
*vport
= cmdiocb
->vport
;
2203 irsp
= &rspiocb
->iocb
;
2205 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
2206 "ELS cmd cmpl: status:x%x/x%x did:x%x",
2207 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
2208 irsp
->un
.elsreq64
.remoteID
);
2209 /* ELS cmd tag <ulpIoTag> completes */
2210 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
2211 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
2212 irsp
->ulpIoTag
, irsp
->ulpStatus
,
2213 irsp
->un
.ulpWord
[4], irsp
->ulpTimeout
);
2214 /* Check to see if link went down during discovery */
2215 lpfc_els_chk_latt(vport
);
2216 lpfc_els_free_iocb(phba
, cmdiocb
);
2221 * lpfc_issue_els_scr - Issue a scr to an node on a vport
2222 * @vport: pointer to a host virtual N_Port data structure.
2223 * @nportid: N_Port identifier to the remote node.
2224 * @retry: number of retries to the command IOCB.
2226 * This routine issues a State Change Request (SCR) to a fabric node
2227 * on a @vport. The remote node @nportid is passed into the function. It
2228 * first search the @vport node list to find the matching ndlp. If no such
2229 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
2230 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
2231 * routine is invoked to send the SCR IOCB.
2233 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2234 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2235 * will be stored into the context1 field of the IOCB for the completion
2236 * callback function to the SCR ELS command.
2239 * 0 - Successfully issued scr command
2240 * 1 - Failed to issue scr command
2243 lpfc_issue_els_scr(struct lpfc_vport
*vport
, uint32_t nportid
, uint8_t retry
)
2245 struct lpfc_hba
*phba
= vport
->phba
;
2247 struct lpfc_iocbq
*elsiocb
;
2248 struct lpfc_sli
*psli
;
2251 struct lpfc_nodelist
*ndlp
;
2254 cmdsize
= (sizeof(uint32_t) + sizeof(SCR
));
2256 ndlp
= lpfc_findnode_did(vport
, nportid
);
2258 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
2261 lpfc_nlp_init(vport
, ndlp
, nportid
);
2262 lpfc_enqueue_node(vport
, ndlp
);
2263 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
2264 ndlp
= lpfc_enable_node(vport
, ndlp
, NLP_STE_UNUSED_NODE
);
2269 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
,
2270 ndlp
->nlp_DID
, ELS_CMD_SCR
);
2273 /* This will trigger the release of the node just
2280 icmd
= &elsiocb
->iocb
;
2281 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
2283 *((uint32_t *) (pcmd
)) = ELS_CMD_SCR
;
2284 pcmd
+= sizeof(uint32_t);
2286 /* For SCR, remainder of payload is SCR parameter page */
2287 memset(pcmd
, 0, sizeof(SCR
));
2288 ((SCR
*) pcmd
)->Function
= SCR_FUNC_FULL
;
2290 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
2291 "Issue SCR: did:x%x",
2292 ndlp
->nlp_DID
, 0, 0);
2294 phba
->fc_stat
.elsXmitSCR
++;
2295 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_cmd
;
2296 if (lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0) ==
2298 /* The additional lpfc_nlp_put will cause the following
2299 * lpfc_els_free_iocb routine to trigger the rlease of
2303 lpfc_els_free_iocb(phba
, elsiocb
);
2306 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2307 * trigger the release of node.
2314 * lpfc_issue_els_farpr - Issue a farp to an node on a vport
2315 * @vport: pointer to a host virtual N_Port data structure.
2316 * @nportid: N_Port identifier to the remote node.
2317 * @retry: number of retries to the command IOCB.
2319 * This routine issues a Fibre Channel Address Resolution Response
2320 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
2321 * is passed into the function. It first search the @vport node list to find
2322 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
2323 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
2324 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
2326 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2327 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2328 * will be stored into the context1 field of the IOCB for the completion
2329 * callback function to the PARPR ELS command.
2332 * 0 - Successfully issued farpr command
2333 * 1 - Failed to issue farpr command
2336 lpfc_issue_els_farpr(struct lpfc_vport
*vport
, uint32_t nportid
, uint8_t retry
)
2338 struct lpfc_hba
*phba
= vport
->phba
;
2340 struct lpfc_iocbq
*elsiocb
;
2341 struct lpfc_sli
*psli
;
2346 struct lpfc_nodelist
*ondlp
;
2347 struct lpfc_nodelist
*ndlp
;
2350 cmdsize
= (sizeof(uint32_t) + sizeof(FARP
));
2352 ndlp
= lpfc_findnode_did(vport
, nportid
);
2354 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
2357 lpfc_nlp_init(vport
, ndlp
, nportid
);
2358 lpfc_enqueue_node(vport
, ndlp
);
2359 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
2360 ndlp
= lpfc_enable_node(vport
, ndlp
, NLP_STE_UNUSED_NODE
);
2365 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
,
2366 ndlp
->nlp_DID
, ELS_CMD_RNID
);
2368 /* This will trigger the release of the node just
2375 icmd
= &elsiocb
->iocb
;
2376 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
2378 *((uint32_t *) (pcmd
)) = ELS_CMD_FARPR
;
2379 pcmd
+= sizeof(uint32_t);
2381 /* Fill in FARPR payload */
2382 fp
= (FARP
*) (pcmd
);
2383 memset(fp
, 0, sizeof(FARP
));
2384 lp
= (uint32_t *) pcmd
;
2385 *lp
++ = be32_to_cpu(nportid
);
2386 *lp
++ = be32_to_cpu(vport
->fc_myDID
);
2388 fp
->Mflags
= (FARP_MATCH_PORT
| FARP_MATCH_NODE
);
2390 memcpy(&fp
->RportName
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
2391 memcpy(&fp
->RnodeName
, &vport
->fc_nodename
, sizeof(struct lpfc_name
));
2392 ondlp
= lpfc_findnode_did(vport
, nportid
);
2393 if (ondlp
&& NLP_CHK_NODE_ACT(ondlp
)) {
2394 memcpy(&fp
->OportName
, &ondlp
->nlp_portname
,
2395 sizeof(struct lpfc_name
));
2396 memcpy(&fp
->OnodeName
, &ondlp
->nlp_nodename
,
2397 sizeof(struct lpfc_name
));
2400 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
2401 "Issue FARPR: did:x%x",
2402 ndlp
->nlp_DID
, 0, 0);
2404 phba
->fc_stat
.elsXmitFARPR
++;
2405 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_cmd
;
2406 if (lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0) ==
2408 /* The additional lpfc_nlp_put will cause the following
2409 * lpfc_els_free_iocb routine to trigger the release of
2413 lpfc_els_free_iocb(phba
, elsiocb
);
2416 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2417 * trigger the release of the node.
2424 * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
2425 * @vport: pointer to a host virtual N_Port data structure.
2426 * @nlp: pointer to a node-list data structure.
2428 * This routine cancels the timer with a delayed IOCB-command retry for
2429 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
2430 * removes the ELS retry event if it presents. In addition, if the
2431 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
2432 * commands are sent for the @vport's nodes that require issuing discovery
2436 lpfc_cancel_retry_delay_tmo(struct lpfc_vport
*vport
, struct lpfc_nodelist
*nlp
)
2438 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2439 struct lpfc_work_evt
*evtp
;
2441 if (!(nlp
->nlp_flag
& NLP_DELAY_TMO
))
2443 spin_lock_irq(shost
->host_lock
);
2444 nlp
->nlp_flag
&= ~NLP_DELAY_TMO
;
2445 spin_unlock_irq(shost
->host_lock
);
2446 del_timer_sync(&nlp
->nlp_delayfunc
);
2447 nlp
->nlp_last_elscmd
= 0;
2448 if (!list_empty(&nlp
->els_retry_evt
.evt_listp
)) {
2449 list_del_init(&nlp
->els_retry_evt
.evt_listp
);
2450 /* Decrement nlp reference count held for the delayed retry */
2451 evtp
= &nlp
->els_retry_evt
;
2452 lpfc_nlp_put((struct lpfc_nodelist
*)evtp
->evt_arg1
);
2454 if (nlp
->nlp_flag
& NLP_NPR_2B_DISC
) {
2455 spin_lock_irq(shost
->host_lock
);
2456 nlp
->nlp_flag
&= ~NLP_NPR_2B_DISC
;
2457 spin_unlock_irq(shost
->host_lock
);
2458 if (vport
->num_disc_nodes
) {
2459 if (vport
->port_state
< LPFC_VPORT_READY
) {
2460 /* Check if there are more ADISCs to be sent */
2461 lpfc_more_adisc(vport
);
2463 /* Check if there are more PLOGIs to be sent */
2464 lpfc_more_plogi(vport
);
2465 if (vport
->num_disc_nodes
== 0) {
2466 spin_lock_irq(shost
->host_lock
);
2467 vport
->fc_flag
&= ~FC_NDISC_ACTIVE
;
2468 spin_unlock_irq(shost
->host_lock
);
2469 lpfc_can_disctmo(vport
);
2470 lpfc_end_rscn(vport
);
2479 * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
2480 * @ptr: holder for the pointer to the timer function associated data (ndlp).
2482 * This routine is invoked by the ndlp delayed-function timer to check
2483 * whether there is any pending ELS retry event(s) with the node. If not, it
2484 * simply returns. Otherwise, if there is at least one ELS delayed event, it
2485 * adds the delayed events to the HBA work list and invokes the
2486 * lpfc_worker_wake_up() routine to wake up worker thread to process the
2487 * event. Note that lpfc_nlp_get() is called before posting the event to
2488 * the work list to hold reference count of ndlp so that it guarantees the
2489 * reference to ndlp will still be available when the worker thread gets
2490 * to the event associated with the ndlp.
2493 lpfc_els_retry_delay(unsigned long ptr
)
2495 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) ptr
;
2496 struct lpfc_vport
*vport
= ndlp
->vport
;
2497 struct lpfc_hba
*phba
= vport
->phba
;
2498 unsigned long flags
;
2499 struct lpfc_work_evt
*evtp
= &ndlp
->els_retry_evt
;
2501 spin_lock_irqsave(&phba
->hbalock
, flags
);
2502 if (!list_empty(&evtp
->evt_listp
)) {
2503 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
2507 /* We need to hold the node by incrementing the reference
2508 * count until the queued work is done
2510 evtp
->evt_arg1
= lpfc_nlp_get(ndlp
);
2511 if (evtp
->evt_arg1
) {
2512 evtp
->evt
= LPFC_EVT_ELS_RETRY
;
2513 list_add_tail(&evtp
->evt_listp
, &phba
->work_list
);
2514 lpfc_worker_wake_up(phba
);
2516 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
2521 * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
2522 * @ndlp: pointer to a node-list data structure.
2524 * This routine is the worker-thread handler for processing the @ndlp delayed
2525 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
2526 * the last ELS command from the associated ndlp and invokes the proper ELS
2527 * function according to the delayed ELS command to retry the command.
2530 lpfc_els_retry_delay_handler(struct lpfc_nodelist
*ndlp
)
2532 struct lpfc_vport
*vport
= ndlp
->vport
;
2533 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2534 uint32_t cmd
, did
, retry
;
2536 spin_lock_irq(shost
->host_lock
);
2537 did
= ndlp
->nlp_DID
;
2538 cmd
= ndlp
->nlp_last_elscmd
;
2539 ndlp
->nlp_last_elscmd
= 0;
2541 if (!(ndlp
->nlp_flag
& NLP_DELAY_TMO
)) {
2542 spin_unlock_irq(shost
->host_lock
);
2546 ndlp
->nlp_flag
&= ~NLP_DELAY_TMO
;
2547 spin_unlock_irq(shost
->host_lock
);
2549 * If a discovery event readded nlp_delayfunc after timer
2550 * firing and before processing the timer, cancel the
2553 del_timer_sync(&ndlp
->nlp_delayfunc
);
2554 retry
= ndlp
->nlp_retry
;
2555 ndlp
->nlp_retry
= 0;
2559 lpfc_issue_els_flogi(vport
, ndlp
, retry
);
2562 if (!lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, retry
)) {
2563 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
2564 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
2568 if (!lpfc_issue_els_adisc(vport
, ndlp
, retry
)) {
2569 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
2570 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_ADISC_ISSUE
);
2574 if (!lpfc_issue_els_prli(vport
, ndlp
, retry
)) {
2575 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
2576 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PRLI_ISSUE
);
2580 if (!lpfc_issue_els_logo(vport
, ndlp
, retry
)) {
2581 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
2582 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
2586 lpfc_issue_els_fdisc(vport
, ndlp
, retry
);
2593 * lpfc_els_retry - Make retry decision on an els command iocb
2594 * @phba: pointer to lpfc hba data structure.
2595 * @cmdiocb: pointer to lpfc command iocb data structure.
2596 * @rspiocb: pointer to lpfc response iocb data structure.
2598 * This routine makes a retry decision on an ELS command IOCB, which has
2599 * failed. The following ELS IOCBs use this function for retrying the command
2600 * when previously issued command responsed with error status: FLOGI, PLOGI,
2601 * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
2602 * returned error status, it makes the decision whether a retry shall be
2603 * issued for the command, and whether a retry shall be made immediately or
2604 * delayed. In the former case, the corresponding ELS command issuing-function
2605 * is called to retry the command. In the later case, the ELS command shall
2606 * be posted to the ndlp delayed event and delayed function timer set to the
2607 * ndlp for the delayed command issusing.
2610 * 0 - No retry of els command is made
2611 * 1 - Immediate or delayed retry of els command is made
2614 lpfc_els_retry(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
2615 struct lpfc_iocbq
*rspiocb
)
2617 struct lpfc_vport
*vport
= cmdiocb
->vport
;
2618 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2619 IOCB_t
*irsp
= &rspiocb
->iocb
;
2620 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) cmdiocb
->context1
;
2621 struct lpfc_dmabuf
*pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
2624 int retry
= 0, maxretry
= lpfc_max_els_tries
, delay
= 0;
2630 /* Note: context2 may be 0 for internal driver abort
2631 * of delays ELS command.
2634 if (pcmd
&& pcmd
->virt
) {
2635 elscmd
= (uint32_t *) (pcmd
->virt
);
2639 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
))
2640 did
= ndlp
->nlp_DID
;
2642 /* We should only hit this case for retrying PLOGI */
2643 did
= irsp
->un
.elsreq64
.remoteID
;
2644 ndlp
= lpfc_findnode_did(vport
, did
);
2645 if ((!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
))
2646 && (cmd
!= ELS_CMD_PLOGI
))
2650 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
2651 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
2652 *(((uint32_t *) irsp
) + 7), irsp
->un
.ulpWord
[4], ndlp
->nlp_DID
);
2654 switch (irsp
->ulpStatus
) {
2655 case IOSTAT_FCP_RSP_ERROR
:
2656 case IOSTAT_REMOTE_STOP
:
2659 case IOSTAT_LOCAL_REJECT
:
2660 switch ((irsp
->un
.ulpWord
[4] & 0xff)) {
2661 case IOERR_LOOP_OPEN_FAILURE
:
2662 if (cmd
== ELS_CMD_FLOGI
) {
2663 if (PCI_DEVICE_ID_HORNET
==
2664 phba
->pcidev
->device
) {
2665 phba
->fc_topology
= TOPOLOGY_LOOP
;
2666 phba
->pport
->fc_myDID
= 0;
2667 phba
->alpa_map
[0] = 0;
2668 phba
->alpa_map
[1] = 0;
2671 if (cmd
== ELS_CMD_PLOGI
&& cmdiocb
->retry
== 0)
2676 case IOERR_ILLEGAL_COMMAND
:
2677 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
2678 "0124 Retry illegal cmd x%x "
2679 "retry:x%x delay:x%x\n",
2680 cmd
, cmdiocb
->retry
, delay
);
2682 /* All command's retry policy */
2684 if (cmdiocb
->retry
> 2)
2688 case IOERR_NO_RESOURCES
:
2689 logerr
= 1; /* HBA out of resources */
2691 if (cmdiocb
->retry
> 100)
2696 case IOERR_ILLEGAL_FRAME
:
2701 case IOERR_SEQUENCE_TIMEOUT
:
2702 case IOERR_INVALID_RPI
:
2708 case IOSTAT_NPORT_RJT
:
2709 case IOSTAT_FABRIC_RJT
:
2710 if (irsp
->un
.ulpWord
[4] & RJT_UNAVAIL_TEMP
) {
2716 case IOSTAT_NPORT_BSY
:
2717 case IOSTAT_FABRIC_BSY
:
2718 logerr
= 1; /* Fabric / Remote NPort out of resources */
2723 stat
.un
.lsRjtError
= be32_to_cpu(irsp
->un
.ulpWord
[4]);
2724 /* Added for Vendor specifc support
2725 * Just keep retrying for these Rsn / Exp codes
2727 switch (stat
.un
.b
.lsRjtRsnCode
) {
2728 case LSRJT_UNABLE_TPC
:
2729 if (stat
.un
.b
.lsRjtRsnCodeExp
==
2730 LSEXP_CMD_IN_PROGRESS
) {
2731 if (cmd
== ELS_CMD_PLOGI
) {
2738 if (cmd
== ELS_CMD_PLOGI
) {
2740 maxretry
= lpfc_max_els_tries
+ 1;
2744 if ((phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
2745 (cmd
== ELS_CMD_FDISC
) &&
2746 (stat
.un
.b
.lsRjtRsnCodeExp
== LSEXP_OUT_OF_RESOURCE
)){
2747 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
2748 "0125 FDISC Failed (x%x). "
2749 "Fabric out of resources\n",
2750 stat
.un
.lsRjtError
);
2751 lpfc_vport_set_state(vport
,
2752 FC_VPORT_NO_FABRIC_RSCS
);
2756 case LSRJT_LOGICAL_BSY
:
2757 if ((cmd
== ELS_CMD_PLOGI
) ||
2758 (cmd
== ELS_CMD_PRLI
)) {
2761 } else if (cmd
== ELS_CMD_FDISC
) {
2762 /* FDISC retry policy */
2764 if (cmdiocb
->retry
>= 32)
2770 case LSRJT_LOGICAL_ERR
:
2771 /* There are some cases where switches return this
2772 * error when they are not ready and should be returning
2773 * Logical Busy. We should delay every time.
2775 if (cmd
== ELS_CMD_FDISC
&&
2776 stat
.un
.b
.lsRjtRsnCodeExp
== LSEXP_PORT_LOGIN_REQ
) {
2782 case LSRJT_PROTOCOL_ERR
:
2783 if ((phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
2784 (cmd
== ELS_CMD_FDISC
) &&
2785 ((stat
.un
.b
.lsRjtRsnCodeExp
== LSEXP_INVALID_PNAME
) ||
2786 (stat
.un
.b
.lsRjtRsnCodeExp
== LSEXP_INVALID_NPORT_ID
))
2788 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
2789 "0122 FDISC Failed (x%x). "
2790 "Fabric Detected Bad WWN\n",
2791 stat
.un
.lsRjtError
);
2792 lpfc_vport_set_state(vport
,
2793 FC_VPORT_FABRIC_REJ_WWN
);
2799 case IOSTAT_INTERMED_RSP
:
2807 if (did
== FDMI_DID
)
2810 if (((cmd
== ELS_CMD_FLOGI
) || (cmd
== ELS_CMD_FDISC
)) &&
2811 (phba
->fc_topology
!= TOPOLOGY_LOOP
) &&
2812 !lpfc_error_lost_link(irsp
)) {
2813 /* FLOGI retry policy */
2817 if (cmdiocb
->retry
>= 100)
2819 else if (cmdiocb
->retry
>= 32)
2824 if (maxretry
&& (cmdiocb
->retry
>= maxretry
)) {
2825 phba
->fc_stat
.elsRetryExceeded
++;
2829 if ((vport
->load_flag
& FC_UNLOADING
) != 0)
2834 /* Retry ELS command <elsCmd> to remote NPORT <did> */
2835 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
2836 "0107 Retry ELS command x%x to remote "
2837 "NPORT x%x Data: x%x x%x\n",
2838 cmd
, did
, cmdiocb
->retry
, delay
);
2840 if (((cmd
== ELS_CMD_PLOGI
) || (cmd
== ELS_CMD_ADISC
)) &&
2841 ((irsp
->ulpStatus
!= IOSTAT_LOCAL_REJECT
) ||
2842 ((irsp
->un
.ulpWord
[4] & 0xff) != IOERR_NO_RESOURCES
))) {
2843 /* Don't reset timer for no resources */
2845 /* If discovery / RSCN timer is running, reset it */
2846 if (timer_pending(&vport
->fc_disctmo
) ||
2847 (vport
->fc_flag
& FC_RSCN_MODE
))
2848 lpfc_set_disctmo(vport
);
2851 phba
->fc_stat
.elsXmitRetry
++;
2852 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
) && delay
) {
2853 phba
->fc_stat
.elsDelayRetry
++;
2854 ndlp
->nlp_retry
= cmdiocb
->retry
;
2856 /* delay is specified in milliseconds */
2857 mod_timer(&ndlp
->nlp_delayfunc
,
2858 jiffies
+ msecs_to_jiffies(delay
));
2859 spin_lock_irq(shost
->host_lock
);
2860 ndlp
->nlp_flag
|= NLP_DELAY_TMO
;
2861 spin_unlock_irq(shost
->host_lock
);
2863 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
2864 if (cmd
== ELS_CMD_PRLI
)
2865 lpfc_nlp_set_state(vport
, ndlp
,
2866 NLP_STE_REG_LOGIN_ISSUE
);
2868 lpfc_nlp_set_state(vport
, ndlp
,
2870 ndlp
->nlp_last_elscmd
= cmd
;
2876 lpfc_issue_els_flogi(vport
, ndlp
, cmdiocb
->retry
);
2879 lpfc_issue_els_fdisc(vport
, ndlp
, cmdiocb
->retry
);
2882 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
)) {
2883 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
2884 lpfc_nlp_set_state(vport
, ndlp
,
2885 NLP_STE_PLOGI_ISSUE
);
2887 lpfc_issue_els_plogi(vport
, did
, cmdiocb
->retry
);
2890 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
2891 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_ADISC_ISSUE
);
2892 lpfc_issue_els_adisc(vport
, ndlp
, cmdiocb
->retry
);
2895 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
2896 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PRLI_ISSUE
);
2897 lpfc_issue_els_prli(vport
, ndlp
, cmdiocb
->retry
);
2900 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
2901 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
2902 lpfc_issue_els_logo(vport
, ndlp
, cmdiocb
->retry
);
2906 /* No retry ELS command <elsCmd> to remote NPORT <did> */
2908 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
2909 "0137 No retry ELS command x%x to remote "
2910 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
2911 cmd
, did
, irsp
->ulpStatus
,
2912 irsp
->un
.ulpWord
[4]);
2915 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
2916 "0108 No retry ELS command x%x to remote "
2917 "NPORT x%x Retried:%d Error:x%x/%x\n",
2918 cmd
, did
, cmdiocb
->retry
, irsp
->ulpStatus
,
2919 irsp
->un
.ulpWord
[4]);
2925 * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
2926 * @phba: pointer to lpfc hba data structure.
2927 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
2929 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
2930 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
2931 * checks to see whether there is a lpfc DMA buffer associated with the
2932 * response of the command IOCB. If so, it will be released before releasing
2933 * the lpfc DMA buffer associated with the IOCB itself.
2936 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
2939 lpfc_els_free_data(struct lpfc_hba
*phba
, struct lpfc_dmabuf
*buf_ptr1
)
2941 struct lpfc_dmabuf
*buf_ptr
;
2943 /* Free the response before processing the command. */
2944 if (!list_empty(&buf_ptr1
->list
)) {
2945 list_remove_head(&buf_ptr1
->list
, buf_ptr
,
2948 lpfc_mbuf_free(phba
, buf_ptr
->virt
, buf_ptr
->phys
);
2951 lpfc_mbuf_free(phba
, buf_ptr1
->virt
, buf_ptr1
->phys
);
2957 * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
2958 * @phba: pointer to lpfc hba data structure.
2959 * @buf_ptr: pointer to the lpfc dma buffer data structure.
2961 * This routine releases the lpfc Direct Memory Access (DMA) buffer
2962 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
2966 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
2969 lpfc_els_free_bpl(struct lpfc_hba
*phba
, struct lpfc_dmabuf
*buf_ptr
)
2971 lpfc_mbuf_free(phba
, buf_ptr
->virt
, buf_ptr
->phys
);
2977 * lpfc_els_free_iocb - Free a command iocb and its associated resources
2978 * @phba: pointer to lpfc hba data structure.
2979 * @elsiocb: pointer to lpfc els command iocb data structure.
2981 * This routine frees a command IOCB and its associated resources. The
2982 * command IOCB data structure contains the reference to various associated
2983 * resources, these fields must be set to NULL if the associated reference
2985 * context1 - reference to ndlp
2986 * context2 - reference to cmd
2987 * context2->next - reference to rsp
2988 * context3 - reference to bpl
2990 * It first properly decrements the reference count held on ndlp for the
2991 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
2992 * set, it invokes the lpfc_els_free_data() routine to release the Direct
2993 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
2994 * adds the DMA buffer the @phba data structure for the delayed release.
2995 * If reference to the Buffer Pointer List (BPL) is present, the
2996 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
2997 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
2998 * invoked to release the IOCB data structure back to @phba IOCBQ list.
3001 * 0 - Success (currently, always return 0)
3004 lpfc_els_free_iocb(struct lpfc_hba
*phba
, struct lpfc_iocbq
*elsiocb
)
3006 struct lpfc_dmabuf
*buf_ptr
, *buf_ptr1
;
3007 struct lpfc_nodelist
*ndlp
;
3009 ndlp
= (struct lpfc_nodelist
*)elsiocb
->context1
;
3011 if (ndlp
->nlp_flag
& NLP_DEFER_RM
) {
3014 /* If the ndlp is not being used by another discovery
3017 if (!lpfc_nlp_not_used(ndlp
)) {
3018 /* If ndlp is being used by another discovery
3019 * thread, just clear NLP_DEFER_RM
3021 ndlp
->nlp_flag
&= ~NLP_DEFER_RM
;
3026 elsiocb
->context1
= NULL
;
3028 /* context2 = cmd, context2->next = rsp, context3 = bpl */
3029 if (elsiocb
->context2
) {
3030 if (elsiocb
->iocb_flag
& LPFC_DELAY_MEM_FREE
) {
3031 /* Firmware could still be in progress of DMAing
3032 * payload, so don't free data buffer till after
3035 elsiocb
->iocb_flag
&= ~LPFC_DELAY_MEM_FREE
;
3036 buf_ptr
= elsiocb
->context2
;
3037 elsiocb
->context2
= NULL
;
3040 spin_lock_irq(&phba
->hbalock
);
3041 if (!list_empty(&buf_ptr
->list
)) {
3042 list_remove_head(&buf_ptr
->list
,
3043 buf_ptr1
, struct lpfc_dmabuf
,
3045 INIT_LIST_HEAD(&buf_ptr1
->list
);
3046 list_add_tail(&buf_ptr1
->list
,
3050 INIT_LIST_HEAD(&buf_ptr
->list
);
3051 list_add_tail(&buf_ptr
->list
, &phba
->elsbuf
);
3053 spin_unlock_irq(&phba
->hbalock
);
3056 buf_ptr1
= (struct lpfc_dmabuf
*) elsiocb
->context2
;
3057 lpfc_els_free_data(phba
, buf_ptr1
);
3061 if (elsiocb
->context3
) {
3062 buf_ptr
= (struct lpfc_dmabuf
*) elsiocb
->context3
;
3063 lpfc_els_free_bpl(phba
, buf_ptr
);
3065 lpfc_sli_release_iocbq(phba
, elsiocb
);
3070 * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
3071 * @phba: pointer to lpfc hba data structure.
3072 * @cmdiocb: pointer to lpfc command iocb data structure.
3073 * @rspiocb: pointer to lpfc response iocb data structure.
3075 * This routine is the completion callback function to the Logout (LOGO)
3076 * Accept (ACC) Response ELS command. This routine is invoked to indicate
3077 * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
3078 * release the ndlp if it has the last reference remaining (reference count
3079 * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
3080 * field to NULL to inform the following lpfc_els_free_iocb() routine no
3081 * ndlp reference count needs to be decremented. Otherwise, the ndlp
3082 * reference use-count shall be decremented by the lpfc_els_free_iocb()
3083 * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
3084 * IOCB data structure.
3087 lpfc_cmpl_els_logo_acc(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
3088 struct lpfc_iocbq
*rspiocb
)
3090 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) cmdiocb
->context1
;
3091 struct lpfc_vport
*vport
= cmdiocb
->vport
;
3094 irsp
= &rspiocb
->iocb
;
3095 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
3096 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
3097 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4], ndlp
->nlp_DID
);
3098 /* ACC to LOGO completes to NPort <nlp_DID> */
3099 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
3100 "0109 ACC to LOGO completes to NPort x%x "
3101 "Data: x%x x%x x%x\n",
3102 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
3105 if (ndlp
->nlp_state
== NLP_STE_NPR_NODE
) {
3106 /* NPort Recovery mode or node is just allocated */
3107 if (!lpfc_nlp_not_used(ndlp
)) {
3108 /* If the ndlp is being used by another discovery
3109 * thread, just unregister the RPI.
3111 lpfc_unreg_rpi(vport
, ndlp
);
3113 /* Indicate the node has already released, should
3114 * not reference to it from within lpfc_els_free_iocb.
3116 cmdiocb
->context1
= NULL
;
3119 lpfc_els_free_iocb(phba
, cmdiocb
);
3124 * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
3125 * @phba: pointer to lpfc hba data structure.
3126 * @pmb: pointer to the driver internal queue element for mailbox command.
3128 * This routine is the completion callback function for unregister default
3129 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
3130 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
3131 * decrements the ndlp reference count held for this completion callback
3132 * function. After that, it invokes the lpfc_nlp_not_used() to check
3133 * whether there is only one reference left on the ndlp. If so, it will
3134 * perform one more decrement and trigger the release of the ndlp.
3137 lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
3139 struct lpfc_dmabuf
*mp
= (struct lpfc_dmabuf
*) (pmb
->context1
);
3140 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) pmb
->context2
;
3143 * This routine is used to register and unregister in previous SLI
3146 if ((pmb
->u
.mb
.mbxCommand
== MBX_UNREG_LOGIN
) &&
3147 (phba
->sli_rev
== LPFC_SLI_REV4
))
3148 lpfc_sli4_free_rpi(phba
, pmb
->u
.mb
.un
.varUnregLogin
.rpi
);
3150 pmb
->context1
= NULL
;
3151 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
3153 mempool_free(pmb
, phba
->mbox_mem_pool
);
3154 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
)) {
3156 /* This is the end of the default RPI cleanup logic for this
3157 * ndlp. If no other discovery threads are using this ndlp.
3158 * we should free all resources associated with it.
3160 lpfc_nlp_not_used(ndlp
);
3167 * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
3168 * @phba: pointer to lpfc hba data structure.
3169 * @cmdiocb: pointer to lpfc command iocb data structure.
3170 * @rspiocb: pointer to lpfc response iocb data structure.
3172 * This routine is the completion callback function for ELS Response IOCB
3173 * command. In normal case, this callback function just properly sets the
3174 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
3175 * field in the command IOCB is not NULL, the referred mailbox command will
3176 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
3177 * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
3178 * link down event occurred during the discovery, the lpfc_nlp_not_used()
3179 * routine shall be invoked trying to release the ndlp if no other threads
3180 * are currently referring it.
3183 lpfc_cmpl_els_rsp(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
3184 struct lpfc_iocbq
*rspiocb
)
3186 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) cmdiocb
->context1
;
3187 struct lpfc_vport
*vport
= ndlp
? ndlp
->vport
: NULL
;
3188 struct Scsi_Host
*shost
= vport
? lpfc_shost_from_vport(vport
) : NULL
;
3191 LPFC_MBOXQ_t
*mbox
= NULL
;
3192 struct lpfc_dmabuf
*mp
= NULL
;
3193 uint32_t ls_rjt
= 0;
3195 irsp
= &rspiocb
->iocb
;
3197 if (cmdiocb
->context_un
.mbox
)
3198 mbox
= cmdiocb
->context_un
.mbox
;
3200 /* First determine if this is a LS_RJT cmpl. Note, this callback
3201 * function can have cmdiocb->contest1 (ndlp) field set to NULL.
3203 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) cmdiocb
->context2
)->virt
);
3204 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
) &&
3205 (*((uint32_t *) (pcmd
)) == ELS_CMD_LS_RJT
)) {
3206 /* A LS_RJT associated with Default RPI cleanup has its own
3207 * separate code path.
3209 if (!(ndlp
->nlp_flag
& NLP_RM_DFLT_RPI
))
3213 /* Check to see if link went down during discovery */
3214 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
) || lpfc_els_chk_latt(vport
)) {
3216 mp
= (struct lpfc_dmabuf
*) mbox
->context1
;
3218 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
3221 mempool_free(mbox
, phba
->mbox_mem_pool
);
3223 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
) &&
3224 (ndlp
->nlp_flag
& NLP_RM_DFLT_RPI
))
3225 if (lpfc_nlp_not_used(ndlp
)) {
3227 /* Indicate the node has already released,
3228 * should not reference to it from within
3229 * the routine lpfc_els_free_iocb.
3231 cmdiocb
->context1
= NULL
;
3236 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
3237 "ELS rsp cmpl: status:x%x/x%x did:x%x",
3238 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
3239 cmdiocb
->iocb
.un
.elsreq64
.remoteID
);
3240 /* ELS response tag <ulpIoTag> completes */
3241 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
3242 "0110 ELS response tag x%x completes "
3243 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
3244 cmdiocb
->iocb
.ulpIoTag
, rspiocb
->iocb
.ulpStatus
,
3245 rspiocb
->iocb
.un
.ulpWord
[4], rspiocb
->iocb
.ulpTimeout
,
3246 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
3249 if ((rspiocb
->iocb
.ulpStatus
== 0)
3250 && (ndlp
->nlp_flag
& NLP_ACC_REGLOGIN
)) {
3251 lpfc_unreg_rpi(vport
, ndlp
);
3252 /* Increment reference count to ndlp to hold the
3253 * reference to ndlp for the callback function.
3255 mbox
->context2
= lpfc_nlp_get(ndlp
);
3256 mbox
->vport
= vport
;
3257 if (ndlp
->nlp_flag
& NLP_RM_DFLT_RPI
) {
3258 mbox
->mbox_flag
|= LPFC_MBX_IMED_UNREG
;
3259 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_dflt_rpi
;
3262 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_reg_login
;
3263 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
3264 lpfc_nlp_set_state(vport
, ndlp
,
3265 NLP_STE_REG_LOGIN_ISSUE
);
3267 if (lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
)
3268 != MBX_NOT_FINISHED
)
3271 /* Decrement the ndlp reference count we
3272 * set for this failed mailbox command.
3276 /* ELS rsp: Cannot issue reg_login for <NPortid> */
3277 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
3278 "0138 ELS rsp: Cannot issue reg_login for x%x "
3279 "Data: x%x x%x x%x\n",
3280 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
3283 if (lpfc_nlp_not_used(ndlp
)) {
3285 /* Indicate node has already been released,
3286 * should not reference to it from within
3287 * the routine lpfc_els_free_iocb.
3289 cmdiocb
->context1
= NULL
;
3292 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
3293 if (!lpfc_error_lost_link(irsp
) &&
3294 ndlp
->nlp_flag
& NLP_ACC_REGLOGIN
) {
3295 if (lpfc_nlp_not_used(ndlp
)) {
3297 /* Indicate node has already been
3298 * released, should not reference
3299 * to it from within the routine
3300 * lpfc_els_free_iocb.
3302 cmdiocb
->context1
= NULL
;
3306 mp
= (struct lpfc_dmabuf
*) mbox
->context1
;
3308 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
3311 mempool_free(mbox
, phba
->mbox_mem_pool
);
3314 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
)) {
3315 spin_lock_irq(shost
->host_lock
);
3316 ndlp
->nlp_flag
&= ~(NLP_ACC_REGLOGIN
| NLP_RM_DFLT_RPI
);
3317 spin_unlock_irq(shost
->host_lock
);
3319 /* If the node is not being used by another discovery thread,
3320 * and we are sending a reject, we are done with it.
3321 * Release driver reference count here and free associated
3325 if (lpfc_nlp_not_used(ndlp
))
3326 /* Indicate node has already been released,
3327 * should not reference to it from within
3328 * the routine lpfc_els_free_iocb.
3330 cmdiocb
->context1
= NULL
;
3333 lpfc_els_free_iocb(phba
, cmdiocb
);
3338 * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
3339 * @vport: pointer to a host virtual N_Port data structure.
3340 * @flag: the els command code to be accepted.
3341 * @oldiocb: pointer to the original lpfc command iocb data structure.
3342 * @ndlp: pointer to a node-list data structure.
3343 * @mbox: pointer to the driver internal queue element for mailbox command.
3345 * This routine prepares and issues an Accept (ACC) response IOCB
3346 * command. It uses the @flag to properly set up the IOCB field for the
3347 * specific ACC response command to be issued and invokes the
3348 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
3349 * @mbox pointer is passed in, it will be put into the context_un.mbox
3350 * field of the IOCB for the completion callback function to issue the
3351 * mailbox command to the HBA later when callback is invoked.
3353 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3354 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3355 * will be stored into the context1 field of the IOCB for the completion
3356 * callback function to the corresponding response ELS IOCB command.
3359 * 0 - Successfully issued acc response
3360 * 1 - Failed to issue acc response
3363 lpfc_els_rsp_acc(struct lpfc_vport
*vport
, uint32_t flag
,
3364 struct lpfc_iocbq
*oldiocb
, struct lpfc_nodelist
*ndlp
,
3367 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
3368 struct lpfc_hba
*phba
= vport
->phba
;
3371 struct lpfc_iocbq
*elsiocb
;
3372 struct lpfc_sli
*psli
;
3376 ELS_PKT
*els_pkt_ptr
;
3379 oldcmd
= &oldiocb
->iocb
;
3383 cmdsize
= sizeof(uint32_t);
3384 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
,
3385 ndlp
, ndlp
->nlp_DID
, ELS_CMD_ACC
);
3387 spin_lock_irq(shost
->host_lock
);
3388 ndlp
->nlp_flag
&= ~NLP_LOGO_ACC
;
3389 spin_unlock_irq(shost
->host_lock
);
3393 icmd
= &elsiocb
->iocb
;
3394 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri */
3395 pcmd
= (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
3396 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
3397 pcmd
+= sizeof(uint32_t);
3399 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
3400 "Issue ACC: did:x%x flg:x%x",
3401 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
3404 cmdsize
= (sizeof(struct serv_parm
) + sizeof(uint32_t));
3405 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
,
3406 ndlp
, ndlp
->nlp_DID
, ELS_CMD_ACC
);
3410 icmd
= &elsiocb
->iocb
;
3411 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri */
3412 pcmd
= (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
3415 elsiocb
->context_un
.mbox
= mbox
;
3417 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
3418 pcmd
+= sizeof(uint32_t);
3419 memcpy(pcmd
, &vport
->fc_sparam
, sizeof(struct serv_parm
));
3421 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
3422 "Issue ACC PLOGI: did:x%x flg:x%x",
3423 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
3426 cmdsize
= sizeof(uint32_t) + sizeof(PRLO
);
3427 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
,
3428 ndlp
, ndlp
->nlp_DID
, ELS_CMD_PRLO
);
3432 icmd
= &elsiocb
->iocb
;
3433 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri */
3434 pcmd
= (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
3436 memcpy(pcmd
, ((struct lpfc_dmabuf
*) oldiocb
->context2
)->virt
,
3437 sizeof(uint32_t) + sizeof(PRLO
));
3438 *((uint32_t *) (pcmd
)) = ELS_CMD_PRLO_ACC
;
3439 els_pkt_ptr
= (ELS_PKT
*) pcmd
;
3440 els_pkt_ptr
->un
.prlo
.acceptRspCode
= PRLO_REQ_EXECUTED
;
3442 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
3443 "Issue ACC PRLO: did:x%x flg:x%x",
3444 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
3449 /* Xmit ELS ACC response tag <ulpIoTag> */
3450 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
3451 "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
3452 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n",
3453 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
,
3454 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
3456 if (ndlp
->nlp_flag
& NLP_LOGO_ACC
) {
3457 spin_lock_irq(shost
->host_lock
);
3458 ndlp
->nlp_flag
&= ~NLP_LOGO_ACC
;
3459 spin_unlock_irq(shost
->host_lock
);
3460 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_logo_acc
;
3462 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
3465 phba
->fc_stat
.elsXmitACC
++;
3466 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
3467 if (rc
== IOCB_ERROR
) {
3468 lpfc_els_free_iocb(phba
, elsiocb
);
3475 * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command
3476 * @vport: pointer to a virtual N_Port data structure.
3478 * @oldiocb: pointer to the original lpfc command iocb data structure.
3479 * @ndlp: pointer to a node-list data structure.
3480 * @mbox: pointer to the driver internal queue element for mailbox command.
3482 * This routine prepares and issue an Reject (RJT) response IOCB
3483 * command. If a @mbox pointer is passed in, it will be put into the
3484 * context_un.mbox field of the IOCB for the completion callback function
3485 * to issue to the HBA later.
3487 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3488 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3489 * will be stored into the context1 field of the IOCB for the completion
3490 * callback function to the reject response ELS IOCB command.
3493 * 0 - Successfully issued reject response
3494 * 1 - Failed to issue reject response
3497 lpfc_els_rsp_reject(struct lpfc_vport
*vport
, uint32_t rejectError
,
3498 struct lpfc_iocbq
*oldiocb
, struct lpfc_nodelist
*ndlp
,
3501 struct lpfc_hba
*phba
= vport
->phba
;
3504 struct lpfc_iocbq
*elsiocb
;
3505 struct lpfc_sli
*psli
;
3511 cmdsize
= 2 * sizeof(uint32_t);
3512 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
, ndlp
,
3513 ndlp
->nlp_DID
, ELS_CMD_LS_RJT
);
3517 icmd
= &elsiocb
->iocb
;
3518 oldcmd
= &oldiocb
->iocb
;
3519 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri */
3520 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
3522 *((uint32_t *) (pcmd
)) = ELS_CMD_LS_RJT
;
3523 pcmd
+= sizeof(uint32_t);
3524 *((uint32_t *) (pcmd
)) = rejectError
;
3527 elsiocb
->context_un
.mbox
= mbox
;
3529 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
3530 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
3531 "0129 Xmit ELS RJT x%x response tag x%x "
3532 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
3534 rejectError
, elsiocb
->iotag
,
3535 elsiocb
->iocb
.ulpContext
, ndlp
->nlp_DID
,
3536 ndlp
->nlp_flag
, ndlp
->nlp_state
, ndlp
->nlp_rpi
);
3537 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
3538 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
3539 ndlp
->nlp_DID
, ndlp
->nlp_flag
, rejectError
);
3541 phba
->fc_stat
.elsXmitLSRJT
++;
3542 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
3543 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
3545 if (rc
== IOCB_ERROR
) {
3546 lpfc_els_free_iocb(phba
, elsiocb
);
3553 * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
3554 * @vport: pointer to a virtual N_Port data structure.
3555 * @oldiocb: pointer to the original lpfc command iocb data structure.
3556 * @ndlp: pointer to a node-list data structure.
3558 * This routine prepares and issues an Accept (ACC) response to Address
3559 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
3560 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3562 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3563 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3564 * will be stored into the context1 field of the IOCB for the completion
3565 * callback function to the ADISC Accept response ELS IOCB command.
3568 * 0 - Successfully issued acc adisc response
3569 * 1 - Failed to issue adisc acc response
3572 lpfc_els_rsp_adisc_acc(struct lpfc_vport
*vport
, struct lpfc_iocbq
*oldiocb
,
3573 struct lpfc_nodelist
*ndlp
)
3575 struct lpfc_hba
*phba
= vport
->phba
;
3577 IOCB_t
*icmd
, *oldcmd
;
3578 struct lpfc_iocbq
*elsiocb
;
3583 cmdsize
= sizeof(uint32_t) + sizeof(ADISC
);
3584 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
, ndlp
,
3585 ndlp
->nlp_DID
, ELS_CMD_ACC
);
3589 icmd
= &elsiocb
->iocb
;
3590 oldcmd
= &oldiocb
->iocb
;
3591 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri */
3593 /* Xmit ADISC ACC response tag <ulpIoTag> */
3594 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
3595 "0130 Xmit ADISC ACC response iotag x%x xri: "
3596 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
3597 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
,
3598 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
3600 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
3602 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
3603 pcmd
+= sizeof(uint32_t);
3605 ap
= (ADISC
*) (pcmd
);
3606 ap
->hardAL_PA
= phba
->fc_pref_ALPA
;
3607 memcpy(&ap
->portName
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
3608 memcpy(&ap
->nodeName
, &vport
->fc_nodename
, sizeof(struct lpfc_name
));
3609 ap
->DID
= be32_to_cpu(vport
->fc_myDID
);
3611 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
3612 "Issue ACC ADISC: did:x%x flg:x%x",
3613 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
3615 phba
->fc_stat
.elsXmitACC
++;
3616 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
3617 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
3618 if (rc
== IOCB_ERROR
) {
3619 lpfc_els_free_iocb(phba
, elsiocb
);
3626 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
3627 * @vport: pointer to a virtual N_Port data structure.
3628 * @oldiocb: pointer to the original lpfc command iocb data structure.
3629 * @ndlp: pointer to a node-list data structure.
3631 * This routine prepares and issues an Accept (ACC) response to Process
3632 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
3633 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3635 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3636 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3637 * will be stored into the context1 field of the IOCB for the completion
3638 * callback function to the PRLI Accept response ELS IOCB command.
3641 * 0 - Successfully issued acc prli response
3642 * 1 - Failed to issue acc prli response
3645 lpfc_els_rsp_prli_acc(struct lpfc_vport
*vport
, struct lpfc_iocbq
*oldiocb
,
3646 struct lpfc_nodelist
*ndlp
)
3648 struct lpfc_hba
*phba
= vport
->phba
;
3653 struct lpfc_iocbq
*elsiocb
;
3654 struct lpfc_sli
*psli
;
3661 cmdsize
= sizeof(uint32_t) + sizeof(PRLI
);
3662 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
, ndlp
,
3663 ndlp
->nlp_DID
, (ELS_CMD_ACC
| (ELS_CMD_PRLI
& ~ELS_RSP_MASK
)));
3667 icmd
= &elsiocb
->iocb
;
3668 oldcmd
= &oldiocb
->iocb
;
3669 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri */
3670 /* Xmit PRLI ACC response tag <ulpIoTag> */
3671 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
3672 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
3673 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
3674 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
,
3675 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
3677 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
3679 *((uint32_t *) (pcmd
)) = (ELS_CMD_ACC
| (ELS_CMD_PRLI
& ~ELS_RSP_MASK
));
3680 pcmd
+= sizeof(uint32_t);
3682 /* For PRLI, remainder of payload is PRLI parameter page */
3683 memset(pcmd
, 0, sizeof(PRLI
));
3685 npr
= (PRLI
*) pcmd
;
3688 * If the remote port is a target and our firmware version is 3.20 or
3689 * later, set the following bits for FC-TAPE support.
3691 if ((ndlp
->nlp_type
& NLP_FCP_TARGET
) &&
3692 (vpd
->rev
.feaLevelHigh
>= 0x02)) {
3693 npr
->ConfmComplAllowed
= 1;
3695 npr
->TaskRetryIdReq
= 1;
3698 npr
->acceptRspCode
= PRLI_REQ_EXECUTED
;
3699 npr
->estabImagePair
= 1;
3700 npr
->readXferRdyDis
= 1;
3701 npr
->ConfmComplAllowed
= 1;
3703 npr
->prliType
= PRLI_FCP_TYPE
;
3704 npr
->initiatorFunc
= 1;
3706 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
3707 "Issue ACC PRLI: did:x%x flg:x%x",
3708 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
3710 phba
->fc_stat
.elsXmitACC
++;
3711 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
3713 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
3714 if (rc
== IOCB_ERROR
) {
3715 lpfc_els_free_iocb(phba
, elsiocb
);
3722 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
3723 * @vport: pointer to a virtual N_Port data structure.
3724 * @format: rnid command format.
3725 * @oldiocb: pointer to the original lpfc command iocb data structure.
3726 * @ndlp: pointer to a node-list data structure.
3728 * This routine issues a Request Node Identification Data (RNID) Accept
3729 * (ACC) response. It constructs the RNID ACC response command according to
3730 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
3731 * issue the response. Note that this command does not need to hold the ndlp
3732 * reference count for the callback. So, the ndlp reference count taken by
3733 * the lpfc_prep_els_iocb() routine is put back and the context1 field of
3734 * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
3735 * there is no ndlp reference available.
3737 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3738 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3739 * will be stored into the context1 field of the IOCB for the completion
3740 * callback function. However, for the RNID Accept Response ELS command,
3741 * this is undone later by this routine after the IOCB is allocated.
3744 * 0 - Successfully issued acc rnid response
3745 * 1 - Failed to issue acc rnid response
3748 lpfc_els_rsp_rnid_acc(struct lpfc_vport
*vport
, uint8_t format
,
3749 struct lpfc_iocbq
*oldiocb
, struct lpfc_nodelist
*ndlp
)
3751 struct lpfc_hba
*phba
= vport
->phba
;
3753 IOCB_t
*icmd
, *oldcmd
;
3754 struct lpfc_iocbq
*elsiocb
;
3755 struct lpfc_sli
*psli
;
3761 cmdsize
= sizeof(uint32_t) + sizeof(uint32_t)
3762 + (2 * sizeof(struct lpfc_name
));
3764 cmdsize
+= sizeof(RNID_TOP_DISC
);
3766 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
, ndlp
,
3767 ndlp
->nlp_DID
, ELS_CMD_ACC
);
3771 icmd
= &elsiocb
->iocb
;
3772 oldcmd
= &oldiocb
->iocb
;
3773 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri */
3774 /* Xmit RNID ACC response tag <ulpIoTag> */
3775 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
3776 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
3777 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
);
3778 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
3779 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
3780 pcmd
+= sizeof(uint32_t);
3782 memset(pcmd
, 0, sizeof(RNID
));
3783 rn
= (RNID
*) (pcmd
);
3784 rn
->Format
= format
;
3785 rn
->CommonLen
= (2 * sizeof(struct lpfc_name
));
3786 memcpy(&rn
->portName
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
3787 memcpy(&rn
->nodeName
, &vport
->fc_nodename
, sizeof(struct lpfc_name
));
3790 rn
->SpecificLen
= 0;
3792 case RNID_TOPOLOGY_DISC
:
3793 rn
->SpecificLen
= sizeof(RNID_TOP_DISC
);
3794 memcpy(&rn
->un
.topologyDisc
.portName
,
3795 &vport
->fc_portname
, sizeof(struct lpfc_name
));
3796 rn
->un
.topologyDisc
.unitType
= RNID_HBA
;
3797 rn
->un
.topologyDisc
.physPort
= 0;
3798 rn
->un
.topologyDisc
.attachedNodes
= 0;
3802 rn
->SpecificLen
= 0;
3806 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
3807 "Issue ACC RNID: did:x%x flg:x%x",
3808 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
3810 phba
->fc_stat
.elsXmitACC
++;
3811 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
3813 elsiocb
->context1
= NULL
; /* Don't need ndlp for cmpl,
3814 * it could be freed */
3816 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
3817 if (rc
== IOCB_ERROR
) {
3818 lpfc_els_free_iocb(phba
, elsiocb
);
3825 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
3826 * @vport: pointer to a host virtual N_Port data structure.
3828 * This routine issues Address Discover (ADISC) ELS commands to those
3829 * N_Ports which are in node port recovery state and ADISC has not been issued
3830 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
3831 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
3832 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
3833 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
3834 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
3835 * IOCBs quit for later pick up. On the other hand, after walking through
3836 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
3837 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
3838 * no more ADISC need to be sent.
3841 * The number of N_Ports with adisc issued.
3844 lpfc_els_disc_adisc(struct lpfc_vport
*vport
)
3846 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
3847 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
3850 /* go thru NPR nodes and issue any remaining ELS ADISCs */
3851 list_for_each_entry_safe(ndlp
, next_ndlp
, &vport
->fc_nodes
, nlp_listp
) {
3852 if (!NLP_CHK_NODE_ACT(ndlp
))
3854 if (ndlp
->nlp_state
== NLP_STE_NPR_NODE
&&
3855 (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
) != 0 &&
3856 (ndlp
->nlp_flag
& NLP_NPR_ADISC
) != 0) {
3857 spin_lock_irq(shost
->host_lock
);
3858 ndlp
->nlp_flag
&= ~NLP_NPR_ADISC
;
3859 spin_unlock_irq(shost
->host_lock
);
3860 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
3861 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_ADISC_ISSUE
);
3862 lpfc_issue_els_adisc(vport
, ndlp
, 0);
3864 vport
->num_disc_nodes
++;
3865 if (vport
->num_disc_nodes
>=
3866 vport
->cfg_discovery_threads
) {
3867 spin_lock_irq(shost
->host_lock
);
3868 vport
->fc_flag
|= FC_NLP_MORE
;
3869 spin_unlock_irq(shost
->host_lock
);
3874 if (sentadisc
== 0) {
3875 spin_lock_irq(shost
->host_lock
);
3876 vport
->fc_flag
&= ~FC_NLP_MORE
;
3877 spin_unlock_irq(shost
->host_lock
);
3883 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
3884 * @vport: pointer to a host virtual N_Port data structure.
3886 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
3887 * which are in node port recovery state, with a @vport. Each time an ELS
3888 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
3889 * the per @vport number of discover count (num_disc_nodes) shall be
3890 * incremented. If the num_disc_nodes reaches a pre-configured threshold
3891 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
3892 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
3893 * later pick up. On the other hand, after walking through all the ndlps with
3894 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
3895 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
3896 * PLOGI need to be sent.
3899 * The number of N_Ports with plogi issued.
3902 lpfc_els_disc_plogi(struct lpfc_vport
*vport
)
3904 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
3905 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
3908 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
3909 list_for_each_entry_safe(ndlp
, next_ndlp
, &vport
->fc_nodes
, nlp_listp
) {
3910 if (!NLP_CHK_NODE_ACT(ndlp
))
3912 if (ndlp
->nlp_state
== NLP_STE_NPR_NODE
&&
3913 (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
) != 0 &&
3914 (ndlp
->nlp_flag
& NLP_DELAY_TMO
) == 0 &&
3915 (ndlp
->nlp_flag
& NLP_NPR_ADISC
) == 0) {
3916 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
3917 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
3918 lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, 0);
3920 vport
->num_disc_nodes
++;
3921 if (vport
->num_disc_nodes
>=
3922 vport
->cfg_discovery_threads
) {
3923 spin_lock_irq(shost
->host_lock
);
3924 vport
->fc_flag
|= FC_NLP_MORE
;
3925 spin_unlock_irq(shost
->host_lock
);
3931 lpfc_set_disctmo(vport
);
3934 spin_lock_irq(shost
->host_lock
);
3935 vport
->fc_flag
&= ~FC_NLP_MORE
;
3936 spin_unlock_irq(shost
->host_lock
);
3942 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
3943 * @vport: pointer to a host virtual N_Port data structure.
3945 * This routine cleans up any Registration State Change Notification
3946 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
3947 * @vport together with the host_lock is used to prevent multiple thread
3948 * trying to access the RSCN array on a same @vport at the same time.
3951 lpfc_els_flush_rscn(struct lpfc_vport
*vport
)
3953 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
3954 struct lpfc_hba
*phba
= vport
->phba
;
3957 spin_lock_irq(shost
->host_lock
);
3958 if (vport
->fc_rscn_flush
) {
3959 /* Another thread is walking fc_rscn_id_list on this vport */
3960 spin_unlock_irq(shost
->host_lock
);
3963 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
3964 vport
->fc_rscn_flush
= 1;
3965 spin_unlock_irq(shost
->host_lock
);
3967 for (i
= 0; i
< vport
->fc_rscn_id_cnt
; i
++) {
3968 lpfc_in_buf_free(phba
, vport
->fc_rscn_id_list
[i
]);
3969 vport
->fc_rscn_id_list
[i
] = NULL
;
3971 spin_lock_irq(shost
->host_lock
);
3972 vport
->fc_rscn_id_cnt
= 0;
3973 vport
->fc_flag
&= ~(FC_RSCN_MODE
| FC_RSCN_DISCOVERY
);
3974 spin_unlock_irq(shost
->host_lock
);
3975 lpfc_can_disctmo(vport
);
3976 /* Indicate we are done walking this fc_rscn_id_list */
3977 vport
->fc_rscn_flush
= 0;
3981 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
3982 * @vport: pointer to a host virtual N_Port data structure.
3983 * @did: remote destination port identifier.
3985 * This routine checks whether there is any pending Registration State
3986 * Configuration Notification (RSCN) to a @did on @vport.
3989 * None zero - The @did matched with a pending rscn
3990 * 0 - not able to match @did with a pending rscn
3993 lpfc_rscn_payload_check(struct lpfc_vport
*vport
, uint32_t did
)
3998 uint32_t payload_len
, i
;
3999 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4001 ns_did
.un
.word
= did
;
4003 /* Never match fabric nodes for RSCNs */
4004 if ((did
& Fabric_DID_MASK
) == Fabric_DID_MASK
)
4007 /* If we are doing a FULL RSCN rediscovery, match everything */
4008 if (vport
->fc_flag
& FC_RSCN_DISCOVERY
)
4011 spin_lock_irq(shost
->host_lock
);
4012 if (vport
->fc_rscn_flush
) {
4013 /* Another thread is walking fc_rscn_id_list on this vport */
4014 spin_unlock_irq(shost
->host_lock
);
4017 /* Indicate we are walking fc_rscn_id_list on this vport */
4018 vport
->fc_rscn_flush
= 1;
4019 spin_unlock_irq(shost
->host_lock
);
4020 for (i
= 0; i
< vport
->fc_rscn_id_cnt
; i
++) {
4021 lp
= vport
->fc_rscn_id_list
[i
]->virt
;
4022 payload_len
= be32_to_cpu(*lp
++ & ~ELS_CMD_MASK
);
4023 payload_len
-= sizeof(uint32_t); /* take off word 0 */
4024 while (payload_len
) {
4025 rscn_did
.un
.word
= be32_to_cpu(*lp
++);
4026 payload_len
-= sizeof(uint32_t);
4027 switch (rscn_did
.un
.b
.resv
& RSCN_ADDRESS_FORMAT_MASK
) {
4028 case RSCN_ADDRESS_FORMAT_PORT
:
4029 if ((ns_did
.un
.b
.domain
== rscn_did
.un
.b
.domain
)
4030 && (ns_did
.un
.b
.area
== rscn_did
.un
.b
.area
)
4031 && (ns_did
.un
.b
.id
== rscn_did
.un
.b
.id
))
4032 goto return_did_out
;
4034 case RSCN_ADDRESS_FORMAT_AREA
:
4035 if ((ns_did
.un
.b
.domain
== rscn_did
.un
.b
.domain
)
4036 && (ns_did
.un
.b
.area
== rscn_did
.un
.b
.area
))
4037 goto return_did_out
;
4039 case RSCN_ADDRESS_FORMAT_DOMAIN
:
4040 if (ns_did
.un
.b
.domain
== rscn_did
.un
.b
.domain
)
4041 goto return_did_out
;
4043 case RSCN_ADDRESS_FORMAT_FABRIC
:
4044 goto return_did_out
;
4048 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4049 vport
->fc_rscn_flush
= 0;
4052 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4053 vport
->fc_rscn_flush
= 0;
4058 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
4059 * @vport: pointer to a host virtual N_Port data structure.
4061 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
4062 * state machine for a @vport's nodes that are with pending RSCN (Registration
4063 * State Change Notification).
4066 * 0 - Successful (currently alway return 0)
4069 lpfc_rscn_recovery_check(struct lpfc_vport
*vport
)
4071 struct lpfc_nodelist
*ndlp
= NULL
;
4073 /* Move all affected nodes by pending RSCNs to NPR state. */
4074 list_for_each_entry(ndlp
, &vport
->fc_nodes
, nlp_listp
) {
4075 if (!NLP_CHK_NODE_ACT(ndlp
) ||
4076 (ndlp
->nlp_state
== NLP_STE_UNUSED_NODE
) ||
4077 !lpfc_rscn_payload_check(vport
, ndlp
->nlp_DID
))
4079 lpfc_disc_state_machine(vport
, ndlp
, NULL
,
4080 NLP_EVT_DEVICE_RECOVERY
);
4081 lpfc_cancel_retry_delay_tmo(vport
, ndlp
);
4087 * lpfc_send_rscn_event - Send an RSCN event to management application
4088 * @vport: pointer to a host virtual N_Port data structure.
4089 * @cmdiocb: pointer to lpfc command iocb data structure.
4091 * lpfc_send_rscn_event sends an RSCN netlink event to management
4095 lpfc_send_rscn_event(struct lpfc_vport
*vport
,
4096 struct lpfc_iocbq
*cmdiocb
)
4098 struct lpfc_dmabuf
*pcmd
;
4099 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4100 uint32_t *payload_ptr
;
4101 uint32_t payload_len
;
4102 struct lpfc_rscn_event_header
*rscn_event_data
;
4104 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
4105 payload_ptr
= (uint32_t *) pcmd
->virt
;
4106 payload_len
= be32_to_cpu(*payload_ptr
& ~ELS_CMD_MASK
);
4108 rscn_event_data
= kmalloc(sizeof(struct lpfc_rscn_event_header
) +
4109 payload_len
, GFP_KERNEL
);
4110 if (!rscn_event_data
) {
4111 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
4112 "0147 Failed to allocate memory for RSCN event\n");
4115 rscn_event_data
->event_type
= FC_REG_RSCN_EVENT
;
4116 rscn_event_data
->payload_length
= payload_len
;
4117 memcpy(rscn_event_data
->rscn_payload
, payload_ptr
,
4120 fc_host_post_vendor_event(shost
,
4121 fc_get_event_number(),
4122 sizeof(struct lpfc_els_event_header
) + payload_len
,
4123 (char *)rscn_event_data
,
4126 kfree(rscn_event_data
);
4130 * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
4131 * @vport: pointer to a host virtual N_Port data structure.
4132 * @cmdiocb: pointer to lpfc command iocb data structure.
4133 * @ndlp: pointer to a node-list data structure.
4135 * This routine processes an unsolicited RSCN (Registration State Change
4136 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
4137 * to invoke fc_host_post_event() routine to the FC transport layer. If the
4138 * discover state machine is about to begin discovery, it just accepts the
4139 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
4140 * contains N_Port IDs for other vports on this HBA, it just accepts the
4141 * RSCN and ignore processing it. If the state machine is in the recovery
4142 * state, the fc_rscn_id_list of this @vport is walked and the
4143 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
4144 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
4145 * routine is invoked to handle the RSCN event.
4148 * 0 - Just sent the acc response
4149 * 1 - Sent the acc response and waited for name server completion
4152 lpfc_els_rcv_rscn(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
4153 struct lpfc_nodelist
*ndlp
)
4155 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4156 struct lpfc_hba
*phba
= vport
->phba
;
4157 struct lpfc_dmabuf
*pcmd
;
4158 uint32_t *lp
, *datap
;
4160 uint32_t payload_len
, length
, nportid
, *cmd
;
4162 int rscn_id
= 0, hba_id
= 0;
4165 icmd
= &cmdiocb
->iocb
;
4166 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
4167 lp
= (uint32_t *) pcmd
->virt
;
4169 payload_len
= be32_to_cpu(*lp
++ & ~ELS_CMD_MASK
);
4170 payload_len
-= sizeof(uint32_t); /* take off word 0 */
4172 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
4173 "0214 RSCN received Data: x%x x%x x%x x%x\n",
4174 vport
->fc_flag
, payload_len
, *lp
,
4175 vport
->fc_rscn_id_cnt
);
4177 /* Send an RSCN event to the management application */
4178 lpfc_send_rscn_event(vport
, cmdiocb
);
4180 for (i
= 0; i
< payload_len
/sizeof(uint32_t); i
++)
4181 fc_host_post_event(shost
, fc_get_event_number(),
4182 FCH_EVT_RSCN
, lp
[i
]);
4184 /* If we are about to begin discovery, just ACC the RSCN.
4185 * Discovery processing will satisfy it.
4187 if (vport
->port_state
<= LPFC_NS_QRY
) {
4188 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
4189 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
4190 ndlp
->nlp_DID
, vport
->port_state
, ndlp
->nlp_flag
);
4192 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
4196 /* If this RSCN just contains NPortIDs for other vports on this HBA,
4197 * just ACC and ignore it.
4199 if ((phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
4200 !(vport
->cfg_peer_port_login
)) {
4205 nportid
= ((be32_to_cpu(nportid
)) & Mask_DID
);
4206 i
-= sizeof(uint32_t);
4208 if (lpfc_find_vport_by_did(phba
, nportid
))
4211 if (rscn_id
== hba_id
) {
4212 /* ALL NPortIDs in RSCN are on HBA */
4213 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
4215 "Data: x%x x%x x%x x%x\n",
4216 vport
->fc_flag
, payload_len
,
4217 *lp
, vport
->fc_rscn_id_cnt
);
4218 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
4219 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
4220 ndlp
->nlp_DID
, vport
->port_state
,
4223 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
,
4229 spin_lock_irq(shost
->host_lock
);
4230 if (vport
->fc_rscn_flush
) {
4231 /* Another thread is walking fc_rscn_id_list on this vport */
4232 vport
->fc_flag
|= FC_RSCN_DISCOVERY
;
4233 spin_unlock_irq(shost
->host_lock
);
4235 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
4238 /* Indicate we are walking fc_rscn_id_list on this vport */
4239 vport
->fc_rscn_flush
= 1;
4240 spin_unlock_irq(shost
->host_lock
);
4241 /* Get the array count after successfully have the token */
4242 rscn_cnt
= vport
->fc_rscn_id_cnt
;
4243 /* If we are already processing an RSCN, save the received
4244 * RSCN payload buffer, cmdiocb->context2 to process later.
4246 if (vport
->fc_flag
& (FC_RSCN_MODE
| FC_NDISC_ACTIVE
)) {
4247 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
4248 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
4249 ndlp
->nlp_DID
, vport
->port_state
, ndlp
->nlp_flag
);
4251 spin_lock_irq(shost
->host_lock
);
4252 vport
->fc_flag
|= FC_RSCN_DEFERRED
;
4253 if ((rscn_cnt
< FC_MAX_HOLD_RSCN
) &&
4254 !(vport
->fc_flag
& FC_RSCN_DISCOVERY
)) {
4255 vport
->fc_flag
|= FC_RSCN_MODE
;
4256 spin_unlock_irq(shost
->host_lock
);
4258 cmd
= vport
->fc_rscn_id_list
[rscn_cnt
-1]->virt
;
4259 length
= be32_to_cpu(*cmd
& ~ELS_CMD_MASK
);
4262 (payload_len
+ length
<= LPFC_BPL_SIZE
)) {
4263 *cmd
&= ELS_CMD_MASK
;
4264 *cmd
|= cpu_to_be32(payload_len
+ length
);
4265 memcpy(((uint8_t *)cmd
) + length
, lp
,
4268 vport
->fc_rscn_id_list
[rscn_cnt
] = pcmd
;
4269 vport
->fc_rscn_id_cnt
++;
4270 /* If we zero, cmdiocb->context2, the calling
4271 * routine will not try to free it.
4273 cmdiocb
->context2
= NULL
;
4276 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
4277 "0235 Deferred RSCN "
4278 "Data: x%x x%x x%x\n",
4279 vport
->fc_rscn_id_cnt
, vport
->fc_flag
,
4282 vport
->fc_flag
|= FC_RSCN_DISCOVERY
;
4283 spin_unlock_irq(shost
->host_lock
);
4284 /* ReDiscovery RSCN */
4285 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
4286 "0234 ReDiscovery RSCN "
4287 "Data: x%x x%x x%x\n",
4288 vport
->fc_rscn_id_cnt
, vport
->fc_flag
,
4291 /* Indicate we are done walking fc_rscn_id_list on this vport */
4292 vport
->fc_rscn_flush
= 0;
4294 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
4295 /* send RECOVERY event for ALL nodes that match RSCN payload */
4296 lpfc_rscn_recovery_check(vport
);
4297 spin_lock_irq(shost
->host_lock
);
4298 vport
->fc_flag
&= ~FC_RSCN_DEFERRED
;
4299 spin_unlock_irq(shost
->host_lock
);
4302 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
4303 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
4304 ndlp
->nlp_DID
, vport
->port_state
, ndlp
->nlp_flag
);
4306 spin_lock_irq(shost
->host_lock
);
4307 vport
->fc_flag
|= FC_RSCN_MODE
;
4308 spin_unlock_irq(shost
->host_lock
);
4309 vport
->fc_rscn_id_list
[vport
->fc_rscn_id_cnt
++] = pcmd
;
4310 /* Indicate we are done walking fc_rscn_id_list on this vport */
4311 vport
->fc_rscn_flush
= 0;
4313 * If we zero, cmdiocb->context2, the calling routine will
4314 * not try to free it.
4316 cmdiocb
->context2
= NULL
;
4317 lpfc_set_disctmo(vport
);
4319 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
4320 /* send RECOVERY event for ALL nodes that match RSCN payload */
4321 lpfc_rscn_recovery_check(vport
);
4322 return lpfc_els_handle_rscn(vport
);
4326 * lpfc_els_handle_rscn - Handle rscn for a vport
4327 * @vport: pointer to a host virtual N_Port data structure.
4329 * This routine handles the Registration State Configuration Notification
4330 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
4331 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
4332 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
4333 * NameServer shall be issued. If CT command to the NameServer fails to be
4334 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
4335 * RSCN activities with the @vport.
4338 * 0 - Cleaned up rscn on the @vport
4339 * 1 - Wait for plogi to name server before proceed
4342 lpfc_els_handle_rscn(struct lpfc_vport
*vport
)
4344 struct lpfc_nodelist
*ndlp
;
4345 struct lpfc_hba
*phba
= vport
->phba
;
4347 /* Ignore RSCN if the port is being torn down. */
4348 if (vport
->load_flag
& FC_UNLOADING
) {
4349 lpfc_els_flush_rscn(vport
);
4353 /* Start timer for RSCN processing */
4354 lpfc_set_disctmo(vport
);
4356 /* RSCN processed */
4357 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
4358 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
4359 vport
->fc_flag
, 0, vport
->fc_rscn_id_cnt
,
4362 /* To process RSCN, first compare RSCN data with NameServer */
4363 vport
->fc_ns_retry
= 0;
4364 vport
->num_disc_nodes
= 0;
4366 ndlp
= lpfc_findnode_did(vport
, NameServer_DID
);
4367 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
)
4368 && ndlp
->nlp_state
== NLP_STE_UNMAPPED_NODE
) {
4369 /* Good ndlp, issue CT Request to NameServer */
4370 if (lpfc_ns_cmd(vport
, SLI_CTNS_GID_FT
, 0, 0) == 0)
4371 /* Wait for NameServer query cmpl before we can
4375 /* If login to NameServer does not exist, issue one */
4376 /* Good status, issue PLOGI to NameServer */
4377 ndlp
= lpfc_findnode_did(vport
, NameServer_DID
);
4378 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
))
4379 /* Wait for NameServer login cmpl before we can
4384 ndlp
= lpfc_enable_node(vport
, ndlp
,
4385 NLP_STE_PLOGI_ISSUE
);
4387 lpfc_els_flush_rscn(vport
);
4390 ndlp
->nlp_prev_state
= NLP_STE_UNUSED_NODE
;
4392 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
4394 lpfc_els_flush_rscn(vport
);
4397 lpfc_nlp_init(vport
, ndlp
, NameServer_DID
);
4398 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
4399 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
4401 ndlp
->nlp_type
|= NLP_FABRIC
;
4402 lpfc_issue_els_plogi(vport
, NameServer_DID
, 0);
4403 /* Wait for NameServer login cmpl before we can
4409 lpfc_els_flush_rscn(vport
);
4414 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
4415 * @vport: pointer to a host virtual N_Port data structure.
4416 * @cmdiocb: pointer to lpfc command iocb data structure.
4417 * @ndlp: pointer to a node-list data structure.
4419 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
4420 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
4421 * point topology. As an unsolicited FLOGI should not be received in a loop
4422 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
4423 * lpfc_check_sparm() routine is invoked to check the parameters in the
4424 * unsolicited FLOGI. If parameters validation failed, the routine
4425 * lpfc_els_rsp_reject() shall be called with reject reason code set to
4426 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
4427 * FLOGI shall be compared with the Port WWN of the @vport to determine who
4428 * will initiate PLOGI. The higher lexicographical value party shall has
4429 * higher priority (as the winning port) and will initiate PLOGI and
4430 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
4431 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
4432 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
4435 * 0 - Successfully processed the unsolicited flogi
4436 * 1 - Failed to process the unsolicited flogi
4439 lpfc_els_rcv_flogi(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
4440 struct lpfc_nodelist
*ndlp
)
4442 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4443 struct lpfc_hba
*phba
= vport
->phba
;
4444 struct lpfc_dmabuf
*pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
4445 uint32_t *lp
= (uint32_t *) pcmd
->virt
;
4446 IOCB_t
*icmd
= &cmdiocb
->iocb
;
4447 struct serv_parm
*sp
;
4454 sp
= (struct serv_parm
*) lp
;
4456 /* FLOGI received */
4458 lpfc_set_disctmo(vport
);
4460 if (phba
->fc_topology
== TOPOLOGY_LOOP
) {
4461 /* We should never receive a FLOGI in loop mode, ignore it */
4462 did
= icmd
->un
.elsreq64
.remoteID
;
4464 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
4466 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
4467 "0113 An FLOGI ELS command x%x was "
4468 "received from DID x%x in Loop Mode\n",
4475 if ((lpfc_check_sparm(vport
, ndlp
, sp
, CLASS3
, 1))) {
4476 /* For a FLOGI we accept, then if our portname is greater
4477 * then the remote portname we initiate Nport login.
4480 rc
= memcmp(&vport
->fc_portname
, &sp
->portName
,
4481 sizeof(struct lpfc_name
));
4484 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4488 lpfc_linkdown(phba
);
4489 lpfc_init_link(phba
, mbox
,
4491 phba
->cfg_link_speed
);
4492 mbox
->u
.mb
.un
.varInitLnk
.lipsr_AL_PA
= 0;
4493 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
4494 mbox
->vport
= vport
;
4495 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
4496 lpfc_set_loopback_flag(phba
);
4497 if (rc
== MBX_NOT_FINISHED
) {
4498 mempool_free(mbox
, phba
->mbox_mem_pool
);
4501 } else if (rc
> 0) { /* greater than */
4502 spin_lock_irq(shost
->host_lock
);
4503 vport
->fc_flag
|= FC_PT2PT_PLOGI
;
4504 spin_unlock_irq(shost
->host_lock
);
4506 spin_lock_irq(shost
->host_lock
);
4507 vport
->fc_flag
|= FC_PT2PT
;
4508 vport
->fc_flag
&= ~(FC_FABRIC
| FC_PUBLIC_LOOP
);
4509 spin_unlock_irq(shost
->host_lock
);
4511 /* Reject this request because invalid parameters */
4512 stat
.un
.b
.lsRjtRsvd0
= 0;
4513 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
4514 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_SPARM_OPTIONS
;
4515 stat
.un
.b
.vendorUnique
= 0;
4516 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
,
4522 lpfc_els_rsp_acc(vport
, ELS_CMD_PLOGI
, cmdiocb
, ndlp
, NULL
);
4528 * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
4529 * @vport: pointer to a host virtual N_Port data structure.
4530 * @cmdiocb: pointer to lpfc command iocb data structure.
4531 * @ndlp: pointer to a node-list data structure.
4533 * This routine processes Request Node Identification Data (RNID) IOCB
4534 * received as an ELS unsolicited event. Only when the RNID specified format
4535 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
4536 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
4537 * Accept (ACC) the RNID ELS command. All the other RNID formats are
4538 * rejected by invoking the lpfc_els_rsp_reject() routine.
4541 * 0 - Successfully processed rnid iocb (currently always return 0)
4544 lpfc_els_rcv_rnid(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
4545 struct lpfc_nodelist
*ndlp
)
4547 struct lpfc_dmabuf
*pcmd
;
4554 icmd
= &cmdiocb
->iocb
;
4555 did
= icmd
->un
.elsreq64
.remoteID
;
4556 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
4557 lp
= (uint32_t *) pcmd
->virt
;
4564 switch (rn
->Format
) {
4566 case RNID_TOPOLOGY_DISC
:
4568 lpfc_els_rsp_rnid_acc(vport
, rn
->Format
, cmdiocb
, ndlp
);
4571 /* Reject this request because format not supported */
4572 stat
.un
.b
.lsRjtRsvd0
= 0;
4573 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
4574 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_CANT_GIVE_DATA
;
4575 stat
.un
.b
.vendorUnique
= 0;
4576 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
,
4583 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
4584 * @vport: pointer to a host virtual N_Port data structure.
4585 * @cmdiocb: pointer to lpfc command iocb data structure.
4586 * @ndlp: pointer to a node-list data structure.
4588 * This routine processes a Link Incident Report Registration(LIRR) IOCB
4589 * received as an ELS unsolicited event. Currently, this function just invokes
4590 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
4593 * 0 - Successfully processed lirr iocb (currently always return 0)
4596 lpfc_els_rcv_lirr(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
4597 struct lpfc_nodelist
*ndlp
)
4601 /* For now, unconditionally reject this command */
4602 stat
.un
.b
.lsRjtRsvd0
= 0;
4603 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
4604 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_CANT_GIVE_DATA
;
4605 stat
.un
.b
.vendorUnique
= 0;
4606 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
4611 * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb
4612 * @vport: pointer to a host virtual N_Port data structure.
4613 * @cmdiocb: pointer to lpfc command iocb data structure.
4614 * @ndlp: pointer to a node-list data structure.
4616 * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB
4617 * received as an ELS unsolicited event. A request to RRQ shall only
4618 * be accepted if the Originator Nx_Port N_Port_ID or the Responder
4619 * Nx_Port N_Port_ID of the target Exchange is the same as the
4620 * N_Port_ID of the Nx_Port that makes the request. If the RRQ is
4621 * not accepted, an LS_RJT with reason code "Unable to perform
4622 * command request" and reason code explanation "Invalid Originator
4623 * S_ID" shall be returned. For now, we just unconditionally accept
4624 * RRQ from the target.
4627 lpfc_els_rcv_rrq(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
4628 struct lpfc_nodelist
*ndlp
)
4630 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
4634 * lpfc_els_rsp_rps_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
4635 * @phba: pointer to lpfc hba data structure.
4636 * @pmb: pointer to the driver internal queue element for mailbox command.
4638 * This routine is the completion callback function for the MBX_READ_LNK_STAT
4639 * mailbox command. This callback function is to actually send the Accept
4640 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
4641 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
4642 * mailbox command, constructs the RPS response with the link statistics
4643 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
4644 * response to the RPS.
4646 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4647 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4648 * will be stored into the context1 field of the IOCB for the completion
4649 * callback function to the RPS Accept Response ELS IOCB command.
4653 lpfc_els_rsp_rps_acc(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
4659 struct lpfc_iocbq
*elsiocb
;
4660 struct lpfc_nodelist
*ndlp
;
4661 uint16_t xri
, status
;
4666 ndlp
= (struct lpfc_nodelist
*) pmb
->context2
;
4667 xri
= (uint16_t) ((unsigned long)(pmb
->context1
));
4668 pmb
->context1
= NULL
;
4669 pmb
->context2
= NULL
;
4671 if (mb
->mbxStatus
) {
4672 mempool_free(pmb
, phba
->mbox_mem_pool
);
4676 cmdsize
= sizeof(RPS_RSP
) + sizeof(uint32_t);
4677 mempool_free(pmb
, phba
->mbox_mem_pool
);
4678 elsiocb
= lpfc_prep_els_iocb(phba
->pport
, 0, cmdsize
,
4679 lpfc_max_els_tries
, ndlp
,
4680 ndlp
->nlp_DID
, ELS_CMD_ACC
);
4682 /* Decrement the ndlp reference count from previous mbox command */
4688 icmd
= &elsiocb
->iocb
;
4689 icmd
->ulpContext
= xri
;
4691 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
4692 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
4693 pcmd
+= sizeof(uint32_t); /* Skip past command */
4694 rps_rsp
= (RPS_RSP
*)pcmd
;
4696 if (phba
->fc_topology
!= TOPOLOGY_LOOP
)
4700 if (phba
->pport
->fc_flag
& FC_FABRIC
)
4704 rps_rsp
->portStatus
= cpu_to_be16(status
);
4705 rps_rsp
->linkFailureCnt
= cpu_to_be32(mb
->un
.varRdLnk
.linkFailureCnt
);
4706 rps_rsp
->lossSyncCnt
= cpu_to_be32(mb
->un
.varRdLnk
.lossSyncCnt
);
4707 rps_rsp
->lossSignalCnt
= cpu_to_be32(mb
->un
.varRdLnk
.lossSignalCnt
);
4708 rps_rsp
->primSeqErrCnt
= cpu_to_be32(mb
->un
.varRdLnk
.primSeqErrCnt
);
4709 rps_rsp
->invalidXmitWord
= cpu_to_be32(mb
->un
.varRdLnk
.invalidXmitWord
);
4710 rps_rsp
->crcCnt
= cpu_to_be32(mb
->un
.varRdLnk
.crcCnt
);
4711 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
4712 lpfc_printf_vlog(ndlp
->vport
, KERN_INFO
, LOG_ELS
,
4713 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
4714 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
4715 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
,
4716 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
4718 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
4719 phba
->fc_stat
.elsXmitACC
++;
4720 if (lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0) == IOCB_ERROR
)
4721 lpfc_els_free_iocb(phba
, elsiocb
);
4726 * lpfc_els_rcv_rps - Process an unsolicited rps iocb
4727 * @vport: pointer to a host virtual N_Port data structure.
4728 * @cmdiocb: pointer to lpfc command iocb data structure.
4729 * @ndlp: pointer to a node-list data structure.
4731 * This routine processes Read Port Status (RPS) IOCB received as an
4732 * ELS unsolicited event. It first checks the remote port state. If the
4733 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
4734 * state, it invokes the lpfc_els_rsp_reject() routine to send the reject
4735 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
4736 * for reading the HBA link statistics. It is for the callback function,
4737 * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command
4738 * to actually sending out RPS Accept (ACC) response.
4741 * 0 - Successfully processed rps iocb (currently always return 0)
4744 lpfc_els_rcv_rps(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
4745 struct lpfc_nodelist
*ndlp
)
4747 struct lpfc_hba
*phba
= vport
->phba
;
4751 struct lpfc_dmabuf
*pcmd
;
4755 if ((ndlp
->nlp_state
!= NLP_STE_UNMAPPED_NODE
) &&
4756 (ndlp
->nlp_state
!= NLP_STE_MAPPED_NODE
))
4757 /* reject the unsolicited RPS request and done with it */
4760 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
4761 lp
= (uint32_t *) pcmd
->virt
;
4762 flag
= (be32_to_cpu(*lp
++) & 0xf);
4766 ((flag
== 1) && (be32_to_cpu(rps
->un
.portNum
) == 0)) ||
4767 ((flag
== 2) && (memcmp(&rps
->un
.portName
, &vport
->fc_portname
,
4768 sizeof(struct lpfc_name
)) == 0))) {
4770 printk("Fix me....\n");
4772 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_ATOMIC
);
4774 lpfc_read_lnk_stat(phba
, mbox
);
4776 (void *)((unsigned long) cmdiocb
->iocb
.ulpContext
);
4777 mbox
->context2
= lpfc_nlp_get(ndlp
);
4778 mbox
->vport
= vport
;
4779 mbox
->mbox_cmpl
= lpfc_els_rsp_rps_acc
;
4780 if (lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
)
4781 != MBX_NOT_FINISHED
)
4782 /* Mbox completion will send ELS Response */
4784 /* Decrement reference count used for the failed mbox
4788 mempool_free(mbox
, phba
->mbox_mem_pool
);
4793 /* issue rejection response */
4794 stat
.un
.b
.lsRjtRsvd0
= 0;
4795 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
4796 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_CANT_GIVE_DATA
;
4797 stat
.un
.b
.vendorUnique
= 0;
4798 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
4803 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
4804 * @vport: pointer to a host virtual N_Port data structure.
4805 * @cmdsize: size of the ELS command.
4806 * @oldiocb: pointer to the original lpfc command iocb data structure.
4807 * @ndlp: pointer to a node-list data structure.
4809 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
4810 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
4812 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4813 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4814 * will be stored into the context1 field of the IOCB for the completion
4815 * callback function to the RPL Accept Response ELS command.
4818 * 0 - Successfully issued ACC RPL ELS command
4819 * 1 - Failed to issue ACC RPL ELS command
4822 lpfc_els_rsp_rpl_acc(struct lpfc_vport
*vport
, uint16_t cmdsize
,
4823 struct lpfc_iocbq
*oldiocb
, struct lpfc_nodelist
*ndlp
)
4825 struct lpfc_hba
*phba
= vport
->phba
;
4826 IOCB_t
*icmd
, *oldcmd
;
4828 struct lpfc_iocbq
*elsiocb
;
4831 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
, ndlp
,
4832 ndlp
->nlp_DID
, ELS_CMD_ACC
);
4837 icmd
= &elsiocb
->iocb
;
4838 oldcmd
= &oldiocb
->iocb
;
4839 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri */
4841 pcmd
= (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
4842 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
4843 pcmd
+= sizeof(uint16_t);
4844 *((uint16_t *)(pcmd
)) = be16_to_cpu(cmdsize
);
4845 pcmd
+= sizeof(uint16_t);
4847 /* Setup the RPL ACC payload */
4848 rpl_rsp
.listLen
= be32_to_cpu(1);
4850 rpl_rsp
.port_num_blk
.portNum
= 0;
4851 rpl_rsp
.port_num_blk
.portID
= be32_to_cpu(vport
->fc_myDID
);
4852 memcpy(&rpl_rsp
.port_num_blk
.portName
, &vport
->fc_portname
,
4853 sizeof(struct lpfc_name
));
4854 memcpy(pcmd
, &rpl_rsp
, cmdsize
- sizeof(uint32_t));
4855 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
4856 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
4857 "0120 Xmit ELS RPL ACC response tag x%x "
4858 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
4860 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
,
4861 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
4863 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
4864 phba
->fc_stat
.elsXmitACC
++;
4865 if (lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0) ==
4867 lpfc_els_free_iocb(phba
, elsiocb
);
4874 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
4875 * @vport: pointer to a host virtual N_Port data structure.
4876 * @cmdiocb: pointer to lpfc command iocb data structure.
4877 * @ndlp: pointer to a node-list data structure.
4879 * This routine processes Read Port List (RPL) IOCB received as an ELS
4880 * unsolicited event. It first checks the remote port state. If the remote
4881 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
4882 * invokes the lpfc_els_rsp_reject() routine to send reject response.
4883 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
4884 * to accept the RPL.
4887 * 0 - Successfully processed rpl iocb (currently always return 0)
4890 lpfc_els_rcv_rpl(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
4891 struct lpfc_nodelist
*ndlp
)
4893 struct lpfc_dmabuf
*pcmd
;
4900 if ((ndlp
->nlp_state
!= NLP_STE_UNMAPPED_NODE
) &&
4901 (ndlp
->nlp_state
!= NLP_STE_MAPPED_NODE
)) {
4902 /* issue rejection response */
4903 stat
.un
.b
.lsRjtRsvd0
= 0;
4904 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
4905 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_CANT_GIVE_DATA
;
4906 stat
.un
.b
.vendorUnique
= 0;
4907 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
,
4909 /* rejected the unsolicited RPL request and done with it */
4913 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
4914 lp
= (uint32_t *) pcmd
->virt
;
4915 rpl
= (RPL
*) (lp
+ 1);
4917 maxsize
= be32_to_cpu(rpl
->maxsize
);
4919 /* We support only one port */
4920 if ((rpl
->index
== 0) &&
4922 ((maxsize
* sizeof(uint32_t)) >= sizeof(RPL_RSP
)))) {
4923 cmdsize
= sizeof(uint32_t) + sizeof(RPL_RSP
);
4925 cmdsize
= sizeof(uint32_t) + maxsize
* sizeof(uint32_t);
4927 lpfc_els_rsp_rpl_acc(vport
, cmdsize
, cmdiocb
, ndlp
);
4933 * lpfc_els_rcv_farp - Process an unsolicited farp request els command
4934 * @vport: pointer to a virtual N_Port data structure.
4935 * @cmdiocb: pointer to lpfc command iocb data structure.
4936 * @ndlp: pointer to a node-list data structure.
4938 * This routine processes Fibre Channel Address Resolution Protocol
4939 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
4940 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
4941 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
4942 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
4943 * remote PortName is compared against the FC PortName stored in the @vport
4944 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
4945 * compared against the FC NodeName stored in the @vport data structure.
4946 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
4947 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
4948 * invoked to send out FARP Response to the remote node. Before sending the
4949 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
4950 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
4951 * routine is invoked to log into the remote port first.
4954 * 0 - Either the FARP Match Mode not supported or successfully processed
4957 lpfc_els_rcv_farp(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
4958 struct lpfc_nodelist
*ndlp
)
4960 struct lpfc_dmabuf
*pcmd
;
4964 uint32_t cmd
, cnt
, did
;
4966 icmd
= &cmdiocb
->iocb
;
4967 did
= icmd
->un
.elsreq64
.remoteID
;
4968 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
4969 lp
= (uint32_t *) pcmd
->virt
;
4973 /* FARP-REQ received from DID <did> */
4974 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
4975 "0601 FARP-REQ received from DID x%x\n", did
);
4976 /* We will only support match on WWPN or WWNN */
4977 if (fp
->Mflags
& ~(FARP_MATCH_NODE
| FARP_MATCH_PORT
)) {
4982 /* If this FARP command is searching for my portname */
4983 if (fp
->Mflags
& FARP_MATCH_PORT
) {
4984 if (memcmp(&fp
->RportName
, &vport
->fc_portname
,
4985 sizeof(struct lpfc_name
)) == 0)
4989 /* If this FARP command is searching for my nodename */
4990 if (fp
->Mflags
& FARP_MATCH_NODE
) {
4991 if (memcmp(&fp
->RnodeName
, &vport
->fc_nodename
,
4992 sizeof(struct lpfc_name
)) == 0)
4997 if ((ndlp
->nlp_state
== NLP_STE_UNMAPPED_NODE
) ||
4998 (ndlp
->nlp_state
== NLP_STE_MAPPED_NODE
)) {
4999 /* Log back into the node before sending the FARP. */
5000 if (fp
->Rflags
& FARP_REQUEST_PLOGI
) {
5001 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
5002 lpfc_nlp_set_state(vport
, ndlp
,
5003 NLP_STE_PLOGI_ISSUE
);
5004 lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, 0);
5007 /* Send a FARP response to that node */
5008 if (fp
->Rflags
& FARP_REQUEST_FARPR
)
5009 lpfc_issue_els_farpr(vport
, did
, 0);
5016 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
5017 * @vport: pointer to a host virtual N_Port data structure.
5018 * @cmdiocb: pointer to lpfc command iocb data structure.
5019 * @ndlp: pointer to a node-list data structure.
5021 * This routine processes Fibre Channel Address Resolution Protocol
5022 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
5023 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
5024 * the FARP response request.
5027 * 0 - Successfully processed FARPR IOCB (currently always return 0)
5030 lpfc_els_rcv_farpr(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
5031 struct lpfc_nodelist
*ndlp
)
5033 struct lpfc_dmabuf
*pcmd
;
5038 icmd
= &cmdiocb
->iocb
;
5039 did
= icmd
->un
.elsreq64
.remoteID
;
5040 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
5041 lp
= (uint32_t *) pcmd
->virt
;
5044 /* FARP-RSP received from DID <did> */
5045 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
5046 "0600 FARP-RSP received from DID x%x\n", did
);
5047 /* ACCEPT the Farp resp request */
5048 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
5054 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
5055 * @vport: pointer to a host virtual N_Port data structure.
5056 * @cmdiocb: pointer to lpfc command iocb data structure.
5057 * @fan_ndlp: pointer to a node-list data structure.
5059 * This routine processes a Fabric Address Notification (FAN) IOCB
5060 * command received as an ELS unsolicited event. The FAN ELS command will
5061 * only be processed on a physical port (i.e., the @vport represents the
5062 * physical port). The fabric NodeName and PortName from the FAN IOCB are
5063 * compared against those in the phba data structure. If any of those is
5064 * different, the lpfc_initial_flogi() routine is invoked to initialize
5065 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
5066 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
5067 * is invoked to register login to the fabric.
5070 * 0 - Successfully processed fan iocb (currently always return 0).
5073 lpfc_els_rcv_fan(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
5074 struct lpfc_nodelist
*fan_ndlp
)
5076 struct lpfc_hba
*phba
= vport
->phba
;
5080 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
, "0265 FAN received\n");
5081 lp
= (uint32_t *)((struct lpfc_dmabuf
*)cmdiocb
->context2
)->virt
;
5083 /* FAN received; Fan does not have a reply sequence */
5084 if ((vport
== phba
->pport
) &&
5085 (vport
->port_state
== LPFC_LOCAL_CFG_LINK
)) {
5086 if ((memcmp(&phba
->fc_fabparam
.nodeName
, &fp
->FnodeName
,
5087 sizeof(struct lpfc_name
))) ||
5088 (memcmp(&phba
->fc_fabparam
.portName
, &fp
->FportName
,
5089 sizeof(struct lpfc_name
)))) {
5090 /* This port has switched fabrics. FLOGI is required */
5091 lpfc_initial_flogi(vport
);
5093 /* FAN verified - skip FLOGI */
5094 vport
->fc_myDID
= vport
->fc_prevDID
;
5095 if (phba
->sli_rev
< LPFC_SLI_REV4
)
5096 lpfc_issue_fabric_reglogin(vport
);
5098 lpfc_issue_reg_vfi(vport
);
5105 * lpfc_els_timeout - Handler funciton to the els timer
5106 * @ptr: holder for the timer function associated data.
5108 * This routine is invoked by the ELS timer after timeout. It posts the ELS
5109 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
5110 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
5111 * up the worker thread. It is for the worker thread to invoke the routine
5112 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
5115 lpfc_els_timeout(unsigned long ptr
)
5117 struct lpfc_vport
*vport
= (struct lpfc_vport
*) ptr
;
5118 struct lpfc_hba
*phba
= vport
->phba
;
5119 uint32_t tmo_posted
;
5120 unsigned long iflag
;
5122 spin_lock_irqsave(&vport
->work_port_lock
, iflag
);
5123 tmo_posted
= vport
->work_port_events
& WORKER_ELS_TMO
;
5125 vport
->work_port_events
|= WORKER_ELS_TMO
;
5126 spin_unlock_irqrestore(&vport
->work_port_lock
, iflag
);
5129 lpfc_worker_wake_up(phba
);
5134 * lpfc_els_timeout_handler - Process an els timeout event
5135 * @vport: pointer to a virtual N_Port data structure.
5137 * This routine is the actual handler function that processes an ELS timeout
5138 * event. It walks the ELS ring to get and abort all the IOCBs (except the
5139 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
5140 * invoking the lpfc_sli_issue_abort_iotag() routine.
5143 lpfc_els_timeout_handler(struct lpfc_vport
*vport
)
5145 struct lpfc_hba
*phba
= vport
->phba
;
5146 struct lpfc_sli_ring
*pring
;
5147 struct lpfc_iocbq
*tmp_iocb
, *piocb
;
5149 struct lpfc_dmabuf
*pcmd
;
5150 uint32_t els_command
= 0;
5152 uint32_t remote_ID
= 0xffffffff;
5154 spin_lock_irq(&phba
->hbalock
);
5155 timeout
= (uint32_t)(phba
->fc_ratov
<< 1);
5157 pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
5159 list_for_each_entry_safe(piocb
, tmp_iocb
, &pring
->txcmplq
, list
) {
5162 if ((piocb
->iocb_flag
& LPFC_IO_LIBDFC
) != 0 ||
5163 piocb
->iocb
.ulpCommand
== CMD_ABORT_XRI_CN
||
5164 piocb
->iocb
.ulpCommand
== CMD_CLOSE_XRI_CN
)
5167 if (piocb
->vport
!= vport
)
5170 pcmd
= (struct lpfc_dmabuf
*) piocb
->context2
;
5172 els_command
= *(uint32_t *) (pcmd
->virt
);
5174 if (els_command
== ELS_CMD_FARP
||
5175 els_command
== ELS_CMD_FARPR
||
5176 els_command
== ELS_CMD_FDISC
)
5179 if (piocb
->drvrTimeout
> 0) {
5180 if (piocb
->drvrTimeout
>= timeout
)
5181 piocb
->drvrTimeout
-= timeout
;
5183 piocb
->drvrTimeout
= 0;
5187 remote_ID
= 0xffffffff;
5188 if (cmd
->ulpCommand
!= CMD_GEN_REQUEST64_CR
)
5189 remote_ID
= cmd
->un
.elsreq64
.remoteID
;
5191 struct lpfc_nodelist
*ndlp
;
5192 ndlp
= __lpfc_findnode_rpi(vport
, cmd
->ulpContext
);
5193 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
))
5194 remote_ID
= ndlp
->nlp_DID
;
5196 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
5197 "0127 ELS timeout Data: x%x x%x x%x "
5198 "x%x\n", els_command
,
5199 remote_ID
, cmd
->ulpCommand
, cmd
->ulpIoTag
);
5200 lpfc_sli_issue_abort_iotag(phba
, pring
, piocb
);
5202 spin_unlock_irq(&phba
->hbalock
);
5204 if (phba
->sli
.ring
[LPFC_ELS_RING
].txcmplq_cnt
)
5205 mod_timer(&vport
->els_tmofunc
, jiffies
+ HZ
* timeout
);
5209 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
5210 * @vport: pointer to a host virtual N_Port data structure.
5212 * This routine is used to clean up all the outstanding ELS commands on a
5213 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
5214 * routine. After that, it walks the ELS transmit queue to remove all the
5215 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
5216 * the IOCBs with a non-NULL completion callback function, the callback
5217 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
5218 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
5219 * callback function, the IOCB will simply be released. Finally, it walks
5220 * the ELS transmit completion queue to issue an abort IOCB to any transmit
5221 * completion queue IOCB that is associated with the @vport and is not
5222 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
5223 * part of the discovery state machine) out to HBA by invoking the
5224 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
5225 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
5226 * the IOCBs are aborted when this function returns.
5229 lpfc_els_flush_cmd(struct lpfc_vport
*vport
)
5231 LIST_HEAD(completions
);
5232 struct lpfc_hba
*phba
= vport
->phba
;
5233 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
5234 struct lpfc_iocbq
*tmp_iocb
, *piocb
;
5237 lpfc_fabric_abort_vport(vport
);
5239 spin_lock_irq(&phba
->hbalock
);
5240 list_for_each_entry_safe(piocb
, tmp_iocb
, &pring
->txq
, list
) {
5243 if (piocb
->iocb_flag
& LPFC_IO_LIBDFC
) {
5247 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
5248 if (cmd
->ulpCommand
== CMD_QUE_RING_BUF_CN
||
5249 cmd
->ulpCommand
== CMD_QUE_RING_BUF64_CN
||
5250 cmd
->ulpCommand
== CMD_CLOSE_XRI_CN
||
5251 cmd
->ulpCommand
== CMD_ABORT_XRI_CN
)
5254 if (piocb
->vport
!= vport
)
5257 list_move_tail(&piocb
->list
, &completions
);
5261 list_for_each_entry_safe(piocb
, tmp_iocb
, &pring
->txcmplq
, list
) {
5262 if (piocb
->iocb_flag
& LPFC_IO_LIBDFC
) {
5266 if (piocb
->vport
!= vport
)
5269 lpfc_sli_issue_abort_iotag(phba
, pring
, piocb
);
5271 spin_unlock_irq(&phba
->hbalock
);
5273 /* Cancell all the IOCBs from the completions list */
5274 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
5281 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
5282 * @phba: pointer to lpfc hba data structure.
5284 * This routine is used to clean up all the outstanding ELS commands on a
5285 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
5286 * routine. After that, it walks the ELS transmit queue to remove all the
5287 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
5288 * the IOCBs with the completion callback function associated, the callback
5289 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
5290 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
5291 * callback function associated, the IOCB will simply be released. Finally,
5292 * it walks the ELS transmit completion queue to issue an abort IOCB to any
5293 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
5294 * management plane IOCBs that are not part of the discovery state machine)
5295 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
5298 lpfc_els_flush_all_cmd(struct lpfc_hba
*phba
)
5300 LIST_HEAD(completions
);
5301 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
5302 struct lpfc_iocbq
*tmp_iocb
, *piocb
;
5305 lpfc_fabric_abort_hba(phba
);
5306 spin_lock_irq(&phba
->hbalock
);
5307 list_for_each_entry_safe(piocb
, tmp_iocb
, &pring
->txq
, list
) {
5309 if (piocb
->iocb_flag
& LPFC_IO_LIBDFC
)
5311 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
5312 if (cmd
->ulpCommand
== CMD_QUE_RING_BUF_CN
||
5313 cmd
->ulpCommand
== CMD_QUE_RING_BUF64_CN
||
5314 cmd
->ulpCommand
== CMD_CLOSE_XRI_CN
||
5315 cmd
->ulpCommand
== CMD_ABORT_XRI_CN
)
5317 list_move_tail(&piocb
->list
, &completions
);
5320 list_for_each_entry_safe(piocb
, tmp_iocb
, &pring
->txcmplq
, list
) {
5321 if (piocb
->iocb_flag
& LPFC_IO_LIBDFC
)
5323 lpfc_sli_issue_abort_iotag(phba
, pring
, piocb
);
5325 spin_unlock_irq(&phba
->hbalock
);
5327 /* Cancel all the IOCBs from the completions list */
5328 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
5335 * lpfc_send_els_failure_event - Posts an ELS command failure event
5336 * @phba: Pointer to hba context object.
5337 * @cmdiocbp: Pointer to command iocb which reported error.
5338 * @rspiocbp: Pointer to response iocb which reported error.
5340 * This function sends an event when there is an ELS command
5344 lpfc_send_els_failure_event(struct lpfc_hba
*phba
,
5345 struct lpfc_iocbq
*cmdiocbp
,
5346 struct lpfc_iocbq
*rspiocbp
)
5348 struct lpfc_vport
*vport
= cmdiocbp
->vport
;
5349 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
5350 struct lpfc_lsrjt_event lsrjt_event
;
5351 struct lpfc_fabric_event_header fabric_event
;
5353 struct lpfc_nodelist
*ndlp
;
5356 ndlp
= cmdiocbp
->context1
;
5357 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
))
5360 if (rspiocbp
->iocb
.ulpStatus
== IOSTAT_LS_RJT
) {
5361 lsrjt_event
.header
.event_type
= FC_REG_ELS_EVENT
;
5362 lsrjt_event
.header
.subcategory
= LPFC_EVENT_LSRJT_RCV
;
5363 memcpy(lsrjt_event
.header
.wwpn
, &ndlp
->nlp_portname
,
5364 sizeof(struct lpfc_name
));
5365 memcpy(lsrjt_event
.header
.wwnn
, &ndlp
->nlp_nodename
,
5366 sizeof(struct lpfc_name
));
5367 pcmd
= (uint32_t *) (((struct lpfc_dmabuf
*)
5368 cmdiocbp
->context2
)->virt
);
5369 lsrjt_event
.command
= *pcmd
;
5370 stat
.un
.lsRjtError
= be32_to_cpu(rspiocbp
->iocb
.un
.ulpWord
[4]);
5371 lsrjt_event
.reason_code
= stat
.un
.b
.lsRjtRsnCode
;
5372 lsrjt_event
.explanation
= stat
.un
.b
.lsRjtRsnCodeExp
;
5373 fc_host_post_vendor_event(shost
,
5374 fc_get_event_number(),
5375 sizeof(lsrjt_event
),
5376 (char *)&lsrjt_event
,
5380 if ((rspiocbp
->iocb
.ulpStatus
== IOSTAT_NPORT_BSY
) ||
5381 (rspiocbp
->iocb
.ulpStatus
== IOSTAT_FABRIC_BSY
)) {
5382 fabric_event
.event_type
= FC_REG_FABRIC_EVENT
;
5383 if (rspiocbp
->iocb
.ulpStatus
== IOSTAT_NPORT_BSY
)
5384 fabric_event
.subcategory
= LPFC_EVENT_PORT_BUSY
;
5386 fabric_event
.subcategory
= LPFC_EVENT_FABRIC_BUSY
;
5387 memcpy(fabric_event
.wwpn
, &ndlp
->nlp_portname
,
5388 sizeof(struct lpfc_name
));
5389 memcpy(fabric_event
.wwnn
, &ndlp
->nlp_nodename
,
5390 sizeof(struct lpfc_name
));
5391 fc_host_post_vendor_event(shost
,
5392 fc_get_event_number(),
5393 sizeof(fabric_event
),
5394 (char *)&fabric_event
,
5402 * lpfc_send_els_event - Posts unsolicited els event
5403 * @vport: Pointer to vport object.
5404 * @ndlp: Pointer FC node object.
5405 * @cmd: ELS command code.
5407 * This function posts an event when there is an incoming
5408 * unsolicited ELS command.
5411 lpfc_send_els_event(struct lpfc_vport
*vport
,
5412 struct lpfc_nodelist
*ndlp
,
5415 struct lpfc_els_event_header
*els_data
= NULL
;
5416 struct lpfc_logo_event
*logo_data
= NULL
;
5417 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
5419 if (*payload
== ELS_CMD_LOGO
) {
5420 logo_data
= kmalloc(sizeof(struct lpfc_logo_event
), GFP_KERNEL
);
5422 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
5423 "0148 Failed to allocate memory "
5424 "for LOGO event\n");
5427 els_data
= &logo_data
->header
;
5429 els_data
= kmalloc(sizeof(struct lpfc_els_event_header
),
5432 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
5433 "0149 Failed to allocate memory "
5438 els_data
->event_type
= FC_REG_ELS_EVENT
;
5441 els_data
->subcategory
= LPFC_EVENT_PLOGI_RCV
;
5444 els_data
->subcategory
= LPFC_EVENT_PRLO_RCV
;
5447 els_data
->subcategory
= LPFC_EVENT_ADISC_RCV
;
5450 els_data
->subcategory
= LPFC_EVENT_LOGO_RCV
;
5451 /* Copy the WWPN in the LOGO payload */
5452 memcpy(logo_data
->logo_wwpn
, &payload
[2],
5453 sizeof(struct lpfc_name
));
5459 memcpy(els_data
->wwpn
, &ndlp
->nlp_portname
, sizeof(struct lpfc_name
));
5460 memcpy(els_data
->wwnn
, &ndlp
->nlp_nodename
, sizeof(struct lpfc_name
));
5461 if (*payload
== ELS_CMD_LOGO
) {
5462 fc_host_post_vendor_event(shost
,
5463 fc_get_event_number(),
5464 sizeof(struct lpfc_logo_event
),
5469 fc_host_post_vendor_event(shost
,
5470 fc_get_event_number(),
5471 sizeof(struct lpfc_els_event_header
),
5482 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
5483 * @phba: pointer to lpfc hba data structure.
5484 * @pring: pointer to a SLI ring.
5485 * @vport: pointer to a host virtual N_Port data structure.
5486 * @elsiocb: pointer to lpfc els command iocb data structure.
5488 * This routine is used for processing the IOCB associated with a unsolicited
5489 * event. It first determines whether there is an existing ndlp that matches
5490 * the DID from the unsolicited IOCB. If not, it will create a new one with
5491 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
5492 * IOCB is then used to invoke the proper routine and to set up proper state
5493 * of the discovery state machine.
5496 lpfc_els_unsol_buffer(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
5497 struct lpfc_vport
*vport
, struct lpfc_iocbq
*elsiocb
)
5499 struct Scsi_Host
*shost
;
5500 struct lpfc_nodelist
*ndlp
;
5503 uint32_t cmd
, did
, newnode
, rjt_err
= 0;
5504 IOCB_t
*icmd
= &elsiocb
->iocb
;
5506 if (!vport
|| !(elsiocb
->context2
))
5510 payload
= ((struct lpfc_dmabuf
*)elsiocb
->context2
)->virt
;
5512 if ((phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) == 0)
5513 lpfc_post_buffer(phba
, pring
, 1);
5515 did
= icmd
->un
.rcvels
.remoteID
;
5516 if (icmd
->ulpStatus
) {
5517 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
5518 "RCV Unsol ELS: status:x%x/x%x did:x%x",
5519 icmd
->ulpStatus
, icmd
->un
.ulpWord
[4], did
);
5523 /* Check to see if link went down during discovery */
5524 if (lpfc_els_chk_latt(vport
))
5527 /* Ignore traffic received during vport shutdown. */
5528 if (vport
->load_flag
& FC_UNLOADING
)
5531 ndlp
= lpfc_findnode_did(vport
, did
);
5533 /* Cannot find existing Fabric ndlp, so allocate a new one */
5534 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
5538 lpfc_nlp_init(vport
, ndlp
, did
);
5539 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
5541 if ((did
& Fabric_DID_MASK
) == Fabric_DID_MASK
)
5542 ndlp
->nlp_type
|= NLP_FABRIC
;
5543 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
5544 ndlp
= lpfc_enable_node(vport
, ndlp
,
5545 NLP_STE_UNUSED_NODE
);
5548 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
5550 if ((did
& Fabric_DID_MASK
) == Fabric_DID_MASK
)
5551 ndlp
->nlp_type
|= NLP_FABRIC
;
5552 } else if (ndlp
->nlp_state
== NLP_STE_UNUSED_NODE
) {
5553 /* This is similar to the new node path */
5554 ndlp
= lpfc_nlp_get(ndlp
);
5557 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
5561 phba
->fc_stat
.elsRcvFrame
++;
5563 elsiocb
->context1
= lpfc_nlp_get(ndlp
);
5564 elsiocb
->vport
= vport
;
5566 if ((cmd
& ELS_CMD_MASK
) == ELS_CMD_RSCN
) {
5567 cmd
&= ELS_CMD_MASK
;
5569 /* ELS command <elsCmd> received from NPORT <did> */
5570 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
5571 "0112 ELS command x%x received from NPORT x%x "
5572 "Data: x%x\n", cmd
, did
, vport
->port_state
);
5575 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
5576 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
5577 did
, vport
->port_state
, ndlp
->nlp_flag
);
5579 phba
->fc_stat
.elsRcvPLOGI
++;
5580 ndlp
= lpfc_plogi_confirm_nport(phba
, payload
, ndlp
);
5582 lpfc_send_els_event(vport
, ndlp
, payload
);
5583 if (vport
->port_state
< LPFC_DISC_AUTH
) {
5584 if (!(phba
->pport
->fc_flag
& FC_PT2PT
) ||
5585 (phba
->pport
->fc_flag
& FC_PT2PT_PLOGI
)) {
5586 rjt_err
= LSRJT_UNABLE_TPC
;
5589 /* We get here, and drop thru, if we are PT2PT with
5590 * another NPort and the other side has initiated
5591 * the PLOGI before responding to our FLOGI.
5595 shost
= lpfc_shost_from_vport(vport
);
5596 spin_lock_irq(shost
->host_lock
);
5597 ndlp
->nlp_flag
&= ~NLP_TARGET_REMOVE
;
5598 spin_unlock_irq(shost
->host_lock
);
5600 lpfc_disc_state_machine(vport
, ndlp
, elsiocb
,
5605 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
5606 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
5607 did
, vport
->port_state
, ndlp
->nlp_flag
);
5609 phba
->fc_stat
.elsRcvFLOGI
++;
5610 lpfc_els_rcv_flogi(vport
, elsiocb
, ndlp
);
5615 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
5616 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
5617 did
, vport
->port_state
, ndlp
->nlp_flag
);
5619 phba
->fc_stat
.elsRcvLOGO
++;
5620 lpfc_send_els_event(vport
, ndlp
, payload
);
5621 if (vport
->port_state
< LPFC_DISC_AUTH
) {
5622 rjt_err
= LSRJT_UNABLE_TPC
;
5625 lpfc_disc_state_machine(vport
, ndlp
, elsiocb
, NLP_EVT_RCV_LOGO
);
5628 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
5629 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
5630 did
, vport
->port_state
, ndlp
->nlp_flag
);
5632 phba
->fc_stat
.elsRcvPRLO
++;
5633 lpfc_send_els_event(vport
, ndlp
, payload
);
5634 if (vport
->port_state
< LPFC_DISC_AUTH
) {
5635 rjt_err
= LSRJT_UNABLE_TPC
;
5638 lpfc_disc_state_machine(vport
, ndlp
, elsiocb
, NLP_EVT_RCV_PRLO
);
5641 phba
->fc_stat
.elsRcvRSCN
++;
5642 lpfc_els_rcv_rscn(vport
, elsiocb
, ndlp
);
5647 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
5648 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
5649 did
, vport
->port_state
, ndlp
->nlp_flag
);
5651 lpfc_send_els_event(vport
, ndlp
, payload
);
5652 phba
->fc_stat
.elsRcvADISC
++;
5653 if (vport
->port_state
< LPFC_DISC_AUTH
) {
5654 rjt_err
= LSRJT_UNABLE_TPC
;
5657 lpfc_disc_state_machine(vport
, ndlp
, elsiocb
,
5661 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
5662 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
5663 did
, vport
->port_state
, ndlp
->nlp_flag
);
5665 phba
->fc_stat
.elsRcvPDISC
++;
5666 if (vport
->port_state
< LPFC_DISC_AUTH
) {
5667 rjt_err
= LSRJT_UNABLE_TPC
;
5670 lpfc_disc_state_machine(vport
, ndlp
, elsiocb
,
5674 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
5675 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
5676 did
, vport
->port_state
, ndlp
->nlp_flag
);
5678 phba
->fc_stat
.elsRcvFARPR
++;
5679 lpfc_els_rcv_farpr(vport
, elsiocb
, ndlp
);
5682 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
5683 "RCV FARP: did:x%x/ste:x%x flg:x%x",
5684 did
, vport
->port_state
, ndlp
->nlp_flag
);
5686 phba
->fc_stat
.elsRcvFARP
++;
5687 lpfc_els_rcv_farp(vport
, elsiocb
, ndlp
);
5690 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
5691 "RCV FAN: did:x%x/ste:x%x flg:x%x",
5692 did
, vport
->port_state
, ndlp
->nlp_flag
);
5694 phba
->fc_stat
.elsRcvFAN
++;
5695 lpfc_els_rcv_fan(vport
, elsiocb
, ndlp
);
5698 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
5699 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
5700 did
, vport
->port_state
, ndlp
->nlp_flag
);
5702 phba
->fc_stat
.elsRcvPRLI
++;
5703 if (vport
->port_state
< LPFC_DISC_AUTH
) {
5704 rjt_err
= LSRJT_UNABLE_TPC
;
5707 lpfc_disc_state_machine(vport
, ndlp
, elsiocb
, NLP_EVT_RCV_PRLI
);
5710 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
5711 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
5712 did
, vport
->port_state
, ndlp
->nlp_flag
);
5714 phba
->fc_stat
.elsRcvLIRR
++;
5715 lpfc_els_rcv_lirr(vport
, elsiocb
, ndlp
);
5720 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
5721 "RCV RPS: did:x%x/ste:x%x flg:x%x",
5722 did
, vport
->port_state
, ndlp
->nlp_flag
);
5724 phba
->fc_stat
.elsRcvRPS
++;
5725 lpfc_els_rcv_rps(vport
, elsiocb
, ndlp
);
5730 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
5731 "RCV RPL: did:x%x/ste:x%x flg:x%x",
5732 did
, vport
->port_state
, ndlp
->nlp_flag
);
5734 phba
->fc_stat
.elsRcvRPL
++;
5735 lpfc_els_rcv_rpl(vport
, elsiocb
, ndlp
);
5740 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
5741 "RCV RNID: did:x%x/ste:x%x flg:x%x",
5742 did
, vport
->port_state
, ndlp
->nlp_flag
);
5744 phba
->fc_stat
.elsRcvRNID
++;
5745 lpfc_els_rcv_rnid(vport
, elsiocb
, ndlp
);
5750 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
5751 "RCV RRQ: did:x%x/ste:x%x flg:x%x",
5752 did
, vport
->port_state
, ndlp
->nlp_flag
);
5754 phba
->fc_stat
.elsRcvRRQ
++;
5755 lpfc_els_rcv_rrq(vport
, elsiocb
, ndlp
);
5760 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
5761 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
5762 cmd
, did
, vport
->port_state
);
5764 /* Unsupported ELS command, reject */
5765 rjt_err
= LSRJT_INVALID_CMD
;
5767 /* Unknown ELS command <elsCmd> received from NPORT <did> */
5768 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
5769 "0115 Unknown ELS command x%x "
5770 "received from NPORT x%x\n", cmd
, did
);
5776 /* check if need to LS_RJT received ELS cmd */
5778 memset(&stat
, 0, sizeof(stat
));
5779 stat
.un
.b
.lsRjtRsnCode
= rjt_err
;
5780 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_NOTHING_MORE
;
5781 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, elsiocb
, ndlp
,
5785 lpfc_nlp_put(elsiocb
->context1
);
5786 elsiocb
->context1
= NULL
;
5790 if (vport
&& !(vport
->load_flag
& FC_UNLOADING
))
5791 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
5792 "0111 Dropping received ELS cmd "
5793 "Data: x%x x%x x%x\n",
5794 icmd
->ulpStatus
, icmd
->un
.ulpWord
[4], icmd
->ulpTimeout
);
5795 phba
->fc_stat
.elsRcvDrop
++;
5799 * lpfc_find_vport_by_vpid - Find a vport on a HBA through vport identifier
5800 * @phba: pointer to lpfc hba data structure.
5801 * @vpi: host virtual N_Port identifier.
5803 * This routine finds a vport on a HBA (referred by @phba) through a
5804 * @vpi. The function walks the HBA's vport list and returns the address
5805 * of the vport with the matching @vpi.
5808 * NULL - No vport with the matching @vpi found
5809 * Otherwise - Address to the vport with the matching @vpi.
5812 lpfc_find_vport_by_vpid(struct lpfc_hba
*phba
, uint16_t vpi
)
5814 struct lpfc_vport
*vport
;
5815 unsigned long flags
;
5817 spin_lock_irqsave(&phba
->hbalock
, flags
);
5818 list_for_each_entry(vport
, &phba
->port_list
, listentry
) {
5819 if (vport
->vpi
== vpi
) {
5820 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
5824 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
5829 * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
5830 * @phba: pointer to lpfc hba data structure.
5831 * @pring: pointer to a SLI ring.
5832 * @elsiocb: pointer to lpfc els iocb data structure.
5834 * This routine is used to process an unsolicited event received from a SLI
5835 * (Service Level Interface) ring. The actual processing of the data buffer
5836 * associated with the unsolicited event is done by invoking the routine
5837 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
5838 * SLI ring on which the unsolicited event was received.
5841 lpfc_els_unsol_event(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
5842 struct lpfc_iocbq
*elsiocb
)
5844 struct lpfc_vport
*vport
= phba
->pport
;
5845 IOCB_t
*icmd
= &elsiocb
->iocb
;
5847 struct lpfc_dmabuf
*bdeBuf1
= elsiocb
->context2
;
5848 struct lpfc_dmabuf
*bdeBuf2
= elsiocb
->context3
;
5850 elsiocb
->context1
= NULL
;
5851 elsiocb
->context2
= NULL
;
5852 elsiocb
->context3
= NULL
;
5854 if (icmd
->ulpStatus
== IOSTAT_NEED_BUFFER
) {
5855 lpfc_sli_hbqbuf_add_hbqs(phba
, LPFC_ELS_HBQ
);
5856 } else if (icmd
->ulpStatus
== IOSTAT_LOCAL_REJECT
&&
5857 (icmd
->un
.ulpWord
[4] & 0xff) == IOERR_RCV_BUFFER_WAITING
) {
5858 phba
->fc_stat
.NoRcvBuf
++;
5859 /* Not enough posted buffers; Try posting more buffers */
5860 if (!(phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
))
5861 lpfc_post_buffer(phba
, pring
, 0);
5865 if ((phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
5866 (icmd
->ulpCommand
== CMD_IOCB_RCV_ELS64_CX
||
5867 icmd
->ulpCommand
== CMD_IOCB_RCV_SEQ64_CX
)) {
5868 if (icmd
->unsli3
.rcvsli3
.vpi
== 0xffff)
5869 vport
= phba
->pport
;
5871 vport
= lpfc_find_vport_by_vpid(phba
,
5872 icmd
->unsli3
.rcvsli3
.vpi
- phba
->vpi_base
);
5874 /* If there are no BDEs associated
5875 * with this IOCB, there is nothing to do.
5877 if (icmd
->ulpBdeCount
== 0)
5880 /* type of ELS cmd is first 32bit word
5883 if (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) {
5884 elsiocb
->context2
= bdeBuf1
;
5886 paddr
= getPaddr(icmd
->un
.cont64
[0].addrHigh
,
5887 icmd
->un
.cont64
[0].addrLow
);
5888 elsiocb
->context2
= lpfc_sli_ringpostbuf_get(phba
, pring
,
5892 lpfc_els_unsol_buffer(phba
, pring
, vport
, elsiocb
);
5894 * The different unsolicited event handlers would tell us
5895 * if they are done with "mp" by setting context2 to NULL.
5897 if (elsiocb
->context2
) {
5898 lpfc_in_buf_free(phba
, (struct lpfc_dmabuf
*)elsiocb
->context2
);
5899 elsiocb
->context2
= NULL
;
5902 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
5903 if ((phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) &&
5904 icmd
->ulpBdeCount
== 2) {
5905 elsiocb
->context2
= bdeBuf2
;
5906 lpfc_els_unsol_buffer(phba
, pring
, vport
, elsiocb
);
5907 /* free mp if we are done with it */
5908 if (elsiocb
->context2
) {
5909 lpfc_in_buf_free(phba
, elsiocb
->context2
);
5910 elsiocb
->context2
= NULL
;
5916 * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
5917 * @phba: pointer to lpfc hba data structure.
5918 * @vport: pointer to a virtual N_Port data structure.
5920 * This routine issues a Port Login (PLOGI) to the Name Server with
5921 * State Change Request (SCR) for a @vport. This routine will create an
5922 * ndlp for the Name Server associated to the @vport if such node does
5923 * not already exist. The PLOGI to Name Server is issued by invoking the
5924 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
5925 * (FDMI) is configured to the @vport, a FDMI node will be created and
5926 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
5929 lpfc_do_scr_ns_plogi(struct lpfc_hba
*phba
, struct lpfc_vport
*vport
)
5931 struct lpfc_nodelist
*ndlp
, *ndlp_fdmi
;
5933 ndlp
= lpfc_findnode_did(vport
, NameServer_DID
);
5935 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
5937 if (phba
->fc_topology
== TOPOLOGY_LOOP
) {
5938 lpfc_disc_start(vport
);
5941 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
5942 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
5943 "0251 NameServer login: no memory\n");
5946 lpfc_nlp_init(vport
, ndlp
, NameServer_DID
);
5947 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
5948 ndlp
= lpfc_enable_node(vport
, ndlp
, NLP_STE_UNUSED_NODE
);
5950 if (phba
->fc_topology
== TOPOLOGY_LOOP
) {
5951 lpfc_disc_start(vport
);
5954 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
5955 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
5956 "0348 NameServer login: node freed\n");
5960 ndlp
->nlp_type
|= NLP_FABRIC
;
5962 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
5964 if (lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, 0)) {
5965 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
5966 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
5967 "0252 Cannot issue NameServer login\n");
5971 if (vport
->cfg_fdmi_on
) {
5972 ndlp_fdmi
= mempool_alloc(phba
->nlp_mem_pool
,
5975 lpfc_nlp_init(vport
, ndlp_fdmi
, FDMI_DID
);
5976 ndlp_fdmi
->nlp_type
|= NLP_FABRIC
;
5977 lpfc_nlp_set_state(vport
, ndlp_fdmi
,
5978 NLP_STE_PLOGI_ISSUE
);
5979 lpfc_issue_els_plogi(vport
, ndlp_fdmi
->nlp_DID
,
5987 * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
5988 * @phba: pointer to lpfc hba data structure.
5989 * @pmb: pointer to the driver internal queue element for mailbox command.
5991 * This routine is the completion callback function to register new vport
5992 * mailbox command. If the new vport mailbox command completes successfully,
5993 * the fabric registration login shall be performed on physical port (the
5994 * new vport created is actually a physical port, with VPI 0) or the port
5995 * login to Name Server for State Change Request (SCR) will be performed
5996 * on virtual port (real virtual port, with VPI greater than 0).
5999 lpfc_cmpl_reg_new_vport(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
6001 struct lpfc_vport
*vport
= pmb
->vport
;
6002 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
6003 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) pmb
->context2
;
6004 MAILBOX_t
*mb
= &pmb
->u
.mb
;
6007 spin_lock_irq(shost
->host_lock
);
6008 vport
->fc_flag
&= ~FC_VPORT_NEEDS_REG_VPI
;
6009 spin_unlock_irq(shost
->host_lock
);
6011 if (mb
->mbxStatus
) {
6012 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
6013 "0915 Register VPI failed: 0x%x\n",
6016 switch (mb
->mbxStatus
) {
6017 case 0x11: /* unsupported feature */
6018 case 0x9603: /* max_vpi exceeded */
6019 case 0x9602: /* Link event since CLEAR_LA */
6020 /* giving up on vport registration */
6021 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
6022 spin_lock_irq(shost
->host_lock
);
6023 vport
->fc_flag
&= ~(FC_FABRIC
| FC_PUBLIC_LOOP
);
6024 spin_unlock_irq(shost
->host_lock
);
6025 lpfc_can_disctmo(vport
);
6027 /* If reg_vpi fail with invalid VPI status, re-init VPI */
6029 spin_lock_irq(shost
->host_lock
);
6030 vport
->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
6031 spin_unlock_irq(shost
->host_lock
);
6032 lpfc_init_vpi(phba
, pmb
, vport
->vpi
);
6034 pmb
->mbox_cmpl
= lpfc_init_vpi_cmpl
;
6035 rc
= lpfc_sli_issue_mbox(phba
, pmb
,
6037 if (rc
== MBX_NOT_FINISHED
) {
6038 lpfc_printf_vlog(vport
,
6040 "2732 Failed to issue INIT_VPI"
6041 " mailbox command\n");
6048 /* Try to recover from this error */
6049 lpfc_mbx_unreg_vpi(vport
);
6050 spin_lock_irq(shost
->host_lock
);
6051 vport
->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
6052 spin_unlock_irq(shost
->host_lock
);
6053 if (vport
->port_type
== LPFC_PHYSICAL_PORT
)
6054 lpfc_initial_flogi(vport
);
6056 lpfc_initial_fdisc(vport
);
6060 spin_lock_irq(shost
->host_lock
);
6061 vport
->vpi_state
|= LPFC_VPI_REGISTERED
;
6062 spin_unlock_irq(shost
->host_lock
);
6063 if (vport
== phba
->pport
) {
6064 if (phba
->sli_rev
< LPFC_SLI_REV4
)
6065 lpfc_issue_fabric_reglogin(vport
);
6068 * If the physical port is instantiated using
6069 * FDISC, do not start vport discovery.
6071 if (vport
->port_state
!= LPFC_FDISC
)
6072 lpfc_start_fdiscs(phba
);
6073 lpfc_do_scr_ns_plogi(phba
, vport
);
6076 lpfc_do_scr_ns_plogi(phba
, vport
);
6079 /* Now, we decrement the ndlp reference count held for this
6084 mempool_free(pmb
, phba
->mbox_mem_pool
);
6089 * lpfc_register_new_vport - Register a new vport with a HBA
6090 * @phba: pointer to lpfc hba data structure.
6091 * @vport: pointer to a host virtual N_Port data structure.
6092 * @ndlp: pointer to a node-list data structure.
6094 * This routine registers the @vport as a new virtual port with a HBA.
6095 * It is done through a registering vpi mailbox command.
6098 lpfc_register_new_vport(struct lpfc_hba
*phba
, struct lpfc_vport
*vport
,
6099 struct lpfc_nodelist
*ndlp
)
6101 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
6104 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
6106 lpfc_reg_vpi(vport
, mbox
);
6107 mbox
->vport
= vport
;
6108 mbox
->context2
= lpfc_nlp_get(ndlp
);
6109 mbox
->mbox_cmpl
= lpfc_cmpl_reg_new_vport
;
6110 if (lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
)
6111 == MBX_NOT_FINISHED
) {
6112 /* mailbox command not success, decrement ndlp
6113 * reference count for this command
6116 mempool_free(mbox
, phba
->mbox_mem_pool
);
6118 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
6119 "0253 Register VPI: Can't send mbox\n");
6123 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
6124 "0254 Register VPI: no memory\n");
6130 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
6131 spin_lock_irq(shost
->host_lock
);
6132 vport
->fc_flag
&= ~FC_VPORT_NEEDS_REG_VPI
;
6133 spin_unlock_irq(shost
->host_lock
);
6138 * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer
6139 * @phba: pointer to lpfc hba data structure.
6141 * This routine cancels the retry delay timers to all the vports.
6144 lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba
*phba
)
6146 struct lpfc_vport
**vports
;
6147 struct lpfc_nodelist
*ndlp
;
6148 uint32_t link_state
;
6151 /* Treat this failure as linkdown for all vports */
6152 link_state
= phba
->link_state
;
6153 lpfc_linkdown(phba
);
6154 phba
->link_state
= link_state
;
6156 vports
= lpfc_create_vport_work_array(phba
);
6159 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
6160 ndlp
= lpfc_findnode_did(vports
[i
], Fabric_DID
);
6162 lpfc_cancel_retry_delay_tmo(vports
[i
], ndlp
);
6163 lpfc_els_flush_cmd(vports
[i
]);
6165 lpfc_destroy_vport_work_array(phba
, vports
);
6170 * lpfc_retry_pport_discovery - Start timer to retry FLOGI.
6171 * @phba: pointer to lpfc hba data structure.
6173 * This routine abort all pending discovery commands and
6174 * start a timer to retry FLOGI for the physical port
6178 lpfc_retry_pport_discovery(struct lpfc_hba
*phba
)
6180 struct lpfc_nodelist
*ndlp
;
6181 struct Scsi_Host
*shost
;
6183 /* Cancel the all vports retry delay retry timers */
6184 lpfc_cancel_all_vport_retry_delay_timer(phba
);
6186 /* If fabric require FLOGI, then re-instantiate physical login */
6187 ndlp
= lpfc_findnode_did(phba
->pport
, Fabric_DID
);
6191 shost
= lpfc_shost_from_vport(phba
->pport
);
6192 mod_timer(&ndlp
->nlp_delayfunc
, jiffies
+ HZ
);
6193 spin_lock_irq(shost
->host_lock
);
6194 ndlp
->nlp_flag
|= NLP_DELAY_TMO
;
6195 spin_unlock_irq(shost
->host_lock
);
6196 ndlp
->nlp_last_elscmd
= ELS_CMD_FLOGI
;
6197 phba
->pport
->port_state
= LPFC_FLOGI
;
6202 * lpfc_fabric_login_reqd - Check if FLOGI required.
6203 * @phba: pointer to lpfc hba data structure.
6204 * @cmdiocb: pointer to FDISC command iocb.
6205 * @rspiocb: pointer to FDISC response iocb.
6207 * This routine checks if a FLOGI is reguired for FDISC
6211 lpfc_fabric_login_reqd(struct lpfc_hba
*phba
,
6212 struct lpfc_iocbq
*cmdiocb
,
6213 struct lpfc_iocbq
*rspiocb
)
6216 if ((rspiocb
->iocb
.ulpStatus
!= IOSTAT_FABRIC_RJT
) ||
6217 (rspiocb
->iocb
.un
.ulpWord
[4] != RJT_LOGIN_REQUIRED
))
6224 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
6225 * @phba: pointer to lpfc hba data structure.
6226 * @cmdiocb: pointer to lpfc command iocb data structure.
6227 * @rspiocb: pointer to lpfc response iocb data structure.
6229 * This routine is the completion callback function to a Fabric Discover
6230 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
6231 * single threaded, each FDISC completion callback function will reset
6232 * the discovery timer for all vports such that the timers will not get
6233 * unnecessary timeout. The function checks the FDISC IOCB status. If error
6234 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
6235 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
6236 * assigned to the vport has been changed with the completion of the FDISC
6237 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
6238 * are unregistered from the HBA, and then the lpfc_register_new_vport()
6239 * routine is invoked to register new vport with the HBA. Otherwise, the
6240 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
6241 * Server for State Change Request (SCR).
6244 lpfc_cmpl_els_fdisc(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
6245 struct lpfc_iocbq
*rspiocb
)
6247 struct lpfc_vport
*vport
= cmdiocb
->vport
;
6248 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
6249 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) cmdiocb
->context1
;
6250 struct lpfc_nodelist
*np
;
6251 struct lpfc_nodelist
*next_np
;
6252 IOCB_t
*irsp
= &rspiocb
->iocb
;
6253 struct lpfc_iocbq
*piocb
;
6255 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
6256 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
6257 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
6259 /* Since all FDISCs are being single threaded, we
6260 * must reset the discovery timer for ALL vports
6261 * waiting to send FDISC when one completes.
6263 list_for_each_entry(piocb
, &phba
->fabric_iocb_list
, list
) {
6264 lpfc_set_disctmo(piocb
->vport
);
6267 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
6268 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
6269 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4], vport
->fc_prevDID
);
6271 if (irsp
->ulpStatus
) {
6273 if (lpfc_fabric_login_reqd(phba
, cmdiocb
, rspiocb
)) {
6274 lpfc_retry_pport_discovery(phba
);
6278 /* Check for retry */
6279 if (lpfc_els_retry(phba
, cmdiocb
, rspiocb
))
6282 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
6283 "0126 FDISC failed. (%d/%d)\n",
6284 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4]);
6287 spin_lock_irq(shost
->host_lock
);
6288 vport
->fc_flag
&= ~FC_VPORT_CVL_RCVD
;
6289 vport
->fc_flag
|= FC_FABRIC
;
6290 if (vport
->phba
->fc_topology
== TOPOLOGY_LOOP
)
6291 vport
->fc_flag
|= FC_PUBLIC_LOOP
;
6292 spin_unlock_irq(shost
->host_lock
);
6294 vport
->fc_myDID
= irsp
->un
.ulpWord
[4] & Mask_DID
;
6295 lpfc_vport_set_state(vport
, FC_VPORT_ACTIVE
);
6296 if ((vport
->fc_prevDID
!= vport
->fc_myDID
) &&
6297 !(vport
->fc_flag
& FC_VPORT_NEEDS_REG_VPI
)) {
6298 /* If our NportID changed, we need to ensure all
6299 * remaining NPORTs get unreg_login'ed so we can
6302 list_for_each_entry_safe(np
, next_np
,
6303 &vport
->fc_nodes
, nlp_listp
) {
6304 if (!NLP_CHK_NODE_ACT(ndlp
) ||
6305 (np
->nlp_state
!= NLP_STE_NPR_NODE
) ||
6306 !(np
->nlp_flag
& NLP_NPR_ADISC
))
6308 spin_lock_irq(shost
->host_lock
);
6309 np
->nlp_flag
&= ~NLP_NPR_ADISC
;
6310 spin_unlock_irq(shost
->host_lock
);
6311 lpfc_unreg_rpi(vport
, np
);
6313 lpfc_mbx_unreg_vpi(vport
);
6314 spin_lock_irq(shost
->host_lock
);
6315 vport
->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
6316 if (phba
->sli_rev
== LPFC_SLI_REV4
)
6317 vport
->fc_flag
|= FC_VPORT_NEEDS_INIT_VPI
;
6318 spin_unlock_irq(shost
->host_lock
);
6321 if (vport
->fc_flag
& FC_VPORT_NEEDS_INIT_VPI
)
6322 lpfc_issue_init_vpi(vport
);
6323 else if (vport
->fc_flag
& FC_VPORT_NEEDS_REG_VPI
)
6324 lpfc_register_new_vport(phba
, vport
, ndlp
);
6326 lpfc_do_scr_ns_plogi(phba
, vport
);
6329 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
6330 /* Cancel discovery timer */
6331 lpfc_can_disctmo(vport
);
6334 lpfc_els_free_iocb(phba
, cmdiocb
);
6338 * lpfc_issue_els_fdisc - Issue a fdisc iocb command
6339 * @vport: pointer to a virtual N_Port data structure.
6340 * @ndlp: pointer to a node-list data structure.
6341 * @retry: number of retries to the command IOCB.
6343 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
6344 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
6345 * routine to issue the IOCB, which makes sure only one outstanding fabric
6346 * IOCB will be sent off HBA at any given time.
6348 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6349 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6350 * will be stored into the context1 field of the IOCB for the completion
6351 * callback function to the FDISC ELS command.
6354 * 0 - Successfully issued fdisc iocb command
6355 * 1 - Failed to issue fdisc iocb command
6358 lpfc_issue_els_fdisc(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
6361 struct lpfc_hba
*phba
= vport
->phba
;
6363 struct lpfc_iocbq
*elsiocb
;
6364 struct serv_parm
*sp
;
6367 int did
= ndlp
->nlp_DID
;
6370 vport
->port_state
= LPFC_FDISC
;
6371 cmdsize
= (sizeof(uint32_t) + sizeof(struct serv_parm
));
6372 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
, did
,
6375 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
6376 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
6377 "0255 Issue FDISC: no IOCB\n");
6381 icmd
= &elsiocb
->iocb
;
6382 icmd
->un
.elsreq64
.myID
= 0;
6383 icmd
->un
.elsreq64
.fl
= 1;
6385 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
6386 /* FDISC needs to be 1 for WQE VPI */
6387 elsiocb
->iocb
.ulpCt_h
= (SLI4_CT_VPI
>> 1) & 1;
6388 elsiocb
->iocb
.ulpCt_l
= SLI4_CT_VPI
& 1 ;
6389 /* Set the ulpContext to the vpi */
6390 elsiocb
->iocb
.ulpContext
= vport
->vpi
+ phba
->vpi_base
;
6392 /* For FDISC, Let FDISC rsp set the NPortID for this VPI */
6397 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
6398 *((uint32_t *) (pcmd
)) = ELS_CMD_FDISC
;
6399 pcmd
+= sizeof(uint32_t); /* CSP Word 1 */
6400 memcpy(pcmd
, &vport
->phba
->pport
->fc_sparam
, sizeof(struct serv_parm
));
6401 sp
= (struct serv_parm
*) pcmd
;
6402 /* Setup CSPs accordingly for Fabric */
6403 sp
->cmn
.e_d_tov
= 0;
6404 sp
->cmn
.w2
.r_a_tov
= 0;
6405 sp
->cls1
.classValid
= 0;
6406 sp
->cls2
.seqDelivery
= 1;
6407 sp
->cls3
.seqDelivery
= 1;
6409 pcmd
+= sizeof(uint32_t); /* CSP Word 2 */
6410 pcmd
+= sizeof(uint32_t); /* CSP Word 3 */
6411 pcmd
+= sizeof(uint32_t); /* CSP Word 4 */
6412 pcmd
+= sizeof(uint32_t); /* Port Name */
6413 memcpy(pcmd
, &vport
->fc_portname
, 8);
6414 pcmd
+= sizeof(uint32_t); /* Node Name */
6415 pcmd
+= sizeof(uint32_t); /* Node Name */
6416 memcpy(pcmd
, &vport
->fc_nodename
, 8);
6418 lpfc_set_disctmo(vport
);
6420 phba
->fc_stat
.elsXmitFDISC
++;
6421 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_fdisc
;
6423 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
6424 "Issue FDISC: did:x%x",
6427 rc
= lpfc_issue_fabric_iocb(phba
, elsiocb
);
6428 if (rc
== IOCB_ERROR
) {
6429 lpfc_els_free_iocb(phba
, elsiocb
);
6430 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
6431 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
6432 "0256 Issue FDISC: Cannot send IOCB\n");
6435 lpfc_vport_set_state(vport
, FC_VPORT_INITIALIZING
);
6440 * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
6441 * @phba: pointer to lpfc hba data structure.
6442 * @cmdiocb: pointer to lpfc command iocb data structure.
6443 * @rspiocb: pointer to lpfc response iocb data structure.
6445 * This routine is the completion callback function to the issuing of a LOGO
6446 * ELS command off a vport. It frees the command IOCB and then decrement the
6447 * reference count held on ndlp for this completion function, indicating that
6448 * the reference to the ndlp is no long needed. Note that the
6449 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
6450 * callback function and an additional explicit ndlp reference decrementation
6451 * will trigger the actual release of the ndlp.
6454 lpfc_cmpl_els_npiv_logo(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
6455 struct lpfc_iocbq
*rspiocb
)
6457 struct lpfc_vport
*vport
= cmdiocb
->vport
;
6459 struct lpfc_nodelist
*ndlp
;
6460 ndlp
= (struct lpfc_nodelist
*)cmdiocb
->context1
;
6462 irsp
= &rspiocb
->iocb
;
6463 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
6464 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
6465 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4], irsp
->un
.rcvels
.remoteID
);
6467 lpfc_els_free_iocb(phba
, cmdiocb
);
6468 vport
->unreg_vpi_cmpl
= VPORT_ERROR
;
6470 /* Trigger the release of the ndlp after logo */
6475 * lpfc_issue_els_npiv_logo - Issue a logo off a vport
6476 * @vport: pointer to a virtual N_Port data structure.
6477 * @ndlp: pointer to a node-list data structure.
6479 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
6481 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6482 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6483 * will be stored into the context1 field of the IOCB for the completion
6484 * callback function to the LOGO ELS command.
6487 * 0 - Successfully issued logo off the @vport
6488 * 1 - Failed to issue logo off the @vport
6491 lpfc_issue_els_npiv_logo(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
6493 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
6494 struct lpfc_hba
*phba
= vport
->phba
;
6496 struct lpfc_iocbq
*elsiocb
;
6500 cmdsize
= 2 * sizeof(uint32_t) + sizeof(struct lpfc_name
);
6501 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, 0, ndlp
, ndlp
->nlp_DID
,
6506 icmd
= &elsiocb
->iocb
;
6507 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
6508 *((uint32_t *) (pcmd
)) = ELS_CMD_LOGO
;
6509 pcmd
+= sizeof(uint32_t);
6511 /* Fill in LOGO payload */
6512 *((uint32_t *) (pcmd
)) = be32_to_cpu(vport
->fc_myDID
);
6513 pcmd
+= sizeof(uint32_t);
6514 memcpy(pcmd
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
6516 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
6517 "Issue LOGO npiv did:x%x flg:x%x",
6518 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
6520 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_npiv_logo
;
6521 spin_lock_irq(shost
->host_lock
);
6522 ndlp
->nlp_flag
|= NLP_LOGO_SND
;
6523 spin_unlock_irq(shost
->host_lock
);
6524 if (lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0) ==
6526 spin_lock_irq(shost
->host_lock
);
6527 ndlp
->nlp_flag
&= ~NLP_LOGO_SND
;
6528 spin_unlock_irq(shost
->host_lock
);
6529 lpfc_els_free_iocb(phba
, elsiocb
);
6536 * lpfc_fabric_block_timeout - Handler function to the fabric block timer
6537 * @ptr: holder for the timer function associated data.
6539 * This routine is invoked by the fabric iocb block timer after
6540 * timeout. It posts the fabric iocb block timeout event by setting the
6541 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
6542 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
6543 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
6544 * posted event WORKER_FABRIC_BLOCK_TMO.
6547 lpfc_fabric_block_timeout(unsigned long ptr
)
6549 struct lpfc_hba
*phba
= (struct lpfc_hba
*) ptr
;
6550 unsigned long iflags
;
6551 uint32_t tmo_posted
;
6553 spin_lock_irqsave(&phba
->pport
->work_port_lock
, iflags
);
6554 tmo_posted
= phba
->pport
->work_port_events
& WORKER_FABRIC_BLOCK_TMO
;
6556 phba
->pport
->work_port_events
|= WORKER_FABRIC_BLOCK_TMO
;
6557 spin_unlock_irqrestore(&phba
->pport
->work_port_lock
, iflags
);
6560 lpfc_worker_wake_up(phba
);
6565 * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
6566 * @phba: pointer to lpfc hba data structure.
6568 * This routine issues one fabric iocb from the driver internal list to
6569 * the HBA. It first checks whether it's ready to issue one fabric iocb to
6570 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
6571 * remove one pending fabric iocb from the driver internal list and invokes
6572 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
6575 lpfc_resume_fabric_iocbs(struct lpfc_hba
*phba
)
6577 struct lpfc_iocbq
*iocb
;
6578 unsigned long iflags
;
6584 spin_lock_irqsave(&phba
->hbalock
, iflags
);
6585 /* Post any pending iocb to the SLI layer */
6586 if (atomic_read(&phba
->fabric_iocb_count
) == 0) {
6587 list_remove_head(&phba
->fabric_iocb_list
, iocb
, typeof(*iocb
),
6590 /* Increment fabric iocb count to hold the position */
6591 atomic_inc(&phba
->fabric_iocb_count
);
6593 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
6595 iocb
->fabric_iocb_cmpl
= iocb
->iocb_cmpl
;
6596 iocb
->iocb_cmpl
= lpfc_cmpl_fabric_iocb
;
6597 iocb
->iocb_flag
|= LPFC_IO_FABRIC
;
6599 lpfc_debugfs_disc_trc(iocb
->vport
, LPFC_DISC_TRC_ELS_CMD
,
6600 "Fabric sched1: ste:x%x",
6601 iocb
->vport
->port_state
, 0, 0);
6603 ret
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, iocb
, 0);
6605 if (ret
== IOCB_ERROR
) {
6606 iocb
->iocb_cmpl
= iocb
->fabric_iocb_cmpl
;
6607 iocb
->fabric_iocb_cmpl
= NULL
;
6608 iocb
->iocb_flag
&= ~LPFC_IO_FABRIC
;
6610 cmd
->ulpStatus
= IOSTAT_LOCAL_REJECT
;
6611 cmd
->un
.ulpWord
[4] = IOERR_SLI_ABORTED
;
6612 iocb
->iocb_cmpl(phba
, iocb
, iocb
);
6614 atomic_dec(&phba
->fabric_iocb_count
);
6623 * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
6624 * @phba: pointer to lpfc hba data structure.
6626 * This routine unblocks the issuing fabric iocb command. The function
6627 * will clear the fabric iocb block bit and then invoke the routine
6628 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
6629 * from the driver internal fabric iocb list.
6632 lpfc_unblock_fabric_iocbs(struct lpfc_hba
*phba
)
6634 clear_bit(FABRIC_COMANDS_BLOCKED
, &phba
->bit_flags
);
6636 lpfc_resume_fabric_iocbs(phba
);
6641 * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
6642 * @phba: pointer to lpfc hba data structure.
6644 * This routine blocks the issuing fabric iocb for a specified amount of
6645 * time (currently 100 ms). This is done by set the fabric iocb block bit
6646 * and set up a timeout timer for 100ms. When the block bit is set, no more
6647 * fabric iocb will be issued out of the HBA.
6650 lpfc_block_fabric_iocbs(struct lpfc_hba
*phba
)
6654 blocked
= test_and_set_bit(FABRIC_COMANDS_BLOCKED
, &phba
->bit_flags
);
6655 /* Start a timer to unblock fabric iocbs after 100ms */
6657 mod_timer(&phba
->fabric_block_timer
, jiffies
+ HZ
/10 );
6663 * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
6664 * @phba: pointer to lpfc hba data structure.
6665 * @cmdiocb: pointer to lpfc command iocb data structure.
6666 * @rspiocb: pointer to lpfc response iocb data structure.
6668 * This routine is the callback function that is put to the fabric iocb's
6669 * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
6670 * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
6671 * function first restores and invokes the original iocb's callback function
6672 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
6673 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
6676 lpfc_cmpl_fabric_iocb(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
6677 struct lpfc_iocbq
*rspiocb
)
6681 if ((cmdiocb
->iocb_flag
& LPFC_IO_FABRIC
) != LPFC_IO_FABRIC
)
6684 switch (rspiocb
->iocb
.ulpStatus
) {
6685 case IOSTAT_NPORT_RJT
:
6686 case IOSTAT_FABRIC_RJT
:
6687 if (rspiocb
->iocb
.un
.ulpWord
[4] & RJT_UNAVAIL_TEMP
) {
6688 lpfc_block_fabric_iocbs(phba
);
6692 case IOSTAT_NPORT_BSY
:
6693 case IOSTAT_FABRIC_BSY
:
6694 lpfc_block_fabric_iocbs(phba
);
6698 stat
.un
.lsRjtError
=
6699 be32_to_cpu(rspiocb
->iocb
.un
.ulpWord
[4]);
6700 if ((stat
.un
.b
.lsRjtRsnCode
== LSRJT_UNABLE_TPC
) ||
6701 (stat
.un
.b
.lsRjtRsnCode
== LSRJT_LOGICAL_BSY
))
6702 lpfc_block_fabric_iocbs(phba
);
6706 if (atomic_read(&phba
->fabric_iocb_count
) == 0)
6709 cmdiocb
->iocb_cmpl
= cmdiocb
->fabric_iocb_cmpl
;
6710 cmdiocb
->fabric_iocb_cmpl
= NULL
;
6711 cmdiocb
->iocb_flag
&= ~LPFC_IO_FABRIC
;
6712 cmdiocb
->iocb_cmpl(phba
, cmdiocb
, rspiocb
);
6714 atomic_dec(&phba
->fabric_iocb_count
);
6715 if (!test_bit(FABRIC_COMANDS_BLOCKED
, &phba
->bit_flags
)) {
6716 /* Post any pending iocbs to HBA */
6717 lpfc_resume_fabric_iocbs(phba
);
6722 * lpfc_issue_fabric_iocb - Issue a fabric iocb command
6723 * @phba: pointer to lpfc hba data structure.
6724 * @iocb: pointer to lpfc command iocb data structure.
6726 * This routine is used as the top-level API for issuing a fabric iocb command
6727 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
6728 * function makes sure that only one fabric bound iocb will be outstanding at
6729 * any given time. As such, this function will first check to see whether there
6730 * is already an outstanding fabric iocb on the wire. If so, it will put the
6731 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
6732 * issued later. Otherwise, it will issue the iocb on the wire and update the
6733 * fabric iocb count it indicate that there is one fabric iocb on the wire.
6735 * Note, this implementation has a potential sending out fabric IOCBs out of
6736 * order. The problem is caused by the construction of the "ready" boolen does
6737 * not include the condition that the internal fabric IOCB list is empty. As
6738 * such, it is possible a fabric IOCB issued by this routine might be "jump"
6739 * ahead of the fabric IOCBs in the internal list.
6742 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
6743 * IOCB_ERROR - failed to issue fabric iocb
6746 lpfc_issue_fabric_iocb(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocb
)
6748 unsigned long iflags
;
6752 if (atomic_read(&phba
->fabric_iocb_count
) > 1)
6755 spin_lock_irqsave(&phba
->hbalock
, iflags
);
6756 ready
= atomic_read(&phba
->fabric_iocb_count
) == 0 &&
6757 !test_bit(FABRIC_COMANDS_BLOCKED
, &phba
->bit_flags
);
6760 /* Increment fabric iocb count to hold the position */
6761 atomic_inc(&phba
->fabric_iocb_count
);
6762 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
6764 iocb
->fabric_iocb_cmpl
= iocb
->iocb_cmpl
;
6765 iocb
->iocb_cmpl
= lpfc_cmpl_fabric_iocb
;
6766 iocb
->iocb_flag
|= LPFC_IO_FABRIC
;
6768 lpfc_debugfs_disc_trc(iocb
->vport
, LPFC_DISC_TRC_ELS_CMD
,
6769 "Fabric sched2: ste:x%x",
6770 iocb
->vport
->port_state
, 0, 0);
6772 ret
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, iocb
, 0);
6774 if (ret
== IOCB_ERROR
) {
6775 iocb
->iocb_cmpl
= iocb
->fabric_iocb_cmpl
;
6776 iocb
->fabric_iocb_cmpl
= NULL
;
6777 iocb
->iocb_flag
&= ~LPFC_IO_FABRIC
;
6778 atomic_dec(&phba
->fabric_iocb_count
);
6781 spin_lock_irqsave(&phba
->hbalock
, iflags
);
6782 list_add_tail(&iocb
->list
, &phba
->fabric_iocb_list
);
6783 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
6790 * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
6791 * @vport: pointer to a virtual N_Port data structure.
6793 * This routine aborts all the IOCBs associated with a @vport from the
6794 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
6795 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
6796 * list, removes each IOCB associated with the @vport off the list, set the
6797 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
6798 * associated with the IOCB.
6800 static void lpfc_fabric_abort_vport(struct lpfc_vport
*vport
)
6802 LIST_HEAD(completions
);
6803 struct lpfc_hba
*phba
= vport
->phba
;
6804 struct lpfc_iocbq
*tmp_iocb
, *piocb
;
6806 spin_lock_irq(&phba
->hbalock
);
6807 list_for_each_entry_safe(piocb
, tmp_iocb
, &phba
->fabric_iocb_list
,
6810 if (piocb
->vport
!= vport
)
6813 list_move_tail(&piocb
->list
, &completions
);
6815 spin_unlock_irq(&phba
->hbalock
);
6817 /* Cancel all the IOCBs from the completions list */
6818 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
6823 * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
6824 * @ndlp: pointer to a node-list data structure.
6826 * This routine aborts all the IOCBs associated with an @ndlp from the
6827 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
6828 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
6829 * list, removes each IOCB associated with the @ndlp off the list, set the
6830 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
6831 * associated with the IOCB.
6833 void lpfc_fabric_abort_nport(struct lpfc_nodelist
*ndlp
)
6835 LIST_HEAD(completions
);
6836 struct lpfc_hba
*phba
= ndlp
->phba
;
6837 struct lpfc_iocbq
*tmp_iocb
, *piocb
;
6838 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
6840 spin_lock_irq(&phba
->hbalock
);
6841 list_for_each_entry_safe(piocb
, tmp_iocb
, &phba
->fabric_iocb_list
,
6843 if ((lpfc_check_sli_ndlp(phba
, pring
, piocb
, ndlp
))) {
6845 list_move_tail(&piocb
->list
, &completions
);
6848 spin_unlock_irq(&phba
->hbalock
);
6850 /* Cancel all the IOCBs from the completions list */
6851 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
6856 * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
6857 * @phba: pointer to lpfc hba data structure.
6859 * This routine aborts all the IOCBs currently on the driver internal
6860 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
6861 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
6862 * list, removes IOCBs off the list, set the status feild to
6863 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
6866 void lpfc_fabric_abort_hba(struct lpfc_hba
*phba
)
6868 LIST_HEAD(completions
);
6870 spin_lock_irq(&phba
->hbalock
);
6871 list_splice_init(&phba
->fabric_iocb_list
, &completions
);
6872 spin_unlock_irq(&phba
->hbalock
);
6874 /* Cancel all the IOCBs from the completions list */
6875 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
6880 * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
6881 * @phba: pointer to lpfc hba data structure.
6882 * @axri: pointer to the els xri abort wcqe structure.
6884 * This routine is invoked by the worker thread to process a SLI4 slow-path
6888 lpfc_sli4_els_xri_aborted(struct lpfc_hba
*phba
,
6889 struct sli4_wcqe_xri_aborted
*axri
)
6891 uint16_t xri
= bf_get(lpfc_wcqe_xa_xri
, axri
);
6892 struct lpfc_sglq
*sglq_entry
= NULL
, *sglq_next
= NULL
;
6893 unsigned long iflag
= 0;
6895 spin_lock_irqsave(&phba
->hbalock
, iflag
);
6896 spin_lock(&phba
->sli4_hba
.abts_sgl_list_lock
);
6897 list_for_each_entry_safe(sglq_entry
, sglq_next
,
6898 &phba
->sli4_hba
.lpfc_abts_els_sgl_list
, list
) {
6899 if (sglq_entry
->sli4_xritag
== xri
) {
6900 list_del(&sglq_entry
->list
);
6901 list_add_tail(&sglq_entry
->list
,
6902 &phba
->sli4_hba
.lpfc_sgl_list
);
6903 sglq_entry
->state
= SGL_FREED
;
6904 spin_unlock(&phba
->sli4_hba
.abts_sgl_list_lock
);
6905 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
6909 spin_unlock(&phba
->sli4_hba
.abts_sgl_list_lock
);
6910 sglq_entry
= __lpfc_get_active_sglq(phba
, xri
);
6911 if (!sglq_entry
|| (sglq_entry
->sli4_xritag
!= xri
)) {
6912 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
6915 sglq_entry
->state
= SGL_XRI_ABORTED
;
6916 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);